Mercurial > mplayer.hg
annotate ac3-iec958.c @ 4883:1602b4fed5a1
callbacks added
author | arpi |
---|---|
date | Thu, 28 Feb 2002 01:41:49 +0000 |
parents | 3a46354aab56 |
children |
rev | line source |
---|---|
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
1 /* ---------------------------------------------------------------------- |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
2 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
3 Copyright (C) 2001 Juha Yrjölä (jyrjola@cc.hut.fi) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
4 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
5 This program is free software; you can redistribute it and/or modify |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
7 the Free Software Foundation; either version 2 of the License, or |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
8 (at your option) any later version. |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
9 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
13 GNU General Public License for more details. |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
14 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
16 along with this program; if not, write to the Free Software |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
18 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
19 ---------------------------------------------------------------------- */ |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
20 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
21 #include <stdlib.h> |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
22 #include <unistd.h> |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
23 #include <string.h> |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
24 #include "ac3-iec958.h" |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
25 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
26 struct frmsize_s |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
27 { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
28 unsigned short bit_rate; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
29 unsigned short frm_size[3]; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
30 }; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
31 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
32 static const struct frmsize_s frmsizecod_tbl[64] = |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
33 { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
34 { 32 ,{64 ,69 ,96 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
35 { 32 ,{64 ,70 ,96 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
36 { 40 ,{80 ,87 ,120 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
37 { 40 ,{80 ,88 ,120 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
38 { 48 ,{96 ,104 ,144 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
39 { 48 ,{96 ,105 ,144 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
40 { 56 ,{112 ,121 ,168 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
41 { 56 ,{112 ,122 ,168 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
42 { 64 ,{128 ,139 ,192 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
43 { 64 ,{128 ,140 ,192 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
44 { 80 ,{160 ,174 ,240 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
45 { 80 ,{160 ,175 ,240 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
46 { 96 ,{192 ,208 ,288 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
47 { 96 ,{192 ,209 ,288 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
48 { 112 ,{224 ,243 ,336 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
49 { 112 ,{224 ,244 ,336 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
50 { 128 ,{256 ,278 ,384 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
51 { 128 ,{256 ,279 ,384 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
52 { 160 ,{320 ,348 ,480 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
53 { 160 ,{320 ,349 ,480 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
54 { 192 ,{384 ,417 ,576 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
55 { 192 ,{384 ,418 ,576 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
56 { 224 ,{448 ,487 ,672 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
57 { 224 ,{448 ,488 ,672 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
58 { 256 ,{512 ,557 ,768 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
59 { 256 ,{512 ,558 ,768 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
60 { 320 ,{640 ,696 ,960 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
61 { 320 ,{640 ,697 ,960 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
62 { 384 ,{768 ,835 ,1152 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
63 { 384 ,{768 ,836 ,1152 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
64 { 448 ,{896 ,975 ,1344 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
65 { 448 ,{896 ,976 ,1344 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
66 { 512 ,{1024 ,1114 ,1536 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
67 { 512 ,{1024 ,1115 ,1536 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
68 { 576 ,{1152 ,1253 ,1728 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
69 { 576 ,{1152 ,1254 ,1728 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
70 { 640 ,{1280 ,1393 ,1920 } }, |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
71 { 640 ,{1280 ,1394 ,1920 } } |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
72 }; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
73 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
74 struct syncframe { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
75 struct syncinfo { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
76 unsigned char syncword[2]; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
77 unsigned char crc1[2]; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
78 unsigned char code; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
79 } syncinfo; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
80 struct bsi { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
81 unsigned char bsidmod; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
82 unsigned char acmod; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
83 } bsi; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
84 }; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
85 |
3829 | 86 int ac3_iec958_build_burst(int length, int data_type, int big_endian, unsigned char * data, unsigned char * out) |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
87 { |
4422 | 88 out[0] = 0x72; |
89 out[1] = 0xF8; | |
90 out[2] = 0x1F; | |
91 out[3] = 0x4E; | |
92 out[4] = (length) ? data_type : 0; /* & 0x1F; */ | |
93 out[5] = 0x00; | |
3829 | 94 out[6] = (length << 3) & 0xFF; |
95 out[7] = (length >> 5) & 0xFF; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
96 if (big_endian) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
97 swab(data, out + 8, length); |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
98 else |
3829 | 99 memcpy(out + 8, data, length); |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
100 memset(out + 8 + length, 0, 6144 - 8 - length); |
3829 | 101 return 6144; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
102 } |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
103 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
104 int ac3_iec958_parse_syncinfo(unsigned char *buf, int size, struct hwac3info *ai, int *skipped) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
105 { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
106 int samplerates[4] = { 48000, 44100, 32000, -1 }; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
107 unsigned short sync = 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
108 unsigned char *ptr = buf; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
109 int fscod, frmsizecod; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
110 struct syncframe *sf; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
111 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
112 sync = buf[0] << 8; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
113 sync |= buf[1]; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
114 ptr = buf + 2; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
115 *skipped = 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
116 while (sync != 0xb77 && *skipped < size - 8) { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
117 sync <<= 8; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
118 sync |= *ptr; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
119 ptr++; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
120 *skipped += 1; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
121 } |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
122 if (sync != 0xb77) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
123 return -1; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
124 ptr -= 2; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
125 sf = (struct syncframe *) ptr; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
126 fscod = (sf->syncinfo.code >> 6) & 0x03; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
127 ai->samplerate = samplerates[fscod]; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
128 if (ai->samplerate == -1) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
129 return -1; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
130 frmsizecod = sf->syncinfo.code & 0x3f; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
131 ai->framesize = 2 * frmsizecod_tbl[frmsizecod].frm_size[fscod]; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
132 ai->bitrate = frmsizecod_tbl[frmsizecod].bit_rate; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
133 if (((sf->bsi.bsidmod >> 3) & 0x1f) != 0x08) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
134 return -1; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
135 ai->bsmod = sf->bsi.bsidmod & 0x7; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
136 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
137 return 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
138 } |