moov.c
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:3k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. #include "quicktime.h"
  2. int quicktime_moov_init(quicktime_moov_t *moov)
  3. {
  4. int i;
  5. moov->total_tracks = 0;
  6. for(i = 0 ; i < MAXTRACKS; i++) moov->trak[i] = 0;
  7. quicktime_mvhd_init(&(moov->mvhd));
  8. quicktime_iods_init(&(moov->iods));
  9. quicktime_udta_init(&(moov->udta));
  10. quicktime_ctab_init(&(moov->ctab));
  11. return 0;
  12. }
  13. int quicktime_moov_delete(quicktime_moov_t *moov)
  14. {
  15. int i;
  16. while(moov->total_tracks) {
  17. quicktime_delete_trak(moov, moov->trak[moov->total_tracks - 1]);
  18. }
  19. quicktime_mvhd_delete(&(moov->mvhd));
  20. quicktime_iods_delete(&(moov->iods));
  21. quicktime_udta_delete(&(moov->udta));
  22. quicktime_ctab_delete(&(moov->ctab));
  23. return 0;
  24. }
  25. int quicktime_moov_dump(quicktime_moov_t *moov)
  26. {
  27. int i;
  28. printf("movien");
  29. quicktime_mvhd_dump(&(moov->mvhd));
  30. quicktime_iods_dump(&(moov->iods));
  31. quicktime_udta_dump(&(moov->udta));
  32. for(i = 0; i < moov->total_tracks; i++)
  33. quicktime_trak_dump(moov->trak[i]);
  34. quicktime_ctab_dump(&(moov->ctab));
  35. }
  36. int quicktime_read_moov(quicktime_t *file, quicktime_moov_t *moov, quicktime_atom_t *parent_atom)
  37. {
  38. /* mandatory mvhd */
  39. quicktime_atom_t leaf_atom;
  40. do
  41. {
  42. quicktime_atom_read_header(file, &leaf_atom);
  43. if(quicktime_atom_is(&leaf_atom, "mvhd"))
  44. {
  45. quicktime_read_mvhd(file, &(moov->mvhd));
  46. }
  47. else
  48. if(quicktime_atom_is(&leaf_atom, "iods"))
  49. {
  50. quicktime_read_iods(file, &(moov->iods));
  51. quicktime_atom_skip(file, &leaf_atom);
  52. }
  53. else
  54. if(quicktime_atom_is(&leaf_atom, "clip"))
  55. {
  56. quicktime_atom_skip(file, &leaf_atom);
  57. }
  58. else
  59. if(quicktime_atom_is(&leaf_atom, "trak"))
  60. {
  61. quicktime_trak_t *trak = quicktime_add_trak(moov);
  62. quicktime_read_trak(file, trak, &leaf_atom);
  63. }
  64. else
  65. if(quicktime_atom_is(&leaf_atom, "udta"))
  66. {
  67. quicktime_read_udta(file, &(moov->udta), &leaf_atom);
  68. quicktime_atom_skip(file, &leaf_atom);
  69. }
  70. else
  71. if(quicktime_atom_is(&leaf_atom, "ctab"))
  72. {
  73. quicktime_read_ctab(file, &(moov->ctab));
  74. }
  75. else
  76. {
  77. quicktime_atom_skip(file, &leaf_atom);
  78. }
  79. }while(quicktime_position(file) < parent_atom->end);
  80. return 0;
  81. }
  82. int quicktime_write_moov(quicktime_t *file, quicktime_moov_t *moov)
  83. {
  84. quicktime_atom_t atom;
  85. int i;
  86. long longest_duration = 0;
  87. long duration, timescale;
  88. quicktime_atom_write_header(file, &atom, "moov");
  89. /* get the duration from the longest track in the mvhd's timescale */
  90. for(i = 0; i < moov->total_tracks; i++)
  91. {
  92. quicktime_trak_fix_counts(file, moov->trak[i]);
  93. quicktime_trak_duration(moov->trak[i], &duration, &timescale);
  94. duration = (long)((float)duration / timescale * moov->mvhd.time_scale);
  95. if(duration > longest_duration)
  96. {
  97. longest_duration = duration;
  98. }
  99. }
  100. moov->mvhd.duration = longest_duration;
  101. moov->mvhd.selection_duration = longest_duration;
  102. quicktime_write_mvhd(file, &(moov->mvhd));
  103. quicktime_write_iods(file, &(moov->iods));
  104. quicktime_write_udta(file, &(moov->udta));
  105. for(i = 0; i < moov->total_tracks; i++)
  106. {
  107. quicktime_write_trak(file, moov->trak[i], moov->mvhd.time_scale);
  108. }
  109. /*quicktime_write_ctab(file, &(moov->ctab)); */
  110. quicktime_atom_write_footer(file, &atom);
  111. }
  112. int quicktime_update_durations(quicktime_moov_t *moov)
  113. {
  114. }
  115. int quicktime_shift_offsets(quicktime_moov_t *moov, long offset)
  116. {
  117. int i;
  118. for(i = 0; i < moov->total_tracks; i++)
  119. {
  120. quicktime_trak_shift_offsets(moov->trak[i], offset);
  121. }
  122. return 0;
  123. }