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

多媒体

开发平台:

Unix_Linux

  1. #include "quicktime.h"
  2. int quicktime_init_vcodecs(quicktime_video_map_t *vtrack)
  3. {
  4. char *compressor = vtrack->track->mdia.minf.stbl.stsd.table[0].format;
  5. if(quicktime_match_32(compressor, QUICKTIME_RAW))
  6. quicktime_init_codec_raw(vtrack);
  7. if(quicktime_match_32(compressor, QUICKTIME_JPEG))
  8. quicktime_init_codec_jpeg(vtrack);
  9. if(quicktime_match_32(compressor, QUICKTIME_YUV2))
  10. quicktime_init_codec_yuv2(vtrack);
  11. return 0;
  12. }
  13. int quicktime_init_acodecs(quicktime_audio_map_t *atrack)
  14. {
  15. char *compressor = atrack->track->mdia.minf.stbl.stsd.table[0].format;
  16. if(quicktime_match_32(compressor, QUICKTIME_IMA4))
  17. quicktime_init_codec_ima4(atrack);
  18. if(quicktime_match_32(compressor, QUICKTIME_ULAW))
  19. quicktime_init_codec_ulaw(atrack);
  20. return 0;
  21. }
  22. int quicktime_delete_vcodecs(quicktime_video_map_t *vtrack)
  23. {
  24. char *compressor = vtrack->track->mdia.minf.stbl.stsd.table[0].format;
  25. if(quicktime_match_32(compressor, QUICKTIME_RAW))
  26. quicktime_delete_codec_raw(vtrack);
  27. if(quicktime_match_32(compressor, QUICKTIME_JPEG))
  28. quicktime_delete_codec_jpeg(vtrack);
  29. if(quicktime_match_32(compressor, QUICKTIME_YUV2))
  30. quicktime_delete_codec_yuv2(vtrack);
  31. return 0;
  32. }
  33. int quicktime_delete_acodecs(quicktime_audio_map_t *atrack)
  34. {
  35. char *compressor = atrack->track->mdia.minf.stbl.stsd.table[0].format;
  36. if(quicktime_match_32(compressor, QUICKTIME_IMA4))
  37. quicktime_delete_codec_ima4(atrack);
  38. if(quicktime_match_32(compressor, QUICKTIME_ULAW))
  39. quicktime_delete_codec_ulaw(atrack);
  40. return 0;
  41. }
  42. int quicktime_supported_video(quicktime_t *file, int track)
  43. {
  44. char *compressor = quicktime_video_compressor(file, track);
  45. if(quicktime_match_32(compressor, QUICKTIME_RAW)) return 1;
  46. if(quicktime_match_32(compressor, QUICKTIME_JPEG)) return 1;
  47. if(quicktime_match_32(compressor, QUICKTIME_YUV2)) return 1;
  48. return 0;
  49. }
  50. int quicktime_supported_audio(quicktime_t *file, int track)
  51. {
  52. char *compressor = quicktime_audio_compressor(file, track);
  53. if(quicktime_match_32(compressor, QUICKTIME_IMA4)) return 1;
  54. if(quicktime_match_32(compressor, QUICKTIME_ULAW)) return 1;
  55. return 0;
  56. }
  57. int quicktime_decode_video(quicktime_t *file, unsigned char **row_pointers, int track)
  58. {
  59. char *compressor = quicktime_video_compressor(file, track);
  60. int result = 0;
  61. // test ram cache boundary
  62. if(file->vtracks[track].frames_cached &&
  63. file->vtracks[track].current_position >= file->vtracks[track].frames_cached) result = 1;
  64. if(!result)
  65. {
  66. if(quicktime_match_32(compressor, QUICKTIME_RAW))
  67. result = quicktime_decode_raw(file, row_pointers, track);
  68. else
  69. if(quicktime_match_32(compressor, QUICKTIME_JPEG))
  70. result = quicktime_decode_jpeg(file, row_pointers, track);
  71. else
  72. if(quicktime_match_32(compressor, QUICKTIME_YUV2))
  73. result = quicktime_decode_yuv2(file, row_pointers, track);
  74. else
  75. result = 1;
  76. }
  77. file->vtracks[track].current_position++;
  78. return result;
  79. }
  80. int quicktime_encode_video(quicktime_t *file, unsigned char **row_pointers, int track)
  81. {
  82. char *compressor = quicktime_video_compressor(file, track);
  83. int result = 0;
  84. if(quicktime_match_32(compressor, QUICKTIME_RAW))
  85. result = quicktime_encode_raw(file, row_pointers, track);
  86. else
  87. if(quicktime_match_32(compressor, QUICKTIME_JPEG))
  88. result = quicktime_encode_jpeg(file, row_pointers, track);
  89. else
  90. if(quicktime_match_32(compressor, QUICKTIME_YUV2))
  91. result = quicktime_encode_yuv2(file, row_pointers, track);
  92. else
  93. result = 1;
  94. file->vtracks[track].current_position++;
  95. return result;
  96. }
  97. int quicktime_decode_audio(quicktime_t *file, 
  98. QUICKTIME_INT16 *output_i, 
  99. float *output_f, 
  100. long samples, 
  101. int channel)
  102. {
  103. int quicktime_track, quicktime_channel;
  104. char *compressor;
  105. int result = 1;
  106. quicktime_channel_location(file, &quicktime_track, &quicktime_channel, channel);
  107. compressor = quicktime_audio_compressor(file, quicktime_track);
  108. if(quicktime_match_32(compressor, QUICKTIME_IMA4))
  109. result = quicktime_decode_ima4(file, output_i, output_f, samples, quicktime_track, quicktime_channel);
  110. else
  111. if(quicktime_match_32(compressor, QUICKTIME_ULAW))
  112. result = quicktime_decode_ulaw(file, output_i, output_f, samples, quicktime_track, quicktime_channel);
  113. else
  114. result = 1;
  115. file->atracks[quicktime_track].current_position += samples;
  116. return result;
  117. }
  118. // Since all channels are written at the same time:
  119. // Encode using the compressor for the first audio track.
  120. // Which means all the audio channels must be on the same track.
  121. int quicktime_encode_audio(quicktime_t *file, QUICKTIME_INT16 **input_i, float **input_f, long samples)
  122. {
  123. int result = 1;
  124. char *compressor = quicktime_audio_compressor(file, 0);
  125. if(quicktime_match_32(compressor, QUICKTIME_IMA4))
  126. result = quicktime_encode_ima4(file, input_i, input_f, 0, samples, 0);
  127. else
  128. if(quicktime_match_32(compressor, QUICKTIME_ULAW))
  129. result = quicktime_encode_ulaw(file, input_i, input_f, 0, samples, 0);
  130. else
  131. result = 1;
  132. file->atracks[0].current_position += samples;
  133. return result;
  134. }
  135. long quicktime_samples_to_bytes(quicktime_trak_t *track, long samples)
  136. {
  137. char *compressor = track->mdia.minf.stbl.stsd.table[0].format;
  138. int channels = track->mdia.minf.stbl.stsd.table[0].channels;
  139. if(quicktime_match_32(compressor, QUICKTIME_IMA4)) 
  140. return samples * channels;
  141. if(quicktime_match_32(compressor, QUICKTIME_ULAW)) 
  142. return samples * channels;
  143. // Default use the sample size specification
  144. return samples * channels * track->mdia.minf.stbl.stsd.table[0].sample_size / 8;
  145. }