minf.c
上传用户:luping1608
上传日期:2007-01-06
资源大小:38k
文件大小:3k
源码类别:

多媒体

开发平台:

Unix_Linux

  1. #include "quicktime.h"
  2. int quicktime_minf_init(quicktime_minf_t *minf)
  3. {
  4. minf->is_video = minf->is_audio = 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. float frame_rate,
  16. char *compressor)
  17. {
  18. minf->is_video = 1;
  19. quicktime_vmhd_init_video(file, &(minf->vmhd), frame_w, frame_h, frame_rate);
  20. quicktime_stbl_init_video(file, &(minf->stbl), frame_w, frame_h, frame_rate, compressor);
  21. quicktime_hdlr_init_data(&(minf->hdlr));
  22. quicktime_dinf_init_all(&(minf->dinf));
  23. }
  24. int quicktime_minf_init_audio(quicktime_t *file, 
  25. quicktime_minf_t *minf, 
  26. int channels, 
  27. int sample_rate, 
  28. int bits, 
  29. char *compressor)
  30. {
  31. minf->is_audio = 1;
  32. // smhd doesn't store anything worth initializing
  33. quicktime_stbl_init_audio(file, &(minf->stbl), channels, sample_rate, bits, compressor);
  34. quicktime_hdlr_init_data(&(minf->hdlr));
  35. quicktime_dinf_init_all(&(minf->dinf));
  36. }
  37. int quicktime_minf_delete(quicktime_minf_t *minf)
  38. {
  39. quicktime_vmhd_delete(&(minf->vmhd));
  40. quicktime_smhd_delete(&(minf->smhd));
  41. quicktime_dinf_delete(&(minf->dinf));
  42. quicktime_stbl_delete(&(minf->stbl));
  43. quicktime_hdlr_delete(&(minf->hdlr));
  44. }
  45. int quicktime_minf_dump(quicktime_minf_t *minf)
  46. {
  47. printf("   media infon");
  48. printf("    is_audio %dn", minf->is_audio);
  49. printf("    is_video %dn", minf->is_video);
  50. if(minf->is_audio) quicktime_smhd_dump(&(minf->smhd));
  51. if(minf->is_video) quicktime_vmhd_dump(&(minf->vmhd));
  52. quicktime_hdlr_dump(&(minf->hdlr));
  53. quicktime_dinf_dump(&(minf->dinf));
  54. quicktime_stbl_dump(minf, &(minf->stbl));
  55. }
  56. int quicktime_read_minf(quicktime_t *file, quicktime_minf_t *minf, quicktime_atom_t *parent_atom)
  57. {
  58. quicktime_atom_t leaf_atom;
  59. do
  60. {
  61. quicktime_atom_read_header(file->stream, &leaf_atom);
  62. // mandatory
  63. if(quicktime_atom_is(&leaf_atom, "vmhd"))
  64. { minf->is_video = 1; quicktime_read_vmhd(file, &(minf->vmhd)); }
  65. else
  66. if(quicktime_atom_is(&leaf_atom, "smhd"))
  67. { minf->is_audio = 1; quicktime_read_smhd(file, &(minf->smhd)); }
  68. else
  69. if(quicktime_atom_is(&leaf_atom, "hdlr"))
  70. { quicktime_read_hdlr(file, &(minf->hdlr)); }
  71. else
  72. if(quicktime_atom_is(&leaf_atom, "dinf"))
  73. { quicktime_read_dinf(file, &(minf->dinf), &leaf_atom); }
  74. else
  75. if(quicktime_atom_is(&leaf_atom, "stbl"))
  76. { quicktime_read_stbl(file, minf, &(minf->stbl), &leaf_atom); }
  77. else
  78. quicktime_atom_skip(file, &leaf_atom);
  79. }while(quicktime_position(file) < parent_atom->end);
  80. return 0;
  81. }
  82. int quicktime_write_minf(quicktime_t *file, quicktime_minf_t *minf)
  83. {
  84. quicktime_atom_t atom;
  85. quicktime_atom_write_header(file, &atom, "minf");
  86. if(minf->is_video) quicktime_write_vmhd(file, &(minf->vmhd));
  87. if(minf->is_audio) quicktime_write_smhd(file, &(minf->smhd));
  88. quicktime_write_hdlr(file, &(minf->hdlr));
  89. quicktime_write_dinf(file, &(minf->dinf));
  90. quicktime_write_stbl(file, minf, &(minf->stbl));
  91. quicktime_atom_write_footer(file, &atom);
  92. }