FFmpeg
rtpdec_dv.c
Go to the documentation of this file.
1 /*
2  * RTP parser for DV payload format (RFC 6469)
3  * Copyright (c) 2015 Thomas Volkert <thomas@homer-conferencing.com>
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/avstring.h"
23 
24 #include "libavcodec/bytestream.h"
25 
26 #include "avio_internal.h"
27 #include "rtpdec_formats.h"
28 
29 struct PayloadContext {
31  uint32_t timestamp;
33 };
34 
36 {
37  ffio_free_dyn_buf(&data->buf);
38 }
39 
41  AVStream *stream,
42  PayloadContext *dv_data,
43  const char *attr, const char *value)
44 {
45  /* does the DV stream include audio? */
46  if (!strcmp(attr, "audio") && !strcmp(value, "bundled"))
47  dv_data->bundled_audio = 1;
48 
49  /* extract the DV profile */
50  if (!strcmp(attr, "encode")) {
51  /* SD-VCR/525-60 */
52  /* SD-VCR/625-50 */
53  /* HD-VCR/1125-60 */
54  /* HD-VCR/1250-50 */
55  /* SDL-VCR/525-60 */
56  /* SDL-VCR/625-50 */
57  /* 314M-25/525-60 */
58  /* 314M-25/625-50 */
59  /* 314M-50/525-60 */
60  /* 314M-50/625-50 */
61  /* 370M/1080-60i */
62  /* 370M/1080-50i */
63  /* 370M/720-60p */
64  /* 370M/720-50p */
65  /* 306M/525-60 (for backward compatibility) */
66  /* 306M/625-50 (for backward compatibility) */
67  }
68 
69  return 0;
70 }
71 
72 static av_cold int dv_parse_sdp_line(AVFormatContext *ctx, int st_index,
73  PayloadContext *dv_data, const char *line)
74 {
75  AVStream *current_stream;
76  const char *sdp_line_ptr = line;
77 
78  if (st_index < 0)
79  return 0;
80 
81  current_stream = ctx->streams[st_index];
82 
83  if (av_strstart(sdp_line_ptr, "fmtp:", &sdp_line_ptr)) {
84  return ff_parse_fmtp(ctx, current_stream, dv_data, sdp_line_ptr,
86  }
87 
88  return 0;
89 }
90 
92  AVStream *st, AVPacket *pkt, uint32_t *timestamp,
93  const uint8_t *buf, int len, uint16_t seq,
94  int flags)
95 {
96  int res = 0;
97 
98  /* drop data of previous packets in case of non-continuous (lossy) packet stream */
99  if (rtp_dv_ctx->buf && rtp_dv_ctx->timestamp != *timestamp) {
100  ffio_free_dyn_buf(&rtp_dv_ctx->buf);
101  }
102 
103  /* sanity check for size of input packet: 1 byte payload at least */
104  if (len < 1) {
105  av_log(ctx, AV_LOG_ERROR, "Too short RTP/DV packet, got %d bytes\n", len);
106  return AVERROR_INVALIDDATA;
107  }
108 
109  /* start frame buffering with new dynamic buffer */
110  if (!rtp_dv_ctx->buf) {
111  res = avio_open_dyn_buf(&rtp_dv_ctx->buf);
112  if (res < 0)
113  return res;
114  /* update the timestamp in the frame packet with the one from the RTP packet */
115  rtp_dv_ctx->timestamp = *timestamp;
116  }
117 
118  /* write the fragment to the dyn. buffer */
119  avio_write(rtp_dv_ctx->buf, buf, len);
120 
121  /* RTP marker bit means: last fragment of current frame was received;
122  otherwise, an additional fragment is needed for the current frame */
123  if (!(flags & RTP_FLAG_MARKER))
124  return AVERROR(EAGAIN);
125 
126  /* close frame buffering and create resulting A/V packet */
127  res = ff_rtp_finalize_packet(pkt, &rtp_dv_ctx->buf, st->index);
128  if (res < 0)
129  return res;
130 
131  return 0;
132 }
133 
135  .enc_name = "DV",
136  .codec_type = AVMEDIA_TYPE_VIDEO,
137  .codec_id = AV_CODEC_ID_DVVIDEO,
138  .need_parsing = AVSTREAM_PARSE_FULL,
139  .parse_sdp_a_line = dv_parse_sdp_line,
140  .priv_data_size = sizeof(PayloadContext),
141  .close = dv_close_context,
143 };
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
rtpdec_formats.h
ff_parse_fmtp
int ff_parse_fmtp(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *p, int(*parse_fmtp)(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *attr, const char *value))
Definition: rtpdec.c:887
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1403
dv_handle_packet
static int dv_handle_packet(AVFormatContext *ctx, PayloadContext *rtp_dv_ctx, AVStream *st, AVPacket *pkt, uint32_t *timestamp, const uint8_t *buf, int len, uint16_t seq, int flags)
Definition: rtpdec_dv.c:91
RTP_FLAG_MARKER
#define RTP_FLAG_MARKER
RTP marker bit was set for this packet.
Definition: rtpdec.h:93
data
const char data[16]
Definition: mxf.c:91
ff_rtp_finalize_packet
int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx)
Close the dynamic buffer and make a packet from it.
Definition: rtpdec.c:925
PayloadContext::timestamp
uint32_t timestamp
current frame timestamp
Definition: rtpdec_ac3.c:31
RTPDynamicProtocolHandler::enc_name
const char * enc_name
Definition: rtpdec.h:116
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_cold
#define av_cold
Definition: attributes.h:90
avio_open_dyn_buf
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1356
s
#define s(width, name)
Definition: cbs_vp9.c:257
ff_dv_dynamic_handler
const RTPDynamicProtocolHandler ff_dv_dynamic_handler
Definition: rtpdec_dv.c:134
ctx
AVFormatContext * ctx
Definition: movenc.c:48
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: utils.c:1449
AVFormatContext
Format I/O context.
Definition: avformat.h:1335
PayloadContext::buf
AVIOContext * buf
Definition: rtpdec_dv.c:30
dv_parse_sdp_line
static av_cold int dv_parse_sdp_line(AVFormatContext *ctx, int st_index, PayloadContext *dv_data, const char *line)
Definition: rtpdec_dv.c:72
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:213
line
Definition: graph2dot.c:48
av_strstart
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition: avstring.c:34
avio_internal.h
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AV_CODEC_ID_DVVIDEO
@ AV_CODEC_ID_DVVIDEO
Definition: codec_id.h:73
uint8_t
uint8_t
Definition: audio_convert.c:194
len
int len
Definition: vorbis_enc_data.h:452
ffio_free_dyn_buf
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1431
AVStream
Stream structure.
Definition: avformat.h:865
dv_close_context
static av_cold void dv_close_context(PayloadContext *data)
Definition: rtpdec_dv.c:35
PayloadContext::bundled_audio
int bundled_audio
Definition: rtpdec_dv.c:32
PayloadContext::buf
uint8_t * buf
the temporary storage buffer
Definition: rtpdec_asf.c:183
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:866
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
dv_sdp_parse_fmtp_config
static av_cold int dv_sdp_parse_fmtp_config(AVFormatContext *s, AVStream *stream, PayloadContext *dv_data, const char *attr, const char *value)
Definition: rtpdec_dv.c:40
AVPacket
This structure stores compressed data.
Definition: packet.h:332
bytestream.h
AVSTREAM_PARSE_FULL
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:786
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
avstring.h
PayloadContext
RTP/JPEG specific private data.
Definition: rdt.c:83
line
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
Definition: swscale.txt:40
RTPDynamicProtocolHandler
Definition: rtpdec.h:115