No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

88 líneas
2.7KB

  1. #include "mov-internal.h"
  2. #include <stdlib.h>
  3. #include <assert.h>
  4. #include <errno.h>
  5. // 8.8.10 Track Fragment Random Access Box (p74)
  6. int mov_read_tfra(struct mov_t* mov, const struct mov_box_t* box)
  7. {
  8. unsigned int version;
  9. uint32_t track_ID;
  10. uint32_t length_size_of;
  11. uint32_t i, j, number_of_entry;
  12. uint32_t traf_number, trun_number, sample_number;
  13. struct mov_track_t* track;
  14. version = mov_buffer_r8(&mov->io); /* version */
  15. mov_buffer_r24(&mov->io); /* flags */
  16. track_ID = mov_buffer_r32(&mov->io); /* track_ID */
  17. track = mov_find_track(mov, track_ID);
  18. if (NULL == track)
  19. return -1;
  20. length_size_of = mov_buffer_r32(&mov->io); /* length_size_of XXX */
  21. number_of_entry = mov_buffer_r32(&mov->io); /* number_of_entry */
  22. if (number_of_entry > 0)
  23. {
  24. void* p = realloc(track->frags, sizeof(struct mov_fragment_t) * number_of_entry);
  25. if (!p) return -ENOMEM;
  26. track->frags = p;
  27. }
  28. track->frag_count = number_of_entry;
  29. for (i = 0; i < number_of_entry; i++)
  30. {
  31. if (1 == version)
  32. {
  33. track->frags[i].time = mov_buffer_r64(&mov->io); /* time */
  34. track->frags[i].offset = mov_buffer_r64(&mov->io); /* moof_offset */
  35. }
  36. else
  37. {
  38. track->frags[i].time = mov_buffer_r32(&mov->io); /* time */
  39. track->frags[i].offset = mov_buffer_r32(&mov->io); /* moof_offset */
  40. }
  41. for (traf_number = 0, j = 0; j < ((length_size_of >> 4) & 0x03) + 1; j++)
  42. traf_number = (traf_number << 8) | mov_buffer_r8(&mov->io); /* traf_number */
  43. for (trun_number = 0, j = 0; j < ((length_size_of >> 2) & 0x03) + 1; j++)
  44. trun_number = (trun_number << 8) | mov_buffer_r8(&mov->io); /* trun_number */
  45. for (sample_number = 0, j = 0; j < (length_size_of & 0x03) + 1; j++)
  46. sample_number = (sample_number << 8) | mov_buffer_r8(&mov->io); /* sample_number */
  47. }
  48. (void)box;
  49. return mov_buffer_error(&mov->io);
  50. }
  51. size_t mov_write_tfra(const struct mov_t* mov)
  52. {
  53. uint32_t i, size;
  54. const struct mov_track_t* track = mov->track;
  55. size = 12/* full box */ + 12/* base */ + track->frag_count * 19/* index */;
  56. mov_buffer_w32(&mov->io, size); /* size */
  57. mov_buffer_write(&mov->io, "tfra", 4);
  58. mov_buffer_w8(&mov->io, 1); /* version */
  59. mov_buffer_w24(&mov->io, 0); /* flags */
  60. mov_buffer_w32(&mov->io, track->tkhd.track_ID); /* track_ID */
  61. mov_buffer_w32(&mov->io, 0); /* length_size_of_traf_num/trun/sample */
  62. mov_buffer_w32(&mov->io, track->frag_count); /* number_of_entry */
  63. for (i = 0; i < track->frag_count; i++)
  64. {
  65. mov_buffer_w64(&mov->io, track->frags[i].time);
  66. mov_buffer_w64(&mov->io, track->frags[i].offset); /* moof_offset */
  67. mov_buffer_w8(&mov->io, 1); /* traf number */
  68. mov_buffer_w8(&mov->io, 1); /* trun number */
  69. mov_buffer_w8(&mov->io, 1); /* sample number */
  70. }
  71. return size;
  72. }