FFmpeg
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 FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 
27  AVStream *st, AVPacket *pkt, uint32_t *timestamp,
28  const uint8_t *buf, int len, uint16_t seq,
29  int flags)
30 {
31  unsigned int h;
32  int ret;
33  if (len <= 4)
34  return AVERROR_INVALIDDATA;
35  h = AV_RB32(buf);
36  buf += 4;
37  len -= 4;
38  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && h & (1 << 26)) {
39  /* MPEG-2 */
40  if (len <= 4)
41  return AVERROR_INVALIDDATA;
42  buf += 4;
43  len -= 4;
44  }
45  if ((ret = av_new_packet(pkt, len)) < 0)
46  return ret;
47  memcpy(pkt->data, buf, len);
48  pkt->stream_index = st->index;
49  return 0;
50 }
51 
54  .codec_id = AV_CODEC_ID_MP3,
55  .need_parsing = AVSTREAM_PARSE_FULL,
56  .parse_packet = mpeg_parse_packet,
57  .static_payload_id = 14,
58 };
59 
62  .codec_id = AV_CODEC_ID_MPEG2VIDEO,
63  .need_parsing = AVSTREAM_PARSE_FULL,
64  .parse_packet = mpeg_parse_packet,
65  .static_payload_id = 32,
66 };
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
rtpdec_formats.h
ff_mpeg_audio_dynamic_handler
const RTPDynamicProtocolHandler ff_mpeg_audio_dynamic_handler
Definition: rtpdec_mpeg12.c:52
AVPacket::data
uint8_t * data
Definition: packet.h:355
data
const char data[16]
Definition: mxf.c:91
mpeg_parse_packet
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:26
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:411
intreadwrite.h
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:88
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AVFormatContext
Format I/O context.
Definition: avformat.h:1335
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1012
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:92
attributes.h
ff_mpeg_video_dynamic_handler
const RTPDynamicProtocolHandler ff_mpeg_video_dynamic_handler
Definition: rtpdec_mpeg12.c:60
uint8_t
uint8_t
Definition: audio_convert.c:194
len
int len
Definition: vorbis_enc_data.h:452
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:865
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:866
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
RTPDynamicProtocolHandler::codec_type
enum AVMediaType codec_type
Definition: rtpdec.h:117
AVPacket::stream_index
int stream_index
Definition: packet.h:357
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVPacket
This structure stores compressed data.
Definition: packet.h:332
AVSTREAM_PARSE_FULL
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:786
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
h
h
Definition: vp9dsp_template.c:2038
PayloadContext
RTP/JPEG specific private data.
Definition: rdt.c:83
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:51
RTPDynamicProtocolHandler
Definition: rtpdec.h:115