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

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. #include "quicktime.h"
  2. int quicktime_tkhd_init(quicktime_tkhd_t *tkhd)
  3. {
  4. int i;
  5. tkhd->version = 0;
  6. tkhd->flags = 15;
  7. tkhd->creation_time = quicktime_current_time();
  8. tkhd->modification_time = quicktime_current_time();
  9. tkhd->track_id;
  10. tkhd->reserved1 = 0;
  11. tkhd->duration = 0;      /* need to set this when closing */
  12. for(i = 0; i < 8; i++) tkhd->reserved2[i] = 0;
  13. tkhd->layer = 0;
  14. tkhd->alternate_group = 0;
  15. tkhd->volume = 0.996094;
  16. tkhd->reserved3 = 0;
  17. quicktime_matrix_init(&(tkhd->matrix));
  18. tkhd->track_width = 0;
  19. tkhd->track_height = 0;
  20. tkhd->is_audio = FALSE;
  21. tkhd->is_video = FALSE;
  22. tkhd->is_hint = FALSE;
  23. return 0;
  24. }
  25. int quicktime_tkhd_init_audio(quicktime_t *file, 
  26. quicktime_tkhd_t *tkhd)
  27. {
  28. tkhd->is_audio = TRUE;
  29. }
  30. int quicktime_tkhd_init_video(quicktime_t *file, 
  31. quicktime_tkhd_t *tkhd, 
  32. int frame_w, 
  33. int frame_h)
  34. {
  35. tkhd->is_video = TRUE;
  36. tkhd->track_width = frame_w;
  37. tkhd->track_height = frame_h;
  38. tkhd->volume = 0;
  39. }
  40. int quicktime_tkhd_init_hint(quicktime_t *file, 
  41. quicktime_tkhd_t *tkhd)
  42. {
  43. tkhd->is_hint = TRUE;
  44. tkhd->flags = 0;
  45. tkhd->volume = 0;
  46. tkhd->alternate_group = 1;
  47. }
  48. int quicktime_tkhd_delete(quicktime_tkhd_t *tkhd)
  49. {
  50. return 0;
  51. }
  52. int quicktime_tkhd_dump(quicktime_tkhd_t *tkhd)
  53. {
  54. printf("  track headern");
  55. printf("   version %dn", tkhd->version);
  56. printf("   flags %ldn", tkhd->flags);
  57. printf("   creation_time %un", tkhd->creation_time);
  58. printf("   modification_time %un", tkhd->modification_time);
  59. printf("   track_id %dn", tkhd->track_id);
  60. printf("   reserved1 %ldn", tkhd->reserved1);
  61. printf("   duration %ldn", tkhd->duration);
  62. quicktime_print_chars("   reserved2 ", tkhd->reserved2, 8);
  63. printf("   layer %dn", tkhd->layer);
  64. printf("   alternate_group %dn", tkhd->alternate_group);
  65. printf("   volume %fn", tkhd->volume);
  66. printf("   reserved3 %dn", tkhd->reserved3);
  67. quicktime_matrix_dump(&(tkhd->matrix));
  68. printf("   track_width %fn", tkhd->track_width);
  69. printf("   track_height %fn", tkhd->track_height);
  70. }
  71. int quicktime_read_tkhd(quicktime_t *file, quicktime_tkhd_t *tkhd)
  72. {
  73. tkhd->version = quicktime_read_char(file);
  74. tkhd->flags = quicktime_read_int24(file);
  75. tkhd->creation_time = quicktime_read_int32(file);
  76. tkhd->modification_time = quicktime_read_int32(file);
  77. tkhd->track_id = quicktime_read_int32(file);
  78. tkhd->reserved1 = quicktime_read_int32(file);
  79. tkhd->duration = quicktime_read_int32(file);
  80. quicktime_read_data(file, tkhd->reserved2, 8);
  81. tkhd->layer = quicktime_read_int16(file);
  82. tkhd->alternate_group = quicktime_read_int16(file);
  83. tkhd->volume = quicktime_read_fixed16(file);
  84. tkhd->reserved3 = quicktime_read_int16(file);
  85. quicktime_read_matrix(file, &(tkhd->matrix));
  86. tkhd->track_width = quicktime_read_fixed32(file);
  87. tkhd->track_height = quicktime_read_fixed32(file);
  88. }
  89. int quicktime_write_tkhd(quicktime_t *file, quicktime_tkhd_t *tkhd)
  90. {
  91. quicktime_atom_t atom;
  92. quicktime_atom_write_header(file, &atom, "tkhd");
  93. quicktime_write_char(file, tkhd->version);
  94. if (file->use_mp4 && tkhd->flags != 0) {
  95. quicktime_write_int24(file, 1);
  96. } else {
  97. quicktime_write_int24(file, tkhd->flags);
  98. }
  99. quicktime_write_int32(file, tkhd->creation_time);
  100. quicktime_write_int32(file, tkhd->modification_time);
  101. quicktime_write_int32(file, tkhd->track_id);
  102. quicktime_write_int32(file, tkhd->reserved1);
  103. quicktime_write_int32(file, tkhd->duration);
  104. if (file->use_mp4) {
  105. int i;
  106. for (i = 0; i < 3; i++) {
  107. quicktime_write_int32(file, 0x00000000);
  108. }
  109. if (tkhd->is_audio) {
  110. quicktime_write_int16(file, 0x0100);
  111. } else {
  112. quicktime_write_int16(file, 0x0000);
  113. }
  114. quicktime_write_int16(file, 0x0000);
  115. quicktime_write_int32(file, 0x00010000);
  116. for (i = 0; i < 3; i++) {
  117. quicktime_write_int32(file, 0x00000000);
  118. }
  119. quicktime_write_int32(file, 0x00010000);
  120. for (i = 0; i < 3; i++) {
  121. quicktime_write_int32(file, 0x00000000);
  122. }
  123. quicktime_write_int32(file, 0x40000000);
  124. if (tkhd->is_video) {
  125. quicktime_write_int32(file, 0x01400000);
  126. quicktime_write_int32(file, 0x00F00000);
  127. } else {
  128. quicktime_write_int32(file, 0x00000000);
  129. quicktime_write_int32(file, 0x00000000);
  130. }
  131. } else {
  132. quicktime_write_data(file, tkhd->reserved2, 8);
  133. quicktime_write_int16(file, tkhd->layer);
  134. quicktime_write_int16(file, tkhd->alternate_group);
  135. quicktime_write_fixed16(file, tkhd->volume);
  136. quicktime_write_int16(file, tkhd->reserved3);
  137. quicktime_write_matrix(file, &(tkhd->matrix));
  138. quicktime_write_fixed32(file, tkhd->track_width);
  139. quicktime_write_fixed32(file, tkhd->track_height);
  140. }
  141. quicktime_atom_write_footer(file, &atom);
  142. }