| 579 | } |
| 580 | |
| 581 | static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) { |
| 582 | int ret = AVERROR(EAGAIN); |
| 583 | |
| 584 | for (;;) { |
| 585 | if (d->queue->serial == d->pkt_serial) { |
| 586 | do { |
| 587 | if (d->queue->abort_request) |
| 588 | return -1; |
| 589 | |
| 590 | switch (d->avctx->codec_type) { |
| 591 | case AVMEDIA_TYPE_VIDEO: |
| 592 | ret = avcodec_receive_frame(d->avctx, frame); |
| 593 | if (ret >= 0) { |
| 594 | if (decoder_reorder_pts == -1) { |
| 595 | frame->pts = frame->best_effort_timestamp; |
| 596 | } else if (!decoder_reorder_pts) { |
| 597 | frame->pts = frame->pkt_dts; |
| 598 | } |
| 599 | } |
| 600 | break; |
| 601 | case AVMEDIA_TYPE_AUDIO: |
| 602 | ret = avcodec_receive_frame(d->avctx, frame); |
| 603 | if (ret >= 0) { |
| 604 | AVRational tb = (AVRational){1, frame->sample_rate}; |
| 605 | if (frame->pts != AV_NOPTS_VALUE) |
| 606 | frame->pts = av_rescale_q(frame->pts, d->avctx->pkt_timebase, tb); |
| 607 | else if (d->next_pts != AV_NOPTS_VALUE) |
| 608 | frame->pts = av_rescale_q(d->next_pts, d->next_pts_tb, tb); |
| 609 | if (frame->pts != AV_NOPTS_VALUE) { |
| 610 | d->next_pts = frame->pts + frame->nb_samples; |
| 611 | d->next_pts_tb = tb; |
| 612 | } |
| 613 | } |
| 614 | break; |
| 615 | } |
| 616 | if (ret == AVERROR_EOF) { |
| 617 | d->finished = d->pkt_serial; |
| 618 | avcodec_flush_buffers(d->avctx); |
| 619 | return 0; |
| 620 | } |
| 621 | if (ret >= 0) |
| 622 | return 1; |
| 623 | } while (ret != AVERROR(EAGAIN)); |
| 624 | } |
| 625 | |
| 626 | do { |
| 627 | if (d->queue->nb_packets == 0) |
| 628 | SDL_CondSignal(d->empty_queue_cond); |
| 629 | if (d->packet_pending) { |
| 630 | d->packet_pending = 0; |
| 631 | } else { |
| 632 | int old_serial = d->pkt_serial; |
| 633 | if (packet_queue_get(d->queue, d->pkt, 1, &d->pkt_serial) < 0) |
| 634 | return -1; |
| 635 | if (old_serial != d->pkt_serial) { |
| 636 | avcodec_flush_buffers(d->avctx); |
| 637 | d->finished = 0; |
| 638 | d->next_pts = d->start_pts; |
no test coverage detected