// 8.7.3.2 Sample Size Box (p57) int mov_read_stsz(struct mov_t* mov, const struct mov_box_t* box) { uint32_t i = 0, sample_size, sample_count; struct mov_track_t* track = mov->track; mov_buffer_r8(&mov->io); /* version */ mov_buffer_r24(&mov->io); /* flags */ sample_size = mov_buffer_r32(&mov->io); sample_count = mov_buffer_r32(&mov->io); assert(0 == track->sample_count && NULL == track->samples); // duplicated STSZ atom if (track->sample_count < sample_count) { void* p = malloc(sizeof(struct mov_sample_t) * (sample_count + 1)); if (NULL == p) return ENOMEM; track->samples = (struct mov_sample_t*)p; } track->sample_count = sample_count; if (0 == sample_size) { for (i = 0; i < sample_count; i++) track->samples[i].bytes = mov_buffer_r32(&mov->io); // uint32_t entry_size } else { for (i = 0; i < sample_count; i++) track->samples[i].bytes = sample_size; } (void)box; return mov_buffer_error(&mov->io); }
// 8.6.1.2 Decoding Time to Sample Box (p47) int mov_read_stts(struct mov_t* mov, const struct mov_box_t* box) { uint32_t i, entry_count; struct mov_stbl_t* stbl = &mov->track->stbl; mov_buffer_r8(&mov->io); /* version */ mov_buffer_r24(&mov->io); /* flags */ entry_count = mov_buffer_r32(&mov->io); assert(0 == stbl->stts_count && NULL == stbl->stts); // duplicated STTS atom if (stbl->stts_count < entry_count) { void* p = realloc(stbl->stts, sizeof(struct mov_stts_t) * entry_count); if (NULL == p) return ENOMEM; stbl->stts = (struct mov_stts_t*)p; } stbl->stts_count = entry_count; for (i = 0; i < entry_count; i++) { stbl->stts[i].sample_count = mov_buffer_r32(&mov->io); stbl->stts[i].sample_delta = mov_buffer_r32(&mov->io); } (void)box; return mov_buffer_error(&mov->io); }
// 8.6.1.4 Composition to Decode Box (p53) int mov_read_cslg(struct mov_t* mov, const struct mov_box_t* box) { uint8_t version; // struct mov_stbl_t* stbl = &mov->track->stbl; version = (uint8_t)mov_buffer_r8(&mov->io); /* version */ mov_buffer_r24(&mov->io); /* flags */ if (0 == version) { (int32_t)mov_buffer_r32(&mov->io); /* compositionToDTSShift */ (int32_t)mov_buffer_r32(&mov->io); /* leastDecodeToDisplayDelta */ (int32_t)mov_buffer_r32(&mov->io); /* greatestDecodeToDisplayDelta */ (int32_t)mov_buffer_r32(&mov->io); /* compositionStartTime */ (int32_t)mov_buffer_r32(&mov->io); /* compositionEndTime */ } else { (int64_t)mov_buffer_r64(&mov->io); (int64_t)mov_buffer_r64(&mov->io); (int64_t)mov_buffer_r64(&mov->io); (int64_t)mov_buffer_r64(&mov->io); (int64_t)mov_buffer_r64(&mov->io); } (void)box; return mov_buffer_error(&mov->io); }
// 8.8.2 Movie Extends Header Box (p68) int mov_read_mehd(struct mov_t* mov, const struct mov_box_t* box) { unsigned int version; uint64_t fragment_duration; version = mov_buffer_r8(&mov->io); /* version */ mov_buffer_r24(&mov->io); /* flags */ if (1 == version) fragment_duration = mov_buffer_r64(&mov->io); /* fragment_duration*/ else fragment_duration = mov_buffer_r32(&mov->io); /* fragment_duration*/ (void)box; assert(fragment_duration <= mov->mvhd.duration); return mov_buffer_error(&mov->io); }
// 8.7.3.3 Compact Sample Size Box (p57) int mov_read_stz2(struct mov_t* mov, const struct mov_box_t* box) { uint32_t i, v, field_size, sample_count; struct mov_track_t* track = mov->track; mov_buffer_r8(&mov->io); /* version */ mov_buffer_r24(&mov->io); /* flags */ // unsigned int(24) reserved = 0; mov_buffer_r24(&mov->io); /* reserved */ field_size = mov_buffer_r8(&mov->io); sample_count = mov_buffer_r32(&mov->io); assert(4 == field_size || 8 == field_size || 16 == field_size); assert(0 == track->sample_count && NULL == track->samples); // duplicated STSZ atom if (track->sample_count < sample_count) { void* p = malloc(sizeof(struct mov_sample_t) * (sample_count + 1)); if (NULL == p) return ENOMEM; track->samples = (struct mov_sample_t*)p; } track->sample_count = sample_count; if (4 == field_size) { for (i = 0; i < sample_count/2; i++) { v = mov_buffer_r8(&mov->io); track->samples[i * 2].bytes = (v >> 4) & 0x0F; track->samples[i * 2 + 1].bytes = v & 0x0F; } if (sample_count % 2) { v = mov_buffer_r8(&mov->io); track->samples[i * 2].bytes = (v >> 4) & 0x0F; } }