Fix audio decoding for some formats, call avcodec_receive_frame until it returns nothing.

This commit is contained in:
Damiano Galassi committed 2016-08-19 11:28:26 +02:00
1 parent 0bcbe786c4
commit cf7fbd26fd
1 file changed
+11 -3
+11 -3
View File
@@ -361,7 +361,7 @@ static int resample(MP42DecodeContext *context, AVFrame *frame, uint8_t **output
return ret;
}
static int decode(MP42DecodeContext *context, MP42SampleBuffer *inSample, MP42SampleBuffer **outSample)
static int send_packet(MP42DecodeContext *context, MP42SampleBuffer *inSample)
{
int ret;
@@ -375,6 +375,12 @@ static int decode(MP42DecodeContext *context, MP42SampleBuffer *inSample, MP42Sa
printf("%s\n", av_err2str(ret));
return ret == AVERROR_EOF ? 0 : ret;
}
return ret;
}
static int receive_frame(MP42DecodeContext *context, MP42SampleBuffer **outSample)
{
int ret;
AVFrame *frame = av_frame_alloc();
ret = avcodec_receive_frame(context->avctx, frame);
@@ -393,7 +399,7 @@ static int decode(MP42DecodeContext *context, MP42SampleBuffer *inSample, MP42Sa
return ret;
}
return 0;
return ret;
}
static inline void enqueue(MP42AudioDecoder *self, MP42SampleBuffer *outSample)
@@ -423,7 +429,8 @@ static inline void enqueue(MP42AudioDecoder *self, MP42SampleBuffer *outSample)
return;
}
else {
decode(_context, sampleBuffer, &outSample);
send_packet(_context, sampleBuffer);
while (!receive_frame(_context, &outSample)) {
if (_context->configured == NO && outSample) {
[_outputUnit reconfigure];
_context->configured = YES;
@@ -434,5 +441,6 @@ static inline void enqueue(MP42AudioDecoder *self, MP42SampleBuffer *outSample)
}
}
}
}
@end