| 469 | } |
| 470 | |
| 471 | static int oh_encode_send_sw_frame(AVCodecContext *avctx, OHBufferQueueItem *input) |
| 472 | { |
| 473 | OHCodecEncContext *s = avctx->priv_data; |
| 474 | AVFrame *frame = s->frame; |
| 475 | OH_AVErrCode err; |
| 476 | int ret; |
| 477 | |
| 478 | if (!s->got_stream_info) { |
| 479 | // This shouldn't happen, add a warning message. |
| 480 | av_log(avctx, AV_LOG_WARNING, |
| 481 | "decoder didn't notify stream info, try get format explicitly\n"); |
| 482 | |
| 483 | OH_AVFormat *format = OH_VideoEncoder_GetOutputDescription(s->enc); |
| 484 | if (!format) { |
| 485 | av_log(avctx, AV_LOG_ERROR, "GetOutputDescription failed\n"); |
| 486 | return AVERROR_EXTERNAL; |
| 487 | } |
| 488 | |
| 489 | oh_encode_on_stream_changed(s->enc, format, avctx); |
| 490 | OH_AVFormat_Destroy(format); |
| 491 | if (!s->got_stream_info) |
| 492 | return AVERROR_EXTERNAL; |
| 493 | } |
| 494 | |
| 495 | if (!frame->buf[0] && !s->eof_sent) { |
| 496 | OH_AVCodecBufferAttr attr = { |
| 497 | .flags = AVCODEC_BUFFER_FLAGS_EOS, |
| 498 | }; |
| 499 | err = OH_AVBuffer_SetBufferAttr(input->buffer, &attr); |
| 500 | if (err != AV_ERR_OK) |
| 501 | return ff_oh_err_to_ff_err(err); |
| 502 | err = OH_VideoEncoder_PushInputBuffer(s->enc, input->index); |
| 503 | if (err != AV_ERR_OK) |
| 504 | return ff_oh_err_to_ff_err(err); |
| 505 | s->eof_sent = true; |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | uint8_t *p = OH_AVBuffer_GetAddr(input->buffer); |
| 510 | int32_t n = OH_AVBuffer_GetCapacity(input->buffer); |
| 511 | if (!p || n <= 0) { |
| 512 | av_log(avctx, AV_LOG_ERROR, |
| 513 | "Failed to get buffer addr (%p) or capacity (%d)\n", |
| 514 | p, n); |
| 515 | return AVERROR_EXTERNAL; |
| 516 | } |
| 517 | |
| 518 | uint8_t *dst[4] = {0}; |
| 519 | int dst_linesizes[4] = {0}; |
| 520 | ret = av_image_fill_linesizes(dst_linesizes, frame->format, s->stride); |
| 521 | if (ret < 0) |
| 522 | return ret; |
| 523 | ret = av_image_fill_pointers(dst, frame->format, s->slice_height, p, |
| 524 | dst_linesizes); |
| 525 | if (ret < 0) |
| 526 | return ret; |
| 527 | |
| 528 | av_image_copy2(dst, dst_linesizes, frame->data, frame->linesize, |
no test coverage detected