annotate libmpcodecs/ad_faad.c @ 37082:9e3b2b71a146

Remove pointless statement. The 'menu' item doesn't have an image, so no need to care about Bitmap.Image.
author ib
date Sat, 26 Apr 2014 16:30:54 +0000
parents a93891202051
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28106
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
1 /*
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
2 * MPlayer AAC decoder using libfaad2
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
3 *
28110
fc04fa771074 license header consistency cosmetics
diego
parents: 28106
diff changeset
4 * Copyright (C) 2002 Felix Buenemann <atmosfear at users.sourceforge.net>
28106
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
5 *
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
6 * This file is part of MPlayer.
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
7 *
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
9 * it under the terms of the GNU General Public License as published by
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
11 * (at your option) any later version.
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
12 *
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
16 * GNU General Public License for more details.
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
17 *
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
18 * You should have received a copy of the GNU General Public License along
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
4932a522100e Replace informal GPL notes by standard GPL header.
diego
parents: 27341
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
21 */
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
22
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
23 #include <stdio.h>
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
24 #include <stdlib.h>
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
25 #include <unistd.h>
32654
85f0d7406e07 Remove forked internal libfaad2 copy.
diego
parents: 32619
diff changeset
26 #include <faad.h>
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
27
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
28 #include "config.h"
34174
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 32654
diff changeset
29 #include "mp_msg.h"
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
30 #include "ad_internal.h"
31986
9986a61354e6 Remove duplicated audio_output_channels extern variable declaration.
diego
parents: 31537
diff changeset
31 #include "dec_audio.h"
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24120
diff changeset
32 #include "libaf/reorder_ch.h"
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
33
30504
cc27da5d7286 Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents: 29826
diff changeset
34 static const ad_info_t info =
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
35 {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
36 "AAC (MPEG2/4 Advanced Audio Coding)",
7174
7672615cc811 sync driver names with codec-cfg
arpi
parents: 6894
diff changeset
37 "faad",
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
38 "Felix Buenemann",
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
39 "faad2",
7191
1eadce15446c -afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents: 7180
diff changeset
40 "uses libfaad2"
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
41 };
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
42
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
43 LIBAD_EXTERN(faad)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
44
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
45 /* configure maximum supported channels, *
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
46 * this is theoretically max. 64 chans */
29826
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29263
diff changeset
47 #define FAAD_MAX_CHANNELS 8
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28110
diff changeset
48 #define FAAD_BUFFLEN (FAAD_MIN_STREAMSIZE*FAAD_MAX_CHANNELS)
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
49
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28110
diff changeset
50 //#define AAC_DUMP_COMPRESSED
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
51
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
52 static faacDecHandle faac_hdec;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
53 static faacDecFrameInfo faac_finfo;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
54
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
55 static int preinit(sh_audio_t *sh)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
56 {
12095
cef97e8c85c0 Support for HE-AAC. Patch by Loren Merritt <lorenm at u dot washington anotherdot edu>.
mosu
parents: 10921
diff changeset
57 sh->audio_out_minsize=8192*FAAD_MAX_CHANNELS;
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
58 sh->audio_in_minsize=FAAD_BUFFLEN;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
59 return 1;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
60 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
61
14564
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
62 static int aac_probe(unsigned char *buffer, int len)
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
63 {
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
64 int i = 0, pos = 0;
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
65 mp_msg(MSGT_DECAUDIO,MSGL_V, "\nAAC_PROBE: %d bytes\n", len);
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
66 while(i <= len-4) {
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
67 if(
15708
bdb826438aa8 fixed wrong binary mask: it precluded the syncword of adts-4 from being recognized as valid
nicodvb
parents: 15019
diff changeset
68 ((buffer[i] == 0xff) && ((buffer[i+1] & 0xf6) == 0xf0)) ||
14564
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
69 (buffer[i] == 'A' && buffer[i+1] == 'D' && buffer[i+2] == 'I' && buffer[i+3] == 'F')
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
70 ) {
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
71 pos = i;
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
72 break;
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
73 }
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
74 mp_msg(MSGT_DECAUDIO,MSGL_V, "AUDIO PAYLOAD: %x %x %x %x\n", buffer[i], buffer[i+1], buffer[i+2], buffer[i+3]);
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
75 i++;
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
76 }
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
77 mp_msg(MSGT_DECAUDIO,MSGL_V, "\nAAC_PROBE: ret %d\n", pos);
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
78 return pos;
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
79 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28110
diff changeset
80
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
81 static int init(sh_audio_t *sh)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
82 {
7648
7ee8239bfcc0 I think libfaad2 changed recently. The functions faacDecInit() and
arpi
parents: 7191
diff changeset
83 unsigned long faac_samplerate;
7ee8239bfcc0 I think libfaad2 changed recently. The functions faacDecInit() and
arpi
parents: 7191
diff changeset
84 unsigned char faac_channels;
14564
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
85 int faac_init, pos = 0;
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
86 faac_hdec = faacDecOpen();
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
87
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
88 // If we don't get the ES descriptor, try manual config
12473
6f11d107f7b8 If demuxer does not fill codecdata try to get if from waveformatex
rtognimp
parents: 12095
diff changeset
89 if(!sh->codecdata_len && sh->wf) {
6f11d107f7b8 If demuxer does not fill codecdata try to get if from waveformatex
rtognimp
parents: 12095
diff changeset
90 sh->codecdata_len = sh->wf->cbSize;
25638
a4c3eb7ef547 Use malloc for codecdata. Fixes segfault in free_sh_sub.
eugeni
parents: 25315
diff changeset
91 sh->codecdata = malloc(sh->codecdata_len);
a4c3eb7ef547 Use malloc for codecdata. Fixes segfault in free_sh_sub.
eugeni
parents: 25315
diff changeset
92 memcpy(sh->codecdata, sh->wf+1, sh->codecdata_len);
12473
6f11d107f7b8 If demuxer does not fill codecdata try to get if from waveformatex
rtognimp
parents: 12095
diff changeset
93 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"FAAD: codecdata extracted from WAVEFORMATEX\n");
6f11d107f7b8 If demuxer does not fill codecdata try to get if from waveformatex
rtognimp
parents: 12095
diff changeset
94 }
32499
4be4c1ecaa4c Fix -ac faad with -demuxer lavf.
reimar
parents: 31986
diff changeset
95 if(!sh->codecdata_len || sh->format == mmioFOURCC('M', 'P', '4', 'L')) {
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
96 faacDecConfigurationPtr faac_conf;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
97 /* Set the default object type and samplerate */
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
98 /* This is useful for RAW AAC files */
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
99 faac_conf = faacDecGetCurrentConfiguration(faac_hdec);
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
100 if(sh->samplerate)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
101 faac_conf->defSampleRate = sh->samplerate;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
102 /* XXX: FAAD support FLOAT output, how do we handle
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
103 * that (FAAD_FMT_FLOAT)? ::atmos
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
104 */
15019
bc17fdd4e2ef step 1 of fixing ad_faad:
rfelker
parents: 14638
diff changeset
105 if (audio_output_channels <= 2) faac_conf->downMatrix = 1;
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
106 switch(sh->samplesize){
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
107 case 1: // 8Bit
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
108 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: 8Bit samplesize not supported by FAAD, assuming 16Bit!\n");
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
109 default:
13427
9d0b052c4f74 setting samplesize to 2 in decoders where neccessary.
reimar
parents: 13307
diff changeset
110 sh->samplesize=2;
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
111 case 2: // 16Bit
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
112 faac_conf->outputFormat = FAAD_FMT_16BIT;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
113 break;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
114 case 3: // 24Bit
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
115 faac_conf->outputFormat = FAAD_FMT_24BIT;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
116 break;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
117 case 4: // 32Bit
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
118 faac_conf->outputFormat = FAAD_FMT_32BIT;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
119 break;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
120 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
121 //faac_conf->defObjectType = LTP; // => MAIN, LC, SSR, LTP available.
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
122
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
123 faacDecSetConfiguration(faac_hdec, faac_conf);
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
124
6894
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
125 sh->a_in_buffer_len = demux_read_data(sh->ds, sh->a_in_buffer, sh->a_in_buffer_size);
32619
34c4e6ff7b17 Fix ad_faad crash when used on an empty audio stream.
reimar
parents: 32499
diff changeset
126 if (!sh->a_in_buffer_len) {
34c4e6ff7b17 Fix ad_faad crash when used on an empty audio stream.
reimar
parents: 32499
diff changeset
127 // faad init will crash with 0 buffer length
34c4e6ff7b17 Fix ad_faad crash when used on an empty audio stream.
reimar
parents: 32499
diff changeset
128 mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "Could not get audio data!\n");
34c4e6ff7b17 Fix ad_faad crash when used on an empty audio stream.
reimar
parents: 32499
diff changeset
129 return 0;
34c4e6ff7b17 Fix ad_faad crash when used on an empty audio stream.
reimar
parents: 32499
diff changeset
130 }
31537
8e5ba4ae7c36 * fix compilation using external libfaad
attila
parents: 31477
diff changeset
131 /* external faad does not have latm lookup support */
8e5ba4ae7c36 * fix compilation using external libfaad
attila
parents: 31477
diff changeset
132 faac_init = faacDecInit(faac_hdec, sh->a_in_buffer,
8e5ba4ae7c36 * fix compilation using external libfaad
attila
parents: 31477
diff changeset
133 sh->a_in_buffer_len, &faac_samplerate, &faac_channels);
31477
86888a4c406e Improve LATM recognition.
cehoyos
parents: 30566
diff changeset
134
86888a4c406e Improve LATM recognition.
cehoyos
parents: 30566
diff changeset
135 if (faac_init < 0) {
14564
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
136 pos = aac_probe(sh->a_in_buffer, sh->a_in_buffer_len);
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
137 if(pos) {
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
138 sh->a_in_buffer_len -= pos;
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
139 memmove(sh->a_in_buffer, &(sh->a_in_buffer[pos]), sh->a_in_buffer_len);
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
140 sh->a_in_buffer_len +=
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
141 demux_read_data(sh->ds,&(sh->a_in_buffer[sh->a_in_buffer_len]),
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
142 sh->a_in_buffer_size - sh->a_in_buffer_len);
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
143 pos = 0;
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
144 }
6894
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
145
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
146 /* init the codec */
31537
8e5ba4ae7c36 * fix compilation using external libfaad
attila
parents: 31477
diff changeset
147 faac_init = faacDecInit(faac_hdec, sh->a_in_buffer,
8e5ba4ae7c36 * fix compilation using external libfaad
attila
parents: 31477
diff changeset
148 sh->a_in_buffer_len, &faac_samplerate, &faac_channels);
31477
86888a4c406e Improve LATM recognition.
cehoyos
parents: 30566
diff changeset
149 }
6894
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
150
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
151 sh->a_in_buffer_len -= (faac_init > 0)?faac_init:0; // how many bytes init consumed
6894
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
152 // XXX FIXME: shouldn't we memcpy() here in a_in_buffer ?? --A'rpi
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
153
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
154 } else { // We have ES DS in codecdata
15019
bc17fdd4e2ef step 1 of fixing ad_faad:
rfelker
parents: 14638
diff changeset
155 faacDecConfigurationPtr faac_conf = faacDecGetCurrentConfiguration(faac_hdec);
bc17fdd4e2ef step 1 of fixing ad_faad:
rfelker
parents: 14638
diff changeset
156 if (audio_output_channels <= 2) {
bc17fdd4e2ef step 1 of fixing ad_faad:
rfelker
parents: 14638
diff changeset
157 faac_conf->downMatrix = 1;
bc17fdd4e2ef step 1 of fixing ad_faad:
rfelker
parents: 14638
diff changeset
158 faacDecSetConfiguration(faac_hdec, faac_conf);
bc17fdd4e2ef step 1 of fixing ad_faad:
rfelker
parents: 14638
diff changeset
159 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28110
diff changeset
160
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
161 /*int i;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
162 for(i = 0; i < sh_audio->codecdata_len; i++)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
163 printf("codecdata_dump %d: 0x%02X\n", i, sh_audio->codecdata[i]);*/
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
164
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
165 faac_init = faacDecInit2(faac_hdec, sh->codecdata,
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
166 sh->codecdata_len, &faac_samplerate, &faac_channels);
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
167 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
168 if(faac_init < 0) {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
169 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: Failed to initialize the decoder!\n"); // XXX: deal with cleanup!
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
170 faacDecClose(faac_hdec);
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
171 // XXX: free a_in_buffer here or in uninit?
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
172 return 0;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
173 } else {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
174 mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: Decoder init done (%dBytes)!\n", sh->a_in_buffer_len); // XXX: remove or move to debug!
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17012
diff changeset
175 mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: Negotiated samplerate: %ldHz channels: %d\n", faac_samplerate, faac_channels);
29826
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29263
diff changeset
176 // 8 channels is aac channel order #7.
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29263
diff changeset
177 sh->channels = faac_channels == 7 ? 8 : faac_channels;
15019
bc17fdd4e2ef step 1 of fixing ad_faad:
rfelker
parents: 14638
diff changeset
178 if (audio_output_channels <= 2) sh->channels = faac_channels > 1 ? 2 : 1;
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
179 sh->samplerate = faac_samplerate;
13427
9d0b052c4f74 setting samplesize to 2 in decoders where neccessary.
reimar
parents: 13307
diff changeset
180 sh->samplesize=2;
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
181 //sh->o_bps = sh->samplesize*faac_channels*faac_samplerate;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
182 if(!sh->i_bps) {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
183 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: compressed input bitrate missing, assuming 128kbit/s!\n");
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
184 sh->i_bps = 128*1000/8; // XXX: HACK!!! ::atmos
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28110
diff changeset
185 } else
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
186 mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: got %dkbit/s bitrate from MP4 header!\n",sh->i_bps*8/1000);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28110
diff changeset
187 }
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
188 return 1;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
189 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
190
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
191 static void uninit(sh_audio_t *sh)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
192 {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
193 mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: Closing decoder!\n");
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
194 faacDecClose(faac_hdec);
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
195 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
196
14564
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
197 static int aac_sync(sh_audio_t *sh)
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
198 {
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
199 int pos = 0;
31477
86888a4c406e Improve LATM recognition.
cehoyos
parents: 30566
diff changeset
200 // do not probe LATM, faad does that
86888a4c406e Improve LATM recognition.
cehoyos
parents: 30566
diff changeset
201 if(!sh->codecdata_len && sh->format != mmioFOURCC('M', 'P', '4', 'L')) {
14564
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
202 if(sh->a_in_buffer_len < sh->a_in_buffer_size){
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
203 sh->a_in_buffer_len +=
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
204 demux_read_data(sh->ds,&sh->a_in_buffer[sh->a_in_buffer_len],
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
205 sh->a_in_buffer_size - sh->a_in_buffer_len);
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
206 }
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
207 pos = aac_probe(sh->a_in_buffer, sh->a_in_buffer_len);
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
208 if(pos) {
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
209 sh->a_in_buffer_len -= pos;
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
210 memmove(sh->a_in_buffer, &(sh->a_in_buffer[pos]), sh->a_in_buffer_len);
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
211 mp_msg(MSGT_DECAUDIO,MSGL_V, "\nAAC SYNC AFTER %d bytes\n", pos);
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
212 }
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
213 }
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
214 return pos;
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
215 }
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
216
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
217 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
218 {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
219 switch(cmd)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
220 {
14564
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
221 case ADCTRL_RESYNC_STREAM:
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
222 aac_sync(sh);
f85875877de9 tries to sync to ADTS/ADIF header before initializing the decoder; implement SYNC
nicodvb
parents: 13427
diff changeset
223 return CONTROL_TRUE;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28110
diff changeset
224 #if 0
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
225 case ADCTRL_SKIP_FRAME:
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
226 return CONTROL_TRUE;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
227 #endif
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
228 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
229 return CONTROL_UNKNOWN;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
230 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
231
16337
7252d024193b * really keep track on how many samples were decoded last round (fix 10l)
attila
parents: 16336
diff changeset
232 #define MAX_FAAD_ERRORS 10
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
233 static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
234 {
24120
dac788e0857d Fix unused variable warning.
diego
parents: 23918
diff changeset
235 int len = 0, last_dec_len = 1, errors = 0;
dac788e0857d Fix unused variable warning.
diego
parents: 23918
diff changeset
236 // int j = 0;
5357
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
237 void *faac_sample_buffer;
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
238
16337
7252d024193b * really keep track on how many samples were decoded last round (fix 10l)
attila
parents: 16336
diff changeset
239 while(len < minlen && last_dec_len > 0 && errors < MAX_FAAD_ERRORS) {
6894
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
240
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
241 /* update buffer for raw aac streams: */
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
242 if(!sh->codecdata_len)
5357
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
243 if(sh->a_in_buffer_len < sh->a_in_buffer_size){
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
244 sh->a_in_buffer_len +=
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
245 demux_read_data(sh->ds,&sh->a_in_buffer[sh->a_in_buffer_len],
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
246 sh->a_in_buffer_size - sh->a_in_buffer_len);
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
247 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28110
diff changeset
248
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
249 #ifdef DUMP_AAC_COMPRESSED
5357
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
250 {int i;
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
251 for (i = 0; i < 16; i++)
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
252 printf ("%02X ", sh->a_in_buffer[i]);
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
253 printf ("\n");}
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
254 #endif
6894
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
255
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
256 if(!sh->codecdata_len){
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
257 // raw aac stream:
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
258 do {
18644
82263a36cfa4 fixes the infinite loop which occurs when there is a decode error in a frame.
gpoirier
parents: 18242
diff changeset
259 faac_sample_buffer = faacDecDecode(faac_hdec, &faac_finfo, sh->a_in_buffer, sh->a_in_buffer_len);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28110
diff changeset
260
5357
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
261 /* update buffer index after faacDecDecode */
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
262 if(faac_finfo.bytesconsumed >= sh->a_in_buffer_len) {
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
263 sh->a_in_buffer_len=0;
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
264 } else {
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
265 sh->a_in_buffer_len-=faac_finfo.bytesconsumed;
15978
c8dc500e078e memcpy and memmove both copy memory, but when using memcpy the source and destination must not overlap, but here, they did overlap.
gpoirier
parents: 15708
diff changeset
266 memmove(sh->a_in_buffer,&sh->a_in_buffer[faac_finfo.bytesconsumed],sh->a_in_buffer_len);
5357
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
267 }
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
268
5357
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
269 if(faac_finfo.error > 0) {
13307
b94f228dfed6 output faad error message in case of a decoder error
reimar
parents: 12473
diff changeset
270 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: error: %s, trying to resync!\n",
b94f228dfed6 output faad error message in case of a decoder error
reimar
parents: 12473
diff changeset
271 faacDecGetErrorMessage(faac_finfo.error));
19995
9cd5e242121e in case of errors after decoding quit the main decoding
nicodvb
parents: 19348
diff changeset
272 if (sh->a_in_buffer_len <= 0) {
9cd5e242121e in case of errors after decoding quit the main decoding
nicodvb
parents: 19348
diff changeset
273 errors = MAX_FAAD_ERRORS;
9cd5e242121e in case of errors after decoding quit the main decoding
nicodvb
parents: 19348
diff changeset
274 break;
9cd5e242121e in case of errors after decoding quit the main decoding
nicodvb
parents: 19348
diff changeset
275 }
18644
82263a36cfa4 fixes the infinite loop which occurs when there is a decode error in a frame.
gpoirier
parents: 18242
diff changeset
276 sh->a_in_buffer_len--;
82263a36cfa4 fixes the infinite loop which occurs when there is a decode error in a frame.
gpoirier
parents: 18242
diff changeset
277 memmove(sh->a_in_buffer,&sh->a_in_buffer[1],sh->a_in_buffer_len);
82263a36cfa4 fixes the infinite loop which occurs when there is a decode error in a frame.
gpoirier
parents: 18242
diff changeset
278 aac_sync(sh);
16337
7252d024193b * really keep track on how many samples were decoded last round (fix 10l)
attila
parents: 16336
diff changeset
279 errors++;
5357
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
280 } else
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
281 break;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28110
diff changeset
282 } while(errors < MAX_FAAD_ERRORS);
6894
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
283 } else {
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
284 // packetized (.mp4) aac stream:
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
285 unsigned char* bufptr=NULL;
18242
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
286 double pts;
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
287 int buflen=ds_get_packet_pts(sh->ds, &bufptr, &pts);
6894
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
288 if(buflen<=0) break;
18242
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
289 if (pts != MP_NOPTS_VALUE) {
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
290 sh->pts = pts;
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
291 sh->pts_bytes = 0;
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
292 }
9321
6fa743f3094b libfaad2 v1.0, v1.1, v1.2 detection, and API change workaround in ad_faad.c
arpi
parents: 7648
diff changeset
293 faac_sample_buffer = faacDecDecode(faac_hdec, &faac_finfo, bufptr, buflen);
6894
a32870fd043b support for packetized aac streams (used in .mp4 files)
arpi
parents: 5458
diff changeset
294 }
15019
bc17fdd4e2ef step 1 of fixing ad_faad:
rfelker
parents: 14638
diff changeset
295 //for (j=0;j<faac_finfo.channels;j++) printf("%d:%d\n", j, faac_finfo.channel_position[j]);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28110
diff changeset
296
5357
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
297 if(faac_finfo.error > 0) {
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
298 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: Failed to decode frame: %s \n",
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
299 faacDecGetErrorMessage(faac_finfo.error));
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
300 } else if (faac_finfo.samples == 0) {
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
301 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"FAAD: Decoded zero samples!\n");
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
302 } else {
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
303 /* XXX: samples already multiplied by channels! */
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17012
diff changeset
304 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"FAAD: Successfully decoded frame (%ld Bytes)!\n",
5357
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
305 sh->samplesize*faac_finfo.samples);
25315
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24120
diff changeset
306
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24120
diff changeset
307 if (sh->channels >= 5)
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24120
diff changeset
308 reorder_channel_copy_nch(faac_sample_buffer,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24120
diff changeset
309 AF_CHANNEL_LAYOUT_AAC_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24120
diff changeset
310 buf+len, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24120
diff changeset
311 sh->channels,
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24120
diff changeset
312 faac_finfo.samples, sh->samplesize);
dfa8a510c81c Fix all current known multi-channel wrong order problems by adding
ulion
parents: 24120
diff changeset
313 else
5357
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
314 memcpy(buf+len,faac_sample_buffer, sh->samplesize*faac_finfo.samples);
16337
7252d024193b * really keep track on how many samples were decoded last round (fix 10l)
attila
parents: 16336
diff changeset
315 last_dec_len = sh->samplesize*faac_finfo.samples;
7252d024193b * really keep track on how many samples were decoded last round (fix 10l)
attila
parents: 16336
diff changeset
316 len += last_dec_len;
18242
caac2ca98168 4 - Implement a better way to calculate current audio pts and use it for
rtognimp
parents: 17366
diff changeset
317 sh->pts_bytes += last_dec_len;
5357
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
318 //printf("FAAD: buffer: %d bytes consumed: %d \n", k, faac_finfo.bytesconsumed);
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
319 }
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
320 }
3c5d5626d3a1 Don't kill me, pure indent change as I forgot to reindent when copy and pasting from dec_audio.c, as this is the first revision it doesn't break changelog!
atmos4
parents: 5356
diff changeset
321 return len;
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
322 }