Dave Chapman | 45f9e5d | 2005-10-29 17:12:52 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2005 Dave Chapman |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Dave Chapman | 45f9e5d | 2005-10-29 17:12:52 +0000 | [diff] [blame] | 16 | * |
| 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 Chapman | aaacb70 | 2007-12-01 01:01:35 +0000 | [diff] [blame] | 28 | /* 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 Chapman | 45f9e5d | 2005-10-29 17:12:52 +0000 | [diff] [blame] | 41 | typedef struct { |
| 42 | struct codec_api* ci; |
| 43 | int eof; |
| 44 | } stream_t; |
| 45 | |
| 46 | typedef uint32_t fourcc_t; |
| 47 | |
| 48 | typedef struct |
| 49 | { |
| 50 | uint16_t num_channels; |
Magnus Holmgren | 9896fd1 | 2006-10-11 17:02:23 +0000 | [diff] [blame] | 51 | uint16_t sound_sample_size; |
| 52 | uint32_t sound_sample_rate; |
Dave Chapman | 45f9e5d | 2005-10-29 17:12:52 +0000 | [diff] [blame] | 53 | fourcc_t format; |
| 54 | void *buf; |
| 55 | |
| 56 | struct { |
Magnus Holmgren | 9896fd1 | 2006-10-11 17:02:23 +0000 | [diff] [blame] | 57 | 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 Chapman | 45f9e5d | 2005-10-29 17:12:52 +0000 | [diff] [blame] | 66 | uint32_t sample_count; |
| 67 | uint32_t sample_duration; |
| 68 | } *time_to_sample; |
| 69 | uint32_t num_time_to_samples; |
| 70 | |
Magnus Holmgren | 38ec5ed | 2006-11-08 19:54:08 +0000 | [diff] [blame] | 71 | uint16_t *sample_byte_size; |
Dave Chapman | 45f9e5d | 2005-10-29 17:12:52 +0000 | [diff] [blame] | 72 | uint32_t num_sample_byte_sizes; |
| 73 | |
| 74 | uint32_t codecdata_len; |
Dave Chapman | aaacb70 | 2007-12-01 01:01:35 +0000 | [diff] [blame] | 75 | uint8_t codecdata[MAX_CODECDATA_SIZE]; |
Dave Chapman | 45f9e5d | 2005-10-29 17:12:52 +0000 | [diff] [blame] | 76 | |
| 77 | int mdat_offset; |
| 78 | uint32_t mdat_len; |
| 79 | #if 0 |
| 80 | void *mdat; |
| 81 | #endif |
| 82 | } demux_res_t; |
| 83 | |
| 84 | int 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 | |
| 103 | void stream_read(stream_t *stream, size_t len, void *buf); |
| 104 | |
| 105 | int32_t stream_tell(stream_t *stream); |
| 106 | int32_t stream_read_int32(stream_t *stream); |
| 107 | uint32_t stream_read_uint32(stream_t *stream); |
| 108 | |
| 109 | int16_t stream_read_int16(stream_t *stream); |
| 110 | uint16_t stream_read_uint16(stream_t *stream); |
| 111 | |
| 112 | int8_t stream_read_int8(stream_t *stream); |
| 113 | uint8_t stream_read_uint8(stream_t *stream); |
| 114 | |
| 115 | void stream_skip(stream_t *stream, size_t skip); |
| 116 | |
| 117 | int stream_eof(stream_t *stream); |
| 118 | |
| 119 | void stream_create(stream_t *stream,struct codec_api* ci); |
Magnus Holmgren | 9896fd1 | 2006-10-11 17:02:23 +0000 | [diff] [blame] | 120 | int get_sample_info(demux_res_t *demux_res, uint32_t sample, |
| 121 | uint32_t *sample_duration, uint32_t *sample_byte_size); |
| 122 | unsigned int get_sample_offset(demux_res_t *demux_res, uint32_t sample); |
| 123 | unsigned 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); |
| 126 | unsigned 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 Chapman | 45f9e5d | 2005-10-29 17:12:52 +0000 | [diff] [blame] | 128 | |
| 129 | #endif /* STREAM_H */ |