MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / liboapve_encode

Function liboapve_encode

libavcodec/liboapvenc.c:478–533  ·  view source on GitHub ↗

* Encode raw data frame into APV packet * * @param[in] avctx codec context * @param[out] avpkt output AVPacket containing encoded data * @param[in] frame AVFrame containing the raw data to be encoded * @param[out] got_packet encoder sets to 0 or 1 to indicate that a * non-empty packet was returned in pkt * * @return 0 on success, negative error code on fai

Source from the content-addressed store, hash-verified

476 * @return 0 on success, negative error code on failure
477 */
478static int liboapve_encode(AVCodecContext *avctx, AVPacket *avpkt,
479 const AVFrame *frame, int *got_packet)
480{
481 ApvEncContext *apv = avctx->priv_data;
482 const oapve_cdesc_t *cdsc = &apv->cdsc;
483 oapv_frm_t *frm = &apv->ifrms.frm[FRM_IDX];
484 oapv_imgb_t *imgb = frm->imgb;
485 int ret;
486
487 if (avctx->width != frame->width || avctx->height != frame->height || avctx->pix_fmt != frame->format) {
488 av_log(avctx, AV_LOG_ERROR, "Dimension changes are not supported\n");
489 return AVERROR(EINVAL);
490 }
491
492 av_image_copy((uint8_t **)imgb->a, imgb->s, (const uint8_t **)frame->data, frame->linesize,
493 frame->format, frame->width, frame->height);
494
495 imgb->ts[0] = frame->pts;
496
497 frm->group_id = 1; // @todo FIX-ME : need to set properly in case of multi-frame
498 frm->pbu_type = OAPV_PBU_TYPE_PRIMARY_FRAME;
499
500 ret = oapve_encode(apv->id, &apv->ifrms, apv->mid, &apv->bitb, &apv->stat, NULL);
501 if (OAPV_FAILED(ret)) {
502 av_log(avctx, AV_LOG_ERROR, "oapve_encode() failed\n");
503 return AVERROR_EXTERNAL;
504 }
505
506 /* store bitstream */
507 if (OAPV_SUCCEEDED(ret) && apv->stat.write > 0) {
508 uint8_t *data = apv->bitb.addr;
509 int size = apv->stat.write;
510
511 // The encoder may return a "Raw bitstream" formatted AU, including au_size.
512 // Discard it as we only need the access_unit() structure.
513 if (size > 4 && AV_RB32(data) != APV_SIGNATURE) {
514 data += 4;
515 size -= 4;
516 }
517
518 ret = ff_get_encode_buffer(avctx, avpkt, size, 0);
519 if (ret < 0)
520 return ret;
521
522 memcpy(avpkt->data, data, size);
523 avpkt->pts = avpkt->dts = frame->pts;
524 avpkt->flags |= AV_PKT_FLAG_KEY;
525
526 if (cdsc->param[FRM_IDX].qp)
527 ff_encode_add_stats_side_data(avpkt, cdsc->param[FRM_IDX].qp * FF_QP2LAMBDA, NULL, 0, AV_PICTURE_TYPE_I);
528
529 *got_packet = 1;
530 }
531
532 return 0;
533}
534
535/**

Callers

nothing calls this directly

Calls 4

av_logFunction · 0.85
av_image_copyFunction · 0.85
ff_get_encode_bufferFunction · 0.85

Tested by

no test coverage detected