summaryrefslogtreecommitdiff
path: root/client/mjpeg_decoder.h
blob: f435f3f32041a7be8fa222a08fb807be40c6acbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
   Copyright (C) 2010 Red Hat, Inc.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _H_MJPEG_DECODER
#define _H_MJPEG_DECODER

#include "common.h"

#ifdef WIN32
/* We need some hacks to avoid warnings from the jpeg headers */
#define XMD_H
#undef FAR
#endif
extern "C" {
#include <jpeglib.h>
}

extern "C" {
    void mjpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes);
}

class MJpegDecoder {
public:
    MJpegDecoder(int width, int height, int stride,
                 uint8_t *frame);
    ~MJpegDecoder();

    bool decode_data(uint8_t *data, size_t length);

private:

    friend void mjpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes);

    void convert_scanline(void);
    void append_data(uint8_t *data, size_t length);

    struct jpeg_decompress_struct _cinfo;
    struct jpeg_error_mgr _jerr;
    struct jpeg_source_mgr _jsrc;

    uint8_t *_data;
    size_t _data_size;
    size_t _data_start;
    size_t _data_end;
    size_t _extra_skip;

    int _width;
    int _height;
    int _stride;
    uint8_t *_frame;

    int _y;
    uint8_t *_scanline;

    int _state;
};

#endif