Hi, Here is a packetizer and a depacketizer for VP8 RTP.
Playback is only semi-smooth; it drops way too many frames. The depacketizer likes to claim it gets an extra packet after the frame-end (which is typically one byte smaller than the actual frame-end packet). Still a work in progress. On a side note, I think it is slightly excessive that we have so many rtpdec_* header files that only declare one or two structs. Would it make sense to combine all those declarations into a single depacketizers.h file or something? Josh
From 6d789bcacbece9a070ffa216e970ac8ed11a8a1e Mon Sep 17 00:00:00 2001 From: Josh Allmann <[email protected]> Date: Wed, 28 Jul 2010 00:30:09 -0700 Subject: [PATCH 1/2] Add RTP packetization of VP8. --- libavformat/rtpenc.c | 27 +++++++++++++++++++++++++++ libavformat/sdp.c | 4 ++++ 2 files changed, 31 insertions(+), 0 deletions(-) diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c index 4453f65..fa978ed 100644 --- a/libavformat/rtpenc.c +++ b/libavformat/rtpenc.c @@ -53,6 +53,7 @@ static int is_supported(enum CodecID id) case CODEC_ID_MPEG2TS: case CODEC_ID_AMR_NB: case CODEC_ID_AMR_WB: + case CODEC_ID_VP8: return 1; default: return 0; @@ -291,6 +292,30 @@ static void rtp_send_mpegaudio(AVFormatContext *s1, } } +static void rtp_send_vp8(AVFormatContext *s1, const uint8_t *buf, int size) +{ + RTPMuxContext *s = s1->priv_data; + int len, max_packet_size, keyframe; + + s->buf_ptr = s->buf; + s->timestamp = s->cur_timestamp; + max_packet_size = s->max_payload_size - 1; // minus one for header byte + keyframe = ( !(*buf & 1) ) << 3; + + *s->buf_ptr++ = keyframe | 4; // 0b100 indicates start of frame + while (size > 0) { + len = size > max_packet_size ? max_packet_size : 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++ = keyframe; + } +} + static void rtp_send_raw(AVFormatContext *s1, const uint8_t *buf1, int size) { @@ -393,6 +418,8 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) case CODEC_ID_H263P: ff_rtp_send_h263(s1, pkt->data, size); break; + case CODEC_ID_VP8: + rtp_send_vp8(s1, pkt->data, size); 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 b34b944..a7a3c13 100644 --- a/libavformat/sdp.c +++ b/libavformat/sdp.c @@ -297,6 +297,10 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, payload_type, c->sample_rate, c->channels, payload_type); 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 fe07918ff7bb1ff8f50fd2e5981cd3ba1871251f Mon Sep 17 00:00:00 2001 From: Josh Allmann <[email protected]> Date: Thu, 29 Jul 2010 03:51:36 -0700 Subject: [PATCH 2/2] Add RTP depacketization of VP8. --- libavformat/Makefile | 1 + libavformat/rtpdec.c | 2 + libavformat/rtpdec_vp8.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++ libavformat/rtpdec_vp8.h | 29 +++++++++++++ 4 files changed, 130 insertions(+), 0 deletions(-) create mode 100644 libavformat/rtpdec_vp8.c create mode 100644 libavformat/rtpdec_vp8.h diff --git a/libavformat/Makefile b/libavformat/Makefile index c32a254..fa4f233 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -233,6 +233,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 0e2aebb..c1ec21d 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -37,6 +37,7 @@ #include "rtpdec_mpeg4.h" #include "rtpdec_qdm2.h" #include "rtpdec_svq3.h" +#include "rtpdec_vp8.h" #include "rtpdec_xiph.h" //#define DEBUG @@ -72,6 +73,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_vp8.c b/libavformat/rtpdec_vp8.c new file mode 100644 index 0000000..4aa4734 --- /dev/null +++ b/libavformat/rtpdec_vp8.c @@ -0,0 +1,98 @@ +/* + * 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 + */ + +#include "rtpdec_vp8.h" + +struct PayloadContext { + ByteIOContext *data; + int is_keyframe; // this is rather unused +}; + +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 = *buf & 4; + int end_packet = flags & RTP_FLAG_MARKER; + int is_keyframe = *buf & 8; + buf++; + len--; + + if (start_packet) { + int res; + if (vp8->data) { // drop old frame + 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 = is_keyframe; + } + + if (!vp8->data) { + av_log(ctx, AV_LOG_WARNING, + "Received no start marker; dropping frame\n"); + return AVERROR(EAGAIN); + } + + put_buffer(vp8->data, buf, len); + + if (end_packet) { + av_init_packet(pkt); + pkt->stream_index = st->index; + 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, +}; diff --git a/libavformat/rtpdec_vp8.h b/libavformat/rtpdec_vp8.h new file mode 100644 index 0000000..f19ecfa --- /dev/null +++ b/libavformat/rtpdec_vp8.h @@ -0,0 +1,29 @@ +/* + * RTP VP8 Protocol + * 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 + */ + +#ifndef AVFORMAT_RTPDEC_VP8_H +#define AVFORMAT_RTPDEC_VP8_H + +#include "rtpdec.h" + +extern RTPDynamicProtocolHandler ff_vp8_dynamic_handler; + +#endif /* AVFORMAT_RTPDEC_VP8_H */ -- 1.7.0.4
_______________________________________________ FFmpeg-soc mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc
