Mercurial > mplayer.hg
annotate libmpcodecs/ad_ffmpeg.c @ 29768:fa5a020677d6
Unbreak the demuxer-specific code in video.c with e.g.
-audiofile by moving the code to manually interleave
subtitles to mp_common.c.
video.c should still be changed to not be demuxer-specific
anymore, it is bad practice but fully fixing it is non-trivial.
author | reimar |
---|---|
date | Sun, 01 Nov 2009 09:48:34 +0000 |
parents | 8cfbe411de01 |
children | 282ea4fbe87d |
rev | line source |
---|---|
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" |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24226
diff
changeset
|
10 #include "libaf/reorder_ch.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
|
11 |
21507
fa99b3d31d13
Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents:
21372
diff
changeset
|
12 #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
|
13 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29133
diff
changeset
|
14 static ad_info_t info = |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
15 { |
7191
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
16 "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
|
17 "ffmpeg", |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
18 "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
|
19 "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
|
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 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
23 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
|
24 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
25 #define assert(x) |
5447 | 26 |
26069
1318e956c092
FFmpeg now uses different (unified) #include paths.
diego
parents:
25962
diff
changeset
|
27 #include "libavcodec/avcodec.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
|
28 |
25962 | 29 extern int avcodec_initialized; |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
30 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
31 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
|
32 { |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
33 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
|
34 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
|
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 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
37 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
|
38 { |
29511
2c47c6dd92b5
Retry deciding to get audio parameters several times on errors, this avoids
reimar
parents:
29491
diff
changeset
|
39 int tries = 0; |
5447 | 40 int x; |
5480 | 41 AVCodecContext *lavc_context; |
42 AVCodec *lavc_codec; | |
5447 | 43 |
44 mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n"); | |
25962 | 45 if(!avcodec_initialized){ |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
46 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
|
47 avcodec_register_all(); |
25962 | 48 avcodec_initialized=1; |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
49 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29133
diff
changeset
|
50 |
5480 | 51 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_audio->codec->dll); |
52 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
|
53 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
|
54 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
|
55 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29133
diff
changeset
|
56 |
7940 | 57 lavc_context = avcodec_alloc_context(); |
5480 | 58 sh_audio->context=lavc_context; |
7940 | 59 |
24226
352d7d9422b5
Set sample_rate and bit_rate from sh_audio as fallback in case sh_audio->wf
reimar
parents:
24108
diff
changeset
|
60 lavc_context->sample_rate = sh_audio->samplerate; |
352d7d9422b5
Set sample_rate and bit_rate from sh_audio as fallback in case sh_audio->wf
reimar
parents:
24108
diff
changeset
|
61 lavc_context->bit_rate = sh_audio->i_bps * 8; |
8590 | 62 if(sh_audio->wf){ |
63 lavc_context->channels = sh_audio->wf->nChannels; | |
64 lavc_context->sample_rate = sh_audio->wf->nSamplesPerSec; | |
65 lavc_context->bit_rate = sh_audio->wf->nAvgBytesPerSec * 8; | |
66 lavc_context->block_align = sh_audio->wf->nBlockAlign; | |
27516
3364aef9a988
Fix compilation after libavcodec major version 52 changes
uau
parents:
26987
diff
changeset
|
67 lavc_context->bits_per_coded_sample = sh_audio->wf->wBitsPerSample; |
8590 | 68 } |
24108 | 69 lavc_context->request_channels = audio_output_channels; |
9547 | 70 lavc_context->codec_tag = sh_audio->format; //FOURCC |
29667
8cfbe411de01
Make sure avctx->codec_type and codec_id are set, since libavcodec
reimar
parents:
29512
diff
changeset
|
71 lavc_context->codec_type = CODEC_TYPE_AUDIO; |
8590 | 72 lavc_context->codec_id = lavc_codec->id; // not sure if required, imho not --A'rpi |
7940 | 73 |
74 /* alloc extra data */ | |
8590 | 75 if (sh_audio->wf && sh_audio->wf->cbSize > 0) { |
17226
255b14c0bc36
malloc padding to avoid access beyond allocated memory
henry
parents:
16165
diff
changeset
|
76 lavc_context->extradata = av_mallocz(sh_audio->wf->cbSize + FF_INPUT_BUFFER_PADDING_SIZE); |
7940 | 77 lavc_context->extradata_size = sh_audio->wf->cbSize; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29133
diff
changeset
|
78 memcpy(lavc_context->extradata, (char *)sh_audio->wf + sizeof(WAVEFORMATEX), |
7940 | 79 lavc_context->extradata_size); |
80 } | |
81 | |
14633 | 82 // for QDM2 |
83 if (sh_audio->codecdata_len && sh_audio->codecdata && !lavc_context->extradata) | |
84 { | |
85 lavc_context->extradata = av_malloc(sh_audio->codecdata_len); | |
86 lavc_context->extradata_size = sh_audio->codecdata_len; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29133
diff
changeset
|
87 memcpy(lavc_context->extradata, (char *)sh_audio->codecdata, |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29133
diff
changeset
|
88 lavc_context->extradata_size); |
14633 | 89 } |
90 | |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
91 /* open it */ |
5480 | 92 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
|
93 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
|
94 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
|
95 } |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
96 mp_msg(MSGT_DECAUDIO,MSGL_V,"INFO: libavcodec init OK!\n"); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29133
diff
changeset
|
97 |
8101 | 98 // printf("\nFOURCC: 0x%X\n",sh_audio->format); |
99 if(sh_audio->format==0x3343414D){ | |
100 // MACE 3:1 | |
101 sh_audio->ds->ss_div = 2*3; // 1 samples/packet | |
8108 | 102 sh_audio->ds->ss_mul = 2*sh_audio->wf->nChannels; // 1 byte*ch/packet |
8101 | 103 } else |
104 if(sh_audio->format==0x3643414D){ | |
105 // MACE 6:1 | |
106 sh_audio->ds->ss_div = 2*6; // 1 samples/packet | |
8108 | 107 sh_audio->ds->ss_mul = 2*sh_audio->wf->nChannels; // 1 byte*ch/packet |
8101 | 108 } |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
109 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
110 // Decode at least 1 byte: (to get header filled) |
29511
2c47c6dd92b5
Retry deciding to get audio parameters several times on errors, this avoids
reimar
parents:
29491
diff
changeset
|
111 do { |
29512 | 112 x=decode_audio(sh_audio,sh_audio->a_buffer,1,sh_audio->a_buffer_size); |
29511
2c47c6dd92b5
Retry deciding to get audio parameters several times on errors, this avoids
reimar
parents:
29491
diff
changeset
|
113 } while (x <= 0 && tries++ < 5); |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
114 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
|
115 |
5480 | 116 sh_audio->channels=lavc_context->channels; |
117 sh_audio->samplerate=lavc_context->sample_rate; | |
118 sh_audio->i_bps=lavc_context->bit_rate/8; | |
28955
ee06f3a8b0d5
Support FFmpeg codecs that decode to other formats than S16.
reimar
parents:
27700
diff
changeset
|
119 switch (lavc_context->sample_fmt) { |
ee06f3a8b0d5
Support FFmpeg codecs that decode to other formats than S16.
reimar
parents:
27700
diff
changeset
|
120 case SAMPLE_FMT_U8: sh_audio->sample_format = AF_FORMAT_U8; break; |
ee06f3a8b0d5
Support FFmpeg codecs that decode to other formats than S16.
reimar
parents:
27700
diff
changeset
|
121 case SAMPLE_FMT_S16: sh_audio->sample_format = AF_FORMAT_S16_NE; break; |
ee06f3a8b0d5
Support FFmpeg codecs that decode to other formats than S16.
reimar
parents:
27700
diff
changeset
|
122 case SAMPLE_FMT_S32: sh_audio->sample_format = AF_FORMAT_S32_NE; break; |
ee06f3a8b0d5
Support FFmpeg codecs that decode to other formats than S16.
reimar
parents:
27700
diff
changeset
|
123 case SAMPLE_FMT_FLT: sh_audio->sample_format = AF_FORMAT_FLOAT_NE; break; |
ee06f3a8b0d5
Support FFmpeg codecs that decode to other formats than S16.
reimar
parents:
27700
diff
changeset
|
124 default: |
ee06f3a8b0d5
Support FFmpeg codecs that decode to other formats than S16.
reimar
parents:
27700
diff
changeset
|
125 mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Unsupported sample format\n"); |
ee06f3a8b0d5
Support FFmpeg codecs that decode to other formats than S16.
reimar
parents:
27700
diff
changeset
|
126 return 0; |
ee06f3a8b0d5
Support FFmpeg codecs that decode to other formats than S16.
reimar
parents:
27700
diff
changeset
|
127 } |
17995
92c4247cc902
Trust the demuxer instead of the decoder for samplerate detection.
diego
parents:
17523
diff
changeset
|
128 if(sh_audio->wf){ |
18150
710d4bc5f8c9
Using channel count, samplerate and input bps values from the container
diego
parents:
17995
diff
changeset
|
129 // If the decoder uses the wrong number of channels all is lost anyway. |
710d4bc5f8c9
Using channel count, samplerate and input bps values from the container
diego
parents:
17995
diff
changeset
|
130 // sh_audio->channels=sh_audio->wf->nChannels; |
20328
5d9f47834495
Do not use sh_audio->wf values if they are definitely invalid
reimar
parents:
18242
diff
changeset
|
131 if (sh_audio->wf->nSamplesPerSec) |
17995
92c4247cc902
Trust the demuxer instead of the decoder for samplerate detection.
diego
parents:
17523
diff
changeset
|
132 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
20328
5d9f47834495
Do not use sh_audio->wf values if they are definitely invalid
reimar
parents:
18242
diff
changeset
|
133 if (sh_audio->wf->nAvgBytesPerSec) |
17995
92c4247cc902
Trust the demuxer instead of the decoder for samplerate detection.
diego
parents:
17523
diff
changeset
|
134 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; |
92c4247cc902
Trust the demuxer instead of the decoder for samplerate detection.
diego
parents:
17523
diff
changeset
|
135 } |
28955
ee06f3a8b0d5
Support FFmpeg codecs that decode to other formats than S16.
reimar
parents:
27700
diff
changeset
|
136 sh_audio->samplesize=af_fmt2bits(sh_audio->sample_format)/ 8; |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
137 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
|
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 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
|
141 { |
7940 | 142 AVCodecContext *lavc_context = sh->context; |
143 | |
144 if (avcodec_close(lavc_context) < 0) | |
5447 | 145 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_CantCloseCodec); |
14431
0c10f923746e
change malloc and free to av_ variants where needed.
reimar
parents:
13427
diff
changeset
|
146 av_freep(&lavc_context->extradata); |
0c10f923746e
change malloc and free to av_ variants where needed.
reimar
parents:
13427
diff
changeset
|
147 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
|
148 } |
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 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
|
151 { |
11977
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents:
9547
diff
changeset
|
152 AVCodecContext *lavc_context = sh->context; |
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents:
9547
diff
changeset
|
153 switch(cmd){ |
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents:
9547
diff
changeset
|
154 case ADCTRL_RESYNC_STREAM: |
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents:
9547
diff
changeset
|
155 avcodec_flush_buffers(lavc_context); |
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents:
9547
diff
changeset
|
156 return CONTROL_TRUE; |
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents:
9547
diff
changeset
|
157 } |
efb37725d616
flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents:
9547
diff
changeset
|
158 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
|
159 } |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
160 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
161 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
|
162 { |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
163 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
|
164 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
|
165 while(len<minlen){ |
23456 | 166 int len2=maxlen; |
18242
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18150
diff
changeset
|
167 double pts; |
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18150
diff
changeset
|
168 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
|
169 if(x<=0) break; // error |
18242
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18150
diff
changeset
|
170 if (pts != MP_NOPTS_VALUE) { |
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18150
diff
changeset
|
171 sh_audio->pts = pts; |
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18150
diff
changeset
|
172 sh_audio->pts_bytes = 0; |
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18150
diff
changeset
|
173 } |
23456 | 174 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
parents:
9547
diff
changeset
|
175 //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
|
176 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
|
177 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
|
178 if(len2>0){ |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24226
diff
changeset
|
179 if (((AVCodecContext *)sh_audio->context)->channels >= 5) { |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24226
diff
changeset
|
180 int src_ch_layout = AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT; |
29491
99eda963d27a
Fix incorrect channel ordering for lavc audio codecs (specifically ffac3,
tack
parents:
29263
diff
changeset
|
181 int samplesize = av_get_bits_per_sample_format(((AVCodecContext *) |
99eda963d27a
Fix incorrect channel ordering for lavc audio codecs (specifically ffac3,
tack
parents:
29263
diff
changeset
|
182 sh_audio->context)->sample_fmt) / 8; |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24226
diff
changeset
|
183 const char *codec=((AVCodecContext*)sh_audio->context)->codec->name; |
29491
99eda963d27a
Fix incorrect channel ordering for lavc audio codecs (specifically ffac3,
tack
parents:
29263
diff
changeset
|
184 if (!strcasecmp(codec, "aac")) |
99eda963d27a
Fix incorrect channel ordering for lavc audio codecs (specifically ffac3,
tack
parents:
29263
diff
changeset
|
185 src_ch_layout = AF_CHANNEL_LAYOUT_LAVC_AAC_DEC_DEFAULT; |
26132
b6280829f7f8
Fix ffvorbis decoder's output channel order with channel reordering function.
ulion
parents:
26069
diff
changeset
|
186 else if (!strcasecmp(codec, "vorbis")) |
26987
d3a0f537dbe8
rename AF_CHANNEL_LAYOUT_LAVC_VORBIS* => AF_CHANNEL_LAYOUT_VORBIS*.
ulion
parents:
26132
diff
changeset
|
187 src_ch_layout = AF_CHANNEL_LAYOUT_VORBIS_DEFAULT; |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24226
diff
changeset
|
188 else |
29491
99eda963d27a
Fix incorrect channel ordering for lavc audio codecs (specifically ffac3,
tack
parents:
29263
diff
changeset
|
189 src_ch_layout = AF_CHANNEL_LAYOUT_LAVC_DEFAULT; |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24226
diff
changeset
|
190 reorder_channel_nch(buf, src_ch_layout, |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24226
diff
changeset
|
191 AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT, |
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24226
diff
changeset
|
192 ((AVCodecContext *)sh_audio->context)->channels, |
29491
99eda963d27a
Fix incorrect channel ordering for lavc audio codecs (specifically ffac3,
tack
parents:
29263
diff
changeset
|
193 len2 / samplesize, samplesize); |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
24226
diff
changeset
|
194 } |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
195 //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
|
196 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
|
197 buf+=len2; |
23456 | 198 maxlen -= len2; |
18242
caac2ca98168
4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents:
18150
diff
changeset
|
199 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
|
200 } |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
201 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
|
202 } |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
203 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
|
204 } |