[vlc-commits] demux: caf: handle Opus (fix #19544)

Francois Cartegnie git at videolan.org
Thu Feb 1 21:30:46 CET 2018


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Feb  1 18:56:25 2018 +0100| [5e2c5c6170fde81870b6ea1efba5e224f9811438] | committer: Francois Cartegnie

demux: caf: handle Opus (fix #19544)

Apple's undocumented framing.
There's no external framing to figure limits. The opus
decoder will never read the full packet, containing
up to CLOCK_FREQ/20 of samples/frames.
We must enforce sending single frames.

(cherry picked from commit eae265ed8dc5240f1ccfc292c33ce70e918b863c)

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

 modules/demux/caf.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/modules/demux/caf.c b/modules/demux/caf.c
index cce8e93afb..0157e51d9e 100644
--- a/modules/demux/caf.c
+++ b/modules/demux/caf.c
@@ -83,6 +83,7 @@ struct demux_sys_t
 {
     es_format_t  fmt;
     es_out_id_t *es;
+    unsigned i_max_frames;
 
     uint64_t i_data_offset;
     uint64_t i_data_size;
@@ -512,6 +513,12 @@ static int ReadDescChunk( demux_t *p_demux )
     p_sys->fmt.audio.i_blockalign = i_bytes_per_packet;
     p_sys->fmt.i_bitrate = i_bits_per_channel * p_sys->fmt.audio.i_rate * i_channels_per_frame;
 
+    if( p_sys->fmt.i_codec == VLC_CODEC_OPUS )
+    {
+        p_sys->i_max_frames = 1;
+    }
+    else p_sys->i_max_frames = UINT_MAX;
+
     return VLC_SUCCESS;
 }
 
@@ -951,12 +958,21 @@ static int Demux( demux_t *p_demux )
     }
     else /* use packet table */
     {
+        uint64_t i_max_frames;
+        if( p_sys->packet_table.i_num_packets > p_sys->position.i_frames )
+            i_max_frames = p_sys->packet_table.i_num_packets - p_sys->position.i_frames;
+        else
+            i_max_frames = 1; /* will be rejected on FrameSpanAddDescription below */
+
+        if( i_max_frames > p_sys->i_max_frames )
+            i_max_frames = p_sys->i_max_frames;
+
         do
         {
             if( FrameSpanAddDescription( p_demux, p_sys->position.i_desc_bytes + advance.i_desc_bytes, &advance ))
                 break;
         }
-        while (( i_req_samples > advance.i_samples ) && ( p_sys->position.i_frames + advance.i_frames ) < p_sys->packet_table.i_num_packets );
+        while ( i_req_samples > advance.i_samples && advance.i_frames < i_max_frames );
     }
 
     if( !advance.i_frames )



More information about the vlc-commits mailing list