[Mplayer-cvslog] CVS: main dec_audio.c,1.38,1.39 dec_video.c,1.35,1.36

Arpi of Ize arpi at mplayer.dev.hu
Fri Sep 21 23:35:13 CEST 2001


Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv15606

Modified Files:
	dec_audio.c dec_video.c 
Log Message:
FFmpeg audio codecs support

Index: dec_audio.c
===================================================================
RCS file: /cvsroot/mplayer/main/dec_audio.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- dec_audio.c	2 Sep 2001 23:06:21 -0000	1.38
+++ dec_audio.c	21 Sep 2001 21:34:56 -0000	1.39
@@ -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);

Index: dec_video.c
===================================================================
RCS file: /cvsroot/mplayer/main/dec_video.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- dec_video.c	8 Sep 2001 23:28:17 -0000	1.35
+++ dec_video.c	21 Sep 2001 21:34:56 -0000	1.36
@@ -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();




More information about the MPlayer-cvslog mailing list