1 | /* |
2 | Copyright (c) 2012, Broadcom Europe Ltd |
3 | All rights reserved. |
4 | |
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the following conditions are met: |
7 | * Redistributions of source code must retain the above copyright |
8 | notice, this list of conditions and the following disclaimer. |
9 | * Redistributions in binary form must reproduce the above copyright |
10 | notice, this list of conditions and the following disclaimer in the |
11 | documentation and/or other materials provided with the distribution. |
12 | * Neither the name of the copyright holder nor the |
13 | names of its contributors may be used to endorse or promote products |
14 | derived from this software without specific prior written permission. |
15 | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | #include <stdlib.h> |
29 | #include <string.h> |
30 | |
31 | #include "containers/containers.h" |
32 | #include "containers/containers_codecs.h" |
33 | #include "containers/core/containers_utils.h" |
34 | |
35 | /*****************************************************************************/ |
36 | static struct { |
37 | VC_CONTAINER_FOURCC_T codec; |
38 | uint16_t id; |
39 | } codec_to_wf_table[] = |
40 | { |
41 | {VC_CONTAINER_CODEC_PCM_SIGNED_LE, WAVE_FORMAT_PCM}, |
42 | {VC_CONTAINER_CODEC_ALAW, WAVE_FORMAT_ALAW}, |
43 | {VC_CONTAINER_CODEC_MULAW, WAVE_FORMAT_MULAW}, |
44 | {VC_CONTAINER_CODEC_ADPCM_MS, WAVE_FORMAT_ADPCM}, |
45 | {VC_CONTAINER_CODEC_MPGA, WAVE_FORMAT_MPEG}, |
46 | {VC_CONTAINER_CODEC_MPGA, WAVE_FORMAT_MPEGLAYER3}, |
47 | {VC_CONTAINER_CODEC_WMA1, WAVE_FORMAT_WMAUDIO1}, |
48 | {VC_CONTAINER_CODEC_WMA2, WAVE_FORMAT_WMAUDIO2}, |
49 | {VC_CONTAINER_CODEC_WMAP, WAVE_FORMAT_WMAUDIOPRO}, |
50 | {VC_CONTAINER_CODEC_WMAL, WAVE_FORMAT_WMAUDIO_LOSSLESS}, |
51 | {VC_CONTAINER_CODEC_WMAV, WAVE_FORMAT_WMAUDIO_VOICE}, |
52 | {VC_CONTAINER_CODEC_AC3, WAVE_FORMAT_DVM}, |
53 | {VC_CONTAINER_CODEC_AC3, WAVE_FORMAT_DOLBY_AC3_SPDIF}, /**< AC-3 padded for S/PDIF */ |
54 | {VC_CONTAINER_CODEC_AC3, WAVE_FORMAT_RAW_SPORT}, /**< AC-3 padded for S/PDIF */ |
55 | {VC_CONTAINER_CODEC_AC3, WAVE_FORMAT_ESST_AC3}, /**< AC-3 padded for S/PDIF */ |
56 | {VC_CONTAINER_CODEC_EAC3, WAVE_FORMAT_DVM}, |
57 | {VC_CONTAINER_CODEC_DTS, WAVE_FORMAT_DTS}, |
58 | #if 0 |
59 | {CODEC_G726, WAVE_FORMAT_G726_ADPCM}, |
60 | {CODEC_G726, WAVE_FORMAT_DF_G726}, |
61 | {CODEC_G726, WAVE_FORMAT_G726ADPCM}, |
62 | {CODEC_G726, WAVE_FORMAT_PANASONIC_G726}, |
63 | #endif |
64 | {VC_CONTAINER_CODEC_MP4A, WAVE_FORMAT_AAC}, |
65 | {VC_CONTAINER_CODEC_MP4A, WAVE_FORMAT_MP4A}, |
66 | {VC_CONTAINER_CODEC_ATRAC3, WAVE_FORMAT_SONY_SCX}, |
67 | {VC_CONTAINER_CODEC_UNKNOWN, WAVE_FORMAT_UNKNOWN} |
68 | }; |
69 | |
70 | VC_CONTAINER_FOURCC_T waveformat_to_codec(uint16_t waveformat_id) |
71 | { |
72 | unsigned int i; |
73 | for(i = 0; codec_to_wf_table[i].codec != VC_CONTAINER_CODEC_UNKNOWN; i++) |
74 | if(codec_to_wf_table[i].id == waveformat_id) break; |
75 | return codec_to_wf_table[i].codec; |
76 | } |
77 | |
78 | uint16_t codec_to_waveformat(VC_CONTAINER_FOURCC_T codec) |
79 | { |
80 | unsigned int i; |
81 | for(i = 0; codec_to_wf_table[i].codec != VC_CONTAINER_CODEC_UNKNOWN; i++) |
82 | if(codec_to_wf_table[i].codec == codec) break; |
83 | return codec_to_wf_table[i].id; |
84 | } |
85 | |
86 | static struct { |
87 | VC_CONTAINER_FOURCC_T codec; |
88 | uint32_t fourcc; |
89 | } codec_to_vfw_table[] = |
90 | { |
91 | #if defined(ENABLE_CONTAINERS_STANDALONE) || !defined(NDEBUG) |
92 | /* We are legally required to not play DivX in RELEASE mode. See Jira SW-3138 */ |
93 | {VC_CONTAINER_CODEC_DIV3, VC_FOURCC('D','I','V','3')}, |
94 | {VC_CONTAINER_CODEC_DIV3, VC_FOURCC('d','i','v','3')}, |
95 | {VC_CONTAINER_CODEC_DIV4, VC_FOURCC('D','I','V','4')}, |
96 | {VC_CONTAINER_CODEC_DIV4, VC_FOURCC('d','i','v','4')}, |
97 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('D','X','5','0')}, |
98 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('D','I','V','X')}, |
99 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('d','i','v','x')}, |
100 | #endif /* ENABLE_CONTAINERS_STANDALONE || !NDEBUG */ |
101 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('M','P','4','V')}, |
102 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('m','p','4','v')}, |
103 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('M','P','4','S')}, |
104 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('m','p','4','s')}, |
105 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('M','4','S','2')}, |
106 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('m','4','s','2')}, |
107 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('F','M','P','4')}, |
108 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('X','V','I','D')}, |
109 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('x','v','i','d')}, |
110 | {VC_CONTAINER_CODEC_DIV3, VC_FOURCC('M','P','4','3')}, |
111 | {VC_CONTAINER_CODEC_DIV3, VC_FOURCC('m','p','4','3')}, |
112 | {VC_CONTAINER_CODEC_MP1V, VC_FOURCC('m','p','g','1')}, |
113 | {VC_CONTAINER_CODEC_MP1V, VC_FOURCC('M','P','G','1')}, |
114 | {VC_CONTAINER_CODEC_MP2V, VC_FOURCC('m','p','g','2')}, |
115 | {VC_CONTAINER_CODEC_MP2V, VC_FOURCC('M','P','G','2')}, |
116 | {VC_CONTAINER_CODEC_MJPEG, VC_FOURCC('M','J','P','G')}, |
117 | {VC_CONTAINER_CODEC_MJPEG, VC_FOURCC('m','j','p','g')}, |
118 | {VC_CONTAINER_CODEC_WMV1, VC_FOURCC('W','M','V','1')}, |
119 | {VC_CONTAINER_CODEC_WMV1, VC_FOURCC('w','m','v','1')}, |
120 | {VC_CONTAINER_CODEC_WMV2, VC_FOURCC('W','M','V','2')}, |
121 | {VC_CONTAINER_CODEC_WMV2, VC_FOURCC('w','m','v','2')}, |
122 | {VC_CONTAINER_CODEC_WMV3, VC_FOURCC('W','M','V','3')}, |
123 | {VC_CONTAINER_CODEC_WMV3, VC_FOURCC('w','m','v','3')}, |
124 | {VC_CONTAINER_CODEC_WVC1, VC_FOURCC('W','V','C','1')}, |
125 | {VC_CONTAINER_CODEC_WVC1, VC_FOURCC('w','v','c','1')}, |
126 | {VC_CONTAINER_CODEC_WMVA, VC_FOURCC('w','m','v','a')}, |
127 | {VC_CONTAINER_CODEC_WMVA, VC_FOURCC('W','M','V','A')}, |
128 | {VC_CONTAINER_CODEC_VP6, VC_FOURCC('V','P','6','F')}, |
129 | {VC_CONTAINER_CODEC_VP6, VC_FOURCC('v','p','6','f')}, |
130 | {VC_CONTAINER_CODEC_VP7, VC_FOURCC('V','P','7','0')}, |
131 | {VC_CONTAINER_CODEC_VP7, VC_FOURCC('v','p','7','0')}, |
132 | {VC_CONTAINER_CODEC_H263, VC_FOURCC('H','2','6','3')}, |
133 | {VC_CONTAINER_CODEC_H263, VC_FOURCC('h','2','6','3')}, |
134 | {VC_CONTAINER_CODEC_H264, VC_FOURCC('H','2','6','4')}, |
135 | {VC_CONTAINER_CODEC_H264, VC_FOURCC('h','2','6','4')}, |
136 | {VC_CONTAINER_CODEC_H264, VC_FOURCC('A','V','C','1')}, |
137 | {VC_CONTAINER_CODEC_H264, VC_FOURCC('a','v','c','1')}, |
138 | {VC_CONTAINER_CODEC_SPARK, VC_FOURCC('F','L','V','1')}, |
139 | {VC_CONTAINER_CODEC_SPARK, VC_FOURCC('f','l','v','1')}, |
140 | {VC_CONTAINER_CODEC_UNKNOWN, 0} |
141 | }; |
142 | |
143 | VC_CONTAINER_FOURCC_T vfw_fourcc_to_codec(uint32_t fourcc) |
144 | { |
145 | unsigned int i; |
146 | for(i = 0; codec_to_vfw_table[i].codec != VC_CONTAINER_CODEC_UNKNOWN; i++) |
147 | if(codec_to_vfw_table[i].fourcc == fourcc) break; |
148 | |
149 | if(codec_to_vfw_table[i].codec == VC_CONTAINER_CODEC_UNKNOWN) |
150 | return fourcc; |
151 | |
152 | return codec_to_vfw_table[i].codec; |
153 | } |
154 | |
155 | uint32_t codec_to_vfw_fourcc(VC_CONTAINER_FOURCC_T codec) |
156 | { |
157 | unsigned int i; |
158 | for(i = 0; codec_to_vfw_table[i].codec != VC_CONTAINER_CODEC_UNKNOWN; i++) |
159 | if(codec_to_vfw_table[i].codec == codec) break; |
160 | |
161 | return codec_to_vfw_table[i].fourcc; |
162 | } |
163 | |
164 | static struct { |
165 | VC_CONTAINER_FOURCC_T codec; |
166 | uint32_t fourcc; |
167 | } codec_to_fourcc_table[] = |
168 | { |
169 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('M','P','4','S')}, |
170 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('M','4','S','2')}, |
171 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('m','p','4','s')}, |
172 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('m','4','s','2')}, |
173 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('M','P','4','V')}, |
174 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('m','p','4','v')}, |
175 | {VC_CONTAINER_CODEC_MP4V, VC_FOURCC('F','M','P','4')}, |
176 | {VC_CONTAINER_CODEC_DIV3, VC_FOURCC('M','P','4','3')}, |
177 | {VC_CONTAINER_CODEC_DIV3, VC_FOURCC('m','p','4','3')}, |
178 | {VC_CONTAINER_CODEC_WMV1, VC_FOURCC('W','M','V','1')}, |
179 | {VC_CONTAINER_CODEC_WMV1, VC_FOURCC('w','m','v','1')}, |
180 | {VC_CONTAINER_CODEC_WMV2, VC_FOURCC('W','M','V','2')}, |
181 | {VC_CONTAINER_CODEC_WMV2, VC_FOURCC('w','m','v','2')}, |
182 | {VC_CONTAINER_CODEC_WMV3, VC_FOURCC('W','M','V','3')}, |
183 | {VC_CONTAINER_CODEC_WMV3, VC_FOURCC('w','m','v','3')}, |
184 | {VC_CONTAINER_CODEC_MP1V, VC_FOURCC('m','p','g','1')}, |
185 | {VC_CONTAINER_CODEC_MP1V, VC_FOURCC('M','P','G','1')}, |
186 | {VC_CONTAINER_CODEC_MP2V, VC_FOURCC('m','p','g','2')}, |
187 | {VC_CONTAINER_CODEC_MP2V, VC_FOURCC('M','P','G','2')}, |
188 | {VC_CONTAINER_CODEC_MJPEG, VC_FOURCC('M','J','P','G')}, |
189 | {VC_CONTAINER_CODEC_MJPEG, VC_FOURCC('m','j','p','g')}, |
190 | {VC_CONTAINER_CODEC_UNKNOWN, 0} |
191 | }; |
192 | |
193 | VC_CONTAINER_FOURCC_T fourcc_to_codec(uint32_t fourcc) |
194 | { |
195 | unsigned int i; |
196 | for(i = 0; codec_to_fourcc_table[i].codec != VC_CONTAINER_CODEC_UNKNOWN; i++) |
197 | if(codec_to_fourcc_table[i].fourcc == fourcc) break; |
198 | |
199 | return codec_to_fourcc_table[i].codec; |
200 | } |
201 | |
202 | uint32_t codec_to_fourcc(VC_CONTAINER_FOURCC_T codec) |
203 | { |
204 | unsigned int i; |
205 | for(i = 0; codec_to_fourcc_table[i].codec != VC_CONTAINER_CODEC_UNKNOWN; i++) |
206 | if(codec_to_fourcc_table[i].codec == codec) break; |
207 | |
208 | return codec_to_fourcc_table[i].fourcc; |
209 | } |
210 | |