chaining_example.c 2.62 KB
Newer Older
Monty's avatar
 
Monty committed
1 2
/********************************************************************
 *                                                                  *
Monty's avatar
 
Monty committed
3
 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
Monty's avatar
 
Monty committed
4 5 6
 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
Monty's avatar
 
Monty committed
7
 *                                                                  *
8 9
 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
 * by the Xiph.Org Foundation http://www.xiph.org/                  *
10
 *                                                                  *
Monty's avatar
 
Monty committed
11 12 13 14 15 16
 ********************************************************************

 function: illustrate simple use of chained bitstream and vorbisfile.a

 ********************************************************************/

Monty's avatar
 
Monty committed
17
#include <stdlib.h>
Monty's avatar
 
Monty committed
18 19
#include <vorbis/codec.h>
#include <vorbis/vorbisfile.h>
Monty's avatar
 
Monty committed
20

21 22 23 24 25
#ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */
#include <io.h>
#include <fcntl.h>
#endif

26
int main(){
Monty's avatar
 
Monty committed
27 28 29
  OggVorbis_File ov;
  int i;

30
#ifdef _WIN32 /* We need to set stdin to binary mode. Damn windows. */
Monty's avatar
Monty committed
31
  /* Beware the evil ifdef. We avoid these where we can, but this one we
32 33 34 35
     cannot. Don't add any more, you'll probably go to hell if you do. */
  _setmode( _fileno( stdin ), _O_BINARY );
#endif

Monty's avatar
 
Monty committed
36
  /* open the file/pipe on stdin */
37
  if(ov_open_callbacks(stdin,&ov,NULL,-1,OV_CALLBACKS_NOCLOSE)<0){
Monty's avatar
 
Monty committed
38 39 40
    printf("Could not open input as an OggVorbis file.\n\n");
    exit(1);
  }
Monty's avatar
Monty committed
41

Monty's avatar
 
Monty committed
42
  /* print details about each logical bitstream in the input */
Monty's avatar
 
Monty committed
43
  if(ov_seekable(&ov)){
Monty's avatar
 
Monty committed
44
    printf("Input bitstream contained %ld logical bitstream section(s).\n",
45
           ov_streams(&ov));
Monty's avatar
 
Monty committed
46
    printf("Total bitstream samples: %ld\n\n",
47
           (long)ov_pcm_total(&ov,-1));
Monty's avatar
 
Monty committed
48
    printf("Total bitstream playing time: %ld seconds\n\n",
49
           (long)ov_time_total(&ov,-1));
Monty's avatar
 
Monty committed
50 51 52

  }else{
    printf("Standard input was not seekable.\n"
53
           "First logical bitstream information:\n\n");
Monty's avatar
 
Monty committed
54 55
  }

Monty's avatar
 
Monty committed
56 57
  for(i=0;i<ov_streams(&ov);i++){
    vorbis_info *vi=ov_info(&ov,i);
Monty's avatar
 
Monty committed
58
    printf("\tlogical bitstream section %d information:\n",i+1);
Monty's avatar
 
Monty committed
59
    printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
60 61
           vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
           ov_serialnumber(&ov,i));
Monty's avatar
 
Monty committed
62
    printf("\t\theader length: %ld bytes\n",(long)
63
           (ov.dataoffsets[i]-ov.offsets[i]));
Monty's avatar
 
Monty committed
64 65
    printf("\t\tcompressed length: %ld bytes\n",(long)(ov_raw_total(&ov,i)));
    printf("\t\tplay time: %lds\n",(long)ov_time_total(&ov,i));
Monty's avatar
 
Monty committed
66
  }
Monty's avatar
 
Monty committed
67

Monty's avatar
 
Monty committed
68
  ov_clear(&ov);
69 70
  return 0;
}
Monty's avatar
 
Monty committed
71