| 143 | } |
| 144 | |
| 145 | static int process_frame(DecodeContext *dc, AVFrame *frame) |
| 146 | { |
| 147 | PrivData *pd = dc->opaque; |
| 148 | int ret; |
| 149 | |
| 150 | if (!avcodec_is_open(pd->enc)) { |
| 151 | if (!frame) { |
| 152 | fprintf(stderr, "No input frames were decoded\n"); |
| 153 | return AVERROR_INVALIDDATA; |
| 154 | } |
| 155 | |
| 156 | pd->enc->width = frame->width; |
| 157 | pd->enc->height = frame->height; |
| 158 | pd->enc->pix_fmt = frame->format; |
| 159 | pd->enc->thread_count = dc->decoder->thread_count; |
| 160 | pd->enc->thread_type = dc->decoder->thread_type; |
| 161 | |
| 162 | // real timestamps do not matter for this test, so we just |
| 163 | // pretend the input is 25fps CFR to avoid any timestamp issues |
| 164 | pd->enc->time_base = (AVRational){ 1, 25 }; |
| 165 | |
| 166 | ret = avcodec_open2(pd->enc, NULL, NULL); |
| 167 | if (ret < 0) { |
| 168 | fprintf(stderr, "Error opening the encoder\n"); |
| 169 | return ret; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if (frame) { |
| 174 | frame->pts = pd->pts_in++; |
| 175 | |
| 176 | // avoid forcing coded frame type |
| 177 | frame->pict_type = AV_PICTURE_TYPE_NONE; |
| 178 | } |
| 179 | |
| 180 | ret = avcodec_send_frame(pd->enc, frame); |
| 181 | if (ret == AVERROR_EOF && !frame) |
| 182 | return 0; |
| 183 | if (ret < 0) { |
| 184 | fprintf(stderr, "Error submitting a frame for encoding\n"); |
| 185 | return ret; |
| 186 | } |
| 187 | |
| 188 | while (1) { |
| 189 | AVPacket *pkt = pd->pkt; |
| 190 | |
| 191 | ret = avcodec_receive_packet(pd->enc, pkt); |
| 192 | if (ret == AVERROR(EAGAIN)) |
| 193 | break; |
| 194 | else if (ret == AVERROR_EOF) |
| 195 | pkt = NULL; |
| 196 | else if (ret < 0) { |
| 197 | fprintf(stderr, "Error receiving a frame from the encoder\n"); |
| 198 | return ret; |
| 199 | } |
| 200 | |
| 201 | if (pkt) { |
| 202 | ret = recon_frame_process(pd, pkt); |
nothing calls this directly
no test coverage detected