summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2005-10-29 17:12:52 +0000
committerDave Chapman <dave@dchapman.com>2005-10-29 17:12:52 +0000
commit45f9e5d7b02ce3b9d165f45d63825d50244634d4 (patch)
tree900097f56dbecc41ea4fc6cd50366f0af3164e84
parente75cbdd2a84904e9294091c0ae599762b067077a (diff)
Remove generic M4A parsing code from libalac and create a libm4a - so it can be used by other codecs
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7682 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/Makefile13
-rw-r--r--apps/codecs/alac.c212
-rw-r--r--apps/codecs/libalac/demux.h55
-rw-r--r--apps/codecs/libalac/stream.h27
-rw-r--r--apps/codecs/libm4a/Makefile47
-rw-r--r--apps/codecs/libm4a/SOURCES2
-rw-r--r--apps/codecs/libm4a/demux.c (renamed from apps/codecs/libalac/demux.c)7
-rw-r--r--apps/codecs/libm4a/m4a.c225
-rw-r--r--apps/codecs/libm4a/m4a.h104
-rwxr-xr-xtools/configure8
10 files changed, 400 insertions, 300 deletions
diff --git a/apps/codecs/Makefile b/apps/codecs/Makefile
index 2c1cd93cc6..3b86435208 100644
--- a/apps/codecs/Makefile
+++ b/apps/codecs/Makefile
@@ -17,7 +17,7 @@ ifdef APPEXTRA
endif
ifdef SOFTWARECODECS
- CODECLIBS = -lmad -la52 -lffmpegFLAC -lTremor -lwavpack -lmusepack -lalac
+ CODECLIBS = -lmad -la52 -lffmpegFLAC -lTremor -lwavpack -lmusepack -lalac -lm4a
endif
# we "borrow" the plugin LDS file
@@ -39,7 +39,7 @@ DIRS = .
CODECDEPS = $(LINKCODEC) $(BUILDDIR)/libcodec.a
-.PHONY: libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac
+.PHONY: libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libm4a
OUTPUT = $(SOFTWARECODECS)
@@ -60,7 +60,7 @@ $(OBJDIR)/vorbis.elf: $(OBJDIR)/vorbis.o $(CODECDEPS) $(BUILDDIR)/libTremor.a
$(OBJDIR)/mpc.elf: $(OBJDIR)/mpc.o $(CODECDEPS) $(BUILDDIR)/libmusepack.a
$(OBJDIR)/wav.elf: $(OBJDIR)/wav.o $(CODECDEPS)
$(OBJDIR)/wavpack.elf: $(OBJDIR)/wavpack.o $(CODECDEPS) $(BUILDDIR)/libwavpack.a
-$(OBJDIR)/alac.elf: $(OBJDIR)/alac.o $(CODECDEPS) $(BUILDDIR)/libalac.a
+$(OBJDIR)/alac.elf: $(OBJDIR)/alac.o $(CODECDEPS) $(BUILDDIR)/libalac.a $(BUILDDIR)/libm4a.a
$(OBJDIR)/%.elf: $(OBJDIR)/%.o $(CODECDEPS)
$(ELFIT)
@@ -157,10 +157,14 @@ libalac:
@echo "MAKE in libalac"
@mkdir -p $(OBJDIR)/libalac
@$(MAKE) -C libalac OBJDIR=$(OBJDIR)/libalac OUTPUT=$(BUILDDIR)/libalac.a
+libm4a:
+ @echo "MAKE in libm4a"
+ @mkdir -p $(OBJDIR)/libm4a
+ @$(MAKE) -C libm4a OBJDIR=$(OBJDIR)/libm4a OUTPUT=$(BUILDDIR)/libm4a.a
clean:
@echo "cleaning codecs"
- $(SILENT)rm -fr $(OBJDIR)/libmad $(BUILDDIR)/libmad.a $(OBJDIR)/liba52 $(OBJDIR)/libffmpegFLAC $(BUILDDIR)/libffmpegFLAC.a $(OBJDIR)/Tremor $(OBJDIR)/libwavpack $(OBJDIR)/dumb $(BUILDDIR)/libdumb.a $(BUILDDIR)/libdumbd.a $(OBJDIR)/libmusepack $(BUILDDIR)/libmusepack.a $(OBJDIR)/libalac $(BUILDDIR)/libalac.a
+ $(SILENT)rm -fr $(OBJDIR)/libmad $(BUILDDIR)/libmad.a $(OBJDIR)/liba52 $(OBJDIR)/libffmpegFLAC $(BUILDDIR)/libffmpegFLAC.a $(OBJDIR)/Tremor $(OBJDIR)/libwavpack $(OBJDIR)/dumb $(BUILDDIR)/libdumb.a $(BUILDDIR)/libdumbd.a $(OBJDIR)/libmusepack $(BUILDDIR)/libmusepack.a $(OBJDIR)/libalac $(BUILDDIR)/libalac.a $(OBJDIR)/libm4a $(BUILDDIR)/libm4a.a
@$(MAKE) -C libmad clean OBJDIR=$(OBJDIR)/libmad
@$(MAKE) -C liba52 clean OBJDIR=$(OBJDIR)/liba52
@$(MAKE) -C libffmpegFLAC clean OBJDIR=$(OBJDIR)/libffmpegFLAC
@@ -168,5 +172,6 @@ clean:
@$(MAKE) -C libwavpack clean OBJDIR=$(OBJDIR)/libwavpack
@$(MAKE) -C libmusepack clean OBJDIR=$(OBJDIR)/libmusepack
@$(MAKE) -C libalac clean OBJDIR=$(OBJDIR)/libalac
+ @$(MAKE) -C libm4a clean OBJDIR=$(OBJDIR)/libm4a
@$(MAKE) -C dumb clean OBJDIR=$(OBJDIR)/dumb
@$(MAKE) -C lib clean OBJDIR=$(OBJDIR)/lib
diff --git a/apps/codecs/alac.c b/apps/codecs/alac.c
index d4823233f2..916dd06262 100644
--- a/apps/codecs/alac.c
+++ b/apps/codecs/alac.c
@@ -18,9 +18,8 @@
****************************************************************************/
#include "codeclib.h"
-#include <codecs/libalac/demux.h>
-#include <codecs/libalac/decomp.h>
-#include <codecs/libalac/stream.h>
+#include "libm4a/m4a.h"
+#include "libalac/decomp.h"
#ifndef SIMULATOR
extern char iramcopy[];
@@ -32,212 +31,16 @@ extern char iramend[];
char inputBuffer[1024*32]; /* Input buffer */
int32_t outputbuffer[ALAC_MAX_CHANNELS][ALAC_BLOCKSIZE] IBSS_ATTR;
-size_t mdat_offset;
+
struct codec_api* rb;
struct codec_api* ci;
-/* Implementation of the stream.h functions used by libalac */
-
-#define _Swap32(v) do { \
- v = (((v) & 0x000000FF) << 0x18) | \
- (((v) & 0x0000FF00) << 0x08) | \
- (((v) & 0x00FF0000) >> 0x08) | \
- (((v) & 0xFF000000) >> 0x18); } while(0)
-
-#define _Swap16(v) do { \
- v = (((v) & 0x00FF) << 0x08) | \
- (((v) & 0xFF00) >> 0x08); } while (0)
-
-/* A normal read without any byte-swapping */
-void stream_read(stream_t *stream, size_t size, void *buf)
-{
- ci->read_filebuf(buf,size);
- if (ci->curpos >= ci->filesize) { stream->eof=1; }
-}
-
-int32_t stream_read_int32(stream_t *stream)
-{
- int32_t v;
- stream_read(stream, 4, &v);
-#ifdef ROCKBOX_LITTLE_ENDIAN
- _Swap32(v);
-#endif
- return v;
-}
-
-uint32_t stream_read_uint32(stream_t *stream)
-{
- uint32_t v;
- stream_read(stream, 4, &v);
-#ifdef ROCKBOX_LITTLE_ENDIAN
- _Swap32(v);
-#endif
- return v;
-}
-
-int16_t stream_read_int16(stream_t *stream)
-{
- int16_t v;
- stream_read(stream, 2, &v);
-#ifdef ROCKBOX_LITTLE_ENDIAN
- _Swap16(v);
-#endif
- return v;
-}
-
-uint16_t stream_read_uint16(stream_t *stream)
-{
- uint16_t v;
- stream_read(stream, 2, &v);
-#ifdef ROCKBOX_LITTLE_ENDIAN
- _Swap16(v);
-#endif
- return v;
-}
-
-int8_t stream_read_int8(stream_t *stream)
-{
- int8_t v;
- stream_read(stream, 1, &v);
- return v;
-}
-
-uint8_t stream_read_uint8(stream_t *stream)
-{
- uint8_t v;
- stream_read(stream, 1, &v);
- return v;
-}
-
-void stream_skip(stream_t *stream, size_t skip)
-{
- (void)stream;
- ci->advance_buffer(skip);
-}
-
-int stream_eof(stream_t *stream)
-{
- return stream->eof;
-}
-
-void stream_create(stream_t *stream)
-{
- stream->eof=0;
-}
-
-/* This function was part of the original alac decoder implementation */
-
-static int get_sample_info(demux_res_t *demux_res, uint32_t samplenum,
- uint32_t *sample_duration,
- uint32_t *sample_byte_size)
-{
- unsigned int duration_index_accum = 0;
- unsigned int duration_cur_index = 0;
-
- if (samplenum >= demux_res->num_sample_byte_sizes) {
- return 0;
- }
-
- if (!demux_res->num_time_to_samples) {
- return 0;
- }
-
- while ((demux_res->time_to_sample[duration_cur_index].sample_count
- + duration_index_accum) <= samplenum) {
- duration_index_accum +=
- demux_res->time_to_sample[duration_cur_index].sample_count;
-
- duration_cur_index++;
- if (duration_cur_index >= demux_res->num_time_to_samples) {
- return 0;
- }
- }
-
- *sample_duration =
- demux_res->time_to_sample[duration_cur_index].sample_duration;
- *sample_byte_size = demux_res->sample_byte_size[samplenum];
-
- return 1;
-}
-
-/* Seek to sample_loc (or close to it). Return 1 on success (and
- modify samplesdone and currentblock), 0 if failed
-
- Seeking uses the following two arrays:
-
- 1) the sample_byte_size array contains the length in bytes of
- each block ("sample" in Applespeak).
-
- 2) the time_to_sample array contains the duration (in samples) of
- each block of data.
-
- So we just find the block number we are going to seek to (using
- time_to_sample) and then find the offset in the file (using
- sample_byte_size).
-
- Each ALAC block seems to be independent of all the others.
- */
-
-static unsigned int alac_seek (demux_res_t* demux_res,
- unsigned int sample_loc,
- uint32_t* samplesdone, int* currentblock)
-{
- int flag;
- unsigned int i,j;
- unsigned int newblock;
- unsigned int newsample;
- unsigned int newpos;
-
- /* First check we have the appropriate metadata - we should always
- have it. */
- if ((demux_res->num_time_to_samples==0) ||
- (demux_res->num_sample_byte_sizes==0)) { return 0; }
-
- /* Find the destination block from time_to_sample array */
- i=0;
- newblock=0;
- newsample=0;
- flag=0;
-
- while ((i<demux_res->num_time_to_samples) && (flag==0) &&
- (newsample < sample_loc)) {
- j=(sample_loc-newsample) /
- demux_res->time_to_sample[i].sample_duration;
-
- if (j <= demux_res->time_to_sample[i].sample_count) {
- newblock+=j;
- newsample+=j*demux_res->time_to_sample[i].sample_duration;
- flag=1;
- } else {
- newsample+=(demux_res->time_to_sample[i].sample_duration
- * demux_res->time_to_sample[i].sample_count);
- newblock+=demux_res->time_to_sample[i].sample_count;
- i++;
- }
- }
-
- /* We know the new block, now calculate the file position */
- newpos=mdat_offset;
- for (i=0;i<newblock;i++) {
- newpos+=demux_res->sample_byte_size[i];
- }
-
- /* We know the new file position, so let's try to seek to it */
- if (ci->seek_buffer(newpos)) {
- *samplesdone=newsample;
- *currentblock=newblock;
- return 1;
- } else {
- return 0;
- }
-}
-
/* this is the codec entry point */
enum codec_status codec_start(struct codec_api* api)
{
size_t n;
demux_res_t demux_res;
- static stream_t input_stream;
+ stream_t input_stream;
uint32_t samplesdone;
uint32_t elapsedtime;
uint32_t sample_duration;
@@ -278,7 +81,7 @@ enum codec_status codec_start(struct codec_api* api)
ci->configure(DSP_SET_FREQUENCY, (long *)(rb->id3->frequency));
- stream_create(&input_stream);
+ stream_create(&input_stream,ci);
/* if qtmovie_read returns successfully, the stream is up to
* the movie data, which can be used directly by the decoder */
@@ -287,9 +90,6 @@ enum codec_status codec_start(struct codec_api* api)
return CODEC_ERROR;
}
- /* Keep track of start of stream in file - used for seeking */
- mdat_offset=ci->curpos;
-
/* initialise the sound converter */
create_alac(demux_res.sample_size, demux_res.num_channels,&alac);
alac_set_info(&alac, demux_res.codecdata);
@@ -305,7 +105,7 @@ enum codec_status codec_start(struct codec_api* api)
/* Deal with any pending seek requests */
if (ci->seek_time) {
- if (alac_seek(&demux_res,
+ if (alac_seek(&demux_res,&input_stream,
(ci->seek_time/10) * (ci->id3->frequency/100),
&samplesdone, &i)) {
elapsedtime=(samplesdone*10)/(ci->id3->frequency/100);
diff --git a/apps/codecs/libalac/demux.h b/apps/codecs/libalac/demux.h
deleted file mode 100644
index 27c9e826c5..0000000000
--- a/apps/codecs/libalac/demux.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef DEMUX_H
-#define DEMUX_H
-
-#include <inttypes.h>
-#include "stream.h"
-
-typedef uint32_t fourcc_t;
-
-typedef struct
-{
- uint16_t num_channels;
- uint16_t sample_size;
- uint32_t sample_rate;
- fourcc_t format;
- void *buf;
-
- struct {
- uint32_t sample_count;
- uint32_t sample_duration;
- } *time_to_sample;
- uint32_t num_time_to_samples;
-
- uint32_t *sample_byte_size;
- uint32_t num_sample_byte_sizes;
-
- uint32_t codecdata_len;
- void *codecdata;
-
- uint32_t mdat_len;
-#if 0
- void *mdat;
-#endif
-} demux_res_t;
-
-int qtmovie_read(stream_t *stream, demux_res_t *demux_res);
-
-#ifndef MAKEFOURCC
-#define MAKEFOURCC(ch0, ch1, ch2, ch3) ( \
- ( (int32_t)(char)(ch0) << 24 ) | \
- ( (int32_t)(char)(ch1) << 16 ) | \
- ( (int32_t)(char)(ch2) << 8 ) | \
- ( (int32_t)(char)(ch3) ) )
-#endif
-
-#ifndef SLPITFOURCC
-/* splits it into ch0, ch1, ch2, ch3 - use for printf's */
-#define SPLITFOURCC(code) \
- (char)((int32_t)code >> 24), \
- (char)((int32_t)code >> 16), \
- (char)((int32_t)code >> 8), \
- (char)code
-#endif
-
-#endif /* DEMUX_H */
-
diff --git a/apps/codecs/libalac/stream.h b/apps/codecs/libalac/stream.h
deleted file mode 100644
index 95be0b56d0..0000000000
--- a/apps/codecs/libalac/stream.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef STREAM_H
-#define STREAM_H
-
-/* stream.h */
-
-#include <inttypes.h>
-
-typedef struct {
- int eof;
-} stream_t;
-
-void stream_read(stream_t *stream, size_t len, void *buf);
-
-int32_t stream_read_int32(stream_t *stream);
-uint32_t stream_read_uint32(stream_t *stream);
-
-int16_t stream_read_int16(stream_t *stream);
-uint16_t stream_read_uint16(stream_t *stream);
-
-int8_t stream_read_int8(stream_t *stream);
-uint8_t stream_read_uint8(stream_t *stream);
-
-void stream_skip(stream_t *stream, size_t skip);
-
-int stream_eof(stream_t *stream);
-
-#endif /* STREAM_H */
diff --git a/apps/codecs/libm4a/Makefile b/apps/codecs/libm4a/Makefile
new file mode 100644
index 0000000000..540a532213
--- /dev/null
+++ b/apps/codecs/libm4a/Makefile
@@ -0,0 +1,47 @@
+# __________ __ ___.
+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+# \/ \/ \/ \/ \/
+# $Id$
+#
+
+INCLUDES=-I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
+ -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(BUILDDIR)
+
+ifdef APPEXTRA
+ INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA)))
+endif
+
+M4AOPTS = -O3
+CFLAGS = $(GCCOPTS) $(M4AOPTS) $(INCLUDES) $(TARGET) $(EXTRA_DEFINES) -DMEM=${MEMORYSIZE}
+
+# This sets up 'SRC' based on the files mentioned in SOURCES
+include $(TOOLSDIR)/makesrc.inc
+
+SOURCES = $(SRC)
+OBJS2 := $(SRC:%.c=$(OBJDIR)/%.o)
+OBJS = $(patsubst %.S, $(OBJDIR)/%.o, $(OBJS2))
+DEPFILE = $(OBJDIR)/dep-libm4a
+DIRS =
+
+OUTPUT = $(BUILDDIR)/libm4a.a
+
+all: $(OUTPUT)
+
+$(OUTPUT): $(OBJS)
+ @echo "AR $@"
+ @$(AR) ruv $@ $+ >/dev/null 2>&1
+
+$(OBJDIR)/libm4a/%.o: $(APPSDIR)/codecs/libm4a/%.c
+ @echo "(libm4a) CC $<"
+ @$(CC) -c $(CFLAGS) -I$(APPSDIR)/codecs/libm4a/ $< -o $@
+
+include $(TOOLSDIR)/make.inc
+
+clean:
+ @echo "cleaning libm4a"
+ @rm -f $(OBJS) $(OUTPUT) $(DEPFILE)
+
+-include $(DEPFILE)
diff --git a/apps/codecs/libm4a/SOURCES b/apps/codecs/libm4a/SOURCES
new file mode 100644
index 0000000000..01b93bef01
--- /dev/null
+++ b/apps/codecs/libm4a/SOURCES
@@ -0,0 +1,2 @@
+m4a.c
+demux.c
diff --git a/apps/codecs/libalac/demux.c b/apps/codecs/libm4a/demux.c
index 80963a2fce..ba0c2feea3 100644
--- a/apps/codecs/libalac/demux.c
+++ b/apps/codecs/libm4a/demux.c
@@ -29,16 +29,13 @@
*
*/
-
#include <string.h>
-#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include "../codec.h"
-#include "stream.h"
-#include "demux.h"
+#include "m4a.h"
typedef struct
{
@@ -637,6 +634,8 @@ int qtmovie_read(stream_t *file, demux_res_t *demux_res)
* as they may not always be avilable */
case MAKEFOURCC('m','d','a','t'):
read_chunk_mdat(&qtmovie, chunk_len);
+ /* Keep track of start of stream in file - used for seeking */
+ qtmovie.res->mdat_offset=stream_tell(qtmovie.stream);
return 1;
/* these following atoms can be skipped !!!! */
diff --git a/apps/codecs/libm4a/m4a.c b/apps/codecs/libm4a/m4a.c
new file mode 100644
index 0000000000..53a8e9fb2f
--- /dev/null
+++ b/apps/codecs/libm4a/m4a.c
@@ -0,0 +1,225 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 Dave Chapman
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <codecs.h>
+#include <inttypes.h>
+#include "m4a.h"
+
+/* Implementation of the stream.h functions used by libalac */
+
+#define _Swap32(v) do { \
+ v = (((v) & 0x000000FF) << 0x18) | \
+ (((v) & 0x0000FF00) << 0x08) | \
+ (((v) & 0x00FF0000) >> 0x08) | \
+ (((v) & 0xFF000000) >> 0x18); } while(0)
+
+#define _Swap16(v) do { \
+ v = (((v) & 0x00FF) << 0x08) | \
+ (((v) & 0xFF00) >> 0x08); } while (0)
+
+/* A normal read without any byte-swapping */
+void stream_read(stream_t *stream, size_t size, void *buf)
+{
+ stream->ci->read_filebuf(buf,size);
+ if (stream->ci->curpos >= stream->ci->filesize) { stream->eof=1; }
+}
+
+int32_t stream_read_int32(stream_t *stream)
+{
+ int32_t v;
+ stream_read(stream, 4, &v);
+#ifdef ROCKBOX_LITTLE_ENDIAN
+ _Swap32(v);
+#endif
+ return v;
+}
+
+int32_t stream_tell(stream_t *stream)
+{
+ return stream->ci->curpos;
+}
+
+uint32_t stream_read_uint32(stream_t *stream)
+{
+ uint32_t v;
+ stream_read(stream, 4, &v);
+#ifdef ROCKBOX_LITTLE_ENDIAN
+ _Swap32(v);
+#endif
+ return v;
+}
+
+int16_t stream_read_int16(stream_t *stream)
+{
+ int16_t v;
+ stream_read(stream, 2, &v);
+#ifdef ROCKBOX_LITTLE_ENDIAN
+ _Swap16(v);
+#endif
+ return v;
+}
+
+uint16_t stream_read_uint16(stream_t *stream)
+{
+ uint16_t v;
+ stream_read(stream, 2, &v);
+#ifdef ROCKBOX_LITTLE_ENDIAN
+ _Swap16(v);
+#endif
+ return v;
+}
+
+int8_t stream_read_int8(stream_t *stream)
+{
+ int8_t v;
+ stream_read(stream, 1, &v);
+ return v;
+}
+
+uint8_t stream_read_uint8(stream_t *stream)
+{
+ uint8_t v;
+ stream_read(stream, 1, &v);
+ return v;
+}
+
+void stream_skip(stream_t *stream, size_t skip)
+{
+ (void)stream;
+ stream->ci->advance_buffer(skip);
+}
+
+int stream_eof(stream_t *stream)
+{
+ return stream->eof;
+}
+
+void stream_create(stream_t *stream,struct codec_api* ci)
+{
+ stream->ci=ci;
+ stream->eof=0;
+}
+
+/* This function was part of the original alac decoder implementation */
+
+int get_sample_info(demux_res_t *demux_res, uint32_t samplenum,
+ uint32_t *sample_duration,
+ uint32_t *sample_byte_size)
+{
+ unsigned int duration_index_accum = 0;
+ unsigned int duration_cur_index = 0;
+
+ if (samplenum >= demux_res->num_sample_byte_sizes) {
+ return 0;
+ }
+
+ if (!demux_res->num_time_to_samples) {
+ return 0;
+ }
+
+ while ((demux_res->time_to_sample[duration_cur_index].sample_count
+ + duration_index_accum) <= samplenum) {
+ duration_index_accum +=
+ demux_res->time_to_sample[duration_cur_index].sample_count;
+
+ duration_cur_index++;
+ if (duration_cur_index >= demux_res->num_time_to_samples) {
+ return 0;
+ }
+ }
+
+ *sample_duration =
+ demux_res->time_to_sample[duration_cur_index].sample_duration;
+ *sample_byte_size = demux_res->sample_byte_size[samplenum];
+
+ return 1;
+}
+
+/* Seek to sample_loc (or close to it). Return 1 on success (and
+ modify samplesdone and currentblock), 0 if failed
+
+ Seeking uses the following two arrays:
+
+ 1) the sample_byte_size array contains the length in bytes of
+ each block ("sample" in Applespeak).
+
+ 2) the time_to_sample array contains the duration (in samples) of
+ each block of data.
+
+ So we just find the block number we are going to seek to (using
+ time_to_sample) and then find the offset in the file (using
+ sample_byte_size).
+
+ Each ALAC block seems to be independent of all the others.
+ */
+
+unsigned int alac_seek (demux_res_t* demux_res,
+ stream_t* stream,
+ unsigned int sample_loc,
+ uint32_t* samplesdone, int* currentblock)
+{
+ int flag;
+ unsigned int i,j;
+ unsigned int newblock;
+ unsigned int newsample;
+ unsigned int newpos;
+
+ /* First check we have the appropriate metadata - we should always
+ have it. */
+ if ((demux_res->num_time_to_samples==0) ||
+ (demux_res->num_sample_byte_sizes==0)) { return 0; }
+
+ /* Find the destination block from time_to_sample array */
+ i=0;
+ newblock=0;
+ newsample=0;
+ flag=0;
+
+ while ((i<demux_res->num_time_to_samples) && (flag==0) &&
+ (newsample < sample_loc)) {
+ j=(sample_loc-newsample) /
+ demux_res->time_to_sample[i].sample_duration;
+
+ if (j <= demux_res->time_to_sample[i].sample_count) {
+ newblock+=j;
+ newsample+=j*demux_res->time_to_sample[i].sample_duration;
+ flag=1;
+ } else {
+ newsample+=(demux_res->time_to_sample[i].sample_duration
+ * demux_res->time_to_sample[i].sample_count);
+ newblock+=demux_res->time_to_sample[i].sample_count;
+ i++;
+ }
+ }
+
+ /* We know the new block, now calculate the file position */
+ newpos=demux_res->mdat_offset;
+ for (i=0;i<newblock;i++) {
+ newpos+=demux_res->sample_byte_size[i];
+ }
+
+ /* We know the new file position, so let's try to seek to it */
+ if (stream->ci->seek_buffer(newpos)) {
+ *samplesdone=newsample;
+ *currentblock=newblock;
+ return 1;
+ } else {
+ return 0;
+ }
+}
diff --git a/apps/codecs/libm4a/m4a.h b/apps/codecs/libm4a/m4a.h
new file mode 100644
index 0000000000..98cf8d6acb
--- /dev/null
+++ b/apps/codecs/libm4a/m4a.h
@@ -0,0 +1,104 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 Dave Chapman
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#ifndef _M4A_H
+#define _M4A_H
+
+#include <codecs.h>
+#include <inttypes.h>
+
+typedef struct {
+ struct codec_api* ci;
+ int eof;
+} stream_t;
+
+typedef uint32_t fourcc_t;
+
+typedef struct
+{
+ uint16_t num_channels;
+ uint16_t sample_size;
+ uint32_t sample_rate;
+ fourcc_t format;
+ void *buf;
+
+ struct {
+ uint32_t sample_count;
+ uint32_t sample_duration;
+ } *time_to_sample;
+ uint32_t num_time_to_samples;
+
+ uint32_t *sample_byte_size;
+ uint32_t num_sample_byte_sizes;
+
+ uint32_t codecdata_len;
+ void *codecdata;
+
+ int mdat_offset;
+ uint32_t mdat_len;
+#if 0
+ void *mdat;
+#endif
+} demux_res_t;
+
+int qtmovie_read(stream_t *stream, demux_res_t *demux_res);
+
+#ifndef MAKEFOURCC
+#define MAKEFOURCC(ch0, ch1, ch2, ch3) ( \
+ ( (int32_t)(char)(ch0) << 24 ) | \
+ ( (int32_t)(char)(ch1) << 16 ) | \
+ ( (int32_t)(char)(ch2) << 8 ) | \
+ ( (int32_t)(char)(ch3) ) )
+#endif
+
+#ifndef SLPITFOURCC
+/* splits it into ch0, ch1, ch2, ch3 - use for printf's */
+#define SPLITFOURCC(code) \
+ (char)((int32_t)code >> 24), \
+ (char)((int32_t)code >> 16), \
+ (char)((int32_t)code >> 8), \
+ (char)code
+#endif
+
+void stream_read(stream_t *stream, size_t len, void *buf);
+
+int32_t stream_tell(stream_t *stream);
+int32_t stream_read_int32(stream_t *stream);
+uint32_t stream_read_uint32(stream_t *stream);
+
+int16_t stream_read_int16(stream_t *stream);
+uint16_t stream_read_uint16(stream_t *stream);
+
+int8_t stream_read_int8(stream_t *stream);
+uint8_t stream_read_uint8(stream_t *stream);
+
+void stream_skip(stream_t *stream, size_t skip);
+
+int stream_eof(stream_t *stream);
+
+void stream_create(stream_t *stream,struct codec_api* ci);
+int get_sample_info(demux_res_t *demux_res, uint32_t samplenum,
+ uint32_t *sample_duration,
+ uint32_t *sample_byte_size);
+unsigned int alac_seek (demux_res_t* demux_res,
+ stream_t* stream,
+ unsigned int sample_loc,
+ uint32_t* samplesdone, int* currentblock);
+
+#endif /* STREAM_H */
diff --git a/tools/configure b/tools/configure
index ad66ba8005..5f0310a83b 100755
--- a/tools/configure
+++ b/tools/configure
@@ -523,7 +523,7 @@ appsdir='\$(ROOTDIR)/apps'
archosrom=""
flash=""
plugins="yes"
- codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac"
+ codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libm4a"
;;
10)
@@ -537,7 +537,7 @@ appsdir='\$(ROOTDIR)/apps'
archosrom=""
flash=""
plugins="yes"
- codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac"
+ codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libm4a"
;;
11)
@@ -551,7 +551,7 @@ appsdir='\$(ROOTDIR)/apps'
archosrom=""
flash=""
plugins="yes"
- codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac"
+ codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libm4a"
;;
12)
@@ -565,7 +565,7 @@ appsdir='\$(ROOTDIR)/apps'
archosrom=""
flash=""
plugins="yes"
- codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac"
+ codecs="libmad liba52 libffmpegFLAC libTremor libwavpack dumb libmusepack libalac libm4a"
;;
*)