Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

74 řádky
2.3KB

  1. #include "mov-internal.h"
  2. #include <assert.h>
  3. // 8.16.3 Segment Index Box (p119)
  4. int mov_read_sidx(struct mov_t* mov, const struct mov_box_t* box)
  5. {
  6. unsigned int version;
  7. unsigned int i, reference_count;
  8. version = mov_buffer_r8(&mov->io); /* version */
  9. mov_buffer_r24(&mov->io); /* flags */
  10. mov_buffer_r32(&mov->io); /* reference_ID */
  11. mov_buffer_r32(&mov->io); /* timescale */
  12. if (0 == version)
  13. {
  14. mov_buffer_r32(&mov->io); /* earliest_presentation_time */
  15. mov_buffer_r32(&mov->io); /* first_offset */
  16. }
  17. else
  18. {
  19. mov_buffer_r64(&mov->io); /* earliest_presentation_time */
  20. mov_buffer_r64(&mov->io); /* first_offset */
  21. }
  22. mov_buffer_r16(&mov->io); /* reserved */
  23. reference_count = mov_buffer_r16(&mov->io); /* reference_count */
  24. for (i = 0; i < reference_count; i++)
  25. {
  26. mov_buffer_r32(&mov->io); /* reference_type & referenced_size */
  27. mov_buffer_r32(&mov->io); /* subsegment_duration */
  28. mov_buffer_r32(&mov->io); /* starts_with_SAP & SAP_type & SAP_delta_time */
  29. }
  30. (void)box;
  31. return mov_buffer_error(&mov->io);
  32. }
  33. size_t mov_write_sidx(const struct mov_t* mov, uint64_t offset)
  34. {
  35. uint32_t duration;
  36. uint64_t earliest_presentation_time;
  37. const struct mov_track_t* track = mov->track;
  38. if (track->sample_count > 0)
  39. {
  40. earliest_presentation_time = track->samples[0].pts;
  41. duration = (uint32_t)(track->samples[track->sample_count - 1].dts - track->samples[0].dts) + (uint32_t)track->turn_last_duration;
  42. }
  43. else
  44. {
  45. duration = 0;
  46. earliest_presentation_time = 0;
  47. }
  48. mov_buffer_w32(&mov->io, 52); /* size */
  49. mov_buffer_write(&mov->io, "sidx", 4);
  50. mov_buffer_w8(&mov->io, 1); /* version */
  51. mov_buffer_w24(&mov->io, 0); /* flags */
  52. mov_buffer_w32(&mov->io, track->tkhd.track_ID); /* reference_ID */
  53. mov_buffer_w32(&mov->io, track->mdhd.timescale); /* timescale */
  54. mov_buffer_w64(&mov->io, earliest_presentation_time); /* earliest_presentation_time */
  55. mov_buffer_w64(&mov->io, offset); /* first_offset */
  56. mov_buffer_w16(&mov->io, 0); /* reserved */
  57. mov_buffer_w16(&mov->io, 1); /* reference_count */
  58. mov_buffer_w32(&mov->io, 0); /* reference_type & referenced_size */
  59. mov_buffer_w32(&mov->io, duration); /* subsegment_duration */
  60. mov_buffer_w32(&mov->io, (1U/*starts_with_SAP*/ << 31) | (1 /*SAP_type*/ << 28) | 0 /*SAP_delta_time*/);
  61. return 52;
  62. }