]> git.sesse.net Git - vlc/blobdiff - modules/codec/flac.c
Qt: use the theme icons for the system tray too
[vlc] / modules / codec / flac.c
index eea32b881eb2389527c5f59129920b822021ab2a..25bc92c51618a33981c1253be93acdf9bba62010 100644 (file)
@@ -37,8 +37,8 @@
 #include <vlc_plugin.h>
 #include <vlc_codec.h>
 
-#include <stream_decoder.h>
-#include <stream_encoder.h>
+#include <FLAC/stream_decoder.h>
+#include <FLAC/stream_encoder.h>
 
 #include <vlc_block_helper.h>
 #include <vlc_bits.h>
@@ -80,8 +80,8 @@ static const int pi_channels_maps[9] =
     AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
      | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE,
     AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
-     | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
-     | AOUT_CHAN_MIDDLERIGHT,
+     | AOUT_CHAN_REARCENTER | AOUT_CHAN_MIDDLELEFT| AOUT_CHAN_MIDDLERIGHT
+     | AOUT_CHAN_LFE,
     AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_REARLEFT
      | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT
      | AOUT_CHAN_LFE
@@ -126,55 +126,15 @@ vlc_module_end ()
 /*****************************************************************************
  * Interleave: helper function to interleave channels
  *****************************************************************************/
-static void Interleave32( int32_t *p_out, const int32_t * const *pp_in,
-                          const int pi_index[],
-                          int i_nb_channels, int i_samples )
+static void Interleave( int32_t *p_out, const int32_t * const *pp_in,
+                        const unsigned char *restrict pi_index, unsigned i_nb_channels,
+                        unsigned i_samples, unsigned bits )
 {
-    int i, j;
-    for ( j = 0; j < i_samples; j++ )
-    {
-        for ( i = 0; i < i_nb_channels; i++ )
-        {
-            p_out[j * i_nb_channels + i] = pp_in[pi_index[i]][j];
-        }
-    }
-}
+    unsigned shift = 32 - bits;
 
-static void Interleave24( int8_t *p_out, const int32_t * const *pp_in,
-                          const int pi_index[],
-                          int i_nb_channels, int i_samples )
-{
-    int i, j;
-    for ( j = 0; j < i_samples; j++ )
-    {
-        for ( i = 0; i < i_nb_channels; i++ )
-        {
-            const int i_index = pi_index[i];
-#ifdef WORDS_BIGENDIAN
-            p_out[3*(j * i_nb_channels + i)+0] = (pp_in[i_index][j] >> 16) & 0xff;
-            p_out[3*(j * i_nb_channels + i)+1] = (pp_in[i_index][j] >> 8 ) & 0xff;
-            p_out[3*(j * i_nb_channels + i)+2] = (pp_in[i_index][j] >> 0 ) & 0xff;
-#else
-            p_out[3*(j * i_nb_channels + i)+2] = (pp_in[i_index][j] >> 16) & 0xff;
-            p_out[3*(j * i_nb_channels + i)+1] = (pp_in[i_index][j] >> 8 ) & 0xff;
-            p_out[3*(j * i_nb_channels + i)+0] = (pp_in[i_index][j] >> 0 ) & 0xff;
-#endif
-        }
-    }
-}
-
-static void Interleave16( int16_t *p_out, const int32_t * const *pp_in,
-                          const int pi_index[],
-                          int i_nb_channels, int i_samples )
-{
-    int i, j;
-    for ( j = 0; j < i_samples; j++ )
-    {
-        for ( i = 0; i < i_nb_channels; i++ )
-        {
-            p_out[j * i_nb_channels + i] = (int32_t)(pp_in[pi_index[i]][j]);
-        }
-    }
+    for( unsigned j = 0; j < i_samples; j++ )
+        for( unsigned i = 0; i < i_nb_channels; i++ )
+            p_out[j * i_nb_channels + i] = pp_in[pi_index[i]][j] << shift;
 }
 
 /*****************************************************************************
@@ -186,17 +146,16 @@ DecoderWriteCallback( const FLAC__StreamDecoder *decoder,
                       const FLAC__int32 *const buffer[], void *client_data )
 {
     /* XXX it supposes our internal format is WG4 */
-    static const int ppi_reorder[1+8][8] = {
-        {-1},
+    static const unsigned char ppi_reorder[1+8][8] = {
+        { },
         { 0, },
         { 0, 1 },
         { 0, 1, 2 },
         { 0, 1, 2, 3 },
         { 0, 1, 3, 4, 2 },
         { 0, 1, 4, 5, 2, 3 },
-
-        { 0, 1, 6, 4, 5, 2, 3 },    /* 7.0 Unspecified by flac, but following SMPTE */
-        { 0, 1, 6, 7, 4, 5, 2, 3 }, /* 7.1 Unspecified by flac, but following SMPTE */
+        { 0, 1, 5, 6, 4, 2, 3 },
+        { 0, 1, 6, 7, 4, 5, 2, 3 },
     };
 
     VLC_UNUSED(decoder);
@@ -209,7 +168,7 @@ DecoderWriteCallback( const FLAC__StreamDecoder *decoder,
     if( date_Get( &p_sys->end_date ) <= VLC_TS_INVALID )
         return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
 
-    const int * const pi_reorder = ppi_reorder[p_dec->fmt_out.audio.i_channels];
+    const unsigned char *pi_reorder = ppi_reorder[p_dec->fmt_out.audio.i_channels];
 
     p_sys->p_aout_buffer =
         decoder_NewAudioBuffer( p_dec, frame->header.blocksize );
@@ -217,20 +176,9 @@ DecoderWriteCallback( const FLAC__StreamDecoder *decoder,
     if( p_sys->p_aout_buffer == NULL )
         return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
 
-    switch( frame->header.bits_per_sample )
-    {
-    case 16:
-        Interleave16( (int16_t *)p_sys->p_aout_buffer->p_buffer, buffer, pi_reorder,
-                      frame->header.channels, frame->header.blocksize );
-        break;
-    case 24:
-        Interleave24( (int8_t *)p_sys->p_aout_buffer->p_buffer, buffer, pi_reorder,
-                      frame->header.channels, frame->header.blocksize );
-        break;
-    default:
-        Interleave32( (int32_t *)p_sys->p_aout_buffer->p_buffer, buffer, pi_reorder,
-                      frame->header.channels, frame->header.blocksize );
-    }
+    Interleave( (int32_t *)p_sys->p_aout_buffer->p_buffer, buffer, pi_reorder,
+                 frame->header.channels, frame->header.blocksize,
+                 frame->header.bits_per_sample );
 
     /* Date management (already done by packetizer) */
     p_sys->p_aout_buffer->i_pts = date_Get( &p_sys->end_date );
@@ -279,27 +227,6 @@ static void DecoderMetadataCallback( const FLAC__StreamDecoder *decoder,
     decoder_t *p_dec = (decoder_t *)client_data;
     decoder_sys_t *p_sys = p_dec->p_sys;
 
-    if( p_dec->pf_decode_audio )
-    {
-        switch( metadata->data.stream_info.bits_per_sample )
-        {
-        case 8:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S8;
-            break;
-        case 16:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S16N;
-            break;
-        case 24:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S24N;
-            break;
-        default:
-            msg_Dbg( p_dec, "strange bit/sample value: %d",
-                     metadata->data.stream_info.bits_per_sample );
-            p_dec->fmt_out.i_codec = VLC_CODEC_FI32;
-            break;
-        }
-    }
-
     /* Setup the format */
     p_dec->fmt_out.audio.i_rate     = metadata->data.stream_info.sample_rate;
     p_dec->fmt_out.audio.i_channels = metadata->data.stream_info.channels;
@@ -413,7 +340,7 @@ static int OpenDecoder( vlc_object_t *p_this )
 
     /* Set output properties */
     p_dec->fmt_out.i_cat = AUDIO_ES;
-    p_dec->fmt_out.i_codec = VLC_CODEC_FL32;
+    p_dec->fmt_out.i_codec = VLC_CODEC_S32N;
 
     /* Set callbacks */
     p_dec->pf_decode_audio = DecodeBlock;