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

Francois Cartegnie git at videolan.org
Wed Dec 19 20:01:43 CET 2018


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

packetizer: flac: check next header

refs #21498

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

 modules/packetizer/flac.c | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/modules/packetizer/flac.c b/modules/packetizer/flac.c
index 1c47c756ed..244e0302cb 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