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 "rtp.h"
32 #include "rtpdec.h"
33 #include "rtpdec_formats.h"
34 
35 struct PayloadContext {
37  int64_t timestamp;
38 };
39 
40 /** return 0 on packet, <0 on partial packet or error... */
42  AVStream *st, AVPacket *pkt,
43  uint32_t *timestamp,
44  const uint8_t *buf, int len, uint16_t seq,
45  int flags)
46 {
47  int config_packet, start_packet, end_packet;
48 
49  if (len < 2)
50  return AVERROR_INVALIDDATA;
51 
52  config_packet = buf[0] & 0x40;
53  start_packet = buf[0] & 0x20;
54  end_packet = buf[0] & 0x10;
55  buf += 2; // ignore buf[1]
56  len -= 2;
57 
58  if (config_packet) {
59 
60  av_freep(&st->codec->extradata);
61  st->codec->extradata_size = 0;
62 
63  if (len < 2 || !(st->codec->extradata =
65  return AVERROR_INVALIDDATA;
66 
67  st->codec->extradata_size = len + 8;
68  memcpy(st->codec->extradata, "SEQH", 4);
69  AV_WB32(st->codec->extradata + 4, len);
70  memcpy(st->codec->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 
85  if (sv->pktbuf) {
86  uint8_t *tmp;
87  avio_close_dyn_buf(sv->pktbuf, &tmp);
88  av_free(tmp);
89  }
90  if ((res = avio_open_dyn_buf(&sv->pktbuf)) < 0)
91  return res;
92  sv->timestamp = *timestamp;
93  }
94 
95  if (!sv->pktbuf)
96  return AVERROR_INVALIDDATA;
97 
98  avio_write(sv->pktbuf, buf, len);
99 
100  if (end_packet) {
101  int ret = ff_rtp_finalize_packet(pkt, &sv->pktbuf, st->index);
102  if (ret < 0)
103  return ret;
104 
105  *timestamp = sv->timestamp;
106  return 0;
107  }
108 
109  return AVERROR(EAGAIN);
110 }
111 
113 {
114  return av_mallocz(sizeof(PayloadContext));
115 }
116 
118 {
119  if (sv->pktbuf) {
120  uint8_t *buf;
121  avio_close_dyn_buf(sv->pktbuf, &buf);
122  av_free(buf);
123  }
124  av_free(sv);
125 }
126 
128  .enc_name = "X-SV3V-ES",
129  .codec_type = AVMEDIA_TYPE_VIDEO,
130  .codec_id = AV_CODEC_ID_NONE, // see if (config_packet) above
131  .alloc = svq3_extradata_new,
132  .free = svq3_extradata_free,
133  .parse_packet = svq3_parse_packet,
134 };
AVPacket pkt
Definition: rtpdec_qt.c:37
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:988
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:41
RTP/JPEG specific private data.
Definition: rdt.c:83
int index
stream index in AVFormatContext
Definition: avformat.h:644
uint8_t * buf
the temporary storage buffer
Definition: rtpdec_asf.c:160
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:976
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
Format I/O context.
Definition: avformat.h:944
#define AV_WB32(p, darg)
Definition: intreadwrite.h:265
uint8_t
static void svq3_extradata_free(PayloadContext *sv)
Definition: rtpdec_svq3.c:117
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:173
uint32_t timestamp
current frame timestamp
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
AVIOContext * pktbuf
Definition: rtpdec_asf.c:159
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int64_t timestamp
Definition: rtpdec_svq3.c:37
ret
Definition: avfilter.c:821
Stream structure.
Definition: avformat.h:643
enum AVCodecID codec_id
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
const char enc_name[50]
Definition: rtpdec.h:120
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
RTPDynamicProtocolHandler ff_svq3_dynamic_handler
Definition: rtpdec_svq3.c:127
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:865
This structure stores compressed data.
static PayloadContext * svq3_extradata_new(void)
Definition: rtpdec_svq3.c:112