annotate rtpdec_svq3.c @ 6400:6928d93146e6 libavformat

asfcrypt: fix unaligned read in ff_asfcrypt_dec()
author mru
date Mon, 23 Aug 2010 15:38:57 +0000
parents 491eea5c52d6
children 29e95ae56fa9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6208
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
1 /*
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
2 * Sorenson-3 (SVQ3/SV3V) payload for RTP
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
3 * Copyright (c) 2010 Ronald S. Bultje
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
4 *
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
5 * This file is part of FFmpeg.
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
6 *
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
11 *
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
15 * Lesser General Public License for more details.
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
16 *
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
20 */
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
21
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
22 /**
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
23 * @file
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
24 * @brief RTP support for the SV3V (SVQ3) payload
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
25 * (http://wiki.multimedia.cx/index.php?title=Sorenson_Video_3#Packetization)
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
26 * @author Ronald S. Bultje <rbultje@ronald.bitfreak.net>
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
27 */
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
28
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
29 #include <string.h>
6313
21797713c770 Include the correct header that actually is used, use quotes instead of angle brackets
mstorsjo
parents: 6256
diff changeset
30 #include "libavutil/intreadwrite.h"
6208
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
31 #include "rtp.h"
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
32 #include "rtpdec.h"
6339
491eea5c52d6 Remove mostly unnecessary rtpdec_*.h files, store the declarations in one file
mstorsjo
parents: 6313
diff changeset
33 #include "rtpdec_formats.h"
6208
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
34
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
35 struct PayloadContext {
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
36 ByteIOContext *pktbuf;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
37 int64_t timestamp;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
38 int is_keyframe;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
39 };
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
40
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
41 /** return 0 on packet, <0 on partial packet or error... */
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
42 static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv,
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
43 AVStream *st, AVPacket *pkt,
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
44 uint32_t *timestamp,
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
45 const uint8_t *buf, int len, int flags)
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
46 {
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
47 int config_packet, start_packet, end_packet;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
48
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
49 if (len < 2)
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
50 return AVERROR_INVALIDDATA;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
51
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
52 config_packet = buf[0] & 0x40;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
53 start_packet = buf[0] & 0x20;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
54 end_packet = buf[0] & 0x10;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
55 buf += 2; // ignore buf[1]
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
56 len -= 2;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
57
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
58 if (config_packet) {
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
59
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
60 av_freep(&st->codec->extradata);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
61 st->codec->extradata_size = 0;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
62
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
63 if (len < 2 || !(st->codec->extradata =
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
64 av_malloc(len + 8 + FF_INPUT_BUFFER_PADDING_SIZE)))
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
65 return AVERROR_INVALIDDATA;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
66
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
67 st->codec->extradata_size = len + 8;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
68 memcpy(st->codec->extradata, "SEQH", 4);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
69 AV_WB32(st->codec->extradata + 4, len);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
70 memcpy(st->codec->extradata + 8, buf, len);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
71
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
72 /* We set codec_id to CODEC_ID_NONE initially to
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
73 * delay decoder initialization since extradata is
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
74 * carried within the RTP stream, not SDP. Here,
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
75 * by setting codec_id to CODEC_ID_SVQ3, we are signalling
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
76 * to the decoder that it is OK to initialize. */
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
77 st->codec->codec_id = CODEC_ID_SVQ3;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
78
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
79 return AVERROR(EAGAIN);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
80 }
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
81
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
82 if (start_packet) {
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
83 int res;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
84
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
85 if (sv->pktbuf) {
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
86 uint8_t *tmp;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
87 url_close_dyn_buf(sv->pktbuf, &tmp);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
88 av_free(tmp);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
89 }
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
90 if ((res = url_open_dyn_buf(&sv->pktbuf)) < 0)
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
91 return res;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
92 sv->timestamp = *timestamp;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
93 sv->is_keyframe = flags & RTP_FLAG_KEY;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
94 }
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
95
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
96 if (!sv->pktbuf)
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
97 return AVERROR_INVALIDDATA;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
98
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
99 put_buffer(sv->pktbuf, buf, len);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
100
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
101 if (end_packet) {
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
102 av_init_packet(pkt);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
103 pkt->stream_index = st->index;
6256
c74a9b10ee6c rtpdec_svq3: Return the timestamp in *timestamp instead of pkt->pts
mstorsjo
parents: 6208
diff changeset
104 *timestamp = sv->timestamp;
6208
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
105 pkt->flags = sv->is_keyframe ? AV_PKT_FLAG_KEY : 0;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
106 pkt->size = url_close_dyn_buf(sv->pktbuf, &pkt->data);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
107 pkt->destruct = av_destruct_packet;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
108 sv->pktbuf = NULL;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
109 return 0;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
110 }
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
111
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
112 return AVERROR(EAGAIN);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
113 }
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
114
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
115 static PayloadContext *svq3_extradata_new(void)
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
116 {
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
117 return av_mallocz(sizeof(PayloadContext));
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
118 }
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
119
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
120 static void svq3_extradata_free(PayloadContext *sv)
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
121 {
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
122 if (sv->pktbuf) {
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
123 uint8_t *buf;
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
124 url_close_dyn_buf(sv->pktbuf, &buf);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
125 av_free(buf);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
126 }
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
127 av_free(sv);
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
128 }
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
129
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
130 RTPDynamicProtocolHandler ff_svq3_dynamic_handler = {
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
131 "X-SV3V-ES",
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
132 CODEC_TYPE_VIDEO,
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
133 CODEC_ID_NONE, // see if (config_packet) above
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
134 NULL, // parse sdp line
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
135 svq3_extradata_new,
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
136 svq3_extradata_free,
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
137 svq3_parse_packet,
209c43ef17af Add RTP depacketization of SVQ3
mstorsjo
parents:
diff changeset
138 };