diff --git a/Changelog b/Changelog index 7c0413c464d4d373b27c8fcbbe76ba6230f13c8a..eb457413f9a07d4bbfeabcb844ff10cc1dc4dab0 100644 --- a/Changelog +++ b/Changelog @@ -29,6 +29,7 @@ version : - ffprobe -show_packets option added - RTP packetization of Theora and Vorbis - RTP depacketization of MP4A-LATM +- RTP packetization and depacketization of VP8 version 0.6: diff --git a/libavformat/Makefile b/libavformat/Makefile index 09cfe8b361d9195211efa979014563fa74841206..b355f18d3ebfac4e6ed9b944578d3ad9131a619d 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -236,6 +236,7 @@ OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o \ rtpdec_mpeg4.o \ rtpdec_qdm2.o \ rtpdec_svq3.o \ + rtpdec_vp8.o \ rtpdec_xiph.o OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o OBJS-$(CONFIG_SHORTEN_DEMUXER) += raw.o diff --git a/libavformat/avformat.h b/libavformat/avformat.h index d4fdc524391f68824666da8d47ef03f6cdca4b30..a6c40ad8b7ad13b297b39d68cae391fe79a17dc3 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -23,7 +23,7 @@ #define LIBAVFORMAT_VERSION_MAJOR 52 #define LIBAVFORMAT_VERSION_MINOR 78 -#define LIBAVFORMAT_VERSION_MICRO 2 +#define LIBAVFORMAT_VERSION_MICRO 3 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index fb58a9da16ed467a3e9115dd70d2adb2c3f3e573..f350251f1164d4f7390529e12b51a9984b22a238 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -66,6 +66,7 @@ void av_register_rtp_dynamic_payload_handlers(void) ff_register_dynamic_payload_handler(&ff_qdm2_dynamic_handler); ff_register_dynamic_payload_handler(&ff_svq3_dynamic_handler); ff_register_dynamic_payload_handler(&ff_mp4a_latm_dynamic_handler); + ff_register_dynamic_payload_handler(&ff_vp8_dynamic_handler); ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfv_handler); ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfa_handler); diff --git a/libavformat/rtpdec_formats.h b/libavformat/rtpdec_formats.h index 2add8ecaf739c412a05fdc869fbd0900234404a0..4b30879ecb599eb3d63b3898aa466738b6421521 100644 --- a/libavformat/rtpdec_formats.h +++ b/libavformat/rtpdec_formats.h @@ -45,5 +45,6 @@ extern RTPDynamicProtocolHandler ff_qdm2_dynamic_handler; extern RTPDynamicProtocolHandler ff_svq3_dynamic_handler; extern RTPDynamicProtocolHandler ff_theora_dynamic_handler; extern RTPDynamicProtocolHandler ff_vorbis_dynamic_handler; +extern RTPDynamicProtocolHandler ff_vp8_dynamic_handler; #endif /* AVFORMAT_RTPDEC_FORMATS_H */ diff --git a/libavformat/rtpdec_vp8.c b/libavformat/rtpdec_vp8.c new file mode 100644 index 0000000000000000000000000000000000000000..8de89ff15240dd69782e8f41d8bbcf68c5c1da4b --- /dev/null +++ b/libavformat/rtpdec_vp8.c @@ -0,0 +1,153 @@ +/* + * RTP VP8 Depacketizer + * Copyright (c) 2010 Josh Allmann + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * @brief RTP support for the VP8 payload + * @author Josh Allmann + * ( http://www.webmproject.org/code/specs/rtp/ ) + */ + +#include "libavcodec/bytestream.h" + +#include "rtpdec_formats.h" + +struct PayloadContext { + ByteIOContext *data; + uint32_t timestamp; + int is_keyframe; +}; + +static void prepare_packet(AVPacket *pkt, PayloadContext *vp8, int stream) +{ + av_init_packet(pkt); + pkt->stream_index = stream; + pkt->flags = vp8->is_keyframe ? AV_PKT_FLAG_KEY : 0; + pkt->size = url_close_dyn_buf(vp8->data, &pkt->data); + pkt->destruct = av_destruct_packet; + vp8->data = NULL; +} + +static int vp8_handle_packet(AVFormatContext *ctx, + PayloadContext *vp8, + AVStream *st, + AVPacket *pkt, + uint32_t *timestamp, + const uint8_t *buf, + int len, int flags) +{ + int start_packet, end_packet, has_au, ret = AVERROR(EAGAIN); + + if (!buf) { + // only called when vp8_handle_packet returns 1 + if (!vp8->data) { + av_log(ctx, AV_LOG_ERROR, "Invalid VP8 data passed\n"); + return AVERROR_INVALIDDATA; + } + prepare_packet(pkt, vp8, st->index); + *timestamp = vp8->timestamp; + return 0; + } + + start_packet = *buf & 1; + end_packet = flags & RTP_FLAG_MARKER; + has_au = *buf & 2; + buf++; + len--; + + if (start_packet) { + int res; + uint32_t ts = *timestamp; + if (vp8->data) { + // missing end marker; return old frame anyway. untested + prepare_packet(pkt, vp8, st->index); + *timestamp = vp8->timestamp; // reset timestamp from old frame + + // if current frame fits into one rtp packet, need to hold + // that for the next av_get_packet call + ret = end_packet ? 1 : 0; + } + if ((res = url_open_dyn_buf(&vp8->data)) < 0) + return res; + vp8->is_keyframe = *buf & 1; + vp8->timestamp = ts; + } + + if (!vp8->data || vp8->timestamp != *timestamp && ret == AVERROR(EAGAIN)) { + av_log(ctx, AV_LOG_WARNING, + "Received no start marker; dropping frame\n"); + return AVERROR(EAGAIN); + } + + // cycle through VP8AU headers if needed + // not tested with actual VP8AUs + while (len) { + int au_len = len; + if (has_au && len > 2) { + au_len = AV_RB16(buf); + buf += 2; + len -= 2; + if (buf + au_len > buf + len) { + av_log(ctx, AV_LOG_ERROR, "Invalid VP8AU length\n"); + return AVERROR_INVALIDDATA; + } + } + + put_buffer(vp8->data, buf, au_len); + buf += au_len; + len -= au_len; + } + + if (ret != AVERROR(EAGAIN)) // did we miss a end marker? + return ret; + + if (end_packet) { + prepare_packet(pkt, vp8, st->index); + return 0; + } + + return AVERROR(EAGAIN); +} + +static PayloadContext *vp8_new_context(void) +{ + av_log(NULL, AV_LOG_WARNING, "RTP VP8 payload is still experimental\n"); + return av_mallocz(sizeof(PayloadContext)); +} + +static void vp8_free_context(PayloadContext *vp8) +{ + if (vp8->data) { + uint8_t *tmp; + url_close_dyn_buf(vp8->data, &tmp); + av_free(tmp); + } + av_free(vp8); +} + +RTPDynamicProtocolHandler ff_vp8_dynamic_handler = { + .enc_name = "VP8", + .codec_type = AVMEDIA_TYPE_VIDEO, + .codec_id = CODEC_ID_VP8, + .open = vp8_new_context, + .close = vp8_free_context, + .parse_packet = vp8_handle_packet, +};