decoder: remove unused variable
[vlc.git] / modules / demux / mxpeg_helper.h
blobea53dd52dab6fdf21934881bf3795532be2070fa
1 /*****************************************************************************
2 * mxpeg_helper.h: MXPEG helper functions
3 *****************************************************************************
4 * Copyright (C) 2012 VLC authors and VideoLAN
6 * Authors: Sébastien Escudier
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.
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.
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 *****************************************************************************/
23 /**
24 * Finds FF XX in the first size byte of data
26 static uint8_t find_jpeg_marker(int *position, const uint8_t *data, int size)
28 for (int i = *position; i + 1 < size; i++) {
29 if (data[i] != 0xff)
30 continue;
31 if (data[i + 1] != 0xff) {
32 *position = i + 2;
33 return data[i + 1];
36 return 0xff;
40 * Mxpeg frame format : http://developer.mobotix.com/docs/mxpeg_frame.html
41 * */
42 static bool IsMxpeg(stream_t *s)
44 const uint8_t *header;
45 int size = vlc_stream_Peek(s, &header, 256);
46 int position = 0;
48 if (find_jpeg_marker(&position, header, size) != 0xd8 || position > size-2)
49 return false;
50 if (find_jpeg_marker(&position, header, position + 2) != 0xe0)
51 return false;
53 if (position + 2 > size)
54 return false;
56 /* Skip this jpeg header */
57 uint32_t header_size = GetWBE(&header[position]);
58 position += header_size;
60 /* Get enough data to analyse the next header */
61 if (position + 6 > size)
63 size = position + 6;
64 if( vlc_stream_Peek (s, &header, size) < size )
65 return false;
68 if ( !(header[position] == 0xFF && header[position+1] == 0xFE) )
69 return false;
70 position += 2;
71 header_size = GetWBE (&header[position]);
73 /* Check if this is a MXF header. We may have a jpeg comment first */
74 if (!memcmp (&header[position+2], "MXF\0", 4) )
75 return true;
77 /* Skip the jpeg comment and find the MXF header after that */
78 size = position + header_size + 8; //8 = FF FE 00 00 M X F 00
79 if (vlc_stream_Peek(s, &header, size ) < size)
80 return false;
82 position += header_size;
83 if ( !(header[position] == 0xFF && header[position+1] == 0xFE) )
84 return false;
86 position += 4;
88 if (memcmp (&header[position], "MXF\0", 4) )
89 return false;
91 return true;