Mercurial > mplayer.hg
annotate ac3-iec958.c @ 4120:a66048f5ae2e
some comments and messages
author | alex |
---|---|
date | Sat, 12 Jan 2002 21:07:17 +0000 |
parents | 30b4f0c45b6e |
children | 3a46354aab56 |
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 { |
3829 | 88 const char sync[6] = { 0x72, 0xF8, 0x1F, 0x4E, 0x00, 0x00 }; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
89 |
3829 | 90 memcpy(out, sync, 6); |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
91 if (length) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
92 out[4] = data_type; /* & 0x1F; */ |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
93 else |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
94 out[4] = 0; |
3829 | 95 out[6] = (length << 3) & 0xFF; |
96 out[7] = (length >> 5) & 0xFF; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
97 if (big_endian) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
98 swab(data, out + 8, length); |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
99 else |
3829 | 100 memcpy(out + 8, data, length); |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
101 memset(out + 8 + length, 0, 6144 - 8 - length); |
3829 | 102 return 6144; |
1528
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 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
105 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
|
106 { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
107 int samplerates[4] = { 48000, 44100, 32000, -1 }; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
108 unsigned short sync = 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
109 unsigned char *ptr = buf; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
110 int fscod, frmsizecod; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
111 struct syncframe *sf; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
112 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
113 sync = buf[0] << 8; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
114 sync |= buf[1]; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
115 ptr = buf + 2; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
116 *skipped = 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
117 while (sync != 0xb77 && *skipped < size - 8) { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
118 sync <<= 8; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
119 sync |= *ptr; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
120 ptr++; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
121 *skipped += 1; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
122 } |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
123 if (sync != 0xb77) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
124 return -1; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
125 ptr -= 2; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
126 sf = (struct syncframe *) ptr; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
127 fscod = (sf->syncinfo.code >> 6) & 0x03; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
128 ai->samplerate = samplerates[fscod]; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
129 if (ai->samplerate == -1) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
130 return -1; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
131 frmsizecod = sf->syncinfo.code & 0x3f; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
132 ai->framesize = 2 * frmsizecod_tbl[frmsizecod].frm_size[fscod]; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
133 ai->bitrate = frmsizecod_tbl[frmsizecod].bit_rate; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
134 if (((sf->bsi.bsidmod >> 3) & 0x1f) != 0x08) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
135 return -1; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
136 ai->bsmod = sf->bsi.bsidmod & 0x7; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
137 |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
138 return 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
diff
changeset
|
139 } |