On 3 August 2010 10:04, Martin Storsjö <[email protected]> wrote:
> On Mon, 2 Aug 2010, Josh Allmann wrote:
>>
>> Unless I've mis-counted my marker bits yet again, we are in full
>> compliance with the spec, except for the parts that are undefined --
>> the "VP8" encoding name in particular.
>
> One issue in the proposal that I don't think we comply to (and that I
> think should be changed before it is finalized, is this:
>
>> 3.3 Lost VP8 RTP packets
>> If a lost packet is detected in the RTP stream, the transport layer
>> MUST throw out the current partial VP8 frame (if there is one) and
>> all subsequent RTP packets until a VP8 payload descriptor with the
>> key-frame bit is set.
>
> Not returning a single packet up until the next keyframe, if a single
> packet is lost, feels quite horrible to me. Even though it may not look
> good if some data is lost, it's still better than not getting any data at
> all up until the next keyframe.
>
Indeed. Currently, we only drop if the start or end markers are
missing, until the next valid start marker. Even then, we *could*
still pass those into the decoder. I made a comment about this on the
webm ML, feel free to chime in there.
>
> Other than that, it looks quite good to me. A few style nitpicks yet:
>
>> + start_packet = *buf & 1;
>> + end_packet = flags & RTP_FLAG_MARKER;
>> + is_keyframe = *buf & 2;
>
> Why so much extra space before the equals sign?
>
Fixed.
>> + if ((res = url_open_dyn_buf(&vp8->data)) < 0)
>> + return res;
>> + vp8->is_keyframe = is_keyframe;
>> + vp8->timestamp = *timestamp;
>
> These could be aligned
>
Fixed.
>> + 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;
>> + }
>
> Some (all?) of these could be aligned, too.
>
Fixed.
>
> I'll see if Luca A wants to say something on the packetizer part, other
> than that, I think this one is done.
>
Sweet.
Also made another minor alignment change in rtpenc.
Josh
From d969a0473e38ab3df91b8ac0479018adf5a870f5 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 | 30 ++++++++++++++++++++++++++++++
libavformat/sdp.c | 4 ++++
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index 4453f65..2a8bbd2 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,32 @@ 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/679a63659ceff3e7?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, 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 ? 0 : 2; // 0b10 indicates keyframe
+
+ *s->buf_ptr++ = keyframe | 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++ = keyframe;
+ }
+}
+
static void rtp_send_raw(AVFormatContext *s1,
const uint8_t *buf1, int size)
{
@@ -393,6 +420,9 @@ 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);
+ 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 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 0d642af57968f54493a8cf1296b89c9d711efe48 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 | 1 +
libavformat/rtpdec_formats.h | 1 +
libavformat/rtpdec_vp8.c | 112 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 115 insertions(+), 0 deletions(-)
create mode 100644 libavformat/rtpdec_vp8.c
diff --git a/libavformat/Makefile b/libavformat/Makefile
index f73bc54..7258a55 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 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..f7fe9a0
--- /dev/null
+++ b/libavformat/rtpdec_vp8.c
@@ -0,0 +1,112 @@
+/*
+ * 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
+ * (https://groups.google.com/a/webmproject.org/group/webm-discuss/msg/679a63659ceff3e7?dmode=source&output=gplain)
+* @author Josh Allmann <[email protected]>
+ */
+
+#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, is_keyframe;
+ if (!buf)
+ return AVERROR_INVALIDDATA;
+
+ start_packet = *buf & 1;
+ end_packet = flags & RTP_FLAG_MARKER;
+ is_keyframe = *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 = is_keyframe;
+ 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);
+ }
+
+ put_buffer(vp8->data, buf, 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
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc