The program in question where this came up is the XMMS2 mpg123 decoder
plugin, written originally by sobukus. It opens the stream with
mpg123_open_feed and decodes the data with mpg123_decode directly from own
buffer.
The problem comes up when trying to use mpg123_length to find the length of
the MP3 file in samples. Sometimes it returns the correct values, but
sometimes it returns some weird negative values. The mpg123_length function
is defined as:
if(mh->track_samples > -1) length = mh->track_samples;
else if(mh->track_frames > 0) length = mh->track_frames*spf(mh);
else
{
/* A bad estimate. Ignoring tags 'n stuff. */
double bpf = mh->mean_framesize ? mh->mean_framesize :
compute_bpf(mh);
length = (off_t)((double)(mh->rdat.filelen)/bpf*spf(mh));
}
From these, track_samples is set if mpg123_scan if that is ever called. In
feed mode calling mpg123_scan is kind of useless, so that is never set.
Then the checked track_frames variable is gotten from the lame headers. It
turns out that files that have lame headers return the correct length
without problems, so this works.
Problems come from the bad estimate thing, it uses the value
(mh->rdat.filelen). This value is initialized in readers.c:mpg123_init
using the function get_fileinfo. However because the defined seek function
for feed mode is buffered_seek_frame and always returns READER_ERROR,
get_fileinfo always returns -1.
----------
Suggestions:
First of all, make the mpg123_length check if the mh->rdat.filelen is -1
and skip the estimation code in that case. This will avoid having some
weird -xxx return values from the function. Second of all, add some way to
be able to manually set the file length (that is, the mh->rdat.filelen
value) directly through the API.
If there's no way to set the file length, I guess I'm forced to rewrite the
whole plugin using mpg123_replace_reader and the low level I/O API. Then it
would work already, but I'm not very motivated to do that and the current
plugin works well otherwise...
Nobody/Anonymous
mpglib
1.5.0
Public
|
Date: 2008-08-28 18:35
|
|
Date: 2008-08-21 17:15
|
|
Date: 2008-08-21 09:27
|
| Field | Old Value | Date | By |
|---|---|---|---|
| status_id | Open | 2008-08-29 10:26 | sobukus |
| close_date | - | 2008-08-29 10:26 | sobukus |