[vlc-commits] packetizer: flac: check next header

Francois Cartegnie git at videolan.org
Fri Oct 18 20:16:12 CEST 2019


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Dec 19 19:47:55 2018 +0100| [2d00056a3174c2d140a50ce085793e9b81b3ca97] | committer: Francois Cartegnie

packetizer: flac: check next header

refs #21498

(cherry picked from commit dfe7d4c1a38572e8b6735393b69ba35284cc1d65)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=2d00056a3174c2d140a50ce085793e9b81b3ca97
---

 NEWS                      |  1 +
 modules/packetizer/flac.c | 37 ++++++++++++++++++++++++++++++-------
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/NEWS b/NEWS
index 93dae58f59..16132d1413 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Demux:
 Packetizers:
  * Fixes H264/HEVC incomplete draining in some cases
  * packetizer_helper: Fix potential trailing junk on last packet
+ * Improved check to prevent fLAC synchronization drops
 
 Decoder:
  * avcodec: revector video decoder to fix incomplete drain
diff --git a/modules/packetizer/flac.c b/modules/packetizer/flac.c
index 40251041c3..8e98ecc690 100644
--- a/modules/packetizer/flac.c
+++ b/modules/packetizer/flac.c
@@ -394,17 +394,35 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
         if(block_FindStartcodeFromOffset(&p_sys->bytestream, &p_sys->i_offset,
                                          NULL, 2,
                                          FLACStartcodeHelper,
-                                         FLACStartcodeMatcher) == VLC_SUCCESS)
+                                         FLACStartcodeMatcher) != VLC_SUCCESS)
         {
-            p_sys->i_state = STATE_GET_DATA;
-            break;
+            if( pp_block == NULL ) /* EOF/Drain */
+            {
+                p_sys->i_offset = block_BytestreamRemaining( &p_sys->bytestream );
+                p_sys->i_state = STATE_GET_DATA;
+                continue;
+            }
+            return NULL;
         }
-        else if( pp_block == NULL )
+
+        /* Check next header */
+        uint8_t nextheader[FLAC_HEADER_SIZE_MAX];
+        if (block_PeekOffsetBytes(&p_sys->bytestream, p_sys->i_offset,
+                                  nextheader, FLAC_HEADER_SIZE_MAX))
+            return NULL; /* Need more data */
+
+        struct flac_header_info dummy;
+        /* Check if frame is valid and get frame info */
+        if(FLAC_ParseSyncInfo(nextheader,
+                              p_sys->b_stream_info ? &p_sys->stream_info : NULL,
+                              NULL, &dummy) == 0)
         {
-            p_sys->i_offset = block_BytestreamRemaining( &p_sys->bytestream );
-            p_sys->i_state = STATE_GET_DATA;
+            p_sys->i_offset++;
+            continue;
         }
-        return NULL;
+
+        p_sys->i_state = STATE_GET_DATA;
+        continue;
     }
 
     case STATE_GET_DATA:
@@ -478,6 +496,11 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
             p_sys->i_last_frame_size = p_sys->i_frame_size;
             p_sys->i_offset = 0;
             p_sys->crc = 0;
+
+            if( block_BytestreamRemaining(&p_sys->bytestream) > 0 )
+                p_sys->i_state = STATE_SEND_DATA;
+            else
+                p_sys->i_state = STATE_NOSYNC;
         }
         break;
 



More information about the vlc-commits mailing list