]> git.sesse.net Git - vlc/blobdiff - modules/codec/flac.c
omxil: get rid of debug ifdefs
[vlc] / modules / codec / flac.c
index 5568fcf155d35d9521029e5e8457b5b92a3f2ff6..b2ee916ab8ce3f6c6632e8eb58d0a1b8ff5dffc8 100644 (file)
@@ -134,7 +134,12 @@ static void Interleave( int32_t *p_out, const int32_t * const *pp_in,
 
     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;
+        {
+            union { int32_t i; uint32_t u; } spl;
+
+            spl.u = ((uint32_t)pp_in[pi_index[i]][j]) << shift;
+            p_out[j * i_nb_channels + i] = spl.i;
+        }
 }
 
 /*****************************************************************************
@@ -233,8 +238,9 @@ static void DecoderMetadataCallback( const FLAC__StreamDecoder *decoder,
     p_dec->fmt_out.audio.i_physical_channels =
         p_dec->fmt_out.audio.i_original_channels =
             pi_channels_maps[metadata->data.stream_info.channels];
-    p_dec->fmt_out.audio.i_bitspersample =
-        metadata->data.stream_info.bits_per_sample;
+    if (!p_dec->fmt_out.audio.i_bitspersample)
+        p_dec->fmt_out.audio.i_bitspersample =
+            metadata->data.stream_info.bits_per_sample;
 
     msg_Dbg( p_dec, "channels:%d samplerate:%d bitspersamples:%d",
              p_dec->fmt_out.audio.i_channels, p_dec->fmt_out.audio.i_rate,
@@ -270,6 +276,10 @@ static void DecoderErrorCallback( const FLAC__StreamDecoder *decoder,
         msg_Err( p_dec, "frame's data did not match the CRC in the "
                  "footer." );
         break;
+    case FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM:
+        msg_Err( p_dec, "The decoder encountered reserved fields in use in "
+                 "the stream." );
+        break;
     default:
         msg_Err( p_dec, "got decoder error: %d", status );
     }
@@ -380,11 +390,18 @@ static void ProcessHeader( decoder_t *p_dec )
     /* Decode STREAMINFO */
     msg_Dbg( p_dec, "decode STREAMINFO" );
     size_t i_extra = p_dec->fmt_in.i_extra;
+    static const char header[4] = { 'f', 'L', 'a', 'C' };
+
+    if (i_extra > 42 && !memcmp(p_dec->fmt_in.p_extra, header, 4))
+        i_extra = 42;
+    else if (i_extra > 34 && memcmp(p_dec->fmt_in.p_extra, header, 4))
+        i_extra = 34;
+
     switch (i_extra) {
     case 34:
         p_sys->p_block = block_Alloc( 8 + i_extra );
         memcpy( p_sys->p_block->p_buffer + 8, p_dec->fmt_in.p_extra, i_extra );
-        memcpy( p_sys->p_block->p_buffer, "fLaC", 4);
+        memcpy( p_sys->p_block->p_buffer, header, 4);
         uint8_t *p = p_sys->p_block->p_buffer;
         p[4] = 0x80 | 0; /* STREAMINFO faked as last block */
         p[5] = 0;
@@ -572,12 +589,15 @@ EncoderWriteCallback( const FLAC__StreamEncoder *encoder,
             msg_Dbg( p_enc, "Writing STREAMINFO: %zu", bytes );
 
             /* Backup the STREAMINFO metadata block */
-            p_enc->fmt_out.i_extra = STREAMINFO_SIZE;
-            p_enc->fmt_out.p_extra = xmalloc( STREAMINFO_SIZE );
-            memcpy(p_enc->fmt_out.p_extra, buffer + 4, STREAMINFO_SIZE );
+            p_enc->fmt_out.i_extra = STREAMINFO_SIZE + 8;
+            p_enc->fmt_out.p_extra = xmalloc( STREAMINFO_SIZE + 8);
+            memcpy(p_enc->fmt_out.p_extra, "fLaC", 4);
+            memcpy((uint8_t*)p_enc->fmt_out.p_extra + 4, buffer, STREAMINFO_SIZE );
+            /* Fake this as the last metadata block */
+            ((uint8_t*)p_enc->fmt_out.p_extra)[4] |= 0x80;
         }
         p_sys->i_headers++;
-        return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+        return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
     }
 
     p_block = block_Alloc( bytes );
@@ -595,7 +615,7 @@ EncoderWriteCallback( const FLAC__StreamEncoder *encoder,
 
     block_ChainAppend( &p_sys->p_chain, p_block );
 
-    return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+    return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
 }
 /*****************************************************************************
  * EncoderMetadataCallback: called by libflac to output metadata
@@ -704,10 +724,10 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
     p_sys->i_samples_delay += p_aout_buf->i_nb_samples;
 
     /* Convert samples to FLAC__int32 */
-    if( p_sys->i_buffer < p_aout_buf->i_buffer * 2 )
+    if( p_sys->i_buffer < p_aout_buf->i_buffer * sizeof(FLAC__int32) )
     {
         p_sys->p_buffer =
-            xrealloc( p_sys->p_buffer, p_aout_buf->i_buffer * 2 );
+            xrealloc( p_sys->p_buffer, p_aout_buf->i_buffer * sizeof(FLAC__int32) );
         p_sys->i_buffer = p_aout_buf->i_buffer * 2;
     }