Commit a7877a29 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

aout: rework aout_Interleave()

This no longer assumes that planes are contiguous. It should help with
libav reference counting, and also avoids interleaving unused padding.
parent f0fa97b3
......@@ -195,8 +195,9 @@ VLC_API unsigned aout_CheckChannelReorder( const uint32_t *, const uint32_t *,
uint32_t mask, uint8_t *table );
VLC_API void aout_ChannelReorder(void *, size_t, unsigned, const uint8_t *, vlc_fourcc_t);
VLC_API void aout_Interleave(void *dst, const void *src, unsigned samples,
unsigned channels, vlc_fourcc_t fourcc);
VLC_API void aout_Interleave(void *dst, const void *const *planes,
unsigned samples, unsigned channels,
vlc_fourcc_t fourcc);
VLC_API void aout_Deinterleave(void *dst, const void *src, unsigned samples,
unsigned channels, vlc_fourcc_t fourcc);
......
......@@ -340,9 +340,13 @@ block_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
block_t *p_buffer = block_Alloc( p_block->i_buffer );
if( unlikely(p_buffer == NULL) )
goto drop;
aout_Interleave( p_buffer->p_buffer, p_block->p_buffer,
p_block->i_nb_samples, ctx->channels,
p_dec->fmt_out.audio.i_format );
const void *planes[ctx->channels];
for( int i = 0; i < ctx->channels; i++)
planes[i] = frame.extended_data[i];
aout_Interleave( p_buffer->p_buffer, planes, frame.nb_samples,
ctx->channels, p_dec->fmt_out.audio.i_format );
if( ctx->channels > AV_NUM_DATA_POINTERS )
free( frame.extended_data );
block_Release( p_block );
......
......@@ -343,21 +343,21 @@ do { \
/**
* Interleaves audio samples within a block of samples.
* \param dst destination buffer for interleaved samples
* \param src source buffer with consecutive planes of samples
* \param srcv source buffers (one per plane) of uninterleaved samples
* \param samples number of samples (per channel/per plane)
* \param chans channels/planes count
* \param fourcc sample format (must be a linear sample format)
* \note The samples must be naturally aligned in memory.
* \warning Destination and source buffers MUST NOT overlap.
*/
void aout_Interleave( void *restrict dst, const void *restrict src,
void aout_Interleave( void *restrict dst, const void *const *srcv,
unsigned samples, unsigned chans, vlc_fourcc_t fourcc )
{
#define INTERLEAVE_TYPE(type) \
do { \
type *d = dst; \
const type *s = src; \
for( size_t i = 0; i < chans; i++ ) { \
const type *s = srcv[i]; \
for( size_t j = 0, k = 0; j < samples; j++, k += chans ) \
d[k] = *(s++); \
d++; \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment