FFmpeg
rtpdec_svq3.c
Go to the documentation of this file.
1 /*
2  * Sorenson-3 (SVQ3/SV3V) payload for RTP
3  * Copyright (c) 2010 Ronald S. Bultje
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 /**
23  * @file
24  * @brief RTP support for the SV3V (SVQ3) payload
25  * @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
26  * @see http://wiki.multimedia.cx/index.php?title=Sorenson_Video_3#Packetization
27  */
28 
29 #include <string.h>
30 #include "libavutil/intreadwrite.h"
31 #include "avio_internal.h"
32 #include "internal.h"
33 #include "rtp.h"
34 #include "rtpdec.h"
35 #include "rtpdec_formats.h"
36 
37 struct PayloadContext {
39  int64_t timestamp;
40 };
41 
42 /** return 0 on packet, <0 on partial packet or error... */
44  AVStream *st, AVPacket *pkt,
45  uint32_t *timestamp,
46  const uint8_t *buf, int len, uint16_t seq,
47  int flags)
48 {
49  int config_packet, start_packet, end_packet;
50 
51  if (len < 2)
52  return AVERROR_INVALIDDATA;
53 
54  config_packet = buf[0] & 0x40;
55  start_packet = buf[0] & 0x20;
56  end_packet = buf[0] & 0x10;
57  buf += 2; // ignore buf[1]
58  len -= 2;
59 
60  if (config_packet) {
61 
63  st->codecpar->extradata_size = 0;
64 
65  if (len < 2 || ff_alloc_extradata(st->codecpar, len + 8))
66  return AVERROR_INVALIDDATA;
67 
68  memcpy(st->codecpar->extradata, "SEQH", 4);
69  AV_WB32(st->codecpar->extradata + 4, len);
70  memcpy(st->codecpar->extradata + 8, buf, len);
71 
72  /* We set codec_id to AV_CODEC_ID_NONE initially to
73  * delay decoder initialization since extradata is
74  * carried within the RTP stream, not SDP. Here,
75  * by setting codec_id to AV_CODEC_ID_SVQ3, we are signalling
76  * to the decoder that it is OK to initialize. */
78 
79  return AVERROR(EAGAIN);
80  }
81 
82  if (start_packet) {
83  int res;
84 
86  if ((res = avio_open_dyn_buf(&sv->pktbuf)) < 0)
87  return res;
88  sv->timestamp = *timestamp;
89  }
90 
91  if (!sv->pktbuf)
92  return AVERROR_INVALIDDATA;
93 
94  avio_write(sv->pktbuf, buf, len);
95 
96  if (end_packet) {
97  int ret = ff_rtp_finalize_packet(pkt, &sv->pktbuf, st->index);
98  if (ret < 0)
99  return ret;
100 
101  *timestamp = sv->timestamp;
102  return 0;
103  }
104 
105  return AVERROR(EAGAIN);
106 }
107 
109 {
111 }
112 
114  .enc_name = "X-SV3V-ES",
115  .codec_type = AVMEDIA_TYPE_VIDEO,
116  .codec_id = AV_CODEC_ID_NONE, // see if (config_packet) above
117  .priv_data_size = sizeof(PayloadContext),
118  .close = svq3_close_context,
120 };
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3971
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
parse_packet
static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index)
Parse a packet, add all split parts to parse_queue.
Definition: utils.c:1451
svq3_close_context
static void svq3_close_context(PayloadContext *sv)
Definition: rtpdec_svq3.c:108
PayloadContext::timestamp
int64_t timestamp
Definition: rtpdec_svq3.c:39
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:927
PayloadContext::timestamp
uint32_t timestamp
current frame timestamp
Definition: rtpdec_ac3.c:31
RTPDynamicProtocolHandler::enc_name
const char * enc_name
Definition: rtpdec.h:116
PayloadContext::pktbuf
AVIOContext * pktbuf
Definition: rtpdec_asf.c:182
buf
void * buf
Definition: avisynth_c.h:766
ff_svq3_dynamic_handler
const RTPDynamicProtocolHandler ff_svq3_dynamic_handler
Definition: rtpdec_svq3.c:113
avio_open_dyn_buf
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1386
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_CODEC_ID_SVQ3
@ AV_CODEC_ID_SVQ3
Definition: avcodec.h:241
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1017
svq3_parse_packet
static int svq3_parse_packet(AVFormatContext *s, PayloadContext *sv, AVStream *st, AVPacket *pkt, uint32_t *timestamp, const uint8_t *buf, int len, uint16_t seq, int flags)
return 0 on packet, <0 on partial packet or error...
Definition: rtpdec_svq3.c:43
rtpdec.h
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3975
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:419
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:218
rtp.h
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: avcodec.h:216
avio_internal.h
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:1445
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:870
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:871
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3957
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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
PayloadContext
RTP/JPEG specific private data.
Definition: rdt.c:83
RTPDynamicProtocolHandler
Definition: rtpdec.h:115
ff_alloc_extradata
int ff_alloc_extradata(AVCodecParameters *par, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0.
Definition: utils.c:3309