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 "rtpdec_formats.h"
23 #include "libavutil/intreadwrite.h"
24 
25 static int mpeg_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
26 {
27  if (st_index < 0)
28  return 0;
29  ctx->streams[st_index]->need_parsing = AVSTREAM_PARSE_FULL;
30  return 0;
31 }
32 
34  AVStream *st, AVPacket *pkt, uint32_t *timestamp,
35  const uint8_t *buf, int len, uint16_t seq,
36  int flags)
37 {
38  unsigned int h;
39  if (len <= 4)
40  return AVERROR_INVALIDDATA;
41  h = AV_RB32(buf);
42  buf += 4;
43  len -= 4;
44  if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && h & (1 << 26)) {
45  /* MPEG-2 */
46  if (len <= 4)
47  return AVERROR_INVALIDDATA;
48  buf += 4;
49  len -= 4;
50  }
51  if (av_new_packet(pkt, len) < 0)
52  return AVERROR(ENOMEM);
53  memcpy(pkt->data, buf, len);
54  pkt->stream_index = st->index;
55  return 0;
56 }
57 
60  .codec_id = AV_CODEC_ID_MP3,
61  .init = mpeg_init,
62  .parse_packet = mpeg_parse_packet,
63  .static_payload_id = 14,
64 };
65 
68  .codec_id = AV_CODEC_ID_MPEG2VIDEO,
69  .init = mpeg_init,
70  .parse_packet = mpeg_parse_packet,
71  .static_payload_id = 32,
72 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
RTP/JPEG specific private data.
Definition: rdt.c:83
int index
stream index in AVFormatContext
Definition: avformat.h:644
enum AVMediaType codec_type
Definition: rtpdec.h:121
Format I/O context.
Definition: avformat.h:944
RTPDynamicProtocolHandler ff_mpeg_audio_dynamic_handler
Definition: rtpdec_mpeg12.c:58
uint8_t
#define AV_RB32
static AVPacket pkt
Definition: demuxing.c:56
enum AVStreamParseType need_parsing
Definition: avformat.h:811
AVStream ** streams
Definition: avformat.h:992
uint8_t * data
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:73
Spectrum Plot time data
preferred ID for decoding MPEG audio layer 1, 2 or 3
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:33
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
preferred ID for MPEG-1/2 video decoding
Stream structure.
Definition: avformat.h:643
enum AVMediaType codec_type
void * buf
Definition: avisynth_c.h:594
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
static int flags
Definition: cpu.c:23
full parsing and repack
Definition: avformat.h:582
static int mpeg_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
Definition: rtpdec_mpeg12.c:25
int len
RTPDynamicProtocolHandler ff_mpeg_video_dynamic_handler
Definition: rtpdec_mpeg12.c:66
This structure stores compressed data.