Mercurial > mplayer.hg
annotate libmpcodecs/ad_hwac3.c @ 27031:0f7770b2230d
Move message about which adapter is used to verbose mode.
author | diego |
---|---|
date | Sun, 15 Jun 2008 12:13:29 +0000 |
parents | cbd9c19ce4d8 |
children | 3d8e6afe3f9f |
rev | line source |
---|---|
5370 | 1 |
2 // Reference: DOCS/tech/hwac3.txt !!!!! | |
3 | |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
4 /* DTS code based on "ac3/decode_dts.c" and "ac3/conversion.c" from "ogle 0.9" |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
5 (see http://www.dtek.chalmers.se/~dvd/) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
6 */ |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
7 |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
8 #include <stdio.h> |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
9 #include <stdlib.h> |
5370 | 10 #include <string.h> |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
11 #include <unistd.h> |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
12 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
13 #include "config.h" |
8026
b465ba5897a3
usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents:
7405
diff
changeset
|
14 #ifdef USE_LIBA52 |
b465ba5897a3
usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents:
7405
diff
changeset
|
15 |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
16 #include "mp_msg.h" |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
17 #include "help_mp.h" |
23638
a81e246e3b38
Make sure we always have a swab() prototype when we use it,
reimar
parents:
18512
diff
changeset
|
18 #include "mpbswap.h" |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
19 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
20 #include "ad_internal.h" |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
21 |
17012 | 22 #include "liba52/a52.h" |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
23 |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
24 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
25 static int isdts = -1; |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
26 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
27 static ad_info_t info = |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
28 { |
14710 | 29 "AC3/DTS pass-through S/PDIF", |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
30 "hwac3", |
23734 | 31 "Nick Kurshev/Peter Schüller", |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
32 "???", |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
33 "" |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
34 }; |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
35 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
36 LIBAD_EXTERN(hwac3) |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
37 |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
38 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
39 static int dts_syncinfo(uint8_t *indata_ptr, int *flags, int *sample_rate, int *bit_rate); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
40 static int decode_audio_dts(unsigned char *indata_ptr, int len, unsigned char *buf); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
41 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
42 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
43 static int ac3dts_fillbuff(sh_audio_t *sh_audio) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
44 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
45 int length = 0; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
46 int flags = 0; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
47 int sample_rate = 0; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
48 int bit_rate = 0; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
49 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
50 sh_audio->a_in_buffer_len = 0; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
51 /* sync frame:*/ |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
52 while(1) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
53 { |
25102
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
54 // Original code DTS has a 10 bytes header. |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
55 // Now max 12 bytes for 14 bits DTS header. |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
56 while(sh_audio->a_in_buffer_len < 12) |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
57 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
58 int c = demux_getc(sh_audio->ds); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
59 if(c<0) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
60 return -1; /* EOF*/ |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
61 sh_audio->a_in_buffer[sh_audio->a_in_buffer_len++] = c; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
62 } |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
63 |
26661 | 64 if (sh_audio->format == 0x2001) |
65 { | |
26662 | 66 length = dts_syncinfo(sh_audio->a_in_buffer, &flags, &sample_rate, &bit_rate); |
67 if(length >= 12) | |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
68 { |
26662 | 69 if(isdts != 1) |
70 { | |
71 mp_msg(MSGT_DECAUDIO, MSGL_STATUS, "hwac3: switched to DTS, %d bps, %d Hz\n", bit_rate, sample_rate); | |
72 isdts = 1; | |
73 } | |
74 break; | |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
75 } |
26661 | 76 } |
77 else | |
78 { | |
26662 | 79 length = a52_syncinfo(sh_audio->a_in_buffer, &flags, &sample_rate, &bit_rate); |
80 if(length >= 7 && length <= 3840) | |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
81 { |
26662 | 82 if(isdts != 0) |
83 { | |
84 mp_msg(MSGT_DECAUDIO, MSGL_STATUS, "hwac3: switched to AC3, %d bps, %d Hz\n", bit_rate, sample_rate); | |
85 isdts = 0; | |
86 } | |
87 break; /* we're done.*/ | |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
88 } |
26661 | 89 } |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
90 /* bad file => resync*/ |
25102
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
91 memcpy(sh_audio->a_in_buffer, sh_audio->a_in_buffer + 1, 11); |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
92 --sh_audio->a_in_buffer_len; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
93 } |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
94 mp_msg(MSGT_DECAUDIO, MSGL_DBG2, "ac3dts: %s len=%d flags=0x%X %d Hz %d bit/s\n", isdts == 1 ? "DTS" : isdts == 0 ? "AC3" : "unknown", length, flags, sample_rate, bit_rate); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
95 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
96 sh_audio->samplerate = sample_rate; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
97 sh_audio->i_bps = bit_rate / 8; |
25102
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
98 demux_read_data(sh_audio->ds, sh_audio->a_in_buffer + 12, length - 12); |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
99 sh_audio->a_in_buffer_len = length; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
100 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
101 // TODO: is DTS also checksummed? |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
102 if(isdts == 0 && crc16_block(sh_audio->a_in_buffer + 2, length - 2) != 0) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
103 mp_msg(MSGT_DECAUDIO, MSGL_STATUS, "a52: CRC check failed! \n"); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
104 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
105 return length; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
106 } |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
107 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
108 |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
109 static int preinit(sh_audio_t *sh) |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
110 { |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
111 /* Dolby AC3 audio: */ |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
112 sh->audio_out_minsize = 128 * 32 * 2 * 2; // DTS seems to need more than AC3 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
113 sh->audio_in_minsize = 8192; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
114 sh->channels = 2; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
115 sh->samplesize = 2; |
14245 | 116 sh->sample_format = AF_FORMAT_AC3; |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
117 return 1; |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
118 } |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
119 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
120 static int init(sh_audio_t *sh_audio) |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
121 { |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
122 /* Dolby AC3 passthrough:*/ |
18512 | 123 a52_state_t *a52_state = a52_init(0); |
124 if(a52_state == NULL) | |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
125 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
126 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "A52 init failed\n"); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
127 return 0; |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
128 } |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
129 if(ac3dts_fillbuff(sh_audio) < 0) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
130 { |
26923 | 131 a52_free(a52_state); |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
132 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "AC3/DTS sync failed\n"); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
133 return 0; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
134 } |
26923 | 135 sh_audio->context = a52_state; |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
136 return 1; |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
137 } |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
138 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
139 static void uninit(sh_audio_t *sh) |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
140 { |
26923 | 141 a52_free(sh->context); |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
142 } |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
143 |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
144 static int control(sh_audio_t *sh,int cmd,void* arg, ...) |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
145 { |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
146 switch(cmd) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
147 { |
15558 | 148 case ADCTRL_RESYNC_STREAM: |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
149 case ADCTRL_SKIP_FRAME: |
15558 | 150 ac3dts_fillbuff(sh); |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
151 return CONTROL_TRUE; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
152 } |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
153 return CONTROL_UNKNOWN; |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
154 } |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
155 |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
156 |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
157 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen) |
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
158 { |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
159 int len = sh_audio->a_in_buffer_len; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
160 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
161 if(len <= 0) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
162 if((len = ac3dts_fillbuff(sh_audio)) <= 0) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
163 return len; /*EOF*/ |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
164 sh_audio->a_in_buffer_len = 0; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
165 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
166 if(isdts == 1) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
167 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
168 return decode_audio_dts(sh_audio->a_in_buffer, len, buf); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
169 } |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
170 else if(isdts == 0) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
171 { |
24432
79fcacd73f9b
Simplify and fix big-endian hwac3 header generation code.
reimar
parents:
23734
diff
changeset
|
172 uint16_t *buf16 = (uint16_t *)buf; |
24433
435b37266f1e
Improved comments, based on patches by Ulion [ulion2002 gmail com]
reimar
parents:
24432
diff
changeset
|
173 buf16[0] = 0xF872; // iec 61937 syncword 1 |
435b37266f1e
Improved comments, based on patches by Ulion [ulion2002 gmail com]
reimar
parents:
24432
diff
changeset
|
174 buf16[1] = 0x4E1F; // iec 61937 syncword 2 |
435b37266f1e
Improved comments, based on patches by Ulion [ulion2002 gmail com]
reimar
parents:
24432
diff
changeset
|
175 buf16[2] = 0x0001; // data-type ac3 |
24509
767a9fd651c7
Copy AC-3 bsmod field into IEC data-type field as required by the specs
reimar
parents:
24508
diff
changeset
|
176 buf16[2] |= (sh_audio->a_in_buffer[5] & 0x7) << 8; // bsmod |
24433
435b37266f1e
Improved comments, based on patches by Ulion [ulion2002 gmail com]
reimar
parents:
24432
diff
changeset
|
177 buf16[3] = len << 3; // number of bits in payload |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
178 #ifdef WORDS_BIGENDIAN |
24433
435b37266f1e
Improved comments, based on patches by Ulion [ulion2002 gmail com]
reimar
parents:
24432
diff
changeset
|
179 memcpy(buf + 8, sh_audio->a_in_buffer, len); |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
180 #else |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
181 swab(sh_audio->a_in_buffer, buf + 8, len); |
24508
4f9b7524f65d
Handle swab when input length is odd (treat it as if there was an additional
reimar
parents:
24436
diff
changeset
|
182 if (len & 1) { |
4f9b7524f65d
Handle swab when input length is odd (treat it as if there was an additional
reimar
parents:
24436
diff
changeset
|
183 buf[8+len-1] = 0; |
4f9b7524f65d
Handle swab when input length is odd (treat it as if there was an additional
reimar
parents:
24436
diff
changeset
|
184 buf[8+len] = sh_audio->a_in_buffer[len-1]; |
4f9b7524f65d
Handle swab when input length is odd (treat it as if there was an additional
reimar
parents:
24436
diff
changeset
|
185 len++; |
4f9b7524f65d
Handle swab when input length is odd (treat it as if there was an additional
reimar
parents:
24436
diff
changeset
|
186 } |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
187 #endif |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
188 memset(buf + 8 + len, 0, 6144 - 8 - len); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
189 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
190 return 6144; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
191 } |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
192 else |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
193 return -1; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
194 } |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
195 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
196 |
24435 | 197 static const int DTS_SAMPLEFREQS[16] = |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
198 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
199 0, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
200 8000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
201 16000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
202 32000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
203 64000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
204 128000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
205 11025, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
206 22050, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
207 44100, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
208 88200, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
209 176400, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
210 12000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
211 24000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
212 48000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
213 96000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
214 192000 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
215 }; |
5370 | 216 |
24435 | 217 static const int DTS_BITRATES[30] = |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
218 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
219 32000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
220 56000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
221 64000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
222 96000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
223 112000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
224 128000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
225 192000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
226 224000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
227 256000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
228 320000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
229 384000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
230 448000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
231 512000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
232 576000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
233 640000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
234 768000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
235 896000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
236 1024000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
237 1152000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
238 1280000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
239 1344000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
240 1408000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
241 1411200, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
242 1472000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
243 1536000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
244 1920000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
245 2048000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
246 3072000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
247 3840000, |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
248 4096000 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
249 }; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
250 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
251 static int dts_decode_header(uint8_t *indata_ptr, int *rate, int *nblks, int *sfreq) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
252 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
253 int ftype; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
254 int surp; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
255 int unknown_bit; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
256 int fsize; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
257 int amode; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
258 |
25102
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
259 int word_mode; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
260 int le_mode; |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
261 |
25102
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
262 unsigned int first4bytes = indata_ptr[0] << 24 | indata_ptr[1] << 16 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
263 | indata_ptr[2] << 8 | indata_ptr[3]; |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
264 |
25102
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
265 switch(first4bytes) |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
266 { |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
267 /* 14 bits LE */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
268 case 0xff1f00e8: |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
269 /* Also make sure frame type is 1. */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
270 if ((indata_ptr[4]&0xf0) != 0xf0 || indata_ptr[5] != 0x07) |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
271 return -1; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
272 word_mode = 0; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
273 le_mode = 1; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
274 break; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
275 /* 14 bits BE */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
276 case 0x1fffe800: |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
277 /* Also make sure frame type is 1. */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
278 if (indata_ptr[4] != 0x07 || (indata_ptr[5]&0xf0) != 0xf0) |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
279 return -1; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
280 word_mode = 0; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
281 le_mode = 0; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
282 break; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
283 /* 16 bits LE */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
284 case 0xfe7f0180: |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
285 word_mode = 1; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
286 le_mode = 1; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
287 break; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
288 /* 16 bits BE */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
289 case 0x7ffe8001: |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
290 word_mode = 1; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
291 le_mode = 0; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
292 break; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
293 default: |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
294 return -1; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
295 } |
5370 | 296 |
25102
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
297 if(word_mode) |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
298 { |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
299 /* First bit after first 32 bits: |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
300 Frame type ( 1: Normal frame; 0: Termination frame ) */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
301 ftype = indata_ptr[4+le_mode] >> 7; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
302 |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
303 if(ftype != 1) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
304 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
305 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "DTS: Termination frames not handled, REPORT BUG\n"); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
306 return -1; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
307 } |
25102
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
308 /* Next 5 bits: Surplus Sample Count V SURP 5 bits */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
309 surp = indata_ptr[4+le_mode] >> 2 & 0x1f; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
310 /* Number of surplus samples */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
311 surp = (surp + 1) % 32; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
312 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
313 /* One unknown bit, crc? */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
314 unknown_bit = indata_ptr[4+le_mode] >> 1 & 0x01; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
315 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
316 /* NBLKS 7 bits: Valid Range=5-127, Invalid Range=0-4 */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
317 *nblks = (indata_ptr[4+le_mode] & 0x01) << 6 | indata_ptr[5-le_mode] >> 2; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
318 /* NBLKS+1 indicates the number of 32 sample PCM audio blocks per channel |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
319 encoded in the current frame per channel. */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
320 ++(*nblks); |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
321 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
322 /* Frame Byte Size V FSIZE 14 bits: 0-94=Invalid, 95-8191=Valid range-1 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
323 (ie. 96 bytes to 8192 bytes), 8192-16383=Invalid |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
324 FSIZE defines the byte size of the current audio frame. */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
325 fsize = (indata_ptr[5-le_mode] & 0x03) << 12 | indata_ptr[6+le_mode] << 4 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
326 | indata_ptr[7-le_mode] >> 4; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
327 ++fsize; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
328 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
329 /* Audio Channel Arrangement ACC AMODE 6 bits */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
330 amode = (indata_ptr[7-le_mode] & 0x0f) << 2 | indata_ptr[8+le_mode] >> 6; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
331 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
332 /* Source Sampling rate ACC SFREQ 4 bits */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
333 *sfreq = indata_ptr[8+le_mode] >> 2 & 0x0f; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
334 /* Transmission Bit Rate ACC RATE 5 bits */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
335 *rate = (indata_ptr[8+le_mode] & 0x03) << 3 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
336 | (indata_ptr[9-le_mode] >> 5 & 0x07); |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
337 } |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
338 else |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
339 { |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
340 /* in the case judgement, we assure this */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
341 ftype = 1; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
342 surp = 0; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
343 /* 14 bits support, every 2 bytes, & 0x3fff, got used 14 bits */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
344 /* Bits usage: |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
345 32 bits: Sync code (28 + 4) 1th and 2th word, 4 bits in 3th word |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
346 1 bits: Frame type 1 bits in 3th word |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
347 5 bits: SURP 5 bits in 3th word |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
348 1 bits: crc? 1 bits in 3th word |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
349 7 bits: NBLKS 3 bits in 3th word, 4 bits in 4th word |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
350 14 bits: FSIZE 10 bits in 4th word, 4 bits in 5th word |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
351 in 14 bits mode, FSIZE = FSIZE*8/14*2 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
352 6 bits: AMODE 6 bits in 5th word |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
353 4 bits: SFREQ 4 bits in 5th word |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
354 5 bits: RATE 5 bits in 6th word |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
355 total bits: 75 bits */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
356 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
357 /* NBLKS 7 bits: Valid Range=5-127, Invalid Range=0-4 */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
358 *nblks = (indata_ptr[5-le_mode] & 0x07) << 4 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
359 | (indata_ptr[6+le_mode] & 0x3f) >> 2; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
360 /* NBLKS+1 indicates the number of 32 sample PCM audio blocks per channel |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
361 encoded in the current frame per channel. */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
362 ++(*nblks); |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
363 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
364 /* Frame Byte Size V FSIZE 14 bits: 0-94=Invalid, 95-8191=Valid range-1 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
365 (ie. 96 bytes to 8192 bytes), 8192-16383=Invalid |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
366 FSIZE defines the byte size of the current audio frame. */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
367 fsize = (indata_ptr[6+le_mode] & 0x03) << 12 | indata_ptr[7-le_mode] << 4 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
368 | (indata_ptr[8+le_mode] & 0x3f) >> 2; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
369 ++fsize; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
370 fsize = fsize * 8 / 14 * 2; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
371 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
372 /* Audio Channel Arrangement ACC AMODE 6 bits */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
373 amode = (indata_ptr[8+le_mode] & 0x03) << 4 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
374 | (indata_ptr[9-le_mode] & 0xf0) >> 4; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
375 |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
376 /* Source Sampling rate ACC SFREQ 4 bits */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
377 *sfreq = indata_ptr[9-le_mode] & 0x0f; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
378 /* Transmission Bit Rate ACC RATE 5 bits */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
379 *rate = (indata_ptr[10+le_mode] & 0x3f) >> 1; |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
380 } |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
381 #if 0 |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
382 if(*sfreq != 13) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
383 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
384 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "DTS: Only 48kHz supported, REPORT BUG\n"); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
385 return -1; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
386 } |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
387 #endif |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
388 if((fsize > 8192) || (fsize < 96)) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
389 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
390 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "DTS: fsize: %d invalid, REPORT BUG\n", fsize); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
391 return -1; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
392 } |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
393 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
394 if(*nblks != 8 && |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
395 *nblks != 16 && |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
396 *nblks != 32 && |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
397 *nblks != 64 && |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
398 *nblks != 128 && |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
399 ftype == 1) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
400 { |
10948
aebf939834c3
10l found by Dominik 'Rathann' Mierzejewski <dominik@rangers.eu.org>
alex
parents:
10012
diff
changeset
|
401 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "DTS: nblks %d not valid for normal frame, REPORT BUG\n", *nblks); |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
402 return -1; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
403 } |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
404 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
405 return fsize; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
406 } |
5370 | 407 |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
408 static int dts_syncinfo(uint8_t *indata_ptr, int *flags, int *sample_rate, int *bit_rate) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
409 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
410 int nblks; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
411 int fsize; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
412 int rate; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
413 int sfreq; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
414 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
415 fsize = dts_decode_header(indata_ptr, &rate, &nblks, &sfreq); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
416 if(fsize >= 0) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
417 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
418 if(rate >= 0 && rate <= 29) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
419 *bit_rate = DTS_BITRATES[rate]; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
420 else |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
421 *bit_rate = 0; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
422 if(sfreq >= 1 && sfreq <= 15) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
423 *sample_rate = DTS_SAMPLEFREQS[sfreq]; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
424 else |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
425 *sample_rate = 0; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
426 } |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
427 return fsize; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
428 } |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
429 |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
430 static int convert_14bits_to_16bits(const unsigned char *src, |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
431 unsigned char *dest, |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
432 int len, |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
433 int is_le) |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
434 { |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
435 uint16_t *p = (uint16_t *)dest; |
25139
94e618df1dea
Simplify convert_14bits_to_16bits function in ad_hwac3
reimar
parents:
25124
diff
changeset
|
436 uint16_t buf = 0; |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
437 int spacebits = 16; |
25139
94e618df1dea
Simplify convert_14bits_to_16bits function in ad_hwac3
reimar
parents:
25124
diff
changeset
|
438 if (len <= 0) return 0; |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
439 while (len > 0) { |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
440 uint16_t v; |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
441 if (len == 1) |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
442 v = is_le ? src[0] : src[0] << 8; |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
443 else |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
444 v = is_le ? src[1] << 8 | src[0] : src[0] << 8 | src[1]; |
25139
94e618df1dea
Simplify convert_14bits_to_16bits function in ad_hwac3
reimar
parents:
25124
diff
changeset
|
445 v <<= 2; |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
446 src += 2; |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
447 len -= 2; |
25139
94e618df1dea
Simplify convert_14bits_to_16bits function in ad_hwac3
reimar
parents:
25124
diff
changeset
|
448 buf |= v >> (16 - spacebits); |
94e618df1dea
Simplify convert_14bits_to_16bits function in ad_hwac3
reimar
parents:
25124
diff
changeset
|
449 spacebits -= 14; |
94e618df1dea
Simplify convert_14bits_to_16bits function in ad_hwac3
reimar
parents:
25124
diff
changeset
|
450 if (spacebits < 0) { |
94e618df1dea
Simplify convert_14bits_to_16bits function in ad_hwac3
reimar
parents:
25124
diff
changeset
|
451 *p++ = buf; |
94e618df1dea
Simplify convert_14bits_to_16bits function in ad_hwac3
reimar
parents:
25124
diff
changeset
|
452 spacebits += 16; |
94e618df1dea
Simplify convert_14bits_to_16bits function in ad_hwac3
reimar
parents:
25124
diff
changeset
|
453 buf = v << (spacebits - 2); |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
454 } |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
455 } |
25139
94e618df1dea
Simplify convert_14bits_to_16bits function in ad_hwac3
reimar
parents:
25124
diff
changeset
|
456 *p++ = buf; |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
457 return (unsigned char *)p - dest; |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
458 } |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
459 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
460 static int decode_audio_dts(unsigned char *indata_ptr, int len, unsigned char *buf) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
461 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
462 int nblks; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
463 int fsize; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
464 int rate; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
465 int sfreq; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
466 int nr_samples; |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
467 int convert_16bits = 0; |
24432
79fcacd73f9b
Simplify and fix big-endian hwac3 header generation code.
reimar
parents:
23734
diff
changeset
|
468 uint16_t *buf16 = (uint16_t *)buf; |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
469 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
470 fsize = dts_decode_header(indata_ptr, &rate, &nblks, &sfreq); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
471 if(fsize < 0) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
472 return -1; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
473 nr_samples = nblks * 32; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
474 |
24432
79fcacd73f9b
Simplify and fix big-endian hwac3 header generation code.
reimar
parents:
23734
diff
changeset
|
475 buf16[0] = 0xf872; /* iec 61937 */ |
24434 | 476 buf16[1] = 0x4e1f; /* syncword */ |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
477 switch(nr_samples) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
478 { |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
479 case 512: |
24432
79fcacd73f9b
Simplify and fix big-endian hwac3 header generation code.
reimar
parents:
23734
diff
changeset
|
480 buf16[2] = 0x000b; /* DTS-1 (512-sample bursts) */ |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
481 break; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
482 case 1024: |
24432
79fcacd73f9b
Simplify and fix big-endian hwac3 header generation code.
reimar
parents:
23734
diff
changeset
|
483 buf16[2] = 0x000c; /* DTS-2 (1024-sample bursts) */ |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
484 break; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
485 case 2048: |
24432
79fcacd73f9b
Simplify and fix big-endian hwac3 header generation code.
reimar
parents:
23734
diff
changeset
|
486 buf16[2] = 0x000d; /* DTS-3 (2048-sample bursts) */ |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
487 break; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
488 default: |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
489 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "DTS: %d-sample bursts not supported\n", nr_samples); |
24432
79fcacd73f9b
Simplify and fix big-endian hwac3 header generation code.
reimar
parents:
23734
diff
changeset
|
490 buf16[2] = 0x0000; |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
491 break; |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
492 } |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
493 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
494 if(fsize + 8 > nr_samples * 2 * 2) |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
495 { |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
496 // dts wav (14bits LE) match this condition, one way to passthrough |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
497 // is not add iec 61937 header, decoders will notice the dts header |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
498 // and identify the dts stream. Another way here is convert |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
499 // the stream from 14 bits to 16 bits. |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
500 if ((indata_ptr[0] == 0xff || indata_ptr[0] == 0x1f) |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
501 && fsize * 14 / 16 + 8 <= nr_samples * 2 * 2) { |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
502 // The input stream is 14 bits, we can shrink it to 16 bits |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
503 // to save space for add the 61937 header |
25149 | 504 fsize = convert_14bits_to_16bits(indata_ptr, |
505 &buf[8], | |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
506 fsize, |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
507 indata_ptr[0] == 0xff /* is LE */ |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
508 ); |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
509 mp_msg(MSGT_DECAUDIO, MSGL_DBG3, "DTS: shrink 14 bits stream to " |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
510 "16 bits %02x%02x%02x%02x => %02x%02x%02x%02x, new size %d.\n", |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
511 indata_ptr[0], indata_ptr[1], indata_ptr[2], indata_ptr[3], |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
512 buf[8], buf[9], buf[10], buf[11], fsize); |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
513 convert_16bits = 1; |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
514 } |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
515 else |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
516 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "DTS: more data than fits\n"); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
517 } |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
518 |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
519 buf16[3] = fsize << 3; |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
520 |
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
521 if (!convert_16bits) { |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
522 #ifdef WORDS_BIGENDIAN |
25102
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
523 /* BE stream */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
524 if (indata_ptr[0] == 0x1f || indata_ptr[0] == 0x7f) |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
525 #else |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
526 /* LE stream */ |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
527 if (indata_ptr[0] == 0xff || indata_ptr[0] == 0xfe) |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
528 #endif |
24433
435b37266f1e
Improved comments, based on patches by Ulion [ulion2002 gmail com]
reimar
parents:
24432
diff
changeset
|
529 memcpy(&buf[8], indata_ptr, fsize); |
25102
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
530 else |
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
531 { |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
532 swab(indata_ptr, &buf[8], fsize); |
24508
4f9b7524f65d
Handle swab when input length is odd (treat it as if there was an additional
reimar
parents:
24436
diff
changeset
|
533 if (fsize & 1) { |
4f9b7524f65d
Handle swab when input length is odd (treat it as if there was an additional
reimar
parents:
24436
diff
changeset
|
534 buf[8+fsize-1] = 0; |
4f9b7524f65d
Handle swab when input length is odd (treat it as if there was an additional
reimar
parents:
24436
diff
changeset
|
535 buf[8+fsize] = indata_ptr[fsize-1]; |
4f9b7524f65d
Handle swab when input length is odd (treat it as if there was an additional
reimar
parents:
24436
diff
changeset
|
536 fsize++; |
4f9b7524f65d
Handle swab when input length is odd (treat it as if there was an additional
reimar
parents:
24436
diff
changeset
|
537 } |
25102
55d8b87b62da
Make hwdts support more dts format identification, 14bits or 16bits, LE or BE.
ulion
parents:
24509
diff
changeset
|
538 } |
25124
8809817b2266
Support convert 14-bit DTS stream into 16-bit stream if needed,
ulion
parents:
25102
diff
changeset
|
539 } |
10012
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
540 memset(&buf[fsize + 8], 0, nr_samples * 2 * 2 - (fsize + 8)); |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
541 |
f8f3f8b4e0d7
DTS support by Peter Schuller <peterschueller@telemed.de> (revised by arpi)
alex
parents:
8026
diff
changeset
|
542 return nr_samples * 2 * 2; |
5340
0f12fb7c1c5d
imported from MPlayerXP, dlopen() hack removed, some bugs fixed, interface functions changed to static, info->author field added
arpi
parents:
diff
changeset
|
543 } |
8026
b465ba5897a3
usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents:
7405
diff
changeset
|
544 #endif |