Add new internal APIs for extra preview stream format
[platform/core/api/camera.git] / include / camera_internal.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 #ifndef __TIZEN_MULTIMEDIA_CAMERA_INTERNAL_H__
18 #define __TIZEN_MULTIMEDIA_CAMERA_INTERNAL_H__
19
20 #include <camera.h>
21 #include <mm_types.h>
22 #include <tbm_surface_internal.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /**
29  * @file camera_internal.h
30  * @brief This file contains the internal Camera API, related structures and enumerations.
31  * @since_tizen 3.0
32  */
33
34 /**
35  * @addtogroup CAPI_MEDIA_CAMERA_INTERNAL_MODULE
36  * @{
37  */
38
39 #ifdef BUFFER_MAX_PLANE_NUM
40 #undef BUFFER_MAX_PLANE_NUM
41 #endif /* BUFFER_MAX_PLANE_NUM */
42
43 #define BUFFER_MAX_PLANE_NUM     4
44 #define CAMERA_DEVICE_MAX        ((CAMERA_DEVICE_CAMERA9 + 1) * 2)
45 #define DEVICE_NAME_MAX_LENGTH   64
46 #define DEVICE_ID_MAX_LENGTH     64
47
48 typedef struct _camera_stream_data_s {
49         union {
50                 struct {
51                         unsigned char *yuv;
52                         unsigned int length_yuv;
53                 } yuv420, yuv422;
54                 struct {
55                         unsigned char *y;
56                         unsigned int length_y;
57                         unsigned char *uv;
58                         unsigned int length_uv;
59                 } yuv420sp;
60                 struct {
61                         unsigned char *y;
62                         unsigned int length_y;
63                         unsigned char *u;
64                         unsigned int length_u;
65                         unsigned char *v;
66                         unsigned int length_v;
67                 } yuv420p, yuv422p;
68                 struct {
69                         unsigned char *data;
70                         unsigned int length_data;
71                         int is_delta_frame;
72                 } encoded, depth, rgb;
73         } data;                         /**< pointer of captured stream */
74         int data_type;                  /**< data type */
75         unsigned int length_total;      /**< total length of stream buffer (in byte)*/
76         unsigned int num_planes;        /**< number of planes */
77         MMPixelFormatType format;       /**< image format */
78         int width;                      /**< width of video buffer */
79         int height;                     /**< height of video buffer */
80         unsigned int timestamp;         /**< timestamp of stream buffer (msec)*/
81         void *bo[BUFFER_MAX_PLANE_NUM]; /**< TBM buffer object */
82         void *internal_buffer;          /**< Internal buffer pointer */
83         int stride[BUFFER_MAX_PLANE_NUM];    /**< Stride of each plane */
84         int elevation[BUFFER_MAX_PLANE_NUM]; /**< Elevation of each plane */
85         int extra_stream_id;            /**< ID of extra preview stream */
86 } camera_stream_data_s;
87
88
89 typedef enum {
90         CAMERA_DEVICE_TYPE_BUILTIN = 0, /**< Built-in camera */
91         CAMERA_DEVICE_TYPE_USB,         /**< USB connected camera */
92         CAMERA_DEVICE_TYPE_NETWORK      /**< Network camera */
93 } camera_device_type_e;
94
95 typedef struct _camera_device_s {
96         camera_device_type_e type;
97         camera_device_e index;
98         char name[DEVICE_NAME_MAX_LENGTH];
99         char id[DEVICE_ID_MAX_LENGTH];
100         int extra_stream_num;
101 } camera_device_s;
102
103 typedef struct _camera_device_list_s {
104         unsigned int count;
105         camera_device_s device[CAMERA_DEVICE_MAX];
106 } camera_device_list_s;
107
108 typedef struct camera_device_manager *camera_device_manager_h;
109
110 /**
111  * @internal
112  * @brief Called when the camera device list is changed.
113  * @since_tizen 6.0
114  * @param[in] list      The device list of the camera
115  * @param[in] user_data The user data passed from the callback registration function
116  * @see camera_device_manager_add_device_list_changed_cb()
117  */
118 typedef void (*camera_device_list_changed_cb)(camera_device_list_s *list, void *user_data);
119
120 /**
121  * @internal
122  * @brief Called to register for notifications about delivering a copy of the new extra preview frames.
123  * @since_tizen 6.5
124  * @param[in] frame     The reference pointer to extra preview stream data
125  * @param[in] stream_id The id of stream
126  * @param[in] user_data The user data passed from the callback registration function
127  * @pre camera_start_preview() will invoke this callback function if you register this callback using camera_set_extra_preview_cb().
128  * @see camera_start_preview()
129  * @see camera_set_extra_preview_cb()
130  * @see camera_unset_extra_preview_cb()
131  */
132 typedef void (*camera_extra_preview_cb)(camera_preview_data_s *frame, int stream_id, void *user_data);
133
134 /**
135  * @internal
136  * @brief Start the evas rendering.
137  * @since_tizen 3.0
138  * @param[in] camera The handle to the camera
139  * @return @c 0 on success, otherwise a negative error value
140  * @retval #CAMERA_ERROR_NONE Successful
141  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
142  * @retval #CAMERA_ERROR_INVALID_STATE Invalid state
143  * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
144  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
145  */
146 int camera_start_evas_rendering(camera_h camera);
147
148 /**
149  * @internal
150  * @brief Stop the evas rendering.
151  * @since_tizen 3.0
152  * @param[in] camera The handle to the camera
153  * @param[in] keep_screen If @c true keep last frame on display, otherwise @c false
154  * @return @c 0 on success, otherwise a negative error value
155  * @retval #CAMERA_ERROR_NONE Successful
156  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
157  * @retval #CAMERA_ERROR_INVALID_STATE Invalid state
158  * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
159  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
160  */
161 int camera_stop_evas_rendering(camera_h camera, bool keep_screen);
162
163 /**
164  * @internal
165  * @brief Sets the ecore wayland video display.
166  * @since_tizen 6.0
167  * @remarks This function must be called in main thread of the application.
168  *          Otherwise, it will return #CAMERA_ERROR_INVALID_OPERATION by internal restriction.
169  *          To avoid #CAMERA_ERROR_INVALID_OPERATION in sub thread, ecore_thread_main_loop_begin() and
170  *          ecore_thread_main_loop_end() can be used, but deadlock can occur if the main thread is busy.
171  *          So, it's not recommended to use them.
172  * @param[in] camera The handle to the camera
173  * @param[in] ecore_wl_window The ecore wayland window handle
174  * @return @c 0 on success,
175  *         otherwise a negative error value
176  * @retval #CAMERA_ERROR_NONE Successful
177  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
178  * @retval #CAMERA_ERROR_INVALID_STATE Invalid state
179  * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
180  * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected
181  * @pre The camera state must be set to #CAMERA_STATE_CREATED.
182  * @see camera_start_preview()
183  * @see ecore_thread_main_loop_begin()
184  * @see ecore_thread_main_loop_end()
185  */
186 int camera_set_ecore_wl_display(camera_h camera, void *ecore_wl_window);
187
188 /**
189  * @internal
190  * @brief Creates preview frame from stream data.
191  * @since_tizen 6.0
192  * @param[in] stream The stream from internal pipeline
193  * @param[in] num_buffer_fd The number of buffer fd
194  * @param[in] buffer_bo_handle The bo handle of buffer
195  * @param[in] data_bo_handle The bo handle of data
196  * @param[out] frame The frame which will be filled
197  */
198 void camera_create_preview_frame(camera_stream_data_s *stream, int num_buffer_fd,
199         tbm_bo_handle *buffer_bo_handle, tbm_bo_handle *data_bo_handle, camera_preview_data_s *frame);
200
201 /**
202  * @internal
203  * @brief Creates a new camera handle for controlling a network camera.
204  * @since_tizen 6.0
205  * @remarks A @a camera must be released using camera_destroy().
206  * @param[in]  device The network camera to access
207  * @param[out] camera A newly returned handle to the camera
208  * @return @c 0 on success, otherwise a negative error value
209  * @retval #CAMERA_ERROR_NONE Successful
210  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
211  * @retval #CAMERA_ERROR_OUT_OF_MEMORY Out of memory
212  * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
213  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
214  * @post If it succeeds, the camera state will be #CAMERA_STATE_CREATED.
215  *
216  * @see camera_destroy()
217  */
218 int camera_create_network(camera_device_e device, camera_h *camera);
219
220 /**
221  * @internal
222  * @brief Initialize a camera device manager.
223  * @since_tizen 6.0
224  * @param[out] manager A newly returned handle to the camera device manager
225  * @return @c 0 on success, otherwise a negative error value
226  * @retval #CAMERA_ERROR_NONE Successful
227  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
228  * @retval #CAMERA_ERROR_OUT_OF_MEMORY Out of memory
229  * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
230  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
231  * @see camera_device_manager_deinitialize()
232  */
233 int camera_device_manager_initialize(camera_device_manager_h *manager);
234
235 /**
236  * @internal
237  * @brief Deinitialize the camera device manager handle.
238  * @since_tizen 6.0
239  * @param[in] manager The handle to the camera device manager
240  * @return @c 0 on success, otherwise a negative error value
241  * @retval #CAMERA_ERROR_NONE Successful
242  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
243  * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
244  * @see camera_device_manager_initialize()
245  */
246 int camera_device_manager_deinitialize(camera_device_manager_h manager);
247
248 /**
249  * @internal
250  * @brief Gets a list of available camera devices.
251  * @since_tizen 6.0
252  * @param[in]  manager The handle to the camera device manager
253  * @param[out] list    A list of available camera devices
254  * @return @c 0 on success, otherwise a negative error value
255  * @retval #CAMERA_ERROR_NONE Successful
256  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
257  * @retval #CAMERA_ERROR_OUT_OF_MEMORY Out of memory
258  * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
259  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
260  */
261 int camera_device_manager_get_device_list(camera_device_manager_h manager, camera_device_list_s *list);
262
263 /**
264  * @internal
265  * @brief Registers a callback function to be called when the camera device list changes.
266  * @since_tizen 6.0
267  * @param[in]  manager   The handle to the camera device manager
268  * @param[in]  callback  The callback function to register
269  * @param[in]  user_data The user data to be passed to the callback function
270  * @param[out] cb_id     The id of registered callback
271  * @return @c 0 on success, otherwise a negative error value
272  * @retval #CAMERA_ERROR_NONE Successful
273  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
274  * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
275  * @retval #CAMERA_ERROR_OUT_OF_MEMORY Out of memory
276  * @post This function will invoke camera_device_list_changed_cb() when the camera device list changes.
277  * @see camera_device_manager_remove_device_list_changed_cb()
278  * @see camera_device_list_changed_cb()
279  */
280 int camera_device_manager_add_device_list_changed_cb(camera_device_manager_h manager, camera_device_list_changed_cb callback, void *user_data, int *cb_id);
281
282 /**
283  * @internal
284  * @brief Unregisters the callback function.
285  * @since_tizen 6.0
286  * @param[in] manager The handle to the camera device manager
287  * @param[in] cb_id   The id of registered callback
288  * @return @c 0 on success, otherwise a negative error value
289  * @retval #CAMERA_ERROR_NONE Successful
290  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
291  * @retval #CAMERA_ERROR_INVALID_OPERATION Invalid operation
292  * @see camera_device_manager_add_device_list_changed_cb()
293  */
294 int camera_device_manager_remove_device_list_changed_cb(camera_device_manager_h manager, int cb_id);
295
296 /**
297  * @internal
298  * @brief Sets the brightness level of flash.
299  * @since_tizen 6.5
300  * @remarks If the min value is greater than the max value from camera_attr_get_flash_brightness_range(), \n
301  *          it means that this feature is not supported.
302  * @param[in] camera The handle to the camera
303  * @param[in] level The brightness level of flash
304  * @return @c 0 on success, otherwise a negative error value
305  * @retval #CAMERA_ERROR_NONE Successful
306  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
307  * @retval #CAMERA_ERROR_INVALID_STATE Invalid state
308  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
309  * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected
310  * @pre The camera state must be set to #CAMERA_STATE_CREATED or #CAMERA_STATE_PREVIEW.
311  * @see camera_attr_get_flash_brightness()
312  * @see camera_attr_get_flash_brightness_range()
313  */
314 int camera_attr_set_flash_brightness(camera_h camera, int level);
315
316 /**
317  * @internal
318  * @brief Gets the brightness level of flash.
319  * @since_tizen 6.5
320  * @param[in]  camera The handle to the camera
321  * @param[out] level  The brightness level of flash
322  * @return @c 0 on success, otherwise a negative error value
323  * @retval #CAMERA_ERROR_NONE Successful
324  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
325  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
326  * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected
327  * @see camera_attr_set_flash_brightness()
328  * @see camera_attr_get_flash_brightness_range()
329  */
330 int camera_attr_get_flash_brightness(camera_h camera, int *level);
331
332 /**
333  * @internal
334  * @brief Gets the available brightness level of flash.
335  * @since_tizen 6.5
336  * @remarks If the min value is greater than the max value, it means that this feature is not supported.
337  * @param[in]  camera The handle to the camera
338  * @param[out] min    The minimum brightness level of flash
339  * @param[out] max    The maximum brightness level of flash
340  * @return @c 0 on success, otherwise a negative error value
341  * @retval #CAMERA_ERROR_NONE Successful
342  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
343  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
344  * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected
345  * @see camera_attr_set_flash_brightness()
346  * @see camera_attr_get_flash_brightness()
347  */
348 int camera_attr_get_flash_brightness_range(camera_h camera, int *min, int *max);
349
350 /**
351  * @internal
352  * @brief Registers a callback function to be called for extra preview frames.
353  * @since_tizen 6.5
354  * @param[in] camera    The handle to the camera
355  * @param[in] callback  The callback function to be registered
356  * @param[in] user_data The user data to be passed to the callback function
357  * @return @c 0 on success, otherwise a negative error value
358  * @retval #CAMERA_ERROR_NONE Successful
359  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
360  * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected
361  * @pre The camera state must be set to #CAMERA_STATE_CREATED or #CAMERA_STATE_PREVIEW.
362  * @see camera_start_preview()
363  * @see camera_unset_extra_preview_cb()
364  * @see camera_extra_preview_cb()
365  */
366 int camera_set_extra_preview_cb(camera_h camera, camera_extra_preview_cb callback, void *user_data);
367
368 /**
369  * @internal
370  * @brief Unregisters the callback function.
371  * @since_tizen 6.5
372  * @param[in] camera The handle to the camera
373  * @return @c 0 on success, otherwise a negative error value
374  * @retval #CAMERA_ERROR_NONE Successful
375  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
376  * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected
377  * @see camera_set_extra_preview_cb()
378  */
379 int camera_unset_extra_preview_cb(camera_h camera);
380
381 /**
382  * @internal
383  * @brief Sets the extra preview stream format.
384  * @since_tizen 6.5
385  * @param[in] camera       The handle to the camera
386  * @param[in] stream_id    The id of extra preview stream
387  * @param[in] pixel_format The pixel format of extra preview stream
388  * @param[in] width        The width of extra preview stream
389  * @param[in] height       The height of extra preview stream
390  * @param[in] fps          The fps of extra preview stream
391  * @return @c 0 on success, otherwise a negative error value
392  * @retval #CAMERA_ERROR_NONE Successful
393  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
394  * @retval #CAMERA_ERROR_INVALID_STATE Invalid state
395  * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected
396  * @pre The camera state must be set to #CAMERA_STATE_CREATED or #CAMERA_STATE_PREVIEW.
397  * @see camera_start_preview()
398  * @see camera_set_extra_preview_cb()
399  * @see camera_unset_extra_preview_cb()
400  * @see camera_get_extra_preview_stream_format()
401  */
402 int camera_set_extra_preview_stream_format(camera_h camera, int stream_id, camera_pixel_format_e pixel_format, int width, int height, int fps);
403
404 /**
405  * @internal
406  * @brief Gets the extra preview stream format.
407  * @since_tizen 6.5
408  * @param[in] camera        The handle to the camera
409  * @param[in] stream_id     The id of extra preview stream
410  * @param[out] pixel_format The pixel format of extra preview stream
411  * @param[out] width        The width of extra preview stream
412  * @param[out] height       The height of extra preview stream
413  * @param[out] fps          The fps of extra preview stream
414  * @return @c 0 on success, otherwise a negative error value
415  * @retval #CAMERA_ERROR_NONE Successful
416  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
417  * @retval #CAMERA_ERROR_INVALID_STATE Invalid state
418  * @retval #CAMERA_ERROR_SERVICE_DISCONNECTED The socket to multimedia server is disconnected
419  * @pre The camera state must be set to #CAMERA_STATE_PREVIEW.
420  * @see camera_start_preview()
421  * @see camera_set_extra_preview_cb()
422  * @see camera_unset_extra_preview_cb()
423  * @see camera_set_extra_preview_stream_format()
424  */
425 int camera_get_extra_preview_stream_format(camera_h camera, int stream_id, camera_pixel_format_e *pixel_format, int *width, int *height, int *fps);
426
427 /**
428  * @internal
429  * @brief Sets the manual focus level.
430  * @since_tizen 6.5
431  * @remarks The auto focusing will be stopped when camera_attr_set_focus_level() is called.
432  * @param[in] camera The handle to the camera
433  * @param[in] level The manual focus level
434  * @return @c 0 on success, otherwise a negative error value
435  * @retval #CAMERA_ERROR_NONE Successful
436  * @retval #CAMERA_ERROR_INVALID_OPERATION Internal error
437  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
438  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
439  * @see camera_attr_get_focus_level()
440  * @see camera_attr_get_focus_level_range()
441  */
442 int camera_attr_set_focus_level(camera_h camera, int level);
443
444 /**
445  * @internal
446  * @brief Gets the manual focus level.
447  * @since_tizen 6.5
448  * @param[in] camera The handle to the camera
449  * @param[out] level The manual focus level
450  * @return @c 0 on success, otherwise a negative error value
451  * @retval #CAMERA_ERROR_NONE Successful
452  * @retval #CAMERA_ERROR_INVALID_OPERATION Internal error
453  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
454  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
455  * @see camera_attr_set_focus_level()
456  * @see camera_attr_get_focus_level_range()
457  */
458 int camera_attr_get_focus_level(camera_h camera, int *level);
459
460 /**
461  * @internal
462  * @brief Gets lower limit and upper limit for manual focus level.
463  * @since_tizen 6.5
464  * @remarks If the min value is greater than the max value, it means that this feature is not supported.
465  * @param[in] camera The handle to the camera
466  * @param[out] min The lower limit for manual focus level
467  * @param[out] max The upper limit for manual focus level
468  * @return @c 0 on success, otherwise a negative error value
469  * @retval #CAMERA_ERROR_NONE Successful
470  * @retval #CAMERA_ERROR_INVALID_OPERATION Internal error
471  * @retval #CAMERA_ERROR_INVALID_PARAMETER Invalid parameter
472  * @retval #CAMERA_ERROR_NOT_SUPPORTED The feature is not supported
473  * @see camera_attr_set_focus_level()
474  * @see camera_attr_get_focus_level()
475  */
476 int camera_attr_get_focus_level_range(camera_h camera, int *min, int *max);
477
478 /**
479  * @}
480  */
481 #ifdef __cplusplus
482 }
483 #endif
484
485 #endif /* __TIZEN_MULTIMEDIA_CAMERA_INTERNAL_H__ */