chaining_example.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  5. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
  9. * by the Xiph.Org Foundation http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: illustrate simple use of chained bitstream and vorbisfile.a
  13. ********************************************************************/
  14. #include <stdlib.h>
  15. #include <vorbis/codec.h>
  16. #include <vorbis/vorbisfile.h>
  17. #ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */
  18. #include <io.h>
  19. #include <fcntl.h>
  20. #endif
  21. int main(){
  22. OggVorbis_File ov;
  23. int i;
  24. #ifdef _WIN32 /* We need to set stdin to binary mode. Damn windows. */
  25. /* Beware the evil ifdef. We avoid these where we can, but this one we
  26. cannot. Don't add any more, you'll probably go to hell if you do. */
  27. _setmode( _fileno( stdin ), _O_BINARY );
  28. #endif
  29. /* open the file/pipe on stdin */
  30. if(ov_open_callbacks(stdin,&ov,NULL,-1,OV_CALLBACKS_NOCLOSE)<0){
  31. printf("Could not open input as an OggVorbis file.\n\n");
  32. exit(1);
  33. }
  34. /* print details about each logical bitstream in the input */
  35. if(ov_seekable(&ov)){
  36. printf("Input bitstream contained %ld logical bitstream section(s).\n",
  37. ov_streams(&ov));
  38. printf("Total bitstream samples: %ld\n\n",
  39. (long)ov_pcm_total(&ov,-1));
  40. printf("Total bitstream playing time: %ld seconds\n\n",
  41. (long)ov_time_total(&ov,-1));
  42. }else{
  43. printf("Standard input was not seekable.\n"
  44. "First logical bitstream information:\n\n");
  45. }
  46. for(i=0;i<ov_streams(&ov);i++){
  47. vorbis_info *vi=ov_info(&ov,i);
  48. printf("\tlogical bitstream section %d information:\n",i+1);
  49. printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
  50. vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
  51. ov_serialnumber(&ov,i));
  52. printf("\t\theader length: %ld bytes\n",(long)
  53. (ov.dataoffsets[i]-ov.offsets[i]));
  54. printf("\t\tcompressed length: %ld bytes\n",(long)(ov_raw_total(&ov,i)));
  55. printf("\t\tplay time: %lds\n",(long)ov_time_total(&ov,i));
  56. }
  57. ov_clear(&ov);
  58. return 0;
  59. }