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

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. #include "quicktime.h"
  2. int quicktime_stss_init(quicktime_stss_t *stss)
  3. {
  4. stss->version = 0;
  5. stss->flags = 0;
  6. stss->total_entries = 0;
  7. stss->entries_allocated = 0;
  8. }
  9. int quicktime_stss_init_common(quicktime_t *file, quicktime_stss_t *stss)
  10. {
  11. if (stss->entries_allocated == 0) {
  12. stss->entries_allocated = 100;
  13. stss->table = (quicktime_stss_table_t*)
  14. malloc(sizeof(quicktime_stss_table_t) * stss->entries_allocated);
  15. }
  16. }
  17. int quicktime_stss_delete(quicktime_stss_t *stss)
  18. {
  19. if(stss->total_entries) 
  20. free(stss->table);
  21. stss->total_entries = 0;
  22. }
  23. int quicktime_stss_dump(quicktime_stss_t *stss)
  24. {
  25. int i;
  26. printf("     sync samplen");
  27. printf("      version %dn", stss->version);
  28. printf("      flags %dn", stss->flags);
  29. printf("      total_entries %dn", stss->total_entries);
  30. for(i = 0; i < stss->total_entries; i++)
  31. {
  32. printf("       sample %un", stss->table[i].sample);
  33. }
  34. }
  35. int quicktime_read_stss(quicktime_t *file, quicktime_stss_t *stss)
  36. {
  37. int i;
  38. stss->version = quicktime_read_char(file);
  39. stss->flags = quicktime_read_int24(file);
  40. stss->total_entries = quicktime_read_int32(file);
  41. stss->table = (quicktime_stss_table_t*)malloc(sizeof(quicktime_stss_table_t) * stss->total_entries);
  42. for(i = 0; i < stss->total_entries; i++)
  43. {
  44. stss->table[i].sample = quicktime_read_int32(file);
  45. }
  46. }
  47. int quicktime_write_stss(quicktime_t *file, quicktime_stss_t *stss)
  48. {
  49. int i;
  50. quicktime_atom_t atom;
  51. if(stss->total_entries)
  52. {
  53. quicktime_atom_write_header(file, &atom, "stss");
  54. quicktime_write_char(file, stss->version);
  55. quicktime_write_int24(file, stss->flags);
  56. quicktime_write_int32(file, stss->total_entries);
  57. for(i = 0; i < stss->total_entries; i++)
  58. {
  59. quicktime_write_int32(file, stss->table[i].sample);
  60. }
  61. quicktime_atom_write_footer(file, &atom);
  62. }
  63. }
  64. int quicktime_update_stss(quicktime_stss_t *stss, long sample)
  65. {
  66. if (stss->total_entries >= stss->entries_allocated) {
  67. stss->entries_allocated *= 2;
  68. stss->table = (quicktime_stss_table_t*)realloc(stss->table,
  69. sizeof(quicktime_stss_table_t) * stss->entries_allocated);
  70. }
  71. stss->table[stss->total_entries++].sample = sample;
  72. }