]> git.sesse.net Git - vlc/blobdiff - modules/codec/ffmpeg/audio.c
* don't add an 'empty folder' if the user hit cancel when asked to enter a name for it
[vlc] / modules / codec / ffmpeg / audio.c
index 967594494606b64d3c72bdfbeaa327e0b0d2831d..0153a0c741266216cf0ce0a8929a15044abb062d 100644 (file)
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
 #include <vlc/vlc.h>
-#include <vlc/decoder.h>
+#include <vlc_aout.h>
+#include <vlc_codec.h>
 
 /* ffmpeg header */
 #ifdef HAVE_FFMPEG_AVCODEC_H
@@ -58,7 +59,7 @@ struct decoder_sys_t
     /* Common part between video and audio decoder */
     int i_cat;
     int i_codec_id;
-    char *psz_namecodec;
+    const char *psz_namecodec;
     AVCodecContext      *p_context;
     AVCodec             *p_codec;
 
@@ -84,12 +85,12 @@ struct decoder_sys_t
  * The ffmpeg codec will be opened, some memory allocated.
  *****************************************************************************/
 int E_(InitAudioDec)( decoder_t *p_dec, AVCodecContext *p_context,
-                      AVCodec *p_codec, int i_codec_id, char *psz_namecodec )
+                      AVCodec *p_codec, int i_codec_id, const char *psz_namecodec )
 {
     decoder_sys_t *p_sys;
     vlc_value_t lockval;
 
-    var_Get( p_dec->p_libvlc, "avcodec", &lockval );
+    var_Get( p_dec->p_libvlc_global, "avcodec", &lockval );
 
     /* Allocate the memory needed to store the decoder's structure */
     if( ( p_dec->p_sys = p_sys =
@@ -143,7 +144,7 @@ int E_(InitAudioDec)( decoder_t *p_dec, AVCodecContext *p_context,
 
     msg_Dbg( p_dec, "ffmpeg codec (%s) started", p_sys->psz_namecodec );
 
-    p_sys->p_output = malloc( 3 * AVCODEC_MAX_AUDIO_FRAME_SIZE );
+    p_sys->p_output = malloc( AVCODEC_MAX_AUDIO_FRAME_SIZE );
     p_sys->p_samples = NULL;
     p_sys->i_samples = 0;
 
@@ -165,7 +166,7 @@ int E_(InitAudioDec)( decoder_t *p_dec, AVCodecContext *p_context,
  * SplitBuffer: Needed because aout really doesn't like big audio chunk and
  * wma produces easily > 30000 samples...
  *****************************************************************************/
-aout_buffer_t *SplitBuffer( decoder_t *p_dec )
+static aout_buffer_t *SplitBuffer( decoder_t *p_dec )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
     int i_samples = __MIN( p_sys->i_samples, 4096 );
@@ -219,12 +220,19 @@ aout_buffer_t *E_( DecodeAudio )( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
 
-    if( p_block->i_buffer <= 0 || ( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
+    if( p_block->i_buffer <= 0 ||
+        (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) )
     {
         block_Release( p_block );
         return NULL;
     }
 
+    if( p_block->i_buffer > AVCODEC_MAX_AUDIO_FRAME_SIZE )
+    {
+        /* Grow output buffer if necessary (eg. for PCM data) */
+        p_sys->p_output = realloc(p_sys->p_output, p_block->i_buffer);
+    }
+
     i_used = avcodec_decode_audio( p_sys->p_context,
                                    (int16_t*)p_sys->p_output, &i_output,
                                    p_block->p_buffer, p_block->i_buffer );