FFmpeg
Loading...
Searching...
No Matches
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>
31#include "avio_internal.h"
32#include "internal.h"
33#include "rtp.h"
34#include "rtpdec.h"
35#include "rtpdec_formats.h"
36
37struct PayloadContext {
38 AVIOContext *pktbuf;
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)
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 if (len < 2 || ff_alloc_extradata(st->codecpar, len + 8))
63
64 memcpy(st->codecpar->extradata, "SEQH", 4);
65 AV_WB32(st->codecpar->extradata + 4, len);
66 memcpy(st->codecpar->extradata + 8, buf, len);
67
68 /* We set codec_id to AV_CODEC_ID_NONE initially to
69 * delay decoder initialization since extradata is
70 * carried within the RTP stream, not SDP. Here,
71 * by setting codec_id to AV_CODEC_ID_SVQ3, we are signalling
72 * to the decoder that it is OK to initialize. */
74
75 return AVERROR(EAGAIN);
76 }
77
78 if (start_packet) {
79 int res;
80
82 if ((res = avio_open_dyn_buf(&sv->pktbuf)) < 0)
83 return res;
84 sv->timestamp = *timestamp;
85 }
86
87 if (!sv->pktbuf)
89
90 avio_write(sv->pktbuf, buf, len);
91
92 if (end_packet) {
93 int ret = ff_rtp_finalize_packet(pkt, &sv->pktbuf, st->index);
94 if (ret < 0)
95 return ret;
96
97 *timestamp = sv->timestamp;
98 return 0;
99 }
100
101 return AVERROR(EAGAIN);
102}
103
105{
107}
108
110 .enc_name = "X-SV3V-ES",
111 .codec_type = AVMEDIA_TYPE_VIDEO,
112 .codec_id = AV_CODEC_ID_NONE, // see if (config_packet) above
113 .priv_data_size = sizeof(PayloadContext),
116};
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition aviobuf.c:206
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition aviobuf.c:1365
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition aviobuf.c:1438
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define s(width, name)
Definition cbs_vp9.c:198
long long int64_t
Definition coverity.c:34
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:1178
static AVPacket * pkt
@ AV_CODEC_ID_SVQ3
Definition codec_id.h:73
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_WB32(p, v)
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:237
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:983
const RTPDynamicProtocolHandler ff_svq3_dynamic_handler
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
static void svq3_close_context(PayloadContext *sv)
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
Format I/O context.
Definition avformat.h:1333
This structure stores compressed data.
Definition packet.h:580
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int index
stream index in AVFormatContext
Definition avformat.h:772
RTP/AV1 specific private data.
Definition rdt.c:85
uint32_t timestamp
last received timestamp for frame
Definition rtpdec_ac3.c:31
AVIOContext * pktbuf
Definition rtpdec_asf.c:187
int len