You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4KB

  1. #include "mov-internal.h"
  2. #include <errno.h>
  3. #include <stdint.h>
  4. #include <stdlib.h>
  5. #include <assert.h>
  6. // 8.8.12 Track fragment decode time (p76)
  7. int mov_read_tfdt(struct mov_t* mov, const struct mov_box_t* box)
  8. {
  9. unsigned int version;
  10. version = mov_buffer_r8(&mov->io); /* version */
  11. mov_buffer_r24(&mov->io); /* flags */
  12. if (1 == version)
  13. mov->track->tfdt_dts = mov_buffer_r64(&mov->io); /* baseMediaDecodeTime */
  14. else
  15. mov->track->tfdt_dts = mov_buffer_r32(&mov->io); /* baseMediaDecodeTime */
  16. // baseMediaDecodeTime + ELST start offset
  17. mov_apply_elst_tfdt(mov->track);
  18. (void)box;
  19. return mov_buffer_error(&mov->io);
  20. }
  21. size_t mov_write_tfdt(const struct mov_t* mov)
  22. {
  23. uint8_t version;
  24. uint64_t baseMediaDecodeTime;
  25. if (mov->track->sample_count < 1)
  26. return 0;
  27. baseMediaDecodeTime = mov->track->samples[0].dts - mov->track->start_dts;
  28. version = baseMediaDecodeTime > INT32_MAX ? 1 : 0;
  29. mov_buffer_w32(&mov->io, 0 == version ? 16 : 20); /* size */
  30. mov_buffer_write(&mov->io, "tfdt", 4);
  31. mov_buffer_w8(&mov->io, version); /* version */
  32. mov_buffer_w24(&mov->io, 0); /* flags */
  33. if (1 == version)
  34. mov_buffer_w64(&mov->io, baseMediaDecodeTime); /* baseMediaDecodeTime */
  35. else
  36. mov_buffer_w32(&mov->io, (uint32_t)baseMediaDecodeTime); /* baseMediaDecodeTime */
  37. return 0 == version ? 16 : 20;
  38. }