[mpg123-devel] [ mpg123-Feature Requests-3348882 ] Peek size of internal buffer
Brought to you by:
sobukus
From: SourceForge.net <no...@so...> - 2011-09-06 04:26:05
|
Feature Requests item #3348882, was opened at 2011-07-01 15:34 Message generated for change (Comment added) made by mtlung You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=733197&aid=3348882&group_id=135704 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: mpg123 Group: None Status: Open >Resolution: Fixed Priority: 5 Private: No Submitted By: Lung Man Tat (mtlung) Assigned to: Nobody/Anonymous (nobody) Summary: Peek size of internal buffer Initial Comment: Most of the time I use mpg123_decode() with fixed size pre-allocated input and output buffer Without a peek function to let me know how much buffer can be decoded without feeding new data, I will run into situations either: - Feed data faster than consumption --> mpg123 internal buffer get increase without bound, or - Peridoically invoke mpg123_read() --> having many tiny output buffer size, which will do no good (memory/performance) to my underlaying audio engine So I would suggest to have a function like int mpg123_peek_outbuffer(); May be there is some existing API that I can use to solve my problem I missed? ---------------------------------------------------------------------- >Comment By: Lung Man Tat (mtlung) Date: 2011-09-06 12:26 Message: It works! Thanks so much. Following is an example on how I use the new feature: long mpgInternalSize = 0; if(MPG123_OK != mpg123_getstate(mpg, MPG123_BUFFERFILL, &mpgInternalSize, NULL)) return false; char buf[chunkSize]; unsigned readCount = mpgInternalSize > _dataChunkSize ? 0 : myRead(buf, chunkSize); mpg123_decode(mpg, buf, readCount, ...); ---------------------------------------------------------------------- Comment By: Thomas Orgis (sobukus) Date: 2011-08-25 04:48 Message: Have a look at the current http://mpg123.org/snapshot and mpg123_getstate(handle, MPG123_BUFFERFILL, &value, NULL). Does that work for you? I hope so;-) ---------------------------------------------------------------------- Comment By: Lung Man Tat (mtlung) Date: 2011-07-19 12:27 Message: Yes, being able to get "number of bytes currently residing in the internal buffer" would definitely help. Although I make the wrong impression that the internal buffer is a decompressed one, but with statistic of input bytes, internal buffer bytes and audio sample produced, I should also able to perform optimal buffer size management. By the way, you comment seems to be cut off after "A simple approach for" ---------------------------------------------------------------------- Comment By: Thomas Orgis (sobukus) Date: 2011-07-18 19:39 Message: So basicaly, you want to know the number of input bytes needed for a certain number of ouptut bytes... which is where all the fun lies in variable-bitrate encoding;-) But OK, you limited the view a bit ... you want an extra function that tries to parse what's available in the internal buffer and reports the number of full frames/samples/bytes that would be available for immediate decoding. That's not available right now ... of course you could mpg123_scan() in advance and extract the frame index, which will give you the relation between input byte offsets and MPEG frames (thus, output sample offsets). But for generic streaming, where you cannot seek at will, this is obviously not applicable. Such functionality could be added, but developer time is very limited currently. What would be easier is to export the number of bytes currently residing in the internal buffer. With that, you could collect rather detailed statistics of consumed input bytes and produced output bytes, giving rise to optimal input/output buffer sizes that should avoid MPG123_NEED_MORE situations and also excessive overflow. Would that work for you? A simple approach for ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=733197&aid=3348882&group_id=135704 |