decoder/ffmpeg: move code to pcm/Interleave.cxx

This commit is contained in:
Max Kellermann
2015-06-22 14:28:23 +02:00
parent 4dd2ad9b27
commit 142a9fe530
4 changed files with 87 additions and 19 deletions

View File

@@ -31,6 +31,7 @@
#include "../DecoderAPI.hxx"
#include "FfmpegMetaData.hxx"
#include "FfmpegIo.hxx"
#include "pcm/Interleave.hxx"
#include "tag/TagHandler.hxx"
#include "input/InputStream.hxx"
#include "CheckAudioFormat.hxx"
@@ -100,20 +101,6 @@ start_time_fallback(const AVStream &stream)
return FfmpegTimestampFallback(stream.start_time, 0);
}
static void
copy_interleave_frame2(uint8_t *dest, uint8_t **src,
unsigned nframes, unsigned nchannels,
unsigned sample_size)
{
for (unsigned frame = 0; frame < nframes; ++frame) {
for (unsigned channel = 0; channel < nchannels; ++channel) {
memcpy(dest, src[channel] + frame * sample_size,
sample_size);
dest += sample_size;
}
}
}
/**
* Copy PCM data from a non-empty AVFrame to an interleaved buffer.
*/
@@ -147,11 +134,11 @@ copy_interleave_frame(const AVCodecContext &codec_context,
return 0;
}
copy_interleave_frame2((uint8_t *)output_buffer,
frame.extended_data,
frame.nb_samples,
codec_context.channels,
av_get_bytes_per_sample(codec_context.sample_fmt));
PcmInterleave(output_buffer,
ConstBuffer<const void *>((const void *const*)frame.extended_data,
codec_context.channels),
frame.nb_samples,
av_get_bytes_per_sample(codec_context.sample_fmt));
} else {
output_buffer = frame.extended_data[0];
}