annotate dtsdec.c @ 5016:3674582fb4e7 libavcodec

Remove lots of unused commented code. (Cleanup)
author banan
date Thu, 17 May 2007 07:50:08 +0000
parents 03aa103464d4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
1 /*
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
2 * dtsdec.c : free DTS Coherent Acoustics stream decoder.
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
3 * Copyright (C) 2004 Benjamin Zores <ben@geexbox.org>
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3267
diff changeset
5 * This file is part of FFmpeg.
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
6 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3267
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or modify
2126
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
8 * it under the terms of the GNU General Public License as published by
3965
418b123f1b74 Fix GPL/LGPL license version mismatch.
diego
parents: 3947
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
2126
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
10 * (at your option) any later version.
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2222
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3267
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2126
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
15 * GNU General Public License for more details.
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2222
diff changeset
16 *
2126
181cb6785f6b remove dts_internal.h
michael
parents: 2123
diff changeset
17 * You should have received a copy of the GNU General Public License
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3267
diff changeset
18 * along with FFmpeg; if not, write to the Free Software
4385
c0e2e4249145 Fix FSF postal address.
diego
parents: 4170
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
20 */
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
21
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
22 #include "avcodec.h"
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
23 #include <dts.h>
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
24
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
25 #include <stdlib.h>
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
26 #include <string.h>
2186
be0ad4f3e8ea bsd patch by (Bohdan Horst <nexus at irc dot pl>)
michael
parents: 2141
diff changeset
27
3267
8072ed8993f6 dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents: 2979
diff changeset
28 #define BUFFER_SIZE 18726
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
29 #define HEADER_SIZE 14
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
30
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
31 #define CONVERT_LEVEL 1
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
32 #define CONVERT_BIAS 0
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
33
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
34 typedef struct DTSContext {
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
35 dts_state_t *state;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
36 uint8_t buf[BUFFER_SIZE];
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
37 uint8_t *bufptr;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
38 uint8_t *bufpos;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
39 } DTSContext;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
40
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
41 static inline int16_t
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
42 convert(sample_t s)
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
43 {
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
44 return s * 0x7fff;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
45 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
46
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
47 static void
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
48 convert2s16_multi(sample_t *f, int16_t *s16, int flags)
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
49 {
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
50 int i;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
51
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
52 switch(flags & (DTS_CHANNEL_MASK | DTS_LFE)){
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
53 case DTS_MONO:
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
54 for(i = 0; i < 256; i++){
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
55 s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
56 s16[5*i+4] = convert(f[i]);
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
57 }
5011
03aa103464d4 DTS decoding was broken for every speaker configuration except 5.1.
diego
parents: 4897
diff changeset
58 break;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
59 case DTS_CHANNEL:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
60 case DTS_STEREO:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
61 case DTS_DOLBY:
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
62 for(i = 0; i < 256; i++){
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
63 s16[2*i] = convert(f[i]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
64 s16[2*i+1] = convert(f[i+256]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
65 }
5011
03aa103464d4 DTS decoding was broken for every speaker configuration except 5.1.
diego
parents: 4897
diff changeset
66 break;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
67 case DTS_3F:
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
68 for(i = 0; i < 256; i++){
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
69 s16[5*i] = convert(f[i+256]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
70 s16[5*i+1] = convert(f[i+512]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
71 s16[5*i+2] = s16[5*i+3] = 0;
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
72 s16[5*i+4] = convert(f[i]);
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
73 }
5011
03aa103464d4 DTS decoding was broken for every speaker configuration except 5.1.
diego
parents: 4897
diff changeset
74 break;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
75 case DTS_2F2R:
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
76 for(i = 0; i < 256; i++){
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
77 s16[4*i] = convert(f[i]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
78 s16[4*i+1] = convert(f[i+256]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
79 s16[4*i+2] = convert(f[i+512]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
80 s16[4*i+3] = convert(f[i+768]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
81 }
5011
03aa103464d4 DTS decoding was broken for every speaker configuration except 5.1.
diego
parents: 4897
diff changeset
82 break;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
83 case DTS_3F2R:
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
84 for(i = 0; i < 256; i++){
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
85 s16[5*i] = convert(f[i+256]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
86 s16[5*i+1] = convert(f[i+512]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
87 s16[5*i+2] = convert(f[i+768]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
88 s16[5*i+3] = convert(f[i+1024]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
89 s16[5*i+4] = convert(f[i]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
90 }
5011
03aa103464d4 DTS decoding was broken for every speaker configuration except 5.1.
diego
parents: 4897
diff changeset
91 break;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
92 case DTS_MONO | DTS_LFE:
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
93 for(i = 0; i < 256; i++){
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
94 s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
95 s16[6*i+4] = convert(f[i]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
96 s16[6*i+5] = convert(f[i+256]);
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
97 }
5011
03aa103464d4 DTS decoding was broken for every speaker configuration except 5.1.
diego
parents: 4897
diff changeset
98 break;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
99 case DTS_CHANNEL | DTS_LFE:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
100 case DTS_STEREO | DTS_LFE:
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
101 case DTS_DOLBY | DTS_LFE:
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
102 for(i = 0; i < 256; i++){
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
103 s16[6*i] = convert(f[i]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
104 s16[6*i+1] = convert(f[i+256]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
105 s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
106 s16[6*i+5] = convert(f[i+512]);
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
107 }
5011
03aa103464d4 DTS decoding was broken for every speaker configuration except 5.1.
diego
parents: 4897
diff changeset
108 break;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
109 case DTS_3F | DTS_LFE:
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
110 for(i = 0; i < 256; i++){
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
111 s16[6*i] = convert(f[i+256]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
112 s16[6*i+1] = convert(f[i+512]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
113 s16[6*i+2] = s16[6*i+3] = 0;
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
114 s16[6*i+4] = convert(f[i]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
115 s16[6*i+5] = convert(f[i+768]);
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
116 }
5011
03aa103464d4 DTS decoding was broken for every speaker configuration except 5.1.
diego
parents: 4897
diff changeset
117 break;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
118 case DTS_2F2R | DTS_LFE:
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
119 for(i = 0; i < 256; i++){
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
120 s16[6*i] = convert(f[i]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
121 s16[6*i+1] = convert(f[i+256]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
122 s16[6*i+2] = convert(f[i+512]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
123 s16[6*i+3] = convert(f[i+768]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
124 s16[6*i+4] = 0;
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
125 s16[6*i+5] = convert(f[i+1024]);
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
126 }
5011
03aa103464d4 DTS decoding was broken for every speaker configuration except 5.1.
diego
parents: 4897
diff changeset
127 break;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
128 case DTS_3F2R | DTS_LFE:
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
129 for(i = 0; i < 256; i++){
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
130 s16[6*i] = convert(f[i+256]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
131 s16[6*i+1] = convert(f[i+512]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
132 s16[6*i+2] = convert(f[i+768]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
133 s16[6*i+3] = convert(f[i+1024]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
134 s16[6*i+4] = convert(f[i]);
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
135 s16[6*i+5] = convert(f[i+1280]);
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
136 }
5011
03aa103464d4 DTS decoding was broken for every speaker configuration except 5.1.
diego
parents: 4897
diff changeset
137 break;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
138 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
139 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
140
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
141 static int
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
142 channels_multi(int flags)
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
143 {
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
144 switch(flags & (DTS_CHANNEL_MASK | DTS_LFE)){
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
145 case DTS_CHANNEL:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
146 case DTS_STEREO:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
147 case DTS_DOLBY:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
148 return 2;
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
149 case DTS_2F2R:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
150 return 4;
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
151 case DTS_MONO:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
152 case DTS_3F:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
153 case DTS_3F2R:
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
154 return 5;
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
155 case DTS_MONO | DTS_LFE:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
156 case DTS_CHANNEL | DTS_LFE:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
157 case DTS_STEREO | DTS_LFE:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
158 case DTS_DOLBY | DTS_LFE:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
159 case DTS_3F | DTS_LFE:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
160 case DTS_2F2R | DTS_LFE:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
161 case DTS_3F2R | DTS_LFE:
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
162 return 6;
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
163 }
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
164
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
165 return -1;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
166 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
167
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
168 static int
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
169 dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
170 uint8_t * buff, int buff_size)
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
171 {
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
172 DTSContext *s = avctx->priv_data;
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
173 uint8_t *start = buff;
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
174 uint8_t *end = buff + buff_size;
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
175 int16_t *out_samples = data;
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
176 int sample_rate;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
177 int frame_length;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
178 int flags;
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
179 int bit_rate;
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
180 int len;
4479
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
181 level_t level;
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
182 sample_t bias;
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
183 int nblocks;
4479
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
184 int i;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
185
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
186 *data_size = 0;
2222
ef568cc0972c 10l (gcc 2.95 compilation)
michael
parents: 2186
diff changeset
187
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
188 while(1) {
4479
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
189 int length;
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
190
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
191 len = end - start;
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
192 if(!len)
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
193 break;
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
194 if(len > s->bufpos - s->bufptr)
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
195 len = s->bufpos - s->bufptr;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
196 memcpy(s->bufptr, start, len);
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
197 s->bufptr += len;
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
198 start += len;
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
199 if(s->bufptr != s->bufpos)
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
200 return start - buff;
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
201 if(s->bufpos != s->buf + HEADER_SIZE)
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
202 break;
3267
8072ed8993f6 dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents: 2979
diff changeset
203
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
204 length = dts_syncinfo(s->state, s->buf, &flags, &sample_rate,
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
205 &bit_rate, &frame_length);
4479
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
206 if(!length) {
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
207 av_log(NULL, AV_LOG_INFO, "skip\n");
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
208 for(s->bufptr = s->buf; s->bufptr < s->buf + HEADER_SIZE - 1; s->bufptr++)
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
209 s->bufptr[0] = s->bufptr[1];
4479
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
210 continue;
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
211 }
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
212 s->bufpos = s->buf + length;
4479
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
213 }
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
214
4479
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
215 level = CONVERT_LEVEL;
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
216 bias = CONVERT_BIAS;
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
217
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
218 flags |= DTS_ADJUST_LEVEL;
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
219 if(dts_frame(s->state, s->buf, &flags, &level, bias)) {
4479
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
220 av_log(avctx, AV_LOG_ERROR, "dts_frame() failed\n");
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
221 goto end;
3267
8072ed8993f6 dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents: 2979
diff changeset
222 }
8072ed8993f6 dtsdec.c copies one input packet at a time to a (static) buffer of size
rtognimp
parents: 2979
diff changeset
223
4479
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
224 avctx->sample_rate = sample_rate;
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
225 avctx->channels = channels_multi(flags);
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
226 avctx->bit_rate = bit_rate;
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
227
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
228 nblocks = dts_blocks_num(s->state);
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
229
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
230 for(i = 0; i < nblocks; i++) {
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
231 if(dts_block(s->state)) {
4479
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
232 av_log(avctx, AV_LOG_ERROR, "dts_block() failed\n");
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
233 goto end;
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
234 }
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
235
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
236 convert2s16_multi(dts_samples(s->state), out_samples, flags);
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
237
4482
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
238 out_samples += 256 * avctx->channels;
ee7422a921cb fix multichannel decoding
mru
parents: 4481
diff changeset
239 *data_size += 256 * sizeof(int16_t) * avctx->channels;
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
240 }
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
241
4479
f1057be02298 cosmetics: don't needlessly open new blocks
mru
parents: 4478
diff changeset
242 end:
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
243 s->bufptr = s->buf;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
244 s->bufpos = s->buf + HEADER_SIZE;
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
245 return start - buff;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
246 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
247
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
248 static int
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
249 dts_decode_init(AVCodecContext * avctx)
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
250 {
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
251 DTSContext *s = avctx->priv_data;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
252 s->bufptr = s->buf;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
253 s->bufpos = s->buf + HEADER_SIZE;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
254 s->state = dts_init(0);
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
255 if(s->state == NULL)
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
256 return -1;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
257
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
258 return 0;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
259 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
260
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
261 static int
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
262 dts_decode_end(AVCodecContext * avctx)
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
263 {
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
264 DTSContext *s = avctx->priv_data;
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
265 dts_free(s->state);
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
266 return 0;
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
267 }
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
268
4897
8f47dc8782f9 Rename dts_decoder to libdts_decoder.
diego
parents: 4482
diff changeset
269 AVCodec libdts_decoder = {
8f47dc8782f9 Rename dts_decoder to libdts_decoder.
diego
parents: 4482
diff changeset
270 "libdts",
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
271 CODEC_TYPE_AUDIO,
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
272 CODEC_ID_DTS,
4481
f3987e08b9da move static variables to private context struct
mru
parents: 4480
diff changeset
273 sizeof(DTSContext),
4478
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
274 dts_decode_init,
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
275 NULL,
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
276 dts_decode_end,
ca8c6efd00d3 cosmetic: indent sensibly so code can be read at all
mru
parents: 4411
diff changeset
277 dts_decode_frame,
2123
ef54decf5624 libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
diff changeset
278 };