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

多媒体

开发平台:

Unix_Linux

  1. #include "quicktime.h"
  2. int quicktime_stts_init(quicktime_stts_t *stts)
  3. {
  4. stts->version = 0;
  5. stts->flags = 0;
  6. stts->total_entries = 0;
  7. }
  8. int quicktime_stts_init_table(quicktime_stts_t *stts)
  9. {
  10. if(!stts->total_entries)
  11. {
  12. stts->total_entries = 1;
  13. stts->table = (quicktime_stts_table_t*)malloc(sizeof(quicktime_stts_table_t) * stts->total_entries);
  14. }
  15. }
  16. int quicktime_stts_init_video(quicktime_t *file, quicktime_stts_t *stts, float frame_rate)
  17. {
  18. quicktime_stts_table_t *table;
  19. quicktime_stts_init_table(stts);
  20. table = &(stts->table[0]);
  21. table->sample_count = 0;      // need to set this when closing
  22. table->sample_duration = file->moov.mvhd.time_scale / frame_rate;
  23. }
  24. int quicktime_stts_init_audio(quicktime_t *file, quicktime_stts_t *stts, int sample_rate)
  25. {
  26. quicktime_stts_table_t *table;
  27. quicktime_stts_init_table(stts);
  28. table = &(stts->table[0]);
  29. table->sample_count = 0;     // need to set this when closing
  30. table->sample_duration = 1;
  31. }
  32. int quicktime_stts_delete(quicktime_stts_t *stts)
  33. {
  34. if(stts->total_entries) free(stts->table);
  35. stts->total_entries = 0;
  36. }
  37. int quicktime_stts_dump(quicktime_stts_t *stts)
  38. {
  39. int i;
  40. printf("     time to samplen");
  41. printf("      version %dn", stts->version);
  42. printf("      flags %dn", stts->flags);
  43. printf("      total_entries %dn", stts->total_entries);
  44. for(i = 0; i < stts->total_entries; i++)
  45. {
  46. printf("       count %ld duration %ldn", stts->table[i].sample_count, stts->table[i].sample_duration);
  47. }
  48. }
  49. int quicktime_read_stts(quicktime_t *file, quicktime_stts_t *stts)
  50. {
  51. int i;
  52. stts->version = quicktime_read_char(file);
  53. stts->flags = quicktime_read_int24(file);
  54. stts->total_entries = quicktime_read_int32(file);
  55. stts->table = (quicktime_stts_table_t*)malloc(sizeof(quicktime_stts_table_t) * stts->total_entries);
  56. for(i = 0; i < stts->total_entries; i++)
  57. {
  58. stts->table[i].sample_count = quicktime_read_int32(file);
  59. stts->table[i].sample_duration = quicktime_read_int32(file);
  60. }
  61. }
  62. int quicktime_write_stts(quicktime_t *file, quicktime_stts_t *stts)
  63. {
  64. int i;
  65. quicktime_atom_t atom;
  66. quicktime_atom_write_header(file, &atom, "stts");
  67. quicktime_write_char(file, stts->version);
  68. quicktime_write_int24(file, stts->flags);
  69. quicktime_write_int32(file, stts->total_entries);
  70. for(i = 0; i < stts->total_entries; i++)
  71. {
  72. quicktime_write_int32(file, stts->table[i].sample_count);
  73. quicktime_write_int32(file, stts->table[i].sample_duration);
  74. }
  75. quicktime_atom_write_footer(file, &atom);
  76. }