~ubuntu-branches/ubuntu/maverick/vlc/maverick

« back to all changes in this revision

Viewing changes to extras/faad2/plugins/in_mp4/aacinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello, Mario Limonciello, Martin Hamrle
  • Date: 2008-03-25 20:08:07 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20080325200807-64amsvla1tnnen5s
Tags: 0.8.6.release.e+x264svn20071224+faad2.6.1-0ubuntu1
[ Mario Limonciello ]
* New upstream version. (LP: #206918)
  - New versioning scheme to bring attention to the fact that
    faad and x264 are in the .orig.tar.gz.
  - Fixes 6 CVEs (LP: #196452)
    + CVE: 2007-6681
    + CVE: 2007-6682
    + CVE: 2007-6683
    + CVE: 2008-0295
    + CVE: 2008-0296
* Drop 021_CVE-2008-0984 as it's included upstream.
* debian/rules:
  - Adjust items touched for faad2 when building.
  - Apply all faad2 patches when building
* debian/control:
  - Add dpatch, libfaad-dev, and autotools-dev to build-depends to allow 
    faad2 to build again.
  - Add automake, cvs, and libtool to build depends (now needed for building VLC)

[ Martin Hamrle ]
 * Add new package with pulse output plugin (LP: #196417)
   - debian/patches/030_pulse.diff:
     + patch from upstream trunk to support pulseaudio output
   - debian/rules:
     + enable pulseaudio
   - debian/control:
     + add dependencies to libpulse-dev
     + new package description
   - Creates a NEW binary package, requiring FFe (LP: #204050)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3
 
** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
4
 
**  
5
 
** This program is free software; you can redistribute it and/or modify
6
 
** it under the terms of the GNU General Public License as published by
7
 
** the Free Software Foundation; either version 2 of the License, or
8
 
** (at your option) any later version.
9
 
** 
10
 
** This program is distributed in the hope that it will be useful,
11
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
** GNU General Public License for more details.
14
 
** 
15
 
** You should have received a copy of the GNU General Public License
16
 
** along with this program; if not, write to the Free Software 
17
 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
 
**
19
 
** Any non-GPL usage of this software or parts of this software is strictly
20
 
** forbidden.
21
 
**
22
 
** Commercial non-GPL licensing of this software is possible.
23
 
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
24
 
**
25
 
** $Id: aacinfo.c,v 1.6 2004/10/18 19:25:00 menno Exp $
26
 
**/
27
 
 
28
 
#define WIN32_LEAN_AND_MEAN
29
 
#include <windows.h>
30
 
#include <malloc.h>
31
 
#include <stdlib.h>
32
 
#include <stdio.h>
33
 
#include <math.h>
34
 
#include "aacinfo.h"
35
 
#include "utils.h"
36
 
 
37
 
#define ADIF_MAX_SIZE 30 /* Should be enough */
38
 
#define ADTS_MAX_SIZE 10 /* Should be enough */
39
 
 
40
 
static int sample_rates[] = {96000,88200,64000,48000,44100,32000,24000,22050,16000,12000,11025,8000};
41
 
 
42
 
static int read_ADIF_header(FILE *file, faadAACInfo *info)
43
 
{
44
 
    int bitstream;
45
 
    unsigned char buffer[ADIF_MAX_SIZE];
46
 
    int skip_size = 0;
47
 
    int sf_idx;
48
 
 
49
 
    /* Get ADIF header data */
50
 
    info->headertype = 1;
51
 
 
52
 
    if (fread(buffer, 1, ADIF_MAX_SIZE, file) != ADIF_MAX_SIZE)
53
 
        return -1;
54
 
 
55
 
    /* copyright string */
56
 
    if(buffer[0] & 0x80)
57
 
        skip_size += 9; /* skip 9 bytes */
58
 
 
59
 
    bitstream = buffer[0 + skip_size] & 0x10;
60
 
    info->bitrate = ((unsigned int)(buffer[0 + skip_size] & 0x0F)<<19)|
61
 
        ((unsigned int)buffer[1 + skip_size]<<11)|
62
 
        ((unsigned int)buffer[2 + skip_size]<<3)|
63
 
        ((unsigned int)buffer[3 + skip_size] & 0xE0);
64
 
 
65
 
    if (bitstream == 0)
66
 
    {
67
 
        info->object_type =  ((buffer[6 + skip_size]&0x01)<<1)|((buffer[7 + skip_size]&0x80)>>7);
68
 
        sf_idx = (buffer[7 + skip_size]&0x78)>>3;
69
 
    } else {
70
 
        info->object_type = (buffer[4 + skip_size] & 0x18)>>3;
71
 
        sf_idx = ((buffer[4 + skip_size] & 0x07)<<1)|((buffer[5 + skip_size] & 0x80)>>7);
72
 
    }
73
 
    info->sampling_rate = sample_rates[sf_idx];
74
 
 
75
 
    return 0;
76
 
}
77
 
 
78
 
static int read_ADTS_header(FILE *file, faadAACInfo *info)
79
 
{
80
 
    /* Get ADTS header data */
81
 
    unsigned char buffer[ADTS_MAX_SIZE];
82
 
    int frames, t_framelength = 0, frame_length, sr_idx = 0, ID;
83
 
    int second = 0, pos;
84
 
    float frames_per_sec = 0;
85
 
    unsigned long bytes;
86
 
    unsigned long *tmp_seek_table = NULL;
87
 
 
88
 
    info->headertype = 2;
89
 
 
90
 
    /* Read all frames to ensure correct time and bitrate */
91
 
    for (frames = 0; /* */; frames++)
92
 
    {
93
 
        bytes = fread(buffer, 1, ADTS_MAX_SIZE, file);
94
 
 
95
 
        if (bytes != ADTS_MAX_SIZE)
96
 
            break;
97
 
 
98
 
        /* check syncword */
99
 
        if (!((buffer[0] == 0xFF)&&((buffer[1] & 0xF6) == 0xF0)))
100
 
            break;
101
 
 
102
 
        if (!frames)
103
 
        {
104
 
            /* fixed ADTS header is the same for every frame, so we read it only once */
105
 
            /* Syncword found, proceed to read in the fixed ADTS header */
106
 
            ID = buffer[1] & 0x08;
107
 
            info->object_type = (buffer[2]&0xC0)>>6;
108
 
            sr_idx = (buffer[2]&0x3C)>>2;
109
 
            info->channels = ((buffer[2]&0x01)<<2)|((buffer[3]&0xC0)>>6);
110
 
 
111
 
            frames_per_sec = sample_rates[sr_idx] / 1024.f;
112
 
        }
113
 
 
114
 
        /* ...and the variable ADTS header */
115
 
        if (ID == 0)
116
 
        {
117
 
            info->version = 4;
118
 
        } else { /* MPEG-2 */
119
 
            info->version = 2;
120
 
        }
121
 
        frame_length = ((((unsigned int)buffer[3] & 0x3)) << 11)
122
 
            | (((unsigned int)buffer[4]) << 3) | (buffer[5] >> 5);
123
 
 
124
 
        t_framelength += frame_length;
125
 
 
126
 
        pos = ftell(file) - ADTS_MAX_SIZE;
127
 
 
128
 
        fseek(file, frame_length - ADTS_MAX_SIZE, SEEK_CUR);
129
 
    }
130
 
 
131
 
    if (frames > 0)
132
 
    {
133
 
        float sec_per_frame, bytes_per_frame;
134
 
        info->sampling_rate = sample_rates[sr_idx];
135
 
        sec_per_frame = (float)info->sampling_rate/1024.0;
136
 
        bytes_per_frame = (float)t_framelength / (float)frames;
137
 
        info->bitrate = 8 * (int)floor(bytes_per_frame * sec_per_frame);
138
 
        info->length = (int)floor((float)frames/frames_per_sec)*1000;
139
 
    } else {
140
 
        info->sampling_rate = 4;
141
 
        info->bitrate = 128000;
142
 
        info->length = 0;
143
 
        info->channels = 0;
144
 
    }
145
 
 
146
 
    return 0;
147
 
}
148
 
 
149
 
int get_AAC_format(char *filename, faadAACInfo *info)
150
 
{
151
 
    unsigned long tagsize;
152
 
    FILE *file;
153
 
    char buffer[10];
154
 
    unsigned long file_len;
155
 
    unsigned char adxx_id[5];
156
 
    unsigned long tmp;
157
 
 
158
 
    memset(info, 0, sizeof(faadAACInfo));
159
 
 
160
 
    file = fopen(filename, "rb");
161
 
 
162
 
    if(file == NULL)
163
 
        return -1;
164
 
 
165
 
    fseek(file, 0, SEEK_END);
166
 
    file_len = ftell(file);
167
 
    fseek(file, 0, SEEK_SET);
168
 
 
169
 
    /* Skip the tag, if it's there */
170
 
    tmp = fread(buffer, 10, 1, file);
171
 
 
172
 
    if (StringComp(buffer, "ID3", 3) == 0)
173
 
    {
174
 
        /* high bit is not used */
175
 
        tagsize = (buffer[6] << 21) | (buffer[7] << 14) |
176
 
            (buffer[8] <<  7) | (buffer[9] <<  0);
177
 
 
178
 
        fseek(file, tagsize, SEEK_CUR);
179
 
        tagsize += 10;
180
 
    } else {
181
 
        tagsize = 0;
182
 
        fseek(file, 0, SEEK_SET);
183
 
    }
184
 
 
185
 
    if (file_len)
186
 
        file_len -= tagsize;
187
 
 
188
 
    tmp = fread(adxx_id, 2, 1, file);
189
 
    adxx_id[5-1] = 0;
190
 
    info->length = 0;
191
 
 
192
 
    /* Determine the header type of the file, check the first two bytes */
193
 
    if (StringComp(adxx_id, "AD", 2) == 0)
194
 
    {
195
 
        /* We think its an ADIF header, but check the rest just to make sure */
196
 
        tmp = fread(adxx_id + 2, 2, 1, file);
197
 
 
198
 
        if (StringComp(adxx_id, "ADIF", 4) == 0)
199
 
        {
200
 
            read_ADIF_header(file, info);
201
 
 
202
 
            info->length = (int)((float)file_len*8000.0/((float)info->bitrate));
203
 
        }
204
 
    } else {
205
 
        /* No ADIF, check for ADTS header */
206
 
        if ((adxx_id[0] == 0xFF)&&((adxx_id[1] & 0xF6) == 0xF0))
207
 
        {
208
 
            /* ADTS  header located */
209
 
            fseek(file, tagsize, SEEK_SET);
210
 
            read_ADTS_header(file, info);
211
 
        } else {
212
 
            /* Unknown/headerless AAC file, assume format: */
213
 
            info->version = 2;
214
 
            info->bitrate = 128000;
215
 
            info->sampling_rate = 44100;
216
 
            info->channels = 2;
217
 
            info->headertype = 0;
218
 
            info->object_type = 1;
219
 
        }
220
 
    }
221
 
 
222
 
    fclose(file);
223
 
 
224
 
    return 0;
225
 
}
 
1
/*
 
2
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
 
3
** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
 
4
**  
 
5
** This program is free software; you can redistribute it and/or modify
 
6
** it under the terms of the GNU General Public License as published by
 
7
** the Free Software Foundation; either version 2 of the License, or
 
8
** (at your option) any later version.
 
9
** 
 
10
** This program is distributed in the hope that it will be useful,
 
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
** GNU General Public License for more details.
 
14
** 
 
15
** You should have received a copy of the GNU General Public License
 
16
** along with this program; if not, write to the Free Software 
 
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
**
 
19
** Any non-GPL usage of this software or parts of this software is strictly
 
20
** forbidden.
 
21
**
 
22
** Commercial non-GPL licensing of this software is possible.
 
23
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 
24
**
 
25
** $Id: aacinfo.c,v 1.6 2004/10/18 19:25:00 menno Exp $
 
26
**/
 
27
 
 
28
#define WIN32_LEAN_AND_MEAN
 
29
#include <windows.h>
 
30
#include <malloc.h>
 
31
#include <stdlib.h>
 
32
#include <stdio.h>
 
33
#include <math.h>
 
34
#include "aacinfo.h"
 
35
#include "utils.h"
 
36
 
 
37
#define ADIF_MAX_SIZE 30 /* Should be enough */
 
38
#define ADTS_MAX_SIZE 10 /* Should be enough */
 
39
 
 
40
static int sample_rates[] = {96000,88200,64000,48000,44100,32000,24000,22050,16000,12000,11025,8000};
 
41
 
 
42
static int read_ADIF_header(FILE *file, faadAACInfo *info)
 
43
{
 
44
    int bitstream;
 
45
    unsigned char buffer[ADIF_MAX_SIZE];
 
46
    int skip_size = 0;
 
47
    int sf_idx;
 
48
 
 
49
    /* Get ADIF header data */
 
50
    info->headertype = 1;
 
51
 
 
52
    if (fread(buffer, 1, ADIF_MAX_SIZE, file) != ADIF_MAX_SIZE)
 
53
        return -1;
 
54
 
 
55
    /* copyright string */
 
56
    if(buffer[0] & 0x80)
 
57
        skip_size += 9; /* skip 9 bytes */
 
58
 
 
59
    bitstream = buffer[0 + skip_size] & 0x10;
 
60
    info->bitrate = ((unsigned int)(buffer[0 + skip_size] & 0x0F)<<19)|
 
61
        ((unsigned int)buffer[1 + skip_size]<<11)|
 
62
        ((unsigned int)buffer[2 + skip_size]<<3)|
 
63
        ((unsigned int)buffer[3 + skip_size] & 0xE0);
 
64
 
 
65
    if (bitstream == 0)
 
66
    {
 
67
        info->object_type =  ((buffer[6 + skip_size]&0x01)<<1)|((buffer[7 + skip_size]&0x80)>>7);
 
68
        sf_idx = (buffer[7 + skip_size]&0x78)>>3;
 
69
    } else {
 
70
        info->object_type = (buffer[4 + skip_size] & 0x18)>>3;
 
71
        sf_idx = ((buffer[4 + skip_size] & 0x07)<<1)|((buffer[5 + skip_size] & 0x80)>>7);
 
72
    }
 
73
    info->sampling_rate = sample_rates[sf_idx];
 
74
 
 
75
    return 0;
 
76
}
 
77
 
 
78
static int read_ADTS_header(FILE *file, faadAACInfo *info)
 
79
{
 
80
    /* Get ADTS header data */
 
81
    unsigned char buffer[ADTS_MAX_SIZE];
 
82
    int frames, t_framelength = 0, frame_length, sr_idx = 0, ID;
 
83
    int second = 0, pos;
 
84
    float frames_per_sec = 0;
 
85
    unsigned long bytes;
 
86
    unsigned long *tmp_seek_table = NULL;
 
87
 
 
88
    info->headertype = 2;
 
89
 
 
90
    /* Read all frames to ensure correct time and bitrate */
 
91
    for (frames = 0; /* */; frames++)
 
92
    {
 
93
        bytes = fread(buffer, 1, ADTS_MAX_SIZE, file);
 
94
 
 
95
        if (bytes != ADTS_MAX_SIZE)
 
96
            break;
 
97
 
 
98
        /* check syncword */
 
99
        if (!((buffer[0] == 0xFF)&&((buffer[1] & 0xF6) == 0xF0)))
 
100
            break;
 
101
 
 
102
        if (!frames)
 
103
        {
 
104
            /* fixed ADTS header is the same for every frame, so we read it only once */
 
105
            /* Syncword found, proceed to read in the fixed ADTS header */
 
106
            ID = buffer[1] & 0x08;
 
107
            info->object_type = (buffer[2]&0xC0)>>6;
 
108
            sr_idx = (buffer[2]&0x3C)>>2;
 
109
            info->channels = ((buffer[2]&0x01)<<2)|((buffer[3]&0xC0)>>6);
 
110
 
 
111
            frames_per_sec = sample_rates[sr_idx] / 1024.f;
 
112
        }
 
113
 
 
114
        /* ...and the variable ADTS header */
 
115
        if (ID == 0)
 
116
        {
 
117
            info->version = 4;
 
118
        } else { /* MPEG-2 */
 
119
            info->version = 2;
 
120
        }
 
121
        frame_length = ((((unsigned int)buffer[3] & 0x3)) << 11)
 
122
            | (((unsigned int)buffer[4]) << 3) | (buffer[5] >> 5);
 
123
 
 
124
        t_framelength += frame_length;
 
125
 
 
126
        pos = ftell(file) - ADTS_MAX_SIZE;
 
127
 
 
128
        fseek(file, frame_length - ADTS_MAX_SIZE, SEEK_CUR);
 
129
    }
 
130
 
 
131
    if (frames > 0)
 
132
    {
 
133
        float sec_per_frame, bytes_per_frame;
 
134
        info->sampling_rate = sample_rates[sr_idx];
 
135
        sec_per_frame = (float)info->sampling_rate/1024.0;
 
136
        bytes_per_frame = (float)t_framelength / (float)frames;
 
137
        info->bitrate = 8 * (int)floor(bytes_per_frame * sec_per_frame);
 
138
        info->length = (int)floor((float)frames/frames_per_sec)*1000;
 
139
    } else {
 
140
        info->sampling_rate = 4;
 
141
        info->bitrate = 128000;
 
142
        info->length = 0;
 
143
        info->channels = 0;
 
144
    }
 
145
 
 
146
    return 0;
 
147
}
 
148
 
 
149
int get_AAC_format(char *filename, faadAACInfo *info)
 
150
{
 
151
    unsigned long tagsize;
 
152
    FILE *file;
 
153
    char buffer[10];
 
154
    unsigned long file_len;
 
155
    unsigned char adxx_id[5];
 
156
    unsigned long tmp;
 
157
 
 
158
    memset(info, 0, sizeof(faadAACInfo));
 
159
 
 
160
    file = fopen(filename, "rb");
 
161
 
 
162
    if(file == NULL)
 
163
        return -1;
 
164
 
 
165
    fseek(file, 0, SEEK_END);
 
166
    file_len = ftell(file);
 
167
    fseek(file, 0, SEEK_SET);
 
168
 
 
169
    /* Skip the tag, if it's there */
 
170
    tmp = fread(buffer, 10, 1, file);
 
171
 
 
172
    if (StringComp(buffer, "ID3", 3) == 0)
 
173
    {
 
174
        /* high bit is not used */
 
175
        tagsize = (buffer[6] << 21) | (buffer[7] << 14) |
 
176
            (buffer[8] <<  7) | (buffer[9] <<  0);
 
177
 
 
178
        fseek(file, tagsize, SEEK_CUR);
 
179
        tagsize += 10;
 
180
    } else {
 
181
        tagsize = 0;
 
182
        fseek(file, 0, SEEK_SET);
 
183
    }
 
184
 
 
185
    if (file_len)
 
186
        file_len -= tagsize;
 
187
 
 
188
    tmp = fread(adxx_id, 2, 1, file);
 
189
    adxx_id[5-1] = 0;
 
190
    info->length = 0;
 
191
 
 
192
    /* Determine the header type of the file, check the first two bytes */
 
193
    if (StringComp(adxx_id, "AD", 2) == 0)
 
194
    {
 
195
        /* We think its an ADIF header, but check the rest just to make sure */
 
196
        tmp = fread(adxx_id + 2, 2, 1, file);
 
197
 
 
198
        if (StringComp(adxx_id, "ADIF", 4) == 0)
 
199
        {
 
200
            read_ADIF_header(file, info);
 
201
 
 
202
            info->length = (int)((float)file_len*8000.0/((float)info->bitrate));
 
203
        }
 
204
    } else {
 
205
        /* No ADIF, check for ADTS header */
 
206
        if ((adxx_id[0] == 0xFF)&&((adxx_id[1] & 0xF6) == 0xF0))
 
207
        {
 
208
            /* ADTS  header located */
 
209
            fseek(file, tagsize, SEEK_SET);
 
210
            read_ADTS_header(file, info);
 
211
        } else {
 
212
            /* Unknown/headerless AAC file, assume format: */
 
213
            info->version = 2;
 
214
            info->bitrate = 128000;
 
215
            info->sampling_rate = 44100;
 
216
            info->channels = 2;
 
217
            info->headertype = 0;
 
218
            info->object_type = 1;
 
219
        }
 
220
    }
 
221
 
 
222
    fclose(file);
 
223
 
 
224
    return 0;
 
225
}