annotate libmpcodecs/ad_ffmpeg.c @ 31056:486781107898

Fix compilation with live555 after libavutil r22965.
author cehoyos
date Tue, 27 Apr 2010 08:19:42 +0000
parents b7040d298579
children 002cdc635c03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 30379
diff changeset
18
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
19 #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
20 #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
21 #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
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 #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
24 #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
25 #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
26
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
27 #include "ad_internal.h"
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24226
diff changeset
28 #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
29
21507
fa99b3d31d13 Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents: 21372
diff changeset
30 #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
31
30504
cc27da5d7286 Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents: 30421
diff changeset
32 static const 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
33 {
7191
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
34 "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
35 "ffmpeg",
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
36 "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
37 "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
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
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
41 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
42
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
43 #define assert(x)
5447
63082aa173f8 using sh->context
alex
parents: 5343
diff changeset
44
26069
1318e956c092 FFmpeg now uses different (unified) #include paths.
diego
parents: 25962
diff changeset
45 #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
46
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25315
diff changeset
47 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
48
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
49 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
50 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
51 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
52 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
53 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
54
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
55 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
56 {
29511
2c47c6dd92b5 Retry deciding to get audio parameters several times on errors, this avoids
reimar
parents: 29491
diff changeset
57 int tries = 0;
5447
63082aa173f8 using sh->context
alex
parents: 5343
diff changeset
58 int x;
5480
df12f6eb80e3 removed useless contect struct -> code simplified
arpi
parents: 5447
diff changeset
59 AVCodecContext *lavc_context;
df12f6eb80e3 removed useless contect struct -> code simplified
arpi
parents: 5447
diff changeset
60 AVCodec *lavc_codec;
5447
63082aa173f8 using sh->context
alex
parents: 5343
diff changeset
61
63082aa173f8 using sh->context
alex
parents: 5343
diff changeset
62 mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n");
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25315
diff changeset
63 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
64 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
65 avcodec_register_all();
25962
afa125da85cf typo fix: inited --> initialized
diego
parents: 25315
diff changeset
66 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
67 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29133
diff changeset
68
5480
df12f6eb80e3 removed useless contect struct -> code simplified
arpi
parents: 5447
diff changeset
69 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_audio->codec->dll);
df12f6eb80e3 removed useless contect struct -> code simplified
arpi
parents: 5447
diff changeset
70 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
71 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
72 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
73 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29133
diff changeset
74
7940
26fd599d4bad pass extradata to the codec
arpi
parents: 7191
diff changeset
75 lavc_context = avcodec_alloc_context();
5480
df12f6eb80e3 removed useless contect struct -> code simplified
arpi
parents: 5447
diff changeset
76 sh_audio->context=lavc_context;
7940
26fd599d4bad pass extradata to the codec
arpi
parents: 7191
diff changeset
77
24226
352d7d9422b5 Set sample_rate and bit_rate from sh_audio as fallback in case sh_audio->wf
reimar
parents: 24108
diff changeset
78 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
79 lavc_context->bit_rate = sh_audio->i_bps * 8;
8590
0328af0565bf ffmp2 (with mpeg files) sig11 fixed
arpi
parents: 8108
diff changeset
80 if(sh_audio->wf){
0328af0565bf ffmp2 (with mpeg files) sig11 fixed
arpi
parents: 8108
diff changeset
81 lavc_context->channels = sh_audio->wf->nChannels;
0328af0565bf ffmp2 (with mpeg files) sig11 fixed
arpi
parents: 8108
diff changeset
82 lavc_context->sample_rate = sh_audio->wf->nSamplesPerSec;
0328af0565bf ffmp2 (with mpeg files) sig11 fixed
arpi
parents: 8108
diff changeset
83 lavc_context->bit_rate = sh_audio->wf->nAvgBytesPerSec * 8;
0328af0565bf ffmp2 (with mpeg files) sig11 fixed
arpi
parents: 8108
diff changeset
84 lavc_context->block_align = sh_audio->wf->nBlockAlign;
27516
3364aef9a988 Fix compilation after libavcodec major version 52 changes
uau
parents: 26987
diff changeset
85 lavc_context->bits_per_coded_sample = sh_audio->wf->wBitsPerSample;
8590
0328af0565bf ffmp2 (with mpeg files) sig11 fixed
arpi
parents: 8108
diff changeset
86 }
24108
51cd49ee92d6 Use new request_channels
reimar
parents: 23978
diff changeset
87 lavc_context->request_channels = audio_output_channels;
9547
3b3b7b6fdb22 merging fourcc with codec_tag
michael
parents: 8590
diff changeset
88 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
89 lavc_context->codec_type = CODEC_TYPE_AUDIO;
8590
0328af0565bf ffmp2 (with mpeg files) sig11 fixed
arpi
parents: 8108
diff changeset
90 lavc_context->codec_id = lavc_codec->id; // not sure if required, imho not --A'rpi
7940
26fd599d4bad pass extradata to the codec
arpi
parents: 7191
diff changeset
91
26fd599d4bad pass extradata to the codec
arpi
parents: 7191
diff changeset
92 /* alloc extra data */
8590
0328af0565bf ffmp2 (with mpeg files) sig11 fixed
arpi
parents: 8108
diff changeset
93 if (sh_audio->wf && sh_audio->wf->cbSize > 0) {
17226
255b14c0bc36 malloc padding to avoid access beyond allocated memory
henry
parents: 16165
diff changeset
94 lavc_context->extradata = av_mallocz(sh_audio->wf->cbSize + FF_INPUT_BUFFER_PADDING_SIZE);
7940
26fd599d4bad pass extradata to the codec
arpi
parents: 7191
diff changeset
95 lavc_context->extradata_size = sh_audio->wf->cbSize;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29133
diff changeset
96 memcpy(lavc_context->extradata, (char *)sh_audio->wf + sizeof(WAVEFORMATEX),
7940
26fd599d4bad pass extradata to the codec
arpi
parents: 7191
diff changeset
97 lavc_context->extradata_size);
26fd599d4bad pass extradata to the codec
arpi
parents: 7191
diff changeset
98 }
26fd599d4bad pass extradata to the codec
arpi
parents: 7191
diff changeset
99
14633
bde5c3261037 pass wave extradata to the codec..
alex
parents: 14431
diff changeset
100 // for QDM2
bde5c3261037 pass wave extradata to the codec..
alex
parents: 14431
diff changeset
101 if (sh_audio->codecdata_len && sh_audio->codecdata && !lavc_context->extradata)
bde5c3261037 pass wave extradata to the codec..
alex
parents: 14431
diff changeset
102 {
bde5c3261037 pass wave extradata to the codec..
alex
parents: 14431
diff changeset
103 lavc_context->extradata = av_malloc(sh_audio->codecdata_len);
bde5c3261037 pass wave extradata to the codec..
alex
parents: 14431
diff changeset
104 lavc_context->extradata_size = sh_audio->codecdata_len;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29133
diff changeset
105 memcpy(lavc_context->extradata, (char *)sh_audio->codecdata,
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29133
diff changeset
106 lavc_context->extradata_size);
14633
bde5c3261037 pass wave extradata to the codec..
alex
parents: 14431
diff changeset
107 }
bde5c3261037 pass wave extradata to the codec..
alex
parents: 14431
diff changeset
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 /* open it */
5480
df12f6eb80e3 removed useless contect struct -> code simplified
arpi
parents: 5447
diff changeset
110 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
111 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
112 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
113 }
29928
731ddb53dc92 when using -v, print also which lavc codec has been used, not
attila
parents: 29913
diff changeset
114 mp_msg(MSGT_DECAUDIO,MSGL_V,"INFO: libavcodec \"%s\" init OK!\n", lavc_codec->name);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29133
diff changeset
115
8101
1bce6e325946 MACE fix
arpi
parents: 7958
diff changeset
116 // printf("\nFOURCC: 0x%X\n",sh_audio->format);
1bce6e325946 MACE fix
arpi
parents: 7958
diff changeset
117 if(sh_audio->format==0x3343414D){
1bce6e325946 MACE fix
arpi
parents: 7958
diff changeset
118 // MACE 3:1
1bce6e325946 MACE fix
arpi
parents: 7958
diff changeset
119 sh_audio->ds->ss_div = 2*3; // 1 samples/packet
8108
d9b2b39e5c06 Fix stereo MACE files
rtognimp
parents: 8101
diff changeset
120 sh_audio->ds->ss_mul = 2*sh_audio->wf->nChannels; // 1 byte*ch/packet
8101
1bce6e325946 MACE fix
arpi
parents: 7958
diff changeset
121 } else
1bce6e325946 MACE fix
arpi
parents: 7958
diff changeset
122 if(sh_audio->format==0x3643414D){
1bce6e325946 MACE fix
arpi
parents: 7958
diff changeset
123 // MACE 6:1
1bce6e325946 MACE fix
arpi
parents: 7958
diff changeset
124 sh_audio->ds->ss_div = 2*6; // 1 samples/packet
8108
d9b2b39e5c06 Fix stereo MACE files
rtognimp
parents: 8101
diff changeset
125 sh_audio->ds->ss_mul = 2*sh_audio->wf->nChannels; // 1 byte*ch/packet
8101
1bce6e325946 MACE fix
arpi
parents: 7958
diff changeset
126 }
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
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
128 // 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
129 do {
29512
93da3c10c2ac Reindent
reimar
parents: 29511
diff changeset
130 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
131 } 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
132 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
133
5480
df12f6eb80e3 removed useless contect struct -> code simplified
arpi
parents: 5447
diff changeset
134 sh_audio->channels=lavc_context->channels;
df12f6eb80e3 removed useless contect struct -> code simplified
arpi
parents: 5447
diff changeset
135 sh_audio->samplerate=lavc_context->sample_rate;
df12f6eb80e3 removed useless contect struct -> code simplified
arpi
parents: 5447
diff changeset
136 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
137 switch (lavc_context->sample_fmt) {
ee06f3a8b0d5 Support FFmpeg codecs that decode to other formats than S16.
reimar
parents: 27700
diff changeset
138 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
139 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
140 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
141 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
142 default:
ee06f3a8b0d5 Support FFmpeg codecs that decode to other formats than S16.
reimar
parents: 27700
diff changeset
143 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
144 return 0;
ee06f3a8b0d5 Support FFmpeg codecs that decode to other formats than S16.
reimar
parents: 27700
diff changeset
145 }
17995
92c4247cc902 Trust the demuxer instead of the decoder for samplerate detection.
diego
parents: 17523
diff changeset
146 if(sh_audio->wf){
18150
710d4bc5f8c9 Using channel count, samplerate and input bps values from the container
diego
parents: 17995
diff changeset
147 // 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
148 // sh_audio->channels=sh_audio->wf->nChannels;
31010
b7040d298579 Cosmetics/indentation fixes.
reimar
parents: 31009
diff changeset
149
31009
591ab361a131 Add workaround for aac-sbr-ffaac-slow.mkv playing to slow with FFmpeg
reimar
parents: 30504
diff changeset
150 if (lavc_context->codec_id == CODEC_ID_AAC &&
591ab361a131 Add workaround for aac-sbr-ffaac-slow.mkv playing to slow with FFmpeg
reimar
parents: 30504
diff changeset
151 sh_audio->samplerate == 2*sh_audio->wf->nSamplesPerSec) {
591ab361a131 Add workaround for aac-sbr-ffaac-slow.mkv playing to slow with FFmpeg
reimar
parents: 30504
diff changeset
152 mp_msg(MSGT_DECAUDIO, MSGL_WARN,
591ab361a131 Add workaround for aac-sbr-ffaac-slow.mkv playing to slow with FFmpeg
reimar
parents: 30504
diff changeset
153 "Ignoring broken container sample rate for ACC with SBR\n");
31010
b7040d298579 Cosmetics/indentation fixes.
reimar
parents: 31009
diff changeset
154 } else if (sh_audio->wf->nSamplesPerSec)
b7040d298579 Cosmetics/indentation fixes.
reimar
parents: 31009
diff changeset
155 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec;
b7040d298579 Cosmetics/indentation fixes.
reimar
parents: 31009
diff changeset
156
20328
5d9f47834495 Do not use sh_audio->wf values if they are definitely invalid
reimar
parents: 18242
diff changeset
157 if (sh_audio->wf->nAvgBytesPerSec)
31010
b7040d298579 Cosmetics/indentation fixes.
reimar
parents: 31009
diff changeset
158 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec;
17995
92c4247cc902 Trust the demuxer instead of the decoder for samplerate detection.
diego
parents: 17523
diff changeset
159 }
28955
ee06f3a8b0d5 Support FFmpeg codecs that decode to other formats than S16.
reimar
parents: 27700
diff changeset
160 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
161 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
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
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
164 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
165 {
7940
26fd599d4bad pass extradata to the codec
arpi
parents: 7191
diff changeset
166 AVCodecContext *lavc_context = sh->context;
26fd599d4bad pass extradata to the codec
arpi
parents: 7191
diff changeset
167
26fd599d4bad pass extradata to the codec
arpi
parents: 7191
diff changeset
168 if (avcodec_close(lavc_context) < 0)
5447
63082aa173f8 using sh->context
alex
parents: 5343
diff changeset
169 mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_CantCloseCodec);
14431
0c10f923746e change malloc and free to av_ variants where needed.
reimar
parents: 13427
diff changeset
170 av_freep(&lavc_context->extradata);
0c10f923746e change malloc and free to av_ variants where needed.
reimar
parents: 13427
diff changeset
171 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
172 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
173
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
174 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
175 {
11977
efb37725d616 flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents: 9547
diff changeset
176 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
177 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
178 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
179 avcodec_flush_buffers(lavc_context);
30379
0140d505dd91 Reset the parser on seek. Should fix some cases of audio "blips" after seeking.
reimar
parents: 30272
diff changeset
180 ds_clear_parser(sh->ds);
11977
efb37725d616 flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents: 9547
diff changeset
181 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
182 }
efb37725d616 flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents: 9547
diff changeset
183 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
184 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
185
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
186 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
187 {
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
188 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
189 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
190 while(len<minlen){
29913
9e76a5f9e717 Switch ad_ffmpeg to avcodec_decode_audio3
reimar
parents: 29912
diff changeset
191 AVPacket pkt;
23456
1582297cc3d2 Use avcodec_decode_audio2 in ad_ffmpeg.c
reimar
parents: 21507
diff changeset
192 int len2=maxlen;
18242
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 18150
diff changeset
193 double pts;
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 18150
diff changeset
194 int x=ds_get_packet_pts(sh_audio->ds,&start, &pts);
30088
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
195 if(x<=0) {
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
196 start = NULL;
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
197 x = 0;
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
198 ds_parse(sh_audio->ds, &start, &x, MP_NOPTS_VALUE, 0);
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
199 if (x <= 0)
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
200 break; // error
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
201 } else {
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
202 int in_size = x;
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
203 int consumed = ds_parse(sh_audio->ds, &start, &x, pts, 0);
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
204 sh_audio->ds->buffer_pos -= in_size - consumed;
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
205 }
29913
9e76a5f9e717 Switch ad_ffmpeg to avcodec_decode_audio3
reimar
parents: 29912
diff changeset
206 av_init_packet(&pkt);
9e76a5f9e717 Switch ad_ffmpeg to avcodec_decode_audio3
reimar
parents: 29912
diff changeset
207 pkt.data = start;
9e76a5f9e717 Switch ad_ffmpeg to avcodec_decode_audio3
reimar
parents: 29912
diff changeset
208 pkt.size = x;
18242
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 18150
diff changeset
209 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
210 sh_audio->pts = pts;
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 18150
diff changeset
211 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
212 }
29913
9e76a5f9e717 Switch ad_ffmpeg to avcodec_decode_audio3
reimar
parents: 29912
diff changeset
213 y=avcodec_decode_audio3(sh_audio->context,(int16_t*)buf,&len2,&pkt);
11977
efb37725d616 flushing stuff after seeking (finally we can view MPEG without thouse blocks after seeking with -vc ffmpeg12)
michael
parents: 9547
diff changeset
214 //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
215 if(y<0){ mp_msg(MSGT_DECAUDIO,MSGL_V,"lavc_audio: error\n");break; }
30272
c6c40936049c We only need to disable seeking back in ad_ffmpeg when we actually _use_
reimar
parents: 30088
diff changeset
216 if(!sh_audio->parser && y<x)
30088
4977e04f3a18 Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents: 29928
diff changeset
217 sh_audio->ds->buffer_pos+=y-x; // put back data (HACK!)
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
218 if(len2>0){
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24226
diff changeset
219 if (((AVCodecContext *)sh_audio->context)->channels >= 5) {
29491
99eda963d27a Fix incorrect channel ordering for lavc audio codecs (specifically ffac3,
tack
parents: 29263
diff changeset
220 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
221 sh_audio->context)->sample_fmt) / 8;
29779
282ea4fbe87d ad_ffmpeg: Fix channel layout for ffvorbis and ffaac
tack
parents: 29667
diff changeset
222 reorder_channel_nch(buf, AF_CHANNEL_LAYOUT_LAVC_DEFAULT,
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24226
diff changeset
223 AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24226
diff changeset
224 ((AVCodecContext *)sh_audio->context)->channels,
29491
99eda963d27a Fix incorrect channel ordering for lavc audio codecs (specifically ffac3,
tack
parents: 29263
diff changeset
225 len2 / samplesize, samplesize);
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24226
diff changeset
226 }
5340
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
227 //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
228 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
229 buf+=len2;
23456
1582297cc3d2 Use avcodec_decode_audio2 in ad_ffmpeg.c
reimar
parents: 21507
diff changeset
230 maxlen -= len2;
18242
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 18150
diff changeset
231 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
232 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
233 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
234 }
0f12fb7c1c5d imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff changeset
235 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
236 }