diff --git a/dec_audio.c b/dec_audio.c index e2f2a281a2..85711ea338 100644 --- a/dec_audio.c +++ b/dec_audio.c @@ -43,8 +43,16 @@ int fakemono=0; #include #endif +#ifdef USE_LIBAVCODEC +#include "libavcodec/avcodec.h" + static AVCodec *lavc_codec=NULL; + static AVCodecContext lavc_context; + extern int avcodec_inited; +#endif + extern int init_acm_audio_codec(sh_audio_t *sh_audio); extern int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int minlen,int maxlen); +int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen); static sh_audio_t* dec_audio_sh=NULL; @@ -163,6 +171,15 @@ case AFM_MPEG: // MPEG Audio: sh_audio->audio_out_minsize=4608; break; +case AFM_FFMPEG: +#ifndef USE_LIBAVCODEC + mp_msg(MSGT_DECAUDIO,MSGL_ERR,"MPlayer was compiled WITHOUT libavcodec support!\n"); + return 0; +#else + // FFmpeg Audio: + sh_audio->audio_out_minsize=AVCODEC_MAX_AUDIO_FRAME_SIZE; + break; +#endif } if(!driver) return 0; @@ -275,6 +292,44 @@ case AFM_ALAW: { sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate; break; } +#ifdef USE_LIBAVCODEC +case AFM_FFMPEG: { + int x; + mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n"); + if(!avcodec_inited){ + avcodec_init(); + avcodec_register_all(); + avcodec_inited=1; + } + lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_audio->codec->dll); + if(!lavc_codec){ + mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Can't find codec '%s' in libavcodec...\n",sh_audio->codec->dll); + return 0; + } + memset(&lavc_context, 0, sizeof(lavc_context)); + /* open it */ + if (avcodec_open(&lavc_context, lavc_codec) < 0) { + mp_msg(MSGT_DECAUDIO,MSGL_ERR, "could not open codec\n"); + return 0; + } + mp_msg(MSGT_DECAUDIO,MSGL_V,"INFO: libavcodec init OK!\n"); + + // Decode at least 1 byte: (to get header filled) + x=decode_audio(sh_audio,sh_audio->a_buffer,1,sh_audio->a_buffer_size); + if(x>0) sh_audio->a_buffer_len=x; + +#if 1 + sh_audio->channels=lavc_context.channels; + sh_audio->samplerate=lavc_context.sample_rate; + sh_audio->i_bps=lavc_context.bit_rate/8; +#else + sh_audio->channels=sh_audio->wf->nChannels; + sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; + sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; +#endif + break; +} +#endif case AFM_GSM: { // MS-GSM audio codec: GSM_Init(); @@ -448,6 +503,27 @@ if(!sh_audio->channels || !sh_audio->samplerate){ int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){ int len=-1; switch(sh_audio->codec->driver){ +#ifdef USE_LIBAVCODEC + case AFM_FFMPEG: { + unsigned char *start=NULL; + int y; + while(lends,&start); + if(x<=0) break; // error + y=avcodec_decode_audio(&lavc_context,buf,&len2,start,x); + if(y<0){ printf("lavc_audio: error\n");break; } + if(yds->buffer_pos+=y-x; // put back data (HACK!) + if(len2>0){ + //len=len2;break; + if(len<0) len=len2; else len+=len2; + buf+=len2; + } + mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"Decoded %d -> %d \n",y,len2); + } + } + break; +#endif case AFM_MPEG: // MPEG layer 2 or 3 len=MP3_DecodeFrame(buf,-1); // len=MP3_DecodeFrame(buf,3); diff --git a/dec_video.c b/dec_video.c index 0898b5d6d8..13a3ad221b 100644 --- a/dec_video.c +++ b/dec_video.c @@ -50,9 +50,10 @@ extern int init_video_codec(sh_video_t *sh_video,int ex); #ifdef USE_LIBAVCODEC #include "libavcodec/avcodec.h" - AVCodec *lavc_codec=NULL; - AVCodecContext lavc_context; - AVPicture lavc_picture; + static AVCodec *lavc_codec=NULL; + static AVCodecContext lavc_context; + static AVPicture lavc_picture; + int avcodec_inited=0; #endif #ifndef NEW_DECORE @@ -306,7 +307,6 @@ switch(sh_video->codec->driver){ mp_msg(MSGT_DECVIDEO,MSGL_ERR,"MPlayer was compiled WITHOUT libavcodec support!\n"); return 0; #else - static int avcodec_inited=0; mp_msg(MSGT_DECVIDEO,MSGL_V,"FFmpeg's libavcodec video codec\n"); if(!avcodec_inited){ avcodec_init();