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

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. #include "quicktime.h"
  2. int quicktime_stco_init(quicktime_stco_t *stco)
  3. {
  4. stco->version = 0;
  5. stco->flags = 0;
  6. stco->total_entries = 0;
  7. stco->entries_allocated = 0;
  8. }
  9. int quicktime_stco_delete(quicktime_stco_t *stco)
  10. {
  11. if(stco->total_entries) free(stco->table);
  12. stco->total_entries = 0;
  13. stco->entries_allocated = 0;
  14. }
  15. int quicktime_stco_init_common(quicktime_t *file, quicktime_stco_t *stco)
  16. {
  17. if(!stco->entries_allocated)
  18. {
  19. stco->entries_allocated = 2000;
  20. stco->total_entries = 0;
  21. stco->table = (quicktime_stco_table_t*)malloc(sizeof(quicktime_stco_table_t) * stco->entries_allocated);
  22. /*printf("quicktime_stco_init_common %xn", stco->table); */
  23. }
  24. }
  25. int quicktime_stco_dump(quicktime_stco_t *stco)
  26. {
  27. int i;
  28. printf("     chunk offsetn");
  29. printf("      version %dn", stco->version);
  30. printf("      flags %dn", stco->flags);
  31. printf("      total_entries %dn", stco->total_entries);
  32. for(i = 0; i < stco->total_entries; i++)
  33. {
  34. printf("       offset %d %xn", i, stco->table[i].offset);
  35. }
  36. }
  37. int quicktime_read_stco(quicktime_t *file, quicktime_stco_t *stco)
  38. {
  39. int i;
  40. stco->version = quicktime_read_char(file);
  41. stco->flags = quicktime_read_int24(file);
  42. stco->total_entries = quicktime_read_int32(file);
  43. /*printf("stco->total_entries %d %xn", stco->total_entries, stco); */
  44. stco->entries_allocated = stco->total_entries;
  45. stco->table = (quicktime_stco_table_t*)malloc(sizeof(quicktime_stco_table_t) * stco->entries_allocated);
  46. for(i = 0; i < stco->total_entries; i++)
  47. {
  48. stco->table[i].offset = quicktime_read_int32(file);
  49. }
  50. }
  51. int quicktime_write_stco(quicktime_t *file, quicktime_stco_t *stco)
  52. {
  53. int i;
  54. quicktime_atom_t atom;
  55. quicktime_atom_write_header(file, &atom, "stco");
  56. quicktime_write_char(file, stco->version);
  57. quicktime_write_int24(file, stco->flags);
  58. quicktime_write_int32(file, stco->total_entries);
  59. for(i = 0; i < stco->total_entries; i++)
  60. {
  61. quicktime_write_int32(file, stco->table[i].offset);
  62. }
  63. quicktime_atom_write_footer(file, &atom);
  64. }
  65. int quicktime_update_stco(quicktime_stco_t *stco, long chunk, long offset)
  66. {
  67. quicktime_stco_table_t *new_table;
  68. long i;
  69. if(chunk > stco->entries_allocated)
  70. {
  71. stco->entries_allocated = chunk * 2;
  72. stco->table = (quicktime_stco_table_t*)realloc(stco->table,
  73. sizeof(quicktime_stco_table_t) * stco->entries_allocated);
  74. }
  75. stco->table[chunk - 1].offset = offset;
  76. if(chunk > stco->total_entries) 
  77. stco->total_entries = chunk;
  78. }