Patch by Josh Allmann, joshua dot allmann at gmail
Originally committed as revision 24798 to svn://svn.ffmpeg.org/ffmpeg/trunk
... | ... |
@@ -23,7 +23,7 @@ |
23 | 23 |
|
24 | 24 |
#define LIBAVFORMAT_VERSION_MAJOR 52 |
25 | 25 |
#define LIBAVFORMAT_VERSION_MINOR 78 |
26 |
-#define LIBAVFORMAT_VERSION_MICRO 2 |
|
26 |
+#define LIBAVFORMAT_VERSION_MICRO 3 |
|
27 | 27 |
|
28 | 28 |
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |
29 | 29 |
LIBAVFORMAT_VERSION_MINOR, \ |
... | ... |
@@ -66,6 +66,7 @@ void av_register_rtp_dynamic_payload_handlers(void) |
66 | 66 |
ff_register_dynamic_payload_handler(&ff_qdm2_dynamic_handler); |
67 | 67 |
ff_register_dynamic_payload_handler(&ff_svq3_dynamic_handler); |
68 | 68 |
ff_register_dynamic_payload_handler(&ff_mp4a_latm_dynamic_handler); |
69 |
+ ff_register_dynamic_payload_handler(&ff_vp8_dynamic_handler); |
|
69 | 70 |
|
70 | 71 |
ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfv_handler); |
71 | 72 |
ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfa_handler); |
... | ... |
@@ -45,5 +45,6 @@ extern RTPDynamicProtocolHandler ff_qdm2_dynamic_handler; |
45 | 45 |
extern RTPDynamicProtocolHandler ff_svq3_dynamic_handler; |
46 | 46 |
extern RTPDynamicProtocolHandler ff_theora_dynamic_handler; |
47 | 47 |
extern RTPDynamicProtocolHandler ff_vorbis_dynamic_handler; |
48 |
+extern RTPDynamicProtocolHandler ff_vp8_dynamic_handler; |
|
48 | 49 |
|
49 | 50 |
#endif /* AVFORMAT_RTPDEC_FORMATS_H */ |
50 | 51 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,153 @@ |
0 |
+/* |
|
1 |
+ * RTP VP8 Depacketizer |
|
2 |
+ * Copyright (c) 2010 Josh Allmann |
|
3 |
+ * |
|
4 |
+ * This file is part of FFmpeg. |
|
5 |
+ * |
|
6 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
7 |
+ * modify it under the terms of the GNU Lesser General Public |
|
8 |
+ * License as published by the Free Software Foundation; either |
|
9 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
10 |
+ * |
|
11 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
12 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
+ * Lesser General Public License for more details. |
|
15 |
+ * |
|
16 |
+ * You should have received a copy of the GNU Lesser General Public |
|
17 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
18 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
19 |
+ */ |
|
20 |
+ |
|
21 |
+/** |
|
22 |
+ * @file |
|
23 |
+ * @brief RTP support for the VP8 payload |
|
24 |
+ * @author Josh Allmann <joshua.allmann@gmail.com> |
|
25 |
+ * ( http://www.webmproject.org/code/specs/rtp/ ) |
|
26 |
+ */ |
|
27 |
+ |
|
28 |
+#include "libavcodec/bytestream.h" |
|
29 |
+ |
|
30 |
+#include "rtpdec_formats.h" |
|
31 |
+ |
|
32 |
+struct PayloadContext { |
|
33 |
+ ByteIOContext *data; |
|
34 |
+ uint32_t timestamp; |
|
35 |
+ int is_keyframe; |
|
36 |
+}; |
|
37 |
+ |
|
38 |
+static void prepare_packet(AVPacket *pkt, PayloadContext *vp8, int stream) |
|
39 |
+{ |
|
40 |
+ av_init_packet(pkt); |
|
41 |
+ pkt->stream_index = stream; |
|
42 |
+ pkt->flags = vp8->is_keyframe ? AV_PKT_FLAG_KEY : 0; |
|
43 |
+ pkt->size = url_close_dyn_buf(vp8->data, &pkt->data); |
|
44 |
+ pkt->destruct = av_destruct_packet; |
|
45 |
+ vp8->data = NULL; |
|
46 |
+} |
|
47 |
+ |
|
48 |
+static int vp8_handle_packet(AVFormatContext *ctx, |
|
49 |
+ PayloadContext *vp8, |
|
50 |
+ AVStream *st, |
|
51 |
+ AVPacket *pkt, |
|
52 |
+ uint32_t *timestamp, |
|
53 |
+ const uint8_t *buf, |
|
54 |
+ int len, int flags) |
|
55 |
+{ |
|
56 |
+ int start_packet, end_packet, has_au, ret = AVERROR(EAGAIN); |
|
57 |
+ |
|
58 |
+ if (!buf) { |
|
59 |
+ // only called when vp8_handle_packet returns 1 |
|
60 |
+ if (!vp8->data) { |
|
61 |
+ av_log(ctx, AV_LOG_ERROR, "Invalid VP8 data passed\n"); |
|
62 |
+ return AVERROR_INVALIDDATA; |
|
63 |
+ } |
|
64 |
+ prepare_packet(pkt, vp8, st->index); |
|
65 |
+ *timestamp = vp8->timestamp; |
|
66 |
+ return 0; |
|
67 |
+ } |
|
68 |
+ |
|
69 |
+ start_packet = *buf & 1; |
|
70 |
+ end_packet = flags & RTP_FLAG_MARKER; |
|
71 |
+ has_au = *buf & 2; |
|
72 |
+ buf++; |
|
73 |
+ len--; |
|
74 |
+ |
|
75 |
+ if (start_packet) { |
|
76 |
+ int res; |
|
77 |
+ uint32_t ts = *timestamp; |
|
78 |
+ if (vp8->data) { |
|
79 |
+ // missing end marker; return old frame anyway. untested |
|
80 |
+ prepare_packet(pkt, vp8, st->index); |
|
81 |
+ *timestamp = vp8->timestamp; // reset timestamp from old frame |
|
82 |
+ |
|
83 |
+ // if current frame fits into one rtp packet, need to hold |
|
84 |
+ // that for the next av_get_packet call |
|
85 |
+ ret = end_packet ? 1 : 0; |
|
86 |
+ } |
|
87 |
+ if ((res = url_open_dyn_buf(&vp8->data)) < 0) |
|
88 |
+ return res; |
|
89 |
+ vp8->is_keyframe = *buf & 1; |
|
90 |
+ vp8->timestamp = ts; |
|
91 |
+ } |
|
92 |
+ |
|
93 |
+ if (!vp8->data || vp8->timestamp != *timestamp && ret == AVERROR(EAGAIN)) { |
|
94 |
+ av_log(ctx, AV_LOG_WARNING, |
|
95 |
+ "Received no start marker; dropping frame\n"); |
|
96 |
+ return AVERROR(EAGAIN); |
|
97 |
+ } |
|
98 |
+ |
|
99 |
+ // cycle through VP8AU headers if needed |
|
100 |
+ // not tested with actual VP8AUs |
|
101 |
+ while (len) { |
|
102 |
+ int au_len = len; |
|
103 |
+ if (has_au && len > 2) { |
|
104 |
+ au_len = AV_RB16(buf); |
|
105 |
+ buf += 2; |
|
106 |
+ len -= 2; |
|
107 |
+ if (buf + au_len > buf + len) { |
|
108 |
+ av_log(ctx, AV_LOG_ERROR, "Invalid VP8AU length\n"); |
|
109 |
+ return AVERROR_INVALIDDATA; |
|
110 |
+ } |
|
111 |
+ } |
|
112 |
+ |
|
113 |
+ put_buffer(vp8->data, buf, au_len); |
|
114 |
+ buf += au_len; |
|
115 |
+ len -= au_len; |
|
116 |
+ } |
|
117 |
+ |
|
118 |
+ if (ret != AVERROR(EAGAIN)) // did we miss a end marker? |
|
119 |
+ return ret; |
|
120 |
+ |
|
121 |
+ if (end_packet) { |
|
122 |
+ prepare_packet(pkt, vp8, st->index); |
|
123 |
+ return 0; |
|
124 |
+ } |
|
125 |
+ |
|
126 |
+ return AVERROR(EAGAIN); |
|
127 |
+} |
|
128 |
+ |
|
129 |
+static PayloadContext *vp8_new_context(void) |
|
130 |
+{ |
|
131 |
+ av_log(NULL, AV_LOG_WARNING, "RTP VP8 payload is still experimental\n"); |
|
132 |
+ return av_mallocz(sizeof(PayloadContext)); |
|
133 |
+} |
|
134 |
+ |
|
135 |
+static void vp8_free_context(PayloadContext *vp8) |
|
136 |
+{ |
|
137 |
+ if (vp8->data) { |
|
138 |
+ uint8_t *tmp; |
|
139 |
+ url_close_dyn_buf(vp8->data, &tmp); |
|
140 |
+ av_free(tmp); |
|
141 |
+ } |
|
142 |
+ av_free(vp8); |
|
143 |
+} |
|
144 |
+ |
|
145 |
+RTPDynamicProtocolHandler ff_vp8_dynamic_handler = { |
|
146 |
+ .enc_name = "VP8", |
|
147 |
+ .codec_type = AVMEDIA_TYPE_VIDEO, |
|
148 |
+ .codec_id = CODEC_ID_VP8, |
|
149 |
+ .open = vp8_new_context, |
|
150 |
+ .close = vp8_free_context, |
|
151 |
+ .parse_packet = vp8_handle_packet, |
|
152 |
+}; |