annotate libmpcodecs/ad_faad.c @ 6172:9b40f17128cc

majd biztos strong bazmeg
author gabucino
date Thu, 23 May 2002 21:01:56 +0000
parents b3d1348b251f
children a32870fd043b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
1 /* ad_faad.c - MPlayer AAC decoder using libfaad2
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
2 * This file is part of MPlayer, see http://mplayerhq.hu/ for info.
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
3 * (c)2002 by Felix Buenemann <atmosfear at users.sourceforge.net>
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
4 * File licensed under the GPL, see http://www.fsf.org/ for more info.
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
5 */
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
6
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
7 #include <stdio.h>
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
8 #include <stdlib.h>
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
9 #include <unistd.h>
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
10
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
11 #include "config.h"
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
12 #include "ad_internal.h"
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
13
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
14 #ifdef HAVE_FAAD
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
15
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
16 static ad_info_t info =
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
17 {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
18 "AAC (MPEG2/4 Advanced Audio Coding)",
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
19 "libfaad2",
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
20 AFM_AAC,
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
21 "Felix Buenemann",
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
22 "faad2",
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
23 "Under development!"
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
24 };
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
25
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
26 LIBAD_EXTERN(faad)
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 <faad.h>
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
29
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
30 /* configure maximum supported channels, *
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
31 * this is theoretically max. 64 chans */
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
32 #define FAAD_MAX_CHANNELS 6
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
33 #define FAAD_BUFFLEN (FAAD_MIN_STREAMSIZE*FAAD_MAX_CHANNELS)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
34
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
35 //#define AAC_DUMP_COMPRESSED
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
36
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
37 static faacDecHandle faac_hdec;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
38 static faacDecFrameInfo faac_finfo;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
39
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
40 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
41 {
5458
b3d1348b251f audio input buffer allocation/free cleanup
arpi
parents: 5357
diff changeset
42 sh->audio_out_minsize=2048*FAAD_MAX_CHANNELS;
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
43 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
44 return 1;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
45 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
46
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
47 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
48 {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
49 unsigned long faac_samplerate, faac_channels;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
50 int faac_init;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
51 faac_hdec = faacDecOpen();
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
52
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
53 sh->a_in_buffer_len = demux_read_data(sh->ds, sh->a_in_buffer, sh->a_in_buffer_size);
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 // If we don't get the ES descriptor, try manual config
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
56 if(!sh->codecdata_len) {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
57 #if 1
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
58 faacDecConfigurationPtr faac_conf;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
59 /* 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
60 /* 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
61 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
62 if(sh->samplerate)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
63 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
64 /* 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
65 * 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
66 */
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
67 if(sh->samplesize)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
68 switch(sh->samplesize){
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
69 case 1: // 8Bit
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
70 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
71 default:
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
72 case 2: // 16Bit
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
73 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
74 break;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
75 case 3: // 24Bit
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
76 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
77 break;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
78 case 4: // 32Bit
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
79 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
80 break;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
81 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
82 //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
83
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
84 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
85 #endif
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
86
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
87 /* init the codec */
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
88 faac_init = faacDecInit(faac_hdec, sh->a_in_buffer,
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
89 &faac_samplerate, &faac_channels);
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
90 sh->a_in_buffer_len -= (faac_init > 0)?faac_init:0; // how many bytes init consumed
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
91
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
92 } else { // We have ES DS in codecdata
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
93 /*int i;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
94 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
95 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
96
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
97 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
98 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
99 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
100 if(faac_init < 0) {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
101 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
102 faacDecClose(faac_hdec);
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
103 // 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
104 return 0;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
105 } else {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
106 mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: Decoder init done (%dBytes)!\n", sh->a_in_buffer_len); // XXX: remove or move to debug!
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
107 mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: Negotiated samplerate: %dHz channels: %d\n", faac_samplerate, faac_channels);
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
108 sh->channels = faac_channels;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
109 sh->samplerate = faac_samplerate;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
110 //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
111 if(!sh->i_bps) {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
112 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
113 sh->i_bps = 128*1000/8; // XXX: HACK!!! ::atmos
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
114 } else
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
115 mp_msg(MSGT_DECAUDIO,MSGL_V,"FAAD: got %dkbit/s bitrate from MP4 header!\n",sh->i_bps*8/1000);
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
116 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
117 return 1;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
118 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
119
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
120 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
121 {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
122 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
123 faacDecClose(faac_hdec);
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
124 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
125
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
126 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
127 {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
128 switch(cmd)
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
129 {
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
130 #if 0
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
131 case ADCTRL_RESYNC_STREAM:
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
132 return CONTROL_TRUE;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
133 case ADCTRL_SKIP_FRAME:
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
134 return CONTROL_TRUE;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
135 #endif
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
136 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
137 return CONTROL_UNKNOWN;
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
138 }
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
139
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
140 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
141 {
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
142 int j = 0, 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
143 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
144
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
145 while(len < minlen) {
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
146 /* update buffer */
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
147 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
148 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
149 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
150 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
151 }
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
152
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
153 #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
154 {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
155 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
156 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
157 printf ("\n");}
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
158 #endif
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
159 do {
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
160 faac_sample_buffer = faacDecDecode(faac_hdec, &faac_finfo, sh->a_in_buffer+j);
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
161 /* 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
162 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
163 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
164 } 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
165 sh->a_in_buffer_len-=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
166 memcpy(sh->a_in_buffer,&sh->a_in_buffer[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
167 }
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
168
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
169 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
170 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"FAAD: Trying to resync!\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
171 j++;
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
172 } 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
173 break;
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
174 } while(j < FAAD_BUFFLEN);
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
175
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
176 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
177 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
178 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
179 } 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
180 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
181 } 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
182 /* XXX: samples already multiplied by channels! */
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
183 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"FAAD: Successfully decoded frame (%d Bytes)!\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
184 sh->samplesize*faac_finfo.samples);
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
185 memcpy(buf+len,faac_sample_buffer, sh->samplesize*faac_finfo.samples);
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
186 len += sh->samplesize*faac_finfo.samples;
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
187 //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
188 }
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
189 }
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
190 return len;
5356
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
191 }
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 #endif /* !HAVE_FAAD */
739cad21c32c Port dec_audio.c faad aac decoder to libmpcodecs, cleaned up code, improved buffering scheme.
atmos4
parents:
diff changeset
194