FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/rawenc.c
Date: 2021-09-24 20:55:06
Exec Total Coverage
Lines: 21 31 67.7%
Branches: 6 24 25.0%

Line Branch Exec Source
1 /*
2 * Raw Video Encoder
3 * Copyright (c) 2001 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Raw Video Encoder
25 */
26
27 #include "avcodec.h"
28 #include "encode.h"
29 #include "raw.h"
30 #include "internal.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/intreadwrite.h"
33 #include "libavutil/imgutils.h"
34 #include "libavutil/internal.h"
35
36 4116 static av_cold int raw_encode_init(AVCodecContext *avctx)
37 {
38 4116 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
39
40 4116 avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc);
41
1/2
✓ Branch 0 taken 4116 times.
✗ Branch 1 not taken.
4116 if(!avctx->codec_tag)
42 4116 avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
43 4116 avctx->bit_rate = ff_guess_coded_bitrate(avctx);
44
45 4116 return 0;
46 }
47
48 77970 static int raw_encode(AVCodecContext *avctx, AVPacket *pkt,
49 const AVFrame *frame, int *got_packet)
50 {
51 77970 int ret = av_image_get_buffer_size(frame->format,
52 77970 frame->width, frame->height, 1);
53
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 77970 times.
77970 if (ret < 0)
55 return ret;
56
57
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 77970 times.
77970 if ((ret = ff_get_encode_buffer(avctx, pkt, ret, 0)) < 0)
58 return ret;
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 77970 times.
77970 if ((ret = av_image_copy_to_buffer(pkt->data, pkt->size,
60 77970 (const uint8_t **)frame->data, frame->linesize,
61 77970 frame->format,
62 77970 frame->width, frame->height, 1)) < 0)
63 return ret;
64
65
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 77970 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
77970 if(avctx->codec_tag == AV_RL32("yuv2") && ret > 0 &&
66 frame->format == AV_PIX_FMT_YUYV422) {
67 int x;
68 for(x = 1; x < frame->height*frame->width*2; x += 2)
69 pkt->data[x] ^= 0x80;
70
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 77970 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
77970 } else if (avctx->codec_tag == AV_RL32("b64a") && ret > 0 &&
71 frame->format == AV_PIX_FMT_RGBA64BE) {
72 uint64_t v;
73 int x;
74 for (x = 0; x < frame->height * frame->width; x++) {
75 v = AV_RB64(&pkt->data[8 * x]);
76 AV_WB64(&pkt->data[8 * x], v << 48 | v >> 16);
77 }
78 }
79 77970 pkt->flags |= AV_PKT_FLAG_KEY;
80 77970 *got_packet = 1;
81 77970 return 0;
82 }
83
84 const AVCodec ff_rawvideo_encoder = {
85 .name = "rawvideo",
86 .long_name = NULL_IF_CONFIG_SMALL("raw video"),
87 .type = AVMEDIA_TYPE_VIDEO,
88 .id = AV_CODEC_ID_RAWVIDEO,
89 .capabilities = AV_CODEC_CAP_DR1,
90 .init = raw_encode_init,
91 .encode2 = raw_encode,
92 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
93 };
94