Libav
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 Libav.
6  *
7  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
29 #include <string.h>
30 #include "libavutil/intreadwrite.h"
31 #include "avio_internal.h"
32 #include "rtp.h"
33 #include "rtpdec.h"
34 #include "rtpdec_formats.h"
35 
36 struct PayloadContext {
38  int64_t timestamp;
39 };
40 
43  AVStream *st, AVPacket *pkt,
44  uint32_t *timestamp,
45  const uint8_t *buf, int len, uint16_t seq,
46  int flags)
47 {
48  int config_packet, start_packet, end_packet;
49 
50  if (len < 2)
51  return AVERROR_INVALIDDATA;
52 
53  config_packet = buf[0] & 0x40;
54  start_packet = buf[0] & 0x20;
55  end_packet = buf[0] & 0x10;
56  buf += 2; // ignore buf[1]
57  len -= 2;
58 
59  if (config_packet) {
60 
62  st->codecpar->extradata_size = 0;
63 
64  if (len < 2 || !(st->codecpar->extradata =
66  return AVERROR_INVALIDDATA;
67 
68  st->codecpar->extradata_size = len + 8;
69  memcpy(st->codecpar->extradata, "SEQH", 4);
70  AV_WB32(st->codecpar->extradata + 4, len);
71  memcpy(st->codecpar->extradata + 8, buf, len);
72 
73  /* We set codec_id to AV_CODEC_ID_NONE initially to
74  * delay decoder initialization since extradata is
75  * carried within the RTP stream, not SDP. Here,
76  * by setting codec_id to AV_CODEC_ID_SVQ3, we are signalling
77  * to the decoder that it is OK to initialize. */
79 
80  return AVERROR(EAGAIN);
81  }
82 
83  if (start_packet) {
84  int res;
85 
87  if ((res = avio_open_dyn_buf(&sv->pktbuf)) < 0)
88  return res;
89  sv->timestamp = *timestamp;
90  }
91 
92  if (!sv->pktbuf)
93  return AVERROR_INVALIDDATA;
94 
95  avio_write(sv->pktbuf, buf, len);
96 
97  if (end_packet) {
98  int ret = ff_rtp_finalize_packet(pkt, &sv->pktbuf, st->index);
99  if (ret < 0)
100  return ret;
101 
102  *timestamp = sv->timestamp;
103  return 0;
104  }
105 
106  return AVERROR(EAGAIN);
107 }
108 
110 {
112 }
113 
115  .enc_name = "X-SV3V-ES",
116  .codec_type = AVMEDIA_TYPE_VIDEO,
117  .codec_id = AV_CODEC_ID_NONE, // see if (config_packet) above
118  .priv_data_size = sizeof(PayloadContext),
119  .close = svq3_close_context,
121 };
AVPacket pkt
Definition: rtpdec_qt.c:37
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:62
Bytestream IO Context.
Definition: avio.h:104
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
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:42
RTP/JPEG specific private data.
Definition: rdt.c:83
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3483
int index
stream index in AVFormatContext
Definition: avformat.h:706
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1143
#define AV_WB32(p, val)
Definition: intreadwrite.h:246
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:202
Format I/O context.
Definition: avformat.h:940
uint8_t
static int flags
Definition: log.c:50
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:221
uint32_t timestamp
current frame timestamp
Definition: rtpdec_ac3.c:31
#define AVERROR(e)
Definition: error.h:43
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3501
AVIOContext * pktbuf
Definition: rtpdec_asf.c:167
int64_t timestamp
Definition: rtpdec_svq3.c:38
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1183
Stream structure.
Definition: avformat.h:705
static void svq3_close_context(PayloadContext *sv)
Definition: rtpdec_svq3.c:109
uint8_t * buf
the temporary storage buffer
Definition: rtpdec_asf.c:168
const char * enc_name
Definition: rtpdec.h:116
RTPDynamicProtocolHandler ff_svq3_dynamic_handler
Definition: rtpdec_svq3.c:114
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:891
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:638
static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index)
Parse a packet, add all split parts to parse_queue.
Definition: utils.c:816
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3497
AVCodecParameters * codecpar
Definition: avformat.h:831
This structure stores compressed data.
Definition: avcodec.h:1323