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

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. #include "quicktime.h"
  2. int quicktime_stbl_init(quicktime_stbl_t *stbl)
  3. {
  4. stbl->version = 0;
  5. stbl->flags = 0;
  6. quicktime_stsd_init(&(stbl->stsd));
  7. quicktime_stts_init(&(stbl->stts));
  8. quicktime_stss_init(&(stbl->stss));
  9. quicktime_stsc_init(&(stbl->stsc));
  10. quicktime_stsz_init(&(stbl->stsz));
  11. quicktime_stco_init(&(stbl->stco));
  12. quicktime_ctts_init(&(stbl->ctts));
  13. }
  14. int quicktime_stbl_init_video(quicktime_t *file, 
  15. quicktime_stbl_t *stbl, 
  16. int frame_w,
  17. int frame_h, 
  18. int time_scale, 
  19. float frame_rate,
  20. char *compressor)
  21. {
  22. quicktime_stsd_init_video(file, &(stbl->stsd), frame_w, frame_h, frame_rate, compressor);
  23. quicktime_stts_init_video(file, &(stbl->stts), time_scale, frame_rate);
  24. quicktime_stss_init_common(file, &(stbl->stss));
  25. quicktime_stsc_init_video(file, &(stbl->stsc));
  26. quicktime_stsz_init_video(file, &(stbl->stsz));
  27. quicktime_stco_init_common(file, &(stbl->stco));
  28. quicktime_ctts_init_common(file, &(stbl->ctts));
  29. }
  30. int quicktime_stbl_init_audio(quicktime_t *file, 
  31. quicktime_stbl_t *stbl, 
  32. int channels, 
  33. int sample_rate, 
  34. int bits, 
  35. int sample_size,
  36. int time_scale,
  37. int sample_duration,
  38. char *compressor)
  39. {
  40. quicktime_stsd_init_audio(file, &(stbl->stsd), channels, sample_rate, bits, compressor);
  41. quicktime_stts_init_audio(file, &(stbl->stts), time_scale, sample_duration);
  42. quicktime_stss_init_common(file, &(stbl->stss));
  43. quicktime_stsc_init_audio(file, &(stbl->stsc));
  44. quicktime_stsz_init_audio(file, &(stbl->stsz), sample_size);
  45. quicktime_stco_init_common(file, &(stbl->stco));
  46. quicktime_ctts_init_common(file, &(stbl->ctts));
  47. }
  48. int quicktime_stbl_init_hint(quicktime_t *file, 
  49. quicktime_stbl_t *stbl, 
  50. quicktime_trak_t *refTrak,
  51. int maxPktSize,
  52. int timeScale, 
  53. int sample_duration)
  54. {
  55. quicktime_stsd_init_hint(file, &(stbl->stsd), maxPktSize, timeScale);
  56. quicktime_stts_init_hint(file, &(stbl->stts), sample_duration);
  57. quicktime_stss_init_common(file, &(stbl->stss));
  58. /* video's versions seems to be what we want, so we reuse them here */
  59. quicktime_stsc_init_video(file, &(stbl->stsc));
  60. quicktime_stsz_init_video(file, &(stbl->stsz));
  61. quicktime_stco_init_common(file, &(stbl->stco));
  62. quicktime_ctts_init_common(file, &(stbl->ctts));
  63. }
  64. int quicktime_stbl_delete(quicktime_stbl_t *stbl)
  65. {
  66. quicktime_stsd_delete(&(stbl->stsd));
  67. quicktime_stts_delete(&(stbl->stts));
  68. quicktime_stss_delete(&(stbl->stss));
  69. quicktime_stsc_delete(&(stbl->stsc));
  70. quicktime_stsz_delete(&(stbl->stsz));
  71. quicktime_stco_delete(&(stbl->stco));
  72. quicktime_ctts_delete(&(stbl->ctts));
  73. }
  74. int quicktime_stbl_dump(void *minf_ptr, quicktime_stbl_t *stbl)
  75. {
  76. printf("    sample tablen");
  77. quicktime_stsd_dump(minf_ptr, &(stbl->stsd));
  78. quicktime_stts_dump(&(stbl->stts));
  79. quicktime_stss_dump(&(stbl->stss));
  80. quicktime_stsc_dump(&(stbl->stsc));
  81. quicktime_stsz_dump(&(stbl->stsz));
  82. quicktime_stco_dump(&(stbl->stco));
  83. quicktime_ctts_dump(&(stbl->ctts));
  84. }
  85. int quicktime_read_stbl(quicktime_t *file, quicktime_minf_t *minf, quicktime_stbl_t *stbl, quicktime_atom_t *parent_atom)
  86. {
  87. quicktime_atom_t leaf_atom;
  88. do
  89. {
  90. quicktime_atom_read_header(file, &leaf_atom);
  91. /* mandatory */
  92. if(quicktime_atom_is(&leaf_atom, "stsd"))
  93. quicktime_read_stsd(file, minf, &(stbl->stsd)); 
  94. /* Some codecs store extra information at the end of this */
  95. quicktime_atom_skip(file, &leaf_atom);
  96. }
  97. else
  98. if(quicktime_atom_is(&leaf_atom, "stts"))
  99. { quicktime_read_stts(file, &(stbl->stts)); }
  100. else
  101. if(quicktime_atom_is(&leaf_atom, "stss"))
  102. { quicktime_read_stss(file, &(stbl->stss)); }
  103. else
  104. if(quicktime_atom_is(&leaf_atom, "stsc"))
  105. { quicktime_read_stsc(file, &(stbl->stsc)); }
  106. else
  107. if(quicktime_atom_is(&leaf_atom, "stsz"))
  108. { quicktime_read_stsz(file, &(stbl->stsz)); }
  109. else
  110. if(quicktime_atom_is(&leaf_atom, "stco"))
  111. { quicktime_read_stco(file, &(stbl->stco)); }
  112. else
  113. if(quicktime_atom_is(&leaf_atom, "ctts"))
  114. { quicktime_read_ctts(file, &(stbl->ctts)); }
  115. else
  116. quicktime_atom_skip(file, &leaf_atom);
  117. }while(quicktime_position(file) < parent_atom->end);
  118. return 0;
  119. }
  120. int quicktime_write_stbl(quicktime_t *file, quicktime_minf_t *minf, quicktime_stbl_t *stbl)
  121. {
  122. quicktime_atom_t atom;
  123. quicktime_atom_write_header(file, &atom, "stbl");
  124. quicktime_write_stsd(file, minf, &(stbl->stsd));
  125. quicktime_write_stts(file, &(stbl->stts));
  126. quicktime_write_stss(file, &(stbl->stss));
  127. quicktime_write_stsc(file, &(stbl->stsc));
  128. quicktime_write_stsz(file, &(stbl->stsz));
  129. quicktime_write_stco(file, &(stbl->stco));
  130. quicktime_write_ctts(file, &(stbl->ctts));
  131. quicktime_atom_write_footer(file, &atom);
  132. }