| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | #include <stdlib.h> |
| 32 | #include "mp4ffint.h" |
| 33 | |
| 34 | |
| 35 | int32_t mp4ff_chunk_of_sample(const mp4ff_t *f, const int32_t track, const int32_t sample, |
| 36 | int32_t *chunk_sample, int32_t *chunk) |
| 37 | { |
| 38 | int32_t total_entries = 0; |
| 39 | int32_t chunk2entry; |
| 40 | int32_t chunk1, chunk2, chunk1samples, range_samples, total = 0; |
| 41 | |
| 42 | if (f->track[track] == NULL((void*)0)) |
| |
| 43 | { |
| 44 | return -1; |
| 45 | } |
| 46 | |
| 47 | total_entries = f->track[track]->stsc_entry_count; |
| 48 | |
| 49 | chunk1 = 1; |
| 50 | chunk1samples = 0; |
| 51 | chunk2entry = 0; |
| 52 | |
| 53 | do |
| 54 | { |
| 55 | chunk2 = f->track[track]->stsc_first_chunk[chunk2entry]; |
| 56 | *chunk = chunk2 - chunk1; |
| 57 | range_samples = *chunk * chunk1samples; |
| 58 | |
| 59 | if (sample < total + range_samples) break; |
| 60 | |
| 61 | chunk1samples = f->track[track]->stsc_samples_per_chunk[chunk2entry]; |
| 62 | chunk1 = chunk2; |
| 63 | |
| 64 | if(chunk2entry < total_entries) |
| 65 | { |
| 66 | chunk2entry++; |
| 67 | total += range_samples; |
| 68 | } |
| 69 | } while (chunk2entry < total_entries); |
| 70 | |
| 71 | if (chunk1samples) |
| 72 | *chunk = (sample - total) / chunk1samples + chunk1; |
| 73 | else |
| 74 | *chunk = 1; |
| 75 | |
| 76 | *chunk_sample = total + (*chunk - chunk1) * chunk1samples; |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | int32_t mp4ff_chunk_to_offset(const mp4ff_t *f, const int32_t track, const int32_t chunk) |
| 82 | { |
| 83 | const mp4ff_track_t * p_track = f->track[track]; |
| 84 | |
| 85 | if (p_track->stco_entry_count && (chunk > p_track->stco_entry_count)) |
| 86 | { |
| 87 | return p_track->stco_chunk_offset[p_track->stco_entry_count - 1]; |
| 88 | } else if (p_track->stco_entry_count) { |
| 89 | return p_track->stco_chunk_offset[chunk - 1]; |
| 90 | } else { |
| 91 | return 8; |
| 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | int32_t mp4ff_sample_range_size(const mp4ff_t *f, const int32_t track, |
| 98 | const int32_t chunk_sample, const int32_t sample) |
| 99 | { |
| 100 | int32_t i, total; |
| 101 | const mp4ff_track_t * p_track = f->track[track]; |
| 102 | |
| 103 | if (p_track->stsz_sample_size) |
| 104 | { |
| 105 | return (sample - chunk_sample) * p_track->stsz_sample_size; |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | if (sample>=p_track->stsz_sample_count) return 0; |
| 110 | |
| 111 | for(i = chunk_sample, total = 0; i < sample; i++) |
| 112 | { |
| 113 | total += p_track->stsz_table[i]; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | return total; |
| 118 | } |
| 119 | |
| 120 | int32_t mp4ff_sample_to_offset(const mp4ff_t *f, const int32_t track, const int32_t sample) |
| 121 | { |
| 122 | int32_t chunk, chunk_sample, chunk_offset1, chunk_offset2; |
| 2 | | 'chunk' declared without an initial value | |
|
| 123 | |
| 124 | mp4ff_chunk_of_sample(f, track, sample, &chunk_sample, &chunk); |
| 3 | | Calling 'mp4ff_chunk_of_sample' | |
|
| 5 | | Returning from 'mp4ff_chunk_of_sample' | |
|
| 125 | |
| 126 | chunk_offset1 = mp4ff_chunk_to_offset(f, track, chunk); |
| 6 | | Function call argument is an uninitialized value |
|
| 127 | chunk_offset2 = chunk_offset1 + mp4ff_sample_range_size(f, track, chunk_sample, sample); |
| 128 | |
| 129 | return chunk_offset2; |
| 130 | } |
| 131 | |
| 132 | int32_t mp4ff_audio_frame_size(const mp4ff_t *f, const int32_t track, const int32_t sample) |
| 133 | { |
| 134 | int32_t bytes; |
| 135 | const mp4ff_track_t * p_track = f->track[track]; |
| 136 | |
| 137 | if (p_track->stsz_sample_size) |
| 138 | { |
| 139 | bytes = p_track->stsz_sample_size; |
| 140 | } else { |
| 141 | bytes = p_track->stsz_table[sample]; |
| 142 | } |
| 143 | |
| 144 | return bytes; |
| 145 | } |
| 146 | |
| 147 | int32_t mp4ff_set_sample_position(mp4ff_t *f, const int32_t track, const int32_t sample) |
| 148 | { |
| 149 | int32_t offset; |
| 150 | |
| 151 | offset = mp4ff_sample_to_offset(f, track, sample); |
| 1 | Calling 'mp4ff_sample_to_offset' | |
|
| 152 | mp4ff_set_position(f, offset); |
| 153 | |
| 154 | return 0; |
| 155 | } |