]> git.sesse.net Git - vlc/blobdiff - modules/codec/wmafixed/wma.c
LGPL
[vlc] / modules / codec / wmafixed / wma.c
index a67e6eb8bcdbab29238f9a2dddc965b5c112f1ba..0e678145631cdf9ba67b53e61e3f05894cc6d9fb 100644 (file)
@@ -5,19 +5,19 @@
  *
  * Authors: Rafaël Carré <rcarre@m2x.nl>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -30,7 +30,6 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_codec.h>
-#include <vlc_aout.h>
 #include <vlc_block_helper.h>
 #include <vlc_bits.h>
 
@@ -43,7 +42,7 @@
  *****************************************************************************/
 struct decoder_sys_t
 {
-    audio_date_t end_date; /* To set the PTS */
+    date_t end_date; /* To set the PTS */
     WMADecodeContext wmadec; /* name is self explanative */
 
     int32_t *p_output; /* buffer where the frames are rendered */
@@ -72,7 +71,7 @@ static unsigned int pi_channels_maps[7] =
 static int  OpenDecoder   ( vlc_object_t * );
 static void CloseDecoder  ( vlc_object_t * );
 
-static aout_buffer_t *DecodeFrame  ( decoder_t *, block_t ** );
+static block_t *DecodeFrame( decoder_t *, block_t ** );
 
 /*****************************************************************************
  * Module descriptor
@@ -81,7 +80,7 @@ vlc_module_begin();
     set_category( CAT_INPUT );
     set_subcategory( SUBCAT_INPUT_ACODEC );
     set_description( _("WMA v1/v2 fixed point audio decoder") );
-    set_capability( "decoder", 50 );
+    set_capability( "decoder", 80 );
     add_shortcut( "wmafixed" )
     set_callbacks( OpenDecoder, CloseDecoder );
 vlc_module_end();
@@ -90,22 +89,23 @@ vlc_module_end();
  * SplitBuffer: Needed because aout really doesn't like big audio chunk and
  * wma produces easily > 30000 samples...
  *****************************************************************************/
-static aout_buffer_t *SplitBuffer( decoder_t *p_dec )
+static block_t *SplitBuffer( decoder_t *p_dec )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
     unsigned int i_samples = __MIN( p_sys->i_samples, 2048 );
-    aout_buffer_t *p_buffer;
+    block_t *p_buffer;
 
     if( i_samples == 0 ) return NULL;
 
-    if( !( p_buffer = p_dec->pf_aout_buffer_new( p_dec, i_samples ) ) )
+    if( !( p_buffer = decoder_NewAudioBuffer( p_dec, i_samples ) ) )
         return NULL;
 
-    p_buffer->start_date = aout_DateGet( &p_sys->end_date );
-    p_buffer->end_date = aout_DateIncrement( &p_sys->end_date, i_samples );
+    p_buffer->i_pts = date_Get( &p_sys->end_date );
+    p_buffer->i_length = date_Increment( &p_sys->end_date, i_samples )
+                         - p_buffer->i_pts;
 
-    memcpy( p_buffer->p_buffer, p_sys->p_samples, p_buffer->i_nb_bytes );
-    p_sys->p_samples += p_buffer->i_nb_bytes;
+    memcpy( p_buffer->p_buffer, p_sys->p_samples, p_buffer->i_buffer );
+    p_sys->p_samples += p_buffer->i_buffer;
     p_sys->i_samples -= i_samples;
 
     return p_buffer;
@@ -133,7 +133,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     memset( p_sys, 0, sizeof( decoder_sys_t ) );
 
     /* Date */
-    aout_DateInit( &p_sys->end_date, p_dec->fmt_in.audio.i_rate );
+    date_Init( &p_sys->end_date, p_dec->fmt_in.audio.i_rate, 1 );
 
     /* Set output properties */
     p_dec->fmt_out.i_cat = AUDIO_ES;
@@ -191,14 +191,11 @@ static int OpenDecoder( vlc_object_t *p_this )
 /*****************************************************************************
  * DecodeFrame: decodes a wma frame.
  *****************************************************************************/
-static aout_buffer_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
+static block_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
     block_t       *p_block;
-    aout_buffer_t *p_aout_buffer = NULL;
-#ifdef NDEBUG
-    mtime_t start = mdate(); /* for statistics */
-#endif
+    block_t       *p_aout_buffer = NULL;
 
     if( !pp_block || !*pp_block ) return NULL;
 
@@ -206,7 +203,7 @@ static aout_buffer_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
 
     if( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
     {
-        aout_DateSet( &p_sys->end_date, 0 );
+        date_Set( &p_sys->end_date, 0 );
         block_Release( p_block );
         *pp_block = NULL;
         return NULL;
@@ -228,14 +225,14 @@ static aout_buffer_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
     }
 
     /* Date management */
-    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 );
         /* don't reuse the same pts */
-        p_block->i_pts = 0;
+        p_block->i_pts = VLC_TS_INVALID;
     }
-    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 );
@@ -261,8 +258,7 @@ static aout_buffer_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
 
     /* worst case */
     size_t i_buffer = BLOCK_MAX_SIZE * MAX_CHANNELS * p_sys->wmadec.nb_frames;
-    if( p_sys->p_output )
-        free( p_sys->p_output );
+    free( p_sys->p_output );
     p_sys->p_output = malloc(i_buffer * sizeof(int32_t) );
     p_sys->p_samples = (int8_t*)p_sys->p_output;
 
@@ -302,9 +298,6 @@ static aout_buffer_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
     p_aout_buffer = SplitBuffer( p_dec );
     assert( p_aout_buffer );
 
-#ifdef NDEBUG
-    msg_Dbg( p_dec, "%s took %"PRIi64" us",__func__,mdate()-start);
-#endif
     return p_aout_buffer;
 }