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

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. #include "quicktime.h"
  2. int quicktime_minf_init(quicktime_minf_t *minf)
  3. {
  4. minf->is_video = minf->is_audio = minf->is_hint = 0;
  5. quicktime_vmhd_init(&(minf->vmhd));
  6. quicktime_smhd_init(&(minf->smhd));
  7. quicktime_hdlr_init(&(minf->hdlr));
  8. quicktime_dinf_init(&(minf->dinf));
  9. quicktime_stbl_init(&(minf->stbl));
  10. }
  11. int quicktime_minf_init_video(quicktime_t *file, 
  12. quicktime_minf_t *minf, 
  13. int frame_w,
  14. int frame_h, 
  15. int time_scale, 
  16. float frame_rate,
  17. char *compressor)
  18. {
  19. minf->is_video = 1;
  20. quicktime_vmhd_init_video(file, &(minf->vmhd), frame_w, frame_h, frame_rate);
  21. quicktime_stbl_init_video(file, &(minf->stbl), frame_w, frame_h, time_scale, frame_rate, compressor);
  22. quicktime_hdlr_init_data(&(minf->hdlr));
  23. quicktime_dinf_init_all(&(minf->dinf));
  24. }
  25. int quicktime_minf_init_audio(quicktime_t *file, 
  26. quicktime_minf_t *minf, 
  27. int channels, 
  28. int sample_rate, 
  29. int bits,
  30. int sample_size,
  31. int time_scale,
  32. int sample_duration,
  33. char *compressor)
  34. {
  35. minf->is_audio = 1;
  36. /* smhd doesn't store anything worth initializing */
  37. quicktime_stbl_init_audio(file, &(minf->stbl), channels, sample_rate, bits, sample_size, time_scale, sample_duration, compressor);
  38. quicktime_hdlr_init_data(&(minf->hdlr));
  39. quicktime_dinf_init_all(&(minf->dinf));
  40. }
  41. int quicktime_minf_init_hint(quicktime_t *file, 
  42. quicktime_minf_t *minf, 
  43. quicktime_trak_t *refTrak,
  44. int maxPktSize,
  45. int timeScale, int sampleDuration)
  46. {
  47. minf->is_hint = 1;
  48. quicktime_gmhd_init(&(minf->gmhd));
  49. quicktime_hmhd_init(&(minf->hmhd));
  50. quicktime_stbl_init_hint(file, &(minf->stbl), refTrak, 
  51. maxPktSize, timeScale, sampleDuration);
  52. quicktime_hdlr_init_data(&(minf->hdlr));
  53. quicktime_dinf_init_all(&(minf->dinf));
  54. }
  55. int quicktime_minf_delete(quicktime_minf_t *minf)
  56. {
  57. quicktime_vmhd_delete(&(minf->vmhd));
  58. quicktime_smhd_delete(&(minf->smhd));
  59. quicktime_gmhd_delete(&(minf->gmhd));
  60. quicktime_hmhd_delete(&(minf->hmhd));
  61. quicktime_dinf_delete(&(minf->dinf));
  62. quicktime_stbl_delete(&(minf->stbl));
  63. quicktime_hdlr_delete(&(minf->hdlr));
  64. }
  65. int quicktime_minf_dump(quicktime_minf_t *minf)
  66. {
  67. printf("   media infon");
  68. printf("    is_audio %dn", minf->is_audio);
  69. printf("    is_video %dn", minf->is_video);
  70. printf("    is_hint %dn", minf->is_hint);
  71. if(minf->is_audio) quicktime_smhd_dump(&(minf->smhd));
  72. if(minf->is_video) quicktime_vmhd_dump(&(minf->vmhd));
  73. if(minf->is_hint) {
  74. /* don't know which format we're using so just dump both */
  75. quicktime_hmhd_dump(&(minf->hmhd));
  76. quicktime_gmhd_dump(&(minf->gmhd));
  77. }
  78. quicktime_hdlr_dump(&(minf->hdlr));
  79. quicktime_dinf_dump(&(minf->dinf));
  80. quicktime_stbl_dump(minf, &(minf->stbl));
  81. }
  82. int quicktime_read_minf(quicktime_t *file, quicktime_minf_t *minf, quicktime_atom_t *parent_atom)
  83. {
  84. quicktime_atom_t leaf_atom;
  85. long pos = quicktime_position(file);
  86. do
  87. {
  88. quicktime_atom_read_header(file, &leaf_atom);
  89. /* mandatory */
  90. if(quicktime_atom_is(&leaf_atom, "vmhd"))
  91. { minf->is_video = 1; quicktime_read_vmhd(file, &(minf->vmhd)); }
  92. else
  93. if(quicktime_atom_is(&leaf_atom, "smhd"))
  94. { minf->is_audio = 1; quicktime_read_smhd(file, &(minf->smhd)); }
  95. else
  96. if(quicktime_atom_is(&leaf_atom, "gmhd"))
  97. { minf->is_hint = 1; quicktime_read_gmhd(file, &(minf->gmhd), &leaf_atom); }
  98. else
  99. if(quicktime_atom_is(&leaf_atom, "hmhd"))
  100. { minf->is_hint = 1; quicktime_read_hmhd(file, &(minf->hmhd), &leaf_atom); }
  101. else
  102. if(quicktime_atom_is(&leaf_atom, "hdlr"))
  103. quicktime_read_hdlr(file, &(minf->hdlr)); 
  104. /* Main Actor doesn't write component name */
  105. quicktime_atom_skip(file, &leaf_atom);
  106. }
  107. else
  108. if(quicktime_atom_is(&leaf_atom, "dinf"))
  109. { quicktime_read_dinf(file, &(minf->dinf), &leaf_atom); }
  110. else
  111. quicktime_atom_skip(file, &leaf_atom);
  112. }while(quicktime_position(file) < parent_atom->end);
  113. quicktime_set_position(file, pos);
  114. do {
  115. quicktime_atom_read_header(file, &leaf_atom);
  116. if(quicktime_atom_is(&leaf_atom, "stbl")) {
  117. quicktime_read_stbl(file, minf, &(minf->stbl), &leaf_atom);
  118. } else {
  119. quicktime_atom_skip(file, &leaf_atom);
  120. }
  121. } while(quicktime_position(file) < parent_atom->end);
  122. return 0;
  123. }
  124. int quicktime_write_minf(quicktime_t *file, quicktime_minf_t *minf)
  125. {
  126. quicktime_atom_t atom;
  127. quicktime_atom_write_header(file, &atom, "minf");
  128. if(minf->is_video) quicktime_write_vmhd(file, &(minf->vmhd));
  129. if(minf->is_audio) quicktime_write_smhd(file, &(minf->smhd));
  130. if(minf->is_hint) {
  131. if (file->use_mp4) {
  132. quicktime_write_hmhd(file, &(minf->hmhd));
  133. } else {
  134. quicktime_write_gmhd(file, &(minf->gmhd));
  135. }
  136. }
  137. quicktime_write_hdlr(file, &(minf->hdlr));
  138. quicktime_write_dinf(file, &(minf->dinf));
  139. quicktime_write_stbl(file, minf, &(minf->stbl));
  140. quicktime_atom_write_footer(file, &atom);
  141. }