- /* Give this data provided there is some, and its time is sane */
- if (ct >= ContentTime() && data->frames() > 0) {
- audio->emit (film(), *stream, data, ct);
- }
+void
+FFmpegDecoder::decode_and_process_audio_packet (AVPacket* packet)
+{
+ auto stream = audio_stream_from_index (packet->stream_index);
+ if (!stream) {
+ return;
+ }
+
+ auto context = _codec_context[stream->index(_format_context)];
+
+ int r = avcodec_send_packet (context, packet);
+ if (r < 0) {
+ /* We could cope with AVERROR(EAGAIN) and re-send the packet but I think it should never happen.
+ * Likewise I think AVERROR_EOF should not happen.
+ */
+ if (_errors_to_ignore > 0) {
+ /* We see errors here after a seek, which is hopefully to be nothing to worry about */
+ --_errors_to_ignore;
+ LOG_GENERAL("Ignoring error %1 avcodec_send_packet after seek; will ignore %2 more", r, _errors_to_ignore);
+ return;
+ }
+ throw DecodeError (N_("avcodec_send_packet"), N_("FFmpegDecoder::decode_and_process_audio_packet"), r);
+ }
+
+ while (r >= 0) {
+ r = avcodec_receive_frame (context, _frame);
+ if (r == AVERROR(EAGAIN)) {
+ /* More input is required */
+ return;