diff options
author | arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-09-21 21:34:56 +0000 |
---|---|---|
committer | arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-09-21 21:34:56 +0000 |
commit | ffe1e2c3e3bef206f6660b049c4df5173fbb934f (patch) | |
tree | ad5a9e9e20a45d706563b31743850dd706325d6a /dec_audio.c | |
parent | c8f1f9576664f9086ccbf6da94ba867c3caa24e8 (diff) | |
download | mpv-ffe1e2c3e3bef206f6660b049c4df5173fbb934f.tar.bz2 mpv-ffe1e2c3e3bef206f6660b049c4df5173fbb934f.tar.xz |
FFmpeg audio codecs support
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1928 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'dec_audio.c')
-rw-r--r-- | dec_audio.c | 76 |
1 files changed, 76 insertions, 0 deletions
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 <vorbis/codec.h> #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(len<minlen){ + int len2=0; + int x=ds_get_packet(sh_audio->ds,&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(y<x) sh_audio->ds->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); |