On 11 August 2010 00:46, Josh Allmann <joshua.allm...@gmail.com> wrote: > On 4 August 2010 03:32, Luca Barbato <lu_z...@gentoo.org> wrote: >> On 08/04/2010 09:59 AM, Martin Storsjö wrote: >>> David, how large is this first data partition approximately? The frames >>> are fragmented into RTP packets of around ~1450 bytes (usually) - so if >>> we've got the first packet of a frame but not the rest, would we be better >>> off returning this than just skipping it? >> >> Even better: is there a way to get this information? >> >> If is common for every packet/there is a known upper bound, we can pass >> it through the sdp, or if not we could think about storing the value in >> an extension header. >> > > Not sure; I'd have to dig through the bitstream spec for this. Ronald, > do you happen to know off the top of your head? > >> Still I guess we could extend the depacketizer interface to get all the >> standard rtp information as well. >> > > Attached patches should work against the updated VP8 rtp proposal*. > Also pulled from latest trunk, so they also work with the Xiph stuff. > > The depacketizer now supports multiple VP8AUs in one packet but I > haven't tested that codepath, because VP8AUs are not used by the > packetizer. > > * > https://groups.google.com/a/webmproject.org/group/webm-discuss/msg/eef6d312ac5c09c3?dmode=source&output=gplain >
Attaching... > Josh >
From b1e3d1fa0dfae7ca89770e1b428f18d90f335345 Mon Sep 17 00:00:00 2001 From: Josh Allmann <joshua.allm...@gmail.com> Date: Wed, 28 Jul 2010 00:30:09 -0700 Subject: [PATCH 1/2] Add RTP packetization of VP8. --- libavformat/rtpenc.c | 29 +++++++++++++++++++++++++++++ libavformat/sdp.c | 4 ++++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c index 9335e8c..6caf220 100644 --- a/libavformat/rtpenc.c +++ b/libavformat/rtpenc.c @@ -55,6 +55,7 @@ static int is_supported(enum CodecID id) case CODEC_ID_AMR_WB: case CODEC_ID_VORBIS: case CODEC_ID_THEORA: + case CODEC_ID_VP8: return 1; default: return 0; @@ -301,6 +302,31 @@ static void rtp_send_mpegaudio(AVFormatContext *s1, } } +/* Based on a draft spec for VP8 RTP. + * (https://groups.google.com/a/webmproject.org/group/webm-discuss/msg/eef6d312ac5c09c3?dmode=source&output=gplain) */ +static void rtp_send_vp8(AVFormatContext *s1, const uint8_t *buf, int size) +{ + RTPMuxContext *s = s1->priv_data; + int len, max_packet_size; + + s->buf_ptr = s->buf; + s->timestamp = s->cur_timestamp; + max_packet_size = s->max_payload_size - 1; // minus one for header byte + + *s->buf_ptr++ = 1; // 0b1 indicates start of frame + while (size > 0) { + len = FFMIN(size, max_packet_size); + + memcpy(s->buf_ptr, buf, len); + ff_rtp_send_data(s1, s->buf, len+1, size == len); // marker bit is last packet in frame + + size -= len; + buf += len; + s->buf_ptr = s->buf; + *s->buf_ptr++ = 0; // payload descriptor + } +} + static void rtp_send_raw(AVFormatContext *s1, const uint8_t *buf1, int size) { @@ -407,6 +433,9 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) case CODEC_ID_THEORA: ff_rtp_send_xiph(s1, pkt->data, size); break; + case CODEC_ID_VP8: + rtp_send_vp8(s1, pkt->data, size); + break; default: /* better than nothing : send the codec raw data */ rtp_send_raw(s1, pkt->data, size); diff --git a/libavformat/sdp.c b/libavformat/sdp.c index ab5ef40..ad06906 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -412,6 +412,10 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, c->width, c->height, pix_fmt, config); break; } + case CODEC_ID_VP8: + av_strlcatf(buff, size, "a=rtpmap:%d VP8/90000\r\n", + payload_type); + break; default: /* Nothing special to do here... */ break; -- 1.7.0.4
From e011b60502faff08495f78f6a66d96d5c43435c2 Mon Sep 17 00:00:00 2001 From: Josh Allmann <joshua.allm...@gmail.com> Date: Thu, 29 Jul 2010 03:51:36 -0700 Subject: [PATCH 2/2] Add RTP depacketization of VP8. --- libavformat/Makefile | 1 + libavformat/rtpdec.c | 1 + libavformat/rtpdec_formats.h | 1 + libavformat/rtpdec_vp8.c | 130 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+), 0 deletions(-) create mode 100644 libavformat/rtpdec_vp8.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 16aa0c7..251c463 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -234,6 +234,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/rtpdec.c b/libavformat/rtpdec.c index c17dc2d..2c5243a 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -65,6 +65,7 @@ void av_register_rtp_dynamic_payload_handlers(void) ff_register_dynamic_payload_handler(&ff_theora_dynamic_handler); ff_register_dynamic_payload_handler(&ff_qdm2_dynamic_handler); ff_register_dynamic_payload_handler(&ff_svq3_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 eac1b52..a96ffa6 100644 --- a/libavformat/rtpdec_formats.h +++ b/libavformat/rtpdec_formats.h @@ -44,5 +44,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 0000000..0036d77 --- /dev/null +++ b/libavformat/rtpdec_vp8.c @@ -0,0 +1,130 @@ +/* + * 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 <joshua.allm...@gmail.com> + * (https://groups.google.com/a/webmproject.org/group/webm-discuss/msg/eef6d312ac5c09c3?dmode=source&output=gplain) + */ + +#include "libavcodec/bytestream.h" + +#include "rtpdec_formats.h" + +struct PayloadContext { + ByteIOContext *data; + uint32_t timestamp; + int is_keyframe; +}; + +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; + if (!buf) + return AVERROR_INVALIDDATA; + + start_packet = *buf & 1; + end_packet = flags & RTP_FLAG_MARKER; + has_au = *buf & 2; + buf++; + len--; + + if (start_packet) { + int res; + if (vp8->data) { // drop previous frame if needed + uint8_t *tmp; + url_close_dyn_buf(vp8->data, &tmp); + vp8->data = NULL; + av_free(tmp); + } + if ((res = url_open_dyn_buf(&vp8->data)) < 0) + return res; + vp8->is_keyframe = *buf & 1; + vp8->timestamp = *timestamp; + } + + if (!vp8->data || vp8->timestamp != *timestamp) { + av_log(ctx, AV_LOG_WARNING, + "Received no start marker; dropping frame\n"); + return AVERROR(EAGAIN); + } + + // cycle through VP8AU headers if needed + while (len) { + int au_len = len; + if (has_au && len > 2) { + au_len = AV_RB16(buf) & 0x7ff; // use lower 11 bits + 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 (end_packet) { + av_init_packet(pkt); + pkt->stream_index = st->index; + 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; + return 0; + } + + return AVERROR(EAGAIN); +} + +static PayloadContext *vp8_new_context(void) +{ + 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, +}; -- 1.7.0.4
_______________________________________________ FFmpeg-soc mailing list FFmpeg-soc@mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc