Share

mpg123

Tracker: Bugs

5 mpg123_length broken in open_feed mode - ID: 2064322
Last Update: Settings changed ( sobukus )

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...


Juho Vähä-Herttua ( juhovh ) - 2008-08-21 09:23

5

Closed

None

Nobody/Anonymous

mpglib

1.5.0

Public


Comments ( 3 )




Date: 2008-08-28 18:35
Sender: juhovh


Confirmed this to work now with the snapshot, thank you. This bug can be
closed, hope you can get the 1.5.1 released and into the debian
repositories too, the XMMS2 plugin depends on it now. :)


Date: 2008-08-21 17:15
Sender: sobukusProject AdminAccepting Donations


Added mpg123_set_filesize() to the API now... setting rdat.filelen .

Also, mpg123_length shall now return MPG123_ERR in a controlled way when
this or any better guess is missing.

Please check out http://mpg123.org/snapshot (and /api, of course) and tell
me if this works out for you.
Thanks for your work on the xmms2 plugin, btw.


Date: 2008-08-21 09:27
Sender: juhovh


Oh and by the way, I would suggest to redefine:

int mpg123_open_feed (mpg123_handle *mh)

into:

int mpg123_open_feed (mpg123_handle *mh, off_t filelen)

But this would break the backwards compatibility and be incompatible
with:

Let me emphasize that the policy for libmpg123 is to always stay backwards
compatible -- only additions are planned (and it's not yet planned to
change the plans;-).


Log in to comment.

Attached File

No Files Currently Attached

Changes ( 2 )

Field Old Value Date By
status_id Open 2008-08-29 10:26 sobukus
close_date - 2008-08-29 10:26 sobukus