summaryrefslogtreecommitdiffstats
path: root/recipes-multimedia/tinycompress/tinycompress/0001-tinycompress-Add-id3-decoding.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-multimedia/tinycompress/tinycompress/0001-tinycompress-Add-id3-decoding.patch')
-rwxr-xr-xrecipes-multimedia/tinycompress/tinycompress/0001-tinycompress-Add-id3-decoding.patch1001
1 files changed, 1001 insertions, 0 deletions
diff --git a/recipes-multimedia/tinycompress/tinycompress/0001-tinycompress-Add-id3-decoding.patch b/recipes-multimedia/tinycompress/tinycompress/0001-tinycompress-Add-id3-decoding.patch
new file mode 100755
index 00000000..f578148a
--- /dev/null
+++ b/recipes-multimedia/tinycompress/tinycompress/0001-tinycompress-Add-id3-decoding.patch
@@ -0,0 +1,1001 @@
1From 16f6b7a5baec41f18fde75fd311fb988e3c31810 Mon Sep 17 00:00:00 2001
2From: Shengjiu Wang <shengjiu.wang@nxp.com>
3Date: Fri, 13 Jul 2018 18:13:24 +0800
4Subject: [PATCH] tinycompress: Add id3 decoding
5
6Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
7---
8 include/tinycompress/id3_tag_decode.h | 198 +++++++++++
9 src/utils/Makefile.am | 2 +-
10 src/utils/cplay.c | 88 +++++
11 src/utils/id3_tag_decode.c | 642 ++++++++++++++++++++++++++++++++++
12 4 files changed, 929 insertions(+), 1 deletion(-)
13 create mode 100644 include/tinycompress/id3_tag_decode.h
14 create mode 100644 src/utils/id3_tag_decode.c
15
16diff --git a/include/tinycompress/id3_tag_decode.h b/include/tinycompress/id3_tag_decode.h
17new file mode 100644
18index 0000000..1a911d7
19--- /dev/null
20+++ b/include/tinycompress/id3_tag_decode.h
21@@ -0,0 +1,198 @@
22+/*
23+ * Copyright (c) 2006-2017 Cadence Design Systems, Inc.
24+ * Copyright 2018 NXP
25+ *
26+ * Permission is hereby granted, free of charge, to any person obtaining
27+ * a copy of this software and associated documentation files (the
28+ * "Software"), to deal in the Software without restriction, including
29+ * without limitation the rights to use, copy, modify, merge, publish,
30+ * distribute, sublicense, and/or sell copies of the Software, and to
31+ * permit persons to whom the Software is furnished to do so, subject to
32+ * the following conditions:
33+ *
34+ * The above copyright notice and this permission notice shall be included
35+ * in all copies or substantial portions of the Software.
36+ *
37+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
40+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
41+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
42+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
43+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44+ */
45+
46+/******************************************************************
47+ * file name : id3_tag_decode.h
48+ *
49+ * description : stores typedefs of structures specific to MP3 tag
50+ *
51+ * revision history:
52+ * 29 04 2004 DK creation
53+ *****************************************************************/
54+
55+#ifndef ID3_TAG_DECODE_H
56+#define ID3_TAG_DECODE_H
57+
58+typedef signed char WORD8;
59+typedef signed char * pWORD8;
60+typedef unsigned char UWORD8;
61+typedef unsigned char * pUWORD8;
62+
63+typedef signed short WORD16;
64+typedef signed short * pWORD16;
65+typedef unsigned short UWORD16;
66+typedef unsigned short * pUWORD16;
67+
68+typedef signed int WORD24;
69+typedef signed int * pWORD24;
70+typedef unsigned int UWORD24;
71+typedef unsigned int * pUWORD24;
72+
73+typedef signed int WORD32;
74+typedef signed int * pWORD32;
75+typedef unsigned int UWORD32;
76+typedef unsigned int * pUWORD32;
77+
78+typedef void VOID;
79+typedef void * pVOID;
80+
81+typedef signed int BOOL;
82+typedef unsigned int UBOOL;
83+typedef signed int FLAG;
84+typedef unsigned int UFLAG;
85+typedef signed int LOOPIDX;
86+typedef unsigned int ULOOPIDX;
87+typedef signed int WORD;
88+typedef unsigned int UWORD;
89+
90+#define MAX_TAG_FRAME_SIZE 100
91+
92+#define ID3V1 (0x544147) /* 0x544147 is TAG in WORD8 */
93+
94+#define ID3V2 (0x494433) /* 0x494433 is ID3 in WORD8 */
95+
96+/*
97+ * structure corresponding to ID3 tag v1 header.
98+ * this structure has all the field corresponding to ID3 tag v1 header.
99+ */
100+
101+typedef struct {
102+ WORD32 tag; // 3 bytes
103+
104+ WORD16 version; // 2 bytes
105+
106+ WORD8 flag; //1 byte
107+
108+ WORD32 size; //4 bytes
109+
110+} id3_v2_header_struct;
111+
112+/* structure which will store the frame data and
113+ * also put a limit max data to be stored
114+ */
115+typedef struct {
116+ WORD8 frame_data[MAX_TAG_FRAME_SIZE];
117+
118+ WORD32 max_size; //4 bytes
119+
120+ WORD16 tag_present;
121+
122+ WORD16 exceeds_buffer_size;
123+
124+} id3_v2_frame_struct;
125+
126+/*
127+ * structure corresponding to ID3 tag v2.
128+ * this structure has some of the field corresponding to ID3 tag v2.
129+ * if user wants to read some more tag information from
130+ * the MP3 file, he can add that field in this structure and pass address
131+ * of that element to get_inf function in id3_tag_decode.c under the
132+ * corresponding field frame header. few fields which are needed are already
133+ * populated by reading from the TAG header.
134+ */
135+typedef struct {
136+ id3_v2_frame_struct album_movie_show_title;
137+
138+ id3_v2_frame_struct composer_name;
139+
140+ id3_v2_frame_struct content_type;
141+
142+ id3_v2_frame_struct encoded_by;
143+
144+ id3_v2_frame_struct lyricist_text_writer;
145+
146+ id3_v2_frame_struct content_group_description;
147+
148+ id3_v2_frame_struct title_songname_content_description;
149+
150+ id3_v2_frame_struct medxa_type;
151+
152+ id3_v2_frame_struct original_album_movie_show_title;
153+
154+ id3_v2_frame_struct original_filename;
155+
156+ id3_v2_frame_struct original_lyricist_text_writer;
157+
158+ id3_v2_frame_struct original_artist_performer;
159+
160+ id3_v2_frame_struct file_owner_licensee;
161+
162+ id3_v2_frame_struct lead_performer_soloist;
163+
164+ id3_v2_frame_struct publisher;
165+
166+ id3_v2_frame_struct private_frame;
167+
168+ id3_v2_frame_struct other_info;
169+
170+ id3_v2_header_struct id3_v2_header;
171+
172+ WORD32 header_end;
173+
174+ WORD32 bytes_consumed;
175+
176+} id3v2_struct;
177+
178+/*
179+ * structure corresponding to ID3 tag v1.
180+ * this structure has all the field corresponding to ID3 tag v1.
181+ */
182+typedef struct {
183+ WORD8 song_title[30]; //30 word8acters
184+
185+ WORD8 artist[30]; //30 word8acters
186+
187+ WORD8 album[30]; //30 word8acters
188+
189+ WORD8 year[4]; //4 word8acters
190+
191+ WORD8 comment[30]; //30 word8acters
192+
193+ WORD8 genre[1]; //1 byte
194+
195+} id3v1_struct;
196+
197+WORD32 get_info(const char *inp_buffer,
198+ unsigned int avail_inp,
199+ WORD32 tag_size,
200+ id3_v2_frame_struct *dest);
201+
202+WORD32 search_id3_v2(UWORD8 *buffer);
203+
204+WORD32 decode_id3_v2(const char *const buffer,
205+ id3v2_struct *id3v2,
206+ WORD32 continue_flag,
207+ WORD32 insize);
208+
209+WORD32 get_id3_v2_bytes(UWORD8 *buffer);
210+
211+WORD32 get_v1_info(UWORD8 *buffer, id3v1_struct *id3v1);
212+
213+WORD32 search_id3_v1(UWORD8 *buffer);
214+
215+WORD32 decode_id3_v1(UWORD8 *buffer, id3v1_struct *id3v1);
216+
217+void init_id3v2_field(id3v2_struct *id3v2);
218+
219+#endif
220diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am
221index 1b996d4..e813689 100644
222--- a/src/utils/Makefile.am
223+++ b/src/utils/Makefile.am
224@@ -1,6 +1,6 @@
225 bin_PROGRAMS = cplay crecord
226
227-cplay_SOURCES = cplay.c
228+cplay_SOURCES = cplay.c id3_tag_decode.c
229 crecord_SOURCES = crecord.c
230
231 cplay_CFLAGS = -I$(top_srcdir)/include
232diff --git a/src/utils/cplay.c b/src/utils/cplay.c
233index 87863a3..2a52b52 100644
234--- a/src/utils/cplay.c
235+++ b/src/utils/cplay.c
236@@ -72,6 +72,7 @@
237 #include "sound/compress_params.h"
238 #include "tinycompress/tinycompress.h"
239 #include "tinycompress/tinymp3.h"
240+#include "tinycompress/id3_tag_decode.h"
241
242 static int verbose;
243 static const unsigned int DEFAULT_CODEC_ID = SND_AUDIOCODEC_PCM;
244@@ -245,12 +246,97 @@ int main(int argc, char **argv)
245 exit(EXIT_SUCCESS);
246 }
247
248+void shift_buffer(char *buf, int buf_size, int bytes_consumed)
249+{
250+ int i;
251+
252+ if (bytes_consumed <= 0)
253+ return;
254+
255+ for (i = 0; i < buf_size - bytes_consumed; i++)
256+ buf[i] = buf[i + bytes_consumed];
257+}
258+
259+void parse_id3(FILE *file, int *offset) {
260+ /* ID3 tag specific declarations */
261+ unsigned char id3_buf[128];
262+ unsigned char id3v2_buf[4096];
263+ signed int id3_v1_found = 0, id3_v1_decoded = 0;
264+ signed int id3_v2_found = 0, id3_v2_complete = 0;
265+ signed int i_bytes_consumed = 0;
266+ signed int i_fread_bytes;
267+ id3v1_struct id3v1;
268+ id3v2_struct id3v2;
269+
270+ {
271+ fseek(file, -128, SEEK_END);
272+ fread(id3_buf, 1, 128, file);
273+
274+ /* search for ID3V1 */
275+ id3_v1_found = search_id3_v1(id3_buf + 0);
276+ if (id3_v1_found) {
277+ /* if ID3V1 is found, decode ID3V1 */
278+ decode_id3_v1(id3_buf + 3, &id3v1);
279+ id3_v1_decoded = 1;
280+ }
281+ fseek(file, 0, SEEK_SET);
282+ }
283+
284+ {
285+ signed int flag = 0;
286+ signed int continue_flag = 0;
287+
288+ i_fread_bytes = fread(id3v2_buf,
289+ sizeof(char), 0x1000, file);
290+
291+ /* search for ID3V2 */
292+ id3_v2_found =
293+ search_id3_v2(id3v2_buf);
294+
295+ if (id3_v2_found) {
296+ /* initialise the max fields */
297+ init_id3v2_field(&id3v2);
298+
299+ while (!id3_v2_complete && id3_v2_found) {
300+ /* if ID3V2 is found, decode ID3V2 */
301+ id3_v2_complete = decode_id3_v2((const char *const)id3v2_buf,
302+ &id3v2, continue_flag, i_fread_bytes);
303+
304+ if (!id3_v2_complete) {
305+ continue_flag = 1;
306+ i_bytes_consumed = id3v2.bytes_consumed;
307+
308+ fseek(file, i_bytes_consumed, SEEK_SET);
309+
310+ i_fread_bytes = fread(id3v2_buf,
311+ sizeof(unsigned char), 0x1000, file);
312+ if (i_fread_bytes <= 0) {
313+ return;
314+ }
315+ }
316+ }
317+
318+ if (id3_v2_complete) {
319+ i_bytes_consumed = id3v2.bytes_consumed;
320+ fseek(file, i_bytes_consumed, SEEK_SET);
321+ }
322+ }
323+ }
324+
325+ *offset = i_bytes_consumed;
326+}
327+
328 void get_codec_mp3(FILE *file, struct compr_config *config,
329 struct snd_codec *codec)
330 {
331 size_t read;
332 struct mp3_header header;
333 unsigned int channels, rate, bits;
334+ int offset = 0;
335+
336+ parse_id3(file, &offset);
337+
338+ fseek(file, offset, SEEK_SET);
339
340 read = fread(&header, 1, sizeof(header), file);
341 if (read != sizeof(header)) {
342@@ -279,6 +365,8 @@ void get_codec_mp3(FILE *file, struct compr_config *config,
343 codec->level = 0;
344 codec->ch_mode = 0;
345 codec->format = 0;
346+
347+ fseek(file, offset, SEEK_SET);
348 }
349
350 void get_codec_iec(FILE *file, struct compr_config *config,
351diff --git a/src/utils/id3_tag_decode.c b/src/utils/id3_tag_decode.c
352new file mode 100644
353index 0000000..393967a
354--- /dev/null
355+++ b/src/utils/id3_tag_decode.c
356@@ -0,0 +1,642 @@
357+/*
358+ * Copyright (c) 2006-2017 Cadence Design Systems, Inc.
359+ * Copyright 2018 NXP
360+ *
361+ * Permission is hereby granted, free of charge, to any person obtaining
362+ * a copy of this software and associated documentation files (the
363+ * "Software"), to deal in the Software without restriction, including
364+ * without limitation the rights to use, copy, modify, merge, publish,
365+ * distribute, sublicense, and/or sell copies of the Software, and to
366+ * permit persons to whom the Software is furnished to do so, subject to
367+ * the following conditions:
368+ *
369+ * The above copyright notice and this permission notice shall be included
370+ * in all copies or substantial portions of the Software.
371+ *
372+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
373+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
374+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
375+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
376+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
377+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
378+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
379+ */
380+#include <ctype.h>
381+#include "tinycompress/id3_tag_decode.h"
382+
383+#define CHAR4(c1, c2, c3, c4) \
384+ (int)(((unsigned char)(c1) << 24) | \
385+ ((unsigned char)(c2) << 16) | \
386+ ((unsigned char)(c3) << 8) | \
387+ ((unsigned char)c4))
388+
389+#ifndef MSVC_BUILD
390+unsigned int umin(unsigned int a, unsigned int b)
391+{
392+ return (a < b ? a : b);
393+}
394+
395+#else
396+unsigned int umin(unsigned int a, unsigned int b)
397+{
398+ return (a < b ? a : b);
399+}
400+#endif
401+
402+/***********************************************************
403+ * function name : display
404+ *
405+ * description : display ID3 tag contents.
406+ *
407+ * arguments : input parameters
408+ *
409+ * values returned : 0
410+ ***********************************************************/
411+
412+static void display2(const id3_v2_frame_struct * const src,
413+ int size,
414+ const char * const disp)
415+{
416+ int j;
417+
418+
419+ for (j = 0; j < size; j++) {
420+ int c = src->frame_data[j];
421+
422+ if (c) {
423+ if (!isprint(c))
424+ break;
425+ }
426+ }
427+}
428+
429+static VOID display1(WORD8 src[], WORD32 size, WORD8 disp[])
430+{
431+ WORD32 j;
432+
433+ for (j = 0; j < size ; j++) {
434+ int c = src[j];
435+
436+ if (c) {
437+ if (!isprint(c))
438+ break;
439+ }
440+ }
441+}
442+
443+/*****************************************************************
444+ * function name : init_id3_header
445+ *
446+ * description : initialise the max filed size of teh farem.
447+ *
448+ * arguments : input parameters
449+ *
450+ * values returned : 0
451+ ****************************************************************/
452+
453+VOID init_id3v2_field(id3v2_struct *id3v2)
454+{
455+ id3v2->album_movie_show_title.max_size = MAX_TAG_FRAME_SIZE;
456+ id3v2->composer_name.max_size = MAX_TAG_FRAME_SIZE;
457+ id3v2->content_type.max_size = MAX_TAG_FRAME_SIZE;
458+ id3v2->encoded_by.max_size = MAX_TAG_FRAME_SIZE;
459+ id3v2->lyricist_text_writer.max_size = MAX_TAG_FRAME_SIZE;
460+ id3v2->content_group_description.max_size = MAX_TAG_FRAME_SIZE;
461+ id3v2->title_songname_content_description.max_size = MAX_TAG_FRAME_SIZE;
462+ id3v2->medxa_type.max_size = MAX_TAG_FRAME_SIZE;
463+ id3v2->original_album_movie_show_title.max_size = MAX_TAG_FRAME_SIZE;
464+ id3v2->original_filename.max_size = MAX_TAG_FRAME_SIZE;
465+ id3v2->original_lyricist_text_writer.max_size = MAX_TAG_FRAME_SIZE;
466+ id3v2->original_artist_performer.max_size = MAX_TAG_FRAME_SIZE;
467+ id3v2->file_owner_licensee.max_size = MAX_TAG_FRAME_SIZE;
468+ id3v2->lead_performer_soloist.max_size = MAX_TAG_FRAME_SIZE;
469+ id3v2->publisher.max_size = MAX_TAG_FRAME_SIZE;
470+ id3v2->private_frame.max_size = MAX_TAG_FRAME_SIZE;
471+ id3v2->other_info.max_size = MAX_TAG_FRAME_SIZE;
472+
473+ /* resetting the flag to indicate presese of frame */
474+ id3v2->album_movie_show_title.tag_present = 0;
475+ id3v2->composer_name.tag_present = 0;
476+ id3v2->content_type.tag_present = 0;
477+ id3v2->encoded_by.tag_present = 0;
478+ id3v2->lyricist_text_writer.tag_present = 0;
479+ id3v2->content_group_description.tag_present = 0;
480+ id3v2->title_songname_content_description.tag_present = 0;
481+ id3v2->medxa_type.tag_present = 0;
482+ id3v2->original_album_movie_show_title.tag_present = 0;
483+ id3v2->original_filename.tag_present = 0;
484+ id3v2->original_lyricist_text_writer.tag_present = 0;
485+ id3v2->original_artist_performer.tag_present = 0;
486+ id3v2->file_owner_licensee.tag_present = 0;
487+ id3v2->lead_performer_soloist.tag_present = 0;
488+ id3v2->publisher.tag_present = 0;
489+ id3v2->private_frame.tag_present = 0;
490+ id3v2->other_info.tag_present = 0;
491+
492+ /* resetting the flag which indicates that size of the frame has
493+ * exceeded the max buffer size
494+ */
495+ id3v2->album_movie_show_title.exceeds_buffer_size = 0;
496+ id3v2->composer_name.exceeds_buffer_size = 0;
497+ id3v2->content_type.exceeds_buffer_size = 0;
498+ id3v2->encoded_by.exceeds_buffer_size = 0;
499+ id3v2->lyricist_text_writer.exceeds_buffer_size = 0;
500+ id3v2->content_group_description.exceeds_buffer_size = 0;
501+ id3v2->title_songname_content_description.exceeds_buffer_size = 0;
502+ id3v2->medxa_type.exceeds_buffer_size = 0;
503+ id3v2->original_album_movie_show_title.exceeds_buffer_size = 0;
504+ id3v2->original_filename.exceeds_buffer_size = 0;
505+ id3v2->original_lyricist_text_writer.exceeds_buffer_size = 0;
506+ id3v2->original_artist_performer.exceeds_buffer_size = 0;
507+ id3v2->file_owner_licensee.exceeds_buffer_size = 0;
508+ id3v2->lead_performer_soloist.exceeds_buffer_size = 0;
509+ id3v2->publisher.exceeds_buffer_size = 0;
510+ id3v2->private_frame.exceeds_buffer_size = 0;
511+ id3v2->other_info.exceeds_buffer_size = 0;
512+
513+ id3v2->bytes_consumed = 0;
514+ id3v2->header_end = 0;
515+}
516+
517+/***************************************************************
518+ * function name : search_id3_v2
519+ *
520+ * description : finds if ID3V2 starts at the start of given buffer.
521+ *
522+ * arguments : input parameters
523+ * buffer input buffer
524+ *
525+ * values returned : FLAG 1: ID3 found 0: ID3 not found
526+ ***************************************************************/
527+WORD32 search_id3_v2(UWORD8 *buffer)
528+{
529+ UWORD32 temp;
530+
531+ temp = buffer[0] << 16;
532+ temp |= buffer[1] << 8;
533+ temp |= buffer[2];
534+
535+ if (temp == ID3V2)
536+ return 1; /* ID3 found */
537+
538+ return 0; /* ID3 not found */
539+}
540+
541+/**************************************************************
542+ * function name : search_id3_v1
543+ *
544+ * description : finds if ID3V1 starts at the start of given buffer.
545+ *
546+ * arguments : input parameters
547+ * buffer input buffer
548+ *
549+ * values returned : FLAG 1: ID3 found 0: ID3 not found
550+ **************************************************************/
551+WORD32 search_id3_v1(UWORD8 *buffer)
552+{
553+ UWORD32 temp;
554+
555+ temp = buffer[0] << 16;
556+ temp |= buffer[1] << 8;
557+ temp |= buffer[2];
558+
559+ if (temp == ID3V1)
560+ return 1; /* ID3 found */
561+
562+ return 0; /* ID3 not found */
563+}
564+
565+/***************************************************************
566+ * function name : decode_id3_v1
567+ *
568+ * description : decodes ID3V1 tag.
569+ *
570+ * arguments : input parameters
571+ * buffer input buffer
572+ * id3v1 structure
573+ *
574+ * values returned : bytes consumed
575+ **************************************************************/
576+WORD32 decode_id3_v1(UWORD8 *buffer, id3v1_struct *id3v1)
577+{
578+ WORD32 bytes_consumed = 0;
579+ short tag_type;
580+
581+ /* setting the tag type */
582+ tag_type = 1;
583+
584+ bytes_consumed = get_v1_info(buffer, id3v1);
585+
586+ return bytes_consumed;
587+}
588+
589+/***********************************************************
590+ * function name : get_v1_info
591+ *
592+ * description : gets ID3V1 information fields.
593+ *
594+ * arguments : input parameters
595+ * buffer input buffer
596+ * id3v1 structure
597+ *
598+ * values returned : bytes consumed
599+ ***********************************************************/
600+WORD32 get_v1_info(UWORD8 *buffer, id3v1_struct *id3v1)
601+{
602+ WORD32 i;
603+ WORD32 bytes_consumed = 0;
604+
605+ /* get song_title */
606+ for (i = 0; i < 30; i++)
607+ id3v1->song_title[i] = buffer[i];
608+
609+ buffer += 30;
610+ bytes_consumed += 30;
611+ display1(id3v1->song_title, 30, (WORD8 *)"song_title : ");
612+
613+ /* get artist */
614+ for (i = 0; i < 30; i++)
615+ id3v1->artist[i] = buffer[i];
616+
617+ buffer += 30;
618+ bytes_consumed += 30;
619+ display1(id3v1->artist, 30, (WORD8 *)"artist : ");
620+
621+ /* get album */
622+ for (i = 0; i < 30; i++)
623+ id3v1->album[i] = buffer[i];
624+
625+ buffer += 30;
626+ bytes_consumed += 30;
627+ display1(id3v1->album, 30, (WORD8 *)"album : ");
628+
629+ /* get year */
630+ for (i = 0; i < 4; i++)
631+ id3v1->year[i] = buffer[i];
632+
633+ buffer += 4;
634+ bytes_consumed += 4;
635+ display1(id3v1->year, 4, (WORD8 *)"year : ");
636+
637+ /* get comment */
638+ for (i = 0; i < 30; i++)
639+ id3v1->comment[i] = buffer[i];
640+
641+ buffer += 30;
642+ bytes_consumed += 30;
643+ display1(id3v1->comment, 30, (WORD8 *)"comment : ");
644+
645+ /* get genre */
646+ for (i = 0; i < 1; i++)
647+ id3v1->genre[i] = buffer[i];
648+
649+ buffer += 1;
650+ bytes_consumed += 1;
651+
652+ return bytes_consumed;
653+}
654+
655+/*****************************************************
656+ * function name : decode_id3_v2
657+ *
658+ * description : decodes ID3V2 tag.
659+ *
660+ * arguments : input parameters
661+ * buffer input buffer
662+ * id3v2 structure
663+ * continue_flag FLAG to indicate whether
664+ * it is first call or not
665+ * insize input buffer size
666+ *
667+ * values returned : bytes consumed
668+ ******************************************************/
669+WORD32 decode_id3_v2(const char *const buffer,
670+ id3v2_struct *const id3v2,
671+ WORD32 continue_flag,
672+ WORD32 insize)
673+{
674+ UWORD32 size = 0, flag;
675+ WORD32 i, buf_update_val;
676+ UWORD8 buf[4], frame_header[10], id3_buffer[10];
677+ WORD8 *bitstream_ptr;
678+ short tag_type;
679+
680+ WORD32 bytes_consumed = 0;
681+
682+ if (id3v2->header_end == 1) {
683+ id3v2->bytes_consumed += insize;
684+ if (id3v2->bytes_consumed < id3v2->id3_v2_header.size)
685+ return 0;
686+
687+ id3v2->bytes_consumed = (id3v2->id3_v2_header.size + 10);
688+ return 1;
689+ }
690+
691+ bitstream_ptr = (WORD8 *)id3_buffer;
692+
693+ if (!continue_flag) {
694+ bytes_consumed += 3;
695+ /* setting the tag type */
696+ tag_type = 2;
697+ id3v2->id3_v2_header.version = buffer[bytes_consumed + 0] << 8;
698+ id3v2->id3_v2_header.version |= buffer[bytes_consumed + 1];
699+ id3v2->id3_v2_header.flag = buffer[bytes_consumed + 2];
700+
701+ /* making the msb of each byte zero */
702+ buf[0] = buffer[bytes_consumed + 6] & 0x7f;
703+ buf[1] = buffer[bytes_consumed + 5] & 0x7f;
704+ buf[2] = buffer[bytes_consumed + 4] & 0x7f;
705+ buf[3] = buffer[bytes_consumed + 3] & 0x7f;
706+
707+ bytes_consumed += 7;
708+
709+ /* concatenation the bytes after making
710+ * 7th bit zero to get 28 bits size
711+ */
712+ size = buf[0];
713+ size |= (buf[1] << 7);
714+ size |= (buf[2] << 14);
715+ size |= (buf[3] << 21);
716+ /* storing the size */
717+ id3v2->id3_v2_header.size = size;
718+
719+ /* check for extended header */
720+ if (id3v2->id3_v2_header.flag & 0x20) {
721+ for (i = 0; i < 10; i++)
722+ bitstream_ptr[i] = buffer[bytes_consumed + i];
723+
724+ i = 0;
725+ bytes_consumed += 10;
726+
727+ size = bitstream_ptr[i++] << 24;
728+ size |= bitstream_ptr[i++] << 16;
729+ size |= bitstream_ptr[i++] << 8;
730+ size |= bitstream_ptr[i++];
731+
732+ /* two bytes for flag */
733+ i += 2;
734+ {
735+ UWORD32 padding_size;
736+
737+ padding_size = bitstream_ptr[i++] << 24;
738+ padding_size |= bitstream_ptr[i++] << 16;
739+ padding_size |= bitstream_ptr[i++] << 8;
740+ padding_size |= bitstream_ptr[i++];
741+
742+ /* skipping the padding and frame size
743+ * number of bytes
744+ */
745+ bytes_consumed += (padding_size + size);
746+ }
747+ }
748+ }
749+
750+ while (id3v2->header_end != 1) {
751+ char *key;
752+ id3_v2_frame_struct *value;
753+ unsigned int avail_inp;
754+
755+ /* reading the 10 bytes to get the frame header */
756+
757+ for (i = 0; i < 10; i++)
758+ frame_header[i] = buffer[bytes_consumed + i];
759+ bytes_consumed += 10;
760+
761+ /* getting the size from the header */
762+ size = frame_header[4] << 24;
763+ size |= frame_header[5] << 16;
764+ size |= frame_header[6] << 8;
765+ size |= frame_header[7];
766+
767+ /* decoding the flag, currently not used */
768+ flag = frame_header[8] << 8;
769+ flag |= frame_header[9];
770+
771+ avail_inp = insize - bytes_consumed;
772+
773+ /* switching to the frame type */
774+ switch (CHAR4(frame_header[0],
775+ frame_header[1],
776+ frame_header[2],
777+ frame_header[3])) {
778+ case CHAR4('A', 'E', 'N', 'C'):
779+ case CHAR4('A', 'P', 'I', 'C'):
780+ case CHAR4('C', 'O', 'M', 'M'):
781+ case CHAR4('C', 'O', 'M', 'R'):
782+ case CHAR4('E', 'N', 'C', 'R'):
783+ case CHAR4('E', 'Q', 'U', 'A'):
784+ case CHAR4('E', 'T', 'C', 'O'):
785+ case CHAR4('G', 'E', 'O', 'B'):
786+ case CHAR4('G', 'R', 'I', 'D'):
787+ case CHAR4('I', 'P', 'L', 'S'):
788+ case CHAR4('L', 'I', 'N', 'K'):
789+ case CHAR4('M', 'C', 'D', 'I'):
790+ case CHAR4('M', 'L', 'L', 'T'):
791+ case CHAR4('O', 'W', 'N', 'E'):
792+ case CHAR4('P', 'C', 'N', 'T'):
793+ case CHAR4('P', 'O', 'P', 'M'):
794+ case CHAR4('P', 'O', 'S', 'S'):
795+ case CHAR4('R', 'B', 'U', 'F'):
796+ case CHAR4('R', 'V', 'A', 'D'):
797+ case CHAR4('R', 'V', 'R', 'B'):
798+ case CHAR4('S', 'Y', 'L', 'T'):
799+ case CHAR4('S', 'Y', 'T', 'C'):
800+ case CHAR4('T', 'B', 'P', 'M'):
801+ case CHAR4('T', 'C', 'O', 'P'):
802+ case CHAR4('T', 'D', 'A', 'T'):
803+ case CHAR4('T', 'D', 'L', 'Y'):
804+ case CHAR4('T', 'F', 'L', 'T'):
805+ case CHAR4('T', 'I', 'M', 'E'):
806+ case CHAR4('T', 'K', 'E', 'Y'):
807+ case CHAR4('T', 'L', 'A', 'N'):
808+ case CHAR4('T', 'L', 'E', 'N'):
809+ case CHAR4('T', 'M', 'E', 'D'):
810+ case CHAR4('T', 'O', 'F', 'N'):
811+ case CHAR4('T', 'O', 'L', 'Y'):
812+ case CHAR4('T', 'O', 'R', 'Y'):
813+ case CHAR4('T', 'P', 'E', '2'):
814+ case CHAR4('T', 'P', 'E', '3'):
815+ case CHAR4('T', 'P', 'E', '4'):
816+ case CHAR4('T', 'P', 'O', 'S'):
817+ case CHAR4('T', 'R', 'C', 'K'):
818+ case CHAR4('T', 'R', 'D', 'A'):
819+ case CHAR4('T', 'R', 'S', 'N'):
820+ case CHAR4('T', 'R', 'S', 'O'):
821+ case CHAR4('T', 'S', 'I', 'Z'):
822+ case CHAR4('T', 'S', 'R', 'C'):
823+ case CHAR4('T', 'S', 'S', 'E'):
824+ case CHAR4('T', 'Y', 'E', 'R'):
825+ case CHAR4('T', 'X', 'X', 'X'):
826+ case CHAR4('U', 'F', 'I', 'D'):
827+ case CHAR4('U', 'S', 'E', 'R'):
828+ case CHAR4('U', 'S', 'L', 'T'):
829+ case CHAR4('W', 'C', 'O', 'M'):
830+ case CHAR4('W', 'C', 'O', 'P'):
831+ case CHAR4('W', 'O', 'A', 'F'):
832+ case CHAR4('W', 'O', 'A', 'R'):
833+ case CHAR4('W', 'O', 'A', 'S'):
834+ case CHAR4('W', 'O', 'R', 'S'):
835+ case CHAR4('W', 'P', 'A', 'Y'):
836+ case CHAR4('W', 'P', 'U', 'B'):
837+ case CHAR4('W', 'X', 'X', 'X'):
838+ case CHAR4('T', 'I', 'T', '3'):
839+ key = "other_info : ";
840+ value = &id3v2->other_info;
841+ break;
842+ case CHAR4('P', 'R', 'I', 'V'):
843+ key = "private_frame : ";
844+ value = &id3v2->private_frame;
845+ break;
846+ case CHAR4('T', 'A', 'L', 'B'):
847+ key = "album_movie_show_title : ";
848+ value = &id3v2->album_movie_show_title;
849+ break;
850+ case CHAR4('T', 'C', 'O', 'M'):
851+ key = "composer_name : ";
852+ value = &id3v2->composer_name;
853+ break;
854+ case CHAR4('T', 'C', 'O', 'N'):
855+ key = "content_type : ";
856+ value = &id3v2->content_type;
857+ break;
858+ case CHAR4('T', 'E', 'N', 'C'):
859+ key = "encoded_by : ";
860+ value = &id3v2->encoded_by;
861+ break;
862+ case CHAR4('T', 'E', 'X', 'T'):
863+ key = "lyricist_text_writer : ";
864+ value = &id3v2->lyricist_text_writer;
865+ break;
866+ case CHAR4('T', 'I', 'T', '1'):
867+ key = "content_group_description : ";
868+ value = &id3v2->content_group_description;
869+ break;
870+ case CHAR4('T', 'I', 'T', '2'):
871+ key = "title_songname_content_description : ";
872+ value = &id3v2->title_songname_content_description;
873+ break;
874+ case CHAR4('T', 'O', 'A', 'L'):
875+ key = "original_album_movie_show_title : ";
876+ value = &id3v2->original_album_movie_show_title;
877+ break;
878+ case CHAR4('T', 'O', 'P', 'E'):
879+ key = "original_artist_performer : ";
880+ value = &id3v2->original_artist_performer;
881+ break;
882+ case CHAR4('T', 'O', 'W', 'N'):
883+ key = "file_owner_licensee : ";
884+ value = &id3v2->file_owner_licensee;
885+ break;
886+ case CHAR4('T', 'P', 'E', '1'):
887+ key = "lead_performer_soloist : ";
888+ value = &id3v2->lead_performer_soloist;
889+ break;
890+ case CHAR4('T', 'P', 'U', 'B'):
891+ key = "publisher : ";
892+ value = &id3v2->publisher;
893+ break;
894+ default:
895+ /* skipping the read 10 bytes */
896+ buf_update_val = -10;
897+ id3v2->header_end = 1;
898+ value = 0;
899+ key = 0;
900+ break;
901+ }
902+
903+ if (value != 0)
904+ buf_update_val = get_info(&buffer[bytes_consumed],
905+ avail_inp, size, value);
906+
907+ /* Negative value for buf_update_val means one of two things:
908+ * 1. The default case happened and we're done with ID3V2 tag
909+ * frames, or
910+ * 2. get_info() returned -1 to indicate that more input is
911+ * required to decode this frame of the tag.
912+ */
913+ if (buf_update_val >= 0)
914+ display2(value,
915+ umin(value->max_size, buf_update_val), key);
916+
917+ if (buf_update_val == -1) {
918+ id3v2->bytes_consumed += bytes_consumed;
919+ return 1;
920+ }
921+
922+ bytes_consumed += buf_update_val;
923+
924+ /* Is there enough input left (10 bytes) to begin
925+ * decoding another frame? If not, bag out temporarily
926+ * now. The caller will refill our input buffer and
927+ * call us again with continue_flag == 1.
928+ */
929+ if (insize - bytes_consumed < 10) {
930+ id3v2->bytes_consumed += bytes_consumed;
931+ return 0; /* not completely decoded */
932+ }
933+ }
934+
935+ id3v2->bytes_consumed += bytes_consumed;
936+ if ((id3v2->bytes_consumed + 10) < id3v2->id3_v2_header.size)
937+ return 0; /* not completely decoded */
938+
939+ return 1; /* completely decoded */
940+}
941+
942+/*******************************************************
943+ * function name : get_id3_v2_bytes
944+ *
945+ * description : tells the size of ID3V2 tag.
946+ *
947+ * arguments : input parameters
948+ * buffer input buffer
949+ *
950+ * values returned : bytes consumed
951+ ********************************************************/
952+WORD32 get_id3_v2_bytes(UWORD8 *buffer)
953+{
954+ WORD32 size;
955+
956+ /* making the msb of each byte zero */
957+ size = (buffer[9] & 0x7f);
958+ size |= ((buffer[8] & 0x7f) << 7);
959+ size |= ((buffer[7] & 0x7f) << 14);
960+ size |= ((buffer[6] & 0x7f) << 21);
961+
962+ return (size + 10);
963+}
964+
965+/****************************************************
966+ * function name : get_info
967+ *
968+ * description : read the frame information from the input buffer.
969+ *
970+ * arguments : input parameters
971+ *
972+ * values returned : update value for buffer
973+ ****************************************************/
974+WORD32 get_info(const char *inp_buffer,
975+ unsigned int avail_inp,
976+ WORD32 tag_size,
977+ id3_v2_frame_struct *dest)
978+{
979+ WORD32 j;
980+
981+ /* setting the tag to indicate the presence of frame */
982+ dest->tag_present = 1;
983+ /* If there isn't enough input available, we punt back to the top
984+ * level and ask for more.
985+ */
986+ if (avail_inp < umin(tag_size, dest->max_size))
987+ return -1;
988+
989+ if (dest->max_size >= tag_size) {
990+ for (j = 0; j < tag_size ; j++)
991+ dest->frame_data[j] = inp_buffer[j];
992+ } else {
993+ dest->exceeds_buffer_size = 1;
994+ for (j = 0; j < dest->max_size ; j++)
995+ dest->frame_data[j] = inp_buffer[j];
996+ }
997+ return tag_size;
998+}
999--
10002.7.4
1001