| 858 | } |
| 859 | |
| 860 | int encoder_thread(void *arg) |
| 861 | { |
| 862 | OutputStream *ost = arg; |
| 863 | Encoder *e = ost->enc; |
| 864 | EncoderPriv *ep = ep_from_enc(e); |
| 865 | EncoderThread et; |
| 866 | int ret = 0, input_status = 0; |
| 867 | int name_set = 0; |
| 868 | |
| 869 | ret = enc_thread_init(&et); |
| 870 | if (ret < 0) |
| 871 | goto finish; |
| 872 | |
| 873 | /* Open the subtitle encoders immediately. AVFrame-based encoders |
| 874 | * are opened through a callback from the scheduler once they get |
| 875 | * their first frame |
| 876 | * |
| 877 | * N.B.: because the callback is called from a different thread, |
| 878 | * enc_ctx MUST NOT be accessed before sch_enc_receive() returns |
| 879 | * for the first time for audio/video. */ |
| 880 | if (ost->type != AVMEDIA_TYPE_VIDEO && ost->type != AVMEDIA_TYPE_AUDIO) { |
| 881 | ret = enc_open(ost, NULL); |
| 882 | if (ret < 0) |
| 883 | goto finish; |
| 884 | } |
| 885 | |
| 886 | while (!input_status) { |
| 887 | input_status = sch_enc_receive(ep->sch, ep->sch_idx, et.frame); |
| 888 | if (input_status < 0) { |
| 889 | if (input_status == AVERROR_EOF) { |
| 890 | av_log(e, AV_LOG_VERBOSE, "Encoder thread received EOF\n"); |
| 891 | if (ep->opened) |
| 892 | break; |
| 893 | |
| 894 | av_log(e, AV_LOG_ERROR, "Could not open encoder before EOF\n"); |
| 895 | ret = AVERROR(EINVAL); |
| 896 | } else { |
| 897 | av_log(e, AV_LOG_ERROR, "Error receiving a frame for encoding: %s\n", |
| 898 | av_err2str(ret)); |
| 899 | ret = input_status; |
| 900 | } |
| 901 | goto finish; |
| 902 | } |
| 903 | |
| 904 | if (!name_set) { |
| 905 | enc_thread_set_name(ost); |
| 906 | name_set = 1; |
| 907 | } |
| 908 | |
| 909 | ret = frame_encode(ost, et.frame, et.pkt); |
| 910 | |
| 911 | av_packet_unref(et.pkt); |
| 912 | av_frame_unref(et.frame); |
| 913 | |
| 914 | if (ret < 0) { |
| 915 | if (ret == AVERROR_EOF) |
| 916 | av_log(e, AV_LOG_VERBOSE, "Encoder returned EOF, finishing\n"); |
| 917 | else |
nothing calls this directly
no test coverage detected