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

多媒体

开发平台:

Unix_Linux

  1. #include "quicktime.h"
  2. int quicktime_stsd_table_init(quicktime_stsd_table_t *table)
  3. {
  4. int i;
  5. table->format[0] = 'y';
  6. table->format[1] = 'u';
  7. table->format[2] = 'v';
  8. table->format[3] = '2';
  9. for(i = 0; i < 6; i++) table->reserved[i] = 0;
  10. table->data_reference = 1;
  11. table->version = 0;
  12. table->revision = 0;
  13.   table->vendor[0] = 'l';
  14.   table->vendor[1] = 'n';
  15.   table->vendor[2] = 'u';
  16.   table->vendor[3] = 'x';
  17. table->temporal_quality = 0;
  18. table->spatial_quality = 258;
  19. table->width = 0;
  20. table->height = 0;
  21. table->dpi_horizontal = 72;
  22. table->dpi_vertical = 72;
  23. table->data_size = 0;
  24. table->frames_per_sample = 1;
  25. for(i = 0; i < 32; i++) table->compressor_name[i] = 0;
  26. sprintf(table->compressor_name, "Linux Quicktime");
  27. table->depth = 24;
  28. table->ctab_id = 65535;
  29. quicktime_ctab_init(&(table->ctab));
  30. table->gamma = 0;
  31. table->fields = 0;
  32. quicktime_mjqt_init(&(table->mjqt));
  33. quicktime_mjht_init(&(table->mjht));
  34. table->channels = 0;
  35. table->sample_size = 0;
  36. table->compression_id = 0;
  37. table->packet_size = 0;
  38. table->sample_rate = 0;
  39. }
  40. int quicktime_stsd_table_delete(quicktime_stsd_table_t *table)
  41. {
  42. quicktime_ctab_delete(&(table->ctab));
  43. quicktime_mjqt_delete(&(table->mjqt));
  44. quicktime_mjht_delete(&(table->mjht));
  45. }
  46. int quicktime_stsd_table_dump(void *minf_ptr, quicktime_stsd_table_t *table)
  47. {
  48. quicktime_minf_t *minf = minf_ptr;
  49. printf("       format %c%c%c%cn", table->format[0], table->format[1], table->format[2], table->format[3]);
  50. quicktime_print_chars("       reserved ", table->reserved, 6);
  51. printf("       data_reference %dn", table->data_reference);
  52. if(minf->is_audio) quicktime_stsd_audio_dump(table);
  53. if(minf->is_video) quicktime_stsd_video_dump(table);
  54. }
  55. int quicktime_stsd_audio_dump(quicktime_stsd_table_t *table)
  56. {
  57. printf("       version %dn", table->version);
  58. printf("       revision %dn", table->revision);
  59. printf("       vendor %c%c%c%cn", table->vendor[0], table->vendor[1], table->vendor[2], table->vendor[3]);
  60. printf("       channels %dn", table->channels);
  61. printf("       sample_size %dn", table->sample_size);
  62. printf("       compression_id %dn", table->compression_id);
  63. printf("       packet_size %dn", table->packet_size);
  64. printf("       sample_rate %fn", table->sample_rate);
  65. }
  66. int quicktime_stsd_video_dump(quicktime_stsd_table_t *table)
  67. {
  68. printf("       version %dn", table->version);
  69. printf("       revision %dn", table->revision);
  70. printf("       vendor %c%c%c%cn", table->vendor[0], table->vendor[1], table->vendor[2], table->vendor[3]);
  71. printf("       temporal_quality %ldn", table->temporal_quality);
  72. printf("       spatial_quality %ldn", table->spatial_quality);
  73. printf("       width %dn", table->width);
  74. printf("       height %dn", table->height);
  75. printf("       dpi_horizontal %fn", table->dpi_horizontal);
  76. printf("       dpi_vertical %fn", table->dpi_vertical);
  77. printf("       data_size %ldn", table->data_size);
  78. printf("       frames_per_sample %dn", table->frames_per_sample);
  79. printf("       compressor_name %sn", table->compressor_name);
  80. printf("       depth %dn", table->depth);
  81. printf("       ctab_id %dn", table->ctab_id);
  82. printf("       gamma %fn", table->gamma);
  83. printf("       fields %dn", table->fields);
  84. if(!table->ctab_id) quicktime_ctab_dump(&(table->ctab));
  85. quicktime_mjqt_dump(&(table->mjqt));
  86. quicktime_mjht_dump(&(table->mjht));
  87. }
  88. int quicktime_read_stsd_table(quicktime_t *file, quicktime_minf_t *minf, quicktime_stsd_table_t *table)
  89. {
  90. quicktime_atom_t leaf_atom;
  91. quicktime_atom_read_header(file->stream, &leaf_atom);
  92. table->format[0] = leaf_atom.type[0];
  93. table->format[1] = leaf_atom.type[1];
  94. table->format[2] = leaf_atom.type[2];
  95. table->format[3] = leaf_atom.type[3];
  96. quicktime_read_data(file, table->reserved, 6);
  97. table->data_reference = quicktime_read_int16(file);
  98. if(minf->is_audio) quicktime_read_stsd_audio(file, table, &leaf_atom);
  99. if(minf->is_video) quicktime_read_stsd_video(file, table, &leaf_atom);
  100. }
  101. int quicktime_write_stsd_table(quicktime_t *file, quicktime_minf_t *minf, quicktime_stsd_table_t *table)
  102. {
  103. quicktime_atom_t atom;
  104. quicktime_atom_write_header(file, &atom, table->format);
  105. quicktime_write_data(file, table->reserved, 6);
  106. quicktime_write_int16(file, table->data_reference);
  107. if(minf->is_audio) quicktime_write_stsd_audio(file, table);
  108. if(minf->is_video) quicktime_write_stsd_video(file, table);
  109. quicktime_atom_write_footer(file, &atom);
  110. }
  111. int quicktime_read_stsd_audio(quicktime_t *file, quicktime_stsd_table_t *table, quicktime_atom_t *parent_atom)
  112. {
  113. table->version = quicktime_read_int16(file);
  114. table->revision = quicktime_read_int16(file);
  115. quicktime_read_data(file, table->vendor, 4);
  116. table->channels = quicktime_read_int16(file);
  117. table->sample_size = quicktime_read_int16(file);
  118. table->compression_id = quicktime_read_int16(file);
  119. table->packet_size = quicktime_read_int16(file);
  120. table->sample_rate = quicktime_read_fixed32(file);
  121. }
  122. int quicktime_write_stsd_audio(quicktime_t *file, quicktime_stsd_table_t *table)
  123. {
  124. quicktime_write_int16(file, table->version);
  125. quicktime_write_int16(file, table->revision);
  126. quicktime_write_data(file, table->vendor, 4);
  127. quicktime_write_int16(file, table->channels);
  128. quicktime_write_int16(file, table->sample_size);
  129. quicktime_write_int16(file, table->compression_id);
  130. quicktime_write_int16(file, table->packet_size);
  131. quicktime_write_fixed32(file, table->sample_rate);
  132. }
  133. int quicktime_read_stsd_video(quicktime_t *file, quicktime_stsd_table_t *table, quicktime_atom_t *parent_atom)
  134. {
  135. quicktime_atom_t leaf_atom;
  136. int len;
  137. table->version = quicktime_read_int16(file);
  138. table->revision = quicktime_read_int16(file);
  139. quicktime_read_data(file, table->vendor, 4);
  140. table->temporal_quality = quicktime_read_int32(file);
  141. table->spatial_quality = quicktime_read_int32(file);
  142. table->width = quicktime_read_int16(file);
  143. table->height = quicktime_read_int16(file);
  144. table->dpi_horizontal = quicktime_read_fixed32(file);
  145. table->dpi_vertical = quicktime_read_fixed32(file);
  146. table->data_size = quicktime_read_int32(file);
  147. table->frames_per_sample = quicktime_read_int16(file);
  148. len = quicktime_read_char(file);
  149. quicktime_read_data(file, table->compressor_name, 31);
  150. table->depth = quicktime_read_int16(file);
  151. table->ctab_id = quicktime_read_int16(file);
  152. while(quicktime_position(file) < parent_atom->end)
  153. {
  154. quicktime_atom_read_header(file->stream, &leaf_atom);
  155. if(quicktime_atom_is(&leaf_atom, "ctab"))
  156. {
  157. quicktime_read_ctab(file, &(table->ctab));
  158. }
  159. else
  160. if(quicktime_atom_is(&leaf_atom, "gama"))
  161. {
  162. table->gamma= quicktime_read_fixed32(file);
  163. }
  164. else
  165. if(quicktime_atom_is(&leaf_atom, "fiel"))
  166. {
  167. table->fields = quicktime_read_int16(file);
  168. }
  169. else
  170. //  if(quicktime_atom_is(&leaf_atom, "mjqt"))
  171. //  {
  172. //  quicktime_read_mjqt(file, &(table->mjqt));
  173. //  }
  174. //  else
  175. //  if(quicktime_atom_is(&leaf_atom, "mjht"))
  176. //  {
  177. //  quicktime_read_mjht(file, &(table->mjht));
  178. //  }
  179. //  else
  180. quicktime_atom_skip(file, &leaf_atom);
  181. }
  182. }
  183. int quicktime_write_stsd_video(quicktime_t *file, quicktime_stsd_table_t *table)
  184. {
  185. quicktime_write_int16(file, table->version);
  186. quicktime_write_int16(file, table->revision);
  187. quicktime_write_data(file, table->vendor, 4);
  188. quicktime_write_int32(file, table->temporal_quality);
  189. quicktime_write_int32(file, table->spatial_quality);
  190. quicktime_write_int16(file, table->width);
  191. quicktime_write_int16(file, table->height);
  192. quicktime_write_fixed32(file, table->dpi_horizontal);
  193. quicktime_write_fixed32(file, table->dpi_vertical);
  194. quicktime_write_int32(file, table->data_size);
  195. quicktime_write_int16(file, table->frames_per_sample);
  196. quicktime_write_char(file, strlen(table->compressor_name));
  197. quicktime_write_data(file, table->compressor_name, 31);
  198. quicktime_write_int16(file, table->depth);
  199. quicktime_write_int16(file, table->ctab_id);
  200. }
  201. int quicktime_mjqt_init(quicktime_mjqt_t *mjqt)
  202. {
  203. }
  204. int quicktime_mjqt_delete(quicktime_mjqt_t *mjqt)
  205. {
  206. }
  207. int quicktime_mjqt_dump(quicktime_mjqt_t *mjqt)
  208. {
  209. }
  210. int quicktime_mjht_init(quicktime_mjht_t *mjht)
  211. {
  212. }
  213. int quicktime_mjht_delete(quicktime_mjht_t *mjht)
  214. {
  215. }
  216. int quicktime_mjht_dump(quicktime_mjht_t *mjht)
  217. {
  218. }