]> granicus.if.org Git - handbrake/commitdiff
libhb: pass AV_PKT_FLAG_DISCARD through to decoder
authorJohn Stebbins <jstebbins.hb@gmail.com>
Thu, 2 May 2019 18:56:02 +0000 (12:56 -0600)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Sun, 5 May 2019 21:19:54 +0000 (15:19 -0600)
Edit list cuts are not always on keyframe boundaries and therefore
sometimes require dropping frames after decoding them.
AV_PKT_FLAG_DISCARD tells us when to do this.

Fixes https://github.com/HandBrake/HandBrake/issues/1900

(cherry picked from commit 9be711f822e4458d4d4edda1d00a6b752fc4e7b8)

libhb/decavcodec.c
libhb/internal.h
libhb/stream.c

index f3e0773b00564bf52193dab373ce73d13bc5539d..3641b18fb7c09d7fc44bb63583b93c657ce13b0b 100644 (file)
@@ -81,6 +81,7 @@ typedef struct
     int                    frametype;
     int                    scr_sequence;
     int                    new_chap;
+    int                    discard;
 } packet_info_t;
 
 typedef struct reordered_data_s reordered_data_t;
@@ -505,6 +506,7 @@ static int decavcodecaWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
         pv->packet_info.scr_sequence = in->s.scr_sequence;
         pv->packet_info.new_chap     = in->s.new_chap;
         pv->packet_info.frametype    = in->s.frametype;
+        pv->packet_info.discard      = !!(in->s.flags & HB_FLAG_DISCARD);
     }
     for (pos = 0; pos < in->size; pos += len)
     {
@@ -538,6 +540,7 @@ static int decavcodecaWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
             // decodeAudio that is now finished.  The next packet is associated
             // with the input buffer, so set it's chapter and scr info.
             pv->packet_info.scr_sequence = in->s.scr_sequence;
+            pv->packet_info.discard      = !!(in->s.flags & HB_FLAG_DISCARD);
             pv->unfinished               = 0;
         }
         if (len > 0 && pout_len <= 0)
@@ -1415,6 +1418,7 @@ static int decodeFrame( hb_work_private_t * pv, packet_info_t * packet_info )
         {
             avp.flags |= AV_PKT_FLAG_KEY;
         }
+        avp.flags  |= packet_info->discard * AV_PKT_FLAG_DISCARD;
     }
     else
     {
@@ -1844,6 +1848,7 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
         pv->packet_info.scr_sequence = in->s.scr_sequence;
         pv->packet_info.new_chap     = in->s.new_chap;
         pv->packet_info.frametype    = in->s.frametype;
+        pv->packet_info.discard      = !!(in->s.flags & HB_FLAG_DISCARD);
     }
     for (pos = 0; pos < in->size; pos += len)
     {
@@ -1898,6 +1903,7 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
             pv->packet_info.scr_sequence = in->s.scr_sequence;
             pv->packet_info.new_chap     = in->s.new_chap;
             pv->packet_info.frametype    = in->s.frametype;
+            pv->packet_info.discard      = !!(in->s.flags & HB_FLAG_DISCARD);
             pv->unfinished               = 0;
         }
         if (len > 0 && pout_len <= 0)
@@ -2220,6 +2226,7 @@ static void decodeAudio(hb_work_private_t *pv, packet_info_t * packet_info)
         avp.size = packet_info->size;
         avp.pts  = packet_info->pts;
         avp.dts  = AV_NOPTS_VALUE;
+        avp.flags |= packet_info->discard * AV_PKT_FLAG_DISCARD;
     }
     else
     {
index cef1c2ebbf2f4ab55d32dc7db3ffa0c6d20d2914..8d7e7738592cfa9c4488feaaaf494d28cb62016f 100644 (file)
@@ -98,6 +98,7 @@ struct hb_buffer_settings_s
 #define HB_BUF_FLAG_EOS             0x0800
 #define HB_FLAG_FRAMETYPE_KEY       0x1000
 #define HB_FLAG_FRAMETYPE_REF       0x2000
+#define HB_FLAG_DISCARD             0x4000
     uint16_t      flags;
 
 #define HB_COMB_NONE  0
index 6f5ec4d2ea44cbb1e67803c1f36491948a8b11b7..e8e29154c3bb2e8cfc75ca76c7727668158e2c9a 100644 (file)
@@ -5945,6 +5945,10 @@ hb_buffer_t * hb_ffmpeg_read( hb_stream_t *stream )
             memcpy( buf->palette->data, palette, size );
         }
     }
+    if (stream->ffmpeg_pkt.flags & AV_PKT_FLAG_DISCARD)
+    {
+        buf->s.flags |= HB_FLAG_DISCARD;
+    }
     buf->s.id = stream->ffmpeg_pkt.stream_index;
 
     // compute a conversion factor to go from the ffmpeg
@@ -5974,7 +5978,7 @@ hb_buffer_t * hb_ffmpeg_read( hb_stream_t *stream )
              */
             if (stream->ffmpeg_pkt.flags & AV_PKT_FLAG_KEY)
             {
-                buf->s.flags = HB_FLAG_FRAMETYPE_KEY;
+                buf->s.flags |= HB_FLAG_FRAMETYPE_KEY;
                 buf->s.frametype = HB_FRAME_I;
             }
             break;