1
0
mirror of http://mpg123.de/trunk/.git synced 2025-07-30 02:01:12 +03:00

Include the examples in API doc.

git-svn-id: svn://scm.orgis.org/mpg123/trunk@1196 35dc7657-300d-0410-a2e5-dc2837fedb53
This commit is contained in:
thor
2007-11-30 23:20:04 +00:00
parent bcbc89aa56
commit 49204b005f
3 changed files with 37 additions and 15 deletions

View File

@ -10,14 +10,14 @@
#include <unistd.h>
#include <stdio.h>
#define INBUFF 16384
unsigned char buf[INBUFF];
#define INBUFF 16384
#define OUTBUFF 32768
int main(int argc, char **argv)
{
size_t size;
unsigned char out[8192];
unsigned char buf[INBUFF]; /* input buffer */
unsigned char out[OUTBUFF]; /* output buffer */
ssize_t len;
int ret;
size_t in = 0, outc = 0;
@ -30,13 +30,16 @@ int main(int argc, char **argv)
fprintf(stderr,"Unable to create mpg123 handle: %s\n", mpg123_plain_strerror(ret));
return -1;
}
mpg123_param(m, MPG123_VERBOSE, 2, 0);
/* mpg123_param(m, MPG123_ADD_FLAGS, MPG123_GAPLESS, 0); */
/* mpg123_param(m, MPG123_START_FRAME, 2300, 0); */
mpg123_param(m, MPG123_VERBOSE, 2, 0); /* Brabble a bit about the parsing/decoding. */
/* Now mpg123 is being prepared for feeding. The main loop will read chunks from stdin and feed them to mpg123;
then take decoded data as available to write to stdout. */
mpg123_open_feed(m);
if(m == NULL) return -1;
fprintf(stderr, "Feed me some MPEG audio to stdin, I will decode to stdout.\n");
while(1) {
while(1) /* Read and write until everything is through. */
{
len = read(0,buf,INBUFF);
if(len <= 0)
{
@ -44,8 +47,8 @@ int main(int argc, char **argv)
break;
}
in += len;
/*fprintf(stderr, ">> %lu KiB in\n", (unsigned long)in>>10);*/
ret = mpg123_decode(m,buf,len,out,8192,&size);
/* Feed input chunk and get first chunk of decoded audio. */
ret = mpg123_decode(m,buf,len,out,OUTBUFF,&size);
if(ret == MPG123_NEW_FORMAT)
{
long rate;
@ -55,16 +58,17 @@ int main(int argc, char **argv)
}
write(1,out,size);
outc += size;
/*fprintf(stderr, "<< %lu KiB out, ret=%i\n", (unsigned long)outc>>10, ret);*/
while(ret != MPG123_ERR && ret != MPG123_NEED_MORE) {
ret = mpg123_decode(m,NULL,0,out,8192,&size);
while(ret != MPG123_ERR && ret != MPG123_NEED_MORE)
{ /* Get all decoded audio that is available now before feeding more input. */
ret = mpg123_decode(m,NULL,0,out,OUTBUFF,&size);
write(1,out,size);
outc += size;
/*fprintf(stderr, "<< %lu KiB out, ret=%i\n", (unsigned long)outc>>10, ret);*/
}
if(ret == MPG123_ERR){ fprintf(stderr, "some error: %s", mpg123_strerror(m)); break; }
}
fprintf(stderr, "%lu bytes in, %lu bytes out\n", (unsigned long)in, (unsigned long)outc);
/* Done decoding, now just clean up and leave. */
mpg123_delete(m);
mpg123_exit();
return 0;