1 /*****************************************************************************
2 * mxpeg_helper.h: MXPEG helper functions
3 *****************************************************************************
4 * Copyright (C) 2012 VLC authors and VideoLAN
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 *****************************************************************************/
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
++) {
32 if (data
[i
+ 1] != 0xff) {
41 * Mxpeg frame format : http://developer.mobotix.com/docs/mxpeg_frame.html
43 static bool IsMxpeg(stream_t
*s
)
45 const uint8_t *header
;
46 int size
= vlc_stream_Peek(s
, &header
, 256);
49 if (find_jpeg_marker(&position
, header
, size
) != 0xd8 || position
> size
-2)
51 if (find_jpeg_marker(&position
, header
, position
+ 2) != 0xe0)
54 if (position
+ 2 > size
)
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
)
65 if( vlc_stream_Peek (s
, &header
, size
) < size
)
69 if ( !(header
[position
] == 0xFF && header
[position
+1] == 0xFE) )
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) )
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
)
83 position
+= header_size
;
84 if ( !(header
[position
] == 0xFF && header
[position
+1] == 0xFE) )
89 if (memcmp (&header
[position
], "MXF\0", 4) )