[vlc-commits] spdif: eac3: handle packetized and no packetized blocks

Thomas Guillem git at videolan.org
Tue Apr 10 18:11:56 CEST 2018


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Apr 10 15:03:26 2018 +0200| [dee8d0bc530cc7699652079d2f178531bdd4cc5f] | committer: Thomas Guillem

spdif: eac3: handle packetized and no packetized blocks

Handle the case where there are more than one a52 streams in a block.

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

 modules/audio_filter/converter/tospdif.c | 48 ++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 15 deletions(-)

diff --git a/modules/audio_filter/converter/tospdif.c b/modules/audio_filter/converter/tospdif.c
index 7c757cb606..0c54dbd1a7 100644
--- a/modules/audio_filter/converter/tospdif.c
+++ b/modules/audio_filter/converter/tospdif.c
@@ -245,18 +245,11 @@ static int write_buffer_ac3( filter_t *p_filter, block_t *p_in_buf )
     return SPDIF_SUCCESS;
 }
 
-static int write_buffer_eac3( filter_t *p_filter, block_t *p_in_buf )
+static int write_buffer_eac3_stream( filter_t *p_filter, block_t *p_in_buf,
+                                     vlc_a52_header_t *p_a52 )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
 
-    vlc_a52_header_t a52 = { };
-    if( vlc_a52_header_Parse( &a52, p_in_buf->p_buffer, p_in_buf->i_buffer )
-        != VLC_SUCCESS || a52.i_size > p_in_buf->i_buffer )
-        return SPDIF_ERROR;
-
-    p_in_buf->i_buffer = a52.i_size;
-    p_in_buf->i_nb_samples = a52.i_samples;
-
     if( !p_sys->p_out_buf
      && write_init( p_filter, p_in_buf, AOUT_SPDIF_SIZE * 4, AOUT_SPDIF_SIZE ) )
         return SPDIF_ERROR;
@@ -265,16 +258,16 @@ static int write_buffer_eac3( filter_t *p_filter, block_t *p_in_buf )
 
     write_buffer( p_filter, p_in_buf );
 
-    if( a52.b_eac3 )
+    if( p_a52->b_eac3 )
     {
-        if( ( a52.eac3.strmtyp == EAC3_STRMTYP_INDEPENDENT
-           || a52.eac3.strmtyp == EAC3_STRMTYP_AC3_CONVERT )
-         && a52.i_blocks_per_sync_frame != 6 )
+        if( ( p_a52->eac3.strmtyp == EAC3_STRMTYP_INDEPENDENT
+           || p_a52->eac3.strmtyp == EAC3_STRMTYP_AC3_CONVERT )
+         && p_a52->i_blocks_per_sync_frame != 6 )
         {
             /* cf. Annex E 2.3.1.2 of AC3 spec */
-            if( a52.eac3.i_substreamid == 0 )
+            if( p_a52->eac3.i_substreamid == 0 )
                 p_sys->eac3.i_nb_blocks_substream0
-                    += a52.i_blocks_per_sync_frame;
+                    += p_a52->i_blocks_per_sync_frame;
 
             if( p_sys->eac3.i_nb_blocks_substream0 != 6 )
                 return SPDIF_MORE_DATA;
@@ -286,7 +279,32 @@ static int write_buffer_eac3( filter_t *p_filter, block_t *p_in_buf )
     }
     else
         return SPDIF_MORE_DATA;
+}
+
+static int write_buffer_eac3( filter_t *p_filter, block_t *p_in_buf )
+{
+    vlc_a52_header_t a52 = { .i_size = 0 };
+
+    size_t i_remaining = p_in_buf->i_buffer;
+    int ret;
+    do
+    {
+        p_in_buf->i_buffer = i_remaining;
+        p_in_buf->p_buffer += a52.i_size;
+
+        if( vlc_a52_header_Parse( &a52, p_in_buf->p_buffer, p_in_buf->i_buffer )
+            != VLC_SUCCESS || a52.i_size > p_in_buf->i_buffer )
+            return SPDIF_ERROR;
+
+        p_in_buf->i_buffer = a52.i_size;
+        p_in_buf->i_nb_samples = a52.i_samples;
+
+        ret = write_buffer_eac3_stream( p_filter, p_in_buf, &a52 );
+        i_remaining -= p_in_buf->i_buffer;
+
+    } while ( ret == SPDIF_MORE_DATA && i_remaining > 0 );
 
+    return ret;
 }
 
 /* Adapted from libavformat/spdifenc.c:



More information about the vlc-commits mailing list