Mercurial > mplayer.hg
comparison libmpcodecs/ad_ffmpeg.c @ 5340:0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
author | arpi |
---|---|
date | Mon, 25 Mar 2002 21:06:01 +0000 |
parents | |
children | 3dd532400d44 |
comparison
equal
deleted
inserted
replaced
5339:e72d8e3955ea | 5340:0f12fb7c1c5d |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <unistd.h> | |
4 | |
5 #include "config.h" | |
6 #include "mp_msg.h" | |
7 #include "help_mp.h" | |
8 | |
9 #include "ad_internal.h" | |
10 | |
11 #include "bswap.h" | |
12 | |
13 static ad_info_t info = | |
14 { | |
15 "FFmpeg audio decoders", | |
16 "ffmpeg", | |
17 AFM_FFMPEG, | |
18 "Nick Kurshev", | |
19 "ffmpeg.sf.net", | |
20 "" | |
21 }; | |
22 | |
23 LIBAD_EXTERN(ffmpeg) | |
24 | |
25 #define assert(x) | |
26 #include "../libavcodec/avcodec.h" | |
27 | |
28 static AVCodec *lavc_codec=NULL; | |
29 static AVCodecContext lavc_context; | |
30 extern int avcodec_inited; | |
31 | |
32 static int preinit(sh_audio_t *sh) | |
33 { | |
34 sh->audio_out_minsize=AVCODEC_MAX_AUDIO_FRAME_SIZE; | |
35 return 1; | |
36 } | |
37 | |
38 static int init(sh_audio_t *sh_audio) | |
39 { | |
40 int x; | |
41 mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n"); | |
42 if(!avcodec_inited){ | |
43 avcodec_init(); | |
44 avcodec_register_all(); | |
45 avcodec_inited=1; | |
46 } | |
47 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_audio->codec->dll); | |
48 if(!lavc_codec){ | |
49 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh_audio->codec->dll); | |
50 return 0; | |
51 } | |
52 memset(&lavc_context, 0, sizeof(lavc_context)); | |
53 /* open it */ | |
54 if (avcodec_open(&lavc_context, lavc_codec) < 0) { | |
55 mp_msg(MSGT_DECAUDIO,MSGL_ERR, MSGTR_CantOpenCodec); | |
56 return 0; | |
57 } | |
58 mp_msg(MSGT_DECAUDIO,MSGL_V,"INFO: libavcodec init OK!\n"); | |
59 | |
60 // Decode at least 1 byte: (to get header filled) | |
61 x=decode_audio(sh_audio,sh_audio->a_buffer,1,sh_audio->a_buffer_size); | |
62 if(x>0) sh_audio->a_buffer_len=x; | |
63 | |
64 #if 1 | |
65 sh_audio->channels=lavc_context.channels; | |
66 sh_audio->samplerate=lavc_context.sample_rate; | |
67 sh_audio->i_bps=lavc_context.bit_rate/8; | |
68 #else | |
69 sh_audio->channels=sh_audio->wf->nChannels; | |
70 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; | |
71 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; | |
72 #endif | |
73 return 1; | |
74 } | |
75 | |
76 static void uninit(sh_audio_t *sh) | |
77 { | |
78 avcodec_close(&lavc_context); | |
79 } | |
80 | |
81 static int control(sh_audio_t *sh,int cmd,void* arg, ...) | |
82 { | |
83 // TODO ??? | |
84 return CONTROL_UNKNOWN; | |
85 } | |
86 | |
87 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen) | |
88 { | |
89 unsigned char *start=NULL; | |
90 int y,len=-1; | |
91 while(len<minlen){ | |
92 int len2=0; | |
93 int x=ds_get_packet(sh_audio->ds,&start); | |
94 if(x<=0) break; // error | |
95 y=avcodec_decode_audio(&lavc_context,(INT16*)buf,&len2,start,x); | |
96 if(y<0){ mp_msg(MSGT_DECAUDIO,MSGL_V,"lavc_audio: error\n");break; } | |
97 if(y<x) sh_audio->ds->buffer_pos+=y-x; // put back data (HACK!) | |
98 if(len2>0){ | |
99 //len=len2;break; | |
100 if(len<0) len=len2; else len+=len2; | |
101 buf+=len2; | |
102 } | |
103 mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"Decoded %d -> %d \n",y,len2); | |
104 } | |
105 return len; | |
106 } |