| 287 | } |
| 288 | |
| 289 | static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt) |
| 290 | { |
| 291 | AVCodecInternal *avci = avctx->internal; |
| 292 | AVFrame *frame = avci->in_frame; |
| 293 | const FFCodec *const codec = ffcodec(avctx->codec); |
| 294 | int got_packet; |
| 295 | int ret; |
| 296 | |
| 297 | if (avci->draining_done) |
| 298 | return AVERROR_EOF; |
| 299 | |
| 300 | if (!frame->buf[0] && !avci->draining) { |
| 301 | av_frame_unref(frame); |
| 302 | ret = ff_encode_get_frame(avctx, frame); |
| 303 | if (ret < 0 && ret != AVERROR_EOF) |
| 304 | return ret; |
| 305 | } |
| 306 | |
| 307 | if (!frame->buf[0]) { |
| 308 | if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY || |
| 309 | avci->frame_thread_encoder)) |
| 310 | return AVERROR_EOF; |
| 311 | |
| 312 | // Flushing is signaled with a NULL frame |
| 313 | frame = NULL; |
| 314 | } |
| 315 | |
| 316 | got_packet = 0; |
| 317 | |
| 318 | av_assert0(codec->cb_type == FF_CODEC_CB_TYPE_ENCODE); |
| 319 | |
| 320 | #if CONFIG_FRAME_THREAD_ENCODER |
| 321 | if (avci->frame_thread_encoder) |
| 322 | /* This will unref frame. */ |
| 323 | ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet); |
| 324 | else |
| 325 | #endif |
| 326 | ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet); |
| 327 | |
| 328 | if (avci->draining && !got_packet) |
| 329 | avci->draining_done = 1; |
| 330 | |
| 331 | return ret; |
| 332 | } |
| 333 | |
| 334 | static int encode_simple_receive_packet(AVCodecContext *avctx, AVPacket *avpkt) |
| 335 | { |
no test coverage detected