--- /dev/null
+---
+# Tizen SE C++ Coding Rule
+
+Language: Cpp
+
+#########################################
+# Turn off build breakable
+FixNamespaceComments: false
+ReflowComments: false
+SortIncludes: false # can break build; turning off
+SortUsingDeclarations: false # can break build; turning off
+
+
+# Enterprise guide
+# M08
+UseTab: Always
+TabWidth: 4
+IndentWidth: 4
+
+# M09
+IndentCaseLabels: false
+
+# R02
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+
+# M10
+SpaceBeforeParens: ControlStatements
+
+
+BreakBeforeBraces: Custom
+BraceWrapping:
+ # M14
+ AfterFunction: true
+
+ # M15
+ AfterControlStatement: false
+ BeforeCatch: false
+ BeforeElse: false
+
+ # M16
+ AfterEnum: false
+ AfterStruct: false
+ AfterUnion: false
+
+ # by inquiry
+ AfterClass: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterExternBlock: false # mediavision want false
+ IndentBraces: false
+ SplitEmptyFunction: false
+ SplitEmptyRecord: false
+ SplitEmptyNamespace: false
+
+# from pptx
+ColumnLimit: 120 # mediavision want 120
+
+# M11
+SpaceAfterCStyleCast: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeRangeBasedForLoopColon: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+
+# M12
+SpaceInEmptyParentheses: false
+
+# by inquiry
+SpaceAfterTemplateKeyword: false
+SpaceBeforeCpp11BracedList: true
+
+################################################################################
+## Other from Linux Kernel Style From https://github.com/torvalds/linux/blob/master/.clang-format
+Standard: Cpp03
+AccessModifierOffset: -4
+AlignEscapedNewlines: Left
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortFunctionsOnASingleLine: None
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializers: BeforeComma
+BreakStringLiterals: false
+ConstructorInitializerIndentWidth: 8
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+KeepEmptyLinesAtTheStartOfBlocks: false
+NamespaceIndentation: None # mediavision want None
+PenaltyBreakAssignment: 10
+PenaltyBreakBeforeFirstCallParameter: 30
+PenaltyBreakComment: 10
+PenaltyBreakFirstLessLess: 0
+PenaltyBreakString: 10
+PenaltyExcessCharacter: 100
+SpacesInAngles: false
+SpacesInContainerLiterals: false
+
+ForEachMacros:
+ - 'apei_estatus_for_each_section'
+ - 'ata_for_each_dev'
+ - 'ata_for_each_link'
+ - '__ata_qc_for_each'
+ - 'ata_qc_for_each'
+ - 'ata_qc_for_each_raw'
+ - 'ata_qc_for_each_with_internal'
+ - 'ax25_for_each'
+ - 'ax25_uid_for_each'
+ - 'bio_for_each_integrity_vec'
+ - '__bio_for_each_segment'
+ - 'bio_for_each_segment'
+ - 'bio_for_each_segment_all'
+ - 'bio_list_for_each'
+ - 'bip_for_each_vec'
+ - 'blkg_for_each_descendant_post'
+ - 'blkg_for_each_descendant_pre'
+ - 'blk_queue_for_each_rl'
+ - 'bond_for_each_slave'
+ - 'bond_for_each_slave_rcu'
+ - 'bpf_for_each_spilled_reg'
+ - 'btree_for_each_safe128'
+ - 'btree_for_each_safe32'
+ - 'btree_for_each_safe64'
+ - 'btree_for_each_safel'
+ - 'card_for_each_dev'
+ - 'cgroup_taskset_for_each'
+ - 'cgroup_taskset_for_each_leader'
+ - 'cpufreq_for_each_entry'
+ - 'cpufreq_for_each_entry_idx'
+ - 'cpufreq_for_each_valid_entry'
+ - 'cpufreq_for_each_valid_entry_idx'
+ - 'css_for_each_child'
+ - 'css_for_each_descendant_post'
+ - 'css_for_each_descendant_pre'
+ - 'device_for_each_child_node'
+ - 'drm_atomic_crtc_for_each_plane'
+ - 'drm_atomic_crtc_state_for_each_plane'
+ - 'drm_atomic_crtc_state_for_each_plane_state'
+ - 'drm_atomic_for_each_plane_damage'
+ - 'drm_connector_for_each_possible_encoder'
+ - 'drm_for_each_connector_iter'
+ - 'drm_for_each_crtc'
+ - 'drm_for_each_encoder'
+ - 'drm_for_each_encoder_mask'
+ - 'drm_for_each_fb'
+ - 'drm_for_each_legacy_plane'
+ - 'drm_for_each_plane'
+ - 'drm_for_each_plane_mask'
+ - 'drm_mm_for_each_hole'
+ - 'drm_mm_for_each_node'
+ - 'drm_mm_for_each_node_in_range'
+ - 'drm_mm_for_each_node_safe'
+ - 'for_each_active_drhd_unit'
+ - 'for_each_active_iommu'
+ - 'for_each_available_child_of_node'
+ - 'for_each_bio'
+ - 'for_each_board_func_rsrc'
+ - 'for_each_bvec'
+ - 'for_each_card_components'
+ - 'for_each_card_links'
+ - 'for_each_card_links_safe'
+ - 'for_each_card_prelinks'
+ - 'for_each_card_rtds'
+ - 'for_each_card_rtds_safe'
+ - 'for_each_cgroup_storage_type'
+ - 'for_each_child_of_node'
+ - 'for_each_clear_bit'
+ - 'for_each_clear_bit_from'
+ - 'for_each_cmsghdr'
+ - 'for_each_compatible_node'
+ - 'for_each_component_dais'
+ - 'for_each_component_dais_safe'
+ - 'for_each_comp_order'
+ - 'for_each_console'
+ - 'for_each_cpu'
+ - 'for_each_cpu_and'
+ - 'for_each_cpu_not'
+ - 'for_each_cpu_wrap'
+ - 'for_each_dev_addr'
+ - 'for_each_dma_cap_mask'
+ - 'for_each_dpcm_be'
+ - 'for_each_dpcm_be_rollback'
+ - 'for_each_dpcm_be_safe'
+ - 'for_each_dpcm_fe'
+ - 'for_each_drhd_unit'
+ - 'for_each_dss_dev'
+ - 'for_each_efi_memory_desc'
+ - 'for_each_efi_memory_desc_in_map'
+ - 'for_each_endpoint_of_node'
+ - 'for_each_evictable_lru'
+ - 'for_each_fib6_node_rt_rcu'
+ - 'for_each_fib6_walker_rt'
+ - 'for_each_free_mem_range'
+ - 'for_each_free_mem_range_reverse'
+ - 'for_each_func_rsrc'
+ - 'for_each_hstate'
+ - 'for_each_if'
+ - 'for_each_iommu'
+ - 'for_each_ip_tunnel_rcu'
+ - 'for_each_irq_nr'
+ - 'for_each_link_codecs'
+ - 'for_each_lru'
+ - 'for_each_matching_node'
+ - 'for_each_matching_node_and_match'
+ - 'for_each_memblock'
+ - 'for_each_memblock_type'
+ - 'for_each_memcg_cache_index'
+ - 'for_each_mem_pfn_range'
+ - 'for_each_mem_range'
+ - 'for_each_mem_range_rev'
+ - 'for_each_migratetype_order'
+ - 'for_each_msi_entry'
+ - 'for_each_msi_entry_safe'
+ - 'for_each_net'
+ - 'for_each_netdev'
+ - 'for_each_netdev_continue'
+ - 'for_each_netdev_continue_rcu'
+ - 'for_each_netdev_feature'
+ - 'for_each_netdev_in_bond_rcu'
+ - 'for_each_netdev_rcu'
+ - 'for_each_netdev_reverse'
+ - 'for_each_netdev_safe'
+ - 'for_each_net_rcu'
+ - 'for_each_new_connector_in_state'
+ - 'for_each_new_crtc_in_state'
+ - 'for_each_new_plane_in_state'
+ - 'for_each_new_private_obj_in_state'
+ - 'for_each_node'
+ - 'for_each_node_by_name'
+ - 'for_each_node_by_type'
+ - 'for_each_node_mask'
+ - 'for_each_node_state'
+ - 'for_each_node_with_cpus'
+ - 'for_each_node_with_property'
+ - 'for_each_of_allnodes'
+ - 'for_each_of_allnodes_from'
+ - 'for_each_of_cpu_node'
+ - 'for_each_of_pci_range'
+ - 'for_each_old_connector_in_state'
+ - 'for_each_old_crtc_in_state'
+ - 'for_each_oldnew_connector_in_state'
+ - 'for_each_oldnew_crtc_in_state'
+ - 'for_each_oldnew_plane_in_state'
+ - 'for_each_oldnew_plane_in_state_reverse'
+ - 'for_each_oldnew_private_obj_in_state'
+ - 'for_each_old_plane_in_state'
+ - 'for_each_old_private_obj_in_state'
+ - 'for_each_online_cpu'
+ - 'for_each_online_node'
+ - 'for_each_online_pgdat'
+ - 'for_each_pci_bridge'
+ - 'for_each_pci_dev'
+ - 'for_each_pci_msi_entry'
+ - 'for_each_populated_zone'
+ - 'for_each_possible_cpu'
+ - 'for_each_present_cpu'
+ - 'for_each_prime_number'
+ - 'for_each_prime_number_from'
+ - 'for_each_process'
+ - 'for_each_process_thread'
+ - 'for_each_property_of_node'
+ - 'for_each_registered_fb'
+ - 'for_each_reserved_mem_region'
+ - 'for_each_rtd_codec_dai'
+ - 'for_each_rtd_codec_dai_rollback'
+ - 'for_each_rtdcom'
+ - 'for_each_rtdcom_safe'
+ - 'for_each_set_bit'
+ - 'for_each_set_bit_from'
+ - 'for_each_sg'
+ - 'for_each_sg_page'
+ - 'for_each_sibling_event'
+ - '__for_each_thread'
+ - 'for_each_thread'
+ - 'for_each_zone'
+ - 'for_each_zone_zonelist'
+ - 'for_each_zone_zonelist_nodemask'
+ - 'fwnode_for_each_available_child_node'
+ - 'fwnode_for_each_child_node'
+ - 'fwnode_graph_for_each_endpoint'
+ - 'gadget_for_each_ep'
+ - 'hash_for_each'
+ - 'hash_for_each_possible'
+ - 'hash_for_each_possible_rcu'
+ - 'hash_for_each_possible_rcu_notrace'
+ - 'hash_for_each_possible_safe'
+ - 'hash_for_each_rcu'
+ - 'hash_for_each_safe'
+ - 'hctx_for_each_ctx'
+ - 'hlist_bl_for_each_entry'
+ - 'hlist_bl_for_each_entry_rcu'
+ - 'hlist_bl_for_each_entry_safe'
+ - 'hlist_for_each'
+ - 'hlist_for_each_entry'
+ - 'hlist_for_each_entry_continue'
+ - 'hlist_for_each_entry_continue_rcu'
+ - 'hlist_for_each_entry_continue_rcu_bh'
+ - 'hlist_for_each_entry_from'
+ - 'hlist_for_each_entry_from_rcu'
+ - 'hlist_for_each_entry_rcu'
+ - 'hlist_for_each_entry_rcu_bh'
+ - 'hlist_for_each_entry_rcu_notrace'
+ - 'hlist_for_each_entry_safe'
+ - '__hlist_for_each_rcu'
+ - 'hlist_for_each_safe'
+ - 'hlist_nulls_for_each_entry'
+ - 'hlist_nulls_for_each_entry_from'
+ - 'hlist_nulls_for_each_entry_rcu'
+ - 'hlist_nulls_for_each_entry_safe'
+ - 'i3c_bus_for_each_i2cdev'
+ - 'i3c_bus_for_each_i3cdev'
+ - 'ide_host_for_each_port'
+ - 'ide_port_for_each_dev'
+ - 'ide_port_for_each_present_dev'
+ - 'idr_for_each_entry'
+ - 'idr_for_each_entry_continue'
+ - 'idr_for_each_entry_ul'
+ - 'inet_bind_bucket_for_each'
+ - 'inet_lhash2_for_each_icsk_rcu'
+ - 'iov_for_each'
+ - 'key_for_each'
+ - 'key_for_each_safe'
+ - 'klp_for_each_func'
+ - 'klp_for_each_object'
+ - 'kvm_for_each_memslot'
+ - 'kvm_for_each_vcpu'
+ - 'list_for_each'
+ - 'list_for_each_codec'
+ - 'list_for_each_codec_safe'
+ - 'list_for_each_entry'
+ - 'list_for_each_entry_continue'
+ - 'list_for_each_entry_continue_rcu'
+ - 'list_for_each_entry_continue_reverse'
+ - 'list_for_each_entry_from'
+ - 'list_for_each_entry_from_rcu'
+ - 'list_for_each_entry_from_reverse'
+ - 'list_for_each_entry_lockless'
+ - 'list_for_each_entry_rcu'
+ - 'list_for_each_entry_reverse'
+ - 'list_for_each_entry_safe'
+ - 'list_for_each_entry_safe_continue'
+ - 'list_for_each_entry_safe_from'
+ - 'list_for_each_entry_safe_reverse'
+ - 'list_for_each_prev'
+ - 'list_for_each_prev_safe'
+ - 'list_for_each_safe'
+ - 'llist_for_each'
+ - 'llist_for_each_entry'
+ - 'llist_for_each_entry_safe'
+ - 'llist_for_each_safe'
+ - 'media_device_for_each_entity'
+ - 'media_device_for_each_intf'
+ - 'media_device_for_each_link'
+ - 'media_device_for_each_pad'
+ - 'nanddev_io_for_each_page'
+ - 'netdev_for_each_lower_dev'
+ - 'netdev_for_each_lower_private'
+ - 'netdev_for_each_lower_private_rcu'
+ - 'netdev_for_each_mc_addr'
+ - 'netdev_for_each_uc_addr'
+ - 'netdev_for_each_upper_dev_rcu'
+ - 'netdev_hw_addr_list_for_each'
+ - 'nft_rule_for_each_expr'
+ - 'nla_for_each_attr'
+ - 'nla_for_each_nested'
+ - 'nlmsg_for_each_attr'
+ - 'nlmsg_for_each_msg'
+ - 'nr_neigh_for_each'
+ - 'nr_neigh_for_each_safe'
+ - 'nr_node_for_each'
+ - 'nr_node_for_each_safe'
+ - 'of_for_each_phandle'
+ - 'of_property_for_each_string'
+ - 'of_property_for_each_u32'
+ - 'pci_bus_for_each_resource'
+ - 'ping_portaddr_for_each_entry'
+ - 'plist_for_each'
+ - 'plist_for_each_continue'
+ - 'plist_for_each_entry'
+ - 'plist_for_each_entry_continue'
+ - 'plist_for_each_entry_safe'
+ - 'plist_for_each_safe'
+ - 'pnp_for_each_card'
+ - 'pnp_for_each_dev'
+ - 'protocol_for_each_card'
+ - 'protocol_for_each_dev'
+ - 'queue_for_each_hw_ctx'
+ - 'radix_tree_for_each_slot'
+ - 'radix_tree_for_each_tagged'
+ - 'rbtree_postorder_for_each_entry_safe'
+ - 'resource_list_for_each_entry'
+ - 'resource_list_for_each_entry_safe'
+ - 'rhl_for_each_entry_rcu'
+ - 'rhl_for_each_rcu'
+ - 'rht_for_each'
+ - 'rht_for_each_continue'
+ - 'rht_for_each_entry'
+ - 'rht_for_each_entry_continue'
+ - 'rht_for_each_entry_rcu'
+ - 'rht_for_each_entry_rcu_continue'
+ - 'rht_for_each_entry_safe'
+ - 'rht_for_each_rcu'
+ - 'rht_for_each_rcu_continue'
+ - '__rq_for_each_bio'
+ - 'rq_for_each_segment'
+ - 'scsi_for_each_prot_sg'
+ - 'scsi_for_each_sg'
+ - 'sctp_for_each_hentry'
+ - 'sctp_skb_for_each'
+ - 'shdma_for_each_chan'
+ - '__shost_for_each_device'
+ - 'shost_for_each_device'
+ - 'sk_for_each'
+ - 'sk_for_each_bound'
+ - 'sk_for_each_entry_offset_rcu'
+ - 'sk_for_each_from'
+ - 'sk_for_each_rcu'
+ - 'sk_for_each_safe'
+ - 'sk_nulls_for_each'
+ - 'sk_nulls_for_each_from'
+ - 'sk_nulls_for_each_rcu'
+ - 'snd_array_for_each'
+ - 'snd_pcm_group_for_each_entry'
+ - 'snd_soc_dapm_widget_for_each_path'
+ - 'snd_soc_dapm_widget_for_each_path_safe'
+ - 'snd_soc_dapm_widget_for_each_sink_path'
+ - 'snd_soc_dapm_widget_for_each_source_path'
+ - 'tb_property_for_each'
+ - 'tcf_exts_for_each_action'
+ - 'udp_portaddr_for_each_entry'
+ - 'udp_portaddr_for_each_entry_rcu'
+ - 'usb_hub_for_each_child'
+ - 'v4l2_device_for_each_subdev'
+ - 'v4l2_m2m_for_each_dst_buf'
+ - 'v4l2_m2m_for_each_dst_buf_safe'
+ - 'v4l2_m2m_for_each_src_buf'
+ - 'v4l2_m2m_for_each_src_buf_safe'
+ - 'virtio_device_for_each_vq'
+ - 'xa_for_each'
+ - 'xas_for_each'
+ - 'xas_for_each_conflict'
+ - 'xas_for_each_marked'
+ - 'zorro_for_each_dev'
+...
--- /dev/null
+PROJECT("singleo")
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+ADD_SUBDIRECTORY(log)
+ADD_SUBDIRECTORY(input)
+ADD_SUBDIRECTORY(inference)
+ADD_SUBDIRECTORY(services)
+ADD_SUBDIRECTORY(test)
+
+SET(PC_NAME ${PROJECT_NAME})
+SET(PC_LDFLAGS -l${PROJECT_NAME})
+SET(PC_CFLAGS -I\${includedir}/media)
+
+CONFIGURE_FILE(
+ ${PROJECT_NAME}.pc.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc
+ @ONLY
+)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
\ No newline at end of file
--- /dev/null
+Copyright (c) 2024 Samsung Electronics Co., Ltd. All rights reserved.\r
+\r
+ Apache License\r
+ Version 2.0, January 2004\r
+ http://www.apache.org/licenses/\r
+\r
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
+\r
+ 1. Definitions.\r
+\r
+ "License" shall mean the terms and conditions for use, reproduction,\r
+ and distribution as defined by Sections 1 through 9 of this document.\r
+\r
+ "Licensor" shall mean the copyright owner or entity authorized by\r
+ the copyright owner that is granting the License.\r
+\r
+ "Legal Entity" shall mean the union of the acting entity and all\r
+ other entities that control, are controlled by, or are under common\r
+ control with that entity. For the purposes of this definition,\r
+ "control" means (i) the power, direct or indirect, to cause the\r
+ direction or management of such entity, whether by contract or\r
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
+ outstanding shares, or (iii) beneficial ownership of such entity.\r
+\r
+ "You" (or "Your") shall mean an individual or Legal Entity\r
+ exercising permissions granted by this License.\r
+\r
+ "Source" form shall mean the preferred form for making modifications,\r
+ including but not limited to software source code, documentation\r
+ source, and configuration files.\r
+\r
+ "Object" form shall mean any form resulting from mechanical\r
+ transformation or translation of a Source form, including but\r
+ not limited to compiled object code, generated documentation,\r
+ and conversions to other media types.\r
+\r
+ "Work" shall mean the work of authorship, whether in Source or\r
+ Object form, made available under the License, as indicated by a\r
+ copyright notice that is included in or attached to the work\r
+ (an example is provided in the Appendix below).\r
+\r
+ "Derivative Works" shall mean any work, whether in Source or Object\r
+ form, that is based on (or derived from) the Work and for which the\r
+ editorial revisions, annotations, elaborations, or other modifications\r
+ represent, as a whole, an original work of authorship. For the purposes\r
+ of this License, Derivative Works shall not include works that remain\r
+ separable from, or merely link (or bind by name) to the interfaces of,\r
+ the Work and Derivative Works thereof.\r
+\r
+ "Contribution" shall mean any work of authorship, including\r
+ the original version of the Work and any modifications or additions\r
+ to that Work or Derivative Works thereof, that is intentionally\r
+ submitted to Licensor for inclusion in the Work by the copyright owner\r
+ or by an individual or Legal Entity authorized to submit on behalf of\r
+ the copyright owner. For the purposes of this definition, "submitted"\r
+ means any form of electronic, verbal, or written communication sent\r
+ to the Licensor or its representatives, including but not limited to\r
+ communication on electronic mailing lists, source code control systems,\r
+ and issue tracking systems that are managed by, or on behalf of, the\r
+ Licensor for the purpose of discussing and improving the Work, but\r
+ excluding communication that is conspicuously marked or otherwise\r
+ designated in writing by the copyright owner as "Not a Contribution."\r
+\r
+ "Contributor" shall mean Licensor and any individual or Legal Entity\r
+ on behalf of whom a Contribution has been received by Licensor and\r
+ subsequently incorporated within the Work.\r
+\r
+ 2. Grant of Copyright License. Subject to the terms and conditions of\r
+ this License, each Contributor hereby grants to You a perpetual,\r
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+ copyright license to reproduce, prepare Derivative Works of,\r
+ publicly display, publicly perform, sublicense, and distribute the\r
+ Work and such Derivative Works in Source or Object form.\r
+\r
+ 3. Grant of Patent License. Subject to the terms and conditions of\r
+ this License, each Contributor hereby grants to You a perpetual,\r
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+ (except as stated in this section) patent license to make, have made,\r
+ use, offer to sell, sell, import, and otherwise transfer the Work,\r
+ where such license applies only to those patent claims licensable\r
+ by such Contributor that are necessarily infringed by their\r
+ Contribution(s) alone or by combination of their Contribution(s)\r
+ with the Work to which such Contribution(s) was submitted. If You\r
+ institute patent litigation against any entity (including a\r
+ cross-claim or counterclaim in a lawsuit) alleging that the Work\r
+ or a Contribution incorporated within the Work constitutes direct\r
+ or contributory patent infringement, then any patent licenses\r
+ granted to You under this License for that Work shall terminate\r
+ as of the date such litigation is filed.\r
+\r
+ 4. Redistribution. You may reproduce and distribute copies of the\r
+ Work or Derivative Works thereof in any medium, with or without\r
+ modifications, and in Source or Object form, provided that You\r
+ meet the following conditions:\r
+\r
+ (a) You must give any other recipients of the Work or\r
+ Derivative Works a copy of this License; and\r
+\r
+ (b) You must cause any modified files to carry prominent notices\r
+ stating that You changed the files; and\r
+\r
+ (c) You must retain, in the Source form of any Derivative Works\r
+ that You distribute, all copyright, patent, trademark, and\r
+ attribution notices from the Source form of the Work,\r
+ excluding those notices that do not pertain to any part of\r
+ the Derivative Works; and\r
+\r
+ (d) If the Work includes a "NOTICE" text file as part of its\r
+ distribution, then any Derivative Works that You distribute must\r
+ include a readable copy of the attribution notices contained\r
+ within such NOTICE file, excluding those notices that do not\r
+ pertain to any part of the Derivative Works, in at least one\r
+ of the following places: within a NOTICE text file distributed\r
+ as part of the Derivative Works; within the Source form or\r
+ documentation, if provided along with the Derivative Works; or,\r
+ within a display generated by the Derivative Works, if and\r
+ wherever such third-party notices normally appear. The contents\r
+ of the NOTICE file are for informational purposes only and\r
+ do not modify the License. You may add Your own attribution\r
+ notices within Derivative Works that You distribute, alongside\r
+ or as an addendum to the NOTICE text from the Work, provided\r
+ that such additional attribution notices cannot be construed\r
+ as modifying the License.\r
+\r
+ You may add Your own copyright statement to Your modifications and\r
+ may provide additional or different license terms and conditions\r
+ for use, reproduction, or distribution of Your modifications, or\r
+ for any such Derivative Works as a whole, provided Your use,\r
+ reproduction, and distribution of the Work otherwise complies with\r
+ the conditions stated in this License.\r
+\r
+ 5. Submission of Contributions. Unless You explicitly state otherwise,\r
+ any Contribution intentionally submitted for inclusion in the Work\r
+ by You to the Licensor shall be under the terms and conditions of\r
+ this License, without any additional terms or conditions.\r
+ Notwithstanding the above, nothing herein shall supersede or modify\r
+ the terms of any separate license agreement you may have executed\r
+ with Licensor regarding such Contributions.\r
+\r
+ 6. Trademarks. This License does not grant permission to use the trade\r
+ names, trademarks, service marks, or product names of the Licensor,\r
+ except as required for reasonable and customary use in describing the\r
+ origin of the Work and reproducing the content of the NOTICE file.\r
+\r
+ 7. Disclaimer of Warranty. Unless required by applicable law or\r
+ agreed to in writing, Licensor provides the Work (and each\r
+ Contributor provides its Contributions) on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
+ implied, including, without limitation, any warranties or conditions\r
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
+ PARTICULAR PURPOSE. You are solely responsible for determining the\r
+ appropriateness of using or redistributing the Work and assume any\r
+ risks associated with Your exercise of permissions under this License.\r
+\r
+ 8. Limitation of Liability. In no event and under no legal theory,\r
+ whether in tort (including negligence), contract, or otherwise,\r
+ unless required by applicable law (such as deliberate and grossly\r
+ negligent acts) or agreed to in writing, shall any Contributor be\r
+ liable to You for damages, including any direct, indirect, special,\r
+ incidental, or consequential damages of any character arising as a\r
+ result of this License or out of the use or inability to use the\r
+ Work (including but not limited to damages for loss of goodwill,\r
+ work stoppage, computer failure or malfunction, or any and all\r
+ other commercial damages or losses), even if such Contributor\r
+ has been advised of the possibility of such damages.\r
+\r
+ 9. Accepting Warranty or Additional Liability. While redistributing\r
+ the Work or Derivative Works thereof, You may choose to offer,\r
+ and charge a fee for, acceptance of support, warranty, indemnity,\r
+ or other liability obligations and/or rights consistent with this\r
+ License. However, in accepting such obligations, You may act only\r
+ on Your own behalf and on Your sole responsibility, not on behalf\r
+ of any other Contributor, and only if You agree to indemnify,\r
+ defend, and hold each Contributor harmless for any liability\r
+ incurred by, or claims asserted against, such Contributor by reason\r
+ of your accepting any such warranty or additional liability.\r
+\r
+ END OF TERMS AND CONDITIONS\r
+\r
+ APPENDIX: How to apply the Apache License to your work.\r
+\r
+ To apply the Apache License to your work, attach the following\r
+ boilerplate notice, with the fields enclosed by brackets "[]"\r
+ replaced with your own identifying information. (Don't include\r
+ the brackets!) The text should be enclosed in the appropriate\r
+ comment syntax for the file format. We also recommend that a\r
+ file or class name and description of purpose be included on the\r
+ same "printed page" as the copyright notice for easier\r
+ identification within third-party archives.\r
+\r
+ Copyright [yyyy] [name of copyright owner]\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+\r
+\r
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+#ifndef __SINGLEO_NATIVE_CAPI_H__
+#define __SINGLEO_NATIVE_CAPI_H__
+
+/**
+ * @brief The singleo service object handle.
+ *
+ * @since_tizen 9.0
+ */
+typedef void *singleo_service_h;
+
+/**
+ * @internal
+ * @brief Creates a handle for a given service.
+ * @details Use this function to create a new singleo service with given option.
+ * Options include:
+ * - "service:": specifies one service name among below list
+ * "auto_zoom"
+ * - "input:": specifies one input feeding type among below list
+ * "camera" : Image data captured by camera device though a given camera backend will be used as input image.
+ * "screen_capture" : Image data captured by screen capture module through a given screen capture backend will be used as input image.
+ * - "camera_backend:": specifies one backend type among below list. This key is valid only input=camera case.
+ * "camera-api" : Tizen camera API will be used as a backend.
+ * "vision-source" : Vision source for Mediavision framework will be used as a backend.
+ * - "fps:": specifies frame per second to capture image from the given input backend. This key is valid only input=camera or input=screen_capture
+ * - "async:": specifies whether service request should be performed in async way or sync one.
+ * "0": service request will be performed in sync way. It means that user can get the result as soon as the request is completed.
+ * "1": service request will be performed in async way. It mean that user is needed to create a new thread to get the result
+ * because it will be returned as soon as the service request is done so user has to wait for the result within its own thread context.
+ * Examples: singleo_service_create("service=auto_zoom, input=camera, camera_backend=camera-api, fbs=30, async=0")
+ *
+ * @since_tizen 9.0
+ *
+ * @param[in] option The option string which is referred when a new service handle is created.
+ * @param[out] handle The handle to the service to be created.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SINGLEO_SERVICE_ERROR_NONE Successful
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_OPERATION Invalid operation
+ */
+int singleo_service_create(const char *option, singleo_service_h *handle);
+
+/**
+ * @internal
+ * @brief Destroys service handle and releases all its resources.
+ *
+ * @since_tizen 9.0
+ *
+ * @param[in] handle The handle to the service to be destroyed.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SINGLEO_SERVICE_ERROR_NONE Successful
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @pre Create inference handle by using mv_face_detection_create()
+ *
+ * @see singleo_service_create()
+ */
+int singleo_service_destroy(singleo_service_h handle);
+
+/**
+ * @internal
+ * @brief Performs the service with input feeding type.
+ *
+ * @since_tizen 9.0
+ * @remarks With this function, the service will be performed with input source obtained by a given input type and its backend.
+ * Therefore, "input", "backend" and "fps" options are mandatorily required when its service handle is created.
+ *
+ * @param[in] handle The handle to the service.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SINGLEO_SERVICE_ERROR_NONE Successful
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Create a source handle by calling singleo_service_create()
+ */
+int singleo_service_perform(singleo_service_h handle);
+
+/**
+ * @internal
+ * @brief Performs the service with a given file name.
+ *
+ * @since_tizen 9.0
+ * @remarks With this function, the service will be performed with input source given by user as a file name.
+ *
+ * @param[in] handle The handle to the service.
+ * @param[in] file_name A file name to be used as input data. It can become one of image files supported by OpenCV.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SINGLEO_SERVICE_ERROR_NONE Successful
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Create a source handle by calling singleo_service_create()
+ */
+int singleo_service_perform_with_file(singleo_service_h handle, const char *file_name);
+
+/**
+ * @internal
+ * @brief Performs the service with image data information.
+ *
+ * @since_tizen 9.0
+ * @remarks With this function, the service will be performed with raw image data information given by user.
+ *
+ * @param[in] handle The handle to the service.
+ * @param[in] buffer A buffer pointer pointing to raw image data.
+ * @param[in] width A number of horizontal pixels in the image.
+ * @param[in] height A number of vertical pixels in the image.
+ * @param[in] byte_per_pixel Each pixel size to a given buffer in bytes.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SINGLEO_SERVICE_ERROR_NONE Successful
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Create a source handle by calling singleo_service_create()
+ */
+int singleo_service_perform_with_image_data(singleo_service_h handle, const unsigned char *buffer, unsigned int width,
+ unsigned int height, unsigned long byte_per_pixel);
+
+/**
+ * @internal
+ * @brief Performs the service with raw data information.
+ *
+ * @since_tizen 9.0
+ * @remarks With this function, the service will be performed with raw data information given by user.
+ *
+ * @param[in] handle The handle to the service.
+ * @param[in] buffer A buffer pointer pointing to raw data.
+ * @param[in] buffer_size_in_bytes Buffer size to a given buffer in bytes.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SINGLEO_SERVICE_ERROR_NONE Successful
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Create a source handle by calling singleo_service_create()
+ */
+int singleo_service_perform_with_raw_data(singleo_service_h handle, const unsigned char *buffer,
+ unsigned long buffer_size_in_bytes);
+
+/**
+ * @internal
+ * @brief Gets a number of results after the service request is completed.
+ *
+ * @since_tizen 9.0
+ *
+ * @param[in] handle The handle to the service.
+ * @param[out] cnt A number of results.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SINGLEO_SERVICE_ERROR_NONE Successful
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Create a source handle by calling singleo_service_create()
+ * @pre Perform a requested service by
+ * calling singleo_service_perform(),
+ * singleo_service_perform_with_file(),
+ * singleo_service_perform_with_image_data(),
+ * or singleo_service_perform_with_raw_data()
+ */
+int singleo_service_get_result_cnt(singleo_service_h handle, unsigned int *cnt);
+
+/**
+ * @internal
+ * @brief Gets integer type of result corresponding to a given index value.
+ *
+ * @since_tizen 9.0
+ *
+ * @param[in] handle The handle to the service.
+ * @param[in] idx Index value to results.
+ * @param[in] key Key string to a certain member of the result.
+ * @param[out] value Pointer to the integer variable to be stored.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SINGLEO_SERVICE_ERROR_NONE Successful
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Create a source handle by calling singleo_service_create()
+ * @pre Perform a requested service by
+ * calling singleo_service_perform(),
+ * singleo_service_perform_with_file(),
+ * singleo_service_perform_with_image_data(),
+ * or singleo_service_perform_with_raw_data()
+ * @pre Get a number of results by calling singleo_service_get_result_cnt()
+ */
+int singleo_service_get_result_int(singleo_service_h handle, unsigned int idx, const char *key, unsigned int *value);
+
+/**
+ * @internal
+ * @brief Gets string type of result corresponding to a given index value.
+ *
+ * @since_tizen 9.0
+ *
+ * @param[in] handle The handle to the service.
+ * @param[in] idx Index value to results.
+ * @param[in] key Key string to a certain member of the result.
+ * @param[out] value Pointer to the string variable to be stored.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SINGLEO_SERVICE_ERROR_NONE Successful
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Create a source handle by calling singleo_service_create()
+ * @pre Perform a requested service by
+ * calling singleo_service_perform(),
+ * singleo_service_perform_with_file(),
+ * singleo_service_perform_with_image_data(),
+ * or singleo_service_perform_with_raw_data()
+ * @pre Get a number of results by calling singleo_service_get_result_cnt()
+ */
+int singleo_service_get_result_str(singleo_service_h handle, unsigned int idx, const char *key, char **value);
+
+/**
+ * @internal
+ * @brief Gets data stream type of result corresponding to a given index value.
+ *
+ * @since_tizen 9.0
+ *
+ * @param[in] handle The handle to the service.
+ * @param[in] idx Index value to results.
+ * @param[in] key Key string to a certain member of the result.
+ * @param[out] ptr Pointer to raw data stream object.
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SINGLEO_SERVICE_ERROR_NONE Successful
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SINGLEO_SERVICE_ERROR_ERROR_INVALID_OPERATION Invalid operation
+ *
+ * @pre Create a source handle by calling singleo_service_create()
+ * @pre Perform a requested service by
+ * calling singleo_service_perform(),
+ * singleo_service_perform_with_file(),
+ * singleo_service_perform_with_image_data(),
+ * or singleo_service_perform_with_raw_data()
+ * @pre Get a number of results by calling singleo_service_get_result_cnt()
+ */
+int singleo_service_get_result_ptr(singleo_service_h handle, unsigned int idx, const char *key, unsigned char **ptr);
+
+#endif
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __ISINGLEO_COMMON_DATA_H__
+#define __ISINGLEO_COMMON_DATA_H__
+
+#include "SingleoCommonTypes.h"
+
+namespace singleo
+{
+class ISingleoCommonData
+{
+public:
+ virtual ~ISingleoCommonData() {};
+
+ virtual void setData(BaseDataType &input_data) = 0;
+ virtual BaseDataType &getData() = 0;
+};
+
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __SINGLEO_COMMON_TYPES_H__
+#define __SINGLEO_COMMON_TYPES_H__
+
+#include <vector>
+#include <string>
+#include <memory>
+#include <map>
+
+namespace singleo
+{
+struct Rect {
+ int left {};
+ int right {};
+ int top {};
+ int bottom {};
+};
+
+using VecRect = std::vector<Rect>;
+
+enum class DataType { NONE, FILE, IMAGE, RAW };
+
+struct BaseDataType {
+ DataType _data_type { DataType::NONE };
+ BaseDataType(DataType data_type) : _data_type(data_type)
+ {}
+ virtual ~BaseDataType()
+ {}
+};
+
+struct FileDataType : public BaseDataType {
+ FileDataType() : BaseDataType(DataType::FILE)
+ {}
+ std::string _file_name;
+};
+
+struct ImageDataType : public BaseDataType {
+ ImageDataType() : BaseDataType(DataType::IMAGE)
+ {}
+ unsigned char *ptr {};
+ unsigned int width {};
+ unsigned int height {};
+ unsigned int byte_per_pixel {};
+};
+
+struct RawDataType : public BaseDataType {
+ RawDataType() : BaseDataType(DataType::RAW)
+ {}
+ unsigned char *ptr {};
+ size_t size_in_bytes {};
+};
+
+enum class ResultType { BOUND_BOX, LANDMARK };
+
+struct BaseResultType {
+ ResultType type;
+ virtual ~BaseResultType()
+ {}
+};
+
+struct OdResultType : public BaseResultType {
+ Rect rect;
+};
+
+enum class ServiceType { NONE, AUTO_ZOOM };
+
+enum class InputFeedType { NONE, CAMERA, SCREEN_CAPTURE };
+
+enum class CameraBackendType { NONE, OPENCV, CAMERA_API, VISION_SOURCE };
+
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __SINGLEO_IMAGE_DATA_H__
+#define __SINGLEO_IMAGE_DATA_H__
+
+#include "ISingleoCommonData.h"
+
+namespace singleo
+{
+class SingleoImageData : public ISingleoCommonData
+{
+private:
+ ImageDataType _data;
+
+public:
+ SingleoImageData() = default;
+ virtual ~SingleoImageData() = default;
+
+ void setData(BaseDataType &input_data) override;
+ BaseDataType &getData() override;
+};
+
+} // singleo
+
+#endif
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __SINGLEO_RAW_DATA_H__
+#define __SINGLEO_RAW_DATA_H__
+
+#include "ISingleoCommonData.h"
+
+namespace singleo
+{
+class SingleoRawData : public ISingleoCommonData
+{
+private:
+ RawDataType _data {};
+
+public:
+ SingleoRawData() = default;
+ virtual ~SingleoRawData() = default;
+
+ void setData(BaseDataType &input_data) override;
+ BaseDataType &getData() override;
+};
+
+} // singleo
+
+#endif
--- /dev/null
+/**
+ * Copyright (c) 2024 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 "SingleoImageData.h"
+
+using namespace std;
+
+namespace singleo
+{
+void SingleoImageData::setData(BaseDataType &input_data)
+{
+ auto image_data = dynamic_cast<ImageDataType &>(input_data);
+ _data = image_data;
+}
+
+BaseDataType &SingleoImageData::getData()
+{
+ return _data;
+}
+
+}
--- /dev/null
+/**
+ * Copyright (c) 2024 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 "SingleoRawData.h"
+
+using namespace std;
+
+namespace singleo
+{
+BaseDataType &SingleoRawData::getData()
+{
+ return _data;
+}
+
+}
--- /dev/null
+PROJECT("singleo_inference")
+CMAKE_MINIMUM_REQUIRED(VERSION 3.13)
+
+ADD_SUBDIRECTORY(backends)
+
+IF (${USE_EXTERNAL_INFERENCE_SERVICE})
+ SET(SINGLEO_INFERENCE_HEADER_DIRECTORY "")
+ SET(SINGLEO_INFERENCE_SERVUCE_FILE "InferenceServiceExternal.cpp")
+ELSE()
+ SET(SINGLEO_INFERENCE_HEADER_DIRECTORY /usr/include/media backends/mediavision/include)
+ SET(SINGLEO_INFERENCE_SERVUCE_FILE "InferenceServiceDefault.cpp")
+ENDIF()
+
+FILE(GLOB SINGLEO_INFERENCE_SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/${SINGLEO_INFERENCE_SERVUCE_FILE}")
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SINGLEO_INFERENCE_SOURCE_FILES})
+
+TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE include ../common/include ${SINGLEO_INFERENCE_HEADER_DIRECTORY})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE singleo_inference_backend)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
\ No newline at end of file
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 3.13)
+PROJECT("singleo_inference_backend")
+
+FILE(GLOB MEDIAVISION_SOURCE_FILES "${PROJECT_SOURCE_DIR}/mediavision/src/*.cpp")
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${MEDIAVISION_SOURCE_FILES})
+
+FIND_PACKAGE(PkgConfig REQUIRED)
+PKG_CHECK_MODULES(${PROJECT_NAME}_DEP REQUIRED capi-media-vision)
+
+TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE ../include ../../common/include ../../log/include mediavision/include /usr/include/media)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE mv_common singleo_log mv_inference mv_object_detection)
+
+# Install the library
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __OBJECT_DETECTION_H__
+#define __OBJECT_DETECTION_H__
+
+#include "IInferenceTaskInterface.h"
+#include "mv_object_detection_internal.h"
+#include "MvOdOutputData.h"
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+class MvObjectDetection : public IInferenceTaskInterface
+{
+private:
+ mv_object_detection_h _handle {};
+ MvOdOutputData _output_data {};
+
+public:
+ MvObjectDetection();
+ virtual ~MvObjectDetection();
+
+ void configure() override;
+ void prepare() override;
+ void invoke(ISingleoCommonData &input, bool async) override;
+ const ISingleoOutputData &result() override;
+};
+
+} // backends
+} // inference
+} // singleo
+
+#endif
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __MV_OD_OUTPUT_DATA_H__
+#define __MV_OD_OUTPUT_DATA_H__
+
+#include "ISingleoOutputData.h"
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+class MvOdOutputData : public ISingleoOutputData
+{
+private:
+ unsigned int _frame_number {};
+ std::vector<OdResultType> _vec_result;
+
+public:
+ MvOdOutputData() {};
+ virtual ~MvOdOutputData() {};
+
+ void setFrameNumber(unsigned int frame_number)
+ {
+ _frame_number = frame_number;
+ }
+
+ void addResult(OdResultType &result)
+ {
+ _vec_result.push_back(result);
+ }
+
+ void clear() override
+ {
+ _vec_result.clear();
+ }
+
+ unsigned int getFrameNumber() const override
+ {
+ return _frame_number;
+ }
+
+ const std::vector<OdResultType> &getResult() const override
+ {
+ return _vec_result;
+ }
+};
+
+} // backends
+} // inference
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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 <stdexcept>
+#include "SingleoImageData.h"
+#include "MvObjectDetection.h"
+#include "SingleoLog.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace inference
+{
+namespace backends
+{
+MvObjectDetection::MvObjectDetection()
+{
+ int ret = mv_object_detection_create(&_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to create object detection handle.");
+}
+
+MvObjectDetection::~MvObjectDetection()
+{
+ mv_object_detection_destroy(_handle);
+}
+
+void MvObjectDetection::configure()
+{
+ int ret = mv_object_detection_configure(_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to configure object detection.");
+}
+
+void MvObjectDetection::prepare()
+{
+ int ret = mv_object_detection_prepare(_handle);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to prepare object detection.");
+}
+
+void MvObjectDetection::invoke(ISingleoCommonData &input, bool async)
+{
+ ImageDataType &data = dynamic_cast<ImageDataType &>(input.getData());
+
+ if (data._data_type != DataType::IMAGE) {
+ SINGLEO_LOGE("Invalid input type.");
+ throw invalid_argument("Input type not support.");
+ }
+
+ mv_source_h mv_src;
+
+ int ret = mv_create_source(&mv_src);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to create mv source.");
+
+ try {
+ ret = mv_source_fill_by_buffer(mv_src, data.ptr, data.width * data.height * data.byte_per_pixel, data.width,
+ data.height, MEDIA_VISION_COLORSPACE_RGB888);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to convert to mv source.");
+
+ ret = mv_object_detection_inference(_handle, mv_src);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to invoke object detection.");
+ } catch (std::runtime_error &e) {
+ SINGLEO_LOGE("%s", e.what());
+ }
+
+ ret = mv_destroy_source(mv_src);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to destroy mv source.");
+}
+
+const ISingleoOutputData &MvObjectDetection::result()
+{
+ unsigned long frame_number;
+ unsigned int result_cnt;
+
+ int ret = mv_object_detection_get_result_count(_handle, &frame_number, &result_cnt);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to get object detection result count.");
+
+ _output_data.clear();
+ _output_data.setFrameNumber(frame_number);
+
+ for (unsigned int idx = 0; idx < result_cnt; ++idx) {
+ OdResultType result_rect;
+
+ ret = mv_object_detection_get_bbox(_handle, idx, &result_rect.rect.left, &result_rect.rect.top,
+ &result_rect.rect.right, &result_rect.rect.bottom);
+ if (ret != MEDIA_VISION_ERROR_NONE)
+ throw runtime_error("Fail to get object detection bound box.");
+
+ _output_data.addResult(result_rect);
+ }
+
+ return _output_data;
+}
+
+}
+}
+}
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __IINFERENCE_SERVICE_INTERFACE_H__
+#define __IINFERENCE_SERVICE_INTERFACE_H__
+
+#include "ISingleoCommonData.h"
+#include "IInferenceTaskInterface.h"
+
+namespace singleo
+{
+namespace inference
+{
+class IInferenceServiceInterface
+{
+public:
+ virtual ~IInferenceServiceInterface() {};
+
+ virtual void configure() = 0;
+ virtual void prepare() = 0;
+ virtual void invoke(ISingleoCommonData &input, bool async = false) = 0;
+ virtual const ISingleoOutputData &result() = 0;
+};
+
+} // inference
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __IINFERENCE_TASK_INTERFACE_H__
+#define __IINFERENCE_TASK_INTERFACE_H__
+
+#include "ISingleoCommonData.h"
+#include "ISingleoOutputData.h"
+
+namespace singleo
+{
+namespace inference
+{
+class IInferenceTaskInterface
+{
+public:
+ virtual ~IInferenceTaskInterface() {};
+
+ virtual void configure() = 0;
+ virtual void prepare() = 0;
+ virtual void invoke(ISingleoCommonData &input, bool async = false) = 0;
+ virtual const ISingleoOutputData &result() = 0;
+};
+
+} // inference
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __ISINGLEO_OUTPUT_DATA_H__
+#define __ISINGLEO_OUTPUT_DATA_H__
+
+#include "SingleoCommonTypes.h"
+
+namespace singleo
+{
+namespace inference
+{
+class ISingleoOutputData
+{
+public:
+ virtual ~ISingleoOutputData() = default;
+
+ virtual void clear() = 0;
+ virtual unsigned int getFrameNumber() const = 0;
+ virtual const std::vector<OdResultType> &getResult() const = 0;
+};
+
+} // inference
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __INFERENCE_SERVICE_DEFAULT_H__
+#define __INFERENCE_SERVICE_DEFAULT_H__
+
+#include <memory>
+#include "IInferenceServiceInterface.h"
+#include "IInferenceTaskInterface.h"
+#include "SingleoInferenceTypes.h"
+
+namespace singleo
+{
+namespace inference
+{
+class InferenceServiceDefault : public IInferenceServiceInterface
+{
+private:
+ std::unique_ptr<IInferenceTaskInterface> _task;
+
+public:
+ explicit InferenceServiceDefault(TaskType task_type);
+ virtual ~InferenceServiceDefault();
+
+ void configure() override;
+ void prepare() override;
+ void invoke(ISingleoCommonData &input, bool async = false) override;
+ const ISingleoOutputData &result() override;
+};
+
+} // inference
+} // singleo
+
+#endif
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __INFERENCE_SERVICE_EXTERNAL_H__
+#define __INFERENCE_SERVICE_EXTERNAL_H__
+
+#include "IInferenceServiceInterface.h"
+#include "IInferenceTaskInterface.h"
+#include "SingleoInferenceTypes.h"
+
+namespace singleo
+{
+namespace inference
+{
+class InferenceServiceExternal : public IInferenceServiceInterface
+{
+public:
+ explicit InferenceServiceExternal(TaskType task_type);
+ virtual ~InferenceServiceExternal();
+
+ void configure() override;
+ void prepare() override;
+ void invoke(ISingleoCommonData &input, bool async = false) override;
+ const ISingleoOutputData &result() override;
+};
+
+} // inference
+} // singleo
+
+#endif
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __SINGLEO_INFERENCE_TYPES_H__
+#define __SINGLEO_INFERENCE_TYPES_H__
+
+#include <vector>
+
+namespace singleo
+{
+namespace inference
+{
+enum class TaskType { IMAGE_CLASSIFICATION, OBJECT_DETECTION, FACE_DETECTION };
+
+} // inference
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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 "InferenceServiceDefault.h"
+#include "MvObjectDetection.h"
+
+using namespace std;
+using namespace singleo::inference::backends;
+
+namespace singleo
+{
+namespace inference
+{
+InferenceServiceDefault::InferenceServiceDefault(TaskType task_type)
+{
+ // TODO. add other task types later.
+ if (task_type != TaskType::OBJECT_DETECTION)
+ invalid_argument("Task type not supported.");
+
+ _task = make_unique<MvObjectDetection>();
+}
+
+InferenceServiceDefault::~InferenceServiceDefault()
+{}
+
+void InferenceServiceDefault::configure()
+{
+ _task->configure();
+}
+
+void InferenceServiceDefault::prepare()
+{
+ _task->prepare();
+}
+
+void InferenceServiceDefault::invoke(ISingleoCommonData &input, bool async)
+{
+ _task->invoke(input, async);
+}
+
+const ISingleoOutputData &InferenceServiceDefault::result()
+{
+ return _task->result();
+}
+
+}
+}
--- /dev/null
+/**
+ * Copyright (c) 2024 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 <stdexcept>
+#include "InferenceServiceExternal.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace inference
+{
+InferenceServiceExternal::InferenceServiceExternal(TaskType task_type)
+{}
+InferenceServiceExternal::~InferenceServiceExternal()
+{}
+
+void InferenceServiceExternal::configure()
+{
+ throw runtime_error("Not support yet.");
+}
+
+void InferenceServiceExternal::prepare()
+{
+ throw runtime_error("Not support yet.");
+}
+
+void InferenceServiceExternal::invoke(ISingleoCommonData &input, bool async)
+{
+ throw runtime_error("Not support yet.");
+}
+
+const ISingleoOutputData &InferenceServiceExternal::result()
+{
+ throw runtime_error("Not support yet.");
+}
+
+}
+}
--- /dev/null
+PROJECT("singleo_input")
+CMAKE_MINIMUM_REQUIRED(VERSION 3.13)
+
+ADD_SUBDIRECTORY(backends)
+
+IF (${USE_EXTERNAL_INPUT_SOURCE})
+ SET(SINGLEO_INPUT_HEADER_DIRECTORY "")
+ELSE()
+ SET(SINGLEO_INPUT_HEADER_DIRECTORY backends/opencv/include)
+ENDIF()
+
+FILE(GLOB SINGLEO_INPUT_SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/*.cpp")
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SINGLEO_INPUT_SOURCE_FILES})
+
+TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE include ../log/include backends/include ../common/include ${SINGLEO_INPUT_HEADER_DIRECTORY})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE singleo_log singleo_input_backend)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
\ No newline at end of file
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 3.13)
+PROJECT("singleo_input_backend")
+
+FILE(GLOB INPUT_BACKEND_SOURCE_FILES "${PROJECT_SOURCE_DIR}/opencv/src/*.cpp")
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${INPUT_BACKEND_SOURCE_FILES})
+
+TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE include ../../common/include ../../log/include opencv/include)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE opencv_core opencv_imgcodecs opencv_highgui opencv_videoio singleo_log)
+
+# Install the library
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __ICAMERA_BACKEND_H__
+#define __ICAMERA_BACKEND_H__
+
+#include <functional>
+#include "SingleoImageData.h"
+
+namespace singleo
+{
+namespace input
+{
+class ICameraBackend
+{
+public:
+ virtual ~ICameraBackend() {};
+
+ virtual void setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+ void *user_data) = 0;
+ virtual void configure() = 0;
+ virtual void capture(SingleoImageData &out_data) = 0;
+};
+
+} // input
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __OPENCV_BACKEND_H__
+#define __OPENCV_BACKEND_H__
+
+#include <thread>
+#include <memory>
+#include <opencv2/opencv.hpp>
+
+#include "ICameraBackend.h"
+#include "SingleoImageData.h"
+
+namespace singleo
+{
+namespace input
+{
+class OpencvBackend : public ICameraBackend
+{
+private:
+ std::unique_ptr<cv::VideoCapture> _video_capture;
+ cv::Mat _captured_image;
+ std::function<void(ISingleoCommonData &data, void *user_data)> _userCb;
+ void *_userData;
+
+ int findFirstAvailableCamera();
+
+public:
+ OpencvBackend();
+ virtual ~OpencvBackend();
+
+ void setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+ void *user_data) override;
+ void configure() override;
+ void capture(SingleoImageData &out_data) override;
+};
+
+} // input
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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 "OpencvBackend.h"
+#include "SingleoLog.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace input
+{
+OpencvBackend::OpencvBackend()
+{
+ // TODO. There are some cases that one camera device has one more camera ID.
+ // For these cases, I will introduce camera specific meta file approach later.
+ // In this case, camera IDs will be parsed from the given camera specific meta file.
+ int cameraId = findFirstAvailableCamera();
+ if (cameraId == -1)
+ throw runtime_error("No available camera device.");
+
+ SINGLEO_LOGD("Camera ID is %d", cameraId);
+
+ _video_capture = make_unique<cv::VideoCapture>(cameraId);
+ if (!_video_capture->isOpened()) {
+ SINGLEO_LOGE("Failed to open WebCam device.");
+ throw runtime_error("Failed to open WebCap device.");
+ }
+}
+
+OpencvBackend::~OpencvBackend()
+{
+ _video_capture->release();
+}
+
+int OpencvBackend::findFirstAvailableCamera()
+{
+ const unsigned int maxCameraCnt = 10;
+
+ for (unsigned int idx = 0; idx < maxCameraCnt; ++idx) {
+ cv::VideoCapture testCap(idx);
+ if (testCap.isOpened()) {
+ testCap.release();
+ return idx;
+ }
+ }
+
+ return -1;
+}
+
+void OpencvBackend::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+ void *user_data)
+{
+ _userCb = userCb;
+ _userData = user_data;
+
+ SINGLEO_LOGD("OpencvBackend::%s : user callback has been registered.", __func__);
+}
+
+void OpencvBackend::configure()
+{}
+
+void OpencvBackend::capture(SingleoImageData &out_data)
+{
+ *_video_capture >> _captured_image;
+ if (_captured_image.empty()) {
+ SINGLEO_LOGE("Captured frame is empty.");
+ throw runtime_error("Captured frame is empty.");
+ }
+
+ int type = _captured_image.type();
+ if (CV_MAT_DEPTH(type) != CV_8U || CV_MAT_CN(type) != 3) {
+ SINGLEO_LOGE("Invalid image format.");
+ throw runtime_error("Invalid image format.");
+ }
+
+ ImageDataType image_data;
+
+ image_data._data_type = DataType::IMAGE;
+ image_data.width = _captured_image.cols;
+ image_data.height = _captured_image.rows;
+ image_data.byte_per_pixel = _captured_image.channels();
+ image_data.ptr = _captured_image.data;
+
+ out_data.setData(image_data);
+}
+
+}
+}
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __CAMERA_SERVICE_DEFAULT_H__
+#define __CAMERA_SERVICE_DEFAULT_H__
+
+#include <functional>
+#include "ICameraService.h"
+#include "ICameraBackend.h"
+#include "InputTypes.h"
+
+namespace singleo
+{
+namespace input
+{
+class CameraServiceDefault : public ICameraService
+{
+private:
+ std::unique_ptr<ICameraBackend> _camera;
+
+public:
+ explicit CameraServiceDefault(CameraConfig &config);
+ virtual ~CameraServiceDefault();
+
+ void setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+ void *user_data) override;
+ void configure() override;
+ void capture(ISingleoCommonData &data) override;
+};
+
+} // input
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __CAMERA_SERVICE_EXTERNAL_H__
+#define __CAMERA_SERVICE_EXTERNAL_H__
+
+#include <functional>
+#include "ICameraService.h"
+#include "InputTypes.h"
+
+namespace singleo
+{
+namespace input
+{
+class CameraServiceExternal : public ICameraService
+{
+public:
+ explicit CameraServiceExternal(CameraConfig &config);
+ virtual ~CameraServiceExternal();
+
+ void setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+ void *user_data) override;
+ void configure() override;
+ void capture(ISingleoCommonData &data) override;
+};
+
+} // input
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __ICAMERA_SERVICE_H__
+#define __ICAMERA_SERVICE_H__
+
+#include "ISingleoCommonData.h"
+
+namespace singleo
+{
+namespace input
+{
+class ICameraService
+{
+public:
+ virtual ~ICameraService() {};
+
+ virtual void setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+ void *user_data) = 0;
+ virtual void configure() = 0;
+ virtual void capture(ISingleoCommonData &data) = 0;
+};
+
+} // input
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __IINPUT_SERVICE_H__
+#define __IINPUT_SERVICE_H__
+
+#include <functional>
+#include "ISingleoCommonData.h"
+
+namespace singleo
+{
+namespace input
+{
+class IInputService
+{
+public:
+ virtual ~IInputService() {};
+
+ virtual void setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+ void *user_data) = 0;
+ virtual void configure() = 0;
+ virtual void capture(ISingleoCommonData &data) = 0;
+};
+
+} // input
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __INPUT_CAMERA_H__
+#define __INPUT_CAMERA_H__
+
+#include <memory>
+#include "IInputService.h"
+#include "ICameraService.h"
+#include "InputTypes.h"
+
+namespace singleo
+{
+namespace input
+{
+class InputCamera : public IInputService
+{
+private:
+ std::unique_ptr<ICameraService> _input;
+
+public:
+ explicit InputCamera(CameraConfig &config);
+ virtual ~InputCamera();
+
+ void setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+ void *user_data) override;
+ void configure() override;
+ virtual void capture(ISingleoCommonData &data) override;
+};
+
+} // input
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __SINGLEO_INPUT_TYPES_H__
+#define __SINGLEO_INPUT_TYPES_H__
+
+#include "SingleoCommonTypes.h"
+
+namespace singleo
+{
+namespace input
+{
+struct InputConfigBase {
+ InputFeedType _input_feed_type { InputFeedType::NONE };
+ InputConfigBase()
+ {}
+ InputConfigBase(InputFeedType input_feed_type) : _input_feed_type(input_feed_type)
+ {}
+ virtual ~InputConfigBase()
+ {}
+};
+
+struct CameraConfig : public InputConfigBase {
+ CameraConfig() : InputConfigBase(InputFeedType::CAMERA)
+ {}
+
+ CameraBackendType backend_type { CameraBackendType::NONE };
+ unsigned int fps {};
+ bool async { false };
+};
+
+struct ScreenCaptureConfig : public InputConfigBase {
+ ScreenCaptureConfig() : InputConfigBase(InputFeedType::SCREEN_CAPTURE)
+ {}
+
+ unsigned int fps {};
+ bool async { false };
+};
+
+} // input
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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 <memory>
+#include "CameraServiceDefault.h"
+#include "OpencvBackend.h"
+#include "SingleoLog.h"
+
+using namespace std;
+using namespace singleo::input;
+
+namespace singleo
+{
+namespace input
+{
+CameraServiceDefault::CameraServiceDefault(CameraConfig &config)
+{
+ if (config.backend_type != CameraBackendType::OPENCV)
+ throw runtime_error("Camera backend type not supported.");
+
+ _camera = make_unique<OpencvBackend>();
+}
+
+CameraServiceDefault::~CameraServiceDefault()
+{}
+
+void CameraServiceDefault::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+ void *user_data)
+{
+ _camera->setUserCb(userCb, user_data);
+}
+
+void CameraServiceDefault::configure()
+{
+ _camera->configure();
+}
+
+void CameraServiceDefault::capture(ISingleoCommonData &data)
+{
+ _camera->capture(dynamic_cast<SingleoImageData &>(data));
+}
+
+}
+}
--- /dev/null
+/**
+ * Copyright (c) 2024 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 "CameraServiceExternal.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace input
+{
+CameraServiceExternal::CameraServiceExternal(CameraConfig &config)
+{}
+
+CameraServiceExternal::~CameraServiceExternal()
+{}
+
+void CameraServiceExternal::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+ void *user_data)
+{}
+
+void CameraServiceExternal::configure()
+{}
+
+void CameraServiceExternal::capture(ISingleoCommonData &data)
+{}
+
+}
+}
--- /dev/null
+/**
+ * Copyright (c) 2024 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 "InputCamera.h"
+#include "CameraServiceDefault.h"
+#include "SingleoImageData.h"
+#include "SingleoLog.h"
+
+using namespace std;
+using namespace singleo::input;
+
+namespace singleo
+{
+namespace input
+{
+InputCamera::InputCamera(CameraConfig &config)
+{
+ _input = make_unique<CameraServiceDefault>(config);
+}
+
+InputCamera::~InputCamera()
+{}
+
+void InputCamera::setUserCb(const std::function<void(ISingleoCommonData &data, void *user_data)> &userCb,
+ void *user_data)
+{
+ _input->setUserCb(userCb, user_data);
+}
+
+void InputCamera::configure()
+{}
+
+void InputCamera::capture(ISingleoCommonData &data)
+{
+ _input->capture(data);
+
+ // TODO. check if image data captured by backend is valid or not such as pixel format.
+}
+
+}
+}
--- /dev/null
+PROJECT("singleo_log")
+CMAKE_MINIMUM_REQUIRED(VERSION 3.13)
+
+if (${PLATFORM_IS_TIZEN})
+ FILE(GLOB SINGLEO_SERVICE_OD_SOURCE_FILES "${PROJECT_SOURCE_DIR}/tizen/*.cpp")
+else()
+ FILE(GLOB SINGLEO_SERVICE_OD_SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/*.cpp")
+endif()
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SINGLEO_SERVICE_OD_SOURCE_FILES})
+
+if (${PLATFORM_IS_TIZEN})
+ TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE include /usr/include/dlog)
+else()
+ TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE include)
+endif()
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __SINGLEO_LOG_H__
+#define __SINGLEO_LOG_H__
+
+#include "SingleoLogBackend.h"
+
+#define SINGLEO_LOGD(format, ...) singleo_log_output(SingleoLogType::DEBUG, format, ##__VA_ARGS__)
+#define SINGLEO_LOGI(format, ...) singleo_log_output(SingleoLogType::INFO, format, ##__VA_ARGS__)
+#define SINGLEO_LOGW(format, ...) singleo_log_output(SingleoLogType::WARNING, format, ##__VA_ARGS__)
+#define SINGLEO_LOGE(format, ...) singleo_log_output(SingleoLogType::ERROR, format, ##__VA_ARGS__)
+#define SINGLEO_LOGC(format, ...) singleo_log_output(SingleoLogType::CRITICAL, format, ##__VA_ARGS__)
+
+void setSingleoLogLevel(SingleoLogType level);
+
+#endif
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __SINGLEO_LOG_BACKEND_H__
+#define __SINGLEO_LOG_BACKEND_H__
+
+#include "SingleoLogType.h"
+
+void singleo_log_output(SingleoLogType level, const char *format, ...);
+
+#endif
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __SINGLEO_LOG_TYPE_H__
+#define __SINGLEO_LOG_TYPE_H__
+
+#include <string>
+#include <cstdio>
+#include <cstdarg>
+
+enum class SingleoLogType { DEBUG, INFO, WARNING, ERROR, CRITICAL };
+
+#endif
--- /dev/null
+/**
+ * Copyright (c) 2024 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 <iostream>
+#include "SingleoLogBackend.h"
+
+using namespace std;
+
+SingleoLogType singleoCurrentLogLevel = SingleoLogType::ERROR;
+
+void singleo_log_output(SingleoLogType level, const char *format, ...)
+{
+ if (level > singleoCurrentLogLevel)
+ return;
+
+ va_list args;
+ va_start(args, format);
+
+ int size = vsnprintf(nullptr, 0, format, args);
+ va_end(args);
+
+ string buffer(size + 1, '\0');
+
+ va_start(args, format);
+ vsnprintf(&buffer[0], buffer.size(), format, args);
+ va_end(args);
+
+ cout << buffer << endl;
+}
+
+void setSingleoLogLevel(SingleoLogType level)
+{
+ singleoCurrentLogLevel = level;
+}
--- /dev/null
+/**
+ * Copyright (c) 2024 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 <dlog.h>
+#include "SingleoLogBackend.h"
+
+using namespace std;
+
+SingleoLogType singleoCurrentLogLevel = SingleoLogType::ERROR;
+
+void singleo_log_output(SingleoLogType level, const char *format, ...)
+{
+ if (level > singleoCurrentLogLevel)
+ return;
+
+ va_list args;
+ va_start(args, format);
+
+ int size = vsnprintf(nullptr, 0, format, args);
+ va_end(args);
+
+ string buffer(size + 1, '\0');
+
+ va_start(args, format);
+ vsnprintf(&buffer[0], buffer.size(), format, args);
+ va_end(args);
+
+ switch (level) {
+ case SingleoLogType::DEBUG:
+ LOGD("%s", buffer.c_str());
+ break;
+ case SingleoLogType::INFO:
+ LOGI("%s", buffer.c_str());
+ break;
+ case SingleoLogType::WARNING:
+ LOGW("%s", buffer.c_str());
+ break;
+ case SingleoLogType::ERROR:
+ case SingleoLogType::CRITICAL:
+ LOGE("%s", buffer.c_str());
+ break;
+ }
+}
+
+void setSingleoLogLevel(SingleoLogType level)
+{
+ singleoCurrentLogLevel = level;
+}
--- /dev/null
+Name: singleo
+Summary: SingleO AI Service Framework
+Version: 0.0.1
+Release: 0
+Group: Multimedia/Framework
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+BuildRequires: cmake
+BuildRequires: pkgconfig(capi-media-vision)
+BuildRequires: pkgconfig(opencv)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: gtest-devel
+
+%define enable_autozoom_api 1
+%define BUILD_OPTIONS -DPLATFORM_IS_TIZEN=0 -DUSE_EXTERNAL_INFERENCE_SERVICE=0 -DUSE_AUTOZOOM_API=%{enable_autozoom_api}
+
+%description
+SingleO AI Service Framework
+
+%package release
+Summary: SingleO AI Service Framework
+Group: Multimedia/Framework
+
+%description release
+SingleO AI Service Framework
+
+%package devel
+Summary: SingleO AI Service Framework
+Group: Multimedia/Framework
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+SingleO AI Service Framework (Dev)
+
+%package test
+Summary: Test case for SingleO AI Service Framework
+Group: Multimedia/Framework
+Requires: %{name} = %{version}-%{release}
+
+%description test
+Test case for SingleO AI Service Framework (Dev)
+
+%prep
+%setup -q
+
+%build
+%if 0%{?sec_build_binary_debug_enable}
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+%endif
+
+export CFLAGS+=" -DPATH_LIBDIR=\\\"%{_libdir}\\\" -DSYSCONFDIR=\\\"%{_hal_sysconfdir}\\\""
+export CXXFLAGS+=" -DPATH_LIBDIR=\\\"%{_libdir}\\\" -DSYSCONFDIR=\\\"%{_hal_sysconfdir}\\\""
+
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DTZ_SYS_BIN=%TZ_SYS_BIN %{BUILD_OPTIONS} \
+
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+
+%make_install
+
+%post -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
+
+%files release
+%manifest singleo.manifest
+%license LICENSE.APLv2
+
+%files devel
+%{_libdir}/pkgconfig/*.pc
+%{_libdir}/libsingleo_log.so
+%{_libdir}/libsingleo_inference.so
+%{_libdir}/libsingleo_inference_backend.so
+%{_libdir}/libsingleo_service.so
+%{_libdir}/libsingleo_input.so
+%{_libdir}/libsingleo_input_backend.so
+
+%files test
+%{_bindir}/test_singleo
--- /dev/null
+PROJECT("singleo_service")
+CMAKE_MINIMUM_REQUIRED(VERSION 3.13)
+
+FILE(GLOB SINGLEO_SERVICE_SOURCE_FILES "${PROJECT_SOURCE_DIR}/*.cpp"
+ "${PROJECT_SOURCE_DIR}/src/*.cpp"
+ "${PROJECT_SOURCE_DIR}/common/src/*.cpp"
+ "${PROJECT_SOURCE_DIR}/../common/src/*.cpp")
+
+IF (${USE_AUTOZOOM_API})
+ INCLUDE(auto_zoom/CMakeLists.txt)
+ LIST(APPEND SERVICE_HEADER_LIST ${CMAKE_CURRENT_SOURCE_DIR}/auto_zoom/include)
+ENDIF()
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SINGLEO_SERVICE_SOURCE_FILES})
+
+TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE include common/include ../capi/ ../input/include ../log/include ../inference/include ../common/include ${SERVICE_HEADER_LIST})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE opencv_imgcodecs singleo_log singleo_input ${SERVICE_LIBRARY_LIST})
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
\ No newline at end of file
--- /dev/null
+set(SINGLEO_SERVICE_SOURCE_FILES
+ ${SINGLEO_SERVICE_SOURCE_FILES}
+ auto_zoom/src/AutoZoom.cpp
+)
+
+LIST(APPEND SERVICE_LIBRARY_LIST singleo_inference)
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __AUTO_ZOOM_H__
+#define __AUTO_ZOOM_H__
+
+#include <queue>
+#include <functional>
+
+#include "IService.h"
+#include "SingleoCommonTypes.h"
+#include "IInferenceServiceInterface.h"
+#include "SingleoImageData.h"
+#include "IInputService.h"
+#include "InputTypes.h"
+
+namespace singleo
+{
+namespace services
+{
+struct AutoZoomResult {
+ size_t num_of_result {};
+ Rect rect;
+};
+
+enum class AutoZoomResultType { X, Y, WIDTH, HEIGHT };
+
+class AutoZoom : public IService
+{
+private:
+ std::unique_ptr<singleo::inference::IInferenceServiceInterface> _inference_service;
+ std::unique_ptr<singleo::input::IInputService> _input_service;
+ std::queue<SingleoImageData> _input_data_q;
+ AutoZoomResult _result {};
+ std::map<std::string, AutoZoomResultType> _result_keys = { { "X", AutoZoomResultType::X },
+ { "Y", AutoZoomResultType::Y },
+ { "WIDTH", AutoZoomResultType::WIDTH },
+ { "HEIGHT", AutoZoomResultType::HEIGHT } };
+
+ bool isKeyValid(std::string key);
+ void updateResult();
+
+public:
+ explicit AutoZoom(input::InputConfigBase &config);
+ virtual ~AutoZoom() = default;
+
+ static IService *create(input::InputConfigBase &config)
+ {
+ return new AutoZoom(config);
+ }
+
+ // This function will be called by specific input service internally.
+ // Ps. caller has to provide captured data with concrete class object as data parameter.
+ static void inputServiceCb(ISingleoCommonData &data, void *user_data);
+ void perform_with_file(BaseDataType &input_data) override;
+ void perform() override;
+ void performAsync() override;
+ void getResultCnt(unsigned int *cnt) override;
+ void getResultInt(unsigned int idx, std::string key, unsigned int *value) override;
+};
+
+} // service
+} // singleo
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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 "AutoZoom.h"
+#include "InferenceServiceDefault.h"
+#include "SingleoLog.h"
+#include "ImagePreprocessor.h"
+#include "ServiceFactory.h"
+#include "InputCamera.h"
+#include "InputTypes.h"
+
+using namespace std;
+using namespace singleo::inference;
+using namespace singleo::input;
+
+namespace singleo
+{
+namespace services
+{
+REGISTER_SERVICE(AutoZoom)
+
+AutoZoom::AutoZoom(InputConfigBase &config)
+{
+ // In default, we will use InferenceServiceDefault class to use Mediavision framework
+ // for inference service.
+ _inference_service = make_unique<InferenceServiceDefault>(TaskType::OBJECT_DETECTION);
+
+ // Create InputCamera service if input service type is CAMERA.
+ if (config._input_feed_type == InputFeedType::CAMERA) {
+ _input_service = make_unique<InputCamera>(dynamic_cast<CameraConfig &>(config));
+ _input_service->setUserCb(inputServiceCb, static_cast<void *>(this));
+ _input_service->configure();
+
+ SINGLEO_LOGD("Camera input service has been initialized.");
+ }
+
+ _inference_service->configure();
+ _inference_service->prepare();
+}
+
+void AutoZoom::inputServiceCb(ISingleoCommonData &data, void *user_data)
+{
+ auto auto_zoom = static_cast<AutoZoom *>(user_data);
+
+ SINGLEO_LOGD("AutoZoom::%s : user callback has been called.", __func__);
+}
+
+bool AutoZoom::isKeyValid(std::string key)
+{
+ auto it = _result_keys.find(key);
+ if (it == _result_keys.end())
+ return false;
+
+ return true;
+}
+
+void AutoZoom::perform_with_file(BaseDataType &input_data)
+{
+ ImagePreprocessor preprocessor(input_data);
+ SingleoImageData image_data;
+ image_data.setData(preprocessor.getData());
+
+ _inference_service->invoke(image_data);
+
+ updateResult();
+}
+
+void AutoZoom::perform()
+{
+ if (!_input_service) {
+ SINGLEO_LOGE("This API is valid only the case that input feed device type is given.");
+ throw runtime_error("Invalid API request.");
+ }
+
+ SingleoImageData captured_image;
+
+ _input_service->capture(captured_image);
+
+ ImagePreprocessor preprocessor(captured_image.getData());
+ SingleoImageData preprocessed_image;
+
+ preprocessed_image.setData(preprocessor.getData());
+ _inference_service->invoke(preprocessed_image);
+
+ updateResult();
+}
+
+void AutoZoom::performAsync()
+{
+ throw runtime_error("Not supported yet.");
+}
+
+void AutoZoom::updateResult()
+{
+ const ISingleoOutputData &output_data = _inference_service->result();
+ unsigned int frame_number = output_data.getFrameNumber();
+ const vector<OdResultType> &result = output_data.getResult();
+
+ // TODO. implement Postprocessor which calculates Autozoom position using above 'result' vector.
+
+ SINGLEO_LOGD("result cnt = %zu", result.size());
+ _result.num_of_result = 0;
+
+ if (result.size() == 0) {
+ SINGLEO_LOGW("No detected objects.");
+ return;
+ }
+
+ // TODO. Temparary code for test.
+ _result.rect = result[0].rect;
+ _result.num_of_result = result.size();
+}
+
+void AutoZoom::getResultCnt(unsigned int *cnt)
+{
+ // TODO. Temparary code.
+ *cnt = static_cast<unsigned int>(_result.num_of_result);
+}
+
+void AutoZoom::getResultInt(unsigned int idx, std::string key, unsigned int *value)
+{
+ transform(key.begin(), key.end(), key.begin(), ::toupper);
+
+ SINGLEO_LOGD("given key = %s", key.c_str());
+
+ if (!isKeyValid(key))
+ throw runtime_error("A given result key is inavlid.");
+
+ switch (_result_keys[key]) {
+ case AutoZoomResultType::X:
+ *value = _result.rect.left;
+ break;
+ case AutoZoomResultType::Y:
+ *value = _result.rect.top;
+ break;
+ case AutoZoomResultType::WIDTH:
+ *value = _result.rect.right;
+ break;
+ case AutoZoomResultType::HEIGHT:
+ *value = _result.rect.bottom;
+ break;
+ }
+}
+
+}
+}
--- /dev/null
+/**
+ * Copyright (c) 2022 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.
+ */
+
+#ifndef __CONTEXT_H__
+#define __CONTEXT_H__
+
+#include "SingleoCommonTypes.h"
+#include "IService.h"
+
+namespace singleo
+{
+namespace services
+{
+class Context
+{
+public:
+ Context()
+ {}
+ ~Context()
+ {}
+
+ ServiceType _service_type;
+ IService *_service_handle {};
+};
+
+}
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __IPREPROCESSOR_H__
+#define __IPREPROCESSOR_H__
+
+#include "SingleoCommonTypes.h"
+
+namespace singleo
+{
+namespace services
+{
+class IPreprocessor
+{
+public:
+ virtual ~IPreprocessor() {};
+
+ virtual void setData(BaseDataType &data) = 0;
+ virtual BaseDataType &getData() = 0;
+};
+
+}
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __ISERVICE_H__
+#define __ISERVICE_H__
+
+#include "SingleoCommonTypes.h"
+#include "IPreprocessor.h"
+#include "InputDataType.h"
+
+namespace singleo
+{
+namespace services
+{
+class IService
+{
+public:
+ virtual ~IService() {};
+
+ virtual void perform_with_file(BaseDataType &input_data) = 0;
+ virtual void perform() = 0;
+ virtual void performAsync() = 0;
+ virtual void getResultCnt(unsigned int *cnt) = 0;
+ virtual void getResultInt(unsigned int idx, std::string key, unsigned int *value) = 0;
+};
+
+}
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __IMAGE_PREPROCESSOR_H__
+#define __IMAGE_PREPROCESSOR_H__
+
+#include <memory>
+#include <string>
+#include <opencv2/opencv.hpp>
+
+#include "IPreprocessor.h"
+#include "InputDataType.h"
+
+namespace singleo
+{
+namespace services
+{
+class ImagePreprocessor : public IPreprocessor
+{
+private:
+ cv::Mat _cv_image {};
+ ImageDataType _image_data {};
+
+ void run(std::string file_name);
+ void run(ImageDataType &image_data);
+
+public:
+ explicit ImagePreprocessor() = default;
+ ImagePreprocessor(BaseDataType &input_data);
+ virtual ~ImagePreprocessor() = default;
+
+ void setData(BaseDataType &data) override;
+ BaseDataType &getData() override;
+
+ // For debug
+ void drawRedBox(Rect &rect);
+ void toFile(std::string file_name);
+};
+
+}
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __INPUT_DATA_TYPE_H__
+#define __INPUT_DATA_TYPE_H__
+
+#include "SingleoCommonTypes.h"
+
+namespace singleo
+{
+namespace services
+{
+// TODO
+
+}
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __SERVICE_CONFIG_PARSER_H__
+#define __SERVICE_CONFIG_PARSER_H__
+
+#include "SingleoCommonTypes.h"
+#include "InputTypes.h"
+
+namespace singleo
+{
+namespace services
+{
+class ServiceConfigParser
+{
+private:
+ std::map<std::string, std::string> _params;
+ ServiceType _service_type { ServiceType::NONE };
+ InputFeedType _input_feed_type { InputFeedType::NONE };
+ CameraBackendType _camera_backend { CameraBackendType::NONE };
+ unsigned int _fps {};
+ bool _async_mode {};
+ input::InputConfigBase _default_config;
+ input::CameraConfig _camera_config;
+ input::ScreenCaptureConfig _screen_capture_config;
+
+ bool isValidPair(const std::string &key, const std::string &value);
+ void trim(std::string &str);
+ bool isKeyValid(std::map<std::string, bool> &valid_keys, const std::string &key);
+ void update();
+ void setServiceType(std::string key);
+ void setInputFeedType(std::string key);
+ void setCameraBackendType(std::string key);
+ void setFps(std::string key);
+ void setAsyncMode(std::string key);
+
+public:
+ explicit ServiceConfigParser() = default;
+ ServiceConfigParser(std::string option);
+ virtual ~ServiceConfigParser() = default;
+
+ void parse(std::string option);
+ ServiceType getServiceType();
+ InputFeedType getInputFeedType();
+ CameraBackendType getCameraBackendType();
+ unsigned int getFps();
+ bool getAsyncMode();
+ input::InputConfigBase &getConfig(InputFeedType input_feed_type);
+};
+
+}
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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.
+ */
+
+#ifndef __SERVICE_FACTORY_H__
+#define __SERVICE_FACTORY_H__
+
+#include <map>
+#include <vector>
+#include <stdexcept>
+#include "IService.h"
+#include "InputTypes.h"
+
+namespace singleo
+{
+namespace services
+{
+class ServiceFactory
+{
+public:
+ using createFunc = IService *(*) (input::InputConfigBase &config);
+ static std::map<std::string, createFunc> __service_table;
+
+ static IService *create(const std::string &className, input::InputConfigBase &config)
+ {
+ auto it = __service_table.find(className);
+ if (it != __service_table.end())
+ return it->second(config);
+
+ return nullptr;
+ }
+};
+
+#define REGISTER_SERVICE(name) \
+ const bool is##nameRegistered = [] { \
+ ServiceFactory::__service_table[#name] = &name::create; \
+ return true; \
+ }();
+
+}
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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 "ImagePreprocessor.h"
+#include "SingleoLog.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace services
+{
+ImagePreprocessor::ImagePreprocessor(BaseDataType &input_data)
+{
+ if (input_data._data_type != DataType::FILE && input_data._data_type != DataType::IMAGE) {
+ SINGLEO_LOGE("Invalid data type.");
+ throw invalid_argument("Invalid data type.");
+ }
+
+ if (input_data._data_type == DataType::FILE) {
+ FileDataType &file_data = dynamic_cast<FileDataType &>(input_data);
+
+ run(file_data._file_name);
+ return;
+ }
+
+ ImageDataType &image_data = dynamic_cast<ImageDataType &>(input_data);
+
+ run(image_data);
+}
+
+void ImagePreprocessor::run(string file_name)
+{
+ _cv_image = cv::imread(file_name, cv::IMREAD_COLOR);
+ cv::cvtColor(_cv_image, _cv_image, cv::COLOR_BGR2RGB);
+
+ if (_cv_image.empty())
+ throw runtime_error("Fail to load image file.");
+}
+
+void ImagePreprocessor::run(ImageDataType &image_data)
+{
+ cv::Mat cv_image(cv::Size(image_data.width, image_data.height), CV_MAKETYPE(CV_8U, 3), image_data.ptr);
+
+ _cv_image = cv_image;
+}
+
+void ImagePreprocessor::setData(BaseDataType &data)
+{
+ _image_data = dynamic_cast<ImageDataType &>(data);
+}
+
+BaseDataType &ImagePreprocessor::getData()
+{
+ if (_cv_image.empty())
+ throw runtime_error("Invalid cv image object.");
+
+ _image_data.width = _cv_image.cols;
+ _image_data.height = _cv_image.rows;
+ _image_data.byte_per_pixel = _cv_image.channels();
+ _image_data.ptr = _cv_image.data;
+
+ return _image_data;
+}
+
+void ImagePreprocessor::drawRedBox(Rect &rect)
+{
+ cv::Point leftTop(rect.left, rect.top);
+ cv::Point rightBottom(rect.right, rect.bottom);
+
+ cv::rectangle(_cv_image, cv::Rect(leftTop, rightBottom), cv::Scalar(0, 0, 255));
+}
+
+void ImagePreprocessor::toFile(string file_name)
+{
+ if (file_name.empty())
+ throw invalid_argument("File name is empty.");
+
+ cv::imwrite(file_name, _cv_image);
+}
+
+}
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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 <sstream>
+#include <algorithm>
+#include "ServiceConfigParser.h"
+#include "SingleoLog.h"
+
+using namespace std;
+using namespace singleo::input;
+
+namespace singleo
+{
+namespace services
+{
+ServiceConfigParser::ServiceConfigParser(string option)
+{
+ parse(option);
+}
+
+bool ServiceConfigParser::isValidPair(const string &key, const string &value)
+{
+ return !key.empty() && !value.empty();
+}
+
+bool ServiceConfigParser::isKeyValid(map<string, bool> &valid_keys, const string &key)
+{
+ auto it = valid_keys.find(key);
+ if (it == valid_keys.end()) {
+ SINGLEO_LOGE("A given key not found.");
+ return false;
+ }
+
+ // check if key is duplicated or not.
+ if (it->second) {
+ SINGLEO_LOGE("Key(%s) is duplicated.", it->first.c_str());
+ return false;
+ }
+
+ it->second = true;
+
+ return true;
+}
+
+void ServiceConfigParser::setServiceType(string key)
+{
+ static map<string, ServiceType> valid_services = { { "AUTO_ZOOM", ServiceType::AUTO_ZOOM } };
+
+ auto it = valid_services.find(key);
+ if (it == valid_services.end())
+ throw runtime_error("Invalid service type.");
+
+ _service_type = it->second;
+}
+
+void ServiceConfigParser::setInputFeedType(std::string key)
+{
+ static map<string, InputFeedType> valid_services = {
+ { "CAMERA", InputFeedType::CAMERA },
+ { "SCREEN_CAPTURE", InputFeedType::SCREEN_CAPTURE },
+ };
+
+ auto it = valid_services.find(key);
+ if (it == valid_services.end())
+ throw invalid_argument("Invalid input feed type.");
+
+ _input_feed_type = it->second;
+}
+
+void ServiceConfigParser::setCameraBackendType(std::string key)
+{
+ static map<string, CameraBackendType> valid_services = { { "OPENCV", CameraBackendType::OPENCV },
+ { "CAMERA_API", CameraBackendType::CAMERA_API },
+ { "VISION_SOURCE", CameraBackendType::VISION_SOURCE } };
+
+ auto it = valid_services.find(key);
+ if (it == valid_services.end())
+ throw invalid_argument("Invalid camera backend type.");
+
+ _camera_backend = it->second;
+}
+
+void ServiceConfigParser::setFps(std::string key)
+{
+ int fps = std::stoi(key);
+ if (fps < 1 || fps > 60)
+ throw invalid_argument("Invalid fps.");
+
+ _fps = fps;
+}
+
+void ServiceConfigParser::setAsyncMode(std::string key)
+{
+ int async_mode = std::stoi(key);
+ if (async_mode != 0 && async_mode != 1)
+ throw invalid_argument("Invalid async mode.Async mode should be 0 or 1.");
+
+ _async_mode = async_mode;
+}
+
+ServiceType ServiceConfigParser::getServiceType()
+{
+ return _service_type;
+}
+
+InputFeedType ServiceConfigParser::getInputFeedType()
+{
+ return _input_feed_type;
+}
+
+void ServiceConfigParser::trim(string &str)
+{
+ str.erase(0, str.find_first_not_of(" \n\r\t"));
+ str.erase(str.find_last_not_of(" \n\r\t") + 1);
+}
+
+void ServiceConfigParser::parse(string option)
+{
+ map<string, bool> valid_keys = {
+ { "SERVICE", false }, { "INPUT", false }, { "CAMERA_BACKEND", false }, { "FPS", false }, { "ASYNC", false }
+ };
+ istringstream iss(option);
+ string token;
+
+ while (std::getline(iss, token, ',')) {
+ string key, value;
+ istringstream kvStream(token);
+
+ if (getline(kvStream, key, '=') && getline(kvStream, value)) {
+ trim(key);
+ trim(value);
+
+ if (!isValidPair(key, value))
+ throw invalid_argument("Invalid option string.");
+
+ transform(key.begin(), key.end(), key.begin(), ::toupper);
+ transform(value.begin(), value.end(), value.begin(), ::toupper);
+
+ if (!isKeyValid(valid_keys, key))
+ throw invalid_argument("A given key is invalid.");
+
+ _params[key] = value;
+ } else {
+ throw invalid_argument("Invalid format for parameter pair.");
+ }
+ }
+
+ update();
+}
+
+void ServiceConfigParser::update()
+{
+ using setParamCallback = void (ServiceConfigParser::*)(std::string);
+
+ auto setParam = [this](const std::string &key, setParamCallback cb) -> void {
+ auto it = _params.find(key);
+ if (it == _params.end()) {
+ if (key == "SERVICE") // "SERVICE is mandatorily required but optional for other."
+ throw invalid_argument(string("Invalid ") + key + ": " + it->second);
+ else
+ return;
+ }
+
+ (this->*cb)(it->second);
+
+ SINGLEO_LOGD("Parsed : key(%s) -> value(%s)", key.c_str(), it->second.c_str());
+ };
+
+ setParam("SERVICE", &ServiceConfigParser::setServiceType);
+ setParam("INPUT", &ServiceConfigParser::setInputFeedType);
+ setParam("CAMERA_BACKEND", &ServiceConfigParser::setCameraBackendType);
+ setParam("FPS", &ServiceConfigParser::setFps);
+ setParam("ASYNC", &ServiceConfigParser::setAsyncMode);
+}
+
+InputConfigBase &ServiceConfigParser::getConfig(InputFeedType input_feed_type)
+{
+ // TODO. consider for Screen capture type later.
+
+ if (input_feed_type != InputFeedType::CAMERA)
+ return _default_config;
+
+ _camera_config.backend_type = _camera_backend;
+ _camera_config.fps = _fps;
+ _camera_config.async = _async_mode;
+
+ return _camera_config;
+}
+
+}
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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 "ServiceFactory.h"
+
+using namespace std;
+
+namespace singleo
+{
+namespace services
+{
+map<string, ServiceFactory::createFunc> ServiceFactory::__service_table;
+
+}
+}
\ No newline at end of file
--- /dev/null
+#include <dlfcn.h>
+
+#include "singleo_native_capi.h"
+#include "Context.h"
+#include "ServiceConfigParser.h"
+#include "IPreprocessor.h"
+#include "SingleoLog.h"
+#include "ServiceFactory.h"
+
+using namespace std;
+using namespace singleo;
+using namespace singleo::services;
+using namespace singleo::input;
+
+int singleo_service_create(const char *option, singleo_service_h *handle)
+{
+ IService *service_handle = NULL;
+ ServiceType service_type {};
+ Context *context = NULL;
+
+ try {
+ ServiceConfigParser parser(option);
+
+ if (ServiceType::AUTO_ZOOM == parser.getServiceType()) {
+ service_handle = ServiceFactory::create("AutoZoom", parser.getConfig(parser.getInputFeedType()));
+ if (!service_handle)
+ throw runtime_error("Failed to create AutoZoom service.");
+
+ SINGLEO_LOGD("AutoZoom service has been created.");
+ service_type = ServiceType::AUTO_ZOOM;
+ } else {
+ SINGLEO_LOGE("Invalid service type.");
+ throw runtime_error("Invalid service type.");
+ }
+
+ context = new Context();
+ } catch (const exception &) {
+ if (service_handle)
+ delete service_handle;
+
+ return -1;
+ }
+
+ context->_service_handle = service_handle;
+ context->_service_type = service_type;
+
+ *handle = static_cast<void *>(context);
+
+ return 0;
+}
+
+int singleo_service_destroy(singleo_service_h handle)
+{
+ auto context = static_cast<Context *>(handle);
+
+ if (context->_service_type == ServiceType::AUTO_ZOOM)
+ delete static_cast<IService *>(context->_service_handle);
+
+ return 0;
+}
+
+int singleo_service_perform_with_file(singleo_service_h handle, const char *file_name)
+{
+ try {
+ auto context = static_cast<Context *>(handle);
+ FileDataType input_data;
+
+ SINGLEO_LOGD("Inference requested with %s", file_name);
+ input_data._file_name = file_name;
+ context->_service_handle->perform_with_file(input_data);
+ } catch (const exception &e) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int singleo_service_perform(singleo_service_h handle)
+{
+ try {
+ auto context = static_cast<Context *>(handle);
+ context->_service_handle->perform();
+ } catch (const exception &e) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int singleo_service_get_result_cnt(singleo_service_h handle, unsigned int *cnt)
+{
+ try {
+ auto context = static_cast<Context *>(handle);
+ context->_service_handle->getResultCnt(cnt);
+ } catch (const exception &e) {
+ return -1;
+ }
+
+ return 0;
+}
+
+int singleo_service_get_result_int(singleo_service_h handle, unsigned int idx, const char *key, unsigned int *value)
+{
+ try {
+ auto context = static_cast<Context *>(handle);
+ context->_service_handle->getResultInt(idx, key, value);
+ } catch (const exception &e) {
+ return -1;
+ }
+
+ return 0;
+}
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+</manifest>
--- /dev/null
+
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=/usr
+libdir=@LIB_INSTALL_DIR@
+includedir=/usr/include/media
+
+Name: @PC_NAME@
+Description: @PACKAGE_DESCRIPTION@
+Version: @VERSION@
+Requires: @PC_REQUIRED@
+Libs: -L${libdir} @PC_LDFLAGS@
+Cflags: -I${includedir} -I/usr/include
--- /dev/null
+add_subdirectory(services)
\ No newline at end of file
--- /dev/null
+PROJECT(test_singleo)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.13)
+
+SET(TEST_SOURCE_LIST test_dummy.cpp)
+
+IF (${USE_AUTOZOOM_API})
+ SET(TEST_SOURCE_LIST ${TEST_SOURCE_LIST} test_autozoom.cpp)
+ENDIF()
+
+SET(SRC_FILES
+ ${TEST_SOURCE_LIST})
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRC_FILES})
+TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} PRIVATE -DTEST_RES_PATH="${TEST_RES_PATH}")
+TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE ../../capi/)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME}
+ gtest gtest_main singleo_service)
+
+install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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 <iostream>
+#include <algorithm>
+#include <string.h>
+
+#include "gtest/gtest.h"
+#include "singleo_native_capi.h"
+
+#define IMG_DOG TEST_RES_PATH "/usr/share/capi-media-vision/res/inference/images/dog2.jpg"
+
+using namespace testing;
+using namespace std;
+
+TEST(AutoZoomTest, InferenceRequestShouldBeOk)
+{
+ singleo_service_h handle;
+
+ int ret = singleo_service_create("service=auto_zoom", &handle);
+ ASSERT_EQ(ret, 0);
+
+ ret = singleo_service_perform_with_file(handle, IMG_DOG);
+ ASSERT_EQ(ret, 0);
+
+ unsigned int cnt;
+
+ ret = singleo_service_get_result_cnt(handle, &cnt);
+ ASSERT_EQ(ret, 0);
+
+ for (unsigned int idx = 0; idx < cnt; ++idx) {
+ unsigned int x, y, w, h;
+
+ ret = singleo_service_get_result_int(handle, idx, "x", &x);
+ ASSERT_EQ(ret, 0);
+ ret = singleo_service_get_result_int(handle, idx, "y", &y);
+ ASSERT_EQ(ret, 0);
+ ret = singleo_service_get_result_int(handle, idx, "width", &w);
+ ASSERT_EQ(ret, 0);
+ ret = singleo_service_get_result_int(handle, idx, "height", &h);
+ ASSERT_EQ(ret, 0);
+
+ cout << x << " x " << y << " ~ " << w << " x " << h << endl;
+ }
+
+ ret = singleo_service_destroy(handle);
+ ASSERT_EQ(ret, 0);
+}
+
+TEST(AutoZoomTest, InferenceRequestWithCameraInputFeedShouldBeOk)
+{
+ singleo_service_h handle;
+
+ int ret =
+ singleo_service_create("service=auto_zoom, input=camera, camera_backend=opencv, fps=30, async=0", &handle);
+ ASSERT_EQ(ret, 0);
+
+ ret = singleo_service_perform(handle);
+ ASSERT_EQ(ret, 0);
+
+ unsigned int cnt;
+
+ ret = singleo_service_get_result_cnt(handle, &cnt);
+ ASSERT_EQ(ret, 0);
+
+ for (unsigned int idx = 0; idx < cnt; ++idx) {
+ unsigned int x, y, w, h;
+
+ ret = singleo_service_get_result_int(handle, idx, "x", &x);
+ ASSERT_EQ(ret, 0);
+ ret = singleo_service_get_result_int(handle, idx, "y", &y);
+ ASSERT_EQ(ret, 0);
+ ret = singleo_service_get_result_int(handle, idx, "width", &w);
+ ASSERT_EQ(ret, 0);
+ ret = singleo_service_get_result_int(handle, idx, "height", &h);
+ ASSERT_EQ(ret, 0);
+
+ cout << x << " x " << y << " ~ " << w << " x " << h << endl;
+ }
+
+ ret = singleo_service_destroy(handle);
+ ASSERT_EQ(ret, 0);
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2024 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 "gtest/gtest.h"
+
+using namespace std;
+using namespace testing;
+
+TEST(SingloTest, DummayTest)
+{}