If the sequence_dirty flag is set, we have lost some frame (so
we should request a new keyframe), but not necessarily fatal
enough to abort all decoding until the next keyframe.

---
Squashed the two patches since they relate to the same, made sure
no "need keyframe" packets are sent until we actually have received
any data. Initialized sequence_ok to 1, so that we get warnings in
the log if the stream starts with anything else than a keyframe.
---
 libavformat/rtpdec_vp8.c |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/libavformat/rtpdec_vp8.c b/libavformat/rtpdec_vp8.c
index 13efa54..12ab56c 100644
--- a/libavformat/rtpdec_vp8.c
+++ b/libavformat/rtpdec_vp8.c
@@ -40,6 +40,8 @@ struct PayloadContext {
     uint16_t     prev_seq;
     int          prev_pictureid;
     int          broken_frame;
+    int          sequence_dirty;
+    int          got_keyframe;
 };
 
 static void vp8_free_buffer(PayloadContext *vp8)
@@ -56,6 +58,7 @@ static int vp8_broken_sequence(AVFormatContext *ctx, 
PayloadContext *vp8,
                                const char *msg)
 {
     vp8->sequence_ok = 0;
+    vp8->sequence_dirty = 1;
     av_log(ctx, AV_LOG_WARNING, "%s", msg);
     vp8_free_buffer(vp8);
     return AVERROR(EAGAIN);
@@ -141,11 +144,15 @@ static int vp8_handle_packet(AVFormatContext *ctx, 
PayloadContext *vp8,
             vp8_free_buffer(vp8);
             // Keyframe, decoding ok again
             vp8->sequence_ok = 1;
+            vp8->sequence_dirty = 0;
+            vp8->got_keyframe = 1;
         } else {
             int can_continue = vp8->data && !vp8->is_keyframe &&
                                avio_tell(vp8->data) >= vp8->first_part_size;
             if (!vp8->sequence_ok)
                 return AVERROR(EAGAIN);
+            if (!vp8->got_keyframe)
+                return vp8_broken_sequence(ctx, vp8, "Keyframe missing\n");
             if (pictureid >= 0) {
                 if (pictureid != ((vp8->prev_pictureid + 1) & pictureid_mask)) 
{
                     return vp8_broken_sequence(ctx, vp8,
@@ -179,6 +186,7 @@ static int vp8_handle_packet(AVFormatContext *ctx, 
PayloadContext *vp8,
                 }
             }
             if (vp8->data) {
+                vp8->sequence_dirty = 1;
                 if (avio_tell(vp8->data) >= vp8->first_part_size) {
                     int ret = ff_rtp_finalize_packet(pkt, &vp8->data, 
st->index);
                     if (ret < 0)
@@ -220,6 +228,7 @@ static int vp8_handle_packet(AVFormatContext *ctx, 
PayloadContext *vp8,
                                            "Missed part of a keyframe, 
sequence broken\n");
             } else if (vp8->data && avio_tell(vp8->data) >= 
vp8->first_part_size) {
                 vp8->broken_frame = 1;
+                vp8->sequence_dirty = 1;
             } else {
                 return vp8_broken_sequence(ctx, vp8,
                                            "Missed part of the first 
partition, sequence broken\n");
@@ -253,7 +262,11 @@ static int vp8_handle_packet(AVFormatContext *ctx, 
PayloadContext *vp8,
 
 static PayloadContext *vp8_new_context(void)
 {
-    return av_mallocz(sizeof(PayloadContext));
+    PayloadContext *vp8 = av_mallocz(sizeof(PayloadContext));
+    if (!vp8)
+        return NULL;
+    vp8->sequence_ok = 1;
+    return vp8;
 }
 
 static void vp8_free_context(PayloadContext *vp8)
@@ -262,6 +275,11 @@ static void vp8_free_context(PayloadContext *vp8)
     av_free(vp8);
 }
 
+static int vp8_need_keyframe(PayloadContext *vp8)
+{
+    return vp8->sequence_dirty;
+}
+
 RTPDynamicProtocolHandler ff_vp8_dynamic_handler = {
     .enc_name       = "VP8",
     .codec_type     = AVMEDIA_TYPE_VIDEO,
@@ -269,4 +287,5 @@ RTPDynamicProtocolHandler ff_vp8_dynamic_handler = {
     .alloc          = vp8_new_context,
     .free           = vp8_free_context,
     .parse_packet   = vp8_handle_packet,
+    .need_keyframe  = vp8_need_keyframe,
 };
-- 
1.7.9.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to