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

多媒体

开发平台:

Unix_Linux

  1. #include "quicktime.h"
  2. int quicktime_stsd_init(quicktime_stsd_t *stsd)
  3. {
  4. stsd->version = 0;
  5. stsd->flags = 0;
  6. stsd->total_entries = 0;
  7. }
  8. int quicktime_stsd_init_table(quicktime_stsd_t *stsd)
  9. {
  10. if(!stsd->total_entries)
  11. {
  12. stsd->total_entries = 1;
  13. stsd->table = (quicktime_stsd_table_t*)malloc(sizeof(quicktime_stsd_table_t) * stsd->total_entries);
  14. quicktime_stsd_table_init(&(stsd->table[0]));
  15. }
  16. }
  17. int quicktime_stsd_init_video(quicktime_t *file, 
  18. quicktime_stsd_t *stsd, 
  19. int frame_w,
  20. int frame_h, 
  21. float frame_rate,
  22. char *compression)
  23. {
  24. quicktime_stsd_table_t *table;
  25. quicktime_stsd_init_table(stsd);
  26. table = &(stsd->table[0]);
  27. quicktime_copy_char32(table->format, compression);
  28. table->width = frame_w;
  29. table->height = frame_h;
  30. table->frames_per_sample = 1;
  31. table->depth = 24;
  32. table->ctab_id = 65535;
  33. }
  34. int quicktime_stsd_init_audio(quicktime_t *file, 
  35. quicktime_stsd_t *stsd, 
  36. int channels,
  37. int sample_rate, 
  38. int bits, 
  39. char *compressor)
  40. {
  41. quicktime_stsd_table_t *table;
  42. quicktime_stsd_init_table(stsd);
  43. table = &(stsd->table[0]);
  44. quicktime_copy_char32(table->format, compressor);
  45. table->channels = channels;
  46. table->sample_size = bits;
  47. table->sample_rate = sample_rate;
  48. }
  49. int quicktime_stsd_delete(quicktime_stsd_t *stsd)
  50. {
  51. int i;
  52. if(stsd->total_entries)
  53. {
  54. for(i = 0; i < stsd->total_entries; i++)
  55. quicktime_stsd_table_delete(&(stsd->table[i]));
  56. free(stsd->table);
  57. }
  58. stsd->total_entries = 0;
  59. }
  60. int quicktime_stsd_dump(void *minf_ptr, quicktime_stsd_t *stsd)
  61. {
  62. int i;
  63. printf("     sample descriptionn");
  64. printf("      version %dn", stsd->version);
  65. printf("      flags %dn", stsd->flags);
  66. printf("      total_entries %dn", stsd->total_entries);
  67. for(i = 0; i < stsd->total_entries; i++)
  68. {
  69. quicktime_stsd_table_dump(minf_ptr, &(stsd->table[i]));
  70. }
  71. }
  72. int quicktime_read_stsd(quicktime_t *file, quicktime_minf_t *minf, quicktime_stsd_t *stsd)
  73. {
  74. int i;
  75. quicktime_atom_t leaf_atom;
  76. stsd->version = quicktime_read_char(file);
  77. stsd->flags = quicktime_read_int24(file);
  78. stsd->total_entries = quicktime_read_int32(file);
  79. stsd->table = (quicktime_stsd_table_t*)malloc(sizeof(quicktime_stsd_table_t) * stsd->total_entries);
  80. for(i = 0; i < stsd->total_entries; i++)
  81. {
  82. quicktime_stsd_table_init(&(stsd->table[i]));
  83. quicktime_read_stsd_table(file, minf, &(stsd->table[i]));
  84. }
  85. }
  86. int quicktime_write_stsd(quicktime_t *file, quicktime_minf_t *minf, quicktime_stsd_t *stsd)
  87. {
  88. quicktime_atom_t atom;
  89. int i;
  90. quicktime_atom_write_header(file, &atom, "stsd");
  91. quicktime_write_char(file, stsd->version);
  92. quicktime_write_int24(file, stsd->flags);
  93. quicktime_write_int32(file, stsd->total_entries);
  94. for(i = 0; i < stsd->total_entries; i++)
  95. {
  96. quicktime_write_stsd_table(file, minf, stsd->table);
  97. }
  98. quicktime_atom_write_footer(file, &atom);
  99. }