Re: [mpg123-users] mpg123_read() (Error reading the stream. (code 18))
Brought to you by:
sobukus
From: Leonard B. <leo...@gm...> - 2021-02-26 08:34:51
|
Hi Martin Found the issues. (1) The use of fread() (2) The small buffer size from mpg123_outblock(mh) which is inadequate for ALSA (a small buffer causes ALSA to play with jitter) To resolve (1) I have changed the code to that used in the example file “mpg123_to_wav_replaced_io.c". This uses read() in a callback arrangement instead of fread(). I haven’t tested if the callback is actually necessary, but I think not.. I assume the issue with fread() is something to do with the internal buffering it does. To resolve (2) I have used a much larger write buffer than read buffer, like this…… int samples = 0; int scale = 16; // Set this high enough to satisfy ALSA buffer_size = mpg123_outblock(mh); unsigned char *buffer = malloc(buffer_size); do { struct sa_audio_data_mp3_t *audio = (struct sa_audio_data_mp3_t*) malloc(sizeof (struct sa_audio_data_mp3_t)); buffer_write_size = buffer_size * scale; audio->data = malloc(buffer_write_size); audio->data_len_bytes = 0; for (int idx = 0; idx < scale; idx++) { // Stack the in data into the out buffer by scale number of times err = mpg123_read(mh, buffer, buffer_size, &size); if (err < 0 ) printf("Error reading (%s)\n", mpg123_strerror(mh)); memcpy(&audio->data[audio->data_len_bytes], buffer, size); audio->data_len_bytes = audio->data_len_bytes + size; } audio->play_metadata = play_metadata; audio->chunk_count = chunk_count++; if (!play_queue_push(audio)) free(audio); samples += size / sizeof (short); } while (err == MPG123_OK); Thanks very much, nice to have it working. Leonard > On 23/02/2021, at 1:21 AM, Martin Guy <mar...@gm...> wrote: > > On 22/02/2021, Leonard Bocock <leo...@gm... <mailto:leo...@gm...>> wrote: >> Hi list >> >> I’m stumped. This is what I see in the trace log. >> >>>> in=294912 read=73728 decoded=73728 chunk=17 >>>> in=294912 read=73728 decoded=73728 chunk=18 >>>> mpg123_read() error (Error reading the stream. (code 18)) >>>> in=294912 read=73728 decoded=32256 chunk=19 >>>> fread() from file >>>> mpg123_feed() fill mpg123 buffer >>>> in=368640 read=73728 decoded=73728 chunk=20 >>>> in=368640 read=73728 decoded=73728 chunk=21 >>>> in=368640 read=73728 decoded=73728 chunk=22 >>>> in=368640 read=73728 decoded=73728 chunk=23 >>>> mpg123_read() error (Error reading the stream. (code 18)) >>>> in=368640 read=73728 decoded=27648 chunk=24 >> >> Notice the last chunk returned from mpg123_read() is truncating by a value >> of either 27648 or 32256 with error code 18. I swapped the coding approach >> to use mpg123_decode() but am seeing the same issue. >> >> The core of the C code w/o error handling is here. > > Hi Leonard > If you can attach the MP3 file in question or make it available > some other way, I'll see if my use of libmpg123 reads it OK. For your > C code, a whole example C file would be easier to debug. The only > thing that comes to mind from a quick inspection is that mh doesn't > know the FORMAT when mpg123_outblock is called, but I doubt it's that > or it wouldn't work at all. > Lastly, to see if it's libmpg123 that's unable to read the MP3 > file, or your use of libmpg123 that needs tweaking, you could see if > the mpg123 command reads the file OK. > > M Leonard Bocock leo...@gm... |