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

Function smc_encode_frame

libavcodec/smcenc.c:531–581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

529}
530
531static int smc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
532 const AVFrame *frame, int *got_packet)
533{
534 SMCContext *s = avctx->priv_data;
535 const AVFrame *pict = frame;
536 PutByteContext pb;
537 uint8_t *pal;
538 int ret;
539
540 ret = ff_alloc_packet(avctx, pkt, 8LL * avctx->height * avctx->width);
541 if (ret < 0)
542 return ret;
543
544 if (avctx->gop_size == 0 || !s->prev_frame->data[0] ||
545 (avctx->frame_num % avctx->gop_size) == 0) {
546 s->key_frame = 1;
547 } else {
548 s->key_frame = 0;
549 }
550
551 bytestream2_init_writer(&pb, pkt->data, pkt->size);
552
553 bytestream2_put_be32(&pb, 0x00);
554
555 pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE);
556 if (!pal)
557 return AVERROR(ENOMEM);
558 memcpy(pal, frame->data[1], AVPALETTE_SIZE);
559
560 smc_encode_stream(s, pict, &pb);
561
562 av_shrink_packet(pkt, bytestream2_tell_p(&pb));
563
564 pkt->data[0] = 0x0;
565
566 // write chunk length
567 AV_WB24(pkt->data + 1, pkt->size);
568
569 ret = av_frame_replace(s->prev_frame, frame);
570 if (ret < 0) {
571 av_log(avctx, AV_LOG_ERROR, "cannot add reference\n");
572 return ret;
573 }
574
575 if (s->key_frame)
576 pkt->flags |= AV_PKT_FLAG_KEY;
577
578 *got_packet = 1;
579
580 return 0;
581}
582
583static av_cold int smc_encode_end(AVCodecContext *avctx)
584{

Callers

nothing calls this directly

Calls 8

ff_alloc_packetFunction · 0.85
bytestream2_init_writerFunction · 0.85
av_packet_new_side_dataFunction · 0.85
smc_encode_streamFunction · 0.85
av_shrink_packetFunction · 0.85
bytestream2_tell_pFunction · 0.85
av_frame_replaceFunction · 0.85
av_logFunction · 0.85

Tested by

no test coverage detected