Coverage Report

Created: 2025-07-11 06:16

/src/vlc/modules/demux/mxpeg_helper.h
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
 * mxpeg_helper.h: MXPEG helper functions
3
 *****************************************************************************
4
 * Copyright (C) 2012 VLC authors and VideoLAN
5
 *
6
 * Authors: Sébastien Escudier
7
 *
8
 * This program is free software; you can redistribute it and/or modify it
9
 * under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation; either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program; if not, write to the Free Software Foundation,
20
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21
 *****************************************************************************/
22
23
/**
24
 * Finds FF XX in the first size byte of data
25
 */
26
static uint8_t find_jpeg_marker(int *position, const uint8_t *data, int size)
27
0
{
28
0
    for (int i = *position; i + 1 < size; i++) {
29
0
        if (data[i] != 0xff)
30
0
            continue;
31
0
        if (data[i + 1] != 0xff) {
32
0
            *position = i + 2;
33
0
            return data[i + 1];
34
0
        }
35
0
    }
36
0
    return 0xff;
37
0
}
38
39
/*
40
 * Mxpeg frame format : http://developer.mobotix.com/docs/mxpeg_frame.html
41
 * */
42
static bool IsMxpeg(stream_t *s)
43
0
{
44
0
    const uint8_t *header;
45
0
    int size = vlc_stream_Peek(s, &header, 256);
46
0
    int position = 0;
47
48
0
    if (find_jpeg_marker(&position, header, size) != 0xd8 || position > size-2)
49
0
        return false;
50
0
    if (find_jpeg_marker(&position, header, position + 2) != 0xe0)
51
0
        return false;
52
53
0
    if (position + 2 > size)
54
0
        return false;
55
56
    /* Skip this jpeg header */
57
0
    uint32_t header_size = GetWBE(&header[position]);
58
0
    position += header_size;
59
60
    /* Get enough data to analyse the next header */
61
0
    if (position + 6 > size)
62
0
    {
63
0
        size = position + 6;
64
0
        if( vlc_stream_Peek (s, &header, size) < size )
65
0
            return false;
66
0
    }
67
68
0
    if ( !(header[position] == 0xFF && header[position+1] == 0xFE) )
69
0
        return false;
70
0
    position += 2;
71
0
    header_size = GetWBE (&header[position]);
72
73
    /* Check if this is a MXF header. We may have a jpeg comment first */
74
0
    if (!memcmp (&header[position+2], "MXF\0", 4) )
75
0
        return true;
76
77
    /* Skip the jpeg comment and find the MXF header after that */
78
0
    size = position + header_size + 8; //8 = FF FE 00 00 M X F 00
79
0
    if (vlc_stream_Peek(s, &header, size ) < size)
80
0
        return false;
81
82
0
    position += header_size;
83
0
    if ( !(header[position] == 0xFF && header[position+1] == 0xFE) )
84
0
        return false;
85
86
0
    position += 4;
87
88
0
    if (memcmp (&header[position], "MXF\0", 4) )
89
0
        return false;
90
91
0
    return true;
92
0
}