| 639 | } |
| 640 | |
| 641 | static int transcode_subtitles(DecoderPriv *dp, const AVPacket *pkt, |
| 642 | AVFrame *frame) |
| 643 | { |
| 644 | AVPacket *flush_pkt = NULL; |
| 645 | AVSubtitle subtitle; |
| 646 | int got_output; |
| 647 | int ret; |
| 648 | |
| 649 | if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_SUB_HEARTBEAT) { |
| 650 | frame->pts = pkt->pts; |
| 651 | frame->time_base = pkt->time_base; |
| 652 | frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_SUB_HEARTBEAT; |
| 653 | |
| 654 | ret = sch_dec_send(dp->sch, dp->sch_idx, 0, frame); |
| 655 | return ret == AVERROR_EOF ? AVERROR_EXIT : ret; |
| 656 | } else if (pkt && (intptr_t)pkt->opaque == PKT_OPAQUE_FIX_SUB_DURATION) { |
| 657 | return fix_sub_duration_heartbeat(dp, av_rescale_q(pkt->pts, pkt->time_base, |
| 658 | AV_TIME_BASE_Q)); |
| 659 | } |
| 660 | |
| 661 | if (!pkt) { |
| 662 | flush_pkt = av_packet_alloc(); |
| 663 | if (!flush_pkt) |
| 664 | return AVERROR(ENOMEM); |
| 665 | } |
| 666 | |
| 667 | ret = avcodec_decode_subtitle2(dp->dec_ctx, &subtitle, &got_output, |
| 668 | pkt ? pkt : flush_pkt); |
| 669 | av_packet_free(&flush_pkt); |
| 670 | |
| 671 | if (ret < 0) { |
| 672 | av_log(dp, AV_LOG_ERROR, "Error decoding subtitles: %s\n", |
| 673 | av_err2str(ret)); |
| 674 | dp->dec.decode_errors++; |
| 675 | return exit_on_error ? ret : 0; |
| 676 | } |
| 677 | |
| 678 | if (!got_output) |
| 679 | return pkt ? 0 : AVERROR_EOF; |
| 680 | |
| 681 | dp->dec.frames_decoded++; |
| 682 | |
| 683 | // XXX the queue for transferring data to consumers runs |
| 684 | // on AVFrames, so we wrap AVSubtitle in an AVBufferRef and put that |
| 685 | // inside the frame |
| 686 | // eventually, subtitles should be switched to use AVFrames natively |
| 687 | ret = subtitle_wrap_frame(frame, &subtitle, 0); |
| 688 | if (ret < 0) { |
| 689 | avsubtitle_free(&subtitle); |
| 690 | return ret; |
| 691 | } |
| 692 | |
| 693 | frame->width = dp->dec_ctx->width; |
| 694 | frame->height = dp->dec_ctx->height; |
| 695 | |
| 696 | return process_subtitle(dp, frame); |
| 697 | } |
| 698 |
no test coverage detected