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