FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/lmlm4.c
Date: 2026-05-02 03:33:10
Exec Total Coverage
Lines: 42 52 80.8%
Functions: 3 3 100.0%
Branches: 21 36 58.3%

Line Branch Exec Source
1 /*
2 * Linux Media Labs MPEG-4 demuxer
3 * Copyright (c) 2008 Ivo van Poorten
4 *
5 * Due to a lack of sample files, only files with one channel are supported.
6 * u-law and ADPCM audio are unsupported for the same reason.
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include "libavutil/attributes.h"
26 #include "libavutil/intreadwrite.h"
27
28 #include "avformat.h"
29 #include "demux.h"
30 #include "internal.h"
31
32 #define LMLM4_I_FRAME 0x00
33 #define LMLM4_P_FRAME 0x01
34 #define LMLM4_B_FRAME 0x02
35 #define LMLM4_INVALID 0x03
36 #define LMLM4_MPEG1L2 0x04
37
38 #define LMLM4_MAX_PACKET_SIZE 1024 * 1024
39
40 7480 static int lmlm4_probe(const AVProbeData *pd)
41 {
42 7480 const unsigned char *buf = pd->buf;
43 unsigned int frame_type, packet_size;
44
45 7480 frame_type = AV_RB16(buf + 2);
46 7480 packet_size = AV_RB32(buf + 4);
47
48
7/8
✓ Branch 0 taken 1443 times.
✓ Branch 1 taken 6037 times.
✓ Branch 2 taken 549 times.
✓ Branch 3 taken 894 times.
✓ Branch 4 taken 509 times.
✓ Branch 5 taken 40 times.
✓ Branch 6 taken 509 times.
✗ Branch 7 not taken.
7480 if (!AV_RB16(buf) && frame_type <= LMLM4_MPEG1L2 && packet_size &&
49
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 508 times.
509 frame_type != LMLM4_INVALID && packet_size <= LMLM4_MAX_PACKET_SIZE) {
50
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (frame_type == LMLM4_MPEG1L2) {
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if ((AV_RB16(buf + 8) & 0xfffe) != 0xfffc)
52 return 0;
53 /* I could calculate the audio framesize and compare with
54 * packet_size-8, but that seems overkill */
55 1 return AVPROBE_SCORE_MAX / 3;
56 } else if (AV_RB24(buf + 8) == 0x000001) { /* PES Signal */
57 return AVPROBE_SCORE_MAX / 5;
58 }
59 }
60
61 7479 return 0;
62 }
63
64 1 static int lmlm4_read_header(AVFormatContext *s)
65 {
66 AVStream *st;
67
68
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!(st = avformat_new_stream(s, NULL)))
69 return AVERROR(ENOMEM);
70 1 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
71 1 st->codecpar->codec_id = AV_CODEC_ID_MPEG4;
72 1 ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS;
73 1 avpriv_set_pts_info(st, 64, 1001, 30000);
74
75
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (!(st = avformat_new_stream(s, NULL)))
76 return AVERROR(ENOMEM);
77 1 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
78 1 st->codecpar->codec_id = AV_CODEC_ID_MP2;
79 1 ffstream(st)->need_parsing = AVSTREAM_PARSE_HEADERS;
80
81 /* the parameters will be extracted from the compressed bitstream */
82 1 return 0;
83 }
84
85 240 static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt)
86 {
87 240 AVIOContext *pb = s->pb;
88 int ret;
89 unsigned int frame_type, packet_size, padding, frame_size;
90
91 240 avio_rb16(pb); /* channel number */
92 240 frame_type = avio_rb16(pb);
93 240 packet_size = avio_rb32(pb);
94 240 padding = -packet_size & 511;
95
96
2/4
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 240 times.
240 if (frame_type > LMLM4_MPEG1L2 || frame_type == LMLM4_INVALID) {
97 av_log(s, AV_LOG_ERROR, "invalid or unsupported frame_type\n");
98 return AVERROR_INVALIDDATA;
99 }
100
2/4
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 240 times.
240 if (packet_size > LMLM4_MAX_PACKET_SIZE || packet_size<=8) {
101 av_log(s, AV_LOG_ERROR, "packet size %d is invalid\n", packet_size);
102 return AVERROR_INVALIDDATA;
103 }
104
105 240 frame_size = packet_size - 8;
106
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 240 times.
240 if ((ret = av_get_packet(pb, pkt, frame_size)) <= 0)
107 return ret < 0 ? ret : AVERROR_INVALIDDATA;
108
109 240 avio_skip(pb, padding);
110
111
3/4
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 148 times.
✗ Branch 3 not taken.
240 switch (frame_type) {
112 6 case LMLM4_I_FRAME:
113 6 pkt->flags = AV_PKT_FLAG_KEY;
114 av_fallthrough;
115 92 case LMLM4_P_FRAME:
116 case LMLM4_B_FRAME:
117 92 pkt->stream_index = 0;
118 92 break;
119 148 case LMLM4_MPEG1L2:
120 148 pkt->stream_index = 1;
121 148 break;
122 }
123
124 240 return ret;
125 }
126
127 const FFInputFormat ff_lmlm4_demuxer = {
128 .p.name = "lmlm4",
129 .p.long_name = NULL_IF_CONFIG_SMALL("raw lmlm4"),
130 .read_probe = lmlm4_probe,
131 .read_header = lmlm4_read_header,
132 .read_packet = lmlm4_read_packet,
133 };
134