]> git.sesse.net Git - vlc/blobdiff - modules/codec/araw.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / modules / codec / araw.c
index d049be451ba3657de2d208a0b0f0d8db6a9b68d8..c441e82964bc0883666971a86f10a310fdf240e2 100644 (file)
@@ -74,7 +74,7 @@ struct decoder_sys_t
     const int16_t *p_logtos16;  /* used with m/alaw to int16_t */
     int i_bytespersample;
 
-    audio_date_t end_date;
+    date_t end_date;
 };
 
 static const int pi_channels_maps[] =
@@ -191,8 +191,10 @@ static int DecoderOpen( vlc_object_t *p_this )
     case VLC_CODEC_ALAW:
     case VLC_CODEC_MULAW:
 
-    case VLC_CODEC_FL64:
-    case VLC_CODEC_FL32:
+    case VLC_CODEC_F64L:
+    case VLC_CODEC_F64B:
+    case VLC_CODEC_F32L:
+    case VLC_CODEC_F32B:
     case VLC_CODEC_S32L:
     case VLC_CODEC_S32B:
     case VLC_CODEC_S24L:
@@ -232,12 +234,14 @@ static int DecoderOpen( vlc_object_t *p_this )
              p_dec->fmt_in.audio.i_rate, p_dec->fmt_in.audio.i_channels,
              p_dec->fmt_in.audio.i_bitspersample );
 
-    if( p_dec->fmt_in.i_codec == VLC_CODEC_FL64 )
+    if( p_dec->fmt_in.i_codec == VLC_CODEC_F64L ||
+        p_dec->fmt_in.i_codec == VLC_CODEC_F64B )
     {
         p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec;
         p_dec->fmt_in.audio.i_bitspersample = 64;
     }
-    else if( p_dec->fmt_in.i_codec == VLC_CODEC_FL32 )
+    else if( p_dec->fmt_in.i_codec == VLC_CODEC_F32L ||
+             p_dec->fmt_in.i_codec == VLC_CODEC_F32B )
     {
         p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec;
         p_dec->fmt_in.audio.i_bitspersample = 32;
@@ -266,98 +270,29 @@ static int DecoderOpen( vlc_object_t *p_this )
         p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec;
         p_dec->fmt_in.audio.i_bitspersample = 8;
     }
-    else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'f', 'l', 't' ) )
-    {
-        switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
-        {
-        case 4:
-            p_dec->fmt_out.i_codec = VLC_CODEC_FL32;
-            break;
-        case 8:
-            p_dec->fmt_out.i_codec = VLC_CODEC_FL64;
-            break;
-        default:
-            msg_Err( p_dec, "bad parameters(bits/sample)" );
-            return VLC_EGENERIC;
-        }
-    }
-    else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'r', 'a', 'w' ) ||
-             p_dec->fmt_in.i_codec == VLC_FOURCC( 'p', 'c', 'm', ' ' ) )
-    {
-        switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
-        {
-        case 1:
-            p_dec->fmt_out.i_codec = VLC_CODEC_U8;
-            break;
-        case 2:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S16L;
-            break;
-        case 3:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S24L;
-            break;
-        case 4:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S32L;
-            break;
-        default:
-            msg_Err( p_dec, "bad parameters(bits/sample)" );
-            return VLC_EGENERIC;
-        }
-    }
-    else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 't', 'w', 'o', 's' ) )
-    {
-        switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
-        {
-        case 1:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S8;
-            break;
-        case 2:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S16B;
-            break;
-        case 3:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S24B;
-            break;
-        case 4:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S32B;
-            break;
-        default:
-            msg_Err( p_dec, "bad parameters(bits/sample)" );
-            return VLC_EGENERIC;
-        }
-    }
-    else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 's', 'o', 'w', 't' ) )
-    {
-        switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
-        {
-        case 1:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S8;
-            break;
-        case 2:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S16L;
-            break;
-        case 3:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S24L;
-            break;
-        case 4:
-            p_dec->fmt_out.i_codec = VLC_CODEC_S32L;
-            break;
-        default:
-            msg_Err( p_dec, "bad parameters(bits/sample)" );
-            return VLC_EGENERIC;
-        }
-    }
     else if( p_dec->fmt_in.i_codec == VLC_CODEC_ALAW )
     {
-        p_dec->fmt_out.i_codec = AOUT_FMT_S16_NE;
+        p_dec->fmt_out.i_codec = VLC_CODEC_S16N;
         p_sys->p_logtos16  = alawtos16;
         p_dec->fmt_in.audio.i_bitspersample = 8;
     }
     else if( p_dec->fmt_in.i_codec == VLC_CODEC_MULAW )
     {
-        p_dec->fmt_out.i_codec = AOUT_FMT_S16_NE;
+        p_dec->fmt_out.i_codec = VLC_CODEC_S16N;
         p_sys->p_logtos16  = ulawtos16;
         p_dec->fmt_in.audio.i_bitspersample = 8;
     }
-    else return VLC_EGENERIC;
+    else
+    {
+        p_dec->fmt_out.i_codec =
+            vlc_fourcc_GetCodecAudio( p_dec->fmt_in.i_codec,
+                                      p_dec->fmt_in.audio.i_bitspersample );
+        if( !p_dec->fmt_out.i_codec )
+        {
+            msg_Err( p_dec, "bad parameters(bits/sample)" );
+            return VLC_EGENERIC;
+        }
+    }
 
     /* Set output properties */
     p_dec->fmt_out.i_cat = AUDIO_ES;
@@ -380,8 +315,8 @@ static int DecoderOpen( vlc_object_t *p_this )
         p_dec->fmt_out.audio.i_bitspersample = 16;
     }
 
-    aout_DateInit( &p_sys->end_date, p_dec->fmt_out.audio.i_rate );
-    aout_DateSet( &p_sys->end_date, 0 );
+    date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 );
+    date_Set( &p_sys->end_date, 0 );
     p_sys->i_bytespersample = ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8;
 
     p_dec->pf_decode_audio = DecodeBlock;
@@ -405,12 +340,12 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
     p_block = *pp_block;
 
-    if( p_block->i_pts != 0 &&
-        p_block->i_pts != aout_DateGet( &p_sys->end_date ) )
+    if( p_block->i_pts > VLC_TS_INVALID &&
+        p_block->i_pts != date_Get( &p_sys->end_date ) )
     {
-        aout_DateSet( &p_sys->end_date, p_block->i_pts );
+        date_Set( &p_sys->end_date, p_block->i_pts );
     }
-    else if( !aout_DateGet( &p_sys->end_date ) )
+    else if( !date_Get( &p_sys->end_date ) )
     {
         /* We've just started the stream, wait for the first PTS. */
         block_Release( p_block );
@@ -418,7 +353,7 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     }
 
     /* Don't re-use the same pts twice */
-    p_block->i_pts = 0;
+    p_block->i_pts = VLC_TS_INVALID;
 
     i_samples = p_block->i_buffer / p_sys->i_bytespersample /
         p_dec->fmt_in.audio.i_channels;
@@ -439,15 +374,16 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
 
-    p_out->start_date = aout_DateGet( &p_sys->end_date );
-    p_out->end_date   = aout_DateIncrement( &p_sys->end_date, i_samples );
+    p_out->i_pts = date_Get( &p_sys->end_date );
+    p_out->i_length = date_Increment( &p_sys->end_date, i_samples )
+                      - p_out->i_pts;
 
     if( p_sys->p_logtos16 )
     {
         int16_t *s = (int16_t*)p_out->p_buffer;
         unsigned int i;
 
-        for( i = 0; i < p_out->i_nb_bytes / 2; i++ )
+        for( i = 0; i < p_out->i_buffer / 2; i++ )
         {
             *s++ = p_sys->p_logtos16[*p_block->p_buffer++];
             p_block->i_buffer--;
@@ -455,9 +391,9 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     }
     else
     {
-        memcpy( p_out->p_buffer, p_block->p_buffer, p_out->i_nb_bytes );
-        p_block->p_buffer += p_out->i_nb_bytes;
-        p_block->i_buffer -= p_out->i_nb_bytes;
+        memcpy( p_out->p_buffer, p_block->p_buffer, p_out->i_buffer );
+        p_block->p_buffer += p_out->i_buffer;
+        p_block->i_buffer -= p_out->i_buffer;
     }
 
     return p_out;
@@ -1406,13 +1342,13 @@ static int EncoderOpen( vlc_object_t *p_this )
     if( p_enc->fmt_out.i_codec == VLC_CODEC_ALAW)
     {
         p_enc->fmt_in.audio.i_bitspersample = 16;
-        p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE;
+        p_enc->fmt_in.i_codec = VLC_CODEC_S16N;
         p_sys->i_s16tolog = ALAW;
     }
     else if( p_enc->fmt_out.i_codec == VLC_CODEC_MULAW )
     {
         p_enc->fmt_in.audio.i_bitspersample = 16;
-        p_enc->fmt_in.i_codec = AOUT_FMT_S16_NE;
+        p_enc->fmt_in.i_codec = VLC_CODEC_S16N;
         p_sys->i_s16tolog = ULAW;
     }
 
@@ -1444,11 +1380,11 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf )
     encoder_sys_t *p_sys = p_enc->p_sys;
     block_t *p_block = NULL;
 
-    if( !p_aout_buf || !p_aout_buf->i_nb_bytes ) return NULL;
+    if( !p_aout_buf || !p_aout_buf->i_buffer ) return NULL;
 
     if( p_sys->i_s16tolog )
     {
-        if( ( p_block = block_New( p_enc, p_aout_buf->i_nb_bytes / 2 ) ) )
+        if( ( p_block = block_New( p_enc, p_aout_buf->i_buffer / 2 ) ) )
         {
             int8_t *s = (int8_t*)p_block->p_buffer; // sink
             int16_t *aout = (int16_t*)p_aout_buf->p_buffer; // source
@@ -1456,7 +1392,7 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf )
 
             if( p_sys->i_s16tolog == ALAW )
             {
-                for( i = 0; i < p_aout_buf->i_nb_bytes / 2; i++ )
+                for( i = 0; i < p_aout_buf->i_buffer / 2; i++ )
                 {
                     if( *aout >= 0)
                         *s++ = alaw_encode[*aout / 16];
@@ -1468,7 +1404,7 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf )
             }
             else /* ULAW */
             {
-                for( i = 0; i < p_aout_buf->i_nb_bytes / 2; i++ )
+                for( i = 0; i < p_aout_buf->i_buffer / 2; i++ )
                 {
                     if( *aout >= 0)
                         *s++ = ulaw_encode[*aout / 4];
@@ -1480,15 +1416,15 @@ static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf )
             }
         }
     }
-    else if( ( p_block = block_New( p_enc, p_aout_buf->i_nb_bytes ) ) )
+    else if( ( p_block = block_New( p_enc, p_aout_buf->i_buffer ) ) )
     {
         memcpy( p_block->p_buffer, p_aout_buf->p_buffer,
-                p_aout_buf->i_nb_bytes );
+                p_aout_buf->i_buffer );
     }
 
     if( p_block )
     {
-        p_block->i_dts = p_block->i_pts = p_aout_buf->start_date;
+        p_block->i_dts = p_block->i_pts = p_aout_buf->i_pts;
         p_block->i_length = (int64_t)p_aout_buf->i_nb_samples *
             (int64_t)1000000 / p_enc->fmt_in.audio.i_rate;
     }