project(vision-source)
include(FindPkgConfig)
-pkg_check_modules(${PROJECT_NAME}_DEP REQUIRED dlog iniparser)
+pkg_check_modules(${PROJECT_NAME}_DEP REQUIRED dlog iniparser capi-media-tool)
add_library(${PROJECT_NAME} SHARED
src/vision_source.c
target_compile_options(${PROJECT_NAME} PUBLIC ${${PROJECT_NAME}_DEP_CFLAGS})
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include)
-target_link_libraries(${PROJECT_NAME}
-${${PROJECT_NAME}_DEP_LIBRARIES}
-dl
-)
+target_link_libraries(${PROJECT_NAME} ${${PROJECT_NAME}_DEP_LIBRARIES} dl)
# install packages
install(
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
install(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/vision_source.ini DESTINATION ${SYSCONF_INSTALL_DIR})
\ No newline at end of file
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/vision_source.ini DESTINATION ${SYSCONF_INSTALL_DIR})
/**
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2022 - 2023 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.
#include <vision_source_interface.h>
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
int vision_source_init(vision_source_h *handle);
int vision_source_exit(vision_source_h handle);
-int vision_source_open_device(vision_source_h handle, int device_index);
+int vision_source_list_devices(vision_source_h handle, const vision_source_device_info_s **dev_list, int *dev_count);
+int vision_source_list_device_caps(vision_source_h handle, int dev_index, const media_format_h **fmt_list,
+ int *fmt_count);
+int vision_source_open_device(vision_source_h handle, int dev_index);
int vision_source_close_device(vision_source_h handle);
-int vision_source_start_stream(vision_source_h handle, stream_cb callback,
- void *user_data);
+int vision_source_set_stream_format(vision_source_h handle, media_format_h fmt);
+int vision_source_start_stream(vision_source_h handle);
int vision_source_stop_stream(vision_source_h handle);
-int vision_source_enumerate_devices(
- vision_source_h handle,
- vision_source_device_info_list_s *info_list);
-int vision_source_set_stream_format(vision_source_h handle,
- vision_source_format_s *format);
-int vision_source_get_capture_frame(vision_source_h handle,
- vision_source_buffer_s *buffer);
-int vision_source_release_capture_frame(vision_source_h handle,
- int buffer_index);
+int vision_source_get_packet(vision_source_h handle, media_packet_h *pkt);
+int vision_source_set_stream_cb(vision_source_h handle, stream_cb callback, void *user_data);
+int vision_source_set_status_cb(vision_source_h handle, status_cb callback, void *user_data);
+int vision_source_set_error_cb(vision_source_h handle, error_cb callback, void *user_data);
int vision_source_ioctl(vision_source_h handle, int request, void *arg);
#ifdef __cplusplus
/**
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2022 - 2023 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.
#ifndef __VISION_SOURCE_INTERFACE__
#define __VISION_SOURCE_INTERFACE__
-#include <stdint.h>
-
-#define BUFFER_PLANE_MAX 4
-#define DEVICE_COUNT_MAX 16
-#define RESOLUTION_COUNT_MAX 32
-#define FPS_COUNT_MAX 16
-#define DEVICE_NAME_LENGTH_MAX 16
-#define DEVICE_NODE_PATH_LENGTH_MAX 16
+#include <media_packet.h>
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
-typedef struct vision_source_resolution
-{
- uint32_t width;
- uint32_t height;
-} vision_source_resolution_s;
-
-typedef enum vision_source_pixel_format
-{
- VISION_SOURCE_PIXEL_FORMAT_RGB24 = 0x0000,
- VISION_SOURCE_PIXEL_FORMAT_GREY,
- VISION_SOURCE_PIXEL_FORMAT_Y10,
- VISION_SOURCE_PIXEL_FORMAT_NV12,
- VISION_SOURCE_PIXEL_FORMAT_NV21,
- VISION_SOURCE_PIXEL_FORMAT_YVU420, //YV12
- VISION_SOURCE_PIXEL_FORMAT_YUV420, //I420
- VISION_SOURCE_PIXEL_FORMAT_Z32F, //FP32 depth data(millimeter distance)
- VISION_SOURCE_PIXEL_FORMAT_Z16U, //U16 depth data(millimeter distance)
- VISION_SOURCE_PIXEL_FORMAT_MAX
-} vision_source_pixel_format_e;
-
-typedef struct vision_source_pixel_format_list
-{
- uint32_t count;
- vision_source_pixel_format_e
- pixel_formats[VISION_SOURCE_PIXEL_FORMAT_MAX];
-} vision_source_pixel_format_list_s;
-
-typedef struct vision_source_resolution_list
-{
- uint32_t count;
- vision_source_resolution_s resolutions[RESOLUTION_COUNT_MAX];
-} vision_source_resolution_list_s;
-
-typedef struct vision_source_fps_list
-{
- uint32_t count;
- int fps[FPS_COUNT_MAX];
-} vision_source_fps_list_s;
-
-typedef struct vision_source_resolution_match_fps
-{
- vision_source_resolution_s resolution;
- vision_source_fps_list_s fps_list;
-} vision_source_resolution_match_fps_s;
-
-typedef struct vision_source_resolution_match_fps_list
-{
- uint32_t count;
- vision_source_resolution_match_fps_s resolutions[RESOLUTION_COUNT_MAX];
-} vision_source_resolution_match_fps_list_s;
-
-typedef struct vision_source_pixel_match_resolution
-{
- vision_source_pixel_format_e pixel_format;
- vision_source_resolution_match_fps_list_s resolution_list;
-} vision_source_pixel_match_resolution_s;
-
-typedef struct vision_source_pixel_match_resolution_list
-{
- uint32_t count;
- vision_source_pixel_match_resolution_s
- pixels[VISION_SOURCE_PIXEL_FORMAT_MAX];
-} vision_source_pixel_match_resolution_list_s;
+#define DEVICE_NAME_LENGTH_MAX 16
-typedef struct vision_source_device_info
-{
+typedef struct vision_source_device_info {
uint32_t index;
char name[DEVICE_NAME_LENGTH_MAX];
- char node_path[DEVICE_NODE_PATH_LENGTH_MAX];
- vision_source_pixel_match_resolution_list_s pixel_list;
} vision_source_device_info_s;
-typedef struct vision_source_device_info_list
-{
- uint32_t count;
- vision_source_device_info_s device_info[DEVICE_COUNT_MAX];
-} vision_source_device_info_list_s;
-
-typedef struct vision_source_plane
-{
- unsigned char *data;
- uint32_t align_width;
- uint32_t align_height;
- uint32_t size;
- uint32_t used_size;
-} vision_source_plane_s;
-
-typedef struct vision_source_format
-{
- vision_source_pixel_format_e pixel_format;
- vision_source_resolution_s resolution;
- uint32_t fps;
- uint32_t quality;
- uint32_t bitrate;
-} vision_source_format_s;
-
-typedef struct vision_source_buffer
-{
- int index;
- vision_source_pixel_format_e pixel_format;
- vision_source_resolution_s resolution;
- uint32_t total_size;
- uint32_t num_planes;
- vision_source_plane_s planes[BUFFER_PLANE_MAX];
- uint64_t timestamp;
- void *priv;
-} vision_source_buffer_s;
-
-typedef enum vision_source_error
-{
+typedef enum vision_source_error {
VISION_SOURCE_ERROR_NONE = 0,
+ VISION_SOURCE_ERROR_NOT_SUPPORTED,
+ VISION_SOURCE_ERROR_MSG_TOO_LONG,
+ VISION_SOURCE_ERROR_NO_DATA,
+ VISION_SOURCE_ERROR_KEY_NOT_AVAILABLE,
+ VISION_SOURCE_ERROR_OUT_OF_MEMORY,
VISION_SOURCE_ERROR_INVALID_PARAMETER,
+ VISION_SOURCE_ERROR_INVALID_OPERATION,
+ VISION_SOURCE_ERROR_PERMISSION_DENIED,
+ VISION_SOURCE_ERROR_NOT_SUPPORTED_FORMAT,
VISION_SOURCE_ERROR_INTERNAL,
- VISION_SOURCE_ERROR_NOT_IMPLEMENTED,
+ VISION_SOURCE_ERROR_INVALID_DATA,
+ VISION_SOURCE_ERROR_INVALID_PATH,
VISION_SOURCE_ERROR_UNKNOWN
} vision_source_error_e;
+typedef enum vision_source_status {
+ VISION_SOURCE_STATUS_INITIALIZED = 0,
+ VISION_SOURCE_STATUS_OPENDED,
+ VISION_SOURCE_STATUS_STARTED
+} vision_source_status_e;
+
typedef void *vision_source_h;
-typedef int (*stream_cb)(vision_source_buffer_s *buffer, void *user_data);
+typedef int (*stream_cb)(media_packet_h pkt, void *user_data);
+typedef int (*status_cb)(vision_source_status_e status, void *user_data);
+typedef int (*error_cb)(vision_source_error_e err, void *user_data);
-typedef struct vision_source_func
-{
+typedef struct vision_source_func {
int (*init)(vision_source_h *handle);
int (*exit)(vision_source_h handle);
- int (*open_device)(vision_source_h handle, int device_index);
+ int (*list_devices)(vision_source_h handle, const vision_source_device_info_s **dev_list, int *dev_count);
+ int (*list_device_caps)(vision_source_h handle, int dev_index, const media_format_h **fmt_list, int *fmt_count);
+ int (*open_device)(vision_source_h handle, int dev_index);
int (*close_device)(vision_source_h handle);
-
- int (*enumerate_devices)(vision_source_h handle,
- vision_source_device_info_list_s *info_list);
- int (*set_stream_format)(vision_source_h handle,
- vision_source_format_s *format);
-
- int (*start_stream)(vision_source_h handle, stream_cb callback,
- void *user_data);
+ int (*set_stream_format)(vision_source_h handle, media_format_h fmt);
+ int (*start_stream)(vision_source_h handle);
int (*stop_stream)(vision_source_h handle);
-
- int (*get_capture_frame)(vision_source_h handle,
- vision_source_buffer_s *buffer);
- int (*release_capture_frame)(vision_source_h handle, int buffer_index);
+ int (*get_packet)(vision_source_h handle, media_packet_h *pkt);
+ int (*set_stream_cb)(vision_source_h handle, stream_cb callback, void *user_data);
+ int (*set_status_cb)(vision_source_h handle, status_cb callback, void *user_data);
+ int (*set_error_cb)(vision_source_h handle, error_cb callback, void *user_data);
int (*ioctl)(vision_source_h handle, int request, void *arg);
} vision_source_func_s;
Name: vision-source
Summary: vision source
-Version: 0.2.1
+Version: 1.0.0
Release: 0
Group: Multimedia/Framework
License: Apache-2.0
BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(iniparser)
+BuildRequires: pkgconfig(capi-media-tool)
%description
Vision source
/**
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2022 - 2023 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.
#define MAX_BACKEND_NAME 32
-typedef struct vision_source_internal
-{
+typedef struct vision_source_internal {
void *backend_handle;
void *dl_handle;
vision_source_func_s funcs;
int _vision_source_dlsym(vision_source_internal_s *handle)
{
- void (*attach_backend)(vision_source_func_s *) =
- dlsym(handle->dl_handle, "attach_backend");
+ void (*attach_backend)(vision_source_func_s *) = dlsym(handle->dl_handle, "attach_backend");
char *error = dlerror();
if (error) {
return VISION_SOURCE_ERROR_NONE;
}
-int _vision_source_attach(const char *backend_name,
- vision_source_internal_s *handle)
+int _vision_source_attach(const char *backend_name, vision_source_internal_s *handle)
{
LOGD("ENTER");
LOGI("backend %s connected", backend_name);
{
LOGD("ENTER");
VISION_SOURCE_NULL_ARG_CHECK(handle);
- vision_source_internal_s *source_handle =
- (vision_source_internal_s *) handle;
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.exit);
int ret = source_handle->funcs.exit(source_handle->backend_handle);
return VISION_SOURCE_ERROR_NONE;
}
-int vision_source_open_device(vision_source_h handle, int device_index)
+int vision_source_list_devices(vision_source_h handle, const vision_source_device_info_s **dev_list, int *dev_count)
+{
+ VISION_SOURCE_NULL_ARG_CHECK(handle);
+ VISION_SOURCE_NULL_ARG_CHECK(dev_list);
+ VISION_SOURCE_NULL_ARG_CHECK(dev_count);
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
+ VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.list_devices);
+
+ return source_handle->funcs.list_devices(source_handle->backend_handle, dev_list, dev_count);
+}
+
+int vision_source_list_device_caps(vision_source_h handle, int dev_index, const media_format_h **fmt_list,
+ int *fmt_count)
+{
+ VISION_SOURCE_NULL_ARG_CHECK(handle);
+ VISION_SOURCE_NULL_ARG_CHECK(fmt_list);
+ VISION_SOURCE_NULL_ARG_CHECK(fmt_count);
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
+ VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.list_device_caps);
+
+ return source_handle->funcs.list_device_caps(source_handle->backend_handle, dev_index, fmt_list, fmt_count);
+}
+
+int vision_source_open_device(vision_source_h handle, int dev_index)
{
VISION_SOURCE_NULL_ARG_CHECK(handle);
- vision_source_internal_s *source_handle =
- (vision_source_internal_s *) handle;
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.open_device);
- return source_handle->funcs.open_device(source_handle->backend_handle,
- device_index);
+
+ return source_handle->funcs.open_device(source_handle->backend_handle, dev_index);
}
+
int vision_source_close_device(vision_source_h handle)
{
VISION_SOURCE_NULL_ARG_CHECK(handle);
- vision_source_internal_s *source_handle =
- (vision_source_internal_s *) handle;
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.close_device);
+
return source_handle->funcs.close_device(source_handle->backend_handle);
}
-int vision_source_start_stream(vision_source_h handle, stream_cb callback,
- void *user_data)
+
+int vision_source_set_stream_format(vision_source_h handle, media_format_h fmt)
+{
+ VISION_SOURCE_NULL_ARG_CHECK(handle);
+ VISION_SOURCE_NULL_ARG_CHECK(fmt);
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
+ VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.set_stream_format);
+
+ return source_handle->funcs.set_stream_format(source_handle->backend_handle, fmt);
+}
+
+int vision_source_start_stream(vision_source_h handle)
{
VISION_SOURCE_NULL_ARG_CHECK(handle);
- vision_source_internal_s *source_handle =
- (vision_source_internal_s *) handle;
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.start_stream);
- return source_handle->funcs.start_stream(source_handle->backend_handle,
- callback, user_data);
+
+ return source_handle->funcs.start_stream(source_handle->backend_handle);
}
+
int vision_source_stop_stream(vision_source_h handle)
{
VISION_SOURCE_NULL_ARG_CHECK(handle);
- vision_source_internal_s *source_handle =
- (vision_source_internal_s *) handle;
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.stop_stream);
+
return source_handle->funcs.stop_stream(source_handle->backend_handle);
}
-int vision_source_enumerate_devices(vision_source_h handle,
- vision_source_device_info_list_s *info_list)
+int vision_source_get_packet(vision_source_h handle, media_packet_h *pkt)
{
VISION_SOURCE_NULL_ARG_CHECK(handle);
- vision_source_internal_s *source_handle =
- (vision_source_internal_s *) handle;
- VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.enumerate_devices);
- return source_handle->funcs.enumerate_devices(source_handle->backend_handle,
- info_list);
+ VISION_SOURCE_NULL_ARG_CHECK(pkt);
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
+ VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.get_packet);
+
+ return source_handle->funcs.get_packet(source_handle->backend_handle, pkt);
}
-int vision_source_set_stream_format(vision_source_h handle,
- vision_source_format_s *format)
+int vision_source_set_stream_cb(vision_source_h handle, stream_cb callback, void *user_data)
{
VISION_SOURCE_NULL_ARG_CHECK(handle);
- vision_source_internal_s *source_handle =
- (vision_source_internal_s *) handle;
- VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.set_stream_format);
- return source_handle->funcs.set_stream_format(source_handle->backend_handle,
- format);
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
+ VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.set_stream_cb);
+
+ return source_handle->funcs.set_stream_cb(source_handle->backend_handle, callback, user_data);
}
-int vision_source_get_capture_frame(vision_source_h handle,
- vision_source_buffer_s *buffer)
+
+int vision_source_set_status_cb(vision_source_h handle, status_cb callback, void *user_data)
{
VISION_SOURCE_NULL_ARG_CHECK(handle);
- vision_source_internal_s *source_handle =
- (vision_source_internal_s *) handle;
- VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.get_capture_frame);
- return source_handle->funcs.get_capture_frame(source_handle->backend_handle,
- buffer);
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
+ VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.set_status_cb);
+
+ return source_handle->funcs.set_status_cb(source_handle->backend_handle, callback, user_data);
}
-int vision_source_release_capture_frame(vision_source_h handle,
- int buffer_index)
+int vision_source_set_error_cb(vision_source_h handle, error_cb callback, void *user_data)
{
VISION_SOURCE_NULL_ARG_CHECK(handle);
- vision_source_internal_s *source_handle =
- (vision_source_internal_s *) handle;
- VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.release_capture_frame);
- return source_handle->funcs.release_capture_frame(
- source_handle->backend_handle, buffer_index);
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
+ VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.set_error_cb);
+
+ return source_handle->funcs.set_error_cb(source_handle->backend_handle, callback, user_data);
}
int vision_source_ioctl(vision_source_h handle, int request, void *arg)
{
VISION_SOURCE_NULL_ARG_CHECK(handle);
- vision_source_internal_s *source_handle =
- (vision_source_internal_s *) handle;
+
+ vision_source_internal_s *source_handle = (vision_source_internal_s *) handle;
VISION_SOURCE_IMPLEMENT_CHECK(source_handle->funcs.ioctl);
- return source_handle->funcs.ioctl(source_handle->backend_handle, request,
- arg);
-}
\ No newline at end of file
+
+ return source_handle->funcs.ioctl(source_handle->backend_handle, request, arg);
+}
/**
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2022 - 2023 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.
} \
} while (0)
-#define VISION_SOURCE_NULL_ARG_CHECK(arg) \
- VISION_SOURCE_CHECK_CONDITION(arg != NULL, \
- VISION_SOURCE_ERROR_INVALID_PARAMETER, \
+#define VISION_SOURCE_NULL_ARG_CHECK(arg) \
+ VISION_SOURCE_CHECK_CONDITION(arg != NULL, VISION_SOURCE_ERROR_INVALID_PARAMETER, \
"VISION_SOURCE_ERROR_INVALID_PARAMETER")
-#define VISION_SOURCE_IMPLEMENT_CHECK(arg) \
- VISION_SOURCE_CHECK_CONDITION(arg != NULL, \
- VISION_SOURCE_ERROR_NOT_IMPLEMENTED, \
- "VISION_SOURCE_ERROR_NOT_IMPLEMENTED")
-#endif /* __VISION_SOURCE_INTERFACE__ */
\ No newline at end of file
+#define VISION_SOURCE_IMPLEMENT_CHECK(arg) \
+ VISION_SOURCE_CHECK_CONDITION(arg != NULL, VISION_SOURCE_ERROR_NOT_SUPPORTED, "VISION_SOURCE_ERROR_NOT_SUPPORTED")
+
+#endif /* __VISION_SOURCE_PRIVATE_H__ */
[Common]
name = "v4l2";
-
-[Stream]
-dev_id = 0;
-width = 640;
-height = 480;
-fps = 30;
-pixel_format = 0;
\ No newline at end of file