changeset 1927:296208b47fd4

FFmpeg audio codecs support
author arpi
date Fri, 21 Sep 2001 21:34:56 +0000
parents 0b14f254ae9b
children 07f50ea77510
files dec_audio.c dec_video.c
diffstat 2 files changed, 80 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/dec_audio.c	Fri Sep 21 17:07:19 2001 +0000
+++ b/dec_audio.c	Fri Sep 21 21:34:56 2001 +0000
@@ -43,8 +43,16 @@
 #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 @@
   // 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 @@
   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 @@
 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);
--- a/dec_video.c	Fri Sep 21 17:07:19 2001 +0000
+++ b/dec_video.c	Fri Sep 21 21:34:56 2001 +0000
@@ -50,9 +50,10 @@
 
 #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 @@
    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();