FFmpeg
rtpdec_mpegts.c
Go to the documentation of this file.
1 /*
2  * RTP MPEG2TS depacketizer
3  * Copyright (c) 2003 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 "mpegts.h"
24 #include "rtpdec_formats.h"
25 
26 struct PayloadContext {
27  struct MpegTSContext *ts;
30  uint8_t buf[RTP_MAX_PACKET_LENGTH];
31 };
32 
34 {
35  if (!data)
36  return;
37  if (data->ts)
39 }
40 
41 static av_cold int mpegts_init(AVFormatContext *ctx, int st_index,
43 {
45  if (!data->ts)
46  return AVERROR(ENOMEM);
47  return 0;
48 }
49 
51  AVStream *st, AVPacket *pkt, uint32_t *timestamp,
52  const uint8_t *buf, int len, uint16_t seq,
53  int flags)
54 {
55  int ret;
56 
57  // We don't want to use the RTP timestamps at all. If the mpegts demuxer
58  // doesn't set any pts/dts, the generic rtpdec code shouldn't try to
59  // fill it in either, since the mpegts and RTP timestamps are in totally
60  // different ranges.
61  *timestamp = RTP_NOTS_VALUE;
62 
63  if (!buf) {
64  if (data->read_buf_index >= data->read_buf_size)
65  return AVERROR(EAGAIN);
66  ret = avpriv_mpegts_parse_packet(data->ts, pkt, data->buf + data->read_buf_index,
67  data->read_buf_size - data->read_buf_index);
68  if (ret < 0)
69  return AVERROR(EAGAIN);
70  data->read_buf_index += ret;
71  if (data->read_buf_index < data->read_buf_size)
72  return 1;
73  else
74  return 0;
75  }
76 
78  /* The only error that can be returned from avpriv_mpegts_parse_packet
79  * is "no more data to return from the provided buffer", so return
80  * AVERROR(EAGAIN) for all errors */
81  if (ret < 0)
82  return AVERROR(EAGAIN);
83  if (ret < len) {
84  data->read_buf_size = FFMIN(len - ret, sizeof(data->buf));
85  memcpy(data->buf, buf + ret, data->read_buf_size);
86  data->read_buf_index = 0;
87  return 1;
88  }
89  return 0;
90 }
91 
94  .priv_data_size = sizeof(PayloadContext),
96  .init = mpegts_init,
97  .close = mpegts_close_context,
98  .static_payload_id = 33,
99 };
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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. Frame references ownership and permissions
mpegts.h
avpriv_mpegts_parse_packet
int avpriv_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, const uint8_t *buf, int len)
Definition: mpegts.c:3396
rtpdec_formats.h
data
const char data[16]
Definition: mxf.c:143
mpegts_init
static av_cold int mpegts_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
Definition: rtpdec_mpegts.c:41
init
static int init
Definition: av_tx.c:47
PayloadContext::read_buf_index
int read_buf_index
Definition: rtpdec_mpegts.c:28
avpriv_mpegts_parse_close
void avpriv_mpegts_parse_close(MpegTSContext *ts)
Definition: mpegts.c:3421
pkt
AVPacket * pkt
Definition: movenc.c:59
av_cold
#define av_cold
Definition: attributes.h:90
RTP_NOTS_VALUE
#define RTP_NOTS_VALUE
Definition: rtpdec.h:41
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
AVFormatContext
Format I/O context.
Definition: avformat.h:1213
MpegTSContext
Definition: mpegts.c:129
attributes.h
PayloadContext::read_buf_size
int read_buf_size
Definition: rtpdec_mpegts.c:29
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
len
int len
Definition: vorbis_enc_data.h:426
ff_mpegts_dynamic_handler
const RTPDynamicProtocolHandler ff_mpegts_dynamic_handler
Definition: rtpdec_mpegts.c:92
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:948
RTP_MAX_PACKET_LENGTH
#define RTP_MAX_PACKET_LENGTH
Definition: rtpdec.h:37
PayloadContext::buf
uint8_t * buf
the temporary storage buffer
Definition: rtpdec_asf.c:183
RTPDynamicProtocolHandler::codec_type
enum AVMediaType codec_type
Definition: rtpdec.h:118
mpegts_handle_packet
static int mpegts_handle_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_mpegts.c:50
avpriv_mpegts_parse_open
MpegTSContext * avpriv_mpegts_parse_open(AVFormatContext *s)
Definition: mpegts.c:3374
parse_packet
static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index, int flush)
Parse a packet, add all split parts to parse_queue.
Definition: demux.c:1118
AVPacket
This structure stores compressed data.
Definition: packet.h:351
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
PayloadContext
RTP/JPEG specific private data.
Definition: rdt.c:83
mpegts_close_context
static void mpegts_close_context(PayloadContext *data)
Definition: rtpdec_mpegts.c:33
PayloadContext::ts
struct MpegTSContext * ts
Definition: rtpdec_mpegts.c:27
RTPDynamicProtocolHandler
Definition: rtpdec.h:116