FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/frmdec.c
Date: 2022-12-05 20:26:17
Exec Total Coverage
Lines: 5 39 12.8%
Functions: 1 3 33.3%
Branches: 7 26 26.9%

Line Branch Exec Source
1 /*
2 * Megalux Frame demuxer
3 * Copyright (c) 2010 Peter Ross <pross@xvid.org>
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 * Megalux Frame demuxer
25 */
26
27 #include "libavutil/imgutils.h"
28 #include "libavutil/intreadwrite.h"
29 #include "avformat.h"
30
31 static const enum AVPixelFormat frm_pix_fmt_tags[] = {
32 AV_PIX_FMT_RGB555,
33 AV_PIX_FMT_RGB0,
34 AV_PIX_FMT_RGB24,
35 AV_PIX_FMT_BGR0,
36 AV_PIX_FMT_BGRA,
37 };
38
39 typedef struct {
40 int count;
41 } FrmContext;
42
43 6782 static int frm_read_probe(const AVProbeData *p)
44 {
45
1/2
✓ Branch 0 taken 6782 times.
✗ Branch 1 not taken.
6782 if (p->buf_size > 8 &&
46
5/6
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 6722 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 59 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
6782 p->buf[0] == 'F' && p->buf[1] == 'R' && p->buf[2] == 'M' &&
47
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 AV_RL16(&p->buf[4]) && AV_RL16(&p->buf[6]))
48 return AVPROBE_SCORE_MAX / 4;
49 6782 return 0;
50 }
51
52 static int frm_read_header(AVFormatContext *avctx)
53 {
54 AVIOContext *pb = avctx->pb;
55 AVStream *st = avformat_new_stream(avctx, 0);
56 unsigned idx;
57
58 if (!st)
59 return AVERROR(ENOMEM);
60
61 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
62 st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
63 avio_skip(pb, 3);
64
65 idx = avio_r8(pb) - 1;
66 if (idx >= FF_ARRAY_ELEMS(frm_pix_fmt_tags))
67 return AVERROR_INVALIDDATA;
68 st->codecpar->format = frm_pix_fmt_tags[idx];
69
70 st->codecpar->codec_tag = 0;
71 st->codecpar->width = avio_rl16(pb);
72 st->codecpar->height = avio_rl16(pb);
73 return 0;
74 }
75
76 static int frm_read_packet(AVFormatContext *avctx, AVPacket *pkt)
77 {
78 FrmContext *s = avctx->priv_data;
79 AVCodecParameters *par = avctx->streams[0]->codecpar;
80 int packet_size, ret;
81
82 if (s->count)
83 return AVERROR_EOF;
84
85 packet_size = av_image_get_buffer_size(par->format, par->width, par->height, 1);
86 if (packet_size < 0)
87 return AVERROR_INVALIDDATA;
88
89 ret = av_get_packet(avctx->pb, pkt, packet_size);
90 if (ret < 0)
91 return ret;
92
93 if (par->format == AV_PIX_FMT_BGRA) {
94 int i;
95 for (i = 3; i + 1 <= pkt->size; i += 4)
96 pkt->data[i] = 0xFF - pkt->data[i];
97 }
98
99 pkt->stream_index = 0;
100 s->count++;
101
102 return 0;
103 }
104
105 const AVInputFormat ff_frm_demuxer = {
106 .name = "frm",
107 .priv_data_size = sizeof(FrmContext),
108 .long_name = NULL_IF_CONFIG_SMALL("Megalux Frame"),
109 .read_probe = frm_read_probe,
110 .read_header = frm_read_header,
111 .read_packet = frm_read_packet,
112 };
113