Libav
rtpdec_mpeg12.c
Go to the documentation of this file.
1 /*
2  * Common code for the RTP depacketization of MPEG-1/2 formats.
3  * Copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/attributes.h"
23 #include "libavutil/intreadwrite.h"
24 #include "rtpdec_formats.h"
25 
26 static av_cold int mpeg_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
27 {
28  if (st_index < 0)
29  return 0;
30  ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
31  return 0;
32 }
33 
35  AVStream *st, AVPacket *pkt, uint32_t *timestamp,
36  const uint8_t *buf, int len, uint16_t seq,
37  int flags)
38 {
39  unsigned int h;
40  if (len <= 4)
41  return AVERROR_INVALIDDATA;
42  h = AV_RB32(buf);
43  buf += 4;
44  len -= 4;
45  if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && h & (1 << 26)) {
46  /* MPEG-2 */
47  if (len <= 4)
48  return AVERROR_INVALIDDATA;
49  buf += 4;
50  len -= 4;
51  }
52  if (av_new_packet(pkt, len) < 0)
53  return AVERROR(ENOMEM);
54  memcpy(pkt->data, buf, len);
55  pkt->stream_index = st->index;
56  return 0;
57 }
58 
61  .codec_id = AV_CODEC_ID_MP3,
62  .init = mpeg_init,
63  .parse_packet = mpeg_parse_packet,
64  .static_payload_id = 14,
65 };
66 
69  .codec_id = AV_CODEC_ID_MPEG2VIDEO,
70  .init = mpeg_init,
71  .parse_packet = mpeg_parse_packet,
72  .static_payload_id = 32,
73 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
RTP/JPEG specific private data.
Definition: rdt.c:83
int index
stream index in AVFormatContext
Definition: avformat.h:700
enum AVMediaType codec_type
Definition: rtpdec.h:117
Macro definitions for various function/variable attributes.
Format I/O context.
Definition: avformat.h:922
RTPDynamicProtocolHandler ff_mpeg_audio_dynamic_handler
Definition: rtpdec_mpeg12.c:59
uint8_t
#define av_cold
Definition: attributes.h:66
#define AV_RB32
Definition: intreadwrite.h:130
enum AVStreamParseType need_parsing
Definition: avformat.h:867
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:990
const char data[16]
Definition: mxf.c:70
uint8_t * data
Definition: avcodec.h:973
static int flags
Definition: log.c:44
static av_cold int mpeg_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
Definition: rtpdec_mpeg12.c:26
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:81
#define AVERROR(e)
Definition: error.h:43
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:379
static int mpeg_parse_packet(AVFormatContext *ctx, PayloadContext *data, AVStream *st, AVPacket *pkt, uint32_t *timestamp, const uint8_t *buf, int len, uint16_t seq, int flags)
Definition: rtpdec_mpeg12.c:34
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:718
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:110
Stream structure.
Definition: avformat.h:699
enum AVMediaType codec_type
Definition: avcodec.h:1058
full parsing and repack
Definition: avformat.h:653
int len
RTPDynamicProtocolHandler ff_mpeg_video_dynamic_handler
Definition: rtpdec_mpeg12.c:67
int stream_index
Definition: avcodec.h:975
This structure stores compressed data.
Definition: avcodec.h:950