[vlc-commits] xiph: constify xiph_SplitHeaders()

Rémi Denis-Courmont git at videolan.org
Tue Jul 23 19:43:20 CEST 2019


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jul 23 20:39:51 2019 +0300| [0fa1d4e11145b2e9e59766428f9f0e4339858365] | committer: Rémi Denis-Courmont

xiph: constify xiph_SplitHeaders()

... and fix invalid pointer conversion from const void ** to void **
in xiph_PacketHeaders().

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

 modules/codec/daala.c        |  8 ++++----
 modules/codec/kate.c         |  6 +++---
 modules/codec/opus.c         |  4 ++--
 modules/codec/speex.c        |  6 +++---
 modules/codec/theora.c       |  8 ++++----
 modules/codec/vorbis.c       |  8 ++++----
 modules/demux/avformat/mux.c |  2 +-
 modules/demux/ogg.c          | 23 +++++++++++++++--------
 modules/demux/xiph.h         |  8 +++++---
 modules/mux/ogg.c            | 10 ++++++----
 modules/stream_out/rtpfmt.c  |  5 +++--
 11 files changed, 50 insertions(+), 38 deletions(-)

diff --git a/modules/codec/daala.c b/modules/codec/daala.c
index cb6e2d0c95..ad516e1cd3 100644
--- a/modules/codec/daala.c
+++ b/modules/codec/daala.c
@@ -278,7 +278,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     daala_setup_info *ds = NULL; /* daala setup information */
 
     unsigned pi_size[XIPH_MAX_HEADER_COUNT];
-    void     *pp_data[XIPH_MAX_HEADER_COUNT];
+    const void *pp_data[XIPH_MAX_HEADER_COUNT];
     unsigned i_count;
     if( xiph_SplitHeaders( pi_size, pp_data, &i_count,
                            p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) )
@@ -293,7 +293,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     /* Take care of the initial info header */
     dpacket.b_o_s  = 1; /* yes this actually is a b_o_s packet :) */
     dpacket.bytes  = pi_size[0];
-    dpacket.packet = pp_data[0];
+    dpacket.packet = (void *)pp_data[0];
     if( daala_decode_header_in( &p_sys->di, &p_sys->dc, &ds, &dpacket ) < 0 )
     {
         msg_Err( p_dec, "this bitstream does not contain Daala video data" );
@@ -354,7 +354,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     /* The next packet in order is the comments header */
     dpacket.b_o_s  = 0;
     dpacket.bytes  = pi_size[1];
-    dpacket.packet = pp_data[1];
+    dpacket.packet = (void *)pp_data[1];
 
     if( daala_decode_header_in( &p_sys->di, &p_sys->dc, &ds, &dpacket ) < 0 )
     {
@@ -370,7 +370,7 @@ static int ProcessHeaders( decoder_t *p_dec )
      * missing or corrupted header is fatal. */
     dpacket.b_o_s  = 0;
     dpacket.bytes  = pi_size[2];
-    dpacket.packet = pp_data[2];
+    dpacket.packet = (void *)pp_data[2];
     if( daala_decode_header_in( &p_sys->di, &p_sys->dc, &ds, &dpacket ) < 0 )
     {
         msg_Err( p_dec, "Daala setup header is corrupted" );
diff --git a/modules/codec/kate.c b/modules/codec/kate.c
index 65c810295c..cb2e2672fb 100644
--- a/modules/codec/kate.c
+++ b/modules/codec/kate.c
@@ -532,7 +532,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     kate_packet kp;
 
     unsigned pi_size[XIPH_MAX_HEADER_COUNT];
-    void     *pp_data[XIPH_MAX_HEADER_COUNT];
+    const void *pp_data[XIPH_MAX_HEADER_COUNT];
     unsigned i_count;
     if( xiph_SplitHeaders( pi_size, pp_data, &i_count,
                            p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) )
@@ -543,7 +543,7 @@ static int ProcessHeaders( decoder_t *p_dec )
 
     /* Take care of the initial Kate header */
     kp.nbytes = pi_size[0];
-    kp.data   = pp_data[0];
+    kp.data   = (void *)pp_data[0];
     int i_ret = kate_decode_headerin( &p_sys->ki, &p_sys->kc, &kp );
     if( i_ret < 0 )
     {
@@ -560,7 +560,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     for( unsigned i_headeridx = 1; i_headeridx < i_count; i_headeridx++ )
     {
         kp.nbytes = pi_size[i_headeridx];
-        kp.data   = pp_data[i_headeridx];
+        kp.data   = (void *)pp_data[i_headeridx];
         i_ret = kate_decode_headerin( &p_sys->ki, &p_sys->kc, &kp );
         if( i_ret < 0 )
         {
diff --git a/modules/codec/opus.c b/modules/codec/opus.c
index 5faa34c464..c6aaf407cb 100644
--- a/modules/codec/opus.c
+++ b/modules/codec/opus.c
@@ -242,7 +242,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     ogg_packet oggpacket;
 
     unsigned pi_size[XIPH_MAX_HEADER_COUNT];
-    void     *pp_data[XIPH_MAX_HEADER_COUNT];
+    const void *pp_data[XIPH_MAX_HEADER_COUNT];
     unsigned i_count;
 
     int i_extra = p_dec->fmt_in.i_extra;
@@ -284,7 +284,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     /* Take care of the initial Opus header */
     oggpacket.b_o_s = 1; /* yes this actually is a b_o_s packet :) */
     oggpacket.bytes  = pi_size[0];
-    oggpacket.packet = pp_data[0];
+    oggpacket.packet = (void *)pp_data[0];
     int ret = ProcessInitialHeader( p_dec, &oggpacket );
 
     if (ret != VLC_SUCCESS)
diff --git a/modules/codec/speex.c b/modules/codec/speex.c
index 5f7c093245..38eb459dc6 100644
--- a/modules/codec/speex.c
+++ b/modules/codec/speex.c
@@ -410,7 +410,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     ogg_packet oggpacket;
 
     unsigned pi_size[XIPH_MAX_HEADER_COUNT];
-    void     *pp_data[XIPH_MAX_HEADER_COUNT];
+    const void *pp_data[XIPH_MAX_HEADER_COUNT];
     unsigned i_count;
     if( xiph_SplitHeaders( pi_size, pp_data, &i_count,
                            p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) )
@@ -425,7 +425,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     /* Take care of the initial Vorbis header */
     oggpacket.b_o_s = 1; /* yes this actually is a b_o_s packet :) */
     oggpacket.bytes  = pi_size[0];
-    oggpacket.packet = pp_data[0];
+    oggpacket.packet = (void *)pp_data[0];
     if( ProcessInitialHeader( p_dec, &oggpacket ) != VLC_SUCCESS )
     {
         msg_Err( p_dec, "initial Speex header is corrupted" );
@@ -435,7 +435,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     /* The next packet in order is the comments header */
     oggpacket.b_o_s = 0;
     oggpacket.bytes  = pi_size[1];
-    oggpacket.packet = pp_data[1];
+    oggpacket.packet = (void *)pp_data[1];
     ParseSpeexComments( p_dec, &oggpacket );
 
     if( p_sys->b_packetizer )
diff --git a/modules/codec/theora.c b/modules/codec/theora.c
index a4874f1f47..b038502fd2 100644
--- a/modules/codec/theora.c
+++ b/modules/codec/theora.c
@@ -257,7 +257,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     int i_max_pp, i_pp;
 
     unsigned pi_size[XIPH_MAX_HEADER_COUNT];
-    void     *pp_data[XIPH_MAX_HEADER_COUNT];
+    const void *pp_data[XIPH_MAX_HEADER_COUNT];
     unsigned i_count;
     if( xiph_SplitHeaders( pi_size, pp_data, &i_count,
                            p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) )
@@ -272,7 +272,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     /* Take care of the initial Vorbis header */
     oggpacket.b_o_s  = 1; /* yes this actually is a b_o_s packet :) */
     oggpacket.bytes  = pi_size[0];
-    oggpacket.packet = pp_data[0];
+    oggpacket.packet = (void *)pp_data[0];
     if( th_decode_headerin( &p_sys->ti, &p_sys->tc, &ts, &oggpacket ) < 0 )
     {
         msg_Err( p_dec, "this bitstream does not contain Theora video data" );
@@ -360,7 +360,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     /* The next packet in order is the comments header */
     oggpacket.b_o_s  = 0;
     oggpacket.bytes  = pi_size[1];
-    oggpacket.packet = pp_data[1];
+    oggpacket.packet = (void *)pp_data[1];
 
     if( th_decode_headerin( &p_sys->ti, &p_sys->tc, &ts, &oggpacket ) < 0 )
     {
@@ -375,7 +375,7 @@ static int ProcessHeaders( decoder_t *p_dec )
      * missing or corrupted header is fatal. */
     oggpacket.b_o_s  = 0;
     oggpacket.bytes  = pi_size[2];
-    oggpacket.packet = pp_data[2];
+    oggpacket.packet = (void *)pp_data[2];
     if( th_decode_headerin( &p_sys->ti, &p_sys->tc, &ts, &oggpacket ) < 0 )
     {
         msg_Err( p_dec, "3rd Theora header is corrupted" );
diff --git a/modules/codec/vorbis.c b/modules/codec/vorbis.c
index a571e54c8f..39133e5ff2 100644
--- a/modules/codec/vorbis.c
+++ b/modules/codec/vorbis.c
@@ -351,7 +351,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     ogg_packet oggpacket;
 
     unsigned pi_size[XIPH_MAX_HEADER_COUNT];
-    void *pp_data[XIPH_MAX_HEADER_COUNT];
+    const void *pp_data[XIPH_MAX_HEADER_COUNT];
     unsigned i_count;
     if( xiph_SplitHeaders( pi_size, pp_data, &i_count,
                            p_dec->fmt_in.i_extra, p_dec->fmt_in.p_extra) )
@@ -366,7 +366,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     /* Take care of the initial Vorbis header */
     oggpacket.b_o_s  = 1; /* yes this actually is a b_o_s packet :) */
     oggpacket.bytes  = pi_size[0];
-    oggpacket.packet = pp_data[0];
+    oggpacket.packet = (void *)pp_data[0];
     if( vorbis_synthesis_headerin( &p_sys->vi, &p_sys->vc, &oggpacket ) < 0 )
     {
         msg_Err( p_dec, "this bitstream does not contain Vorbis audio data");
@@ -397,7 +397,7 @@ static int ProcessHeaders( decoder_t *p_dec )
     /* The next packet in order is the comments header */
     oggpacket.b_o_s  = 0;
     oggpacket.bytes  = pi_size[1];
-    oggpacket.packet = pp_data[1];
+    oggpacket.packet = (void *)pp_data[1];
     if( vorbis_synthesis_headerin( &p_sys->vi, &p_sys->vc, &oggpacket ) < 0 )
     {
         msg_Err( p_dec, "2nd Vorbis header is corrupted" );
@@ -410,7 +410,7 @@ static int ProcessHeaders( decoder_t *p_dec )
      * missing or corrupted header is fatal. */
     oggpacket.b_o_s  = 0;
     oggpacket.bytes  = pi_size[2];
-    oggpacket.packet = pp_data[2];
+    oggpacket.packet = (void *)pp_data[2];
     if( vorbis_synthesis_headerin( &p_sys->vi, &p_sys->vc, &oggpacket ) < 0 )
     {
         msg_Err( p_dec, "3rd Vorbis header is corrupted" );
diff --git a/modules/demux/avformat/mux.c b/modules/demux/avformat/mux.c
index 7244f51ffc..b9d9c378c8 100644
--- a/modules/demux/avformat/mux.c
+++ b/modules/demux/avformat/mux.c
@@ -202,7 +202,7 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
     }
 
     unsigned opus_size[XIPH_MAX_HEADER_COUNT];
-    void     *opus_packet[XIPH_MAX_HEADER_COUNT];
+    const void *opus_packet[XIPH_MAX_HEADER_COUNT];
     if( fmt->i_codec == VLC_CODEC_OPUS )
     {
         unsigned count;
diff --git a/modules/demux/ogg.c b/modules/demux/ogg.c
index ac349371c2..649e154a7e 100644
--- a/modules/demux/ogg.c
+++ b/modules/demux/ogg.c
@@ -2321,14 +2321,16 @@ static void Ogg_LogicalStreamDelete( demux_t *p_demux, logical_stream_t *p_strea
 static bool Ogg_IsVorbisFormatCompatible( const es_format_t *p_new, const es_format_t *p_old )
 {
     unsigned pi_new_size[XIPH_MAX_HEADER_COUNT];
-    void     *pp_new_data[XIPH_MAX_HEADER_COUNT];
+    const void *pp_new_data[XIPH_MAX_HEADER_COUNT];
     unsigned i_new_count;
+
     if( xiph_SplitHeaders(pi_new_size, pp_new_data, &i_new_count, p_new->i_extra, p_new->p_extra ) )
         i_new_count = 0;
 
     unsigned pi_old_size[XIPH_MAX_HEADER_COUNT];
-    void     *pp_old_data[XIPH_MAX_HEADER_COUNT];
+    const void *pp_old_data[XIPH_MAX_HEADER_COUNT];
     unsigned i_old_count;
+
     if( xiph_SplitHeaders(pi_old_size, pp_old_data, &i_old_count, p_old->i_extra, p_old->p_extra ) )
         i_old_count = 0;
 
@@ -2350,20 +2352,23 @@ static bool Ogg_IsOpusFormatCompatible( const es_format_t *p_new,
                                         const es_format_t *p_old )
 {
     unsigned pi_new_size[XIPH_MAX_HEADER_COUNT];
-    void     *pp_new_data[XIPH_MAX_HEADER_COUNT];
+    const void *pp_new_data[XIPH_MAX_HEADER_COUNT];
     unsigned i_new_count;
+
     if( xiph_SplitHeaders(pi_new_size, pp_new_data, &i_new_count, p_new->i_extra, p_new->p_extra ) )
         i_new_count = 0;
+
     unsigned pi_old_size[XIPH_MAX_HEADER_COUNT];
-    void     *pp_old_data[XIPH_MAX_HEADER_COUNT];
+    const void *pp_old_data[XIPH_MAX_HEADER_COUNT];
     unsigned i_old_count;
+
     if( xiph_SplitHeaders(pi_old_size, pp_old_data, &i_old_count, p_old->i_extra, p_old->p_extra ) )
         i_old_count = 0;
     bool b_match = false;
     if( i_new_count == i_old_count && i_new_count > 0 )
     {
         static const unsigned char default_map[2] = { 0, 1 };
-        unsigned char *p_old_head;
+        const unsigned char *p_old_head;
         unsigned char *p_new_head;
         const unsigned char *p_old_map;
         const unsigned char *p_new_map;
@@ -2373,7 +2378,7 @@ static bool Ogg_IsOpusFormatCompatible( const es_format_t *p_new,
         int i_new_stream_count;
         int i_old_coupled_count;
         int i_new_coupled_count;
-        p_old_head = (unsigned char *)pp_old_data[0];
+        p_old_head = pp_old_data[0];
         i_old_channel_count = i_old_stream_count = i_old_coupled_count = 0;
         p_old_map = default_map;
         if( pi_old_size[0] >= 19 && p_old_head[8] <= 15 )
@@ -2523,7 +2528,7 @@ static void Ogg_ExtractXiphMeta( demux_t *p_demux, es_format_t *p_fmt,
                                  const void *p_headers, unsigned i_headers, unsigned i_skip )
 {
     unsigned pi_size[XIPH_MAX_HEADER_COUNT];
-    void     *pp_data[XIPH_MAX_HEADER_COUNT];
+    const void *pp_data[XIPH_MAX_HEADER_COUNT];
     unsigned i_count;
 
     if( xiph_SplitHeaders( pi_size, pp_data, &i_count, i_headers, p_headers ) )
@@ -2531,7 +2536,9 @@ static void Ogg_ExtractXiphMeta( demux_t *p_demux, es_format_t *p_fmt,
     /* TODO how to handle multiple comments properly ? */
     if( i_count >= 2 && pi_size[1] > i_skip )
     {
-        Ogg_ExtractComments( p_demux, p_fmt, (uint8_t*)pp_data[1] + i_skip, pi_size[1] - i_skip );
+        Ogg_ExtractComments( p_demux, p_fmt,
+                             (const uint8_t *)pp_data[1] + i_skip,
+                             pi_size[1] - i_skip );
     }
 }
 
diff --git a/modules/demux/xiph.h b/modules/demux/xiph.h
index 549e0ef276..eaa8158d7c 100644
--- a/modules/demux/xiph.h
+++ b/modules/demux/xiph.h
@@ -56,7 +56,8 @@ static inline unsigned int xiph_CountHeaders( const void *extra, unsigned int i_
     }
 }
 
-static inline int xiph_SplitHeaders(unsigned packet_size[], void * packet[], unsigned *packet_count,
+static inline int xiph_SplitHeaders(unsigned packet_size[],
+                                    const void *packet[], unsigned *packet_count,
                                     unsigned extra_size, const void *extra)
 {
     const uint8_t *current = (const uint8_t *)extra;
@@ -161,8 +162,9 @@ static inline int xiph_AppendHeaders(int *extra_size, void **extra,
                                      unsigned size, const void *data)
 {
     unsigned packet_size[XIPH_MAX_HEADER_COUNT];
-    void *packet[XIPH_MAX_HEADER_COUNT];
+    const void *packet[XIPH_MAX_HEADER_COUNT];
     unsigned count;
+
     if (*extra_size > 0 && *extra) {
         if (xiph_SplitHeaders(packet_size, packet, &count, *extra_size, *extra))
             return VLC_EGENERIC;
@@ -177,7 +179,7 @@ static inline int xiph_AppendHeaders(int *extra_size, void **extra,
     packet_size[count] = size;
     packet[count]      = (void*)data;
     if (xiph_PackHeaders(extra_size, extra, packet_size,
-                         (const void **)packet, count + 1)) {
+                         packet, count + 1)) {
         *extra_size = 0;
         *extra      = NULL;
     }
diff --git a/modules/mux/ogg.c b/modules/mux/ogg.c
index 3baff56e78..c41b940434 100644
--- a/modules/mux/ogg.c
+++ b/modules/mux/ogg.c
@@ -1021,8 +1021,9 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
             {
                 /* First packet in order: vorbis/speex/opus/theora/daala info */
                 unsigned pi_size[XIPH_MAX_HEADER_COUNT];
-                void     *pp_data[XIPH_MAX_HEADER_COUNT];
+                const void *pp_data[XIPH_MAX_HEADER_COUNT];
                 unsigned i_count;
+
                 if( xiph_SplitHeaders( pi_size, pp_data, &i_count,
                                        p_input->p_fmt->i_extra, p_input->p_fmt->p_extra ) )
                 {
@@ -1032,7 +1033,7 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
                 }
 
                 op.bytes  = pi_size[0];
-                op.packet = pp_data[0];
+                op.packet = (void *)pp_data[0];
                 if( pi_size[0] <= 0 )
                     msg_Err( p_mux, "header data corrupted");
 
@@ -1187,8 +1188,9 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
             p_stream->fmt.i_codec == VLC_CODEC_DAALA )
         {
             unsigned pi_size[XIPH_MAX_HEADER_COUNT];
-            void     *pp_data[XIPH_MAX_HEADER_COUNT];
+            const void *pp_data[XIPH_MAX_HEADER_COUNT];
             unsigned i_count;
+
             if( xiph_SplitHeaders( pi_size, pp_data, &i_count,
                                    p_input->p_fmt->i_extra, p_input->p_fmt->p_extra ) )
                 i_count = 0;
@@ -1198,7 +1200,7 @@ static bool OggCreateHeaders( sout_mux_t *p_mux )
             for( unsigned j = 1; j < i_count; j++ )
             {
                 op.bytes  = pi_size[j];
-                op.packet = pp_data[j];
+                op.packet = (void *)pp_data[j];
                 if( pi_size[j] <= 0 )
                     msg_Err( p_mux, "header data corrupted");
 
diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c
index 29032581fd..356abd4eb6 100644
--- a/modules/stream_out/rtpfmt.c
+++ b/modules/stream_out/rtpfmt.c
@@ -72,8 +72,9 @@ static int rtp_xiph_pack_headers(size_t room, void *p_extra, size_t i_extra,
                                  uint8_t *theora_pixel_fmt)
 {
     unsigned packet_size[XIPH_MAX_HEADER_COUNT];
-    void *packet[XIPH_MAX_HEADER_COUNT];
+    const void *packet[XIPH_MAX_HEADER_COUNT];
     unsigned packet_count;
+
     if (xiph_SplitHeaders(packet_size, packet, &packet_count,
                                 i_extra, p_extra))
         return VLC_EGENERIC;;
@@ -84,7 +85,7 @@ static int rtp_xiph_pack_headers(size_t room, void *p_extra, size_t i_extra,
     {
         if (packet_size[0] < 42)
             return VLC_EGENERIC;
-        *theora_pixel_fmt = (((uint8_t *)packet[0])[41] >> 3) & 0x03;
+        *theora_pixel_fmt = (((const uint8_t *)packet[0])[41] >> 3) & 0x03;
     }
 
     unsigned length_size[2] = { 0, 0 };



More information about the vlc-commits mailing list