Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

80 lines
2.0KB

  1. #include "mov-internal.h"
  2. #include <stdlib.h>
  3. #include <assert.h>
  4. #include <errno.h>
  5. // 8.6.2 Sync Sample Box (p50)
  6. int mov_read_stss(struct mov_t* mov, const struct mov_box_t* box)
  7. {
  8. uint32_t i, entry_count;
  9. struct mov_stbl_t* stbl = &mov->track->stbl;
  10. mov_buffer_r8(&mov->io); /* version */
  11. mov_buffer_r24(&mov->io); /* flags */
  12. entry_count = mov_buffer_r32(&mov->io);
  13. assert(0 == stbl->stss_count && NULL == stbl->stss);
  14. if (stbl->stss_count < entry_count)
  15. {
  16. void* p = realloc(stbl->stss, sizeof(stbl->stss[0]) * entry_count);
  17. if (NULL == p) return -ENOMEM;
  18. stbl->stss = p;
  19. }
  20. stbl->stss_count = entry_count;
  21. for (i = 0; i < entry_count; i++)
  22. stbl->stss[i] = mov_buffer_r32(&mov->io); // uint32_t sample_number
  23. (void)box;
  24. return mov_buffer_error(&mov->io);
  25. }
  26. size_t mov_write_stss(const struct mov_t* mov)
  27. {
  28. uint64_t offset;
  29. uint64_t offset2;
  30. uint32_t size, i, j;
  31. const struct mov_sample_t* sample;
  32. const struct mov_track_t* track = mov->track;
  33. size = 12/* full box */ + 4/* entry count */;
  34. offset = mov_buffer_tell(&mov->io);
  35. mov_buffer_w32(&mov->io, 0); /* size */
  36. mov_buffer_write(&mov->io, "stss", 4);
  37. mov_buffer_w32(&mov->io, 0); /* version & flags */
  38. mov_buffer_w32(&mov->io, 0); /* entry count */
  39. for (i = 0, j = 0; i < track->sample_count; i++)
  40. {
  41. sample = &track->samples[i];
  42. if (sample->flags & MOV_AV_FLAG_KEYFREAME)
  43. {
  44. ++j;
  45. mov_buffer_w32(&mov->io, i + 1); // start from 1
  46. }
  47. }
  48. size += j * 4/* entry */;
  49. offset2 = mov_buffer_tell(&mov->io);
  50. mov_buffer_seek(&mov->io, offset);
  51. mov_buffer_w32(&mov->io, size); /* size */
  52. mov_buffer_seek(&mov->io, offset + 12);
  53. mov_buffer_w32(&mov->io, j); /* entry count */
  54. mov_buffer_seek(&mov->io, offset2);
  55. return size;
  56. }
  57. void mov_apply_stss(struct mov_track_t* track)
  58. {
  59. size_t i, j;
  60. struct mov_stbl_t* stbl = &track->stbl;
  61. for (i = 0; i < stbl->stss_count; i++)
  62. {
  63. j = stbl->stss[i]; // start from 1
  64. if (j > 0 && j <= track->sample_count)
  65. track->samples[j - 1].flags |= MOV_AV_FLAG_KEYFREAME;
  66. }
  67. }