summaryrefslogtreecommitdiff
path: root/common_video/jpeg/data_manager.cc
blob: 72380e7c1f68483d2b891543f36cbc263ad71fc6 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "webrtc/common_video/jpeg/data_manager.h"

namespace webrtc
{

typedef struct
{
    jpeg_source_mgr  mgr;
    JOCTET* next_input_byte;
    size_t bytes_in_buffer;      /* # of byte spaces remaining in buffer */
} DataSrcMgr;

void
jpegSetSrcBuffer(j_decompress_ptr cinfo, JOCTET* srcBuffer, size_t bufferSize)
{
    DataSrcMgr* src;
    if (cinfo->src == NULL)
    {  /* first time for this JPEG object? */
        cinfo->src = (struct jpeg_source_mgr *)
                   (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
                       JPOOL_PERMANENT, sizeof(DataSrcMgr));
    }

    // Setting required functionality
    src = (DataSrcMgr*) cinfo->src;
    src->mgr.init_source = initSrc;;
    src->mgr.fill_input_buffer = fillInputBuffer;
    src->mgr.skip_input_data = skipInputData;
    src->mgr.resync_to_restart = jpeg_resync_to_restart; // use default
    src->mgr.term_source = termSource;
    // setting buffer/src
    src->bytes_in_buffer = bufferSize;
    src->next_input_byte = srcBuffer;

}


void
initSrc(j_decompress_ptr cinfo)
{
    DataSrcMgr  *src = (DataSrcMgr*)cinfo->src;
    src->mgr.next_input_byte = src->next_input_byte;
    src->mgr.bytes_in_buffer = src->bytes_in_buffer;
}

boolean
fillInputBuffer(j_decompress_ptr cinfo)
{
    return false;
}


void
skipInputData(j_decompress_ptr cinfo, long num_bytes)
{
    DataSrcMgr* src = (DataSrcMgr*)cinfo->src;
    if (num_bytes > 0)
    {
          if ((unsigned long)num_bytes > src->mgr.bytes_in_buffer)
              src->mgr.bytes_in_buffer = 0;
          else
          {
              src->mgr.next_input_byte += num_bytes;
              src->mgr.bytes_in_buffer -= num_bytes;
          }
    }
}


void
termSource (j_decompress_ptr cinfo)
{
  //
}

} // end of namespace webrtc