- /* fetch new packet or eof */
- ret = ff_decode_get_packet(avctx, &s->buffered_pkt);
- if (ret == AVERROR_EOF) {
- AVPacket null_pkt = { 0 };
- ret = ff_mediacodec_dec_send(avctx, s->ctx, &null_pkt);
- if (ret < 0)
+ /* try to flush any buffered packet data */
+ if (s->buffered_pkt.size > 0) {
+ ret = ff_mediacodec_dec_send(avctx, s->ctx, &s->buffered_pkt, false);
+ if (ret >= 0) {
+ s->buffered_pkt.size -= ret;
+ s->buffered_pkt.data += ret;
+ if (s->buffered_pkt.size <= 0) {
+ av_packet_unref(&s->buffered_pkt);
+ } else {
+ av_log(avctx, AV_LOG_WARNING,
+ "could not send entire packet in single input buffer (%d < %d)\n",
+ ret, s->buffered_pkt.size+ret);
+ }
+ } else if (ret < 0 && ret != AVERROR(EAGAIN)) {
+ return ret;
+ }
+
+ if (s->amlogic_mpeg2_api23_workaround && s->buffered_pkt.size <= 0) {
+ /* fallthrough to fetch next packet regardless of input buffer space */
+ } else {
+ /* poll for space again */
+ continue;
+ }
+ }
+
+ /* fetch new packet or eof */
+ ret = ff_decode_get_packet(avctx, &s->buffered_pkt);
+ if (ret == AVERROR_EOF) {
+ AVPacket null_pkt = { 0 };
+ ret = ff_mediacodec_dec_send(avctx, s->ctx, &null_pkt, true);
+ if (ret < 0)
+ return ret;
+ return ff_mediacodec_dec_receive(avctx, s->ctx, frame, true);
+ } else if (ret == AVERROR(EAGAIN) && s->ctx->current_input_buffer < 0) {
+ return ff_mediacodec_dec_receive(avctx, s->ctx, frame, true);
+ } else if (ret < 0) {