blob: e2d4376d12899e05269121570db0229ffc7ec1a5 [file] [log] [blame]
Dave Chapman45f9e5d2005-10-29 17:12:52 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Dave Chapman
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Dave Chapman45f9e5d2005-10-29 17:12:52 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _M4A_H
23#define _M4A_H
24
25#include <codecs.h>
26#include <inttypes.h>
27
Dave Chapmanaaacb702007-12-01 01:01:35 +000028/* AAC codecdata appears to always be less than 8 bytes - see
29 AudioSpecificConfig2 in libfaad/mp4.c
30
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.
33
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.
37*/
38
39#define MAX_CODECDATA_SIZE 64
40
Dave Chapman45f9e5d2005-10-29 17:12:52 +000041typedef struct {
42 struct codec_api* ci;
43 int eof;
44} stream_t;
45
46typedef uint32_t fourcc_t;
47
48typedef struct
49{
50 uint16_t num_channels;
Magnus Holmgren9896fd12006-10-11 17:02:23 +000051 uint16_t sound_sample_size;
52 uint32_t sound_sample_rate;
Dave Chapman45f9e5d2005-10-29 17:12:52 +000053 fourcc_t format;
54 void *buf;
55
56 struct {
Magnus Holmgren9896fd12006-10-11 17:02:23 +000057 uint32_t first_chunk;
58 uint32_t num_samples;
59 } *sample_to_chunk;
60 uint32_t num_sample_to_chunks;
61
62 uint32_t *chunk_offset;
63 uint32_t num_chunk_offsets;
64
65 struct {
Dave Chapman45f9e5d2005-10-29 17:12:52 +000066 uint32_t sample_count;
67 uint32_t sample_duration;
68 } *time_to_sample;
69 uint32_t num_time_to_samples;
70
Magnus Holmgren38ec5ed2006-11-08 19:54:08 +000071 uint16_t *sample_byte_size;
Dave Chapman45f9e5d2005-10-29 17:12:52 +000072 uint32_t num_sample_byte_sizes;
73
74 uint32_t codecdata_len;
Dave Chapmanaaacb702007-12-01 01:01:35 +000075 uint8_t codecdata[MAX_CODECDATA_SIZE];
Dave Chapman45f9e5d2005-10-29 17:12:52 +000076
77 int mdat_offset;
78 uint32_t mdat_len;
79#if 0
80 void *mdat;
81#endif
82} demux_res_t;
83
84int qtmovie_read(stream_t *stream, demux_res_t *demux_res);
85
86#ifndef MAKEFOURCC
87#define MAKEFOURCC(ch0, ch1, ch2, ch3) ( \
88 ( (int32_t)(char)(ch0) << 24 ) | \
89 ( (int32_t)(char)(ch1) << 16 ) | \
90 ( (int32_t)(char)(ch2) << 8 ) | \
91 ( (int32_t)(char)(ch3) ) )
92#endif
93
94#ifndef SLPITFOURCC
95/* splits it into ch0, ch1, ch2, ch3 - use for printf's */
96#define SPLITFOURCC(code) \
97 (char)((int32_t)code >> 24), \
98 (char)((int32_t)code >> 16), \
99 (char)((int32_t)code >> 8), \
100 (char)code
101#endif
102
103void stream_read(stream_t *stream, size_t len, void *buf);
104
105int32_t stream_tell(stream_t *stream);
106int32_t stream_read_int32(stream_t *stream);
107uint32_t stream_read_uint32(stream_t *stream);
108
109int16_t stream_read_int16(stream_t *stream);
110uint16_t stream_read_uint16(stream_t *stream);
111
112int8_t stream_read_int8(stream_t *stream);
113uint8_t stream_read_uint8(stream_t *stream);
114
115void stream_skip(stream_t *stream, size_t skip);
116
117int stream_eof(stream_t *stream);
118
119void stream_create(stream_t *stream,struct codec_api* ci);
Magnus Holmgren9896fd12006-10-11 17:02:23 +0000120int get_sample_info(demux_res_t *demux_res, uint32_t sample,
121 uint32_t *sample_duration, uint32_t *sample_byte_size);
122unsigned int get_sample_offset(demux_res_t *demux_res, uint32_t sample);
123unsigned int alac_seek (demux_res_t* demux_res, stream_t* stream,
124 uint32_t sound_sample_loc, uint32_t* sound_samples_done,
125 int* current_sample);
126unsigned int alac_seek_raw (demux_res_t* demux_res, stream_t* stream,
127 uint32_t file_loc, uint32_t* sound_samples_done, int* current_sample);
Dave Chapman45f9e5d2005-10-29 17:12:52 +0000128
129#endif /* STREAM_H */