blob: 5c555923221b53f434c49a4aec44163de3ebf29e [file] [log] [blame]
codeworkxf1be2fe2012-03-24 17:38:29 +01001/*
2 * Copyright@ Samsung Electronics Co. LTD
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "videodev2.h"
18
19#define JPEG_DEC_NODE "/dev/video11"
20#define JPEG_ENC_NODE "/dev/video12"
21
22#define JPEG_MAX_PLANE_CNT 3
23#define JPEG_DEC_OUT_BYTE_ALIGN 8
24
25//#define JPEG_PERF_MEAS
26
27#ifdef JPEG_PERF_MEAS
28#define JPEG_PERF_DEFINE(n) \
29 struct timeval time_start_##n, time_stop_##n; unsigned long log_time_##n = 0;
30
31#define JPEG_PERF_START(n) \
32 gettimeofday(&time_start_##n, NULL);
33
34#define JPEG_PERF_END(n) \
35 gettimeofday(&time_stop_##n, NULL); log_time_##n = measure_time(&time_start_##n, &time_stop_##n);
36
37#define JPEG_PERF(n) \
38 log_time_##n
39#else
40#define JPEG_PERF_DEFINE(n)
41#define JPEG_PERF_START(n)
42#define JPEG_PERF_END(n)
43#define JPEG_PERF(n)
44#endif
45
46enum jpeg_ret_type {
47 JPEG_FAIL,
48 JPEG_OK,
49 JPEG_ENCODE_FAIL,
50 JPEG_ENCODE_OK,
51 JPEG_DECODE_FAIL,
52 JPEG_DECODE_OK,
53 JPEG_OUT_OF_MEMORY,
54 JPEG_UNKNOWN_ERROR
55};
56
57enum jpeg_quality_level {
58 QUALITY_LEVEL_1 = 0, /* high */
59 QUALITY_LEVEL_2,
60 QUALITY_LEVEL_3,
61 QUALITY_LEVEL_4, /* low */
62};
63
64enum jpeg_mode {
65 JPEG_ENCODE,
66 JPEG_DECODE
67};
68
69struct jpeg_buf {
70 int num_planes;
71 void *start[JPEG_MAX_PLANE_CNT];
72 int length[JPEG_MAX_PLANE_CNT];
73 enum v4l2_memory memory;
74 enum v4l2_buf_type buf_type; // Caller need not set this
75};
76
77struct jpeg_buf_info {
78 int num_planes;
79 enum v4l2_memory memory;
80 enum v4l2_buf_type buf_type;
81 int reserved[4];
82};
83
84struct jpeg_pixfmt {
85 int in_fmt;
86 int out_fmt;
87 int reserved[4];
88};
89
90struct jpeg_config {
91 enum jpeg_mode mode;
92 enum jpeg_quality_level enc_qual; // for encoding
93
94 int width;
95 int height;
96
97 int num_planes;
98
99 int scaled_width; // 1/2, 1/4 scaling for decoding
100 int scaled_height; // 1/2, 1/4 scaling for decoding
101
102 int sizeJpeg;
103
104 union {
105 struct jpeg_pixfmt enc_fmt;
106 struct jpeg_pixfmt dec_fmt;
107 } pix;
108
109 int reserved[8];
110};
111
112#ifdef __cplusplus
113extern "C" {
114#endif
115int jpeghal_dec_init();
116int jpeghal_enc_init();
117
118int jpeghal_dec_setconfig(int fd, struct jpeg_config *config);
119int jpeghal_enc_setconfig(int fd, struct jpeg_config *config);
120int jpeghal_dec_getconfig(int fd, struct jpeg_config *config);
121int jpeghal_enc_getconfig(int fd, struct jpeg_config *config);
122
123int jpeghal_set_inbuf(int fd, struct jpeg_buf *buf);
124int jpeghal_set_outbuf(int fd, struct jpeg_buf *buf);
125
126int jpeghal_dec_exe(int fd, struct jpeg_buf *in_buf, struct jpeg_buf *out_buf);
127int jpeghal_enc_exe(int fd, struct jpeg_buf *in_buf, struct jpeg_buf *out_buf);
128
129int jpeghal_deinit(int fd, struct jpeg_buf *in_buf, struct jpeg_buf *out_buf);
130
131int jpeghal_s_ctrl(int fd, int cid, int value);
132int jpeghal_g_ctrl(int fd, int id);
133
134unsigned long measure_time(struct timeval *start, struct timeval *stop);
135#ifdef __cplusplus
136}
137#endif