ffmpeg: fixing ffmpeg_send_packet to allow multipackets

This commit is contained in:
Viliam Mateicka 2008-12-15 18:35:34 +01:00 committed by Max Kellermann
parent 8a412aaa27
commit 88ab54d3d4

View File

@ -208,30 +208,46 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
AVCodecContext *codec_context, AVCodecContext *codec_context,
const AVRational *time_base) const AVRational *time_base)
{ {
enum decoder_command cmd = DECODE_COMMAND_NONE;
int position; int position;
uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2]; uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
int len, audio_size; int len, audio_size;
uint8_t *packet_data;
int packet_size;
position = av_rescale_q(packet->pts, *time_base, packet_data = packet->data;
(AVRational){1, 1}); packet_size = packet->size;
while ((packet_size > 0) && (cmd == DECODE_COMMAND_NONE)) {
audio_size = sizeof(audio_buf); audio_size = sizeof(audio_buf);
len = avcodec_decode_audio2(codec_context, len = avcodec_decode_audio2(codec_context,
(int16_t *)audio_buf, (int16_t *)audio_buf,
&audio_size, &audio_size,
packet->data, packet->size); packet_data, packet_size);
position = av_rescale_q(packet->pts, *time_base,
(AVRational){1, 1});
if (len < 0) { if (len < 0) {
g_message("skipping frame\n"); /* if error, we skip the frame */
return decoder_get_command(decoder); g_message("decoding failed\n");
break;
} }
assert(audio_size >= 0); packet_data += len;
packet_size -= len;
return decoder_data(decoder, is, if (audio_size <= 0) {
g_message("no audio frame\n");
continue;
}
cmd = decoder_data(decoder, is,
audio_buf, audio_size, audio_buf, audio_size,
position, position,
codec_context->bit_rate / 1000, NULL); codec_context->bit_rate / 1000, NULL);
}
return cmd;
} }
static bool static bool