Commit 721e1cd9 authored by Laurent Aimar's avatar Laurent Aimar

* ffmpeg: some clean. Added a mutex to avoid multiple initialisation.

parent b752c610
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* audio.c: audio decoder using ffmpeg library * audio.c: audio decoder using ffmpeg library
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id: audio.c,v 1.18 2003/04/25 18:57:41 fenrir Exp $ * $Id: audio.c,v 1.19 2003/07/10 01:33:41 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -115,12 +115,10 @@ int E_( InitThread_Audio )( adec_thread_t *p_adec ) ...@@ -115,12 +115,10 @@ int E_( InitThread_Audio )( adec_thread_t *p_adec )
if( ( p_adec->p_context->extradata_size = p_wf->cbSize ) > 0 ) if( ( p_adec->p_context->extradata_size = p_wf->cbSize ) > 0 )
{ {
p_adec->p_context->extradata = p_adec->p_context->extradata = malloc( p_wf->cbSize + FF_INPUT_BUFFER_PADDING_SIZE );
malloc( p_wf->cbSize );
memcpy( p_adec->p_context->extradata, memcpy( p_adec->p_context->extradata, &p_wf[1], p_wf->cbSize);
&p_wf[1], memset( &((uint8_t*)p_adec->p_context->extradata)[p_wf->cbSize], 0, FF_INPUT_BUFFER_PADDING_SIZE );
p_wf->cbSize);
} }
/* ***** Open the codec ***** */ /* ***** Open the codec ***** */
...@@ -182,14 +180,14 @@ void E_( DecodeThread_Audio )( adec_thread_t *p_adec ) ...@@ -182,14 +180,14 @@ void E_( DecodeThread_Audio )( adec_thread_t *p_adec )
if( i_frame_size > 0 ) if( i_frame_size > 0 )
{ {
uint8_t *p_last;
int i_need; int i_need;
i_need = i_frame_size + 16 + p_adec->i_buffer; i_need = i_frame_size + FF_INPUT_BUFFER_PADDING_SIZE + p_adec->i_buffer;
if( p_adec->i_buffer_size < i_need ) if( p_adec->i_buffer_size < i_need )
{ {
p_last = p_adec->p_buffer; uint8_t *p_last = p_adec->p_buffer;
p_adec->p_buffer = malloc( i_need ); p_adec->p_buffer = malloc( i_need );
p_adec->i_buffer_size = i_need; p_adec->i_buffer_size = i_need;
if( p_adec->i_buffer > 0 ) if( p_adec->i_buffer > 0 )
...@@ -203,9 +201,7 @@ void E_( DecodeThread_Audio )( adec_thread_t *p_adec ) ...@@ -203,9 +201,7 @@ void E_( DecodeThread_Audio )( adec_thread_t *p_adec )
i_frame_size, i_frame_size,
p_pes ); p_pes );
/* make ffmpeg happier but I'm not sure it's needed for audio */ /* make ffmpeg happier but I'm not sure it's needed for audio */
memset( p_adec->p_buffer + p_adec->i_buffer + i_frame_size, memset( p_adec->p_buffer + p_adec->i_buffer + i_frame_size, 0, FF_INPUT_BUFFER_PADDING_SIZE );
0,
16 );
} }
input_DeletePES( p_adec->p_fifo->p_packets_mgt, p_pes ); input_DeletePES( p_adec->p_fifo->p_packets_mgt, p_pes );
} while( i_frame_size <= 0 ); } while( i_frame_size <= 0 );
...@@ -242,7 +238,7 @@ usenextdata: ...@@ -242,7 +238,7 @@ usenextdata:
i_frame_size -= i_used; i_frame_size -= i_used;
// msg_Dbg( p_adec->p_fifo, "frame size:%d buffer used:%d", i_frame_size, i_used ); //msg_Dbg( p_adec->p_fifo, "frame size:%d buffer used:%d", i_frame_size, i_used );
if( i_output_size <= 0 ) if( i_output_size <= 0 )
{ {
msg_Warn( p_adec->p_fifo, msg_Warn( p_adec->p_fifo,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ffmpeg.c: video decoder using ffmpeg library * ffmpeg.c: video decoder using ffmpeg library
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id: ffmpeg.c,v 1.44 2003/06/16 20:23:41 gbazin Exp $ * $Id: ffmpeg.c,v 1.45 2003/07/10 01:33:41 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -178,6 +178,7 @@ vlc_module_begin(); ...@@ -178,6 +178,7 @@ vlc_module_begin();
set_callbacks( E_(OpenChroma), NULL ); set_callbacks( E_(OpenChroma), NULL );
set_description( _("ffmpeg chroma conversion") ); set_description( _("ffmpeg chroma conversion") );
var_Create( p_module->p_libvlc, "avcodec", VLC_VAR_MUTEX );
vlc_module_end(); vlc_module_end();
/***************************************************************************** /*****************************************************************************
...@@ -281,10 +282,16 @@ static int RunDecoder( decoder_fifo_t *p_fifo ) ...@@ -281,10 +282,16 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
static int InitThread( generic_thread_t *p_decoder ) static int InitThread( generic_thread_t *p_decoder )
{ {
int i_result; int i_result;
vlc_value_t lockval;
var_Get( p_decoder->p_fifo->p_libvlc, "avcodec", &lockval );
vlc_mutex_lock( lockval.p_address );
/* *** init ffmpeg library (libavcodec) *** */ /* *** init ffmpeg library (libavcodec) *** */
if( !b_ffmpeginit ) if( !b_ffmpeginit )
{ {
avcodec_init(); avcodec_init();
avcodec_register_all(); avcodec_register_all();
b_ffmpeginit = 1; b_ffmpeginit = 1;
...@@ -296,6 +303,7 @@ static int InitThread( generic_thread_t *p_decoder ) ...@@ -296,6 +303,7 @@ static int InitThread( generic_thread_t *p_decoder )
{ {
msg_Dbg( p_decoder->p_fifo, "libavcodec already initialized" ); msg_Dbg( p_decoder->p_fifo, "libavcodec already initialized" );
} }
vlc_mutex_unlock( lockval.p_address );
/* *** determine codec type *** */ /* *** determine codec type *** */
ffmpeg_GetFfmpegCodec( p_decoder->p_fifo->i_fourcc, ffmpeg_GetFfmpegCodec( p_decoder->p_fifo->i_fourcc,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* video.c: video decoder using ffmpeg library * video.c: video decoder using ffmpeg library
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id: video.c,v 1.34 2003/06/28 23:56:31 fenrir Exp $ * $Id: video.c,v 1.35 2003/07/10 01:33:41 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Gildas Bazin <gbazin@netcourrier.com> * Gildas Bazin <gbazin@netcourrier.com>
...@@ -361,10 +361,11 @@ int E_( InitThread_Video )( vdec_thread_t *p_vdec ) ...@@ -361,10 +361,11 @@ int E_( InitThread_Video )( vdec_thread_t *p_vdec )
else else
{ {
p_vdec->p_context->extradata_size = i_size; p_vdec->p_context->extradata_size = i_size;
p_vdec->p_context->extradata = malloc( i_size ); p_vdec->p_context->extradata = malloc( i_size + FF_INPUT_BUFFER_PADDING_SIZE );
memcpy( p_vdec->p_context->extradata, memcpy( p_vdec->p_context->extradata,
&p_vdec->p_format[1], &p_vdec->p_format[1],
i_size ); i_size );
memset( &((uint8_t*)p_vdec->p_context->extradata)[i_size], 0, FF_INPUT_BUFFER_PADDING_SIZE );
} }
} }
p_vdec->p_vout = NULL; p_vdec->p_vout = NULL;
...@@ -477,7 +478,7 @@ void E_( DecodeThread_Video )( vdec_thread_t *p_vdec ) ...@@ -477,7 +478,7 @@ void E_( DecodeThread_Video )( vdec_thread_t *p_vdec )
int i_need; int i_need;
/* XXX Don't forget that ffmpeg required a little more bytes /* XXX Don't forget that ffmpeg required a little more bytes
* that the real frame size */ * that the real frame size */
i_need = i_frame_size + 16 + p_vdec->i_buffer; i_need = i_frame_size + FF_INPUT_BUFFER_PADDING_SIZE + p_vdec->i_buffer;
if( p_vdec->i_buffer_size < i_need) if( p_vdec->i_buffer_size < i_need)
{ {
p_last = p_vdec->p_buffer; p_last = p_vdec->p_buffer;
...@@ -493,9 +494,7 @@ void E_( DecodeThread_Video )( vdec_thread_t *p_vdec ) ...@@ -493,9 +494,7 @@ void E_( DecodeThread_Video )( vdec_thread_t *p_vdec )
E_( GetPESData )( p_vdec->p_buffer + p_vdec->i_buffer, E_( GetPESData )( p_vdec->p_buffer + p_vdec->i_buffer,
i_frame_size , i_frame_size ,
p_pes ); p_pes );
memset( p_vdec->p_buffer + p_vdec->i_buffer + i_frame_size, memset( p_vdec->p_buffer + p_vdec->i_buffer + i_frame_size, 0, FF_INPUT_BUFFER_PADDING_SIZE );
0,
16 );
} }
input_DeletePES( p_vdec->p_fifo->p_packets_mgt, p_pes ); input_DeletePES( p_vdec->p_fifo->p_packets_mgt, p_pes );
} while( i_frame_size <= 0 ); } while( i_frame_size <= 0 );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment