5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
1 #include <stdio.h>
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
2 #include <stdlib.h>
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
3 #include <unistd.h>
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
4
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
5 #include "config.h"
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
6 #include "mp_msg.h"
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
7 #include "help_mp.h"
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
8
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
9 #include "ad_internal.h"
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
10
|
21507
|
11 #include "mpbswap.h"
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
12
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
13 static ad_info_t info =
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
14 {
|
7191
|
15 "FFmpeg/libavcodec audio decoders",
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
16 "ffmpeg",
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
17 "Nick Kurshev",
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
18 "ffmpeg.sf.net",
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
19 ""
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
20 };
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
21
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
22 LIBAD_EXTERN(ffmpeg)
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
23
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
24 #define assert(x)
|
5447
|
25
|
|
26 #ifdef USE_LIBAVCODEC_SO
|
7004
|
27 #include <ffmpeg/avcodec.h>
|
5447
|
28 #else
|
16165
|
29 #include "avcodec.h"
|
5447
|
30 #endif
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
31
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
32 extern int avcodec_inited;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
33
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
34 static int preinit(sh_audio_t *sh)
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
35 {
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
36 sh->audio_out_minsize=AVCODEC_MAX_AUDIO_FRAME_SIZE;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
37 return 1;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
38 }
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
39
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
40 static int init(sh_audio_t *sh_audio)
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
41 {
|
5447
|
42 int x;
|
5480
|
43 AVCodecContext *lavc_context;
|
|
44 AVCodec *lavc_codec;
|
5447
|
45
|
|
46 mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n");
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
47 if(!avcodec_inited){
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
48 avcodec_init();
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
49 avcodec_register_all();
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
50 avcodec_inited=1;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
51 }
|
5447
|
52
|
5480
|
53 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_audio->codec->dll);
|
|
54 if(!lavc_codec){
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
55 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh_audio->codec->dll);
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
56 return 0;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
57 }
|
5447
|
58
|
7940
|
59 lavc_context = avcodec_alloc_context();
|
5480
|
60 sh_audio->context=lavc_context;
|
7940
|
61
|
24226
|
62 lavc_context->sample_rate = sh_audio->samplerate;
|
|
63 lavc_context->bit_rate = sh_audio->i_bps * 8;
|
8590
|
64 if(sh_audio->wf){
|
|
65 lavc_context->channels = sh_audio->wf->nChannels;
|
|
66 lavc_context->sample_rate = sh_audio->wf->nSamplesPerSec;
|
|
67 lavc_context->bit_rate = sh_audio->wf->nAvgBytesPerSec * 8;
|
|
68 lavc_context->block_align = sh_audio->wf->nBlockAlign;
|
14922
|
69 lavc_context->bits_per_sample = sh_audio->wf->wBitsPerSample;
|
8590
|
70 }
|
24108
|
71 lavc_context->request_channels = audio_output_channels;
|
9547
|
72 lavc_context->codec_tag = sh_audio->format; //FOURCC
|
8590
|
73 lavc_context->codec_id = lavc_codec->id; // not sure if required, imho not --A'rpi
|
7940
|
74
|
|
75 /* alloc extra data */
|
8590
|
76 if (sh_audio->wf && sh_audio->wf->cbSize > 0) {
|
17226
|
77 lavc_context->extradata = av_mallocz(sh_audio->wf->cbSize + FF_INPUT_BUFFER_PADDING_SIZE);
|
7940
|
78 lavc_context->extradata_size = sh_audio->wf->cbSize;
|
|
79 memcpy(lavc_context->extradata, (char *)sh_audio->wf + sizeof(WAVEFORMATEX),
|
|
80 lavc_context->extradata_size);
|
|
81 }
|
|
82
|
14633
|
83 // for QDM2
|
|
84 if (sh_audio->codecdata_len && sh_audio->codecdata && !lavc_context->extradata)
|
|
85 {
|
|
86 lavc_context->extradata = av_malloc(sh_audio->codecdata_len);
|
|
87 lavc_context->extradata_size = sh_audio->codecdata_len;
|
|
88 memcpy(lavc_context->extradata, (char *)sh_audio->codecdata,
|
|
89 lavc_context->extradata_size);
|
|
90 }
|
|
91
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
92 /* open it */
|
5480
|
93 if (avcodec_open(lavc_context, lavc_codec) < 0) {
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
94 mp_msg(MSGT_DECAUDIO,MSGL_ERR, MSGTR_CantOpenCodec);
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
95 return 0;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
96 }
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
97 mp_msg(MSGT_DECAUDIO,MSGL_V,"INFO: libavcodec init OK!\n");
|
8101
|
98
|
|
99 // printf("\nFOURCC: 0x%X\n",sh_audio->format);
|
|
100 if(sh_audio->format==0x3343414D){
|
|
101 // MACE 3:1
|
|
102 sh_audio->ds->ss_div = 2*3; // 1 samples/packet
|
8108
|
103 sh_audio->ds->ss_mul = 2*sh_audio->wf->nChannels; // 1 byte*ch/packet
|
8101
|
104 } else
|
|
105 if(sh_audio->format==0x3643414D){
|
|
106 // MACE 6:1
|
|
107 sh_audio->ds->ss_div = 2*6; // 1 samples/packet
|
8108
|
108 sh_audio->ds->ss_mul = 2*sh_audio->wf->nChannels; // 1 byte*ch/packet
|
8101
|
109 }
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
110
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
111 // Decode at least 1 byte: (to get header filled)
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
112 x=decode_audio(sh_audio,sh_audio->a_buffer,1,sh_audio->a_buffer_size);
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
113 if(x>0) sh_audio->a_buffer_len=x;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
114
|
5480
|
115 sh_audio->channels=lavc_context->channels;
|
|
116 sh_audio->samplerate=lavc_context->sample_rate;
|
|
117 sh_audio->i_bps=lavc_context->bit_rate/8;
|
17995
|
118 if(sh_audio->wf){
|
18150
|
119 // If the decoder uses the wrong number of channels all is lost anyway.
|
|
120 // sh_audio->channels=sh_audio->wf->nChannels;
|
20328
|
121 if (sh_audio->wf->nSamplesPerSec)
|
17995
|
122 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
|
20328
|
123 if (sh_audio->wf->nAvgBytesPerSec)
|
17995
|
124 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
|
|
125 }
|
13427
|
126 sh_audio->samplesize=2;
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
127 return 1;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
128 }
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
129
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
130 static void uninit(sh_audio_t *sh)
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
131 {
|
7940
|
132 AVCodecContext *lavc_context = sh->context;
|
|
133
|
|
134 if (avcodec_close(lavc_context) < 0)
|
5447
|
135 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_CantCloseCodec);
|
14431
|
136 av_freep(&lavc_context->extradata);
|
|
137 av_freep(&lavc_context);
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
138 }
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
139
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
140 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
141 {
|
11977
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
diff
changeset
|
142 AVCodecContext *lavc_context = sh->context;
|
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
diff
changeset
|
143 switch(cmd){
|
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
diff
changeset
|
144 case ADCTRL_RESYNC_STREAM:
|
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
diff
changeset
|
145 avcodec_flush_buffers(lavc_context);
|
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
diff
changeset
|
146 return CONTROL_TRUE;
|
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
diff
changeset
|
147 }
|
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
diff
changeset
|
148 return CONTROL_UNKNOWN;
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
149 }
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
150
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
151 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
152 {
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
153 unsigned char *start=NULL;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
154 int y,len=-1;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
155 while(len<minlen){
|
23456
|
156 int len2=maxlen;
|
18242
|
157 double pts;
|
|
158 int x=ds_get_packet_pts(sh_audio->ds,&start, &pts);
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
159 if(x<=0) break; // error
|
18242
|
160 if (pts != MP_NOPTS_VALUE) {
|
|
161 sh_audio->pts = pts;
|
|
162 sh_audio->pts_bytes = 0;
|
|
163 }
|
23456
|
164 y=avcodec_decode_audio2(sh_audio->context,(int16_t*)buf,&len2,start,x);
|
11977
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
diff
changeset
|
165 //printf("return:%d samples_out:%d bitstream_in:%d sample_sum:%d\n", y, len2, x, len); fflush(stdout);
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
166 if(y<0){ mp_msg(MSGT_DECAUDIO,MSGL_V,"lavc_audio: error\n");break; }
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
167 if(y<x) sh_audio->ds->buffer_pos+=y-x; // put back data (HACK!)
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
168 if(len2>0){
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
169 //len=len2;break;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
170 if(len<0) len=len2; else len+=len2;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
171 buf+=len2;
|
23456
|
172 maxlen -= len2;
|
18242
|
173 sh_audio->pts_bytes += len2;
|
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
174 }
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
175 mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"Decoded %d -> %d \n",y,len2);
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
176 }
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
177 return len;
|
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
178 }
|