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 *****************************************************************************/
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
++) {
31 if (data
[i
+ 1] != 0xff) {
40 * Mxpeg frame format : http://developer.mobotix.com/docs/mxpeg_frame.html
42 static bool IsMxpeg(stream_t
*s
)
44 const uint8_t *header
;
45 int size
= vlc_stream_Peek(s
, &header
, 256);
48 if (find_jpeg_marker(&position
, header
, size
) != 0xd8 || position
> size
-2)
50 if (find_jpeg_marker(&position
, header
, position
+ 2) != 0xe0)
53 if (position
+ 2 > size
)
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
)
64 if( vlc_stream_Peek (s
, &header
, size
) < size
)
68 if ( !(header
[position
] == 0xFF && header
[position
+1] == 0xFE) )
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) )
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
)
82 position
+= header_size
;
83 if ( !(header
[position
] == 0xFF && header
[position
+1] == 0xFE) )
88 if (memcmp (&header
[position
], "MXF\0", 4) )