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

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  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_init_hint(quicktime_t *file, 
  50. quicktime_stsd_t *stsd, 
  51. int maxPktSize,
  52. int timeScale)
  53. {
  54. quicktime_stsd_table_t *table;
  55. quicktime_stsd_init_table(stsd);
  56. table = &(stsd->table[0]);
  57. quicktime_copy_char32(table->format, "rtp ");
  58. table->version = 1;
  59. table->revision = 1;
  60. table->maxPktSize = maxPktSize;
  61. table->tims.timeScale = timeScale;
  62. }
  63. int quicktime_stsd_delete(quicktime_stsd_t *stsd)
  64. {
  65. int i;
  66. if(stsd->total_entries)
  67. {
  68. for(i = 0; i < stsd->total_entries; i++)
  69. quicktime_stsd_table_delete(&(stsd->table[i]));
  70. free(stsd->table);
  71. }
  72. stsd->total_entries = 0;
  73. }
  74. int quicktime_stsd_dump(void *minf_ptr, quicktime_stsd_t *stsd)
  75. {
  76. int i;
  77. printf("     sample descriptionn");
  78. printf("      version %dn", stsd->version);
  79. printf("      flags %dn", stsd->flags);
  80. printf("      total_entries %dn", stsd->total_entries);
  81. for(i = 0; i < stsd->total_entries; i++)
  82. {
  83. quicktime_stsd_table_dump(minf_ptr, &(stsd->table[i]));
  84. }
  85. }
  86. int quicktime_read_stsd(quicktime_t *file, quicktime_minf_t *minf, quicktime_stsd_t *stsd)
  87. {
  88. int i;
  89. quicktime_atom_t leaf_atom;
  90. stsd->version = quicktime_read_char(file);
  91. stsd->flags = quicktime_read_int24(file);
  92. stsd->total_entries = quicktime_read_int32(file);
  93. stsd->table = (quicktime_stsd_table_t*)malloc(sizeof(quicktime_stsd_table_t) * stsd->total_entries);
  94. for(i = 0; i < stsd->total_entries; i++)
  95. {
  96. quicktime_stsd_table_init(&(stsd->table[i]));
  97. quicktime_read_stsd_table(file, minf, &(stsd->table[i]));
  98. }
  99. }
  100. int quicktime_write_stsd(quicktime_t *file, quicktime_minf_t *minf, quicktime_stsd_t *stsd)
  101. {
  102. quicktime_atom_t atom;
  103. int i;
  104. quicktime_atom_write_header(file, &atom, "stsd");
  105. quicktime_write_char(file, stsd->version);
  106. quicktime_write_int24(file, stsd->flags);
  107. quicktime_write_int32(file, stsd->total_entries);
  108. for(i = 0; i < stsd->total_entries; i++)
  109. {
  110. quicktime_write_stsd_table(file, minf, stsd->table);
  111. }
  112. quicktime_atom_write_footer(file, &atom);
  113. }