~ubuntu-branches/ubuntu/vivid/ffmpeg/vivid-updates

« back to all changes in this revision

Viewing changes to debian/patches/aac-regression.patch

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2010-03-04 10:34:37 UTC
  • mfrom: (1.1.11 upstream) (0.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100304103437-mj2hpq7a581pzrxv
Tags: 4:0.5.1-1ubuntu1
* merge from debian. remaining changes:
  - don't disable encoders
  - don't build against libfaad, libdirac and libopenjpeg (all in universe)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
fix aac playback regression
2
 
 
3
 
patch taken from upstream svn:
4
 
 
5
 
------------------------------------------------------------------------
6
 
r17856 | alexc | 2009-03-06 20:47:01 +0100 (Fr, 06. Mär 2009) | 3 lines
7
 
 
8
 
Fix the channel allocation bug/assumption (issue 800).
9
 
Approved by Rob on IRC.
10
 
 
11
 
------------------------------------------------------------------------
12
 
r17860 | alexc | 2009-03-06 23:36:24 +0100 (Fr, 06. Mär 2009) | 2 lines
13
 
 
14
 
If we get an error from ff_aac_parse_header() we should not trust the
15
 
header info that it provides.
16
 
 
17
 
------------------------------------------------------------------------
18
 
r17861 | alexc | 2009-03-06 23:37:21 +0100 (Fr, 06. Mär 2009) | 2 lines
19
 
 
20
 
Re-indent after last commit.
21
 
 
22
 
------------------------------------------------------------------------
23
 
 
24
 
diff --git a/libavcodec/aac.c b/libavcodec/aac.c
25
 
index 80195c0..b6759dd 100644
26
 
--- a/libavcodec/aac.c
27
 
+++ b/libavcodec/aac.c
28
 
@@ -97,6 +97,56 @@ static VLC vlc_scalefactors;
29
 
 static VLC vlc_spectral[11];
30
 
 
31
 
 
32
 
+static ChannelElement* get_che(AACContext *ac, int type, int elem_id) {
33
 
+    static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 };
34
 
+    if (ac->tag_che_map[type][elem_id]) {
35
 
+        return ac->tag_che_map[type][elem_id];
36
 
+    }
37
 
+    if (ac->tags_mapped >= tags_per_config[ac->m4ac.chan_config]) {
38
 
+        return NULL;
39
 
+    }
40
 
+    switch (ac->m4ac.chan_config) {
41
 
+        case 7:
42
 
+            if (ac->tags_mapped == 3 && type == TYPE_CPE) {
43
 
+                ac->tags_mapped++;
44
 
+                return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
45
 
+            }
46
 
+        case 6:
47
 
+            /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
48
 
+               instead of SCE[0] CPE[0] CPE[0] LFE[0]. If we seem to have
49
 
+               encountered such a stream, transfer the LFE[0] element to SCE[1] */
50
 
+            if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
51
 
+                ac->tags_mapped++;
52
 
+                return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
53
 
+            }
54
 
+        case 5:
55
 
+            if (ac->tags_mapped == 2 && type == TYPE_CPE) {
56
 
+                ac->tags_mapped++;
57
 
+                return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
58
 
+            }
59
 
+        case 4:
60
 
+            if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {
61
 
+                ac->tags_mapped++;
62
 
+                return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
63
 
+            }
64
 
+        case 3:
65
 
+        case 2:
66
 
+            if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {
67
 
+                ac->tags_mapped++;
68
 
+                return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
69
 
+            } else if (ac->m4ac.chan_config == 2) {
70
 
+                return NULL;
71
 
+            }
72
 
+        case 1:
73
 
+            if (!ac->tags_mapped && type == TYPE_SCE) {
74
 
+                ac->tags_mapped++;
75
 
+                return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
76
 
+            }
77
 
+        default:
78
 
+            return NULL;
79
 
+    }
80
 
+}
81
 
+
82
 
 /**
83
 
  * Configure output channel order based on the current program configuration element.
84
 
  *
85
 
@@ -106,7 +156,7 @@ static VLC vlc_spectral[11];
86
 
  * @return  Returns error status. 0 - OK, !0 - error
87
 
  */
88
 
 static int output_configure(AACContext *ac, enum ChannelPosition che_pos[4][MAX_ELEM_ID],
89
 
-        enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]) {
90
 
+        enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], int channel_config) {
91
 
     AVCodecContext *avctx = ac->avccontext;
92
 
     int i, type, channels = 0;
93
 
 
94
 
@@ -140,7 +190,16 @@ static int output_configure(AACContext *ac, enum ChannelPosition che_pos[4][MAX_
95
 
         }
96
 
     }
97
 
 
98
 
+    if (channel_config) {
99
 
+        memset(ac->tag_che_map, 0,       4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
100
 
+        ac->tags_mapped = 0;
101
 
+    } else {
102
 
+        memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
103
 
+        ac->tags_mapped = 4*MAX_ELEM_ID;
104
 
+    }
105
 
+
106
 
     avctx->channels = channels;
107
 
+
108
 
     return 0;
109
 
 }
110
 
 
111
 
@@ -286,7 +345,7 @@ static int decode_ga_specific_config(AACContext * ac, GetBitContext * gb, int ch
112
 
         if((ret = set_default_channel_config(ac, new_che_pos, channel_config)))
113
 
             return ret;
114
 
     }
115
 
-    if((ret = output_configure(ac, ac->che_pos, new_che_pos)))
116
 
+    if((ret = output_configure(ac, ac->che_pos, new_che_pos, channel_config)))
117
 
         return ret;
118
 
 
119
 
     if (extension_flag) {
120
 
@@ -394,7 +453,7 @@ static av_cold int aac_decode_init(AVCodecContext * avccontext) {
121
 
         memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
122
 
         if(set_default_channel_config(ac, new_che_pos, avccontext->channels - (avccontext->channels == 8)))
123
 
             return -1;
124
 
-        if(output_configure(ac, ac->che_pos, new_che_pos))
125
 
+        if(output_configure(ac, ac->che_pos, new_che_pos, 1))
126
 
             return -1;
127
 
         ac->m4ac.sample_rate = avccontext->sample_rate;
128
 
     } else {
129
 
@@ -1538,19 +1597,20 @@ static int parse_adts_frame_header(AACContext * ac, GetBitContext * gb) {
130
 
         ac->m4ac.sample_rate     = hdr_info.sample_rate;
131
 
         ac->m4ac.sampling_index  = hdr_info.sampling_index;
132
 
         ac->m4ac.object_type     = hdr_info.object_type;
133
 
-    }
134
 
-    if (hdr_info.num_aac_frames == 1) {
135
 
-        if (!hdr_info.crc_absent)
136
 
-            skip_bits(gb, 16);
137
 
-    } else {
138
 
-        ff_log_missing_feature(ac->avccontext, "More than one AAC RDB per ADTS frame is", 0);
139
 
-        return -1;
140
 
+        if (hdr_info.num_aac_frames == 1) {
141
 
+            if (!hdr_info.crc_absent)
142
 
+                skip_bits(gb, 16);
143
 
+        } else {
144
 
+            ff_log_missing_feature(ac->avccontext, "More than one AAC RDB per ADTS frame is", 0);
145
 
+            return -1;
146
 
+        }
147
 
     }
148
 
     return size;
149
 
 }
150
 
 
151
 
 static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data_size, const uint8_t * buf, int buf_size) {
152
 
     AACContext * ac = avccontext->priv_data;
153
 
+    ChannelElement * che = NULL;
154
 
     GetBitContext gb;
155
 
     enum RawDataBlockType elem_type;
156
 
     int err, elem_id, data_size_tmp;
157
 
@@ -1573,15 +1633,7 @@ static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data
158
 
         elem_id = get_bits(&gb, 4);
159
 
         err = -1;
160
 
 
161
 
-        if(elem_type == TYPE_SCE && elem_id == 1 &&
162
 
-                !ac->che[TYPE_SCE][elem_id] && ac->che[TYPE_LFE][0]) {
163
 
-            /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
164
 
-               instead of SCE[0] CPE[0] CPE[0] LFE[0]. If we seem to have
165
 
-               encountered such a stream, transfer the LFE[0] element to SCE[1] */
166
 
-            ac->che[TYPE_SCE][elem_id] = ac->che[TYPE_LFE][0];
167
 
-            ac->che[TYPE_LFE][0] = NULL;
168
 
-        }
169
 
-        if(elem_type < TYPE_DSE && !ac->che[elem_type][elem_id]) {
170
 
+        if(elem_type < TYPE_DSE && !(che=get_che(ac, elem_type, elem_id))) {
171
 
             av_log(ac->avccontext, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", elem_type, elem_id);
172
 
             return -1;
173
 
         }
174
 
@@ -1589,19 +1641,19 @@ static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data
175
 
         switch (elem_type) {
176
 
 
177
 
         case TYPE_SCE:
178
 
-            err = decode_ics(ac, &ac->che[TYPE_SCE][elem_id]->ch[0], &gb, 0, 0);
179
 
+            err = decode_ics(ac, &che->ch[0], &gb, 0, 0);
180
 
             break;
181
 
 
182
 
         case TYPE_CPE:
183
 
-            err = decode_cpe(ac, &gb, ac->che[TYPE_CPE][elem_id]);
184
 
+            err = decode_cpe(ac, &gb, che);
185
 
             break;
186
 
 
187
 
         case TYPE_CCE:
188
 
-            err = decode_cce(ac, &gb, ac->che[TYPE_CCE][elem_id]);
189
 
+            err = decode_cce(ac, &gb, che);
190
 
             break;
191
 
 
192
 
         case TYPE_LFE:
193
 
-            err = decode_ics(ac, &ac->che[TYPE_LFE][elem_id]->ch[0], &gb, 0, 0);
194
 
+            err = decode_ics(ac, &che->ch[0], &gb, 0, 0);
195
 
             break;
196
 
 
197
 
         case TYPE_DSE:
198
 
@@ -1615,7 +1667,7 @@ static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data
199
 
             memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
200
 
             if((err = decode_pce(ac, new_che_pos, &gb)))
201
 
                 break;
202
 
-            err = output_configure(ac, ac->che_pos, new_che_pos);
203
 
+            err = output_configure(ac, ac->che_pos, new_che_pos, 0);
204
 
             break;
205
 
         }
206
 
 
207
 
        Modified libavcodec/aac.h
208
 
diff --git a/libavcodec/aac.h b/libavcodec/aac.h
209
 
index 66b2e22..32e7224 100644
210
 
--- a/libavcodec/aac.h
211
 
+++ b/libavcodec/aac.h
212
 
@@ -260,6 +260,8 @@ typedef struct {
213
 
                                                    *   first index as the first 4 raw data block types
214
 
                                                    */
215
 
     ChannelElement * che[4][MAX_ELEM_ID];
216
 
+    ChannelElement * tag_che_map[4][MAX_ELEM_ID];
217
 
+    int tags_mapped;
218
 
     /** @} */
219
 
 
220
 
     /**