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

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. #include "quicktime.h"
  2. int quicktime_mdia_init(quicktime_mdia_t *mdia)
  3. {
  4. quicktime_mdhd_init(&(mdia->mdhd));
  5. quicktime_hdlr_init(&(mdia->hdlr));
  6. quicktime_minf_init(&(mdia->minf));
  7. }
  8. int quicktime_mdia_init_video(quicktime_t *file, 
  9. quicktime_mdia_t *mdia,
  10. int frame_w,
  11. int frame_h, 
  12. float frame_rate,
  13. int time_scale,
  14. char *compressor)
  15. {
  16. quicktime_mdhd_init_video(file, &(mdia->mdhd), time_scale);
  17. quicktime_minf_init_video(file, &(mdia->minf), frame_w, frame_h, mdia->mdhd.time_scale, frame_rate, compressor);
  18. quicktime_hdlr_init_video(&(mdia->hdlr));
  19. }
  20. int quicktime_mdia_init_audio(quicktime_t *file, 
  21. quicktime_mdia_t *mdia, 
  22. int channels,
  23. int sample_rate, 
  24. int bits, 
  25. int sample_size,
  26. int time_scale,
  27. int sample_duration,
  28. char *compressor)
  29. {
  30. quicktime_mdhd_init_audio(file, &(mdia->mdhd), time_scale);
  31. quicktime_minf_init_audio(file, &(mdia->minf), channels, sample_rate, bits, sample_size, time_scale, sample_duration, compressor);
  32. quicktime_hdlr_init_audio(&(mdia->hdlr));
  33. }
  34. int quicktime_mdia_init_hint(quicktime_t *file, 
  35. quicktime_mdia_t *mdia, 
  36. quicktime_trak_t *refTrak,
  37. int maxPktSize,
  38. int time_scale, 
  39. int sampleDuration)
  40. {
  41. quicktime_mdhd_init_hint(file, &(mdia->mdhd), refTrak, time_scale);
  42. quicktime_minf_init_hint(file, &(mdia->minf), refTrak, 
  43. maxPktSize, time_scale, sampleDuration);
  44. quicktime_hdlr_init_hint(&(mdia->hdlr));
  45. }
  46. int quicktime_mdia_delete(quicktime_mdia_t *mdia)
  47. {
  48. quicktime_mdhd_delete(&(mdia->mdhd));
  49. quicktime_hdlr_delete(&(mdia->hdlr));
  50. quicktime_minf_delete(&(mdia->minf));
  51. }
  52. int quicktime_mdia_dump(quicktime_mdia_t *mdia)
  53. {
  54. printf("  median");
  55. quicktime_mdhd_dump(&(mdia->mdhd));
  56. quicktime_hdlr_dump(&(mdia->hdlr));
  57. quicktime_minf_dump(&(mdia->minf));
  58. }
  59. int quicktime_read_mdia(quicktime_t *file, quicktime_mdia_t *mdia, quicktime_atom_t *trak_atom)
  60. {
  61. quicktime_atom_t leaf_atom;
  62. do
  63. {
  64. quicktime_atom_read_header(file, &leaf_atom);
  65. /* mandatory */
  66. if(quicktime_atom_is(&leaf_atom, "mdhd"))
  67. { quicktime_read_mdhd(file, &(mdia->mdhd)); }
  68. else
  69. if(quicktime_atom_is(&leaf_atom, "hdlr"))
  70. {
  71. quicktime_read_hdlr(file, &(mdia->hdlr)); 
  72. /* Main Actor doesn't write component name */
  73. quicktime_atom_skip(file, &leaf_atom);
  74. /*printf("quicktime_read_mdia %ldn", quicktime_position(file)); */
  75. }
  76. else
  77. if(quicktime_atom_is(&leaf_atom, "minf"))
  78. { quicktime_read_minf(file, &(mdia->minf), &leaf_atom); }
  79. else
  80. quicktime_atom_skip(file, &leaf_atom);
  81. }while(quicktime_position(file) < trak_atom->end);
  82. return 0;
  83. }
  84. int quicktime_write_mdia(quicktime_t *file, quicktime_mdia_t *mdia)
  85. {
  86. quicktime_atom_t atom;
  87. quicktime_atom_write_header(file, &atom, "mdia");
  88. quicktime_write_mdhd(file, &(mdia->mdhd));
  89. quicktime_write_hdlr(file, &(mdia->hdlr));
  90. quicktime_write_minf(file, &(mdia->minf));
  91. quicktime_atom_write_footer(file, &atom);
  92. }