3 * Copyright (c) 2010 Josh Allmann
4 * Copyright (c) 2012 Martin Storsjo
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * @brief RTP support for the VP8 payload
26 * @author Josh Allmann <joshua.allmann@gmail.com>
27 * @see http://tools.ietf.org/html/draft-ietf-payload-vp8-05
30 #include "libavcodec/bytestream.h"
32 #include "rtpdec_formats.h"
34 struct PayloadContext {
39 static int vp8_handle_packet(AVFormatContext *ctx,
47 int start_partition, end_packet;
48 int extended_bits, part_id;
49 int pictureid_present = 0, tl0picidx_present = 0, tid_present = 0,
53 return AVERROR_INVALIDDATA;
55 extended_bits = buf[0] & 0x80;
56 start_partition = buf[0] & 0x10;
57 part_id = buf[0] & 0x0f;
58 end_packet = flags & RTP_FLAG_MARKER;
63 return AVERROR_INVALIDDATA;
64 pictureid_present = buf[0] & 0x80;
65 tl0picidx_present = buf[0] & 0x40;
66 tid_present = buf[0] & 0x20;
67 keyidx_present = buf[0] & 0x10;
71 if (pictureid_present) {
74 return AVERROR_INVALIDDATA;
75 size = buf[0] & 0x80 ? 2 : 1;
79 if (tl0picidx_present) {
80 // Ignoring temporal level zero index
84 if (tid_present || keyidx_present) {
85 // Ignoring temporal layer index, layer sync bit and keyframe index
90 return AVERROR_INVALIDDATA;
92 if (start_partition && part_id == 0) {
96 avio_close_dyn_buf(vp8->data, &tmp);
100 if ((res = avio_open_dyn_buf(&vp8->data)) < 0)
102 vp8->timestamp = *timestamp;
105 if (!vp8->data || vp8->timestamp != *timestamp) {
106 av_log(ctx, AV_LOG_WARNING,
107 "Received no start marker; dropping frame\n");
108 return AVERROR(EAGAIN);
111 avio_write(vp8->data, buf, len);
114 int ret = ff_rtp_finalize_packet(pkt, &vp8->data, st->index);
120 return AVERROR(EAGAIN);
123 static PayloadContext *vp8_new_context(void)
125 return av_mallocz(sizeof(PayloadContext));
128 static void vp8_free_context(PayloadContext *vp8)
132 avio_close_dyn_buf(vp8->data, &tmp);
138 RTPDynamicProtocolHandler ff_vp8_dynamic_handler = {
140 .codec_type = AVMEDIA_TYPE_VIDEO,
141 .codec_id = AV_CODEC_ID_VP8,
142 .alloc = vp8_new_context,
143 .free = vp8_free_context,
144 .parse_packet = vp8_handle_packet,