fixed buffer size format negotiation
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6810 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f19cd99782
commit
fd8c0a5cca
@ -15,9 +15,10 @@
|
||||
#define DECODE_BUFFER_SIZE (32 * 1024)
|
||||
|
||||
inline size_t
|
||||
AudioBufferSize(int32 channel_count, uint32 sample_format, float frame_rate, bigtime_t buffer_duration = 50000 /* 50 ms */)
|
||||
AudioBufferSize(const media_raw_audio_format &raf, bigtime_t buffer_duration = 50000 /* 50 ms */)
|
||||
{
|
||||
return (sample_format & 0xf) * channel_count * (size_t)((frame_rate * buffer_duration) / 1000000.0);
|
||||
return (raf.format & 0xf) * (raf.channel_count)
|
||||
* (size_t)((raf.frame_rate * buffer_duration) / 1000000.0);
|
||||
}
|
||||
|
||||
// bit_rate_table[mpeg_version_index][layer_index][bitrate_index]
|
||||
@ -129,18 +130,17 @@ mp3Decoder::NegotiateOutputFormat(media_format *ioDecodedFormat)
|
||||
ioDecodedFormat->type = B_MEDIA_RAW_AUDIO;
|
||||
ioDecodedFormat->u.raw_audio.frame_rate = fFrameRate;
|
||||
ioDecodedFormat->u.raw_audio.channel_count = fChannelCount;
|
||||
ioDecodedFormat->u.raw_audio.format = media_raw_audio_format::B_AUDIO_SHORT; // XXX should support other formats, too
|
||||
ioDecodedFormat->u.raw_audio.byte_order = B_MEDIA_HOST_ENDIAN; // XXX should support other endain, too
|
||||
if (ioDecodedFormat->u.raw_audio.buffer_size < 512 || ioDecodedFormat->u.raw_audio.buffer_size > 65536)
|
||||
ioDecodedFormat->u.raw_audio.buffer_size = AudioBufferSize(
|
||||
fChannelCount,
|
||||
ioDecodedFormat->u.raw_audio.format,
|
||||
fFrameRate);
|
||||
ioDecodedFormat->u.raw_audio.format = media_raw_audio_format::B_AUDIO_SHORT;
|
||||
ioDecodedFormat->u.raw_audio.byte_order = B_MEDIA_HOST_ENDIAN;
|
||||
|
||||
int frame_size = (ioDecodedFormat->u.raw_audio.format & 0xf) * ioDecodedFormat->u.raw_audio.channel_count;
|
||||
if (ioDecodedFormat->u.raw_audio.buffer_size == 0 || (ioDecodedFormat->u.raw_audio.buffer_size % frame_size) != 0)
|
||||
ioDecodedFormat->u.raw_audio.buffer_size = AudioBufferSize(ioDecodedFormat->u.raw_audio);
|
||||
if (ioDecodedFormat->u.raw_audio.channel_mask == 0)
|
||||
ioDecodedFormat->u.raw_audio.channel_mask = (fChannelCount == 1) ? B_CHANNEL_LEFT : B_CHANNEL_LEFT | B_CHANNEL_RIGHT;
|
||||
|
||||
// setup rest of the needed variables
|
||||
fFrameSize = (ioDecodedFormat->u.raw_audio.format & 0xf) * fChannelCount;
|
||||
fFrameSize = frame_size;
|
||||
fOutputBufferSize = ioDecodedFormat->u.raw_audio.buffer_size;
|
||||
|
||||
return B_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user