Skip to content

Commit e8f1c25

Browse files
author
Clement Champetier
committed
InputStreamAudio: fix decode
* Use av_samples_copy instead of av_samples_fill_arrays to copy the frame data to our DataBuffer. * Get nb_channels by the CodecContext, intead of av_get_channel_layout_nb_channels (see commit 1cdebe6). * Throw a more specific runtime_error if an error occured during audio decoding.
1 parent 423c28b commit e8f1c25

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/AvTranscoder/InputStreamAudio.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ bool InputStreamAudio::readNextFrame( AudioFrame& audioFrameBuffer )
122122

123123
if( ret < 0 )
124124
{
125-
throw std::runtime_error( "an error occured during audio decoding" );
125+
char err[250];
126+
av_strerror( ret, err, 250);
127+
128+
throw std::runtime_error( "an error occured during audio decoding" + std::string( err ) );
126129
}
127130

128131
av_free_packet( &packet );
@@ -135,15 +138,13 @@ bool InputStreamAudio::readNextFrame( AudioFrame& audioFrameBuffer )
135138
if( decodedSize )
136139
{
137140
if( audioFrameBuffer.getSize() != decodedSize )
138-
audioFrameBuffer.getBuffer().resize( decodedSize );
139-
140-
int nb_channels = av_get_channel_layout_nb_channels( *m_codecContext->codec->channel_layouts );
141+
audioFrameBuffer.getBuffer().resize( decodedSize, 0 );
141142

142143
unsigned char* dest = audioFrameBuffer.getPtr();
143-
av_samples_fill_arrays(&dest, m_frame->linesize,
144-
m_frame->data[0],
145-
nb_channels, m_frame->nb_samples,
146-
m_codecContext->sample_fmt, 1);
144+
int nb_channels = m_codecContext->channels;
145+
av_samples_copy(&dest, (uint8_t* const* )m_frame->data, 0,
146+
0, m_frame->nb_samples, nb_channels,
147+
m_codecContext->sample_fmt);
147148
}
148149

149150
return true;

0 commit comments

Comments
 (0)