[vlc-commits] [Git][videolan/vlc][master] 6 commits: mux/avi: use es_format_category_e for the stream category

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Sep 16 11:00:48 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
be6d9a89 by Steve Lhomme at 2023-09-16T10:42:39+00:00
mux/avi: use es_format_category_e for the stream category

- - - - -
b7e097a2 by Steve Lhomme at 2023-09-16T10:42:39+00:00
mux/avi: split VLC_BITMAPINFOHEADER creation from extra data

The extra can either be empty (BI_RGB), contain 3 color masks (BI_BITFIELD) or
a palette buffer.

- - - - -
f6e55c88 by Steve Lhomme at 2023-09-16T10:42:39+00:00
mux/avi: always have a VLC_BITMAPINFOHEADER

It's either that or a WAVEFORMATEX.

- - - - -
52247542 by Steve Lhomme at 2023-09-16T10:42:39+00:00
mux/avi: split WAVEFORMATEX creation from extra data

- - - - -
5bef6fe9 by Steve Lhomme at 2023-09-16T10:42:39+00:00
mux/avi: always have a WAVEFORMATEX

It's either that or a VLC_BITMAPINFOHEADER.

- - - - -
f630d448 by Steve Lhomme at 2023-09-16T10:42:39+00:00
mux/avi: use a union to split audio and video structures.

That will save a bit of space. The structure data are exclusive based on i_cat.

- - - - -


2 changed files:

- modules/demux/avi/bitmapinfoheader.h
- modules/mux/avi.c


Changes:

=====================================
modules/demux/avi/bitmapinfoheader.h
=====================================
@@ -248,8 +248,10 @@ static inline int ParseBitmapInfoHeader( VLC_BITMAPINFOHEADER *p_bih, size_t i_b
     return VLC_SUCCESS;
 }
 
-static inline VLC_BITMAPINFOHEADER * CreateBitmapInfoHeader( const es_format_t *fmt,
-                                                             size_t *pi_total )
+static inline int CreateBitmapInfoHeader( const es_format_t *fmt,
+                                          VLC_BITMAPINFOHEADER *p_bih,
+                                          uint8_t **p_bih_extra,
+                                          size_t *pi_total )
 {
     uint16_t biBitCount = 0;
     uint32_t biCompression = BI_RGB;
@@ -308,13 +310,11 @@ static inline VLC_BITMAPINFOHEADER * CreateBitmapInfoHeader( const es_format_t *
     else
         i_bih_extra = fmt->i_extra;
 
-    VLC_BITMAPINFOHEADER *p_bih = malloc( sizeof(VLC_BITMAPINFOHEADER) +
-                                          i_bih_extra +  i_bmiColors );
-    if( p_bih == NULL )
-        return NULL;
+    *p_bih_extra = malloc( i_bih_extra + i_bmiColors );
+    if( *p_bih_extra == NULL && (i_bih_extra + i_bmiColors) != 0 )
+        return VLC_ENOMEM;
 
-    uint8_t *p_bih_extra = (uint8_t *) &p_bih[1];
-    uint8_t *p_bmiColors = p_bih_extra + i_bih_extra;
+    uint8_t *p_bmiColors = *p_bih_extra;
     p_bih->biClrUsed = 0;
     if( biCompression == BI_BITFIELDS )
     {
@@ -343,7 +343,7 @@ static inline VLC_BITMAPINFOHEADER * CreateBitmapInfoHeader( const es_format_t *
     }
     else if( fmt->i_extra )
     {
-        memcpy( p_bih_extra, fmt->p_extra, fmt->i_extra );
+        memcpy( *p_bih_extra, fmt->p_extra, fmt->i_extra );
     }
 
     p_bih->biSize = sizeof(VLC_BITMAPINFOHEADER) + i_bih_extra;
@@ -357,6 +357,6 @@ static inline VLC_BITMAPINFOHEADER * CreateBitmapInfoHeader( const es_format_t *
     p_bih->biYPelsPerMeter = 0;
     p_bih->biClrImportant = 0;
 
-    *pi_total = sizeof(VLC_BITMAPINFOHEADER) + i_bih_extra +  i_bmiColors;
-    return p_bih;
+    *pi_total = i_bih_extra + i_bmiColors;
+    return VLC_SUCCESS;
 }


=====================================
modules/mux/avi.c
=====================================
@@ -88,7 +88,7 @@ static int Mux      ( sout_mux_t * );
 
 typedef struct avi_stream_s
 {
-    int i_cat;
+    enum es_format_category_e i_cat;
 
     char fcc[4];
 
@@ -100,9 +100,17 @@ typedef struct avi_stream_s
     float   f_fps;
     int     i_bitrate;
 
-    VLC_BITMAPINFOHEADER    *p_bih;
-    size_t                   i_bih;
-    WAVEFORMATEX            *p_wf;
+    union {
+        struct {
+            VLC_BITMAPINFOHEADER  bih;
+            uint8_t               *p_bitmap_extra;
+            size_t                 i_bitmap_extra;
+        };
+        struct {
+            uint8_t               *p_wav_extra;
+            WAVEFORMATEX          wf;
+        };
+    };
 
 } avi_stream_t;
 
@@ -259,8 +267,10 @@ static void Close( vlc_object_t * p_this )
     {
         avi_stream_t *p_stream;
         p_stream = &p_sys->stream[i_stream];
-        free( p_stream->p_bih );
-        free( p_stream->p_wf );
+        if ( p_stream->i_cat == VIDEO_ES )
+            free( p_stream->p_bitmap_extra );
+        else if ( p_stream->i_cat == AUDIO_ES )
+            free( p_stream->p_wav_extra );
     }
     free( p_sys->idx1.entry );
     free( p_sys );
@@ -316,23 +326,21 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
             p_stream->fcc[1] = '0' + p_sys->i_streams % 10;
             p_stream->fcc[2] = 'w';
             p_stream->fcc[3] = 'b';
+            p_stream->p_wav_extra = NULL;
 
-            p_stream->p_bih = NULL;
-            p_stream->i_bih = 0;
-
-            WAVEFORMATEX *p_wf  = malloc( sizeof( WAVEFORMATEX ) +
-                                  p_input->p_fmt->i_extra );
-            if( !p_wf )
-            {
-                free( p_input->p_sys );
-                p_input->p_sys = NULL;
-                return VLC_ENOMEM;
-            }
+            WAVEFORMATEX *p_wf = &p_stream->wf;
 
             p_wf->cbSize = p_input->p_fmt->i_extra;
             if( p_wf->cbSize > 0 )
             {
-                memcpy( &p_wf[1],
+                p_stream->p_wav_extra = malloc( p_wf->cbSize );
+                if ( unlikely(p_stream->p_wav_extra == NULL) )
+                {
+                    free( p_input->p_sys );
+                    p_input->p_sys = NULL;
+                    return VLC_ENOMEM;
+                }
+                memcpy( p_stream->p_wav_extra,
                         p_input->p_fmt->p_extra,
                         p_input->p_fmt->i_extra );
             }
@@ -405,12 +413,11 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
                                       p_wf->nSamplesPerSec * p_wf->nChannels;
                     break;
                 default:
-                    free( p_wf );
+                    free( p_stream->p_wav_extra );
                     free( p_input->p_sys );
                     p_input->p_sys = NULL;
                     return VLC_EGENERIC;
             }
-            p_stream->p_wf = p_wf;
             break;
         case VIDEO_ES:
             p_stream->i_cat = VIDEO_ES;
@@ -418,13 +425,14 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
             p_stream->fcc[1] = '0' + p_sys->i_streams % 10;
             p_stream->fcc[2] = 'd';
             p_stream->fcc[3] = 'c';
+            p_stream->p_bitmap_extra = NULL;
             if( p_sys->i_stream_video < 0 )
             {
                 p_sys->i_stream_video = p_sys->i_streams;
             }
-            p_stream->p_wf  = NULL;
-            p_stream->p_bih = CreateBitmapInfoHeader( &p_input->fmt, &p_stream->i_bih );
-            if( !p_stream->p_bih )
+            if( CreateBitmapInfoHeader( &p_input->fmt, &p_stream->bih,
+                                        &p_stream->p_bitmap_extra,
+                                        &p_stream->i_bitmap_extra ) != VLC_SUCCESS )
             {
                 free( p_input->p_sys );
                 p_input->p_sys = NULL;
@@ -463,22 +471,21 @@ static int PrepareSamples( const avi_stream_t *p_stream,
     {
        /* Add header present at the end of BITMAP info header
           to first frame in case of XVID */
-       if( p_stream->p_bih->biCompression == VLC_FOURCC( 'X', 'V', 'I', 'D' ) )
+       if( p_stream->bih.biCompression == VLC_FOURCC( 'X', 'V', 'I', 'D' ) )
        {
-           size_t i_header_length =
-               p_stream->p_bih->biSize - sizeof(VLC_BITMAPINFOHEADER);
+           size_t i_header_length = p_stream->i_bitmap_extra;
            *pp_block = block_Realloc( *pp_block, i_header_length,
                                       (*pp_block)->i_buffer );
            if( !*pp_block )
                return VLC_ENOMEM;
-           memcpy((*pp_block)->p_buffer,&p_stream->p_bih[1], i_header_length);
+           memcpy((*pp_block)->p_buffer,p_stream->p_bitmap_extra, i_header_length);
        }
     }
 
     /* RV24 is only BGR in AVI, and we can't use BI_BITFIELD */
     if( p_stream->i_cat == VIDEO_ES &&
-        p_stream->p_bih->biCompression == BI_RGB &&
-        p_stream->p_bih->biBitCount == 24 &&
+        p_stream->bih.biCompression == BI_RGB &&
+        p_stream->bih.biBitCount == 24 &&
         (p_fmt->video.i_bmask != 0xFF0000 ||
          p_fmt->video.i_rmask != 0x0000FF) )
     {
@@ -684,8 +691,8 @@ static int avi_HeaderAdd_avih( sout_mux_t *p_mux,
     bo_add_32le( p_bo, 1024 * 1024 );         /* suggested buffer size */
     if( p_video )
     {
-        bo_add_32le( p_bo, p_video->p_bih->biWidth );
-        bo_add_32le( p_bo, p_video->p_bih->biHeight );
+        bo_add_32le( p_bo, p_video->bih.biWidth );
+        bo_add_32le( p_bo, p_video->bih.biHeight );
     }
     else
     {
@@ -708,13 +715,13 @@ static int avi_HeaderAdd_strh( bo_t *p_bo, avi_stream_t *p_stream )
         case VIDEO_ES:
             {
                 bo_add_fourcc( p_bo, "vids" );
-                if( p_stream->p_bih->biBitCount )
+                if( p_stream->bih.biBitCount )
                     bo_add_fourcc( p_bo, "DIB " );
                 else
 #ifdef WORDS_BIGENDIAN
-                bo_add_32be( p_bo, p_stream->p_bih->biCompression );
+                bo_add_32be( p_bo, p_stream->bih.biCompression );
 #else
-                bo_add_32le( p_bo, p_stream->p_bih->biCompression );
+                bo_add_32le( p_bo, p_stream->bih.biCompression );
 #endif
                 bo_add_32le( p_bo, 0 );   /* flags */
                 bo_add_16le(  p_bo, 0 );   /* priority */
@@ -729,15 +736,15 @@ static int avi_HeaderAdd_strh( bo_t *p_bo, avi_stream_t *p_stream )
                 bo_add_32le( p_bo, 0 );   /* samplesize */
                 bo_add_16le(  p_bo, 0 );   /* ??? */
                 bo_add_16le(  p_bo, 0 );   /* ??? */
-                bo_add_16le(  p_bo, p_stream->p_bih->biWidth );
-                bo_add_16le(  p_bo, p_stream->p_bih->biHeight );
+                bo_add_16le(  p_bo, p_stream->bih.biWidth );
+                bo_add_16le(  p_bo, p_stream->bih.biHeight );
             }
             break;
         case AUDIO_ES:
             {
                 int i_rate, i_scale, i_samplesize;
 
-                i_samplesize = p_stream->p_wf->nBlockAlign;
+                i_samplesize = p_stream->wf.nBlockAlign;
                 if( i_samplesize > 1 )
                 {
                     i_scale = i_samplesize;
@@ -768,6 +775,9 @@ static int avi_HeaderAdd_strh( bo_t *p_bo, avi_stream_t *p_stream )
                 bo_add_16le(  p_bo, 0 );
             }
             break;
+        default:
+            // unsupported track type
+            break;
     }
 
     AVI_BOX_EXIT( 0 );
@@ -780,34 +790,35 @@ static int avi_HeaderAdd_strf( bo_t *p_bo, avi_stream_t *p_stream )
     switch( p_stream->i_cat )
     {
         case AUDIO_ES:
-            bo_add_16le( p_bo, p_stream->p_wf->wFormatTag );
-            bo_add_16le( p_bo, p_stream->p_wf->nChannels );
-            bo_add_32le( p_bo, p_stream->p_wf->nSamplesPerSec );
-            bo_add_32le( p_bo, p_stream->p_wf->nAvgBytesPerSec );
-            bo_add_16le( p_bo, p_stream->p_wf->nBlockAlign );
-            bo_add_16le( p_bo, p_stream->p_wf->wBitsPerSample );
-            bo_add_16le( p_bo, p_stream->p_wf->cbSize );
-            bo_add_mem( p_bo, p_stream->p_wf->cbSize, (uint8_t*)&p_stream->p_wf[1] );
+            bo_add_16le( p_bo, p_stream->wf.wFormatTag );
+            bo_add_16le( p_bo, p_stream->wf.nChannels );
+            bo_add_32le( p_bo, p_stream->wf.nSamplesPerSec );
+            bo_add_32le( p_bo, p_stream->wf.nAvgBytesPerSec );
+            bo_add_16le( p_bo, p_stream->wf.nBlockAlign );
+            bo_add_16le( p_bo, p_stream->wf.wBitsPerSample );
+            bo_add_16le( p_bo, p_stream->wf.cbSize );
+            bo_add_mem( p_bo, p_stream->wf.cbSize, p_stream->p_wav_extra );
             break;
         case VIDEO_ES:
-            bo_add_32le( p_bo, p_stream->p_bih->biSize );
-            bo_add_32le( p_bo, p_stream->p_bih->biWidth );
-            bo_add_32le( p_bo, p_stream->p_bih->biHeight );
-            bo_add_16le( p_bo, p_stream->p_bih->biPlanes );
-            bo_add_16le( p_bo, p_stream->p_bih->biBitCount );
+            bo_add_32le( p_bo, p_stream->bih.biSize );
+            bo_add_32le( p_bo, p_stream->bih.biWidth );
+            bo_add_32le( p_bo, p_stream->bih.biHeight );
+            bo_add_16le( p_bo, p_stream->bih.biPlanes );
+            bo_add_16le( p_bo, p_stream->bih.biBitCount );
 #ifdef WORDS_BIGENDIAN
-                bo_add_32be( p_bo, p_stream->p_bih->biCompression );
+                bo_add_32be( p_bo, p_stream->bih.biCompression );
 #else
-                bo_add_32le( p_bo, p_stream->p_bih->biCompression );
+                bo_add_32le( p_bo, p_stream->bih.biCompression );
 #endif
-            bo_add_32le( p_bo, p_stream->p_bih->biSizeImage );
-            bo_add_32le( p_bo, p_stream->p_bih->biXPelsPerMeter );
-            bo_add_32le( p_bo, p_stream->p_bih->biYPelsPerMeter );
-            bo_add_32le( p_bo, p_stream->p_bih->biClrUsed );
-            bo_add_32le( p_bo, p_stream->p_bih->biClrImportant );
-            bo_add_mem( p_bo,
-                        p_stream->i_bih - sizeof( VLC_BITMAPINFOHEADER ),
-                        (uint8_t*)&p_stream->p_bih[1] );
+            bo_add_32le( p_bo, p_stream->bih.biSizeImage );
+            bo_add_32le( p_bo, p_stream->bih.biXPelsPerMeter );
+            bo_add_32le( p_bo, p_stream->bih.biYPelsPerMeter );
+            bo_add_32le( p_bo, p_stream->bih.biClrUsed );
+            bo_add_32le( p_bo, p_stream->bih.biClrImportant );
+            bo_add_mem( p_bo, p_stream->i_bitmap_extra, p_stream->p_bitmap_extra );
+            break;
+        default:
+            // unsupported track type
             break;
     }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6040a1df198f48acae5f82891bd76858d08b3fca...f630d44842faafeeb20204bca2ea735a6a7fb1dc

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6040a1df198f48acae5f82891bd76858d08b3fca...f630d44842faafeeb20204bca2ea735a6a7fb1dc
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list