annotate libmpcodecs/ad_libdca.c @ 33499:e4f533bf5a9a

Only enable NEED_GLOB on win32, currently this has the effect of compiling win32-only code - and even if that compiled it would not be used anyway!
author reimar
date Sat, 11 Jun 2011 16:40:10 +0000
parents 9986a61354e6
children baa7a9f7ce9e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
1 /*
26727
82601a38e2a7 Use standard license headers.
diego
parents: 25278
diff changeset
2 * DTS Coherent Acoustics stream decoder using libdca
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
3 * This file is partially based on dtsdec.c r9036 from FFmpeg and ad_liba52.c
26727
82601a38e2a7 Use standard license headers.
diego
parents: 25278
diff changeset
4 *
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
5 * Copyright (C) 2007 Roberto Togni
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
6 *
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
7 * This file is part of MPlayer.
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
8 *
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
9 * MPlayer is free software; you can redistribute it and/or modify
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
12 * (at your option) any later version.
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
13 *
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
14 * MPlayer is distributed in the hope that it will be useful,
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
17 * GNU General Public License for more details.
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
18 *
26727
82601a38e2a7 Use standard license headers.
diego
parents: 25278
diff changeset
19 * You should have received a copy of the GNU General Public License along
82601a38e2a7 Use standard license headers.
diego
parents: 25278
diff changeset
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
82601a38e2a7 Use standard license headers.
diego
parents: 25278
diff changeset
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
22 */
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
23
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
24 #include <stdio.h>
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
25 #include <stdlib.h>
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
26 #include <unistd.h>
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
27 #include <assert.h>
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
28 #include "config.h"
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
29
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
30 #include "mp_msg.h"
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
31 #include "ad_internal.h"
31986
9986a61354e6 Remove duplicated audio_output_channels extern variable declaration.
diego
parents: 30504
diff changeset
32 #include "dec_audio.h"
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
33
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
34 #include <dts.h>
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
35
30504
cc27da5d7286 Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents: 26727
diff changeset
36 static const ad_info_t info =
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
37 {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
38 "DTS decoding with libdca",
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
39 "libdca",
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
40 "Roberto Togni",
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
41 "",
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
42 ""
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
43 };
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
44
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
45 LIBAD_EXTERN(libdca)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
46
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
47 #define DTSBUFFER_SIZE 18726
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
48 #define HEADER_SIZE 14
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
49
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
50 #define CONVERT_LEVEL 1
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
51 #define CONVERT_BIAS 0
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
52
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
53 static const char ch2flags[6] = {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
54 DTS_MONO,
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
55 DTS_STEREO,
24701
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
56 DTS_3F,
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
57 DTS_2F2R,
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
58 DTS_3F2R,
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
59 DTS_3F2R | DTS_LFE
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
60 };
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
61
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
62 static inline int16_t convert(sample_t s)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
63 {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
64 int i = s * 0x7fff;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
65
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
66 return (i > 32767) ? 32767 : ((i < -32768) ? -32768 : i);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
67 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
68
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
69 static void convert2s16_multi(sample_t *f, int16_t *s16, int flags, int ch_out)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
70 {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
71 int i;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
72
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
73 switch(flags & (DTS_CHANNEL_MASK | DTS_LFE)){
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
74 case DTS_MONO:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
75 if (ch_out == 1)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
76 for(i = 0; i < 256; i++)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
77 s16[i] = convert(f[i]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
78 else
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
79 for(i = 0; i < 256; i++){
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
80 s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
81 s16[5*i+4] = convert(f[i]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
82 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
83 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
84 case DTS_CHANNEL:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
85 case DTS_STEREO:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
86 case DTS_DOLBY:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
87 for(i = 0; i < 256; i++){
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
88 s16[2*i] = convert(f[i]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
89 s16[2*i+1] = convert(f[i+256]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
90 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
91 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
92 case DTS_3F:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
93 for(i = 0; i < 256; i++){
24701
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
94 s16[3*i] = convert(f[i+256]);
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
95 s16[3*i+1] = convert(f[i+512]);
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
96 s16[3*i+2] = convert(f[i]);
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
97 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
98 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
99 case DTS_2F2R:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
100 for(i = 0; i < 256; i++){
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
101 s16[4*i] = convert(f[i]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
102 s16[4*i+1] = convert(f[i+256]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
103 s16[4*i+2] = convert(f[i+512]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
104 s16[4*i+3] = convert(f[i+768]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
105 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
106 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
107 case DTS_3F2R:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
108 for(i = 0; i < 256; i++){
24701
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
109 s16[5*i] = convert(f[i+256]);
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
110 s16[5*i+1] = convert(f[i+512]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
111 s16[5*i+2] = convert(f[i+768]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
112 s16[5*i+3] = convert(f[i+1024]);
24701
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
113 s16[5*i+4] = convert(f[i]);
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
114 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
115 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
116 case DTS_MONO | DTS_LFE:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
117 for(i = 0; i < 256; i++){
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
118 s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
24701
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
119 s16[6*i+4] = convert(f[i]);
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
120 s16[6*i+5] = convert(f[i+256]);
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
121 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
122 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
123 case DTS_CHANNEL | DTS_LFE:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
124 case DTS_STEREO | DTS_LFE:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
125 case DTS_DOLBY | DTS_LFE:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
126 for(i = 0; i < 256; i++){
24701
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
127 s16[6*i] = convert(f[i]);
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
128 s16[6*i+1] = convert(f[i+256]);
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
129 s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
24701
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
130 s16[6*i+5] = convert(f[i+512]);
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
131 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
132 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
133 case DTS_3F | DTS_LFE:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
134 for(i = 0; i < 256; i++){
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
135 s16[6*i] = convert(f[i+256]);
24701
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
136 s16[6*i+1] = convert(f[i+512]);
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
137 s16[6*i+2] = s16[6*i+3] = 0;
24701
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
138 s16[6*i+4] = convert(f[i]);
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
139 s16[6*i+5] = convert(f[i+768]);
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
140 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
141 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
142 case DTS_2F2R | DTS_LFE:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
143 for(i = 0; i < 256; i++){
24701
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
144 s16[6*i] = convert(f[i]);
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
145 s16[6*i+1] = convert(f[i+256]);
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
146 s16[6*i+2] = convert(f[i+512]);
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
147 s16[6*i+3] = convert(f[i+768]);
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
148 s16[6*i+4] = 0;
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
149 s16[6*i+5] = convert(f[1024]);
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
150 }
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
151 break;
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
152 case DTS_3F2R | DTS_LFE:
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
153 for(i = 0; i < 256; i++){
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
154 s16[6*i] = convert(f[i+256]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
155 s16[6*i+1] = convert(f[i+512]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
156 s16[6*i+2] = convert(f[i+768]);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
157 s16[6*i+3] = convert(f[i+1024]);
24701
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
158 s16[6*i+4] = convert(f[i]);
d51389598170 Fix output channle ordering
rtogni
parents: 24693
diff changeset
159 s16[6*i+5] = convert(f[i+1280]);
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
160 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
161 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
162 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
163 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
164
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
165 static void channels_info(int flags)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
166 {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
167 int lfe = 0;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
168 char lfestr[5] = "";
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
169
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
170 if (flags & DTS_LFE) {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
171 lfe = 1;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
172 strcpy(lfestr, "+lfe");
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
173 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
174 mp_msg(MSGT_DECAUDIO, MSGL_V, "DTS: ");
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
175 switch(flags & DTS_CHANNEL_MASK){
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
176 case DTS_MONO:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
177 mp_msg(MSGT_DECAUDIO, MSGL_V, "1.%d (mono%s)", lfe, lfestr);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
178 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
179 case DTS_CHANNEL:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
180 mp_msg(MSGT_DECAUDIO, MSGL_V, "2.%d (channel%s)", lfe, lfestr);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
181 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
182 case DTS_STEREO:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
183 mp_msg(MSGT_DECAUDIO, MSGL_V, "2.%d (stereo%s)", lfe, lfestr);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
184 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
185 case DTS_3F:
24693
rtogni
parents: 23918
diff changeset
186 mp_msg(MSGT_DECAUDIO, MSGL_V, "3.%d (3f%s)", lfe, lfestr);
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
187 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
188 case DTS_2F2R:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
189 mp_msg(MSGT_DECAUDIO, MSGL_V, "4.%d (2f+2r%s)", lfe, lfestr);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
190 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
191 case DTS_3F2R:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
192 mp_msg(MSGT_DECAUDIO, MSGL_V, "5.%d (3f+2r%s)", lfe, lfestr);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
193 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
194 default:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
195 mp_msg(MSGT_DECAUDIO, MSGL_V, "x.%d (unknown%s)", lfe, lfestr);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
196 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
197 mp_msg(MSGT_DECAUDIO, MSGL_V, "\n");
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
198 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
199
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
200 static int dts_sync(sh_audio_t *sh, int *flags)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
201 {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
202 dts_state_t *s = sh->context;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
203 int length;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
204 int sample_rate;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
205 int frame_length;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
206 int bit_rate;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
207
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
208 sh->a_in_buffer_len=0;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
209
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
210 while(1) {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
211 while(sh->a_in_buffer_len < HEADER_SIZE) {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
212 int c = demux_getc(sh->ds);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
213
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
214 if(c < 0)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
215 return -1;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
216 sh->a_in_buffer[sh->a_in_buffer_len++] = c;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
217 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
218
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
219 length = dts_syncinfo(s, sh->a_in_buffer, flags, &sample_rate,
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
220 &bit_rate, &frame_length);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
221
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
222 if(length >= HEADER_SIZE)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
223 break;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
224
25278
b037a816be70 Prevent from outputing mass of 'skip' log messages in verbose level.
ulion
parents: 24701
diff changeset
225 // mp_msg(MSGT_DECAUDIO, MSGL_V, "skip\n");
23821
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
226 memmove(sh->a_in_buffer, sh->a_in_buffer+1, HEADER_SIZE-1);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
227 --sh->a_in_buffer_len;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
228 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
229
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
230 demux_read_data(sh->ds, sh->a_in_buffer + HEADER_SIZE, length - HEADER_SIZE);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
231
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
232 sh->samplerate = sample_rate;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
233 sh->i_bps = bit_rate/8;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
234
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
235 return length;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
236 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
237
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
238 static int decode_audio(sh_audio_t *sh, unsigned char *buf, int minlen, int maxlen)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
239 {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
240 dts_state_t *s = sh->context;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
241 int16_t *out_samples = (int16_t*)buf;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
242 int flags;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
243 level_t level;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
244 sample_t bias;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
245 int nblocks;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
246 int i;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
247 int data_size = 0;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
248
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
249 if(!sh->a_in_buffer_len)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
250 if(dts_sync(sh, &flags) < 0) return -1; /* EOF */
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
251 sh->a_in_buffer_len=0;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
252
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
253 flags &= ~(DTS_CHANNEL_MASK | DTS_LFE);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
254 flags |= ch2flags[sh->channels - 1];
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
255
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
256 level = CONVERT_LEVEL;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
257 bias = CONVERT_BIAS;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
258 flags |= DTS_ADJUST_LEVEL;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
259 if(dts_frame(s, sh->a_in_buffer, &flags, &level, bias)) {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
260 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "dts_frame() failed\n");
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
261 goto end;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
262 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
263
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
264 nblocks = dts_blocks_num(s);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
265
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
266 for(i = 0; i < nblocks; i++) {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
267 if(dts_block(s)) {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
268 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "dts_block() failed\n");
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
269 goto end;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
270 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
271
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
272 convert2s16_multi(dts_samples(s), out_samples, flags, sh->channels);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
273
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
274 out_samples += 256 * sh->channels;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
275 data_size += 256 * sizeof(int16_t) * sh->channels;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
276 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
277
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
278 end:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
279 return data_size;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
280 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
281
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
282 static int preinit(sh_audio_t *sh)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
283 {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
284 /* 256 = samples per block, 16 = max number of blocks */
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
285 sh->audio_out_minsize = audio_output_channels * sizeof(int16_t) * 256 * 16;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
286 sh->audio_in_minsize = DTSBUFFER_SIZE;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
287 sh->samplesize=2;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
288
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
289 return 1;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
290 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
291
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
292 static int init(sh_audio_t *sh)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
293 {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
294 dts_state_t *s;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
295 int flags;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
296 int decoded_bytes;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
297
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
298 s = dts_init(0);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
299 if(s == NULL) {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
300 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "dts_init() failed\n");
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
301 return 0;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
302 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
303 sh->context = s;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
304
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
305 if(dts_sync(sh, &flags) < 0) {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
306 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "dts sync failed\n");
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
307 dts_free(s);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
308 return 0;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
309 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
310 channels_info(flags);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
311
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
312 assert(audio_output_channels >= 1 && audio_output_channels <= 6);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
313 sh->channels = audio_output_channels;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
314
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
315 decoded_bytes = decode_audio(sh, sh->a_buffer, 1, sh->a_buffer_size);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
316 if(decoded_bytes > 0)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
317 sh->a_buffer_len = decoded_bytes;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
318 else {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
319 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "dts decode failed on first frame (up/downmix problem?)\n");
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
320 dts_free(s);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
321 return 0;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
322 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
323
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
324 return 1;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
325 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
326
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
327 static void uninit(sh_audio_t *sh)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
328 {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
329 dts_state_t *s = sh->context;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
330
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
331 dts_free(s);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
332 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
333
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
334 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
335 {
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
336 int flags;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
337
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
338 switch(cmd){
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
339 case ADCTRL_RESYNC_STREAM:
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
340 dts_sync(sh, &flags);
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
341 return CONTROL_TRUE;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
342 }
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
343 return CONTROL_UNKNOWN;
46b21d6fb61d DTS decoding via libdca
rtogni
parents:
diff changeset
344 }