summaryrefslogtreecommitdiff
path: root/src/camera_internal.c
blob: 7fc9b72d33dbb399c45d972bd0cfd734a9acda7e (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*
 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mm.h>
#include <mm_types.h>
#include <camera_internal.h>
#include <camera_private.h>
#include <dlog.h>

#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "TIZEN_N_CAMERA"


//LCOV_EXCL_START
int __set_level(camera_h camera, muse_camera_api_e api, int level)
{
	int ret = CAMERA_ERROR_NONE;
	camera_cli_s *pc = (camera_cli_s *)camera;
	camera_msg_param param;

	if (!pc || !pc->cb_info) {
		CAM_LOG_ERROR("NULL handle - api[%d]", api);
		return CAMERA_ERROR_INVALID_PARAMETER;
	}

	CAM_LOG_INFO("Enter - api[%d], level[%d]", api, level);

	CAMERA_MSG_PARAM_SET(param, INT, level);

	_camera_msg_send_param1(api, pc->cb_info, &ret, &param, CAMERA_CB_TIMEOUT);

	CAM_LOG_INFO("ret : 0x%x", ret);

	return ret;
}


int camera_start_evas_rendering(camera_h camera)
{
	return _camera_start_evas_rendering(camera);
}


int camera_stop_evas_rendering(camera_h camera, bool keep_screen)
{
	return _camera_stop_evas_rendering(camera, keep_screen);
}


int camera_set_ecore_wl_display(camera_h camera, void *ecore_wl_window)
{
	return _camera_set_display(camera, MM_DISPLAY_TYPE_OVERLAY_EXT, ecore_wl_window);
}
//LCOV_EXCL_STOP


void camera_create_preview_frame(MMCamcorderVideoStreamDataType *stream, int num_buffer_fd,
	tbm_bo_handle *buffer_bo_handle, tbm_bo_handle *data_bo_handle, camera_preview_data_s *frame)
{
	int total_size = 0;
	unsigned char *buf_pos = NULL;

	if (!stream || !buffer_bo_handle || !frame) {
		CAM_LOG_ERROR("invalid param %p,%p,%p", stream, buffer_bo_handle, frame);
		return;
	}

	/* set frame info */
	if (stream->format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY)
		frame->format = MM_PIXEL_FORMAT_UYVY;
	else
		frame->format = stream->format;

	frame->width = stream->width;
	frame->height = stream->height;
	frame->timestamp = stream->timestamp;
	frame->num_of_planes = stream->num_planes;

	if (num_buffer_fd == 0) {
//LCOV_EXCL_START
		/* non-zero copy */
		if (!data_bo_handle || !data_bo_handle->ptr) {
			CAM_LOG_ERROR("NULL pointer");
			return;
		}

		buf_pos = data_bo_handle->ptr;

		switch (stream->format) {
		case MM_PIXEL_FORMAT_ENCODED_H264:
			/* fall through */
		case MM_PIXEL_FORMAT_ENCODED_MJPEG:
			/* fall through */
		case MM_PIXEL_FORMAT_ENCODED_VP8:
			/* fall through */
		case MM_PIXEL_FORMAT_ENCODED_VP9:
			frame->data.encoded_plane.data = buf_pos;
			frame->data.encoded_plane.size = stream->data.encoded.length_data;
			frame->data.encoded_plane.is_delta_frame = (bool)stream->data.encoded.is_delta_frame;
			total_size = stream->data.encoded.length_data;
			break;

		case MM_PIXEL_FORMAT_INVZ:
			frame->data.depth_plane.data = buf_pos;
			frame->data.depth_plane.size = stream->data.depth.length_data;
			total_size = stream->data.depth.length_data;
			break;

		case MM_PIXEL_FORMAT_RGBA:
			/* fall through */
		case MM_PIXEL_FORMAT_ARGB:
			frame->data.rgb_plane.data = buf_pos;
			frame->data.rgb_plane.size = stream->data.rgb.length_data;
			total_size = stream->data.rgb.length_data;
			break;

		default:
			switch (stream->num_planes) {
			case 1:
				frame->data.single_plane.yuv = buf_pos;
				frame->data.single_plane.size = stream->data.yuv420.length_yuv;
				total_size = stream->data.yuv420.length_yuv;
				break;
			case 2:
				frame->data.double_plane.y = buf_pos;
				frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
				buf_pos += stream->data.yuv420sp.length_y;
				frame->data.double_plane.uv = buf_pos;
				frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
				total_size = stream->data.yuv420sp.length_y + \
					stream->data.yuv420sp.length_uv;
				break;
			case 3:
				frame->data.triple_plane.y = buf_pos;
				frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
				buf_pos += stream->data.yuv420p.length_y;
				frame->data.triple_plane.u = buf_pos;
				frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
				buf_pos += stream->data.yuv420p.length_u;
				frame->data.triple_plane.v = buf_pos;
				frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
				total_size = stream->data.yuv420p.length_y + \
					stream->data.yuv420p.length_u + \
					stream->data.yuv420p.length_v;
				break;
			default:
				break;
			}
			break;
		}
//LCOV_EXCL_STOP
	} else {
		/* zero copy */
		switch (stream->num_planes) {
//LCOV_EXCL_START
		case 1:
			if (stream->data_type == MM_CAM_STREAM_DATA_ENCODED) {
				frame->data.encoded_plane.data = buffer_bo_handle[0].ptr;
				frame->data.encoded_plane.size = stream->data.encoded.length_data;
				frame->data.encoded_plane.is_delta_frame = (bool)stream->data.encoded.is_delta_frame;
				total_size = stream->data.encoded.length_data;
			} else {
				frame->data.single_plane.yuv = buffer_bo_handle[0].ptr;
				frame->data.single_plane.size = stream->data.yuv420.length_yuv;
				total_size = stream->data.yuv420.length_yuv;
			}
			break;
//LCOV_EXCL_STOP
		case 2:
			frame->data.double_plane.y = buffer_bo_handle[0].ptr;
			if (stream->num_planes == (unsigned int)num_buffer_fd)
				frame->data.double_plane.uv = buffer_bo_handle[1].ptr;
			else
				frame->data.double_plane.uv = buffer_bo_handle[0].ptr + stream->data.yuv420sp.length_y;
			frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
			frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
			total_size = stream->data.yuv420sp.length_y + \
				stream->data.yuv420sp.length_uv;
			break;
		case 3:
//LCOV_EXCL_START
			frame->data.triple_plane.y = buffer_bo_handle[0].ptr;
			if (stream->num_planes == (unsigned int)num_buffer_fd) {
				frame->data.triple_plane.u = buffer_bo_handle[1].ptr;
				frame->data.triple_plane.v = buffer_bo_handle[2].ptr;
			} else {
				frame->data.triple_plane.u = buffer_bo_handle[0].ptr + stream->data.yuv420p.length_y;
				frame->data.triple_plane.v = buffer_bo_handle[1].ptr + stream->data.yuv420p.length_u;
			}
			frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
			frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
			frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
			total_size = stream->data.yuv420p.length_y + \
				stream->data.yuv420p.length_u + \
				stream->data.yuv420p.length_v;
			break;
//LCOV_EXCL_STOP
		default:
			break;
		}
	}

	CAM_LOG_DEBUG("format[%d], res[%dx%d], size[%d], plane num[%d]",
		frame->format, frame->width, frame->height, total_size, frame->num_of_planes);
}


//LCOV_EXCL_START
int camera_attr_set_flash_brightness(camera_h camera, int level)
{
	return __set_level(camera, MUSE_CAMERA_API_ATTR_SET_FLASH_BRIGHTNESS, level);
}


int camera_attr_get_flash_brightness(camera_h camera, int *level)
{
	int ret = CAMERA_ERROR_NONE;
	camera_cli_s *pc = (camera_cli_s *)camera;
	muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS;

	if (!pc || !pc->cb_info || !level) {
		CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
		return CAMERA_ERROR_INVALID_PARAMETER;
	}

	CAM_LOG_INFO("Enter");

	_camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);

	if (ret == CAMERA_ERROR_NONE)
		*level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FLASH_BRIGHTNESS];

	CAM_LOG_INFO("ret : 0x%x", ret);

	return ret;
}


int camera_attr_get_flash_brightness_range(camera_h camera, int *min, int *max)
{
	int ret = CAMERA_ERROR_NONE;
	camera_cli_s *pc = (camera_cli_s *)camera;
	muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FLASH_BRIGHTNESS_RANGE;

	if (!pc || !pc->cb_info || !min || !max) {
		CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
		return CAMERA_ERROR_INVALID_PARAMETER;
	}

	CAM_LOG_INFO("Enter");

	_camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);

	if (ret == CAMERA_ERROR_NONE) {
		*min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FLASH_BRIGHTNESS_RANGE][0];
		*max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FLASH_BRIGHTNESS_RANGE][1];
	}

	CAM_LOG_INFO("ret : 0x%x", ret);

	return ret;
}


int camera_attr_set_focus_level(camera_h camera, int level)
{
	return __set_level(camera, MUSE_CAMERA_API_ATTR_SET_FOCUS_LEVEL, level);
}


int camera_attr_get_focus_level(camera_h camera, int *level)
{
	int ret = CAMERA_ERROR_NONE;
	camera_cli_s *pc = (camera_cli_s *)camera;
	muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FOCUS_LEVEL;

	if (!pc || !pc->cb_info || !level) {
		CAM_LOG_ERROR("NULL pointer %p %p", pc, level);
		return CAMERA_ERROR_INVALID_PARAMETER;
	}

	CAM_LOG_INFO("Enter");

	_camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);

	if (ret == CAMERA_ERROR_NONE)
		*level = pc->cb_info->get_int[MUSE_CAMERA_GET_INT_FOCUS_LEVEL];

	CAM_LOG_INFO("ret : 0x%x", ret);

	return ret;
}


int camera_attr_get_focus_level_range(camera_h camera, int *min, int *max)
{
	int ret = CAMERA_ERROR_NONE;
	camera_cli_s *pc = (camera_cli_s *)camera;
	muse_camera_api_e api = MUSE_CAMERA_API_ATTR_GET_FOCUS_LEVEL_RANGE;

	if (!pc || !pc->cb_info || !min || !max) {
		CAM_LOG_ERROR("NULL pointer %p %p %p", pc, min, max);
		return CAMERA_ERROR_INVALID_PARAMETER;
	}

	CAM_LOG_INFO("Enter");

	_camera_msg_send(api, NULL, pc->cb_info, &ret, CAMERA_CB_TIMEOUT);

	if (ret == CAMERA_ERROR_NONE) {
		*min = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FOCUS_LEVEL_RANGE][0];
		*max = pc->cb_info->get_int_pair[MUSE_CAMERA_GET_INT_PAIR_FOCUS_LEVEL_RANGE][1];
	}

	CAM_LOG_INFO("ret : 0x%x", ret);

	return ret;
}


int camera_set_extra_preview_device(camera_h camera, int stream_id, camera_device_e device)
{
	int ret = CAMERA_ERROR_NONE;
	char *msg = NULL;
	camera_cli_s *pc = (camera_cli_s *)camera;
	muse_camera_api_e api = MUSE_CAMERA_API_SET_EXTRA_PREVIEW_DEVICE;

	CAMERA_CHECK_HANDLE_RETURN_VAL(pc, CAMERA_ERROR_INVALID_PARAMETER);

	CAM_LOG_INFO("Enter - stream[%d], device[%d]", stream_id, device);

	msg = muse_core_msg_new(api,
		MUSE_TYPE_INT, "stream_id", stream_id,
		MUSE_TYPE_INT, "device", device,
		NULL);

	_camera_send_message_get_return(pc->cb_info, api, msg, CAMERA_CB_TIMEOUT, &ret);

	return ret;
}
//LCOV_EXCL_STOP