You could access this page securely.

API documentation for libmpg123, libout123, and libsyn123

Note: This API doc is automatically generated from the current development version that you can get via Subversion or as a daily snapshot from http://mpg123.org/snapshot. There may be differences (additions) compared to the latest stable release. See NEWS.libmpg123, NEWS.libout123, NEWS.libsyn123, and the overall NEWS file on libmpg123 versions and important changes between them.
Let me emphasize that the policy for the lib*123 family is to always stay backwards compatible -- only additions are planned (and it's not yet planned to change the plans;-).
mpglib.c
Go to the documentation of this file.
1 /*
2  mpglib: test program for libmpg123, in the style of the legacy mpglib test program
3 
4  copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1
5  see COPYING and AUTHORS files in distribution or http://mpg123.org
6  initially written by Thomas Orgis
7 */
8 
9 #include <mpg123.h>
10 
11 /* unistd.h is not available under MSVC,
12  io.h defines the read and write functions */
13 #ifndef _MSC_VER
14 #include <unistd.h>
15 #else
16 #include <io.h>
17 #endif
18 
19 #ifdef _WIN32
20 #include <fcntl.h>
21 #endif
22 
23 #include <stdio.h>
24 
25 #define INBUFF 16384
26 #define OUTBUFF 32768
27 
28 int main(int argc, char **argv)
29 {
30  size_t size;
31  unsigned char buf[INBUFF]; /* input buffer */
32  unsigned char out[OUTBUFF]; /* output buffer */
33  ssize_t len;
34  int ret;
35  size_t in = 0, outc = 0;
36  mpg123_handle *m;
37 
38 #ifdef _WIN32
39 _setmode(_fileno(stdin),_O_BINARY);
40 _setmode(_fileno(stdout),_O_BINARY);
41 #endif
42 
43  mpg123_init();
44  m = mpg123_new(argc > 1 ? argv[1] : NULL, &ret);
45  if(m == NULL)
46  {
47  fprintf(stderr,"Unable to create mpg123 handle: %s\n", mpg123_plain_strerror(ret));
48  return -1;
49  }
50  mpg123_param(m, MPG123_VERBOSE, 2, 0); /* Brabble a bit about the parsing/decoding. */
51 
52  /* Now mpg123 is being prepared for feeding. The main loop will read chunks from stdin and feed them to mpg123;
53  then take decoded data as available to write to stdout. */
55  if(m == NULL) return -1;
56 
57  fprintf(stderr, "Feed me some MPEG audio to stdin, I will decode to stdout.\n");
58  while(1) /* Read and write until everything is through. */
59  {
60  len = read(0,buf,INBUFF);
61  if(len <= 0)
62  {
63  fprintf(stderr, "input data end\n");
64  break;
65  }
66  in += len;
67  /* Feed input chunk and get first chunk of decoded audio. */
68  ret = mpg123_decode(m,buf,len,out,OUTBUFF,&size);
69  if(ret == MPG123_NEW_FORMAT)
70  {
71  long rate;
72  int channels, enc;
73  mpg123_getformat(m, &rate, &channels, &enc);
74  fprintf(stderr, "New format: %li Hz, %i channels, encoding value %i\n", rate, channels, enc);
75  }
76  write(1,out,size);
77  outc += size;
78  while(ret != MPG123_ERR && ret != MPG123_NEED_MORE)
79  { /* Get all decoded audio that is available now before feeding more input. */
80  ret = mpg123_decode(m,NULL,0,out,OUTBUFF,&size);
81  write(1,out,size);
82  outc += size;
83  }
84  if(ret == MPG123_ERR){ fprintf(stderr, "some error: %s", mpg123_strerror(m)); break; }
85  }
86  fprintf(stderr, "%lu bytes in, %lu bytes out\n", (unsigned long)in, (unsigned long)outc);
87 
88  /* Done decoding, now just clean up and leave. */
89  mpg123_delete(m);
90  mpg123_exit();
91  return 0;
92 }
struct mpg123_handle_struct mpg123_handle
Definition: mpg123.h:132
MPG123_EXPORT void mpg123_exit(void)
MPG123_EXPORT const char * mpg123_strerror(mpg123_handle *mh)
MPG123_EXPORT int mpg123_decode(mpg123_handle *mh, const unsigned char *inmemory, size_t inmemsize, void *outmemory, size_t outmemsize, size_t *done)
MPG123_EXPORT const char * mpg123_plain_strerror(int errcode)
MPG123_EXPORT int mpg123_init(void)
MPG123_EXPORT int mpg123_open_feed(mpg123_handle *mh)
MPG123_EXPORT void mpg123_delete(mpg123_handle *mh)
MPG123_EXPORT int mpg123_param(mpg123_handle *mh, enum mpg123_parms type, long value, double fvalue)
MPG123_EXPORT mpg123_handle * mpg123_new(const char *decoder, int *error)
MPG123_EXPORT int mpg123_getformat(mpg123_handle *mh, long *rate, int *channels, int *encoding)
Hopefully valid HTML! Valid CSS!