Mercurial > audlegacy-plugins
comparison src/Input/aac/mp4ff/mp4sample.c @ 0:13389e613d67 trunk
[svn] - initial import of audacious-plugins tree (lots to do)
| author | nenolod |
|---|---|
| date | Mon, 18 Sep 2006 01:11:49 -0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:13389e613d67 |
|---|---|
| 1 /* | |
| 2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
| 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com | |
| 4 ** | |
| 5 ** This program is free software; you can redistribute it and/or modify | |
| 6 ** it under the terms of the GNU General Public License as published by | |
| 7 ** the Free Software Foundation; either version 2 of the License, or | |
| 8 ** (at your option) any later version. | |
| 9 ** | |
| 10 ** This program is distributed in the hope that it will be useful, | |
| 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 ** GNU General Public License for more details. | |
| 14 ** | |
| 15 ** You should have received a copy of the GNU General Public License | |
| 16 ** along with this program; if not, write to the Free Software | |
| 17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 18 ** | |
| 19 ** Any non-GPL usage of this software or parts of this software is strictly | |
| 20 ** forbidden. | |
| 21 ** | |
| 22 ** Commercial non-GPL licensing of this software is possible. | |
| 23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | |
| 24 ** | |
| 25 ** $Id: mp4sample.c,v 1.15 2004/01/11 15:52:19 menno Exp $ | |
| 26 **/ | |
| 27 | |
| 28 #include <stdlib.h> | |
| 29 #include "mp4ffint.h" | |
| 30 | |
| 31 | |
| 32 int32_t mp4ff_chunk_of_sample(const mp4ff_t *f, const int32_t track, const int32_t sample, | |
| 33 int32_t *chunk_sample, int32_t *chunk) | |
| 34 { | |
| 35 int32_t total_entries = 0; | |
| 36 int32_t chunk2entry; | |
| 37 int32_t chunk1, chunk2, chunk1samples, range_samples, total = 0; | |
| 38 | |
| 39 if (f->track[track] == NULL) | |
| 40 { | |
| 41 return -1; | |
| 42 } | |
| 43 | |
| 44 total_entries = f->track[track]->stsc_entry_count; | |
| 45 | |
| 46 chunk1 = 1; | |
| 47 chunk1samples = 0; | |
| 48 chunk2entry = 0; | |
| 49 | |
| 50 do | |
| 51 { | |
| 52 chunk2 = f->track[track]->stsc_first_chunk[chunk2entry]; | |
| 53 *chunk = chunk2 - chunk1; | |
| 54 range_samples = *chunk * chunk1samples; | |
| 55 | |
| 56 if (sample < total + range_samples) break; | |
| 57 | |
| 58 chunk1samples = f->track[track]->stsc_samples_per_chunk[chunk2entry]; | |
| 59 chunk1 = chunk2; | |
| 60 | |
| 61 if(chunk2entry < total_entries) | |
| 62 { | |
| 63 chunk2entry++; | |
| 64 total += range_samples; | |
| 65 } | |
| 66 } while (chunk2entry < total_entries); | |
| 67 | |
| 68 if (chunk1samples) | |
| 69 *chunk = (sample - total) / chunk1samples + chunk1; | |
| 70 else | |
| 71 *chunk = 1; | |
| 72 | |
| 73 *chunk_sample = total + (*chunk - chunk1) * chunk1samples; | |
| 74 | |
| 75 return 0; | |
| 76 } | |
| 77 | |
| 78 int32_t mp4ff_chunk_to_offset(const mp4ff_t *f, const int32_t track, const int32_t chunk) | |
| 79 { | |
| 80 const mp4ff_track_t * p_track = f->track[track]; | |
| 81 | |
| 82 if (p_track->stco_entry_count && (chunk > p_track->stco_entry_count)) | |
| 83 { | |
| 84 return p_track->stco_chunk_offset[p_track->stco_entry_count - 1]; | |
| 85 } else if (p_track->stco_entry_count) { | |
| 86 return p_track->stco_chunk_offset[chunk - 1]; | |
| 87 } else { | |
| 88 return 8; | |
| 89 } | |
| 90 | |
| 91 return 0; | |
| 92 } | |
| 93 | |
| 94 int32_t mp4ff_sample_range_size(const mp4ff_t *f, const int32_t track, | |
| 95 const int32_t chunk_sample, const int32_t sample) | |
| 96 { | |
| 97 int32_t i, total; | |
| 98 const mp4ff_track_t * p_track = f->track[track]; | |
| 99 | |
| 100 if (p_track->stsz_sample_size) | |
| 101 { | |
| 102 return (sample - chunk_sample) * p_track->stsz_sample_size; | |
| 103 } | |
| 104 else | |
| 105 { | |
| 106 if (sample>=p_track->stsz_sample_count) return 0;//error | |
| 107 | |
| 108 for(i = chunk_sample, total = 0; i < sample; i++) | |
| 109 { | |
| 110 total += p_track->stsz_table[i]; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 return total; | |
| 115 } | |
| 116 | |
| 117 int32_t mp4ff_sample_to_offset(const mp4ff_t *f, const int32_t track, const int32_t sample) | |
| 118 { | |
| 119 int32_t chunk, chunk_sample, chunk_offset1, chunk_offset2; | |
| 120 | |
| 121 mp4ff_chunk_of_sample(f, track, sample, &chunk_sample, &chunk); | |
| 122 | |
| 123 chunk_offset1 = mp4ff_chunk_to_offset(f, track, chunk); | |
| 124 chunk_offset2 = chunk_offset1 + mp4ff_sample_range_size(f, track, chunk_sample, sample); | |
| 125 | |
| 126 return chunk_offset2; | |
| 127 } | |
| 128 | |
| 129 int32_t mp4ff_audio_frame_size(const mp4ff_t *f, const int32_t track, const int32_t sample) | |
| 130 { | |
| 131 int32_t bytes; | |
| 132 const mp4ff_track_t * p_track = f->track[track]; | |
| 133 | |
| 134 if (p_track->stsz_sample_size) | |
| 135 { | |
| 136 bytes = p_track->stsz_sample_size; | |
| 137 } else { | |
| 138 bytes = p_track->stsz_table[sample]; | |
| 139 } | |
| 140 | |
| 141 return bytes; | |
| 142 } | |
| 143 | |
| 144 int32_t mp4ff_set_sample_position(mp4ff_t *f, const int32_t track, const int32_t sample) | |
| 145 { | |
| 146 int32_t offset; | |
| 147 | |
| 148 offset = mp4ff_sample_to_offset(f, track, sample); | |
| 149 mp4ff_set_position(f, offset); | |
| 150 | |
| 151 return 0; | |
| 152 } |
