Rework m4a seek/resume code. Seek/resume does now also work properly with files havin...
[kugel-rb.git] / apps / codecs / libm4a / m4a.h
blob2b361e8784cda6ade434a9c21e06e0e0d4da9016
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Dave Chapman
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef _M4A_H
23 #define _M4A_H
25 #include <codecs.h>
26 #include <inttypes.h>
28 /* AAC codecdata appears to always be less than 8 bytes - see
29 AudioSpecificConfig2 in libfaad/mp4.c
31 ALAC codecdata appears to always be 44 bytes (see alac_set_info in
32 libalac/alac.c) but my test file contains 56 bytes.
34 So we go safe and round up to 64 bytes - if we find more than this,
35 we give an error (even though we could possibly continue), so we
36 can increase this buffer.
39 #define MAX_CODECDATA_SIZE 64
41 typedef struct {
42 struct codec_api* ci;
43 int eof;
44 } stream_t;
46 typedef uint32_t fourcc_t;
48 typedef struct
50 uint32_t first_chunk;
51 uint32_t num_samples;
52 } sample_to_chunk_t;
54 typedef struct
56 uint32_t sample_count;
57 uint32_t sample_duration;
58 } time_to_sample_t;
60 typedef struct
62 uint16_t num_channels;
63 uint16_t sound_sample_size;
64 uint32_t sound_sample_rate;
65 fourcc_t format;
66 void *buf;
68 sample_to_chunk_t *sample_to_chunk;
69 uint32_t num_sample_to_chunks;
71 uint32_t *chunk_offset;
72 uint32_t num_chunk_offsets;
74 time_to_sample_t *time_to_sample;
75 uint32_t num_time_to_samples;
77 uint16_t *sample_byte_size;
78 uint32_t num_sample_byte_sizes;
80 uint32_t codecdata_len;
81 uint8_t codecdata[MAX_CODECDATA_SIZE];
83 int mdat_offset;
84 uint32_t mdat_len;
85 #if 0
86 void *mdat;
87 #endif
88 } demux_res_t;
90 int qtmovie_read(stream_t *stream, demux_res_t *demux_res);
92 #ifndef MAKEFOURCC
93 #define MAKEFOURCC(ch0, ch1, ch2, ch3) ( \
94 ( (int32_t)(char)(ch0) << 24 ) | \
95 ( (int32_t)(char)(ch1) << 16 ) | \
96 ( (int32_t)(char)(ch2) << 8 ) | \
97 ( (int32_t)(char)(ch3) ) )
98 #endif
100 #ifndef SLPITFOURCC
101 /* splits it into ch0, ch1, ch2, ch3 - use for printf's */
102 #define SPLITFOURCC(code) \
103 (char)((int32_t)code >> 24), \
104 (char)((int32_t)code >> 16), \
105 (char)((int32_t)code >> 8), \
106 (char)code
107 #endif
109 void stream_read(stream_t *stream, size_t len, void *buf);
111 int32_t stream_tell(stream_t *stream);
112 int32_t stream_read_int32(stream_t *stream);
113 uint32_t stream_read_uint32(stream_t *stream);
115 int16_t stream_read_int16(stream_t *stream);
116 uint16_t stream_read_uint16(stream_t *stream);
118 int8_t stream_read_int8(stream_t *stream);
119 uint8_t stream_read_uint8(stream_t *stream);
121 void stream_skip(stream_t *stream, size_t skip);
122 void stream_seek(stream_t *stream, size_t offset);
124 int stream_eof(stream_t *stream);
126 void stream_create(stream_t *stream,struct codec_api* ci);
127 int get_sample_info(demux_res_t *demux_res, uint32_t sample,
128 uint32_t *sample_duration, uint32_t *sample_byte_size);
129 unsigned int get_sample_offset(demux_res_t *demux_res, uint32_t sample);
130 unsigned int alac_seek (demux_res_t* demux_res, stream_t* stream,
131 uint32_t sound_sample_loc, uint32_t* sound_samples_done,
132 int* current_sample);
133 unsigned int alac_seek_raw (demux_res_t* demux_res, stream_t* stream,
134 uint32_t file_loc, uint32_t* sound_samples_done, int* current_sample);
136 #endif /* STREAM_H */