summaryrefslogtreecommitdiffstats
path: root/recipes-multimedia/tinycompress/tinycompress/0005-cplay-Support-aac-streams.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-multimedia/tinycompress/tinycompress/0005-cplay-Support-aac-streams.patch')
-rwxr-xr-xrecipes-multimedia/tinycompress/tinycompress/0005-cplay-Support-aac-streams.patch251
1 files changed, 251 insertions, 0 deletions
diff --git a/recipes-multimedia/tinycompress/tinycompress/0005-cplay-Support-aac-streams.patch b/recipes-multimedia/tinycompress/tinycompress/0005-cplay-Support-aac-streams.patch
new file mode 100755
index 00000000..2f36551a
--- /dev/null
+++ b/recipes-multimedia/tinycompress/tinycompress/0005-cplay-Support-aac-streams.patch
@@ -0,0 +1,251 @@
1From 2912f8573cea25fbd38ac7a8b68af2ea6a05e599 Mon Sep 17 00:00:00 2001
2From: Zhang Peng <peng.zhang_8@nxp.com>
3Date: Wed, 28 Oct 2020 19:08:53 +0800
4Subject: [PATCH] cplay: Support aac streams
5
6Support run aac format streams for cplay.
7
8Upstream-Status: Inappropriate [i.MX specific]
9Signed-off-by: Zhang Peng <peng.zhang_8@nxp.com>
10---
11 src/utils/cplay.c | 210 ++++++++++++++++++++++++++++++++++++++++++++++
12 1 file changed, 210 insertions(+)
13
14diff --git a/src/utils/cplay.c b/src/utils/cplay.c
15index 8e3dcbb..2a1464a 100644
16--- a/src/utils/cplay.c
17+++ b/src/utils/cplay.c
18@@ -245,6 +245,190 @@ static int parse_wav_header(FILE *file, unsigned int *num_channels, unsigned int
19 return 0;
20 }
21
22+int find_adts_header(FILE *file, unsigned int *num_channels, unsigned int *sample_rate, unsigned int *format)
23+{
24+ int ret;
25+ unsigned char buf[5];
26+
27+ ret = fread(buf, sizeof(buf), 1, file);
28+ if (ret < 0) {
29+ fprintf(stderr, "open file error: %d\n", ret);
30+ return 0;
31+ }
32+ fseek(file, 0, SEEK_SET);
33+
34+ if ((buf[0] != 0xff) || (buf[1] & 0xf0 != 0xf0))
35+ return 0;
36+ /* mpeg id */
37+ switch (buf[1]>>3 & 0x1) {
38+ case 0x0:
39+ *format = SND_AUDIOSTREAMFORMAT_MP4ADTS;
40+ break;
41+ case 0x1:
42+ *format = SND_AUDIOSTREAMFORMAT_MP2ADTS;
43+ break;
44+ default:
45+ fprintf(stderr, "can't find stream format\n");
46+ break;
47+ }
48+ /* sample_rate */
49+ switch (buf[2]>>2 & 0xf) {
50+ case 0x0:
51+ *sample_rate = 96000;
52+ break;
53+ case 0x1:
54+ *sample_rate = 88200;
55+ break;
56+ case 0x2:
57+ *sample_rate = 64000;
58+ break;
59+ case 0x3:
60+ *sample_rate = 48000;
61+ break;
62+ case 0x4:
63+ *sample_rate = 44100;
64+ break;
65+ case 0x5:
66+ *sample_rate = 32000;
67+ break;
68+ case 0x6:
69+ *sample_rate = 24000;
70+ break;
71+ case 0x7:
72+ *sample_rate = 22050;
73+ break;
74+ case 0x8:
75+ *sample_rate = 16000;
76+ break;
77+ case 0x9:
78+ *sample_rate = 12000;
79+ break;
80+ case 0xa:
81+ *sample_rate = 11025;
82+ break;
83+ case 0xb:
84+ *sample_rate = 8000;
85+ break;
86+ case 0xc:
87+ *sample_rate = 7350;
88+ break;
89+ default:
90+ break;
91+ }
92+ /* channel */
93+ switch (((buf[2]&0x1) << 2) | (buf[3]>>6)) {
94+ case 1:
95+ *num_channels = 1;
96+ break;
97+ case 2:
98+ *num_channels = 2;
99+ break;
100+ case 3:
101+ *num_channels = 3;
102+ break;
103+ case 4:
104+ *num_channels = 4;
105+ break;
106+ case 5:
107+ *num_channels = 5;
108+ break;
109+ case 6:
110+ *num_channels = 6;
111+ break;
112+ case 7:
113+ *num_channels = 7;
114+ break;
115+ default:
116+ break;
117+ }
118+ return 1;
119+}
120+
121+static const int aac_sample_rates[] = { 96000, 88200, 64000, 48000, 44100,
122+ 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350
123+};
124+
125+#define MAX_SR_NUM sizeof(aac_sample_rates)/sizeof(aac_sample_rates[0])
126+
127+static int get_sample_rate_from_index(int sr_index)
128+{
129+ if (sr_index >= 0 && sr_index < MAX_SR_NUM)
130+ return aac_sample_rates[sr_index];
131+
132+ return 0;
133+}
134+
135+int find_adif_header(FILE *file, unsigned int *num_channels, unsigned int *sample_rate, unsigned int *format)
136+{
137+ int ret;
138+ unsigned char adif_id[4];
139+ unsigned char adif_header[20];
140+ int bitstream_type;
141+ int bitrate;
142+ int object_type;
143+ int sr_index;
144+ int skip_size = 0;
145+
146+ ret = fread(adif_id, sizeof(unsigned char), 4, file);
147+ if (ret < 0) {
148+ fprintf(stderr, "read data from file err: %d\n", ret);
149+ return 0;
150+ }
151+ /* adif id */
152+ if ((adif_id[0] != 0x41) || (adif_id[1] != 0x44) ||
153+ (adif_id[2] != 0x49) || (adif_id[3] != 0x46))
154+ return 0;
155+
156+ fread(adif_header, sizeof(unsigned char), 20, file);
157+
158+ /* copyright string */
159+ if (adif_header[0] & 0x80)
160+ skip_size = 9;
161+
162+ bitstream_type = adif_header[0 + skip_size] & 0x10;
163+ bitrate =
164+ ((unsigned int) (adif_header[0 + skip_size] & 0x0f) << 19) |
165+ ((unsigned int) adif_header[1 + skip_size] << 11) |
166+ ((unsigned int) adif_header[2 + skip_size] << 3) |
167+ ((unsigned int) adif_header[3 + skip_size] & 0xe0);
168+
169+ if (bitstream_type == 0) {
170+ object_type = ((adif_header[6 + skip_size] & 0x01) << 1) |
171+ ((adif_header[7 + skip_size] & 0x80) >> 7);
172+ sr_index = (adif_header[7 + skip_size] & 0x78) >> 3;
173+ }
174+ /* VBR */
175+ else {
176+ object_type = (adif_header[4 + skip_size] & 0x18) >> 3;
177+ sr_index = ((adif_header[4 + skip_size] & 0x07) << 1) |
178+ ((adif_header[5 + skip_size] & 0x80) >> 7);
179+ }
180+
181+ /* sample rate */
182+ *sample_rate = get_sample_rate_from_index(sr_index);
183+
184+ /* FIXME: assume channels is 2 */
185+ *num_channels = 2;
186+
187+ *format = SND_AUDIOSTREAMFORMAT_ADIF;
188+ fseek(file, 0, SEEK_SET);
189+ return 1;
190+}
191+
192+static int parse_aac_header(FILE *file, unsigned int *num_channels, unsigned int *sample_rate, unsigned int *format)
193+{
194+ if (find_adts_header(file, num_channels, sample_rate, format))
195+ return 1;
196+ else if (find_adif_header(file, num_channels, sample_rate, format))
197+ return 1;
198+ else {
199+ fprintf(stderr, "can't find streams format\n");
200+ return 0;
201+ }
202+
203+ return 1;
204+}
205+
206 static int print_time(struct compress *compress)
207 {
208 unsigned int avail;
209@@ -513,6 +697,29 @@ void get_codec_pcm(FILE *file, struct compr_config *config,
210 codec->format = format;
211 }
212
213+void get_codec_aac(FILE *file, struct compr_config *config,
214+ struct snd_codec *codec)
215+{
216+ unsigned int channels, rate, format;
217+
218+ if (parse_aac_header(file, &channels, &rate, &format) == 0) {
219+ fclose(file);
220+ exit(EXIT_FAILURE);
221+ };
222+ fseek(file, 0, SEEK_SET);
223+
224+ codec->id = SND_AUDIOCODEC_AAC;
225+ codec->ch_in = channels;
226+ codec->ch_out = channels;
227+ codec->sample_rate = rate;
228+ codec->bit_rate = 0;
229+ codec->rate_control = 0;
230+ codec->profile = SND_AUDIOPROFILE_AAC;
231+ codec->level = 0;
232+ codec->ch_mode = 0;
233+ codec->format = format;
234+
235+}
236 void play_samples(char *name, unsigned int card, unsigned int device,
237 unsigned long buffer_size, unsigned int frag,
238 unsigned long codec_id, int pause_count, int pause_block,
239@@ -544,6 +751,9 @@ void play_samples(char *name, unsigned int card, unsigned int device,
240 case SND_AUDIOCODEC_PCM:
241 get_codec_pcm(file, &config, &codec);
242 break;
243+ case SND_AUDIOCODEC_AAC:
244+ get_codec_aac(file, &config, &codec);
245+ break;
246 default:
247 fprintf(stderr, "codec ID %ld is not supported\n", codec_id);
248 exit(EXIT_FAILURE);
249--
2502.17.1
251