From: YoungHun Kim Date: Fri, 2 Aug 2024 08:36:21 +0000 (+0900) Subject: Update file format X-Git-Tag: accepted/tizen/unified/20240806.010604^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dd886f9e1d604a4ac02d2b79e1b97b7e33ff7fc2;p=platform%2Fcore%2Fmultimedia%2Fresource-manager.git Update file format - Remove CRLF line terminators Change-Id: I553d841974802698ab66836e7b152fae826f917b --- diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 index bbe9d02..f94008a 100644 --- a/LICENSE.APLv2 +++ b/LICENSE.APLv2 @@ -1,206 +1,206 @@ -Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. - - - +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + + + diff --git a/include/rm_api.h b/include/rm_api.h index 60167a7..4727db5 100644 --- a/include/rm_api.h +++ b/include/rm_api.h @@ -1,117 +1,117 @@ -/* - * 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 __RM_API_H__ -#define __RM_API_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Register a player - * @param[in] cb callback to receive resource conflict event - * @param[in] data user data passed to cb - * @param[out] handle handle got from resource manager - * @param[in] consumer_info player information such as player type, priority, window id and so on - * @return int failure reason - * @pre None - * @post None - * @exception None - */ -int rm_register(rm_resource_cb cb, void *data, int *handle, rm_consumer_info *consumer_info); - -/** - * @brief Unregister a player - * @param[in] handle handle to unregister - * @return int failure reason - * @pre None - * @post handle is deactivated.\n - * All resources which have been allocated to handle are released - * @exception None - */ -int rm_unregister(int handle); - -/** - * @brief request to allocate resources - * @param[in] handle handle to which resources are to be allocated - * @param[in] requests Resource information to allocate - * can request N resources simultaneously - * Ex. {Resource A, Resource A, Resouce B,¡¦. Resouce N} - * @param[out] return_devices allocated Device ID. Caller needs to release memory allocated by Resource Manager - * !!IMPORTANT!!! - * The member of structure(device_node, omx_comp_name) must be freed by API caller side. - * @return int failure reason - * @pre None - * @post None - * @exception None - */ -int rm_allocate_resources(int handle, const rm_category_request_s *requests, rm_device_return_s *return_devices); - -/** - * @brief request to release resources - * @param[in] handle handle to which resources have been allocated - * @param[in] requests device information to release - * @return int failure reason - * @pre None - * @post None - * @exception None - */ -int rm_deallocate_resources(int handle, rm_device_request_s *requests); - -/** - * @brief Query resource state - * @param[in] handle handle gotten from rm_register() - * @param[in] query_type query type such as allocation - * @param[in] requests Resource information to query - * @param[out] query_result 0: not available - * 1: available - * @return int failure reason - * @pre None - * @post None - * @exception None - */ -int rm_query(int handle, rm_query_type_e query_type, rm_category_request_s *requests, int *query_result); - -/** - * @brief Set priority of handle - * @param[in] handle handle to change priority - * @param[in] priority new priority of handle - * @return int failure reason - * @pre None - * @post None - * @exception None - */ -int rm_set_priority(int handle, int priority); - -/** - * @brief Set application id of handle - * @param[in] handle handle to change application id - * @param[in] app_id new application id of handle - * @return int failure reason - * @pre None - * @post None - * @exception None - */ -int rm_set_app_id(int handle, char *app_id); - - -#ifdef __cplusplus -} -#endif -#endif // __RM_API_H__ \ No newline at end of file +/* + * 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 __RM_API_H__ +#define __RM_API_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Register a player + * @param[in] cb callback to receive resource conflict event + * @param[in] data user data passed to cb + * @param[out] handle handle got from resource manager + * @param[in] consumer_info player information such as player type, priority, window id and so on + * @return int failure reason + * @pre None + * @post None + * @exception None + */ +int rm_register(rm_resource_cb cb, void *data, int *handle, rm_consumer_info *consumer_info); + +/** + * @brief Unregister a player + * @param[in] handle handle to unregister + * @return int failure reason + * @pre None + * @post handle is deactivated.\n + * All resources which have been allocated to handle are released + * @exception None + */ +int rm_unregister(int handle); + +/** + * @brief request to allocate resources + * @param[in] handle handle to which resources are to be allocated + * @param[in] requests Resource information to allocate + * can request N resources simultaneously + * Ex. {Resource A, Resource A, Resouce B, Resouce N} + * @param[out] return_devices allocated Device ID. Caller needs to release memory allocated by Resource Manager + * !!IMPORTANT!!! + * The member of structure(device_node, omx_comp_name) must be freed by API caller side. + * @return int failure reason + * @pre None + * @post None + * @exception None + */ +int rm_allocate_resources(int handle, const rm_category_request_s *requests, rm_device_return_s *return_devices); + +/** + * @brief request to release resources + * @param[in] handle handle to which resources have been allocated + * @param[in] requests device information to release + * @return int failure reason + * @pre None + * @post None + * @exception None + */ +int rm_deallocate_resources(int handle, rm_device_request_s *requests); + +/** + * @brief Query resource state + * @param[in] handle handle gotten from rm_register() + * @param[in] query_type query type such as allocation + * @param[in] requests Resource information to query + * @param[out] query_result 0: not available + * 1: available + * @return int failure reason + * @pre None + * @post None + * @exception None + */ +int rm_query(int handle, rm_query_type_e query_type, rm_category_request_s *requests, int *query_result); + +/** + * @brief Set priority of handle + * @param[in] handle handle to change priority + * @param[in] priority new priority of handle + * @return int failure reason + * @pre None + * @post None + * @exception None + */ +int rm_set_priority(int handle, int priority); + +/** + * @brief Set application id of handle + * @param[in] handle handle to change application id + * @param[in] app_id new application id of handle + * @return int failure reason + * @pre None + * @post None + * @exception None + */ +int rm_set_app_id(int handle, char *app_id); + + +#ifdef __cplusplus +} +#endif +#endif // __RM_API_H__ diff --git a/include/rm_module_api.h b/include/rm_module_api.h index 05ab413..f2fdbcd 100644 --- a/include/rm_module_api.h +++ b/include/rm_module_api.h @@ -1,653 +1,653 @@ -/* - * 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 __RM_MODULE_API_H__ -#define __RM_MODULE_API_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief The resource category option to select a resource - * @remark This is supposed to be used by the resource center only - * @version 3.0 - */ -typedef enum { - RM_FORCE_TO_MAIN = (0x1 << 27), - RM_FORCE_TO_SUB = (0x1 << 26) -} rm_device_request_e; - -/** - * @brief The resource collection - * @remark This is supposed to be used by the resource center only - * @version 4.0 - */ -typedef enum { - RM_RSC_COLLECTION_MAIN = 0, /**< main resources */ - RM_RSC_COLLECTION_ACTIVE_VIDEO_DECODER, /**< active video decoders */ - RM_RSC_COLLECTION_AUDIO /**< audio resources (audio decoder, audio out) */ -} rm_rsc_collection_e; - -/** - * @brief The audio out type - * @remark This is supposed to be used by the resource center only - * @version 3.0 - */ -typedef enum { - RM_AUDIO_OUT_NONE = 0, - RM_AUDIO_OUT_MAIN = 0x1, - RM_AUDIO_OUT_SUB = 0x2, -} rm_audio_out_e; - -/** - * @brief The video sampling format - * @remark This is used as a return value of rm_resource_get_max_sampling_format() - * @version 3.0 - */ -typedef enum { - RM_SAMPLING_FORMAT_ARGB = 0, /**< ARGB */ - RM_SAMPLING_FORMAT_420, /**< YUV420 */ - RM_SAMPLING_FORMAT_422, /**< YUV422 */ - RM_SAMPLING_FORMAT_444 /**< YUV444 */ -} rm_sampling_format_e; - -/** - * @brief The video resolution - * @remark This is used as a return value of rm_resource_get_max_resolution() - * @version 3.0 - */ -typedef enum { - RM_RESOLUTION_HD = 0, /**< HD */ - RM_RESOLUTION_FHD, /**< FHD */ - RM_RESOLUTION_4K, /**< 4K */ - RM_RESOLUTION_8K /**< 8K */ -} rm_resolution_e; - -/** - * @brief Get current resource state - * @param[in] rsc_id resource id - * @param[out] state current resource state - * @return RM_OK on success, otherwise RM_ERROR - * @pre None - * @post None - * @version 3.0 - * @exception None - */ -int rm_get_resource_state(int rsc_id, rm_resource_state_e *state); - -/** - * @brief Get the resource list handle of video scaler - * @param[out] list resource list handle - * @return RM_OK on success, otherwise RM_ERROR - * @pre None - * @post None - * @version 3.0 - * @exception None - * @remark - * \li This API is supposed to be used by the resource center for internal use - * \li Please do not use for other purpose - * \li The returned list must be freed by rm_free_resource_list() after use - */ -int rm_get_scaler_state(rm_resource_list_h *list); - -/** - * @brief Called when scaler state is changed - * @param[out] scalers Scaler list - * @param[out] data The user data passed from the callback registration function - * @pre None - * @post None - * @version 3.0 - */ -typedef void (*scaler_state_change_cb)(rm_resource_list_h scalers, void *data); - -/** - * @brief Register a callback to observe scaler state change - * @details Once there is any state change of scaler, the registered callback will be invoked. - * @param[in] cb The callback function to register - * @param[in] data The user data to be passed to the callback function - * @return @c RM_OK on success, - * otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li This API is supposed to be used by the resource center for internal use - * \li Please do not use for other purpose - */ -int rm_subscribe_scaler_state_change(scaler_state_change_cb cb, void *data); - -/** - * @brief Unregister a callback which had been added to observe scaler state change - * @param[in] cb The callback function to unregister - * @return @c RM_OK on success, - * otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li This API is supposed to be used by the resource center for internal use - * \li Please do not use for other purpose - */ -int rm_unsubscribe_scaler_state_change(scaler_state_change_cb cb); - -/** - * @brief Get virtual id of scaler - * @param[in] scaler scaler handle - * @return virtual id of scaler - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li This API is supposed to be used by the resource center for internal use - * \li Please do not use for other purpose - */ -int rm_scaler_get_virtual_id(rm_resource_h scaler); - -/** - * @brief Get source id of scaler - * @param[in] scaler scaler handle - * @return source id of scaler - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li This API is supposed to be used by the resource center for internal use - * \li Please do not use for other purpose - */ -int rm_scaler_get_source_id(rm_resource_h scaler); - -/** - * @brief Called when a resource state is changed - * @param[out] state The resource state handle - * @param[out] data The user data passed from the callback registration function - * @pre None - * @post None - * @version 3.0 - * @remarks The data of the resource state handle can be accessed by the following APIs. - * rm_rsc_state_get_category() - * rm_rsc_state_get_id() - * rm_rsc_state_get_state() - * The passed resource state handle is valid in resource_state_change_cb() only. - * In other words, the passed resource state handle is freed once resource_state_change_cb() returns. - * Thus, need a deep copy in case information of the resource state handle is required outside of resource_state_change_cb(). - */ -typedef void (*resource_state_change_cb)(rm_resource_state_h state, void *data); - -/** - * @brief Register a callback to observe resource state change - * @details Once there is state change of a resource included in passed category, the registered callback will be invoked. - * @param[in] category category id to observe - * @param[in] cb The callback function to register - * @param[in] data The user data to be passed to the callback function - * @return @c RM_OK on success, - * otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_subscribe_resource_state_change(rm_rsc_category_e category, resource_state_change_cb cb, void *data); - -/** - * @brief Unregister a callback which had been added to observe resource state change - * @param[in] category category id to stop to observe - * @param[in] cb The callback function to unregister - * @return @c RM_OK on success, - * otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_unsubscribe_resource_state_change(rm_rsc_category_e category, resource_state_change_cb cb); - -/** - * @brief Get category id of the state changed resource - * @param[in] state The state changed resource handle - * @return category id of the state changed resource handle on success, - * otherwise negative value - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_rsc_state_get_category(rm_resource_state_h state); - -/** - * @brief Get device id of the state changed resource - * @param[in] state The state changed resource handle - * @return device id of the state changed resource handle on success, - * otherwise negative value - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_rsc_state_get_device_id(rm_resource_state_h state); - -/** - * @brief Get state of the state changed resource - * @param[in] state The state changed resource handle - * @return state of the state changed resource handle on success, - * otherwise negative value - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_rsc_state_get_state(rm_resource_state_h state); - -/** - * @brief Get consumer id of the state changed resource - * @param[in] state The state changed resource handle - * @return consumer id of the state changed resource handle on success, - * otherwise negative value - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_rsc_state_get_consumer_id(rm_resource_state_h state); - -/** - * @brief Get app id of the state changed resource - * @param[in] state The state changed resource handle - * @return app id of the state changed resource handle on success, - * otherwise NULL - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -char *rm_rsc_state_get_app_id(rm_resource_state_h state); - -struct rm_conflict_resource; -/** - * @brief The conflicted resource handle - */ -typedef struct rm_conflict_resource *rm_conflict_resource_h; - -/** - * @brief Called when a resource conflict occurs - * @param[out] resource The conflicted resource handle - * @param[out] data The user data passed from the callback registration function - * @pre None - * @post None - * @version 3.0 - * @remarks The data of the conflicted resource handle can be accessed by the following APIs. - * rm_conflict_get_category_id() - * rm_conflict_get_device_id() - * rm_conflict_get_consumer_id() - * rm_conflict_get_app_id() - * The passed conflicted resource handle is valid in rm_conflict_event_cb() only. - * In other words, the passed conflicted resource handle is freed once rm_conflict_event_cb() returns. - * Thus, need a deep copy in case information of the conflicted resource handle is required outside of rm_conflict_event_cb(). - */ -typedef void (*rm_conflict_event_cb)(rm_conflict_resource_h resource, void *data); - -/** - * @brief Register a callback to observe resource conflict event. - * @details Once there is a resource conflict, the registered callback will be invoked. - * @param[in] cb The callback function to add - * @param[in] data The user data to be passed to the callback function - * @return @c RM_OK on success, - * otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_subscribe_resource_conflict_event(rm_conflict_event_cb cb, void *data); - -/** - * @brief Unregister a callback which had been added to observe resource conflict event. - * @param[in] cb The callback function to remove - * @return @c RM_OK on success, - * otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_unsubscribe_resource_conflict_event(rm_conflict_event_cb cb); - -/** - * @brief Gets resource category id of the conflicted resource - * @param[in] rsc The conflicted resource handle - * @return resource category id of the conflicted resource handle on success, - * otherwise negative value - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_conflict_get_category_id(rm_conflict_resource_h rsc); - -/** - * @brief Gets device id of the conflicted resource - * @param[in] rsc The conflicted resource handle - * @return device id of the conflicted resource handle on success, - * otherwise negative value - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_conflict_get_device_id(rm_conflict_resource_h rsc); - -/** - * @brief Gets consumer id of the conflicted resource - * @param[in] rsc The conflicted resource handle - * @return consumer id of the conflicted resource handle on success, - * otherwise negative value - * @pre None - * @post None - * @remarks The consumer id is an unique id which is assigned to a player as a result of rm_register(). - * @exception None - * @version 3.0 - */ -int rm_conflict_get_consumer_id(rm_conflict_resource_h rsc); - -/** - * @brief Gets application id of the conflicted resource - * @param[in] rsc The conflicted resource handle - * @return application id of the conflicted resource on success - * otherwise NULL - * @pre None - * @post None - * @remarks In case any application id is not set by a player, NULL can be returned on success. - * @exception None - * @version 3.0 - */ -const char *rm_conflict_get_app_id(rm_conflict_resource_h rsc); - -/** - * @brief Gets multiview zone id of the consumer that needs to release the conflicted resource - * @param[in] rsc The conflicted resource handle - * @return multiview zone id in case the conflicted resource is allocated to a multiview zone - * otherwise negative value - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_conflict_get_multiview_zone_id_consumer(rm_conflict_resource_h rsc); - -/** - * @brief Gets multiview zone id of the requester that caused this resource conflict - * @param[in] rsc The conflicted resource handle - * @return multiview zone id in case the requester is placed to a multiview zone - * otherwise negative value - * @pre None - * @post None - * @exception None - * @version 3.0 - */ -int rm_conflict_get_multiview_zone_id_requester(rm_conflict_resource_h rsc); - -/** - * @brief Unmask category option bits - * @param[in] category resource category to unmask - * @return unmasked category id - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - */ -int rm_unmask_category_options(int category); - -/** - * @brief Find real device id which is mapped to virtual device id - * @param[in] virtual_id virtual device id - * @return positive real resource id on success, negative value on failure - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li This API is available for the scaler device supporting virtual device. - */ -int rm_find_device_id(int virtual_id); - -/** - * @brief Swap two resources - * @param[in] device_id_a device id to swap - * @param[in] device_id_b device id to swap - * @return RM_OK on success, otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li This API is available for the scaler device supporting virtual device. - * \li This API is supposed to be called by the resource center only - */ -int rm_swap_resources(int device_id_a, int device_id_b); - -/** - * @brief Swap two resources asynchronously - * @param[in] device_id_a device id to swap - * @param[in] device_id_b device id to swap - * @return RM_OK on success, otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.1 - * @remark - * \li This API is available for the scaler device supporting virtual device. - * \li This API is supposed to be called by the resource center only - */ -int rm_swap_resources_async(int device_id_a, int device_id_b); - -/** - * @brief Restore resources that have been swapped by rm_swap_resources() - * @param[in] category resource category to restore - * @return RM_OK on success, otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li This API is supposed to be called by the resource center only - */ -int rm_restore_resources(int category); - -/** - * @brief Get the resource list handle of resource collection - * @param[in] collection resource collection - * @param[out] list resource list handle - * @return RM_OK on success, otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li The returned list must be freed by rm_free_resource_list() after use - */ -int rm_get_resource_collection_state(rm_rsc_collection_e collection, rm_resource_list_h *list); - -/** - * @brief Get application id of handle - * @param[in] handle player handle returned by rm_register() - * @param[out] app_id application id of handle - * @return RM_OK on success, otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li This API is supposed to be called by the resource center only - * \li Do not use other purpose - */ -int rm_get_app_id(int handle, char**app_id); - -/** - * @brief Get active audio out resources being used by handle - * @param[in] handle player handle returned by rm_register() - * @return positive value masked with rm_audio_out_e on success, otherwise negative value - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li This API is supposed to be called by the resource center only - * \li Do not use other purpose - */ -int rm_get_active_audio_out(int handle); - -/** - * @brief Get hw id of scaler assigned to passed multiview zone id - * @param[in] zone_id multiview zone id - * @param[out] id The hw id of scaler assigned to passed multiview zone id, - * @return positive value on success, otherwise negative value - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li This API is supposed to be called by the resource center only - * \li Do not use other purpose - */ -int rm_get_scaler_hw_id(int zone_id, int *id); - -/** - * @brief Notify current resource policy - * @param[in] policy resource policy - * @return positive value on success, otherwise negative value - * @pre None - * @post None - * @exception None - * @version 3.1 - * @remark - * \li This API is supposed to be called by the resource center only - * \li Do not use other purpose - */ -int rm_notify_resource_policy(int policy); - -/** - * @brief Notify application's zone info in multiview - * @param[in] app_id application id - * @param[in] zone_id zone id - * @return positive value on success, otherwise negative value - * @pre None - * @post None - * @exception None - * @version 5.0 - * @remark - * \li This API is supposed to be called by the resource center only - * \li Do not use other purpose - */ -int rm_notify_app_zone_info_async(const char *app_id, int zone_id); - -/** - * @brief Reclaim all resources allocated to the handle - * @param[in] handle player handle returned by rm_register() - * @return positive value on success, otherwise negative value - * @pre None - * @post None - * @exception None - * @version 4.0 - * @remark - * \li This API is supposed to be called by the resource center only - * \li Do not use other purpose - */ -int rm_reclaim_resources(int handle); - -/** - * @brief Reclaim all resources allocated to the application - * @param[in] app_id application id - * @param[in] notify true : notify resource conflict, false : skip to notify - * @return positive value on success, otherwise negative value - * @pre None - * @post None - * @exception None - * @version 5.0 - * @remark - * \li This API is supposed to be called by the resource center only - * \li Do not use other purpose - */ -int rm_reclaim_app_resources(const char *app_id, const bool notify); - - -/** - * @brief Reclaim all resources allocated to the application asynchronously - * @param[in] app_id application id - * @param[in] notify true : notify resource conflict, false : skip to notify - * @return positive value on success, otherwise negative value - * @pre None - * @post None - * @exception None - * @version 5.0 - * @remark - * \li This API is supposed to be called by the resource center only - * \li Do not use other purpose - */ -int rm_reclaim_app_resources_async(const char *app_id, const bool notify); - -/** - * @brief Reclaim all video decoders allocated to applications other than requester - * @param[in] requester application id of the requester - * @return RM_OK on success, otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 5.0 - * @remark - * \li This API is supposed to be called by the camera framework only - * \li Do not use for other purpose - */ -int rm_reclaim_video_decoders(const char *requester); - -/** - * @brief Check if the handle is valid or not - * @param[in] handle player handle returned by rm_register() - * @return true : player handle is valid, false : player handle is invalid - * @pre None - * @post None - * @exception None - * @version 6.0 - * @remark - * \li This API is supposed to be called by the resource center only - * \li Do not use for other purpose - */ -bool rm_active_player(const int handle); - -/** - * @brief Check if the player is in progress of reclaiming resource - * @param[in] handle player handle returned by rm_register() - * @return true : reclaim is in progress against the player, false : reclaim is not in progress against the player - * @pre None - * @post None - * @exception None - * @remark - * \li This API is supposed to be called by the resource center only - * \li Do not use for other purpose - */ -bool rm_reclaimed_player(const int handle); - -#ifdef __cplusplus -} -#endif -#endif //__RM_MODULE_API_H__ +/* + * 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 __RM_MODULE_API_H__ +#define __RM_MODULE_API_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief The resource category option to select a resource + * @remark This is supposed to be used by the resource center only + * @version 3.0 + */ +typedef enum { + RM_FORCE_TO_MAIN = (0x1 << 27), + RM_FORCE_TO_SUB = (0x1 << 26) +} rm_device_request_e; + +/** + * @brief The resource collection + * @remark This is supposed to be used by the resource center only + * @version 4.0 + */ +typedef enum { + RM_RSC_COLLECTION_MAIN = 0, /**< main resources */ + RM_RSC_COLLECTION_ACTIVE_VIDEO_DECODER, /**< active video decoders */ + RM_RSC_COLLECTION_AUDIO /**< audio resources (audio decoder, audio out) */ +} rm_rsc_collection_e; + +/** + * @brief The audio out type + * @remark This is supposed to be used by the resource center only + * @version 3.0 + */ +typedef enum { + RM_AUDIO_OUT_NONE = 0, + RM_AUDIO_OUT_MAIN = 0x1, + RM_AUDIO_OUT_SUB = 0x2, +} rm_audio_out_e; + +/** + * @brief The video sampling format + * @remark This is used as a return value of rm_resource_get_max_sampling_format() + * @version 3.0 + */ +typedef enum { + RM_SAMPLING_FORMAT_ARGB = 0, /**< ARGB */ + RM_SAMPLING_FORMAT_420, /**< YUV420 */ + RM_SAMPLING_FORMAT_422, /**< YUV422 */ + RM_SAMPLING_FORMAT_444 /**< YUV444 */ +} rm_sampling_format_e; + +/** + * @brief The video resolution + * @remark This is used as a return value of rm_resource_get_max_resolution() + * @version 3.0 + */ +typedef enum { + RM_RESOLUTION_HD = 0, /**< HD */ + RM_RESOLUTION_FHD, /**< FHD */ + RM_RESOLUTION_4K, /**< 4K */ + RM_RESOLUTION_8K /**< 8K */ +} rm_resolution_e; + +/** + * @brief Get current resource state + * @param[in] rsc_id resource id + * @param[out] state current resource state + * @return RM_OK on success, otherwise RM_ERROR + * @pre None + * @post None + * @version 3.0 + * @exception None + */ +int rm_get_resource_state(int rsc_id, rm_resource_state_e *state); + +/** + * @brief Get the resource list handle of video scaler + * @param[out] list resource list handle + * @return RM_OK on success, otherwise RM_ERROR + * @pre None + * @post None + * @version 3.0 + * @exception None + * @remark + * \li This API is supposed to be used by the resource center for internal use + * \li Please do not use for other purpose + * \li The returned list must be freed by rm_free_resource_list() after use + */ +int rm_get_scaler_state(rm_resource_list_h *list); + +/** + * @brief Called when scaler state is changed + * @param[out] scalers Scaler list + * @param[out] data The user data passed from the callback registration function + * @pre None + * @post None + * @version 3.0 + */ +typedef void (*scaler_state_change_cb)(rm_resource_list_h scalers, void *data); + +/** + * @brief Register a callback to observe scaler state change + * @details Once there is any state change of scaler, the registered callback will be invoked. + * @param[in] cb The callback function to register + * @param[in] data The user data to be passed to the callback function + * @return @c RM_OK on success, + * otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li This API is supposed to be used by the resource center for internal use + * \li Please do not use for other purpose + */ +int rm_subscribe_scaler_state_change(scaler_state_change_cb cb, void *data); + +/** + * @brief Unregister a callback which had been added to observe scaler state change + * @param[in] cb The callback function to unregister + * @return @c RM_OK on success, + * otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li This API is supposed to be used by the resource center for internal use + * \li Please do not use for other purpose + */ +int rm_unsubscribe_scaler_state_change(scaler_state_change_cb cb); + +/** + * @brief Get virtual id of scaler + * @param[in] scaler scaler handle + * @return virtual id of scaler + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li This API is supposed to be used by the resource center for internal use + * \li Please do not use for other purpose + */ +int rm_scaler_get_virtual_id(rm_resource_h scaler); + +/** + * @brief Get source id of scaler + * @param[in] scaler scaler handle + * @return source id of scaler + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li This API is supposed to be used by the resource center for internal use + * \li Please do not use for other purpose + */ +int rm_scaler_get_source_id(rm_resource_h scaler); + +/** + * @brief Called when a resource state is changed + * @param[out] state The resource state handle + * @param[out] data The user data passed from the callback registration function + * @pre None + * @post None + * @version 3.0 + * @remarks The data of the resource state handle can be accessed by the following APIs. + * rm_rsc_state_get_category() + * rm_rsc_state_get_id() + * rm_rsc_state_get_state() + * The passed resource state handle is valid in resource_state_change_cb() only. + * In other words, the passed resource state handle is freed once resource_state_change_cb() returns. + * Thus, need a deep copy in case information of the resource state handle is required outside of resource_state_change_cb(). + */ +typedef void (*resource_state_change_cb)(rm_resource_state_h state, void *data); + +/** + * @brief Register a callback to observe resource state change + * @details Once there is state change of a resource included in passed category, the registered callback will be invoked. + * @param[in] category category id to observe + * @param[in] cb The callback function to register + * @param[in] data The user data to be passed to the callback function + * @return @c RM_OK on success, + * otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_subscribe_resource_state_change(rm_rsc_category_e category, resource_state_change_cb cb, void *data); + +/** + * @brief Unregister a callback which had been added to observe resource state change + * @param[in] category category id to stop to observe + * @param[in] cb The callback function to unregister + * @return @c RM_OK on success, + * otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_unsubscribe_resource_state_change(rm_rsc_category_e category, resource_state_change_cb cb); + +/** + * @brief Get category id of the state changed resource + * @param[in] state The state changed resource handle + * @return category id of the state changed resource handle on success, + * otherwise negative value + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_rsc_state_get_category(rm_resource_state_h state); + +/** + * @brief Get device id of the state changed resource + * @param[in] state The state changed resource handle + * @return device id of the state changed resource handle on success, + * otherwise negative value + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_rsc_state_get_device_id(rm_resource_state_h state); + +/** + * @brief Get state of the state changed resource + * @param[in] state The state changed resource handle + * @return state of the state changed resource handle on success, + * otherwise negative value + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_rsc_state_get_state(rm_resource_state_h state); + +/** + * @brief Get consumer id of the state changed resource + * @param[in] state The state changed resource handle + * @return consumer id of the state changed resource handle on success, + * otherwise negative value + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_rsc_state_get_consumer_id(rm_resource_state_h state); + +/** + * @brief Get app id of the state changed resource + * @param[in] state The state changed resource handle + * @return app id of the state changed resource handle on success, + * otherwise NULL + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +char *rm_rsc_state_get_app_id(rm_resource_state_h state); + +struct rm_conflict_resource; +/** + * @brief The conflicted resource handle + */ +typedef struct rm_conflict_resource *rm_conflict_resource_h; + +/** + * @brief Called when a resource conflict occurs + * @param[out] resource The conflicted resource handle + * @param[out] data The user data passed from the callback registration function + * @pre None + * @post None + * @version 3.0 + * @remarks The data of the conflicted resource handle can be accessed by the following APIs. + * rm_conflict_get_category_id() + * rm_conflict_get_device_id() + * rm_conflict_get_consumer_id() + * rm_conflict_get_app_id() + * The passed conflicted resource handle is valid in rm_conflict_event_cb() only. + * In other words, the passed conflicted resource handle is freed once rm_conflict_event_cb() returns. + * Thus, need a deep copy in case information of the conflicted resource handle is required outside of rm_conflict_event_cb(). + */ +typedef void (*rm_conflict_event_cb)(rm_conflict_resource_h resource, void *data); + +/** + * @brief Register a callback to observe resource conflict event. + * @details Once there is a resource conflict, the registered callback will be invoked. + * @param[in] cb The callback function to add + * @param[in] data The user data to be passed to the callback function + * @return @c RM_OK on success, + * otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_subscribe_resource_conflict_event(rm_conflict_event_cb cb, void *data); + +/** + * @brief Unregister a callback which had been added to observe resource conflict event. + * @param[in] cb The callback function to remove + * @return @c RM_OK on success, + * otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_unsubscribe_resource_conflict_event(rm_conflict_event_cb cb); + +/** + * @brief Gets resource category id of the conflicted resource + * @param[in] rsc The conflicted resource handle + * @return resource category id of the conflicted resource handle on success, + * otherwise negative value + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_conflict_get_category_id(rm_conflict_resource_h rsc); + +/** + * @brief Gets device id of the conflicted resource + * @param[in] rsc The conflicted resource handle + * @return device id of the conflicted resource handle on success, + * otherwise negative value + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_conflict_get_device_id(rm_conflict_resource_h rsc); + +/** + * @brief Gets consumer id of the conflicted resource + * @param[in] rsc The conflicted resource handle + * @return consumer id of the conflicted resource handle on success, + * otherwise negative value + * @pre None + * @post None + * @remarks The consumer id is an unique id which is assigned to a player as a result of rm_register(). + * @exception None + * @version 3.0 + */ +int rm_conflict_get_consumer_id(rm_conflict_resource_h rsc); + +/** + * @brief Gets application id of the conflicted resource + * @param[in] rsc The conflicted resource handle + * @return application id of the conflicted resource on success + * otherwise NULL + * @pre None + * @post None + * @remarks In case any application id is not set by a player, NULL can be returned on success. + * @exception None + * @version 3.0 + */ +const char *rm_conflict_get_app_id(rm_conflict_resource_h rsc); + +/** + * @brief Gets multiview zone id of the consumer that needs to release the conflicted resource + * @param[in] rsc The conflicted resource handle + * @return multiview zone id in case the conflicted resource is allocated to a multiview zone + * otherwise negative value + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_conflict_get_multiview_zone_id_consumer(rm_conflict_resource_h rsc); + +/** + * @brief Gets multiview zone id of the requester that caused this resource conflict + * @param[in] rsc The conflicted resource handle + * @return multiview zone id in case the requester is placed to a multiview zone + * otherwise negative value + * @pre None + * @post None + * @exception None + * @version 3.0 + */ +int rm_conflict_get_multiview_zone_id_requester(rm_conflict_resource_h rsc); + +/** + * @brief Unmask category option bits + * @param[in] category resource category to unmask + * @return unmasked category id + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + */ +int rm_unmask_category_options(int category); + +/** + * @brief Find real device id which is mapped to virtual device id + * @param[in] virtual_id virtual device id + * @return positive real resource id on success, negative value on failure + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li This API is available for the scaler device supporting virtual device. + */ +int rm_find_device_id(int virtual_id); + +/** + * @brief Swap two resources + * @param[in] device_id_a device id to swap + * @param[in] device_id_b device id to swap + * @return RM_OK on success, otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li This API is available for the scaler device supporting virtual device. + * \li This API is supposed to be called by the resource center only + */ +int rm_swap_resources(int device_id_a, int device_id_b); + +/** + * @brief Swap two resources asynchronously + * @param[in] device_id_a device id to swap + * @param[in] device_id_b device id to swap + * @return RM_OK on success, otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.1 + * @remark + * \li This API is available for the scaler device supporting virtual device. + * \li This API is supposed to be called by the resource center only + */ +int rm_swap_resources_async(int device_id_a, int device_id_b); + +/** + * @brief Restore resources that have been swapped by rm_swap_resources() + * @param[in] category resource category to restore + * @return RM_OK on success, otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li This API is supposed to be called by the resource center only + */ +int rm_restore_resources(int category); + +/** + * @brief Get the resource list handle of resource collection + * @param[in] collection resource collection + * @param[out] list resource list handle + * @return RM_OK on success, otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li The returned list must be freed by rm_free_resource_list() after use + */ +int rm_get_resource_collection_state(rm_rsc_collection_e collection, rm_resource_list_h *list); + +/** + * @brief Get application id of handle + * @param[in] handle player handle returned by rm_register() + * @param[out] app_id application id of handle + * @return RM_OK on success, otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li This API is supposed to be called by the resource center only + * \li Do not use other purpose + */ +int rm_get_app_id(int handle, char**app_id); + +/** + * @brief Get active audio out resources being used by handle + * @param[in] handle player handle returned by rm_register() + * @return positive value masked with rm_audio_out_e on success, otherwise negative value + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li This API is supposed to be called by the resource center only + * \li Do not use other purpose + */ +int rm_get_active_audio_out(int handle); + +/** + * @brief Get hw id of scaler assigned to passed multiview zone id + * @param[in] zone_id multiview zone id + * @param[out] id The hw id of scaler assigned to passed multiview zone id, + * @return positive value on success, otherwise negative value + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li This API is supposed to be called by the resource center only + * \li Do not use other purpose + */ +int rm_get_scaler_hw_id(int zone_id, int *id); + +/** + * @brief Notify current resource policy + * @param[in] policy resource policy + * @return positive value on success, otherwise negative value + * @pre None + * @post None + * @exception None + * @version 3.1 + * @remark + * \li This API is supposed to be called by the resource center only + * \li Do not use other purpose + */ +int rm_notify_resource_policy(int policy); + +/** + * @brief Notify application's zone info in multiview + * @param[in] app_id application id + * @param[in] zone_id zone id + * @return positive value on success, otherwise negative value + * @pre None + * @post None + * @exception None + * @version 5.0 + * @remark + * \li This API is supposed to be called by the resource center only + * \li Do not use other purpose + */ +int rm_notify_app_zone_info_async(const char *app_id, int zone_id); + +/** + * @brief Reclaim all resources allocated to the handle + * @param[in] handle player handle returned by rm_register() + * @return positive value on success, otherwise negative value + * @pre None + * @post None + * @exception None + * @version 4.0 + * @remark + * \li This API is supposed to be called by the resource center only + * \li Do not use other purpose + */ +int rm_reclaim_resources(int handle); + +/** + * @brief Reclaim all resources allocated to the application + * @param[in] app_id application id + * @param[in] notify true : notify resource conflict, false : skip to notify + * @return positive value on success, otherwise negative value + * @pre None + * @post None + * @exception None + * @version 5.0 + * @remark + * \li This API is supposed to be called by the resource center only + * \li Do not use other purpose + */ +int rm_reclaim_app_resources(const char *app_id, const bool notify); + + +/** + * @brief Reclaim all resources allocated to the application asynchronously + * @param[in] app_id application id + * @param[in] notify true : notify resource conflict, false : skip to notify + * @return positive value on success, otherwise negative value + * @pre None + * @post None + * @exception None + * @version 5.0 + * @remark + * \li This API is supposed to be called by the resource center only + * \li Do not use other purpose + */ +int rm_reclaim_app_resources_async(const char *app_id, const bool notify); + +/** + * @brief Reclaim all video decoders allocated to applications other than requester + * @param[in] requester application id of the requester + * @return RM_OK on success, otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 5.0 + * @remark + * \li This API is supposed to be called by the camera framework only + * \li Do not use for other purpose + */ +int rm_reclaim_video_decoders(const char *requester); + +/** + * @brief Check if the handle is valid or not + * @param[in] handle player handle returned by rm_register() + * @return true : player handle is valid, false : player handle is invalid + * @pre None + * @post None + * @exception None + * @version 6.0 + * @remark + * \li This API is supposed to be called by the resource center only + * \li Do not use for other purpose + */ +bool rm_active_player(const int handle); + +/** + * @brief Check if the player is in progress of reclaiming resource + * @param[in] handle player handle returned by rm_register() + * @return true : reclaim is in progress against the player, false : reclaim is not in progress against the player + * @pre None + * @post None + * @exception None + * @remark + * \li This API is supposed to be called by the resource center only + * \li Do not use for other purpose + */ +bool rm_reclaimed_player(const int handle); + +#ifdef __cplusplus +} +#endif +#endif //__RM_MODULE_API_H__ diff --git a/include/rm_resource.h b/include/rm_resource.h index 2e9adad..4a4e60c 100644 --- a/include/rm_resource.h +++ b/include/rm_resource.h @@ -1,326 +1,326 @@ -/* - * 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 __RM_RESOURCE_H__ -#define __RM_RESOURCE_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Create a resource list handle - * @param None - * @return resource list handle on success, otherwise NULL - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li The returned list must be freed by rm_free_resource_list() after use - */ -rm_resource_list_h rm_resource_list_create(void); - -/** - * @brief Get the resource list handle of resource category - * @param[in] category resource category - * @param[out] list resource list handle - * @return RM_OK on success, otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li The returned list must be freed by rm_free_resource_list() after use - */ -int rm_get_resource_list(rm_rsc_category_e category, rm_resource_list_h *list); - -/** - * @brief Free resource list handle - * @param[in] list resource list handle - * @return None - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li The elements in the list will be freed as well - */ -void rm_free_resource_list(rm_resource_list_h list); - -/** - * @brief Append a resource to the resource list - * @param[in] list resource list handle - * @param[out] resource resource handle - * @return RM_OK on success, otherwise RM_ERROR - * @pre None - * @post None - * @exception None - */ -int rm_resource_list_append(rm_resource_list_h list, rm_resource_h resource); - -/** - * @brief Get next resource handle from resource list handle - * @param[in] list resource list handle - * @return next resource handle - * In case there is no next resource handle or error, returns NULL - * @pre None - * @post None - * @exception None - */ -rm_resource_h rm_resource_list_get_next(rm_resource_list_h list); - -/** - * @brief Get previous resource handle from resource list handle - * @param[in] list resource list handle - * @return previous resource handle - * In case there is no previous resource handle or error, returns NULL - * @pre None - * @post None - * @exception None - */ -rm_resource_h rm_resource_list_get_prev(rm_resource_list_h list); - -/** - * @brief Get first resource handle from resource list handle - * @param[in] list resource list handle - * @return first resource handle - * In case there is no previous resource handle or error, returns NULL - * @pre None - * @post None - * @exception None - */ -rm_resource_h rm_resource_list_get_first(rm_resource_list_h list); - -/** - * @brief Get last resource handle from resource list handle - * @param[in] list resource list handle - * @return last resource handle - * @pre In case there is no last resource handle or error, returns NULL - * @post None - * @exception None - */ -rm_resource_h rm_resource_list_get_last(rm_resource_list_h list); - -/** - * @brief Get number of resource handles in resource list handle - * @param[in] list resource list handle - * @return number of resource handles in resource list handle - * @pre None - * @post None - * @exception None - */ -int rm_resource_list_get_count(rm_resource_list_h list); - -/** - * @brief Get node of the resource - * @param[in] resource resource handle - * @return node of the resource - * @pre None - * @post None - * @exception None - */ -const char *rm_resource_get_node(rm_resource_h resource); - -/** - * @brief Get id of the resource - * @param[in] resource resource handle - * @return resource id - * @pre None - * @post None - * @exception None - */ -int rm_resource_get_id(rm_resource_h resource); - -/** - * @brief Get category id of the resource - * @param[in] resource resource handle - * @return resource id - * @pre None - * @post None - * @exception None - */ -int rm_resource_get_category(rm_resource_h resource); - -/** - * @brief Get category id of the resource - * @param[in] resource resource handle - * @return resource id - * @pre None - * @post None - * @exception None - */ -int rm_resource_get_cur_category(rm_resource_h resource); - -/** - * @brief Get consumer id using the resource - * @param[in] resource resource handle - * @return resource id - * @pre None - * @post None - * @exception None - */ -int rm_resource_get_consumer(rm_resource_h resource); - -/** - * @brief Get state of the resource - * @param[in] resource resource handle - * @return resource id - * @pre None - * @post None - * @exception None - */ -int rm_resource_get_state(rm_resource_h resource); - -/** - * @brief Get application id using the resource - * @param[in] resource resource handle - * @return resource id - * @pre None - * @post None - * @exception None - */ -const char *rm_resource_get_app_id(rm_resource_h resource); - -/** - * @brief Check whether the resource is being used by the android app - * @param[in] resource resource handle - * @return true : the resource is being used by the android app, false : not being used by the android app - * @pre None - * @post None - * @exception None - */ -bool rm_resource_android_app(const rm_resource_h resource); - -/** - * @brief Get framerate of the resource - * @param[in] resource resource handle - * @return framerate - * @pre None - * @post None - * @version 3.0 - * @exception None - */ -unsigned int rm_resource_get_framerate(rm_resource_h resource); - -/** - * @brief Get max resolution of the resource - * @param[in] resource resource handle - * @return max resolution. This is one of rm_resolution_e values. - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li The API is valid for the resource belongs to RM_CATEGORY_DISPLAY_OUT - */ -int rm_resource_get_max_resolution(rm_resource_h resource); - -/** - * @brief This function returns whether the resource supports overlay or not - * @param[in] resource resource handle - * @return true : overlay supported, false : overlay not supported - * @pre None - * @post None - * @exception None - * @version 3.0 - * @remark - * \li The API is valid for the resource belongs to RM_CATEGORY_DISPLAY_OUT - */ -bool rm_resource_support_overlay(rm_resource_h resource); - -/** - * @brief Get max sampling format of the resource - * @param[in] resource resource handle - * @return max color format. This is one of rm_sampling_format_e values. - * @pre None - * @post None - * @exception None - * @remark - * \li The API is valid for the resource belongs to RM_CATEGORY_DISPLAY_OUT - */ -int rm_resource_get_max_sampling_format(rm_resource_h resource); - -/** - * @brief Get multiview zone id of the resource - * @param[in] resource resource handle - * @return multiview zone id - * @pre None - * @post None - * @exception None - * @remark - * \li The API is valid for the resource belongs to RM_CATEGORY_SCALER - */ -int rm_resource_get_zone_id(rm_resource_h resource); - -/** - * @brief Get width of the resource - * @param[in] resource resource handle - * @return width of the content to be encoded - * @pre None - * @post None - * @exception None - * @remark - * \li The API is valid for the resource belongs to RM_CATEGORY_VIDEO_ENCODER - */ -unsigned int rm_resource_get_width(const rm_resource_h resource); - -/** - * @brief Get height of the resource - * @param[in] resource resource handle - * @return height of the content to be encoded - * @pre None - * @post None - * @exception None - * @remark - * \li The API is valid for the resource belongs to RM_CATEGORY_VIDEO_ENCODER - */ -unsigned int rm_resource_get_height(const rm_resource_h resource); - -/** - * @brief Create a video encoder handle - * @param[in] width width of the content to encode (in pixel) - * @param[in] height height of the content to encode (in pixel) - * @param[in] framerate frame rate of the content to encode (frame per second) - * @return resource handle on success, otherwise NULL - * @pre None - * @post None - * @exception None - * @remark - * \li If the returned resource handle is appended to the resource list then you can free this with rm_free_resource_list() - */ -rm_resource_h rm_create_video_encoder(const unsigned int width, const unsigned int height, const unsigned int framerate); - -/** - * @brief Checks whether the video encoders in the list are allocatable for multi encoding scenario - * @param[in] list the resource list including the video encoders - * @param[out] result true : allocatable, false : not allocatable - * @return RM_OK on success, otherwise RM_ERROR - * @pre None - * @post None - * @exception None - * @remark - * \li This function checks whether the video encoders are allocatable based on available bandwidth of the video encoder. - * \li In other words, the result can be different depending on current video encoder usage status. - */ -int rm_allocatable_video_encoders(const rm_resource_list_h list, bool *result); - -#ifdef __cplusplus -} -#endif -#endif //__RM_RESOURCE_H__ +/* + * 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 __RM_RESOURCE_H__ +#define __RM_RESOURCE_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a resource list handle + * @param None + * @return resource list handle on success, otherwise NULL + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li The returned list must be freed by rm_free_resource_list() after use + */ +rm_resource_list_h rm_resource_list_create(void); + +/** + * @brief Get the resource list handle of resource category + * @param[in] category resource category + * @param[out] list resource list handle + * @return RM_OK on success, otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li The returned list must be freed by rm_free_resource_list() after use + */ +int rm_get_resource_list(rm_rsc_category_e category, rm_resource_list_h *list); + +/** + * @brief Free resource list handle + * @param[in] list resource list handle + * @return None + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li The elements in the list will be freed as well + */ +void rm_free_resource_list(rm_resource_list_h list); + +/** + * @brief Append a resource to the resource list + * @param[in] list resource list handle + * @param[out] resource resource handle + * @return RM_OK on success, otherwise RM_ERROR + * @pre None + * @post None + * @exception None + */ +int rm_resource_list_append(rm_resource_list_h list, rm_resource_h resource); + +/** + * @brief Get next resource handle from resource list handle + * @param[in] list resource list handle + * @return next resource handle + * In case there is no next resource handle or error, returns NULL + * @pre None + * @post None + * @exception None + */ +rm_resource_h rm_resource_list_get_next(rm_resource_list_h list); + +/** + * @brief Get previous resource handle from resource list handle + * @param[in] list resource list handle + * @return previous resource handle + * In case there is no previous resource handle or error, returns NULL + * @pre None + * @post None + * @exception None + */ +rm_resource_h rm_resource_list_get_prev(rm_resource_list_h list); + +/** + * @brief Get first resource handle from resource list handle + * @param[in] list resource list handle + * @return first resource handle + * In case there is no previous resource handle or error, returns NULL + * @pre None + * @post None + * @exception None + */ +rm_resource_h rm_resource_list_get_first(rm_resource_list_h list); + +/** + * @brief Get last resource handle from resource list handle + * @param[in] list resource list handle + * @return last resource handle + * @pre In case there is no last resource handle or error, returns NULL + * @post None + * @exception None + */ +rm_resource_h rm_resource_list_get_last(rm_resource_list_h list); + +/** + * @brief Get number of resource handles in resource list handle + * @param[in] list resource list handle + * @return number of resource handles in resource list handle + * @pre None + * @post None + * @exception None + */ +int rm_resource_list_get_count(rm_resource_list_h list); + +/** + * @brief Get node of the resource + * @param[in] resource resource handle + * @return node of the resource + * @pre None + * @post None + * @exception None + */ +const char *rm_resource_get_node(rm_resource_h resource); + +/** + * @brief Get id of the resource + * @param[in] resource resource handle + * @return resource id + * @pre None + * @post None + * @exception None + */ +int rm_resource_get_id(rm_resource_h resource); + +/** + * @brief Get category id of the resource + * @param[in] resource resource handle + * @return resource id + * @pre None + * @post None + * @exception None + */ +int rm_resource_get_category(rm_resource_h resource); + +/** + * @brief Get category id of the resource + * @param[in] resource resource handle + * @return resource id + * @pre None + * @post None + * @exception None + */ +int rm_resource_get_cur_category(rm_resource_h resource); + +/** + * @brief Get consumer id using the resource + * @param[in] resource resource handle + * @return resource id + * @pre None + * @post None + * @exception None + */ +int rm_resource_get_consumer(rm_resource_h resource); + +/** + * @brief Get state of the resource + * @param[in] resource resource handle + * @return resource id + * @pre None + * @post None + * @exception None + */ +int rm_resource_get_state(rm_resource_h resource); + +/** + * @brief Get application id using the resource + * @param[in] resource resource handle + * @return resource id + * @pre None + * @post None + * @exception None + */ +const char *rm_resource_get_app_id(rm_resource_h resource); + +/** + * @brief Check whether the resource is being used by the android app + * @param[in] resource resource handle + * @return true : the resource is being used by the android app, false : not being used by the android app + * @pre None + * @post None + * @exception None + */ +bool rm_resource_android_app(const rm_resource_h resource); + +/** + * @brief Get framerate of the resource + * @param[in] resource resource handle + * @return framerate + * @pre None + * @post None + * @version 3.0 + * @exception None + */ +unsigned int rm_resource_get_framerate(rm_resource_h resource); + +/** + * @brief Get max resolution of the resource + * @param[in] resource resource handle + * @return max resolution. This is one of rm_resolution_e values. + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li The API is valid for the resource belongs to RM_CATEGORY_DISPLAY_OUT + */ +int rm_resource_get_max_resolution(rm_resource_h resource); + +/** + * @brief This function returns whether the resource supports overlay or not + * @param[in] resource resource handle + * @return true : overlay supported, false : overlay not supported + * @pre None + * @post None + * @exception None + * @version 3.0 + * @remark + * \li The API is valid for the resource belongs to RM_CATEGORY_DISPLAY_OUT + */ +bool rm_resource_support_overlay(rm_resource_h resource); + +/** + * @brief Get max sampling format of the resource + * @param[in] resource resource handle + * @return max color format. This is one of rm_sampling_format_e values. + * @pre None + * @post None + * @exception None + * @remark + * \li The API is valid for the resource belongs to RM_CATEGORY_DISPLAY_OUT + */ +int rm_resource_get_max_sampling_format(rm_resource_h resource); + +/** + * @brief Get multiview zone id of the resource + * @param[in] resource resource handle + * @return multiview zone id + * @pre None + * @post None + * @exception None + * @remark + * \li The API is valid for the resource belongs to RM_CATEGORY_SCALER + */ +int rm_resource_get_zone_id(rm_resource_h resource); + +/** + * @brief Get width of the resource + * @param[in] resource resource handle + * @return width of the content to be encoded + * @pre None + * @post None + * @exception None + * @remark + * \li The API is valid for the resource belongs to RM_CATEGORY_VIDEO_ENCODER + */ +unsigned int rm_resource_get_width(const rm_resource_h resource); + +/** + * @brief Get height of the resource + * @param[in] resource resource handle + * @return height of the content to be encoded + * @pre None + * @post None + * @exception None + * @remark + * \li The API is valid for the resource belongs to RM_CATEGORY_VIDEO_ENCODER + */ +unsigned int rm_resource_get_height(const rm_resource_h resource); + +/** + * @brief Create a video encoder handle + * @param[in] width width of the content to encode (in pixel) + * @param[in] height height of the content to encode (in pixel) + * @param[in] framerate frame rate of the content to encode (frame per second) + * @return resource handle on success, otherwise NULL + * @pre None + * @post None + * @exception None + * @remark + * \li If the returned resource handle is appended to the resource list then you can free this with rm_free_resource_list() + */ +rm_resource_h rm_create_video_encoder(const unsigned int width, const unsigned int height, const unsigned int framerate); + +/** + * @brief Checks whether the video encoders in the list are allocatable for multi encoding scenario + * @param[in] list the resource list including the video encoders + * @param[out] result true : allocatable, false : not allocatable + * @return RM_OK on success, otherwise RM_ERROR + * @pre None + * @post None + * @exception None + * @remark + * \li This function checks whether the video encoders are allocatable based on available bandwidth of the video encoder. + * \li In other words, the result can be different depending on current video encoder usage status. + */ +int rm_allocatable_video_encoders(const rm_resource_list_h list, bool *result); + +#ifdef __cplusplus +} +#endif +#endif //__RM_RESOURCE_H__ diff --git a/include_internal/rm_callback.h b/include_internal/rm_callback.h index 5914eeb..4400016 100644 --- a/include_internal/rm_callback.h +++ b/include_internal/rm_callback.h @@ -1,67 +1,67 @@ -/* - * 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 __RM_CALLBACK_H__ -#define __RM_CALLBACK_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - int msg_type; // callback message type - int cid; // consumer id - int pid; // process id - int conflicted_num; // conflicted resource num -} rm_cb_head_s; - -typedef struct { - rm_conflict_event_cb cb; - void *data; -} conflict_event_cb; - -typedef struct { - scaler_state_change_cb cb; - void *data; -} scaler_state_cb; - -GMainLoop *rm_get_main_loop(void); -GMainContext *rm_get_context(void); -void rm_set_context(GMainContext *context); -int rm_init_cb(int cid, rm_resource_cb cb, void *data); -int rm_send_cb_msg(rm_cb_head_s *cb_head, int result); -void rm_register_callback(int handle, rm_resource_cb cb, void *data, int fd, GSource *callback_handler, GIOChannel *gio); -void rm_unregister_callback(int handle); - -int rm_add_state_change_cb(int category, resource_state_change_cb cb, void *data); -int rm_remove_state_change_cb(int category, resource_state_change_cb cb); -void rm_call_state_changed_cb(int category, int device_id, int state, int consumer_id, char *app_id); - -int rm_add_conflict_event_cb(rm_conflict_event_cb cb, void *data); -int rm_remove_conflict_event_cb(rm_conflict_event_cb cb); -std::list& rm_get_conflict_event_cb_list(void); - -int rm_add_scaler_state_change_cb(scaler_state_change_cb cb, void *data); -int rm_remove_scaler_state_change_cb(scaler_state_change_cb cb); -void rm_call_scaler_state_changed_cb(rm_resource_list *scaler_list); - -#ifdef __cplusplus -} -#endif -#endif// __RM_CALLBACK_H__ +/* + * 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 __RM_CALLBACK_H__ +#define __RM_CALLBACK_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + int msg_type; // callback message type + int cid; // consumer id + int pid; // process id + int conflicted_num; // conflicted resource num +} rm_cb_head_s; + +typedef struct { + rm_conflict_event_cb cb; + void *data; +} conflict_event_cb; + +typedef struct { + scaler_state_change_cb cb; + void *data; +} scaler_state_cb; + +GMainLoop *rm_get_main_loop(void); +GMainContext *rm_get_context(void); +void rm_set_context(GMainContext *context); +int rm_init_cb(int cid, rm_resource_cb cb, void *data); +int rm_send_cb_msg(rm_cb_head_s *cb_head, int result); +void rm_register_callback(int handle, rm_resource_cb cb, void *data, int fd, GSource *callback_handler, GIOChannel *gio); +void rm_unregister_callback(int handle); + +int rm_add_state_change_cb(int category, resource_state_change_cb cb, void *data); +int rm_remove_state_change_cb(int category, resource_state_change_cb cb); +void rm_call_state_changed_cb(int category, int device_id, int state, int consumer_id, char *app_id); + +int rm_add_conflict_event_cb(rm_conflict_event_cb cb, void *data); +int rm_remove_conflict_event_cb(rm_conflict_event_cb cb); +std::list& rm_get_conflict_event_cb_list(void); + +int rm_add_scaler_state_change_cb(scaler_state_change_cb cb, void *data); +int rm_remove_scaler_state_change_cb(scaler_state_change_cb cb); +void rm_call_scaler_state_changed_cb(rm_resource_list *scaler_list); + +#ifdef __cplusplus +} +#endif +#endif// __RM_CALLBACK_H__ diff --git a/include_internal/rm_dbus.h b/include_internal/rm_dbus.h index 0cf8140..45904b9 100644 --- a/include_internal/rm_dbus.h +++ b/include_internal/rm_dbus.h @@ -1,38 +1,38 @@ -/* - * 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 __RM_DBUS_H__ -#define __RM_DBUS_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define RM_DBUS_BUS_NAME "rscmgr.resource" -#define RM_DBUS_INTERFACE_NAME "rscmgr.resource" -#define RM_DBUS_OBJ_PATH "/rscmgr/resource" - -int rm_dbus_method_call(const char *method, GVariant *args, GVariant **result); -int rm_dbus_method_call_async_with_no_reply(const char *method, GVariant *args); - -#ifdef __cplusplus -} -#endif - -#endif //__RM_DBUS_H__ \ No newline at end of file +/* + * 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 __RM_DBUS_H__ +#define __RM_DBUS_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define RM_DBUS_BUS_NAME "rscmgr.resource" +#define RM_DBUS_INTERFACE_NAME "rscmgr.resource" +#define RM_DBUS_OBJ_PATH "/rscmgr/resource" + +int rm_dbus_method_call(const char *method, GVariant *args, GVariant **result); +int rm_dbus_method_call_async_with_no_reply(const char *method, GVariant *args); + +#ifdef __cplusplus +} +#endif + +#endif //__RM_DBUS_H__ diff --git a/include_internal/rm_debug.h b/include_internal/rm_debug.h index 4cfb311..fc00a55 100644 --- a/include_internal/rm_debug.h +++ b/include_internal/rm_debug.h @@ -1,59 +1,59 @@ -/* - * 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 __RM_DEBUG_H__ -#define __RM_DEBUG_H__ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef LOG_TAG -#undef LOG_TAG -#endif //LOG_TAG - -#define LOG_TAG "RSC_MGR" - - -#ifndef RM_DBG -#define RM_DBG(fmt, args...) SLOGD(fmt, ##args) -#endif - -#ifndef RM_INFO -#define RM_INFO(fmt, args...) SLOGI(fmt, ##args) -#endif - -#ifndef RM_WARN -#define RM_WARN(fmt, args...) SLOGW(fmt, ##args) -#endif - -#ifndef RM_ERR -#define RM_ERR(fmt, args...) SLOGE(fmt, ##args) -#endif - -const char *rm_convert_requested_state_enum_to_string(rm_requests_resource_state_e state_enum); -const char *rm_convert_category_enum_to_string(rm_rsc_category_e category_enum); -int is_symlink_file(const char *path); -int _rc_get_capable_catgory_id(int handle, const char *app_id, int category_src); - -#ifdef __cplusplus -} -#endif -#endif //__RM_DEBUG_H__ +/* + * 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 __RM_DEBUG_H__ +#define __RM_DEBUG_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef LOG_TAG +#undef LOG_TAG +#endif //LOG_TAG + +#define LOG_TAG "RSC_MGR" + + +#ifndef RM_DBG +#define RM_DBG(fmt, args...) SLOGD(fmt, ##args) +#endif + +#ifndef RM_INFO +#define RM_INFO(fmt, args...) SLOGI(fmt, ##args) +#endif + +#ifndef RM_WARN +#define RM_WARN(fmt, args...) SLOGW(fmt, ##args) +#endif + +#ifndef RM_ERR +#define RM_ERR(fmt, args...) SLOGE(fmt, ##args) +#endif + +const char *rm_convert_requested_state_enum_to_string(rm_requests_resource_state_e state_enum); +const char *rm_convert_category_enum_to_string(rm_rsc_category_e category_enum); +int is_symlink_file(const char *path); +int _rc_get_capable_catgory_id(int handle, const char *app_id, int category_src); + +#ifdef __cplusplus +} +#endif +#endif //__RM_DEBUG_H__ diff --git a/include_internal/rm_internal.h b/include_internal/rm_internal.h index 9759fe0..57533d4 100644 --- a/include_internal/rm_internal.h +++ b/include_internal/rm_internal.h @@ -1,226 +1,226 @@ -/* - * 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 __RM_INTERNAL_H__ -#define __RM_INTERNAL_H__ - -#include -#include - -#define RM_RETURN_ERR_IF_NULL(a, msg) \ - if (!a) \ - { \ - RM_ERR("%s", msg); \ - return RM_ERROR; \ - } - -#define RM_RETURN_NULL_IF_NULL(a, msg) \ - if (!a) \ - { \ - RM_ERR("%s", msg); \ - return NULL; \ - } - -#define RM_RETURN_MINUS_IF_NULL(a, msg) \ - if (!a) \ - { \ - RM_ERR("%s", msg); \ - return -1; \ - } - -#define RM_RETURN_IF_NULL(a, msg) \ - if (!a) \ - { \ - RM_ERR("%s", msg); \ - return; \ - } - -#define RM_FREE(a) \ - if (a) \ - { \ - free(a); \ - a = NULL; \ - } - -#define RM_RETURN_ERR_IF_LT(a, v, msg) \ - if (a < v) \ - { \ - RM_ERR("invalid value(%d)", a); \ - return RM_ERROR; \ - } - -#define RM_RETURN_ERR_IF_GT(a, v, msg) \ - if (a > v) \ - { \ - RM_ERR("invalid value(%d)", a); \ - return RM_ERROR; \ - } - -#define RM_DEVICE_NODE_LEN_MAX 4096 -#define RM_INT32_LEN 32 - -/** - * @enum rm_resource_internal_state_e - * @brief Resource State - * This state can be returned using RM API - */ -typedef enum { - RM_INTERNAL_STATE_FREE, - RM_INTERNAL_STATE_SHARABLE, - RM_INTERNAL_STATE_SHARED, - RM_INTERNAL_STATE_EXCLUSIVE, - RM_INTERNAL_STATE_ERROR -} rm_resource_internal_state_e; - -typedef struct -{ - rm_rsc_category_e category_id; - int device_id; -} rm_conflicted_resource_info_s; - -/** - * @brief request data type - */ -typedef enum { - RM_REQUEST_DATA_TYPE_COMMON = 1, - RM_REQUEST_DATA_TYPE_REGISTER = (0x2 << 29), -} rm_request_data_type; - -typedef enum { - RM_RESPONSE_DATA_TYPE_ALL = 0, - RM_RESPONSE_DATA_TYPE_COMMON = 1, - RM_RESPONSE_DATA_TYPE_REGISTER = (0x2 << 29) -} rm_response_data_type; - -typedef enum { - RM_REQUEST_REGISTER, - RM_REQUEST_UNREGISTER, - RM_REQUEST_ALLOCATE_RESOURCE, - RM_REQUEST_RELEASE_RESOURCES, - RM_REQUEST_QUERY, - RM_REQUEST_SET_PRIORITY, - RM_REQUEST_SET_APPID, - RM_REQUEST_MAX, -} rm_request_type_e; - -/** - * @struct rm_category_s - * @brief category information for allocation - */ -typedef struct -{ - rm_rsc_category_e category_id; - int category_id_optional; - rm_requests_resource_state_e requested_state; -} rm_category_s; - - -/** - * @struct rm_requests_category_s - * @brief resource type information when consumer requests resource category - * - * The rm_requests_category_s struct encapsulate the number of resource. - * resource type array. requests_state in the one data - * - */ -typedef struct -{ - int resources_num; - rm_category_s *resources_categories; -} rm_requests_category_s; - -#define RM_APPID_LENGTH 256 - -typedef struct { - long data_type; - int type; - int handle; - int pid; - int request_num; - int resource[RM_REQUEST_RESOURCE_MAX]; - int resource_option[RM_REQUEST_RESOURCE_MAX]; - int state[RM_REQUEST_RESOURCE_MAX]; - int main_priority; - int sub_priority; - int app_pid; - char app_id[RM_APPID_LENGTH]; /* APPID */ - int device_id[RM_REQUEST_RESOURCE_MAX]; - int sub_type; - unsigned long time; -} rm_msg_request; - -typedef struct { - long data_type; - int type; - int result; - int resource_num; - int resource[RM_REQUEST_RESOURCE_MAX]; - rm_resource_internal_state_e resource_state[RM_REQUEST_RESOURCE_MAX]; - int available; - int handle; - int error_type; - int pid; -} rm_msg_response; - -struct rm_resource { - int id; - char *node; - int state; - int category_id; - int consumer_id; - char *app_id; - int virtual_id; //only for scaler - int source_id; //only for scaler - int max_rez; // max resolution only for scaler - int max_sampling_format; // only for scaler - int support_overlay; // only for scaler - int zone_id; // only for scaler - unsigned int framerate; - int cur_category_id; //only for scaler - unsigned int width; - unsigned int height; - bool android_app; -}; - -struct rm_resource_state { - int catId; - int devId; - int state; - int consumerId; - char *appId; -}; - -struct rm_resource_list { - int n_rsc; - GList *rsc_list; - GList *iter; -}; - -struct rm_conflict_resource { - int catId; // resource category id - int devId; // device id - int cId; // consumer id - const char *appId; // application id - int aZoneId; //application zone id - int rZoneId; //requester zone id -}; - -void rm_wait_for_server_ready(void); - -void rm_set_cpu_inheritance(void); -void rm_clear_cpu_inheritance(void); - -#endif //__RM_INTERNAL_H__ +/* + * 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 __RM_INTERNAL_H__ +#define __RM_INTERNAL_H__ + +#include +#include + +#define RM_RETURN_ERR_IF_NULL(a, msg) \ + if (!a) \ + { \ + RM_ERR("%s", msg); \ + return RM_ERROR; \ + } + +#define RM_RETURN_NULL_IF_NULL(a, msg) \ + if (!a) \ + { \ + RM_ERR("%s", msg); \ + return NULL; \ + } + +#define RM_RETURN_MINUS_IF_NULL(a, msg) \ + if (!a) \ + { \ + RM_ERR("%s", msg); \ + return -1; \ + } + +#define RM_RETURN_IF_NULL(a, msg) \ + if (!a) \ + { \ + RM_ERR("%s", msg); \ + return; \ + } + +#define RM_FREE(a) \ + if (a) \ + { \ + free(a); \ + a = NULL; \ + } + +#define RM_RETURN_ERR_IF_LT(a, v, msg) \ + if (a < v) \ + { \ + RM_ERR("invalid value(%d)", a); \ + return RM_ERROR; \ + } + +#define RM_RETURN_ERR_IF_GT(a, v, msg) \ + if (a > v) \ + { \ + RM_ERR("invalid value(%d)", a); \ + return RM_ERROR; \ + } + +#define RM_DEVICE_NODE_LEN_MAX 4096 +#define RM_INT32_LEN 32 + +/** + * @enum rm_resource_internal_state_e + * @brief Resource State + * This state can be returned using RM API + */ +typedef enum { + RM_INTERNAL_STATE_FREE, + RM_INTERNAL_STATE_SHARABLE, + RM_INTERNAL_STATE_SHARED, + RM_INTERNAL_STATE_EXCLUSIVE, + RM_INTERNAL_STATE_ERROR +} rm_resource_internal_state_e; + +typedef struct +{ + rm_rsc_category_e category_id; + int device_id; +} rm_conflicted_resource_info_s; + +/** + * @brief request data type + */ +typedef enum { + RM_REQUEST_DATA_TYPE_COMMON = 1, + RM_REQUEST_DATA_TYPE_REGISTER = (0x2 << 29), +} rm_request_data_type; + +typedef enum { + RM_RESPONSE_DATA_TYPE_ALL = 0, + RM_RESPONSE_DATA_TYPE_COMMON = 1, + RM_RESPONSE_DATA_TYPE_REGISTER = (0x2 << 29) +} rm_response_data_type; + +typedef enum { + RM_REQUEST_REGISTER, + RM_REQUEST_UNREGISTER, + RM_REQUEST_ALLOCATE_RESOURCE, + RM_REQUEST_RELEASE_RESOURCES, + RM_REQUEST_QUERY, + RM_REQUEST_SET_PRIORITY, + RM_REQUEST_SET_APPID, + RM_REQUEST_MAX, +} rm_request_type_e; + +/** + * @struct rm_category_s + * @brief category information for allocation + */ +typedef struct +{ + rm_rsc_category_e category_id; + int category_id_optional; + rm_requests_resource_state_e requested_state; +} rm_category_s; + + +/** + * @struct rm_requests_category_s + * @brief resource type information when consumer requests resource category + * + * The rm_requests_category_s struct encapsulate the number of resource. + * resource type array. requests_state in the one data + * + */ +typedef struct +{ + int resources_num; + rm_category_s *resources_categories; +} rm_requests_category_s; + +#define RM_APPID_LENGTH 256 + +typedef struct { + long data_type; + int type; + int handle; + int pid; + int request_num; + int resource[RM_REQUEST_RESOURCE_MAX]; + int resource_option[RM_REQUEST_RESOURCE_MAX]; + int state[RM_REQUEST_RESOURCE_MAX]; + int main_priority; + int sub_priority; + int app_pid; + char app_id[RM_APPID_LENGTH]; /* APPID */ + int device_id[RM_REQUEST_RESOURCE_MAX]; + int sub_type; + unsigned long time; +} rm_msg_request; + +typedef struct { + long data_type; + int type; + int result; + int resource_num; + int resource[RM_REQUEST_RESOURCE_MAX]; + rm_resource_internal_state_e resource_state[RM_REQUEST_RESOURCE_MAX]; + int available; + int handle; + int error_type; + int pid; +} rm_msg_response; + +struct rm_resource { + int id; + char *node; + int state; + int category_id; + int consumer_id; + char *app_id; + int virtual_id; //only for scaler + int source_id; //only for scaler + int max_rez; // max resolution only for scaler + int max_sampling_format; // only for scaler + int support_overlay; // only for scaler + int zone_id; // only for scaler + unsigned int framerate; + int cur_category_id; //only for scaler + unsigned int width; + unsigned int height; + bool android_app; +}; + +struct rm_resource_state { + int catId; + int devId; + int state; + int consumerId; + char *appId; +}; + +struct rm_resource_list { + int n_rsc; + GList *rsc_list; + GList *iter; +}; + +struct rm_conflict_resource { + int catId; // resource category id + int devId; // device id + int cId; // consumer id + const char *appId; // application id + int aZoneId; //application zone id + int rZoneId; //requester zone id +}; + +void rm_wait_for_server_ready(void); + +void rm_set_cpu_inheritance(void); +void rm_clear_cpu_inheritance(void); + +#endif //__RM_INTERNAL_H__ diff --git a/include_internal/rm_msg.h b/include_internal/rm_msg.h index 86dd15d..d1da2aa 100644 --- a/include_internal/rm_msg.h +++ b/include_internal/rm_msg.h @@ -1,33 +1,33 @@ -/* - * 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 __RM_MSG_H__ -#define __RM_MSG_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -int rm_send_msg(rm_msg_request *data); -int rm_receive_msg(rm_msg_response *response, int msg_type); -void rm_construct_request_msg(rm_msg_request *request, int msg_type, int handle); - -#ifdef __cplusplus -} -#endif -#endif //__RM_MSG_H__ +/* + * 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 __RM_MSG_H__ +#define __RM_MSG_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int rm_send_msg(rm_msg_request *data); +int rm_receive_msg(rm_msg_response *response, int msg_type); +void rm_construct_request_msg(rm_msg_request *request, int msg_type, int handle); + +#ifdef __cplusplus +} +#endif +#endif //__RM_MSG_H__ diff --git a/packaging/resource-manager.spec b/packaging/resource-manager.spec index 3b06835..6f0df4c 100644 --- a/packaging/resource-manager.spec +++ b/packaging/resource-manager.spec @@ -1,7 +1,7 @@ Name: resource-manager Summary: Resource manager Version: 0.1 -Release: 0 +Release: 1 Group: Multimedia/Libraries License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/rm_dbus.cpp b/src/rm_dbus.cpp index 509eeca..42d42ca 100644 --- a/src/rm_dbus.cpp +++ b/src/rm_dbus.cpp @@ -1,131 +1,131 @@ -/* - * 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 -#include -#include - -#include -#include - -// LCOV_EXCL_START - -static bool _wait_server_ready(void) -{ - const char *rsc_event_name = "/run/rsc_mgr_ready"; - - return access(rsc_event_name, F_OK) == 0; -} - -static GDBusConnection* __dbus_get_connection() -{ - static GDBusConnection *conn = NULL; - GError *err = NULL; - - if (conn) - return conn; - - conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); - if (!conn) { - RM_ERR("g_bus_get_sync() error (%s)", err->message); - g_error_free(err); - return NULL; - } - - return conn; -} - -void rm_set_cpu_inheritance(void) -{ - //resource_set_cpu_inheritance(0, "rscmgr-service", 1000); -} - -void rm_clear_cpu_inheritance(void) -{ - //resource_clear_cpu_inheritance(0, "rscmgr-service"); -} - -int rm_dbus_method_call(const char *method, GVariant *args, GVariant **result) -{ - GError *err = NULL; - GVariant *reply = NULL; - GDBusConnection *conn = NULL; - - if (!method) { - RM_ERR("Invalid Argument"); - g_variant_unref(args); - return -1; - } - - RM_INFO("Method call '%s'", method); - - if (!_wait_server_ready()) { - RM_ERR("server is not ready yet"); - g_variant_unref(args); - return -1; - } - - conn = __dbus_get_connection(); - - if (!conn) { - g_variant_unref(args); - return -1; - } - - rm_set_cpu_inheritance(); - reply = g_dbus_connection_call_sync(conn, RM_DBUS_BUS_NAME, RM_DBUS_OBJ_PATH, RM_DBUS_INTERFACE_NAME, - method, args, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); - rm_clear_cpu_inheritance(); - - if (!reply) { - RM_ERR("Method Call '%s' Failed (%s)", method, err->message); - g_error_free(err); - return -1; - } - - if (result) - *result = reply; - - return 0; -} - -int rm_dbus_method_call_async_with_no_reply(const char *method, GVariant *args) -{ - if (!method) { - RM_ERR("Invalid Argument"); - g_variant_unref(args); - return -1; - } - - RM_INFO("Method call (async) '%s'", method); - - if (!_wait_server_ready()) { - RM_ERR("server is not ready yet"); - return -1; - } - - GDBusConnection *conn = __dbus_get_connection(); - if (!conn) { - g_variant_unref(args); - return -1; - } - - g_dbus_connection_call(conn, RM_DBUS_BUS_NAME, RM_DBUS_OBJ_PATH, RM_DBUS_INTERFACE_NAME, - method, args, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); - - return 0; -} -// LCOV_EXCL_STOP +/* + * 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 +#include +#include + +#include +#include + +// LCOV_EXCL_START + +static bool _wait_server_ready(void) +{ + const char *rsc_event_name = "/run/rsc_mgr_ready"; + + return access(rsc_event_name, F_OK) == 0; +} + +static GDBusConnection* __dbus_get_connection() +{ + static GDBusConnection *conn = NULL; + GError *err = NULL; + + if (conn) + return conn; + + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (!conn) { + RM_ERR("g_bus_get_sync() error (%s)", err->message); + g_error_free(err); + return NULL; + } + + return conn; +} + +void rm_set_cpu_inheritance(void) +{ + //resource_set_cpu_inheritance(0, "rscmgr-service", 1000); +} + +void rm_clear_cpu_inheritance(void) +{ + //resource_clear_cpu_inheritance(0, "rscmgr-service"); +} + +int rm_dbus_method_call(const char *method, GVariant *args, GVariant **result) +{ + GError *err = NULL; + GVariant *reply = NULL; + GDBusConnection *conn = NULL; + + if (!method) { + RM_ERR("Invalid Argument"); + g_variant_unref(args); + return -1; + } + + RM_INFO("Method call '%s'", method); + + if (!_wait_server_ready()) { + RM_ERR("server is not ready yet"); + g_variant_unref(args); + return -1; + } + + conn = __dbus_get_connection(); + + if (!conn) { + g_variant_unref(args); + return -1; + } + + rm_set_cpu_inheritance(); + reply = g_dbus_connection_call_sync(conn, RM_DBUS_BUS_NAME, RM_DBUS_OBJ_PATH, RM_DBUS_INTERFACE_NAME, + method, args, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); + rm_clear_cpu_inheritance(); + + if (!reply) { + RM_ERR("Method Call '%s' Failed (%s)", method, err->message); + g_error_free(err); + return -1; + } + + if (result) + *result = reply; + + return 0; +} + +int rm_dbus_method_call_async_with_no_reply(const char *method, GVariant *args) +{ + if (!method) { + RM_ERR("Invalid Argument"); + g_variant_unref(args); + return -1; + } + + RM_INFO("Method call (async) '%s'", method); + + if (!_wait_server_ready()) { + RM_ERR("server is not ready yet"); + return -1; + } + + GDBusConnection *conn = __dbus_get_connection(); + if (!conn) { + g_variant_unref(args); + return -1; + } + + g_dbus_connection_call(conn, RM_DBUS_BUS_NAME, RM_DBUS_OBJ_PATH, RM_DBUS_INTERFACE_NAME, + method, args, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL); + + return 0; +} +// LCOV_EXCL_STOP diff --git a/src/rm_debug.cpp b/src/rm_debug.cpp index f3dde03..7eb9f52 100644 --- a/src/rm_debug.cpp +++ b/src/rm_debug.cpp @@ -1,128 +1,128 @@ -/* - * 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 -#include -#include -#include - -// LCOV_EXCL_START -const char *rm_convert_requested_state_enum_to_string(rm_requests_resource_state_e state_enum) -{ - switch(state_enum) { - case RM_STATE_PASSIVE: - return "PASSIVE"; - case RM_STATE_SHARABLE: - return "SHARABLE"; - case RM_STATE_EXCLUSIVE: - return "EXCLUSIVE"; - case RM_STATE_EXCLUSIVE_CONDITIONAL: - return "EXCLUSIVE_CONDITIONAL"; - case RM_STATE_EXCLUSIVE_AUTO: - return "EXCLUSIVE_AUTO"; - case RM_STATE_EXCLUSIVE_PREFERENCE: - return "EXCLUSIVE_PREFERENCE"; - default: - return "NONE"; - } -} - -const char *rm_convert_category_enum_to_string(rm_rsc_category_e category_enum) -{ - switch(category_enum) { - case RM_CATEGORY_NONE: - return "NONE"; - case RM_CATEGORY_AUDIO_DECODER: - return "Audio_Decoder"; - case RM_CATEGORY_AUDIO_DECODER_PRIMARY: - return "Audio_Decoder_Primary"; - case RM_CATEGORY_AUDIO_EVENT_COMPRESS: - return "Audio_Event_Compress"; - case RM_CATEGORY_AUDIO_SPDIF_ES_OUTPUT: - return "Not Defined Yet"; - case RM_CATEGORY_VIDEO_DECODER: - return "Video_Decoder"; - case RM_CATEGORY_DEMUX: - return "Demux_Main"; - case RM_CATEGORY_AUDIO_ENCODER: - return "Audio_Encoder"; - case RM_CATEGORY_VIDEO_ENCODER: - return "Video_Encoder"; - case RM_CATEGORY_SCALER: - return "Video_Scaler"; - case RM_CATEGORY_TUNER: - return "Tuner"; - case RM_CATEGORY_AUDIO_MAIN_OUT: - return "Audio_Main_Out"; - case RM_CATEGORY_AUDIO_REMOTE_OUT: - return "Audio_Remote_Out"; - case RM_CATEGORY_AUDIO_SCART_OUT: - return "Audio_Scart_Out"; - case RM_CATEGORY_MM_PCM_OUT: - return "MM_PCM_playback"; - case RM_CATEGORY_AUDIO_DECODER_SUB: - return "Audio_Decorder_Sub"; - case RM_CATEGORY_JPEG_DECODER: - return "JPEG_Decoder"; - case RM_CATEGORY_MJPEG_DECODER: - return "MJPEG_Decoder"; - case RM_CATEGORY_SCALER_SUB: - return "Video_Scaler_Sub"; - case RM_CATEGORY_EXT_VIDEO_SRC: - return "Ext_Video_Src"; - case RM_CATEGORY_EXT_AUDIO_SRC: - return "Ext_Audio_Src"; - case RM_CATEGORY_EXT_HDMI_SRC: - return "Ext_HDMI_Src"; - case RM_CATEGORY_VIDEO_DECODER_SUB: - return "Video_Decoder_Sub"; - case RM_CATEGORY_CAMERA: - return "Camera"; - case RM_CATEGORY_DEMUX_REC: - return "Demux_Rec"; - case RM_CATEGORY_TUNER_SUB: - return "Tuner_Sub"; - case RM_CATEGORY_VIDEO_DECODER_UHD: - return "Video_Decoder UHD"; - case RM_CATEGORY_INPUT_SRC_DTV: - return "Input_Src_DTV"; - case RM_CATEGORY_INPUT_SRC_ATV: - return "Input_Src_ATV"; - case RM_CATEGORY_INPUT_SRC_HDMI: - return "Input_Src_HDMI"; - case RM_CATEGORY_INPUT_SRC_COMP: - return "Input_Src_COMP"; - case RM_CATEGORY_INPUT_SRC_AV: - return "Input_Src_AV"; - case RM_CATEGORY_INPUT_SRC_SCART: - return "Input_Src_SCART"; - - default: - return ""; - } -} - -int is_symlink_file(const char *path) -{ - struct stat st; - if (lstat(path, &st) == -1) { - RM_ERR("stat error. file path(%s)", path); - return 0; - } - - return (S_ISLNK(st.st_mode)) ? 1 : 0; -} -// LCOV_EXCL_STOP +/* + * 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 +#include +#include +#include + +// LCOV_EXCL_START +const char *rm_convert_requested_state_enum_to_string(rm_requests_resource_state_e state_enum) +{ + switch(state_enum) { + case RM_STATE_PASSIVE: + return "PASSIVE"; + case RM_STATE_SHARABLE: + return "SHARABLE"; + case RM_STATE_EXCLUSIVE: + return "EXCLUSIVE"; + case RM_STATE_EXCLUSIVE_CONDITIONAL: + return "EXCLUSIVE_CONDITIONAL"; + case RM_STATE_EXCLUSIVE_AUTO: + return "EXCLUSIVE_AUTO"; + case RM_STATE_EXCLUSIVE_PREFERENCE: + return "EXCLUSIVE_PREFERENCE"; + default: + return "NONE"; + } +} + +const char *rm_convert_category_enum_to_string(rm_rsc_category_e category_enum) +{ + switch(category_enum) { + case RM_CATEGORY_NONE: + return "NONE"; + case RM_CATEGORY_AUDIO_DECODER: + return "Audio_Decoder"; + case RM_CATEGORY_AUDIO_DECODER_PRIMARY: + return "Audio_Decoder_Primary"; + case RM_CATEGORY_AUDIO_EVENT_COMPRESS: + return "Audio_Event_Compress"; + case RM_CATEGORY_AUDIO_SPDIF_ES_OUTPUT: + return "Not Defined Yet"; + case RM_CATEGORY_VIDEO_DECODER: + return "Video_Decoder"; + case RM_CATEGORY_DEMUX: + return "Demux_Main"; + case RM_CATEGORY_AUDIO_ENCODER: + return "Audio_Encoder"; + case RM_CATEGORY_VIDEO_ENCODER: + return "Video_Encoder"; + case RM_CATEGORY_SCALER: + return "Video_Scaler"; + case RM_CATEGORY_TUNER: + return "Tuner"; + case RM_CATEGORY_AUDIO_MAIN_OUT: + return "Audio_Main_Out"; + case RM_CATEGORY_AUDIO_REMOTE_OUT: + return "Audio_Remote_Out"; + case RM_CATEGORY_AUDIO_SCART_OUT: + return "Audio_Scart_Out"; + case RM_CATEGORY_MM_PCM_OUT: + return "MM_PCM_playback"; + case RM_CATEGORY_AUDIO_DECODER_SUB: + return "Audio_Decorder_Sub"; + case RM_CATEGORY_JPEG_DECODER: + return "JPEG_Decoder"; + case RM_CATEGORY_MJPEG_DECODER: + return "MJPEG_Decoder"; + case RM_CATEGORY_SCALER_SUB: + return "Video_Scaler_Sub"; + case RM_CATEGORY_EXT_VIDEO_SRC: + return "Ext_Video_Src"; + case RM_CATEGORY_EXT_AUDIO_SRC: + return "Ext_Audio_Src"; + case RM_CATEGORY_EXT_HDMI_SRC: + return "Ext_HDMI_Src"; + case RM_CATEGORY_VIDEO_DECODER_SUB: + return "Video_Decoder_Sub"; + case RM_CATEGORY_CAMERA: + return "Camera"; + case RM_CATEGORY_DEMUX_REC: + return "Demux_Rec"; + case RM_CATEGORY_TUNER_SUB: + return "Tuner_Sub"; + case RM_CATEGORY_VIDEO_DECODER_UHD: + return "Video_Decoder UHD"; + case RM_CATEGORY_INPUT_SRC_DTV: + return "Input_Src_DTV"; + case RM_CATEGORY_INPUT_SRC_ATV: + return "Input_Src_ATV"; + case RM_CATEGORY_INPUT_SRC_HDMI: + return "Input_Src_HDMI"; + case RM_CATEGORY_INPUT_SRC_COMP: + return "Input_Src_COMP"; + case RM_CATEGORY_INPUT_SRC_AV: + return "Input_Src_AV"; + case RM_CATEGORY_INPUT_SRC_SCART: + return "Input_Src_SCART"; + + default: + return ""; + } +} + +int is_symlink_file(const char *path) +{ + struct stat st; + if (lstat(path, &st) == -1) { + RM_ERR("stat error. file path(%s)", path); + return 0; + } + + return (S_ISLNK(st.st_mode)) ? 1 : 0; +} +// LCOV_EXCL_STOP diff --git a/src/rm_module_api.cpp b/src/rm_module_api.cpp index 8cb6d5f..6567c4f 100644 --- a/src/rm_module_api.cpp +++ b/src/rm_module_api.cpp @@ -1,1260 +1,1260 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// LCOV_EXCL_START - -#define RMS_INITIALIZED (access("/run/rsc_mgr_ready", F_OK) == 0) - -void rm_wait_for_server_ready(void) -{ - while (!RMS_INITIALIZED) { - RM_INFO("waiting for server ready"); - usleep(50*1000); // 50ms - } - RM_WARN("resource manager server is ready !!!"); -} - -int rm_get_resource_state(int rsc_id, rm_resource_state_e *state) -{ - RM_RETURN_ERR_IF_NULL(state, "invalid parameter"); - if (rsc_id < 0) { - RM_ERR("invalid resource id (%d)", rsc_id); - return RM_ERROR; - } - - int ret = RM_OK; - int rsc_state = 0; - GVariant *result = NULL; - - ret = rm_dbus_method_call("GetResourceState", - g_variant_new("(i)", rsc_id), - &result); - - if (ret) { - RM_ERR("dbus_method_call() for FindDeviceId is failed"); - return RM_ERROR; - } - - g_variant_get(result, "(i)", &rsc_state); - - if (rsc_state < 0) { - RM_ERR("can't get state(%d : %d)", rsc_id, rsc_state); - return RM_ERROR; - } - - *state = (rm_resource_state_e) rsc_state; - RM_INFO("state (%d : %d)", rsc_id, rsc_state); - g_variant_unref(result); - return RM_OK; -} - -int rm_get_scaler_state(rm_resource_list_h *list) -{ - RM_RETURN_ERR_IF_NULL(list, "invalid parameter"); - - int ret = RM_OK; - GVariant *result = NULL; - rm_resource_list *list_reply = NULL; - - list_reply = (rm_resource_list*) calloc(1, sizeof(rm_resource_list)); - assert(list_reply); - list_reply->n_rsc = 0; - *list = list_reply; - - ret = rm_dbus_method_call("GetScalerState", - g_variant_new("(i)", RM_CATEGORY_SCALER), - &result); - - if (ret) { - RM_ERR("dbus_method_call() for GetScalerState is failed"); - return RM_ERROR; - } - - int category_id; - int cur_category_id; - int rsc_id; - int state; - int cid; - int zone_id; - int android_app; - gchar *app_id; - - GVariantIter *iter; - g_variant_get(result, "(a(iiiiiisi))", &iter); - - while (g_variant_iter_loop(iter, "(iiiiiisi)", &category_id, &cur_category_id, &rsc_id, &state, &cid, &zone_id, &app_id, &android_app)) { - rm_resource *resource = (rm_resource*) calloc(1, sizeof(rm_resource)); - assert(resource); - resource->category_id = category_id; - resource->cur_category_id = cur_category_id; - resource->id = rsc_id; - resource->state = state; - resource->consumer_id = cid; - resource->zone_id = zone_id; - RM_INFO("(%d : %s)", resource->id, app_id ? app_id : "null"); - resource->app_id = (app_id) ? (char*) strndup(app_id, strlen(app_id)) : NULL; - resource->android_app = android_app; - list_reply->rsc_list = g_list_append(list_reply->rsc_list, resource); - } - g_variant_iter_free(iter); - - list_reply->n_rsc = g_list_length(list_reply->rsc_list); - list_reply->iter = list_reply->rsc_list; - - g_variant_unref(result); - return ret; -} - -int rm_get_resource_list(rm_rsc_category_e category, rm_resource_list_h *list) -{ - RM_RETURN_ERR_IF_NULL(list, "invalid parameter"); - - int ret = RM_OK; - GVariant *result = NULL; - rm_resource_list *list_reply = NULL; - - list_reply = (rm_resource_list*) calloc(1, sizeof(rm_resource_list)); - assert(list_reply); - list_reply->n_rsc = 0; - *list = list_reply; - - ret = rm_dbus_method_call("GetResourceList", - g_variant_new("(i)", category), - &result); - - if (ret) { - RM_ERR("dbus_method_call() for GetResourceList is failed"); - return RM_ERROR; - } - - int rsc_id; - int rsc_state; - int cid; - gchar *dev_node; - gchar *app_id; - - GVariantIter *iter; - g_variant_get(result, "(a(iissi))", &iter); - - while (g_variant_iter_loop(iter, "(iissi)", &rsc_id, &rsc_state, &dev_node, &app_id, &cid)) { - rm_resource *resource = (rm_resource*) calloc(1, sizeof(rm_resource)); - assert(resource); - resource->id = rsc_id; - resource->state = rsc_state; - resource->consumer_id = cid; - resource->support_overlay = ri_is_overlay_supported(rsc_id); - resource->max_rez = ri_get_supported_max_resolution(rsc_id); - resource->max_sampling_format = ri_get_max_sampling_format(rsc_id); - int category_id = 0; - if (ri_get_category_type_by_device_id(rsc_id, &category_id) != RI_OK) { - RM_ERR("failed to get category of (%d)", rsc_id); - } - resource->category_id = category_id; - - RM_INFO("(%d:%s)", resource->id, dev_node?dev_node : "null"); - resource->node = (dev_node) ? (char*) strndup(dev_node, strlen(dev_node)) : NULL; - resource->app_id = (app_id) ? (char*) strndup(app_id, strlen(app_id)) : NULL; - list_reply->rsc_list = g_list_append(list_reply->rsc_list, resource); - } - - g_variant_iter_free(iter); - - list_reply->n_rsc = g_list_length(list_reply->rsc_list); - list_reply->iter = list_reply->rsc_list; - - g_variant_unref(result); - return ret; -} - -static void rm_resource_free(gpointer data) -{ - rm_resource *resource = (rm_resource*) data; - RM_RETURN_IF_NULL(resource, "resource null"); - RM_FREE(resource->node); - RM_FREE(resource->app_id); - RM_FREE(resource); -} - -void rm_free_resource_list(rm_resource_list_h list) -{ - if (!list) - return; - - g_list_free_full(list->rsc_list, rm_resource_free); - RM_FREE(list); -} - -rm_resource_h rm_resource_list_get_next(rm_resource_list_h list) -{ - RM_RETURN_NULL_IF_NULL(list, "invalid list"); - RM_RETURN_NULL_IF_NULL(list->rsc_list, "no device in resource list"); - RM_RETURN_NULL_IF_NULL(list->iter, "no device in resource list"); - - GList *tmp = g_list_next(list->iter); - - RM_RETURN_NULL_IF_NULL(tmp, "no next resource"); - - list->iter = tmp; - return (rm_resource_h) list->iter->data; -} - -rm_resource_h rm_resource_list_get_prev(rm_resource_list_h list) -{ - RM_RETURN_NULL_IF_NULL(list, "invalid list"); - RM_RETURN_NULL_IF_NULL(list->rsc_list, "no device in resource list"); - RM_RETURN_NULL_IF_NULL(list->iter, "no device in resource list"); - - GList *tmp = g_list_previous(list->iter); - - RM_RETURN_NULL_IF_NULL(tmp, "no prev resource"); - - list->iter = tmp; - return (rm_resource_h) list->iter->data; -} - -rm_resource_h rm_resource_list_get_first(rm_resource_list_h list) -{ - RM_RETURN_NULL_IF_NULL(list, "invalid list"); - RM_RETURN_NULL_IF_NULL(list->rsc_list, "no device in resource list"); - RM_RETURN_NULL_IF_NULL(list->iter, "no device in resource list"); - - GList *tmp = g_list_first(list->iter); - - RM_RETURN_NULL_IF_NULL(tmp, "no first resource"); - - list->iter = tmp; - return (rm_resource_h) list->iter->data; -} - -rm_resource_h rm_resource_list_get_last(rm_resource_list_h list) -{ - RM_RETURN_NULL_IF_NULL(list, "invalid list"); - RM_RETURN_NULL_IF_NULL(list->rsc_list, "no device in resource list"); - RM_RETURN_NULL_IF_NULL(list->iter, "no device in resource list"); - - GList *tmp = g_list_last(list->iter); - - RM_RETURN_NULL_IF_NULL(tmp, "no last resource"); - - list->iter = tmp; - return (rm_resource_h) list->iter->data; -} - -int rm_resource_list_get_count(rm_resource_list_h list) -{ - return (list) ? list->n_rsc : 0; -} - -const char *rm_resource_get_node(rm_resource_h resource) -{ - RM_RETURN_NULL_IF_NULL(resource, "invalid parameter"); - return resource->node; -} - -int rm_resource_get_category(rm_resource_h resource) -{ - RM_RETURN_MINUS_IF_NULL(resource, "invalid parameter"); - return resource->category_id; -} - -int rm_resource_get_cur_category(rm_resource_h resource) -{ - RM_RETURN_MINUS_IF_NULL(resource, "invalid parameter"); - return resource->cur_category_id; -} - -int rm_resource_get_consumer(rm_resource_h resource) -{ - RM_RETURN_MINUS_IF_NULL(resource, "invalid parameter"); - return resource->consumer_id; -} - -int rm_resource_get_state(rm_resource_h resource) -{ - RM_RETURN_MINUS_IF_NULL(resource, "invalid parameter"); - return resource->state; -} - -const char *rm_resource_get_app_id(rm_resource_h resource) -{ - RM_RETURN_NULL_IF_NULL(resource, "invalid parameter"); - return resource->app_id; -} - -unsigned int rm_resource_get_framerate(rm_resource_h resource) -{ - RM_RETURN_MINUS_IF_NULL(resource, "invalid parameter"); - return resource->framerate; -} - -int rm_resource_get_id(rm_resource_h resource) -{ - return (resource) ? resource->id : -1; -} - -int rm_resource_get_max_resolution(rm_resource_h resource) -{ - return (resource) ? resource->max_rez : -1; -} - -bool rm_resource_support_overlay(rm_resource_h resource) -{ - return (resource) ? resource->support_overlay : false; -} - -int rm_resource_get_max_sampling_format(rm_resource_h resource) -{ - return (resource) ? resource->max_sampling_format : -1; -} - -int rm_resource_get_zone_id(rm_resource_h resource) -{ - return (resource) ? resource->zone_id : -1; -} - -static unsigned int state_change_signal_id = 0; - -static void onResourceStateChanged(GDBusConnection *conn, - const gchar *sender, - const gchar *object, - const gchar *interface, - const gchar *signal, - GVariant *parameters, - gpointer user_data) -{ - int device_id; - int category_id; - int state; - int handle; - char *app_id; - - g_variant_get(parameters, "(iiii&s)", &device_id, &category_id, &state, &handle, &app_id); - RM_INFO("signal (%s) received - (%d(%d) : %d : %d(%s))", signal, device_id, category_id, state, handle, app_id); - rm_call_state_changed_cb(category_id, device_id, state, handle, app_id); -} - -int rm_subscribe_resource_state_change(rm_rsc_category_e category, resource_state_change_cb cb, void *data) -{ - RM_RETURN_ERR_IF_NULL(cb, "invalid parameter"); - - if (rm_add_state_change_cb(category, cb, data) < 0) { - RM_ERR("already registered cb (%d : %p)", category, cb); - return RM_ERROR; - } - - if (state_change_signal_id) - return RM_OK; - - GError *error = NULL; - GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (!connection) { - RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); - return RM_ERROR; - } - - state_change_signal_id = g_dbus_connection_signal_subscribe(connection, - NULL, - RM_DBUS_INTERFACE_NAME, - "RscStateChanged", - RM_DBUS_OBJ_PATH, - NULL, - G_DBUS_SIGNAL_FLAGS_NONE, - onResourceStateChanged, - NULL, - NULL); - - if (state_change_signal_id == 0) { - if (error) { - RM_ERR("dbus connection close error: %s", error->message); - g_clear_error(&error); - } - return RM_ERROR; - } - - RM_INFO("subscribe resource state changed (%d)", state_change_signal_id); - return RM_OK; -} - -int rm_unsubscribe_resource_state_change(rm_rsc_category_e category, resource_state_change_cb cb) -{ - RM_RETURN_ERR_IF_NULL(cb, "invalid parameter"); - - int remain = 0; - if ((remain = rm_remove_state_change_cb(category, cb)) < 0) { - RM_ERR("not registered cb (%d:%p)", category, cb); - return RM_ERROR; - } - - if (remain > 0) { - RM_INFO("resource state change cb(%d:%p) removed", category, cb); - return RM_OK; - } - - GError *error = NULL; - GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (!connection) { - RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); - return RM_OK; - } - - RM_INFO("remove state change signal id(%d)", state_change_signal_id); - g_dbus_connection_signal_unsubscribe(connection, state_change_signal_id); - state_change_signal_id = 0; - - return RM_OK; -} - -int rm_rsc_state_get_category(rm_resource_state_h state) -{ - RM_RETURN_MINUS_IF_NULL(state, "invalid state"); - return state->catId; -} - -int rm_rsc_state_get_device_id(rm_resource_state_h state) -{ - RM_RETURN_MINUS_IF_NULL(state, "invalid state"); - return state->devId; -} - -int rm_rsc_state_get_state(rm_resource_state_h state) -{ - RM_RETURN_MINUS_IF_NULL(state, "invalid state"); - return state->state; -} - -int rm_rsc_state_get_consumer_id(rm_resource_state_h state) -{ - RM_RETURN_MINUS_IF_NULL(state, "invalid state"); - return state->consumerId; -} - -char *rm_rsc_state_get_app_id(rm_resource_state_h state) -{ - RM_RETURN_NULL_IF_NULL(state, "invalid state"); - return state->appId; -} - -static void OnResourceConflictEvent(GDBusConnection *conn, - const gchar *sender, - const gchar *object, - const gchar *interface, - const gchar *signal, - GVariant *parameters, - gpointer user_data) -{ - rm_conflict_resource rsc; - g_variant_get(parameters, "(iii&sii)", &rsc.catId, &rsc.devId, &rsc.cId, &rsc.appId, &rsc.aZoneId, &rsc.rZoneId); - - RM_INFO("signal (%s) received - (%d:%d:%d:%s:%d:%d)", signal, rsc.catId, rsc.devId, rsc.cId, rsc.appId, rsc.aZoneId, rsc.rZoneId); - - std::list cb_list = rm_get_conflict_event_cb_list(); - - for (auto& it : cb_list) { - RM_INFO("call cb(%p)", it->cb); - it->cb(&rsc, it->data); - } -} - -static unsigned int conflict_event_signal_id = 0; - -int rm_subscribe_resource_conflict_event(rm_conflict_event_cb cb, void *data) -{ - RM_RETURN_ERR_IF_NULL(cb, "invalid cb"); - - if (rm_add_conflict_event_cb(cb, data) < 0) { - RM_ERR("already registered cb(%p)", cb); - return RM_ERROR; - } - - if (conflict_event_signal_id) - return RM_OK; - - GError *error = NULL; - GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (!connection) { - RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); - rm_remove_conflict_event_cb(cb); - return RM_ERROR; - } - - conflict_event_signal_id = g_dbus_connection_signal_subscribe(connection, - NULL, - RM_DBUS_INTERFACE_NAME, - "RscConflicted", - RM_DBUS_OBJ_PATH, - NULL, - G_DBUS_SIGNAL_FLAGS_NONE, - OnResourceConflictEvent, - NULL, - NULL); - - if (conflict_event_signal_id == 0) { - if (error) { - RM_ERR("dbus connection close error: %s", error->message); - g_clear_error(&error); - rm_remove_conflict_event_cb(cb); - } - return RM_ERROR; - } - - RM_INFO("subscribe conflict event (%d)", conflict_event_signal_id); - - return RM_OK; -} - -int rm_unsubscribe_resource_conflict_event(rm_conflict_event_cb cb) -{ - RM_RETURN_ERR_IF_NULL(cb, "invalid cb"); - - int remain = 0; - if ((remain = rm_remove_conflict_event_cb(cb)) < 0) { - RM_ERR("unregistered cb(%p)", cb); - return RM_ERROR; - } - - RM_INFO("callback unregistered(%p)-(%d)", cb, remain); - - if (remain > 0) - return RM_OK; - - GError *error = NULL; - GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (!connection) { - RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); - return RM_OK; - } - - RM_INFO("remove conflict event signal id(%d)", conflict_event_signal_id); - g_dbus_connection_signal_unsubscribe(connection, conflict_event_signal_id); - conflict_event_signal_id = 0; - - return RM_OK; -} - -int rm_conflict_get_category_id(rm_conflict_resource_h rsc) -{ - RM_RETURN_MINUS_IF_NULL(rsc, "invalid rsc"); - return rsc->catId; -} - -int rm_conflict_get_device_id(rm_conflict_resource_h rsc) -{ - RM_RETURN_MINUS_IF_NULL(rsc, "invalid rsc"); - return rsc->devId; -} - -int rm_conflict_get_consumer_id(rm_conflict_resource_h rsc) -{ - RM_RETURN_MINUS_IF_NULL(rsc, "invalid rsc"); - return rsc->cId; -} - -const char *rm_conflict_get_app_id(rm_conflict_resource_h rsc) -{ - RM_RETURN_NULL_IF_NULL(rsc, "invalid rsc"); - return rsc->appId; -} - -int rm_conflict_get_multiview_zone_id_consumer(rm_conflict_resource_h rsc) -{ - RM_RETURN_MINUS_IF_NULL(rsc, "invalid rsc"); - return rsc->aZoneId; -} - -int rm_conflict_get_multiview_zone_id_requester(rm_conflict_resource_h rsc) -{ - RM_RETURN_MINUS_IF_NULL(rsc, "invalid rsc"); - return rsc->rZoneId; -} - -int rm_get_resource_collection_state(rm_rsc_collection_e collection, rm_resource_list_h *list) -{ - RM_RETURN_ERR_IF_NULL(list, "invalid parameter"); - - int ret; - GVariant *result = NULL; - rm_resource_list *list_reply = NULL; - - list_reply = (rm_resource_list*) calloc(1, sizeof(rm_resource_list)); - assert(list_reply); - list_reply->n_rsc = 0; - *list = list_reply; - - ret = rm_dbus_method_call("GetRscCollectionState", - g_variant_new("(i)", collection), - &result); - - if (ret) { - RM_ERR("dbus_method_call() for GetRscCollectionState is failed"); - return RM_ERROR; - } - - int rsc_id; - int rsc_state; - int rsc_category; - int cid; - int zone_id; - int android_app; - gchar *app_id; - gchar *dev_node; - - GVariantIter *iter; - g_variant_get(result, "(a(isiiisii))", &iter); - - while (g_variant_iter_loop(iter, "(isiiisii)", &rsc_id, &dev_node, &rsc_state, &rsc_category, &cid, &app_id, &zone_id, &android_app)) { - rm_resource *resource = (rm_resource*) calloc(1, sizeof(rm_resource)); - assert(resource); - resource->id = rsc_id; - RM_INFO("(%d:%s)", resource->id, dev_node?dev_node : "null"); - resource->node = (dev_node) ? (char*) strndup(dev_node, strlen(dev_node)) : NULL; - resource->state = rsc_state; - resource->category_id = rsc_category; - resource->framerate = ri_get_video_category_framerate(rsc_category); - resource->consumer_id = cid; - resource->app_id = (app_id) ? (char*) strndup(app_id, strlen(app_id)) : NULL; - resource->zone_id = zone_id; - resource->android_app = android_app; - list_reply->rsc_list = g_list_append(list_reply->rsc_list, resource); - } - - g_variant_iter_free(iter); - - list_reply->n_rsc = g_list_length(list_reply->rsc_list); - list_reply->iter = list_reply->rsc_list; - - g_variant_unref(result); - return ret; -} - -int rm_unmask_category_options(int category) -{ - int result = category; - - result = (result & ~RM_DEVICE_OPT_MAIN); - result = (result & ~RM_DEVICE_OPT_SUB); - - return ri_unmask_category_options(result); -} - -int rm_find_device_id(int virtual_id) -{ - if (virtual_id < 0) { - RM_ERR("invalid resource id (%d)", virtual_id); - return -1; - } - - int real_id = 0; - if (rm_shm_find_device_id(virtual_id, &real_id) == RM_OK) { - RM_INFO("real id (%d:%d)", virtual_id, real_id); - return real_id; - } - - int ret = RM_OK; - - GVariant *result = NULL; - - ret = rm_dbus_method_call("FindDeviceId", - g_variant_new("(i)", virtual_id), - &result); - - if (ret) { - RM_ERR("dbus_method_call() for FindDeviceId is failed"); - return RM_ERROR; - } - - g_variant_get(result, "(i)", &real_id); - - RM_INFO("real id (%d:%d)", virtual_id, real_id); - - g_variant_unref(result); - return real_id; -} - -int rm_swap_resources(int device_id_a, int device_id_b) -{ - if ((device_id_a < 0) || (device_id_b < 0)) { - RM_ERR("invalid resource id (%d/%d)", device_id_a, device_id_b); - return RM_ERROR; - } - - int ret = RM_OK; - int swap_result = 0; - GVariant *result = NULL; - - ret = rm_dbus_method_call("SwapResources", - g_variant_new("(ii)", device_id_a, device_id_b), - &result); - - if (ret) { - RM_ERR("dbus_method_call() for SwapResources is failed"); - return RM_ERROR; - } - - g_variant_get(result, "(i)", &swap_result); - - if (swap_result < 0) { - RM_ERR("faild to swap resources(%d:%d)", device_id_a, device_id_b); - ret = RM_ERROR; - } - - RM_INFO("swapped (%d:%d)", device_id_a, device_id_b); - - g_variant_unref(result); - return ret; -} - -int rm_swap_resources_async(int device_id_a, int device_id_b) -{ - if ((device_id_a < 0) || (device_id_b < 0)) { - RM_ERR("invalid resource id (%d/%d)", device_id_a, device_id_b); - return RM_ERROR; - } - - int ret = rm_dbus_method_call_async_with_no_reply("SwapResources", - g_variant_new("(ii)", device_id_a, device_id_b)); - if (ret) { - RM_ERR("dbus_method_call() for SwapResourcesAsync is failed"); - return RM_ERROR; - } - - RM_INFO("swapped requested (%d:%d)", device_id_a, device_id_b); - return RM_OK; -} - -int rm_restore_resources(int category) -{ - if (category < 0) { - RM_ERR("invalid category id (%d)", category); - return RM_ERROR; - } - - int ret = RM_OK; - int restore_result = 0; - GVariant *result = NULL; - - ret = rm_dbus_method_call("RestoreResources", - g_variant_new("(i)", category), - &result); - - if (ret) { - RM_ERR("dbus_method_call() for RestoreResources is failed"); - return RM_ERROR; - } - - g_variant_get(result, "(i)", &restore_result); - - if (restore_result < 0) { - RM_ERR("faild to restore resources(%d)", category); - ret = RM_ERROR; - } - - RM_INFO("restored (%d)", category); - - g_variant_unref(result); - return ret; -} - -int rm_get_app_id(int handle, char**app_id) -{ - if (handle < 0 || !app_id) { - RM_ERR("invalid param (%d)", handle); - return RM_ERROR; - } - - if (rm_shm_get_app_id(handle, app_id) == RM_OK) - return RM_OK; - - int ret = RM_OK; - int dbus_ret = 0; - char *ret_val = NULL; - GVariant *result = NULL; - - ret = rm_dbus_method_call("GetAppId", - g_variant_new("(i)", handle), - &result); - - if (ret) { - RM_ERR("dbus_method_call() for GetAppId is failed"); - return RM_ERROR; - } - - g_variant_get(result, "(i&s)", &dbus_ret, &ret_val); - - if (dbus_ret < 0) - ret = RM_ERROR; - - if (ret_val) - *app_id = strndup(ret_val, strlen(ret_val)); - - RM_INFO("(%d) - app_id(%d : %s)", dbus_ret, handle, (ret_val) ? *app_id : "null"); - - g_variant_unref(result); - return ret; -} - -int rm_get_active_audio_out(int handle) -{ - if (handle < 0) { - RM_ERR("invalid handle(%d)", handle); - return -1; - } - - int active_audio_out = 0; - if (rm_shm_get_active_audio_out(handle, &active_audio_out) == RM_OK) - return active_audio_out; - - int ret = 0; - GVariant *result = NULL; - - ret = rm_dbus_method_call("GetActiveAudioOut", - g_variant_new("(i)", handle), - &result); - if (ret) { - RM_ERR("dbus_method_call() for GetActiveAudioOut is failed"); - return -1; - } - - g_variant_get(result, "(i)", &active_audio_out); - - RM_INFO("active audio out (%d:%d)", handle, active_audio_out); - - g_variant_unref(result); - return active_audio_out; -} - -int rm_scaler_get_virtual_id(rm_resource_h scaler) -{ - return (scaler) ? scaler->virtual_id : -1; -} - -int rm_scaler_get_source_id(rm_resource_h scaler) -{ - return (scaler) ? scaler->source_id : -1; -} - -static unsigned int scaler_change_signal_id = 0; -static void onScalerStateChanged(GDBusConnection *conn, - const gchar *sender, - const gchar *object, - const gchar *interface, - const gchar *signal, - GVariant *param, - gpointer user_data) -{ - rm_resource_list *scaler_list = NULL; - - scaler_list = (rm_resource_list*) calloc(1, sizeof(rm_resource_list)); - assert(scaler_list); - scaler_list->n_rsc = 0; - - int virtual_id; - int source_id; - GVariantIter *iter; - g_variant_get(param, "(a(ii))", &iter); - - RM_INFO(">> scaler state changed"); - while (g_variant_iter_loop(iter, "(ii)", &virtual_id, &source_id)) { - rm_resource *scaler = (rm_resource*) calloc(1, sizeof(rm_resource)); - assert(scaler); - - scaler->virtual_id = virtual_id; - scaler->source_id = source_id; - RM_INFO("(%d:%d)", scaler->virtual_id, scaler->source_id); - - scaler_list->rsc_list = g_list_append(scaler_list->rsc_list, scaler); - } - - g_variant_iter_free(iter); - - scaler_list->n_rsc = g_list_length(scaler_list->rsc_list); - scaler_list->iter = scaler_list->rsc_list; - - rm_call_scaler_state_changed_cb(scaler_list); - - g_list_free_full(scaler_list->rsc_list, rm_resource_free); - RM_FREE(scaler_list); -} - -int rm_subscribe_scaler_state_change(scaler_state_change_cb cb, void *data) -{ - RM_RETURN_ERR_IF_NULL(cb, "invalid parameter"); - - if (rm_add_scaler_state_change_cb(cb, data) < 0) { - RM_ERR("already registered cb (%p)", cb); - return RM_ERROR; - } - - if (scaler_change_signal_id) - return RM_OK; - - GError *error = NULL; - GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (!connection) { - RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); - return RM_ERROR; - } - - scaler_change_signal_id = g_dbus_connection_signal_subscribe(connection, - NULL, - RM_DBUS_INTERFACE_NAME, - "ScalerStateChanged", - RM_DBUS_OBJ_PATH, - NULL, - G_DBUS_SIGNAL_FLAGS_NONE, - onScalerStateChanged, - NULL, - NULL); - - if (scaler_change_signal_id == 0) { - if (error) { - RM_ERR("dbus connection close error: %s", error->message); - g_clear_error(&error); - } - return RM_ERROR; - } - - RM_INFO("subscribe resource state changed (%d)", scaler_change_signal_id); - return RM_OK; -} - -int rm_unsubscribe_scaler_state_change(scaler_state_change_cb cb) -{ - RM_RETURN_ERR_IF_NULL(cb, "invalid parameter"); - - int remain = 0; - if ((remain = rm_remove_scaler_state_change_cb(cb)) < 0) { - RM_ERR("not registered cb (%p)", cb); - return RM_ERROR; - } - - if (remain > 0) { - RM_INFO("scaler state change cb(%p) removed", cb); - return RM_OK; - } - - GError *error = NULL; - GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (!connection) { - RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); - return RM_OK; - } - - RM_INFO("remove scaler change signal id(%d)", scaler_change_signal_id); - g_dbus_connection_signal_unsubscribe(connection, scaler_change_signal_id); - scaler_change_signal_id = 0; - - return RM_OK; -} - -int rm_get_scaler_hw_id(int zone_id, int *id) -{ - if (zone_id <= 0) { - RM_ERR("invalid resource id (%d)", zone_id); - return RM_ERROR; - } - - if (rm_shm_find_scaler_hw_id(zone_id, id) == RM_OK) - return RM_OK; - - int ret = RM_OK; - int hw_id = 0; - GVariant *result = NULL; - - ret = rm_dbus_method_call("GetScalerHWID", - g_variant_new("(i)", zone_id), - &result); - - if (ret) { - RM_ERR("dbus_method_call() for GetScalerHWID is failed"); - return RM_ERROR; - } - - g_variant_get(result, "(i)", &hw_id); - - if (hw_id < 0) { - RM_ERR("can't get hw id(%d:%d)", zone_id, hw_id); - g_variant_unref(result); - return RM_ERROR; - } - - *id = hw_id; - RM_INFO("hw id (%d:%d)", zone_id, hw_id); - g_variant_unref(result); - return RM_OK; -} - -int rm_notify_resource_policy(int policy) -{ - if (policy < 0) { - RM_ERR("invalid policy (%d)", policy); - return RM_ERROR; - } - - int ret = rm_dbus_method_call_async_with_no_reply("NotifyResourcePolicy", - g_variant_new("(i)", policy)); - - if (ret) { - RM_ERR("dbus_method_call() for NotifyResourcePolicy is failed"); - return RM_ERROR; - } - - RM_INFO("notified (%d)", policy); - return ret; -} - -int rm_notify_app_zone_info_async(const char *app_id, int zone_id) -{ - if (!app_id || zone_id < -1) { - RM_ERR("invalid param (%d)", zone_id); - return RM_ERROR; - } - - if (rm_dbus_method_call_async_with_no_reply("NotifyAppZoneInfo", g_variant_new("(si)", app_id, zone_id)) != 0) { - RM_ERR("dbus_method_call() for NotifyAppZoneInfo is failed"); - return RM_ERROR; - } - - RM_INFO("notified (%s:%d)", app_id, zone_id); - return RM_OK; -} - -int rm_reclaim_resources(int handle) -{ - RM_INFO("reclaim resources of (%d)", handle); - - if (rm_dbus_method_call_async_with_no_reply("ReclaimResources", g_variant_new("(i)", handle)) != 0) { - RM_ERR("dbus call for ReclaimResources failed"); - return RM_ERROR; - } - - return RM_OK; -} - -int rm_reclaim_app_resources(const char *app_id, const bool notify) -{ - if (!app_id) { - RM_ERR("invalid app id"); - return RM_ERROR; - } - - RM_INFO("reclaim resources of (%s:%d)", app_id, notify); - - GVariant *response = NULL; - if (rm_dbus_method_call("ReclaimAppResources", g_variant_new("(si)", app_id, notify), &response) != 0) { - RM_ERR("dbus call for ReclaimAppResources failed"); - return RM_ERROR; - } - - int reclaim_result = 0; - g_variant_get(response, "(i)", &reclaim_result); - - int result = (reclaim_result < 0) ? RM_ERROR : RM_OK; - RM_INFO("reclaime result (%s : %d)", app_id, result); - - g_variant_unref(response); - return result; -} - -int rm_reclaim_app_resources_async(const char *app_id, const bool notify) -{ - if (!app_id) { - RM_ERR("invalid app id"); - return RM_ERROR; - } - - RM_INFO("reclaim resources of (%s : %d)", app_id, notify); - - if (rm_dbus_method_call_async_with_no_reply("ReclaimAppResources", g_variant_new("(si)", app_id, notify)) != 0) { - RM_ERR("dbus call for ReclaimAppResources failed"); - return RM_ERROR; - } - - return RM_OK; -} - -rm_resource_list_h rm_resource_list_create(void) -{ - rm_resource_list *list = (rm_resource_list*) calloc(1, sizeof(rm_resource_list)); - if (!list) { - RM_ERR("insufficient memory"); - return NULL; - } - - list->n_rsc = 0; - return list; -} - -int rm_resource_list_append(rm_resource_list_h list, const rm_resource_h resource) -{ - if (!list || !resource) { - RM_ERR("invalid param"); - return RM_ERROR; - } - - list->rsc_list = g_list_append(list->rsc_list, resource); - list->n_rsc = g_list_length(list->rsc_list); - list->iter = list->rsc_list; - return RM_OK; -} - -rm_resource_h rm_create_video_encoder(const unsigned int width, const unsigned int height, const unsigned int framerate) -{ - rm_resource *resource = (rm_resource*) calloc(1, sizeof(rm_resource)); - if (!resource) { - RM_ERR("insufficient memory"); - return NULL; - } - - resource->width = width; - resource->height = height; - resource->framerate = framerate; - return resource; -} - -int rm_allocatable_video_encoders(const rm_resource_list_h list, bool *result) -{ - if (!list) { - RM_ERR("invalid param"); - *result = false; - return RM_ERROR; - } - - GVariantBuilder builder; - g_variant_builder_init(&builder, G_VARIANT_TYPE("(a(uuu))")); - g_variant_builder_open(&builder, G_VARIANT_TYPE("a(uuu)")); - - rm_resource_h resource = rm_resource_list_get_first(list); - while (resource) { - RM_INFO("w(%u)/h(%u)/fps(%u)", rm_resource_get_width(resource), rm_resource_get_height(resource), rm_resource_get_framerate(resource)); - g_variant_builder_add(&builder, "(uuu)", rm_resource_get_width(resource), rm_resource_get_height(resource), rm_resource_get_framerate(resource)); - resource = rm_resource_list_get_next(list); - }; - - g_variant_builder_close(&builder); - - GVariant *response = NULL; - if (rm_dbus_method_call("AllocatableVideoEncoders", g_variant_builder_end(&builder), &response) != 0) { - *result = false; - RM_ERR("dbus_method_call() for AllocatableVideoEncoders failed"); - return RM_ERROR; - } - - int available = 0; - g_variant_get(response, "(i)", &available); - g_variant_unref(response); - RM_INFO("available (%d)", available); - *result = (available == 1); - return RM_OK; -} - -unsigned int rm_resource_get_width(const rm_resource_h resource) -{ - if (!resource) { - RM_ERR("invalid param"); - return 0; - } - return resource->width; -} - -unsigned int rm_resource_get_height(const rm_resource_h resource) -{ - if (!resource) { - RM_ERR("invalid param"); - return 0; - } - return resource->height; -} - -bool rm_resource_android_app(const rm_resource_h resource) -{ - if (!resource) - return false; - - return resource->android_app; -} - -int rm_reclaim_video_decoders(const char *requester) -{ - if (!requester) { - RM_ERR("invalid param"); - return RM_ERROR; - } - - RM_INFO("reclaim video decoders allocated to other than (%s)", requester); - - GVariant *response = NULL; - if (rm_dbus_method_call("ReclaimVideoDecoders", g_variant_new("(s)", requester), &response) != 0) { - RM_ERR("dbus call for ReclaimVideoDecoders failed"); - return RM_ERROR; - } - - int result = 0; - g_variant_get(response, "(i)", &result); - g_variant_unref(response); - - RM_INFO("result : (%d)", result); - return (result == 0) ? RM_OK : RM_ERROR; -} - -bool rm_active_player(const int handle) -{ - bool result = false; - if (rm_shm_active_player(handle, &result) == RM_OK) { - RM_INFO("(%d : %d)", handle, result); - return result; - } - - GVariant *response = NULL; - if (rm_dbus_method_call("ActivePlayer", g_variant_new("(i)", handle), &response) != 0) { - RM_ERR("dbus call for ActivePlayer (%d) failed", handle); - return false; - } - - g_variant_get(response, "(b)", &result); - - RM_INFO("(%d : %d)", handle, result); - return result; -} - -bool rm_reclaimed_player(const int handle) -{ - bool result = false; - - GVariant *response = NULL; - if (rm_dbus_method_call("ReclaimedPlayer", g_variant_new("(i)", handle), &response)!= 0) { - RM_ERR("dbus call for ReclaimedPlayer (%d) failed", handle); - return false; - } - - g_variant_get(response, "(b)", &result); - - RM_INFO("(%d : %d)", handle, result); - return result; -} - -// LCOV_EXCL_STOP +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// LCOV_EXCL_START + +#define RMS_INITIALIZED (access("/run/rsc_mgr_ready", F_OK) == 0) + +void rm_wait_for_server_ready(void) +{ + while (!RMS_INITIALIZED) { + RM_INFO("waiting for server ready"); + usleep(50*1000); // 50ms + } + RM_WARN("resource manager server is ready !!!"); +} + +int rm_get_resource_state(int rsc_id, rm_resource_state_e *state) +{ + RM_RETURN_ERR_IF_NULL(state, "invalid parameter"); + if (rsc_id < 0) { + RM_ERR("invalid resource id (%d)", rsc_id); + return RM_ERROR; + } + + int ret = RM_OK; + int rsc_state = 0; + GVariant *result = NULL; + + ret = rm_dbus_method_call("GetResourceState", + g_variant_new("(i)", rsc_id), + &result); + + if (ret) { + RM_ERR("dbus_method_call() for FindDeviceId is failed"); + return RM_ERROR; + } + + g_variant_get(result, "(i)", &rsc_state); + + if (rsc_state < 0) { + RM_ERR("can't get state(%d : %d)", rsc_id, rsc_state); + return RM_ERROR; + } + + *state = (rm_resource_state_e) rsc_state; + RM_INFO("state (%d : %d)", rsc_id, rsc_state); + g_variant_unref(result); + return RM_OK; +} + +int rm_get_scaler_state(rm_resource_list_h *list) +{ + RM_RETURN_ERR_IF_NULL(list, "invalid parameter"); + + int ret = RM_OK; + GVariant *result = NULL; + rm_resource_list *list_reply = NULL; + + list_reply = (rm_resource_list*) calloc(1, sizeof(rm_resource_list)); + assert(list_reply); + list_reply->n_rsc = 0; + *list = list_reply; + + ret = rm_dbus_method_call("GetScalerState", + g_variant_new("(i)", RM_CATEGORY_SCALER), + &result); + + if (ret) { + RM_ERR("dbus_method_call() for GetScalerState is failed"); + return RM_ERROR; + } + + int category_id; + int cur_category_id; + int rsc_id; + int state; + int cid; + int zone_id; + int android_app; + gchar *app_id; + + GVariantIter *iter; + g_variant_get(result, "(a(iiiiiisi))", &iter); + + while (g_variant_iter_loop(iter, "(iiiiiisi)", &category_id, &cur_category_id, &rsc_id, &state, &cid, &zone_id, &app_id, &android_app)) { + rm_resource *resource = (rm_resource*) calloc(1, sizeof(rm_resource)); + assert(resource); + resource->category_id = category_id; + resource->cur_category_id = cur_category_id; + resource->id = rsc_id; + resource->state = state; + resource->consumer_id = cid; + resource->zone_id = zone_id; + RM_INFO("(%d : %s)", resource->id, app_id ? app_id : "null"); + resource->app_id = (app_id) ? (char*) strndup(app_id, strlen(app_id)) : NULL; + resource->android_app = android_app; + list_reply->rsc_list = g_list_append(list_reply->rsc_list, resource); + } + g_variant_iter_free(iter); + + list_reply->n_rsc = g_list_length(list_reply->rsc_list); + list_reply->iter = list_reply->rsc_list; + + g_variant_unref(result); + return ret; +} + +int rm_get_resource_list(rm_rsc_category_e category, rm_resource_list_h *list) +{ + RM_RETURN_ERR_IF_NULL(list, "invalid parameter"); + + int ret = RM_OK; + GVariant *result = NULL; + rm_resource_list *list_reply = NULL; + + list_reply = (rm_resource_list*) calloc(1, sizeof(rm_resource_list)); + assert(list_reply); + list_reply->n_rsc = 0; + *list = list_reply; + + ret = rm_dbus_method_call("GetResourceList", + g_variant_new("(i)", category), + &result); + + if (ret) { + RM_ERR("dbus_method_call() for GetResourceList is failed"); + return RM_ERROR; + } + + int rsc_id; + int rsc_state; + int cid; + gchar *dev_node; + gchar *app_id; + + GVariantIter *iter; + g_variant_get(result, "(a(iissi))", &iter); + + while (g_variant_iter_loop(iter, "(iissi)", &rsc_id, &rsc_state, &dev_node, &app_id, &cid)) { + rm_resource *resource = (rm_resource*) calloc(1, sizeof(rm_resource)); + assert(resource); + resource->id = rsc_id; + resource->state = rsc_state; + resource->consumer_id = cid; + resource->support_overlay = ri_is_overlay_supported(rsc_id); + resource->max_rez = ri_get_supported_max_resolution(rsc_id); + resource->max_sampling_format = ri_get_max_sampling_format(rsc_id); + int category_id = 0; + if (ri_get_category_type_by_device_id(rsc_id, &category_id) != RI_OK) { + RM_ERR("failed to get category of (%d)", rsc_id); + } + resource->category_id = category_id; + + RM_INFO("(%d:%s)", resource->id, dev_node?dev_node : "null"); + resource->node = (dev_node) ? (char*) strndup(dev_node, strlen(dev_node)) : NULL; + resource->app_id = (app_id) ? (char*) strndup(app_id, strlen(app_id)) : NULL; + list_reply->rsc_list = g_list_append(list_reply->rsc_list, resource); + } + + g_variant_iter_free(iter); + + list_reply->n_rsc = g_list_length(list_reply->rsc_list); + list_reply->iter = list_reply->rsc_list; + + g_variant_unref(result); + return ret; +} + +static void rm_resource_free(gpointer data) +{ + rm_resource *resource = (rm_resource*) data; + RM_RETURN_IF_NULL(resource, "resource null"); + RM_FREE(resource->node); + RM_FREE(resource->app_id); + RM_FREE(resource); +} + +void rm_free_resource_list(rm_resource_list_h list) +{ + if (!list) + return; + + g_list_free_full(list->rsc_list, rm_resource_free); + RM_FREE(list); +} + +rm_resource_h rm_resource_list_get_next(rm_resource_list_h list) +{ + RM_RETURN_NULL_IF_NULL(list, "invalid list"); + RM_RETURN_NULL_IF_NULL(list->rsc_list, "no device in resource list"); + RM_RETURN_NULL_IF_NULL(list->iter, "no device in resource list"); + + GList *tmp = g_list_next(list->iter); + + RM_RETURN_NULL_IF_NULL(tmp, "no next resource"); + + list->iter = tmp; + return (rm_resource_h) list->iter->data; +} + +rm_resource_h rm_resource_list_get_prev(rm_resource_list_h list) +{ + RM_RETURN_NULL_IF_NULL(list, "invalid list"); + RM_RETURN_NULL_IF_NULL(list->rsc_list, "no device in resource list"); + RM_RETURN_NULL_IF_NULL(list->iter, "no device in resource list"); + + GList *tmp = g_list_previous(list->iter); + + RM_RETURN_NULL_IF_NULL(tmp, "no prev resource"); + + list->iter = tmp; + return (rm_resource_h) list->iter->data; +} + +rm_resource_h rm_resource_list_get_first(rm_resource_list_h list) +{ + RM_RETURN_NULL_IF_NULL(list, "invalid list"); + RM_RETURN_NULL_IF_NULL(list->rsc_list, "no device in resource list"); + RM_RETURN_NULL_IF_NULL(list->iter, "no device in resource list"); + + GList *tmp = g_list_first(list->iter); + + RM_RETURN_NULL_IF_NULL(tmp, "no first resource"); + + list->iter = tmp; + return (rm_resource_h) list->iter->data; +} + +rm_resource_h rm_resource_list_get_last(rm_resource_list_h list) +{ + RM_RETURN_NULL_IF_NULL(list, "invalid list"); + RM_RETURN_NULL_IF_NULL(list->rsc_list, "no device in resource list"); + RM_RETURN_NULL_IF_NULL(list->iter, "no device in resource list"); + + GList *tmp = g_list_last(list->iter); + + RM_RETURN_NULL_IF_NULL(tmp, "no last resource"); + + list->iter = tmp; + return (rm_resource_h) list->iter->data; +} + +int rm_resource_list_get_count(rm_resource_list_h list) +{ + return (list) ? list->n_rsc : 0; +} + +const char *rm_resource_get_node(rm_resource_h resource) +{ + RM_RETURN_NULL_IF_NULL(resource, "invalid parameter"); + return resource->node; +} + +int rm_resource_get_category(rm_resource_h resource) +{ + RM_RETURN_MINUS_IF_NULL(resource, "invalid parameter"); + return resource->category_id; +} + +int rm_resource_get_cur_category(rm_resource_h resource) +{ + RM_RETURN_MINUS_IF_NULL(resource, "invalid parameter"); + return resource->cur_category_id; +} + +int rm_resource_get_consumer(rm_resource_h resource) +{ + RM_RETURN_MINUS_IF_NULL(resource, "invalid parameter"); + return resource->consumer_id; +} + +int rm_resource_get_state(rm_resource_h resource) +{ + RM_RETURN_MINUS_IF_NULL(resource, "invalid parameter"); + return resource->state; +} + +const char *rm_resource_get_app_id(rm_resource_h resource) +{ + RM_RETURN_NULL_IF_NULL(resource, "invalid parameter"); + return resource->app_id; +} + +unsigned int rm_resource_get_framerate(rm_resource_h resource) +{ + RM_RETURN_MINUS_IF_NULL(resource, "invalid parameter"); + return resource->framerate; +} + +int rm_resource_get_id(rm_resource_h resource) +{ + return (resource) ? resource->id : -1; +} + +int rm_resource_get_max_resolution(rm_resource_h resource) +{ + return (resource) ? resource->max_rez : -1; +} + +bool rm_resource_support_overlay(rm_resource_h resource) +{ + return (resource) ? resource->support_overlay : false; +} + +int rm_resource_get_max_sampling_format(rm_resource_h resource) +{ + return (resource) ? resource->max_sampling_format : -1; +} + +int rm_resource_get_zone_id(rm_resource_h resource) +{ + return (resource) ? resource->zone_id : -1; +} + +static unsigned int state_change_signal_id = 0; + +static void onResourceStateChanged(GDBusConnection *conn, + const gchar *sender, + const gchar *object, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) +{ + int device_id; + int category_id; + int state; + int handle; + char *app_id; + + g_variant_get(parameters, "(iiii&s)", &device_id, &category_id, &state, &handle, &app_id); + RM_INFO("signal (%s) received - (%d(%d) : %d : %d(%s))", signal, device_id, category_id, state, handle, app_id); + rm_call_state_changed_cb(category_id, device_id, state, handle, app_id); +} + +int rm_subscribe_resource_state_change(rm_rsc_category_e category, resource_state_change_cb cb, void *data) +{ + RM_RETURN_ERR_IF_NULL(cb, "invalid parameter"); + + if (rm_add_state_change_cb(category, cb, data) < 0) { + RM_ERR("already registered cb (%d : %p)", category, cb); + return RM_ERROR; + } + + if (state_change_signal_id) + return RM_OK; + + GError *error = NULL; + GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!connection) { + RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); + return RM_ERROR; + } + + state_change_signal_id = g_dbus_connection_signal_subscribe(connection, + NULL, + RM_DBUS_INTERFACE_NAME, + "RscStateChanged", + RM_DBUS_OBJ_PATH, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + onResourceStateChanged, + NULL, + NULL); + + if (state_change_signal_id == 0) { + if (error) { + RM_ERR("dbus connection close error: %s", error->message); + g_clear_error(&error); + } + return RM_ERROR; + } + + RM_INFO("subscribe resource state changed (%d)", state_change_signal_id); + return RM_OK; +} + +int rm_unsubscribe_resource_state_change(rm_rsc_category_e category, resource_state_change_cb cb) +{ + RM_RETURN_ERR_IF_NULL(cb, "invalid parameter"); + + int remain = 0; + if ((remain = rm_remove_state_change_cb(category, cb)) < 0) { + RM_ERR("not registered cb (%d:%p)", category, cb); + return RM_ERROR; + } + + if (remain > 0) { + RM_INFO("resource state change cb(%d:%p) removed", category, cb); + return RM_OK; + } + + GError *error = NULL; + GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!connection) { + RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); + return RM_OK; + } + + RM_INFO("remove state change signal id(%d)", state_change_signal_id); + g_dbus_connection_signal_unsubscribe(connection, state_change_signal_id); + state_change_signal_id = 0; + + return RM_OK; +} + +int rm_rsc_state_get_category(rm_resource_state_h state) +{ + RM_RETURN_MINUS_IF_NULL(state, "invalid state"); + return state->catId; +} + +int rm_rsc_state_get_device_id(rm_resource_state_h state) +{ + RM_RETURN_MINUS_IF_NULL(state, "invalid state"); + return state->devId; +} + +int rm_rsc_state_get_state(rm_resource_state_h state) +{ + RM_RETURN_MINUS_IF_NULL(state, "invalid state"); + return state->state; +} + +int rm_rsc_state_get_consumer_id(rm_resource_state_h state) +{ + RM_RETURN_MINUS_IF_NULL(state, "invalid state"); + return state->consumerId; +} + +char *rm_rsc_state_get_app_id(rm_resource_state_h state) +{ + RM_RETURN_NULL_IF_NULL(state, "invalid state"); + return state->appId; +} + +static void OnResourceConflictEvent(GDBusConnection *conn, + const gchar *sender, + const gchar *object, + const gchar *interface, + const gchar *signal, + GVariant *parameters, + gpointer user_data) +{ + rm_conflict_resource rsc; + g_variant_get(parameters, "(iii&sii)", &rsc.catId, &rsc.devId, &rsc.cId, &rsc.appId, &rsc.aZoneId, &rsc.rZoneId); + + RM_INFO("signal (%s) received - (%d:%d:%d:%s:%d:%d)", signal, rsc.catId, rsc.devId, rsc.cId, rsc.appId, rsc.aZoneId, rsc.rZoneId); + + std::list cb_list = rm_get_conflict_event_cb_list(); + + for (auto& it : cb_list) { + RM_INFO("call cb(%p)", it->cb); + it->cb(&rsc, it->data); + } +} + +static unsigned int conflict_event_signal_id = 0; + +int rm_subscribe_resource_conflict_event(rm_conflict_event_cb cb, void *data) +{ + RM_RETURN_ERR_IF_NULL(cb, "invalid cb"); + + if (rm_add_conflict_event_cb(cb, data) < 0) { + RM_ERR("already registered cb(%p)", cb); + return RM_ERROR; + } + + if (conflict_event_signal_id) + return RM_OK; + + GError *error = NULL; + GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!connection) { + RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); + rm_remove_conflict_event_cb(cb); + return RM_ERROR; + } + + conflict_event_signal_id = g_dbus_connection_signal_subscribe(connection, + NULL, + RM_DBUS_INTERFACE_NAME, + "RscConflicted", + RM_DBUS_OBJ_PATH, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + OnResourceConflictEvent, + NULL, + NULL); + + if (conflict_event_signal_id == 0) { + if (error) { + RM_ERR("dbus connection close error: %s", error->message); + g_clear_error(&error); + rm_remove_conflict_event_cb(cb); + } + return RM_ERROR; + } + + RM_INFO("subscribe conflict event (%d)", conflict_event_signal_id); + + return RM_OK; +} + +int rm_unsubscribe_resource_conflict_event(rm_conflict_event_cb cb) +{ + RM_RETURN_ERR_IF_NULL(cb, "invalid cb"); + + int remain = 0; + if ((remain = rm_remove_conflict_event_cb(cb)) < 0) { + RM_ERR("unregistered cb(%p)", cb); + return RM_ERROR; + } + + RM_INFO("callback unregistered(%p)-(%d)", cb, remain); + + if (remain > 0) + return RM_OK; + + GError *error = NULL; + GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!connection) { + RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); + return RM_OK; + } + + RM_INFO("remove conflict event signal id(%d)", conflict_event_signal_id); + g_dbus_connection_signal_unsubscribe(connection, conflict_event_signal_id); + conflict_event_signal_id = 0; + + return RM_OK; +} + +int rm_conflict_get_category_id(rm_conflict_resource_h rsc) +{ + RM_RETURN_MINUS_IF_NULL(rsc, "invalid rsc"); + return rsc->catId; +} + +int rm_conflict_get_device_id(rm_conflict_resource_h rsc) +{ + RM_RETURN_MINUS_IF_NULL(rsc, "invalid rsc"); + return rsc->devId; +} + +int rm_conflict_get_consumer_id(rm_conflict_resource_h rsc) +{ + RM_RETURN_MINUS_IF_NULL(rsc, "invalid rsc"); + return rsc->cId; +} + +const char *rm_conflict_get_app_id(rm_conflict_resource_h rsc) +{ + RM_RETURN_NULL_IF_NULL(rsc, "invalid rsc"); + return rsc->appId; +} + +int rm_conflict_get_multiview_zone_id_consumer(rm_conflict_resource_h rsc) +{ + RM_RETURN_MINUS_IF_NULL(rsc, "invalid rsc"); + return rsc->aZoneId; +} + +int rm_conflict_get_multiview_zone_id_requester(rm_conflict_resource_h rsc) +{ + RM_RETURN_MINUS_IF_NULL(rsc, "invalid rsc"); + return rsc->rZoneId; +} + +int rm_get_resource_collection_state(rm_rsc_collection_e collection, rm_resource_list_h *list) +{ + RM_RETURN_ERR_IF_NULL(list, "invalid parameter"); + + int ret; + GVariant *result = NULL; + rm_resource_list *list_reply = NULL; + + list_reply = (rm_resource_list*) calloc(1, sizeof(rm_resource_list)); + assert(list_reply); + list_reply->n_rsc = 0; + *list = list_reply; + + ret = rm_dbus_method_call("GetRscCollectionState", + g_variant_new("(i)", collection), + &result); + + if (ret) { + RM_ERR("dbus_method_call() for GetRscCollectionState is failed"); + return RM_ERROR; + } + + int rsc_id; + int rsc_state; + int rsc_category; + int cid; + int zone_id; + int android_app; + gchar *app_id; + gchar *dev_node; + + GVariantIter *iter; + g_variant_get(result, "(a(isiiisii))", &iter); + + while (g_variant_iter_loop(iter, "(isiiisii)", &rsc_id, &dev_node, &rsc_state, &rsc_category, &cid, &app_id, &zone_id, &android_app)) { + rm_resource *resource = (rm_resource*) calloc(1, sizeof(rm_resource)); + assert(resource); + resource->id = rsc_id; + RM_INFO("(%d:%s)", resource->id, dev_node?dev_node : "null"); + resource->node = (dev_node) ? (char*) strndup(dev_node, strlen(dev_node)) : NULL; + resource->state = rsc_state; + resource->category_id = rsc_category; + resource->framerate = ri_get_video_category_framerate(rsc_category); + resource->consumer_id = cid; + resource->app_id = (app_id) ? (char*) strndup(app_id, strlen(app_id)) : NULL; + resource->zone_id = zone_id; + resource->android_app = android_app; + list_reply->rsc_list = g_list_append(list_reply->rsc_list, resource); + } + + g_variant_iter_free(iter); + + list_reply->n_rsc = g_list_length(list_reply->rsc_list); + list_reply->iter = list_reply->rsc_list; + + g_variant_unref(result); + return ret; +} + +int rm_unmask_category_options(int category) +{ + int result = category; + + result = (result & ~RM_DEVICE_OPT_MAIN); + result = (result & ~RM_DEVICE_OPT_SUB); + + return ri_unmask_category_options(result); +} + +int rm_find_device_id(int virtual_id) +{ + if (virtual_id < 0) { + RM_ERR("invalid resource id (%d)", virtual_id); + return -1; + } + + int real_id = 0; + if (rm_shm_find_device_id(virtual_id, &real_id) == RM_OK) { + RM_INFO("real id (%d:%d)", virtual_id, real_id); + return real_id; + } + + int ret = RM_OK; + + GVariant *result = NULL; + + ret = rm_dbus_method_call("FindDeviceId", + g_variant_new("(i)", virtual_id), + &result); + + if (ret) { + RM_ERR("dbus_method_call() for FindDeviceId is failed"); + return RM_ERROR; + } + + g_variant_get(result, "(i)", &real_id); + + RM_INFO("real id (%d:%d)", virtual_id, real_id); + + g_variant_unref(result); + return real_id; +} + +int rm_swap_resources(int device_id_a, int device_id_b) +{ + if ((device_id_a < 0) || (device_id_b < 0)) { + RM_ERR("invalid resource id (%d/%d)", device_id_a, device_id_b); + return RM_ERROR; + } + + int ret = RM_OK; + int swap_result = 0; + GVariant *result = NULL; + + ret = rm_dbus_method_call("SwapResources", + g_variant_new("(ii)", device_id_a, device_id_b), + &result); + + if (ret) { + RM_ERR("dbus_method_call() for SwapResources is failed"); + return RM_ERROR; + } + + g_variant_get(result, "(i)", &swap_result); + + if (swap_result < 0) { + RM_ERR("faild to swap resources(%d:%d)", device_id_a, device_id_b); + ret = RM_ERROR; + } + + RM_INFO("swapped (%d:%d)", device_id_a, device_id_b); + + g_variant_unref(result); + return ret; +} + +int rm_swap_resources_async(int device_id_a, int device_id_b) +{ + if ((device_id_a < 0) || (device_id_b < 0)) { + RM_ERR("invalid resource id (%d/%d)", device_id_a, device_id_b); + return RM_ERROR; + } + + int ret = rm_dbus_method_call_async_with_no_reply("SwapResources", + g_variant_new("(ii)", device_id_a, device_id_b)); + if (ret) { + RM_ERR("dbus_method_call() for SwapResourcesAsync is failed"); + return RM_ERROR; + } + + RM_INFO("swapped requested (%d:%d)", device_id_a, device_id_b); + return RM_OK; +} + +int rm_restore_resources(int category) +{ + if (category < 0) { + RM_ERR("invalid category id (%d)", category); + return RM_ERROR; + } + + int ret = RM_OK; + int restore_result = 0; + GVariant *result = NULL; + + ret = rm_dbus_method_call("RestoreResources", + g_variant_new("(i)", category), + &result); + + if (ret) { + RM_ERR("dbus_method_call() for RestoreResources is failed"); + return RM_ERROR; + } + + g_variant_get(result, "(i)", &restore_result); + + if (restore_result < 0) { + RM_ERR("faild to restore resources(%d)", category); + ret = RM_ERROR; + } + + RM_INFO("restored (%d)", category); + + g_variant_unref(result); + return ret; +} + +int rm_get_app_id(int handle, char**app_id) +{ + if (handle < 0 || !app_id) { + RM_ERR("invalid param (%d)", handle); + return RM_ERROR; + } + + if (rm_shm_get_app_id(handle, app_id) == RM_OK) + return RM_OK; + + int ret = RM_OK; + int dbus_ret = 0; + char *ret_val = NULL; + GVariant *result = NULL; + + ret = rm_dbus_method_call("GetAppId", + g_variant_new("(i)", handle), + &result); + + if (ret) { + RM_ERR("dbus_method_call() for GetAppId is failed"); + return RM_ERROR; + } + + g_variant_get(result, "(i&s)", &dbus_ret, &ret_val); + + if (dbus_ret < 0) + ret = RM_ERROR; + + if (ret_val) + *app_id = strndup(ret_val, strlen(ret_val)); + + RM_INFO("(%d) - app_id(%d : %s)", dbus_ret, handle, (ret_val) ? *app_id : "null"); + + g_variant_unref(result); + return ret; +} + +int rm_get_active_audio_out(int handle) +{ + if (handle < 0) { + RM_ERR("invalid handle(%d)", handle); + return -1; + } + + int active_audio_out = 0; + if (rm_shm_get_active_audio_out(handle, &active_audio_out) == RM_OK) + return active_audio_out; + + int ret = 0; + GVariant *result = NULL; + + ret = rm_dbus_method_call("GetActiveAudioOut", + g_variant_new("(i)", handle), + &result); + if (ret) { + RM_ERR("dbus_method_call() for GetActiveAudioOut is failed"); + return -1; + } + + g_variant_get(result, "(i)", &active_audio_out); + + RM_INFO("active audio out (%d:%d)", handle, active_audio_out); + + g_variant_unref(result); + return active_audio_out; +} + +int rm_scaler_get_virtual_id(rm_resource_h scaler) +{ + return (scaler) ? scaler->virtual_id : -1; +} + +int rm_scaler_get_source_id(rm_resource_h scaler) +{ + return (scaler) ? scaler->source_id : -1; +} + +static unsigned int scaler_change_signal_id = 0; +static void onScalerStateChanged(GDBusConnection *conn, + const gchar *sender, + const gchar *object, + const gchar *interface, + const gchar *signal, + GVariant *param, + gpointer user_data) +{ + rm_resource_list *scaler_list = NULL; + + scaler_list = (rm_resource_list*) calloc(1, sizeof(rm_resource_list)); + assert(scaler_list); + scaler_list->n_rsc = 0; + + int virtual_id; + int source_id; + GVariantIter *iter; + g_variant_get(param, "(a(ii))", &iter); + + RM_INFO(">> scaler state changed"); + while (g_variant_iter_loop(iter, "(ii)", &virtual_id, &source_id)) { + rm_resource *scaler = (rm_resource*) calloc(1, sizeof(rm_resource)); + assert(scaler); + + scaler->virtual_id = virtual_id; + scaler->source_id = source_id; + RM_INFO("(%d:%d)", scaler->virtual_id, scaler->source_id); + + scaler_list->rsc_list = g_list_append(scaler_list->rsc_list, scaler); + } + + g_variant_iter_free(iter); + + scaler_list->n_rsc = g_list_length(scaler_list->rsc_list); + scaler_list->iter = scaler_list->rsc_list; + + rm_call_scaler_state_changed_cb(scaler_list); + + g_list_free_full(scaler_list->rsc_list, rm_resource_free); + RM_FREE(scaler_list); +} + +int rm_subscribe_scaler_state_change(scaler_state_change_cb cb, void *data) +{ + RM_RETURN_ERR_IF_NULL(cb, "invalid parameter"); + + if (rm_add_scaler_state_change_cb(cb, data) < 0) { + RM_ERR("already registered cb (%p)", cb); + return RM_ERROR; + } + + if (scaler_change_signal_id) + return RM_OK; + + GError *error = NULL; + GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!connection) { + RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); + return RM_ERROR; + } + + scaler_change_signal_id = g_dbus_connection_signal_subscribe(connection, + NULL, + RM_DBUS_INTERFACE_NAME, + "ScalerStateChanged", + RM_DBUS_OBJ_PATH, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + onScalerStateChanged, + NULL, + NULL); + + if (scaler_change_signal_id == 0) { + if (error) { + RM_ERR("dbus connection close error: %s", error->message); + g_clear_error(&error); + } + return RM_ERROR; + } + + RM_INFO("subscribe resource state changed (%d)", scaler_change_signal_id); + return RM_OK; +} + +int rm_unsubscribe_scaler_state_change(scaler_state_change_cb cb) +{ + RM_RETURN_ERR_IF_NULL(cb, "invalid parameter"); + + int remain = 0; + if ((remain = rm_remove_scaler_state_change_cb(cb)) < 0) { + RM_ERR("not registered cb (%p)", cb); + return RM_ERROR; + } + + if (remain > 0) { + RM_INFO("scaler state change cb(%p) removed", cb); + return RM_OK; + } + + GError *error = NULL; + GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!connection) { + RM_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); + return RM_OK; + } + + RM_INFO("remove scaler change signal id(%d)", scaler_change_signal_id); + g_dbus_connection_signal_unsubscribe(connection, scaler_change_signal_id); + scaler_change_signal_id = 0; + + return RM_OK; +} + +int rm_get_scaler_hw_id(int zone_id, int *id) +{ + if (zone_id <= 0) { + RM_ERR("invalid resource id (%d)", zone_id); + return RM_ERROR; + } + + if (rm_shm_find_scaler_hw_id(zone_id, id) == RM_OK) + return RM_OK; + + int ret = RM_OK; + int hw_id = 0; + GVariant *result = NULL; + + ret = rm_dbus_method_call("GetScalerHWID", + g_variant_new("(i)", zone_id), + &result); + + if (ret) { + RM_ERR("dbus_method_call() for GetScalerHWID is failed"); + return RM_ERROR; + } + + g_variant_get(result, "(i)", &hw_id); + + if (hw_id < 0) { + RM_ERR("can't get hw id(%d:%d)", zone_id, hw_id); + g_variant_unref(result); + return RM_ERROR; + } + + *id = hw_id; + RM_INFO("hw id (%d:%d)", zone_id, hw_id); + g_variant_unref(result); + return RM_OK; +} + +int rm_notify_resource_policy(int policy) +{ + if (policy < 0) { + RM_ERR("invalid policy (%d)", policy); + return RM_ERROR; + } + + int ret = rm_dbus_method_call_async_with_no_reply("NotifyResourcePolicy", + g_variant_new("(i)", policy)); + + if (ret) { + RM_ERR("dbus_method_call() for NotifyResourcePolicy is failed"); + return RM_ERROR; + } + + RM_INFO("notified (%d)", policy); + return ret; +} + +int rm_notify_app_zone_info_async(const char *app_id, int zone_id) +{ + if (!app_id || zone_id < -1) { + RM_ERR("invalid param (%d)", zone_id); + return RM_ERROR; + } + + if (rm_dbus_method_call_async_with_no_reply("NotifyAppZoneInfo", g_variant_new("(si)", app_id, zone_id)) != 0) { + RM_ERR("dbus_method_call() for NotifyAppZoneInfo is failed"); + return RM_ERROR; + } + + RM_INFO("notified (%s:%d)", app_id, zone_id); + return RM_OK; +} + +int rm_reclaim_resources(int handle) +{ + RM_INFO("reclaim resources of (%d)", handle); + + if (rm_dbus_method_call_async_with_no_reply("ReclaimResources", g_variant_new("(i)", handle)) != 0) { + RM_ERR("dbus call for ReclaimResources failed"); + return RM_ERROR; + } + + return RM_OK; +} + +int rm_reclaim_app_resources(const char *app_id, const bool notify) +{ + if (!app_id) { + RM_ERR("invalid app id"); + return RM_ERROR; + } + + RM_INFO("reclaim resources of (%s:%d)", app_id, notify); + + GVariant *response = NULL; + if (rm_dbus_method_call("ReclaimAppResources", g_variant_new("(si)", app_id, notify), &response) != 0) { + RM_ERR("dbus call for ReclaimAppResources failed"); + return RM_ERROR; + } + + int reclaim_result = 0; + g_variant_get(response, "(i)", &reclaim_result); + + int result = (reclaim_result < 0) ? RM_ERROR : RM_OK; + RM_INFO("reclaime result (%s : %d)", app_id, result); + + g_variant_unref(response); + return result; +} + +int rm_reclaim_app_resources_async(const char *app_id, const bool notify) +{ + if (!app_id) { + RM_ERR("invalid app id"); + return RM_ERROR; + } + + RM_INFO("reclaim resources of (%s : %d)", app_id, notify); + + if (rm_dbus_method_call_async_with_no_reply("ReclaimAppResources", g_variant_new("(si)", app_id, notify)) != 0) { + RM_ERR("dbus call for ReclaimAppResources failed"); + return RM_ERROR; + } + + return RM_OK; +} + +rm_resource_list_h rm_resource_list_create(void) +{ + rm_resource_list *list = (rm_resource_list*) calloc(1, sizeof(rm_resource_list)); + if (!list) { + RM_ERR("insufficient memory"); + return NULL; + } + + list->n_rsc = 0; + return list; +} + +int rm_resource_list_append(rm_resource_list_h list, const rm_resource_h resource) +{ + if (!list || !resource) { + RM_ERR("invalid param"); + return RM_ERROR; + } + + list->rsc_list = g_list_append(list->rsc_list, resource); + list->n_rsc = g_list_length(list->rsc_list); + list->iter = list->rsc_list; + return RM_OK; +} + +rm_resource_h rm_create_video_encoder(const unsigned int width, const unsigned int height, const unsigned int framerate) +{ + rm_resource *resource = (rm_resource*) calloc(1, sizeof(rm_resource)); + if (!resource) { + RM_ERR("insufficient memory"); + return NULL; + } + + resource->width = width; + resource->height = height; + resource->framerate = framerate; + return resource; +} + +int rm_allocatable_video_encoders(const rm_resource_list_h list, bool *result) +{ + if (!list) { + RM_ERR("invalid param"); + *result = false; + return RM_ERROR; + } + + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE("(a(uuu))")); + g_variant_builder_open(&builder, G_VARIANT_TYPE("a(uuu)")); + + rm_resource_h resource = rm_resource_list_get_first(list); + while (resource) { + RM_INFO("w(%u)/h(%u)/fps(%u)", rm_resource_get_width(resource), rm_resource_get_height(resource), rm_resource_get_framerate(resource)); + g_variant_builder_add(&builder, "(uuu)", rm_resource_get_width(resource), rm_resource_get_height(resource), rm_resource_get_framerate(resource)); + resource = rm_resource_list_get_next(list); + }; + + g_variant_builder_close(&builder); + + GVariant *response = NULL; + if (rm_dbus_method_call("AllocatableVideoEncoders", g_variant_builder_end(&builder), &response) != 0) { + *result = false; + RM_ERR("dbus_method_call() for AllocatableVideoEncoders failed"); + return RM_ERROR; + } + + int available = 0; + g_variant_get(response, "(i)", &available); + g_variant_unref(response); + RM_INFO("available (%d)", available); + *result = (available == 1); + return RM_OK; +} + +unsigned int rm_resource_get_width(const rm_resource_h resource) +{ + if (!resource) { + RM_ERR("invalid param"); + return 0; + } + return resource->width; +} + +unsigned int rm_resource_get_height(const rm_resource_h resource) +{ + if (!resource) { + RM_ERR("invalid param"); + return 0; + } + return resource->height; +} + +bool rm_resource_android_app(const rm_resource_h resource) +{ + if (!resource) + return false; + + return resource->android_app; +} + +int rm_reclaim_video_decoders(const char *requester) +{ + if (!requester) { + RM_ERR("invalid param"); + return RM_ERROR; + } + + RM_INFO("reclaim video decoders allocated to other than (%s)", requester); + + GVariant *response = NULL; + if (rm_dbus_method_call("ReclaimVideoDecoders", g_variant_new("(s)", requester), &response) != 0) { + RM_ERR("dbus call for ReclaimVideoDecoders failed"); + return RM_ERROR; + } + + int result = 0; + g_variant_get(response, "(i)", &result); + g_variant_unref(response); + + RM_INFO("result : (%d)", result); + return (result == 0) ? RM_OK : RM_ERROR; +} + +bool rm_active_player(const int handle) +{ + bool result = false; + if (rm_shm_active_player(handle, &result) == RM_OK) { + RM_INFO("(%d : %d)", handle, result); + return result; + } + + GVariant *response = NULL; + if (rm_dbus_method_call("ActivePlayer", g_variant_new("(i)", handle), &response) != 0) { + RM_ERR("dbus call for ActivePlayer (%d) failed", handle); + return false; + } + + g_variant_get(response, "(b)", &result); + + RM_INFO("(%d : %d)", handle, result); + return result; +} + +bool rm_reclaimed_player(const int handle) +{ + bool result = false; + + GVariant *response = NULL; + if (rm_dbus_method_call("ReclaimedPlayer", g_variant_new("(i)", handle), &response)!= 0) { + RM_ERR("dbus call for ReclaimedPlayer (%d) failed", handle); + return false; + } + + g_variant_get(response, "(b)", &result); + + RM_INFO("(%d : %d)", handle, result); + return result; +} + +// LCOV_EXCL_STOP diff --git a/src/rm_msg.cpp b/src/rm_msg.cpp index f1f6ae4..2175abb 100644 --- a/src/rm_msg.cpp +++ b/src/rm_msg.cpp @@ -1,211 +1,211 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#define RM_MSGQ_KEY_TX 8211 -#define RM_MSGQ_KEY_RX 8212 - -static int msgq_tx = -1; -static int msgq_rx = -1; - -static inline bool msgq_initialized(void) -{ - return ((msgq_tx >= 0) && (msgq_rx >= 0)); -} - -static int msgq_create(void) -{ - msgq_tx = msgget((key_t)RM_MSGQ_KEY_TX, 0666 | IPC_CREAT); - msgq_rx = msgget((key_t)RM_MSGQ_KEY_RX, 0666 | IPC_CREAT); - - if ((msgq_tx == -1) || (msgq_rx == -1)) { - RM_ERR("failed to get msgq_id - msgq_tx(%d), msgq_rx(%d)", msgq_tx, msgq_rx); - return RM_ERROR; - } - - RM_INFO("msgq_tx (%d), msgq_rx(%d)", msgq_tx, msgq_rx); - - return RM_OK; -} - -// LCOV_EXCL_START -static int msgq_recover_tx(void) -{ - msgq_tx = msgget((key_t)RM_MSGQ_KEY_TX, 0666 | IPC_CREAT); - - if (msgq_tx == -1) { - RM_ERR("failed to get new msgq_id - msgq_tx(%d), errno(%d)", msgq_tx, errno); - return RM_ERROR; - } - - RM_ERR("msgq recovered - msgq_tx(%d)", msgq_tx); - return RM_OK; -} - - -static int msgq_recover_rx(void) -{ - msgq_rx = msgget((key_t)RM_MSGQ_KEY_RX, 0666 | IPC_CREAT); - - if (msgq_rx == -1) { - RM_ERR("failed to get new msgq_id - msgq_rx(%d), errno(%d)", msgq_rx, errno); - return RM_ERROR; - } - - RM_ERR("msgq recovered - msgq_rx(%d)", msgq_rx); - return RM_OK; -} -// LCOV_EXCL_STOP - -int rm_send_msg(rm_msg_request *data) -{ - struct timespec tnow; - clock_gettime(CLOCK_MONOTONIC, &tnow); - - if (!msgq_initialized()) - msgq_create(); - - RM_INFO("msgq_tx %d msgq_rx %d", msgq_tx, msgq_rx); - - int retry = 0; - - RM_WARN("handle(%d) req.data_type : %ld, req #%d, req.type : %d, req.pid : %d", data->handle, data->data_type, data->request_num, data->type, data->pid); - - while (msgsnd(msgq_tx,(void*) data, sizeof(rm_msg_request) - sizeof(long), 0) == -1) { - // LCOV_EXCL_START - RM_ERR("failed to send message (%d)", errno); - - if (errno == EIDRM) { - RM_ERR("ERROR! msgid removed from system"); - if (msgq_recover_tx() != RM_OK) - return RM_ERROR; - } else if ((errno == EINVAL) && (data->data_type > 0)) { /* maybe msgid removed from system */ - RM_ERR("ERROR! invalid argument error. maybe msgid removed from system"); - if (msgq_recover_tx() != RM_OK) - return RM_ERROR; - } - - if (retry >= 5) { - RM_ERR("ERROR! timeout"); - return RM_ERROR; - } - - usleep(20 * 1000); /* 20ms */ - retry++; - // LCOV_EXCL_STOP - } - - return RM_OK; -} - -int rm_receive_msg(rm_msg_response *response, int msg_type) -{ - int retry = 0; - struct timespec tnow; - clock_gettime(CLOCK_MONOTONIC, &tnow); - - if (!msgq_initialized()) - msgq_create(); - - while (msgrcv(msgq_rx, (void*) response, sizeof(rm_msg_response) - sizeof(long), msg_type, 0) == -1) { - // LCOV_EXCL_START - RM_ERR("Failed to get message, errno(%d)", errno); - - if (errno == EIDRM) { - RM_ERR("WARNING! msgid removed from system"); - msgq_recover_rx(); - return RM_ERROR; - } else if (errno == EINVAL) { /* maybe msgid removed from system */ - RM_ERR("ERROR! invalid argument error. maybe msgid removed from system"); - if (msgq_recover_rx() != RM_OK) - return RM_ERROR; - - if (retry >= 5) { - RM_ERR("ERROR! timeout"); - return RM_ERROR; - } - - usleep(20 * 1000); /* 20ms */ - retry++; - } else if (errno == EINTR) { - RM_ERR("WARNING! System Call Inturrupted"); - continue; - } else { - RM_ERR("Error(errno:%d) is occured!!", errno); - return RM_ERROR; - } - // LCOV_EXCL_STOP - } - - return RM_OK; -} - -static int get_msg_uid(void) -{ - static int msg_id = 1; - const int msg_id_max = 65535; // (2^16 - 1) - - return (++msg_id > msg_id_max) ? 1 : msg_id; -} - -long get_data_type(int handle, int msg_type) -{ - long data_type = 0L; - int msg_uid = get_msg_uid(); - - data_type = ((static_cast(handle)) << 22); - data_type |= ((static_cast(msg_type)) << 16); - data_type |= msg_uid; - data_type = (data_type < 0) ? labs(data_type) : data_type; /* message type must be > 0, refer to description of struct msgbuf */ - - RM_INFO("data_type : (%ld), msg_uid : (%d), handle : (%d), msg_type : (%d)", data_type, msg_uid, handle, msg_type); - - return data_type; -} - -unsigned long long get_uptime(void) -{ - struct timespec t; - clock_gettime(CLOCK_MONOTONIC, &t); - return t.tv_sec; -} - -void rm_construct_request_msg(rm_msg_request *request, int msg_type, int handle) -{ - if (!request) { - RM_ERR("request is NULL"); - return; - } - - request->data_type = (msg_type == RM_REQUEST_REGISTER) ? (RM_REQUEST_DATA_TYPE_REGISTER | getpid()) : get_data_type(handle, msg_type); - request->type = msg_type; - request->handle = handle; - request->pid = getpid(); - request->time = get_uptime(); - - RM_INFO("DONE"); -} +/* + * 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define RM_MSGQ_KEY_TX 8211 +#define RM_MSGQ_KEY_RX 8212 + +static int msgq_tx = -1; +static int msgq_rx = -1; + +static inline bool msgq_initialized(void) +{ + return ((msgq_tx >= 0) && (msgq_rx >= 0)); +} + +static int msgq_create(void) +{ + msgq_tx = msgget((key_t)RM_MSGQ_KEY_TX, 0666 | IPC_CREAT); + msgq_rx = msgget((key_t)RM_MSGQ_KEY_RX, 0666 | IPC_CREAT); + + if ((msgq_tx == -1) || (msgq_rx == -1)) { + RM_ERR("failed to get msgq_id - msgq_tx(%d), msgq_rx(%d)", msgq_tx, msgq_rx); + return RM_ERROR; + } + + RM_INFO("msgq_tx (%d), msgq_rx(%d)", msgq_tx, msgq_rx); + + return RM_OK; +} + +// LCOV_EXCL_START +static int msgq_recover_tx(void) +{ + msgq_tx = msgget((key_t)RM_MSGQ_KEY_TX, 0666 | IPC_CREAT); + + if (msgq_tx == -1) { + RM_ERR("failed to get new msgq_id - msgq_tx(%d), errno(%d)", msgq_tx, errno); + return RM_ERROR; + } + + RM_ERR("msgq recovered - msgq_tx(%d)", msgq_tx); + return RM_OK; +} + + +static int msgq_recover_rx(void) +{ + msgq_rx = msgget((key_t)RM_MSGQ_KEY_RX, 0666 | IPC_CREAT); + + if (msgq_rx == -1) { + RM_ERR("failed to get new msgq_id - msgq_rx(%d), errno(%d)", msgq_rx, errno); + return RM_ERROR; + } + + RM_ERR("msgq recovered - msgq_rx(%d)", msgq_rx); + return RM_OK; +} +// LCOV_EXCL_STOP + +int rm_send_msg(rm_msg_request *data) +{ + struct timespec tnow; + clock_gettime(CLOCK_MONOTONIC, &tnow); + + if (!msgq_initialized()) + msgq_create(); + + RM_INFO("msgq_tx %d msgq_rx %d", msgq_tx, msgq_rx); + + int retry = 0; + + RM_WARN("handle(%d) req.data_type : %ld, req #%d, req.type : %d, req.pid : %d", data->handle, data->data_type, data->request_num, data->type, data->pid); + + while (msgsnd(msgq_tx,(void*) data, sizeof(rm_msg_request) - sizeof(long), 0) == -1) { + // LCOV_EXCL_START + RM_ERR("failed to send message (%d)", errno); + + if (errno == EIDRM) { + RM_ERR("ERROR! msgid removed from system"); + if (msgq_recover_tx() != RM_OK) + return RM_ERROR; + } else if ((errno == EINVAL) && (data->data_type > 0)) { /* maybe msgid removed from system */ + RM_ERR("ERROR! invalid argument error. maybe msgid removed from system"); + if (msgq_recover_tx() != RM_OK) + return RM_ERROR; + } + + if (retry >= 5) { + RM_ERR("ERROR! timeout"); + return RM_ERROR; + } + + usleep(20 * 1000); /* 20ms */ + retry++; + // LCOV_EXCL_STOP + } + + return RM_OK; +} + +int rm_receive_msg(rm_msg_response *response, int msg_type) +{ + int retry = 0; + struct timespec tnow; + clock_gettime(CLOCK_MONOTONIC, &tnow); + + if (!msgq_initialized()) + msgq_create(); + + while (msgrcv(msgq_rx, (void*) response, sizeof(rm_msg_response) - sizeof(long), msg_type, 0) == -1) { + // LCOV_EXCL_START + RM_ERR("Failed to get message, errno(%d)", errno); + + if (errno == EIDRM) { + RM_ERR("WARNING! msgid removed from system"); + msgq_recover_rx(); + return RM_ERROR; + } else if (errno == EINVAL) { /* maybe msgid removed from system */ + RM_ERR("ERROR! invalid argument error. maybe msgid removed from system"); + if (msgq_recover_rx() != RM_OK) + return RM_ERROR; + + if (retry >= 5) { + RM_ERR("ERROR! timeout"); + return RM_ERROR; + } + + usleep(20 * 1000); /* 20ms */ + retry++; + } else if (errno == EINTR) { + RM_ERR("WARNING! System Call Inturrupted"); + continue; + } else { + RM_ERR("Error(errno:%d) is occured!!", errno); + return RM_ERROR; + } + // LCOV_EXCL_STOP + } + + return RM_OK; +} + +static int get_msg_uid(void) +{ + static int msg_id = 1; + const int msg_id_max = 65535; // (2^16 - 1) + + return (++msg_id > msg_id_max) ? 1 : msg_id; +} + +long get_data_type(int handle, int msg_type) +{ + long data_type = 0L; + int msg_uid = get_msg_uid(); + + data_type = ((static_cast(handle)) << 22); + data_type |= ((static_cast(msg_type)) << 16); + data_type |= msg_uid; + data_type = (data_type < 0) ? labs(data_type) : data_type; /* message type must be > 0, refer to description of struct msgbuf */ + + RM_INFO("data_type : (%ld), msg_uid : (%d), handle : (%d), msg_type : (%d)", data_type, msg_uid, handle, msg_type); + + return data_type; +} + +unsigned long long get_uptime(void) +{ + struct timespec t; + clock_gettime(CLOCK_MONOTONIC, &t); + return t.tv_sec; +} + +void rm_construct_request_msg(rm_msg_request *request, int msg_type, int handle) +{ + if (!request) { + RM_ERR("request is NULL"); + return; + } + + request->data_type = (msg_type == RM_REQUEST_REGISTER) ? (RM_REQUEST_DATA_TYPE_REGISTER | getpid()) : get_data_type(handle, msg_type); + request->type = msg_type; + request->handle = handle; + request->pid = getpid(); + request->time = get_uptime(); + + RM_INFO("DONE"); +} diff --git a/ut/testcase/TCCallbackListener.cpp b/ut/testcase/TCCallbackListener.cpp index 713b85a..81a6703 100644 --- a/ut/testcase/TCCallbackListener.cpp +++ b/ut/testcase/TCCallbackListener.cpp @@ -1,76 +1,76 @@ -/* - * 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 -#include - -#include -#include - -void TCCallbackListener::ScalerStateChangeCb(rm_resource_list_h scalers, void *data) -{ - TCCallbackListener *listener = (TCCallbackListener*) data; - assert(listener); - - listener->RemoveAllScalers(); - listener->IncreaseNotificationNum(); - - int n_allocated_scalers = rm_resource_list_get_count(scalers); - RM_TEST_MSG("n_allocated_scalers(%d)", n_allocated_scalers); - if (n_allocated_scalers == 0) - return; - - rm_resource_h scaler = rm_resource_list_get_first(scalers); - while (scaler) { - RM_TEST_MSG("scaler(%d:%d)", rm_scaler_get_virtual_id(scaler), rm_scaler_get_source_id(scaler)); - listener->AddScaler(rm_scaler_get_virtual_id(scaler), rm_scaler_get_source_id(scaler)); - scaler = rm_resource_list_get_next(scalers); - } -} - -TCCallbackListener::TCCallbackListener() -{ - m_n_notification = 0; -} - -TCCallbackListener::~TCCallbackListener() -{ - UnregisterScalerStateChangeCb(); -} - -void TCCallbackListener::AddScaler(int vid, int src_id) -{ - m_scalers.insert(std::pair(vid, src_id)); -} - -bool TCCallbackListener::IsIncluded(int vid, int src_id) -{ - auto it = m_scalers.find(vid); - if (it == m_scalers.end()) - return false; - - return (it->second == src_id) ? true:false; -} - -int TCCallbackListener::RegisterScalerStateChangeCb(void) -{ - return rm_subscribe_scaler_state_change(TCCallbackListener::ScalerStateChangeCb, this); -} - -int TCCallbackListener::UnregisterScalerStateChangeCb(void) -{ - return rm_unsubscribe_scaler_state_change(TCCallbackListener::ScalerStateChangeCb); -} +/* + * 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 +#include + +#include +#include + +void TCCallbackListener::ScalerStateChangeCb(rm_resource_list_h scalers, void *data) +{ + TCCallbackListener *listener = (TCCallbackListener*) data; + assert(listener); + + listener->RemoveAllScalers(); + listener->IncreaseNotificationNum(); + + int n_allocated_scalers = rm_resource_list_get_count(scalers); + RM_TEST_MSG("n_allocated_scalers(%d)", n_allocated_scalers); + if (n_allocated_scalers == 0) + return; + + rm_resource_h scaler = rm_resource_list_get_first(scalers); + while (scaler) { + RM_TEST_MSG("scaler(%d:%d)", rm_scaler_get_virtual_id(scaler), rm_scaler_get_source_id(scaler)); + listener->AddScaler(rm_scaler_get_virtual_id(scaler), rm_scaler_get_source_id(scaler)); + scaler = rm_resource_list_get_next(scalers); + } +} + +TCCallbackListener::TCCallbackListener() +{ + m_n_notification = 0; +} + +TCCallbackListener::~TCCallbackListener() +{ + UnregisterScalerStateChangeCb(); +} + +void TCCallbackListener::AddScaler(int vid, int src_id) +{ + m_scalers.insert(std::pair(vid, src_id)); +} + +bool TCCallbackListener::IsIncluded(int vid, int src_id) +{ + auto it = m_scalers.find(vid); + if (it == m_scalers.end()) + return false; + + return (it->second == src_id) ? true:false; +} + +int TCCallbackListener::RegisterScalerStateChangeCb(void) +{ + return rm_subscribe_scaler_state_change(TCCallbackListener::ScalerStateChangeCb, this); +} + +int TCCallbackListener::UnregisterScalerStateChangeCb(void) +{ + return rm_unsubscribe_scaler_state_change(TCCallbackListener::ScalerStateChangeCb); +} diff --git a/ut/testcase/TCCallbackListener.h b/ut/testcase/TCCallbackListener.h index b1c1ce5..37abd41 100644 --- a/ut/testcase/TCCallbackListener.h +++ b/ut/testcase/TCCallbackListener.h @@ -1,45 +1,45 @@ -/* - * 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 __TC_CALLBACK_LISTENER_H__ -#define __TC_CALLBACK_LISTENER_H__ - -#include -#include - -class TCCallbackListener -{ -public: - TCCallbackListener(); - ~TCCallbackListener(); - - static void ScalerStateChangeCb(rm_resource_list_h scalers, void *data); - - int RegisterScalerStateChangeCb(void); - int UnregisterScalerStateChangeCb(void); - void RemoveAllScalers(void) { m_scalers.clear(); } - void AddScaler(int vid, int src_id); - bool IsIncluded(int vid, int src_id); - int GetNotificationNum(void) { return m_n_notification; } - void ResetNotificationNum(void) { m_n_notification = 0; } - void IncreaseNotificationNum(void) { m_n_notification++; } - -private: - std::map m_scalers; - int m_n_notification; -}; - -#endif //__TC_CALLBACK_LISTENER_H__ \ No newline at end of file +/* + * 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 __TC_CALLBACK_LISTENER_H__ +#define __TC_CALLBACK_LISTENER_H__ + +#include +#include + +class TCCallbackListener +{ +public: + TCCallbackListener(); + ~TCCallbackListener(); + + static void ScalerStateChangeCb(rm_resource_list_h scalers, void *data); + + int RegisterScalerStateChangeCb(void); + int UnregisterScalerStateChangeCb(void); + void RemoveAllScalers(void) { m_scalers.clear(); } + void AddScaler(int vid, int src_id); + bool IsIncluded(int vid, int src_id); + int GetNotificationNum(void) { return m_n_notification; } + void ResetNotificationNum(void) { m_n_notification = 0; } + void IncreaseNotificationNum(void) { m_n_notification++; } + +private: + std::map m_scalers; + int m_n_notification; +}; + +#endif //__TC_CALLBACK_LISTENER_H__ diff --git a/ut/testcase/TCPlayer.cpp b/ut/testcase/TCPlayer.cpp index 8408b30..e7c9788 100644 --- a/ut/testcase/TCPlayer.cpp +++ b/ut/testcase/TCPlayer.cpp @@ -1,316 +1,316 @@ -/* - * 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" -#include -#include -#include -#include -#include -#include "TCResource.h" -#include "TCPlayer.h" - -TCPlayer::TCPlayer() -{ - m_handle = 0; - m_allocated_rsc_index = 0; - m_rsc_index = 0; - m_query_index = 0; - m_n_conflict = 0; - m_n_conflicted_rsc = 0; -} - -TCPlayer::~TCPlayer() -{ - Unregister(); -} - -rm_cb_result TCPlayer::ConflictCb(int handle, rm_callback_type event, rm_device_request_s *info, void *data) -{ - if (!data) - return RM_CB_RESULT_ERROR; - - TCPlayer *player = (TCPlayer*) data; - player->IncreaseConflictNum(); - player->SetConflictedResourcesNum(info->request_num); - - for (int j = 0; j < info->request_num; j++) { - player->AddConflictedResource(j+1, info->device_id[j]); - } - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); - return RM_CB_RESULT_OK; -} - -int TCPlayer::Register(void) -{ - if (m_handle != 0) - return RM_ERROR; - - return rm_register(TCPlayer::ConflictCb, this, &m_handle, NULL); -} - -int TCPlayer::Unregister(void) -{ - int result = RM_ERROR;; - - RemoveResources(); - RemoveQueries(); - m_allocated_resources.clear(); - - result = rm_unregister(m_handle); - m_handle = 0; - - return result; -} - -int TCPlayer::SetPriority(int priority) -{ - return rm_set_priority(m_handle, priority); -} - -int TCPlayer::SetAppId(std::string app_id) -{ - return rm_set_app_id(m_handle, (char*) app_id.c_str()); -} - -int TCPlayer::AddResource(int category_id, int state) -{ - TCResource *rsc = new TCResource(category_id, 0, state); - m_rsc_index++; - m_requested_resources.insert(std::pair(m_rsc_index, rsc)); - return 0; -} - -int TCPlayer::AddResource(int category_id, int category_option, int state) -{ - TCResource *rsc = new TCResource(category_id, category_option, state); - m_rsc_index++; - m_requested_resources.insert(std::pair(m_rsc_index, rsc)); - return 0; -} - -int TCPlayer::AddQuery(int category_id, int category_option, int state) -{ - TCResource *rsc = new TCResource(category_id, category_option, state); - m_query_index++; - m_queries.insert(std::pair(m_query_index, rsc)); - return 0; -} - -void TCPlayer::RemoveResources(void) -{ - TCResource *rsc = nullptr; - - for (auto &it : m_requested_resources) { - rsc = it.second; - if (rsc) - delete rsc; - } - m_requested_resources.clear(); -} - -int TCPlayer::GetAudioCategory(std::string codec_name, int mixing_mode) -{ - ri_audio_category_option_request_s audio_option; - memset(&audio_option, 0, sizeof(ri_audio_category_option_request_s)); - - audio_option.codec_name = codec_name.c_str(); - audio_option.mixing_mode = (ri_audio_mixing_mode) mixing_mode; - - return ri_get_capable_audio_category_id(&audio_option); -} - -int TCPlayer::GetCapableVideoCategory(std::string codec_name, int h_size, int v_size, int color_depth, int sampling_format, int framerate) -{ - ri_video_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_video_category_option_request_s)); - - opt.codec_name = strndup(codec_name.c_str(), codec_name.length()); - opt.color_depth = color_depth; - opt.framerate = framerate; - opt.h_size = h_size; - opt.v_size = v_size; - opt.sampling_format = sampling_format; - - int result = ri_get_capable_video_category_id(&opt); - - free((void*) opt.codec_name); - return result; -} - -int TCPlayer::GetCapableImageCategory(std::string codec_name, int w_size, int h_size) -{ - char *codec = strndup(codec_name.c_str(), codec_name.length()); - int result = ri_get_image_category_id(codec, w_size, h_size); - free(codec); - return result; -} - -int TCPlayer::GetCapableNDecoderCategory(std::string codec_name, int h_size, int v_size, int color_depth, int sampling_format, int framerate) -{ - ri_video_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_video_category_option_request_s)); - - opt.codec_name = strndup(codec_name.c_str(), codec_name.length()); - opt.color_depth = color_depth; - opt.framerate = framerate; - opt.h_size = h_size; - opt.v_size = v_size; - opt.sampling_format = sampling_format; - - return ri_get_n_decoder_category_id(&opt); -} - -int TCPlayer::Query(int query_type, int *ans) -{ - rm_category_request_s req; - memset(&req, 0, sizeof(rm_category_request_s)); - - int i = 0; - int result = RM_ERROR; - int answer; - - req.request_num = m_queries.size(); - - for (auto &it : m_queries) { - TCResource *rsc = it.second; - req.category_id[i] = (rm_rsc_category_e) rsc->GetCategoryId(); - req.category_option[i] = rsc->GetCategoryOption(); - req.state[i] = (rm_requests_resource_state_e) rsc->GetState(); - i++; - } - - result = rm_query(m_handle, (rm_query_type_e) query_type, &req, &answer); - *ans = answer; - - return result; -} - -void TCPlayer::RemoveQueries(void) -{ - TCResource *rsc = nullptr; - - for (auto &it : m_queries) { - rsc = it.second; - if (rsc) - delete rsc; - } - m_queries.clear(); -} - -void TCPlayer::AddAllocatedResource(int device_id) -{ - m_allocated_resources.insert(std::pair(++m_allocated_rsc_index, device_id)); -} - -int TCPlayer::GetAllocatedResourceId(int index) -{ - auto it = m_allocated_resources.find(index); - - return (it == m_allocated_resources.end()) ? -1 : it->second; -} - -int TCPlayer::AllocateResources(void) -{ - if (m_requested_resources.size() == 0) - return RM_ERROR; - - int i = 0; - int result = RM_ERROR; - - rm_category_request_s req; - memset(&req, 0, sizeof(rm_category_request_s)); - - req.request_num = m_requested_resources.size(); - - for (auto &it : m_requested_resources) { - TCResource *rsc = it.second; - req.category_id[i] = (rm_rsc_category_e) rsc->GetCategoryId(); - req.category_option[i] = rsc->GetCategoryOption(); - req.state[i] = (rm_requests_resource_state_e) rsc->GetState(); - i++; - } - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(allocated)); - - result = rm_allocate_resources(m_handle, &req, &allocated); - - if (result == RM_OK) { - for (int j = 0; j < allocated.allocated_num; j++) - AddAllocatedResource(allocated.device_id[j]); - } - - return result; -} - -int TCPlayer::ReleaseResources(void) -{ - if (m_allocated_resources.size() <= 0) - return RM_ERROR; - - int i = 0; - rm_device_request_s req; - memset(&req, 0, sizeof(req)); - - req.request_num = m_allocated_resources.size(); - - for (auto &it : m_allocated_resources) { - req.device_id[i] = it.second; - i++; - } - - m_allocated_resources.clear(); - - return rm_deallocate_resources(m_handle, &req); -} - -int TCPlayer::ReleaseResource(int index) -{ - if (m_allocated_resources.size() <= 0) - return RM_ERROR; - - auto it = m_allocated_resources.find(index); - int device_id = (it == m_allocated_resources.end()) ? -1 : it->second; - - rm_device_request_s req; - memset(&req, 0, sizeof(req)); - - req.request_num = 1; - req.device_id[0] = device_id; - - m_allocated_resources.erase(index); - - return rm_deallocate_resources(m_handle, &req); -} - -int TCPlayer::GetActiveAudioOut(void) -{ - return rm_get_active_audio_out(m_handle); -} - -int TCPlayer::GetConflictedResourceId(int index) -{ - auto it = m_conflicted_resources.find(index); - - return (it == m_conflicted_resources.end()) ? -1 : it->second; -} - -void TCPlayer::AddConflictedResource(int index, int device_id) -{ - m_conflicted_resources.insert(std::pair(index, device_id)); -} +/* + * 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" +#include +#include +#include +#include +#include +#include "TCResource.h" +#include "TCPlayer.h" + +TCPlayer::TCPlayer() +{ + m_handle = 0; + m_allocated_rsc_index = 0; + m_rsc_index = 0; + m_query_index = 0; + m_n_conflict = 0; + m_n_conflicted_rsc = 0; +} + +TCPlayer::~TCPlayer() +{ + Unregister(); +} + +rm_cb_result TCPlayer::ConflictCb(int handle, rm_callback_type event, rm_device_request_s *info, void *data) +{ + if (!data) + return RM_CB_RESULT_ERROR; + + TCPlayer *player = (TCPlayer*) data; + player->IncreaseConflictNum(); + player->SetConflictedResourcesNum(info->request_num); + + for (int j = 0; j < info->request_num; j++) { + player->AddConflictedResource(j+1, info->device_id[j]); + } + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); + return RM_CB_RESULT_OK; +} + +int TCPlayer::Register(void) +{ + if (m_handle != 0) + return RM_ERROR; + + return rm_register(TCPlayer::ConflictCb, this, &m_handle, NULL); +} + +int TCPlayer::Unregister(void) +{ + int result = RM_ERROR;; + + RemoveResources(); + RemoveQueries(); + m_allocated_resources.clear(); + + result = rm_unregister(m_handle); + m_handle = 0; + + return result; +} + +int TCPlayer::SetPriority(int priority) +{ + return rm_set_priority(m_handle, priority); +} + +int TCPlayer::SetAppId(std::string app_id) +{ + return rm_set_app_id(m_handle, (char*) app_id.c_str()); +} + +int TCPlayer::AddResource(int category_id, int state) +{ + TCResource *rsc = new TCResource(category_id, 0, state); + m_rsc_index++; + m_requested_resources.insert(std::pair(m_rsc_index, rsc)); + return 0; +} + +int TCPlayer::AddResource(int category_id, int category_option, int state) +{ + TCResource *rsc = new TCResource(category_id, category_option, state); + m_rsc_index++; + m_requested_resources.insert(std::pair(m_rsc_index, rsc)); + return 0; +} + +int TCPlayer::AddQuery(int category_id, int category_option, int state) +{ + TCResource *rsc = new TCResource(category_id, category_option, state); + m_query_index++; + m_queries.insert(std::pair(m_query_index, rsc)); + return 0; +} + +void TCPlayer::RemoveResources(void) +{ + TCResource *rsc = nullptr; + + for (auto &it : m_requested_resources) { + rsc = it.second; + if (rsc) + delete rsc; + } + m_requested_resources.clear(); +} + +int TCPlayer::GetAudioCategory(std::string codec_name, int mixing_mode) +{ + ri_audio_category_option_request_s audio_option; + memset(&audio_option, 0, sizeof(ri_audio_category_option_request_s)); + + audio_option.codec_name = codec_name.c_str(); + audio_option.mixing_mode = (ri_audio_mixing_mode) mixing_mode; + + return ri_get_capable_audio_category_id(&audio_option); +} + +int TCPlayer::GetCapableVideoCategory(std::string codec_name, int h_size, int v_size, int color_depth, int sampling_format, int framerate) +{ + ri_video_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_video_category_option_request_s)); + + opt.codec_name = strndup(codec_name.c_str(), codec_name.length()); + opt.color_depth = color_depth; + opt.framerate = framerate; + opt.h_size = h_size; + opt.v_size = v_size; + opt.sampling_format = sampling_format; + + int result = ri_get_capable_video_category_id(&opt); + + free((void*) opt.codec_name); + return result; +} + +int TCPlayer::GetCapableImageCategory(std::string codec_name, int w_size, int h_size) +{ + char *codec = strndup(codec_name.c_str(), codec_name.length()); + int result = ri_get_image_category_id(codec, w_size, h_size); + free(codec); + return result; +} + +int TCPlayer::GetCapableNDecoderCategory(std::string codec_name, int h_size, int v_size, int color_depth, int sampling_format, int framerate) +{ + ri_video_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_video_category_option_request_s)); + + opt.codec_name = strndup(codec_name.c_str(), codec_name.length()); + opt.color_depth = color_depth; + opt.framerate = framerate; + opt.h_size = h_size; + opt.v_size = v_size; + opt.sampling_format = sampling_format; + + return ri_get_n_decoder_category_id(&opt); +} + +int TCPlayer::Query(int query_type, int *ans) +{ + rm_category_request_s req; + memset(&req, 0, sizeof(rm_category_request_s)); + + int i = 0; + int result = RM_ERROR; + int answer; + + req.request_num = m_queries.size(); + + for (auto &it : m_queries) { + TCResource *rsc = it.second; + req.category_id[i] = (rm_rsc_category_e) rsc->GetCategoryId(); + req.category_option[i] = rsc->GetCategoryOption(); + req.state[i] = (rm_requests_resource_state_e) rsc->GetState(); + i++; + } + + result = rm_query(m_handle, (rm_query_type_e) query_type, &req, &answer); + *ans = answer; + + return result; +} + +void TCPlayer::RemoveQueries(void) +{ + TCResource *rsc = nullptr; + + for (auto &it : m_queries) { + rsc = it.second; + if (rsc) + delete rsc; + } + m_queries.clear(); +} + +void TCPlayer::AddAllocatedResource(int device_id) +{ + m_allocated_resources.insert(std::pair(++m_allocated_rsc_index, device_id)); +} + +int TCPlayer::GetAllocatedResourceId(int index) +{ + auto it = m_allocated_resources.find(index); + + return (it == m_allocated_resources.end()) ? -1 : it->second; +} + +int TCPlayer::AllocateResources(void) +{ + if (m_requested_resources.size() == 0) + return RM_ERROR; + + int i = 0; + int result = RM_ERROR; + + rm_category_request_s req; + memset(&req, 0, sizeof(rm_category_request_s)); + + req.request_num = m_requested_resources.size(); + + for (auto &it : m_requested_resources) { + TCResource *rsc = it.second; + req.category_id[i] = (rm_rsc_category_e) rsc->GetCategoryId(); + req.category_option[i] = rsc->GetCategoryOption(); + req.state[i] = (rm_requests_resource_state_e) rsc->GetState(); + i++; + } + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(allocated)); + + result = rm_allocate_resources(m_handle, &req, &allocated); + + if (result == RM_OK) { + for (int j = 0; j < allocated.allocated_num; j++) + AddAllocatedResource(allocated.device_id[j]); + } + + return result; +} + +int TCPlayer::ReleaseResources(void) +{ + if (m_allocated_resources.size() <= 0) + return RM_ERROR; + + int i = 0; + rm_device_request_s req; + memset(&req, 0, sizeof(req)); + + req.request_num = m_allocated_resources.size(); + + for (auto &it : m_allocated_resources) { + req.device_id[i] = it.second; + i++; + } + + m_allocated_resources.clear(); + + return rm_deallocate_resources(m_handle, &req); +} + +int TCPlayer::ReleaseResource(int index) +{ + if (m_allocated_resources.size() <= 0) + return RM_ERROR; + + auto it = m_allocated_resources.find(index); + int device_id = (it == m_allocated_resources.end()) ? -1 : it->second; + + rm_device_request_s req; + memset(&req, 0, sizeof(req)); + + req.request_num = 1; + req.device_id[0] = device_id; + + m_allocated_resources.erase(index); + + return rm_deallocate_resources(m_handle, &req); +} + +int TCPlayer::GetActiveAudioOut(void) +{ + return rm_get_active_audio_out(m_handle); +} + +int TCPlayer::GetConflictedResourceId(int index) +{ + auto it = m_conflicted_resources.find(index); + + return (it == m_conflicted_resources.end()) ? -1 : it->second; +} + +void TCPlayer::AddConflictedResource(int index, int device_id) +{ + m_conflicted_resources.insert(std::pair(index, device_id)); +} diff --git a/ut/testcase/TCPlayer.h b/ut/testcase/TCPlayer.h index 3910ed1..1cc1dfa 100644 --- a/ut/testcase/TCPlayer.h +++ b/ut/testcase/TCPlayer.h @@ -1,82 +1,82 @@ -/* - * 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 __TC_PLAYER_H__ -#define __TC_PLAYER_H__ - -#include -#include -#include - -class TCResource; -class TCPlayer -{ -public: - TCPlayer(); - TCPlayer(std::string app_id) { m_app_id = app_id; } - ~TCPlayer(); - - static rm_cb_result ConflictCb(int handle, rm_callback_type event, rm_device_request_s *info, void *data); - int Register(void); - int Unregister(void); - - int SetPriority(int priority); - int SetAppId(std::string app_id); - void SetCustomHandle(int handle) { m_handle = handle;} - - int AddResource(int category_id, int state); - int AddResource(int category_id, int category_option, int state); - void RemoveResources(void); - int GetAudioCategory(std::string codec_name, int mixing_mode); - int GetCapableVideoCategory(std::string codec_name, int h_size, int v_size, int color_depth, int sampling_format, int framerate); - int GetCapableNDecoderCategory(std::string codec_name, int h_size, int v_size, int color_depth, int sampling_format, int framerate); - int GetCapableImageCategory(std::string codec_name, int h_size, int v_size); - - int AddQuery(int category_id, int category_option, int state); - void RemoveQueries(void); - int Query(int query_type, int *ans); - - void AddAllocatedResource(int device_id); - int AllocateResources(void); - int ReleaseResources(void); - int ReleaseResource(int index); - int GetAllocatedResourceId(int index); - int GetAllocatedResourcesNum(void) { return m_allocated_resources.size(); } - - void IncreaseConflictNum(void) { m_n_conflict++; } - int GetConflictNum(void) { return m_n_conflict; } - void SetConflictedResourcesNum(int n) { m_n_conflicted_rsc = n; } - int GetConflictedResourcesNum(void) { return m_n_conflicted_rsc; } - int GetConflictedResourceId(int index); - void AddConflictedResource(int index, int device_id); - int GetActiveAudioOut(void); - -private: - std::map m_allocated_resources; - std::map m_conflicted_resources; - std::map m_requested_resources; - std::map m_queries; - - std::string m_app_id; - int m_handle; - int m_rsc_index; - int m_query_index; - int m_allocated_rsc_index; - int m_n_conflict; - int m_n_conflicted_rsc; -}; - -#endif //__TC_PLAYER_H__ +/* + * 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 __TC_PLAYER_H__ +#define __TC_PLAYER_H__ + +#include +#include +#include + +class TCResource; +class TCPlayer +{ +public: + TCPlayer(); + TCPlayer(std::string app_id) { m_app_id = app_id; } + ~TCPlayer(); + + static rm_cb_result ConflictCb(int handle, rm_callback_type event, rm_device_request_s *info, void *data); + int Register(void); + int Unregister(void); + + int SetPriority(int priority); + int SetAppId(std::string app_id); + void SetCustomHandle(int handle) { m_handle = handle;} + + int AddResource(int category_id, int state); + int AddResource(int category_id, int category_option, int state); + void RemoveResources(void); + int GetAudioCategory(std::string codec_name, int mixing_mode); + int GetCapableVideoCategory(std::string codec_name, int h_size, int v_size, int color_depth, int sampling_format, int framerate); + int GetCapableNDecoderCategory(std::string codec_name, int h_size, int v_size, int color_depth, int sampling_format, int framerate); + int GetCapableImageCategory(std::string codec_name, int h_size, int v_size); + + int AddQuery(int category_id, int category_option, int state); + void RemoveQueries(void); + int Query(int query_type, int *ans); + + void AddAllocatedResource(int device_id); + int AllocateResources(void); + int ReleaseResources(void); + int ReleaseResource(int index); + int GetAllocatedResourceId(int index); + int GetAllocatedResourcesNum(void) { return m_allocated_resources.size(); } + + void IncreaseConflictNum(void) { m_n_conflict++; } + int GetConflictNum(void) { return m_n_conflict; } + void SetConflictedResourcesNum(int n) { m_n_conflicted_rsc = n; } + int GetConflictedResourcesNum(void) { return m_n_conflicted_rsc; } + int GetConflictedResourceId(int index); + void AddConflictedResource(int index, int device_id); + int GetActiveAudioOut(void); + +private: + std::map m_allocated_resources; + std::map m_conflicted_resources; + std::map m_requested_resources; + std::map m_queries; + + std::string m_app_id; + int m_handle; + int m_rsc_index; + int m_query_index; + int m_allocated_rsc_index; + int m_n_conflict; + int m_n_conflicted_rsc; +}; + +#endif //__TC_PLAYER_H__ diff --git a/ut/testcase/TCResource.cpp b/ut/testcase/TCResource.cpp index c149966..fc61df0 100644 --- a/ut/testcase/TCResource.cpp +++ b/ut/testcase/TCResource.cpp @@ -1,28 +1,28 @@ -/* - * 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 "TCResource.h" - -TCResource::TCResource(int category_id, int category_option, int state) -{ - m_category_id = category_id; - m_category_option = category_option; - m_state = state; -} - -TCResource::~TCResource() -{ -} +/* + * 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 "TCResource.h" + +TCResource::TCResource(int category_id, int category_option, int state) +{ + m_category_id = category_id; + m_category_option = category_option; + m_state = state; +} + +TCResource::~TCResource() +{ +} diff --git a/ut/testcase/TCResource.h b/ut/testcase/TCResource.h index 545b5af..c3068b4 100644 --- a/ut/testcase/TCResource.h +++ b/ut/testcase/TCResource.h @@ -1,36 +1,36 @@ -/* - * 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 __TC_RESOURCE_H__ -#define __TC_RESOURCE_H__ - -class TCResource -{ -public: - TCResource(int category_id, int category_option, int state); - ~TCResource(); - - int GetCategoryId(void) {return m_category_id;} - int GetCategoryOption(void) {return m_category_option;} - int GetState(void) {return m_state;} - -private: - int m_category_id; - int m_category_option; - int m_state; -}; - -#endif //__TC_RESOURCE_H__ \ No newline at end of file +/* + * 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 __TC_RESOURCE_H__ +#define __TC_RESOURCE_H__ + +class TCResource +{ +public: + TCResource(int category_id, int category_option, int state); + ~TCResource(); + + int GetCategoryId(void) {return m_category_id;} + int GetCategoryOption(void) {return m_category_option;} + int GetState(void) {return m_state;} + +private: + int m_category_id; + int m_category_option; + int m_state; +}; + +#endif //__TC_RESOURCE_H__ diff --git a/ut/testcase/common.cpp b/ut/testcase/common.cpp index eaa331b..12b2223 100644 --- a/ut/testcase/common.cpp +++ b/ut/testcase/common.cpp @@ -1,294 +1,294 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved - * For conditions of distribution and use, see the accompanying LICENSE.Samsung file . - */ - -#include -#include -#include -#include -#include "gtest/gtest.h" -#include -#include - -bool read_rm_index(const char *filename, int *data) -{ - FILE *fp = NULL; - char str[10] = {0,}; - size_t str_size; - - if (!data) { - RM_TEST_MSG("invalid input : null data"); - return false; - } - - fp = fopen(filename, "rb"); - - if (!fp) { - RM_TEST_MSG("failed to open (%s) - errno(%d)", filename, errno); - return false; - } - - str_size = fread(str, sizeof(char), sizeof(str)-1, fp); - - str[str_size] = '\0'; - - if (str_size == 0) { - fclose(fp); - return false; - } - - *data = atoi(str); - - fclose(fp); - fp = NULL; - - return true; -} - -bool is_8k_model(void) -{ - return false; -} - -static int conflicted; -static int conflicted_cmp; -static int num_of_dealloc_rsc; - -rm_cb_result rm_cb_counting_conflicted(int handle, rm_callback_type event, rm_device_request_s *info, void *data) -{ - ++conflicted; - num_of_dealloc_rsc = info->request_num; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); - return RM_CB_RESULT_OK; -} - -rm_cb_result rm_cb_counting_conflicted_cmp(int handle, rm_callback_type event, rm_device_request_s *info, void *data) -{ - ++conflicted_cmp; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); - return RM_CB_RESULT_OK; -} - -rm_cb_result rm_cb_set_conflict_flag(int handle, rm_callback_type event, rm_device_request_s *info, void *data) -{ - conflicted = 1; - num_of_dealloc_rsc = info->request_num; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); - - return RM_CB_RESULT_OK; -} - -rm_cb_result rm_cb_for_conditional_check(int handle, rm_callback_type event, rm_device_request_s *info, void *data) -{ - rm_deallocate_resources(handle, info); - return RM_CB_RESULT_OK; -} - -int rm_tc_get_conflict_num(void) -{ - return conflicted; -} - -void rm_tc_reset_conflict_num(void) -{ - conflicted = 0; -} - -int rm_tc_get_conflict_num_cmp(void) -{ - return conflicted_cmp; -} - -void rm_tc_reset_conflict_num_cmp(void) -{ - conflicted_cmp = 0; -} - -int rm_tc_get_conflicted_resources_num(void) -{ - return num_of_dealloc_rsc; -} - -void rm_tc_reset_conflicted_resources_num(void) -{ - num_of_dealloc_rsc = 0; -} - -void rm_tc_clear_audio_decoders(void) -{ - RM_TEST_MSG("clear_audio_decoders..."); - - int handle1 = 0; - if (rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL) != RM_OK) { - RM_TEST_MSG("failed to register"); - return; - } - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 2; - request.category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request.category_option[0] = 0; - request.state[0] = RM_STATE_EXCLUSIVE; - request.category_id[1] = RM_CATEGORY_AUDIO_DECODER_SUB; - request.category_option[1] = 0; - request.state[1] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - if (rm_allocate_resources(handle1, &request, &allocated) != RM_OK) - RM_TEST_MSG("failed to clear audio decoders"); - - if (rm_unregister(handle1) != RM_OK) - RM_TEST_MSG("failed to unregister"); - - RM_TEST_MSG("clear_audio_decoders done..."); -} - -void rm_tc_clear_video_decoders(void) -{ - RM_TEST_MSG("clear_video_decoders..."); - - int handle1 = 0; - if (rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL) != RM_OK) { - RM_TEST_MSG("failed to register"); - return; - } - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = RM_CATEGORY_VIDEO_DECODER_MPEG4_FHD_8BIT_60P; - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - if (rm_allocate_resources(handle1, &request, &allocated) != RM_OK) - RM_TEST_MSG("failed to clear video decoders"); - - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = RM_CATEGORY_VIDEO_DECODER_H264_UHD_8BIT_60P; - request.state[0] = RM_STATE_EXCLUSIVE; - - memset(&allocated, 0, sizeof(rm_device_return_s)); - - if (rm_allocate_resources(handle1, &request, &allocated) != RM_OK) - RM_TEST_MSG("failed to clear video decoders"); - - if (rm_unregister(handle1) != RM_OK) - RM_TEST_MSG("failed to unregister"); - - RM_TEST_MSG("clear_video_decoders done..."); -} - -void rm_tc_template_exceptional_test_case(int vdec1, int vdec2) -{ - //consumer#1 - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); - - //alloc - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request->category_option[0] = vdec1 | RM_DEVICE_OPT_MAIN; - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - - //consumer#2 - int handle2 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); - - //alloc - rm_category_request_s *request2 = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request2, 0, sizeof(rm_category_request_s)); - - request2->request_num = 1; - request2->category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request2->category_option[0] = vdec2; - request2->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated2 = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated2, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request2, allocated2)); - - //unregister - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - - sleep(RM_TEST_SLEEP_TIME); - -} - -bool is_support_4k(void) -{ -#ifdef RM_TC_SUPPORT_4K - return true; -#else - return false; -#endif //RM_TC_SUPPORT_4K -} - -bool is_support_8k(void) -{ -#ifdef RM_TC_SUPPORT_8K - return true; -#else - return false; -#endif //RM_TC_SUPPORT_8K -} - -bool is_support_av1_120p(void) -{ -#ifdef RM_TC_SUPPORT_AV1_120P - return true; -#else - return false; -#endif //RM_TC_SUPPORT_AV1_120P -} - -bool use_unified_jpeg_decoder(void) -{ -#ifdef RM_TC_USE_UNIFIED_JPEG_DEC - return true; -#else - return false; -#endif// RM_TC_USE_UNIFIED_JPEG_DEC -} - -bool is_oscars_unified_jpeg_decoder(void) -{ -#ifdef RM_TC_USE_UNIFIED_JPEG_DEC_OSCARS - return true; -#else - return false; -#endif -} - -bool is_support_audio_dual_decoding(void) -{ -#ifdef RM_TC_SUPPORT_AUDIO_DUAL_DECODING - return true; -#else - return false; -#endif //RM_TC_SUPPORT_AUDIO_DUAL_DECODING -} +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * For conditions of distribution and use, see the accompanying LICENSE.Samsung file . + */ + +#include +#include +#include +#include +#include "gtest/gtest.h" +#include +#include + +bool read_rm_index(const char *filename, int *data) +{ + FILE *fp = NULL; + char str[10] = {0,}; + size_t str_size; + + if (!data) { + RM_TEST_MSG("invalid input : null data"); + return false; + } + + fp = fopen(filename, "rb"); + + if (!fp) { + RM_TEST_MSG("failed to open (%s) - errno(%d)", filename, errno); + return false; + } + + str_size = fread(str, sizeof(char), sizeof(str)-1, fp); + + str[str_size] = '\0'; + + if (str_size == 0) { + fclose(fp); + return false; + } + + *data = atoi(str); + + fclose(fp); + fp = NULL; + + return true; +} + +bool is_8k_model(void) +{ + return false; +} + +static int conflicted; +static int conflicted_cmp; +static int num_of_dealloc_rsc; + +rm_cb_result rm_cb_counting_conflicted(int handle, rm_callback_type event, rm_device_request_s *info, void *data) +{ + ++conflicted; + num_of_dealloc_rsc = info->request_num; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); + return RM_CB_RESULT_OK; +} + +rm_cb_result rm_cb_counting_conflicted_cmp(int handle, rm_callback_type event, rm_device_request_s *info, void *data) +{ + ++conflicted_cmp; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); + return RM_CB_RESULT_OK; +} + +rm_cb_result rm_cb_set_conflict_flag(int handle, rm_callback_type event, rm_device_request_s *info, void *data) +{ + conflicted = 1; + num_of_dealloc_rsc = info->request_num; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); + + return RM_CB_RESULT_OK; +} + +rm_cb_result rm_cb_for_conditional_check(int handle, rm_callback_type event, rm_device_request_s *info, void *data) +{ + rm_deallocate_resources(handle, info); + return RM_CB_RESULT_OK; +} + +int rm_tc_get_conflict_num(void) +{ + return conflicted; +} + +void rm_tc_reset_conflict_num(void) +{ + conflicted = 0; +} + +int rm_tc_get_conflict_num_cmp(void) +{ + return conflicted_cmp; +} + +void rm_tc_reset_conflict_num_cmp(void) +{ + conflicted_cmp = 0; +} + +int rm_tc_get_conflicted_resources_num(void) +{ + return num_of_dealloc_rsc; +} + +void rm_tc_reset_conflicted_resources_num(void) +{ + num_of_dealloc_rsc = 0; +} + +void rm_tc_clear_audio_decoders(void) +{ + RM_TEST_MSG("clear_audio_decoders..."); + + int handle1 = 0; + if (rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL) != RM_OK) { + RM_TEST_MSG("failed to register"); + return; + } + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 2; + request.category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request.category_option[0] = 0; + request.state[0] = RM_STATE_EXCLUSIVE; + request.category_id[1] = RM_CATEGORY_AUDIO_DECODER_SUB; + request.category_option[1] = 0; + request.state[1] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + if (rm_allocate_resources(handle1, &request, &allocated) != RM_OK) + RM_TEST_MSG("failed to clear audio decoders"); + + if (rm_unregister(handle1) != RM_OK) + RM_TEST_MSG("failed to unregister"); + + RM_TEST_MSG("clear_audio_decoders done..."); +} + +void rm_tc_clear_video_decoders(void) +{ + RM_TEST_MSG("clear_video_decoders..."); + + int handle1 = 0; + if (rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL) != RM_OK) { + RM_TEST_MSG("failed to register"); + return; + } + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = RM_CATEGORY_VIDEO_DECODER_MPEG4_FHD_8BIT_60P; + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + if (rm_allocate_resources(handle1, &request, &allocated) != RM_OK) + RM_TEST_MSG("failed to clear video decoders"); + + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = RM_CATEGORY_VIDEO_DECODER_H264_UHD_8BIT_60P; + request.state[0] = RM_STATE_EXCLUSIVE; + + memset(&allocated, 0, sizeof(rm_device_return_s)); + + if (rm_allocate_resources(handle1, &request, &allocated) != RM_OK) + RM_TEST_MSG("failed to clear video decoders"); + + if (rm_unregister(handle1) != RM_OK) + RM_TEST_MSG("failed to unregister"); + + RM_TEST_MSG("clear_video_decoders done..."); +} + +void rm_tc_template_exceptional_test_case(int vdec1, int vdec2) +{ + //consumer#1 + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); + + //alloc + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request->category_option[0] = vdec1 | RM_DEVICE_OPT_MAIN; + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + + //consumer#2 + int handle2 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); + + //alloc + rm_category_request_s *request2 = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request2, 0, sizeof(rm_category_request_s)); + + request2->request_num = 1; + request2->category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request2->category_option[0] = vdec2; + request2->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated2 = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated2, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request2, allocated2)); + + //unregister + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + + sleep(RM_TEST_SLEEP_TIME); + +} + +bool is_support_4k(void) +{ +#ifdef RM_TC_SUPPORT_4K + return true; +#else + return false; +#endif //RM_TC_SUPPORT_4K +} + +bool is_support_8k(void) +{ +#ifdef RM_TC_SUPPORT_8K + return true; +#else + return false; +#endif //RM_TC_SUPPORT_8K +} + +bool is_support_av1_120p(void) +{ +#ifdef RM_TC_SUPPORT_AV1_120P + return true; +#else + return false; +#endif //RM_TC_SUPPORT_AV1_120P +} + +bool use_unified_jpeg_decoder(void) +{ +#ifdef RM_TC_USE_UNIFIED_JPEG_DEC + return true; +#else + return false; +#endif// RM_TC_USE_UNIFIED_JPEG_DEC +} + +bool is_oscars_unified_jpeg_decoder(void) +{ +#ifdef RM_TC_USE_UNIFIED_JPEG_DEC_OSCARS + return true; +#else + return false; +#endif +} + +bool is_support_audio_dual_decoding(void) +{ +#ifdef RM_TC_SUPPORT_AUDIO_DUAL_DECODING + return true; +#else + return false; +#endif //RM_TC_SUPPORT_AUDIO_DUAL_DECODING +} diff --git a/ut/testcase/ut_common.h b/ut/testcase/ut_common.h index d56023c..6639169 100644 --- a/ut/testcase/ut_common.h +++ b/ut/testcase/ut_common.h @@ -1,66 +1,66 @@ -/* - * 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 __UT_COMMON_H__ -#define __UT_COMMON_H__ - -#include -#include -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif//LOG_TAG - -#define LOG_TAG "RSC_MGR_SERVER_TEST" -#define RM_TEST_SLEEP_TIME 1 -#define RM_TEST_MSG(fmt, arg...) \ - do { SLOGE(fmt, ##arg); } while (0) - -#define RM_TC_FREE(a) \ - if (a) \ - { \ - free(a); \ - a = NULL; \ - } - -bool is_8k_model(void); -bool read_rm_index(const char *filename, int *data); -bool is_support_4k(void); -bool is_support_8k(void); -bool is_support_av1_120p(void); -bool use_unified_jpeg_decoder(void); -bool is_support_audio_dual_decoding(void); -bool is_oscars_unified_jpeg_decoder(void); - -GMainContext *get_callback_thread_context(void); - -rm_cb_result rm_cb_counting_conflicted(int handle, rm_callback_type event, rm_device_request_s *info, void *data); -rm_cb_result rm_cb_counting_conflicted_cmp(int handle, rm_callback_type event, rm_device_request_s *info, void *data); -rm_cb_result rm_cb_set_conflict_flag(int handle, rm_callback_type event, rm_device_request_s *info, void *data); -rm_cb_result rm_cb_for_conditional_check(int handle, rm_callback_type event, rm_device_request_s *info, void *data); - -void rm_tc_template_exceptional_test_case(int vdec1, int vdec2); - -int rm_tc_get_conflict_num(void); -void rm_tc_reset_conflict_num(void); -int rm_tc_get_conflict_num_cmp(void); -void rm_tc_reset_conflict_num_cmp(void); -int rm_tc_get_conflicted_resources_num(void); -void rm_tc_reset_conflicted_resources_num(void); -void rm_tc_clear_audio_decoders(void); -void rm_tc_clear_video_decoders(void); -#endif //__UT_COMMON_H__ +/* + * 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 __UT_COMMON_H__ +#define __UT_COMMON_H__ + +#include +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif//LOG_TAG + +#define LOG_TAG "RSC_MGR_SERVER_TEST" +#define RM_TEST_SLEEP_TIME 1 +#define RM_TEST_MSG(fmt, arg...) \ + do { SLOGE(fmt, ##arg); } while (0) + +#define RM_TC_FREE(a) \ + if (a) \ + { \ + free(a); \ + a = NULL; \ + } + +bool is_8k_model(void); +bool read_rm_index(const char *filename, int *data); +bool is_support_4k(void); +bool is_support_8k(void); +bool is_support_av1_120p(void); +bool use_unified_jpeg_decoder(void); +bool is_support_audio_dual_decoding(void); +bool is_oscars_unified_jpeg_decoder(void); + +GMainContext *get_callback_thread_context(void); + +rm_cb_result rm_cb_counting_conflicted(int handle, rm_callback_type event, rm_device_request_s *info, void *data); +rm_cb_result rm_cb_counting_conflicted_cmp(int handle, rm_callback_type event, rm_device_request_s *info, void *data); +rm_cb_result rm_cb_set_conflict_flag(int handle, rm_callback_type event, rm_device_request_s *info, void *data); +rm_cb_result rm_cb_for_conditional_check(int handle, rm_callback_type event, rm_device_request_s *info, void *data); + +void rm_tc_template_exceptional_test_case(int vdec1, int vdec2); + +int rm_tc_get_conflict_num(void); +void rm_tc_reset_conflict_num(void); +int rm_tc_get_conflict_num_cmp(void); +void rm_tc_reset_conflict_num_cmp(void); +int rm_tc_get_conflicted_resources_num(void); +void rm_tc_reset_conflicted_resources_num(void); +void rm_tc_clear_audio_decoders(void); +void rm_tc_clear_video_decoders(void); +#endif //__UT_COMMON_H__ diff --git a/ut/testcase/ut_tc_8k.cpp b/ut/testcase/ut_tc_8k.cpp index 9d8d6e3..a41a738 100644 --- a/ut/testcase/ut_tc_8k.cpp +++ b/ut/testcase/ut_tc_8k.cpp @@ -1,93 +1,93 @@ -/* - * 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" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -/* - * The test cases for 8K model. - * 1. 8K model specific features - */ - -TEST(ut_rm_api, dependency_between_8k_jpeg_decoder_and_bg_scaler) -{ - /* - * 1. Allocate a RI_CATEGORY_JPEG_DECODER_8K -> Alloc : No conflict - * 2. Allocate a RI_CATEGORY_SCALER_BG -> Alloc : (No conflict in 8K not supported model, conflict in 8k model) - */ - - RM_TEST_MSG("dependency_between_8k_jpeg_decoder_and_bg_scaler start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - - // Allocate a RI_CATEGORY_JPEG_DECODER_8K - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_JPEG_DECODER; - request.category_option[0] = ri_get_sub_jpeg_category_id("JPEG", 7680, 4320); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, &request, &allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_SCALER_BG - int handle2 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); - - memset(&request, 0, sizeof(rm_category_request_s)); - memset(&allocated, 0, sizeof(sizeof(rm_device_return_s))); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_SCALER_BG; - request.category_option[0] = 0; - request.state[0] = RM_STATE_EXCLUSIVE; - - int expected_result = RM_OK; // bg scaler exists in 8k model only - int expected_conflict = 1; // bg scaler should be conflicted with 8k jpeg decoder - - EXPECT_EQ(expected_result, rm_allocate_resources(handle2, &request, &allocated)); - EXPECT_EQ(expected_conflict, rm_tc_get_conflict_num()); - - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("dependency_between_8k_jpeg_decoder_and_bg_scaler end..."); -} +/* + * 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" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * The test cases for 8K model. + * 1. 8K model specific features + */ + +TEST(ut_rm_api, dependency_between_8k_jpeg_decoder_and_bg_scaler) +{ + /* + * 1. Allocate a RI_CATEGORY_JPEG_DECODER_8K -> Alloc : No conflict + * 2. Allocate a RI_CATEGORY_SCALER_BG -> Alloc : (No conflict in 8K not supported model, conflict in 8k model) + */ + + RM_TEST_MSG("dependency_between_8k_jpeg_decoder_and_bg_scaler start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + + // Allocate a RI_CATEGORY_JPEG_DECODER_8K + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_JPEG_DECODER; + request.category_option[0] = ri_get_sub_jpeg_category_id("JPEG", 7680, 4320); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, &request, &allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_SCALER_BG + int handle2 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); + + memset(&request, 0, sizeof(rm_category_request_s)); + memset(&allocated, 0, sizeof(sizeof(rm_device_return_s))); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_SCALER_BG; + request.category_option[0] = 0; + request.state[0] = RM_STATE_EXCLUSIVE; + + int expected_result = RM_OK; // bg scaler exists in 8k model only + int expected_conflict = 1; // bg scaler should be conflicted with 8k jpeg decoder + + EXPECT_EQ(expected_result, rm_allocate_resources(handle2, &request, &allocated)); + EXPECT_EQ(expected_conflict, rm_tc_get_conflict_num()); + + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("dependency_between_8k_jpeg_decoder_and_bg_scaler end..."); +} diff --git a/ut/testcase/ut_tc_interaction_sound.cpp b/ut/testcase/ut_tc_interaction_sound.cpp index 760d395..546fbde 100644 --- a/ut/testcase/ut_tc_interaction_sound.cpp +++ b/ut/testcase/ut_tc_interaction_sound.cpp @@ -1,1211 +1,1211 @@ -/* - * 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" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -TEST(ut_rm_api, allocate_audio_decoder_mpeg_InteractionSound) -{ - rm_tc_clear_audio_decoders(); - - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : No conflict - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : No conflict - * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : Conflict with handle#1 - */ - - RM_TEST_MSG("allocate_audio_decoder_mpeg_InteractionSound start..."); - - const char *app_id = "user1"; - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG - int handle2 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*)app_id)); - - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG - - int handle3 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id)); - - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); - EXPECT_EQ(1, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - EXPECT_EQ(RM_OK, rm_unregister(handle3)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_audio_decoder_mpeg_InteractionSound end..."); -} - -TEST(ut_rm_api, allocate_audio_decoder_mpeg_with_differnt_type_of_resources_InteractionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : No conflict - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : No conflict - * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : Conflict with handle#1 - */ - - RM_TEST_MSG("allocate_audio_decoder_mpeg_with_differnt_type_of_resources_InteractionSound start..."); - - const char *app_id = "user1"; - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG - int handle2 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*)app_id)); - - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG - - int handle3 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id)); - - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); - - EXPECT_EQ(1, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - EXPECT_EQ(RM_OK, rm_unregister(handle3)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_audio_decoder_mpeg_with_differnt_type_of_resources_InteractionSound end..."); -} - - -TEST(ut_rm_api, allocate_audio_decoder_ac3_interactionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 (appid : user1) -> Alloc : No conflict - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 (appid : user1) -> Alloc : No conflict - * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 (appid : user1) -> Alloc : Conflict with handle#1 - */ - - RM_TEST_MSG("allocate_audio_decoder_ac3_interactionSound start..."); - - const char *app_id = "user1"; - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_AC3; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 - int handle2 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*)app_id)); - - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_AC3; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 - - int handle3 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id)); - - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_AC3; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); - - EXPECT_EQ(1, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - EXPECT_EQ(RM_OK, rm_unregister(handle3)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_audio_decoder_ac3_interactionSound end..."); -} - -TEST(ut_rm_api, allocate_audio_decoder_ac4_interactionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_AC4 (appid : user1) -> Alloc : No conflict - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_AC4 (appid : user1) -> Alloc : No conflict - */ - - RM_TEST_MSG("allocate_audio_decoder_ac4_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_AC4 - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_AC4; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - int handle2 = 0; - - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); - - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_AC4; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_audio_decoder_ac4_interactionSound end..."); -} - -TEST(ut_rm_api, allocate_audio_decoder_trueHD_interactionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_TRUEHD (appid : user1) -> Alloc : No conflict - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_TRUEHD (appid : user1) -> Alloc : No conflict - */ - - RM_TEST_MSG("allocate_audio_decoder_trueHD_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_TRUEHD - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_TRUEHD; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - int handle2 = 0; - - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); - - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_TRUEHD; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_audio_decoder_trueHD_interactionSound end..."); -} - -TEST(ut_rm_api, allocate_audio_decoder_PCM_interactionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_PCM -> Alloc : Alloc (Mixing mode is supported) - */ - - RM_TEST_MSG("allocate_audio_decoder_PCM_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_PCM - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_PCM; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_audio_decodallocate_audio_decoder_PCM_interactionSounder_PCM end..."); -} - - -TEST(ut_rm_api, allocate_audio_decoder_G2Cook_trueHD_interactionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc : No conflict - */ - - RM_TEST_MSG("allocate_audio_decoder_G2Cook_trueHD_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_audio_decoder_G2Cook_trueHD_interactionSound end..."); -} - -TEST(ut_rm_api, allocate_audio_decoder_G2Cook_trueHD2_interactionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc (appid : user1) : No conflict - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc (appid : user1) : No conflict - * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_TRUEHD -> Alloc (appid : user2) : Alloc conflict with consumer#1 - */ - - RM_TEST_MSG("allocate_audio_decoder_G2Cook_trueHD2_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - const char *app_id1 = "user1"; - const char *app_id2 = "user2"; - - // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id1)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK - int handle2 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*) app_id1)); - - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_TRUEHD - - int handle3 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id2)); - - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_TRUEHD; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); - EXPECT_EQ(1, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - EXPECT_EQ(RM_OK, rm_unregister(handle3)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_audio_decoder_G2Cook_trueHD2_interactionSound end..."); -} - -TEST(ut_rm_api, allocate_audio_decoder_G2Cook_MPEG_interactionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc (appid : user1) : No conflict - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc (appid : user1) : No conflict - * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG -> Alloc (appid : user2) : Alloc conflict with consumer#1 - */ - - RM_TEST_MSG("allocate_audio_decoder_G2Cook_MPEG_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - const char *app_id1 = "user1"; - const char *app_id2 = "user2"; - - // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id1)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK - int handle2 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*) app_id1)); - - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_AUDIO_CODEC_NAME_MPEG - - int handle3 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id2)); - - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); - - EXPECT_EQ(1, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - EXPECT_EQ(RM_OK, rm_unregister(handle3)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_audio_decoder_G2Cook_MPEG_interactionSound end..."); -} - -TEST(ut_rm_api, allocate_audio_decoder_MPEG_MPEG_interactionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG -> Alloc (appid : user1) : No conflict - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG -> Alloc (appid : user2) : No conflict - */ - - RM_TEST_MSG("allocate_audio_decoder_MPEG_MPEG_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - const char *app_id1 = "user1"; - const char *app_id2 = "user2"; - - // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id1)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_AUDIO_CODEC_NAME_MPEG - - int handle3 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id2)); - - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle3)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_audio_decoder_MPEG_MPEG_interactionSound end..."); -} - - -TEST(ut_rm_api, allocate_multi_audio_decoders_by_same_consumer1_interactionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#1 -> Alloc : No conflict - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_ADPCM with consumer id#1 -> Alloc : No conflict - */ - - RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer1_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - const char *user_id = "user1"; - - // Allocate two RI_CATEGORY_AUDIO_DECODER_G2COOK - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)user_id)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - - // Allocate a RI_CATEGORY_AUDIO_DECODER_ADPCM - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_ADPCM; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer1_interactionSound end..."); -} - -TEST(ut_rm_api, allocate_multi_audio_decoders_by_same_consumer2_interactionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#1 -> Alloc : No conflict - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#1 -> Alloc : No conflict - * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#1 -> Alloc : Fail - */ - - RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer2_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - const char *user_id = "user1"; - - // Allocate two RI_CATEGORY_AUDIO_DECODER_G2COOK - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)user_id)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 2; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - request->category_id[1] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[1] = ri_get_capable_audio_category_id(&opt); - request->state[1] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK - //alloc - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_NE(RM_OK, rm_allocate_resources(handle1, request, allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer2_interactionSound end..."); -} - -TEST(ut_rm_api, allocate_reclaim_resource_had_been_allocated_first_interactionSound) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#1 -> Alloc : No conflict -> main audio decoder - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#2 -> Alloc : No conflict -> sub audio decoder - * 3. Release main audio decoder -> released - * 4. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#3 -> Alloc : No conflict -> main audio decoder - * 5. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#4 -> Alloc : conflict with handle#2 -> sub audio decoder - */ - - RM_TEST_MSG("allocate_reclaim_resource_had_been_allocated_first_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - const char *user_id = "user1"; - - // Allocate two RI_CATEGORY_AUDIO_DECODER_G2COOK - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)user_id)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, allocated->device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK - - int handle2 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); - - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated->device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - // release main audio decoder - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - - int handle3 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle3, NULL)); - - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, allocated->device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - int handle4 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle4, NULL)); - - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle4, request, allocated)); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated->device_id[0]); - EXPECT_EQ(1, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - EXPECT_EQ(RM_OK, rm_unregister(handle3)); - EXPECT_EQ(RM_OK, rm_unregister(handle4)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_reclaim_resource_had_been_allocated_first_interactionSound end..."); -} - - -TEST(ut_rm_api, allocate_multi_audio_decoders_by_same_consumer_at_once_interactionSound) -{ - /* - * 1. Allocate RI_CATEGORY_AUDIO_DECODER_G2COOK and RI_CATEGORY_AUDIO_DECODER_TRUEHD with consumer id#1 at once -> Alloc - */ - - RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer_at_once_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - const char *user_id = "user1"; - - // Allocate RI_CATEGORY_AUDIO_DECODER_G2COOK and RI_CATEGORY_AUDIO_DECODER_TRUEHD at once. - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1,(char*) user_id)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 2; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - opt.codec_name = RI_AUDIO_CODEC_NAME_TRUEHD; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->category_id[1] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[1] = ri_get_capable_audio_category_id(&opt); - request->state[1] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer_at_once_interactionSound end..."); -} - -TEST(ut_rm_api, allocate_mixing_not_supported_codec_interactionSound) -{ - /* - * 1. Allocate RI_CATEGORY_AUDIO_DECODER_MPEG_H -> Alloc (Mixing is not supported but allocate) - */ - - RM_TEST_MSG("allocate_mixing_not_supported_codec_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - const char *user_id = "user1"; - - // Allocate RI_CATEGORY_AUDIO_DECODER_MPEG_H - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1,(char*) user_id)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG_H; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_mixing_not_supported_codec_interactionSound end..."); -} - -TEST(ut_rm_api, allocate_mixing_not_supported_codec2_interactionSound) -{ - /* - * 1. Allocate RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc - * 2. Allocate RI_CATEGORY_AUDIO_DECODER_MPEG_H -> Alloc conflict with handle#1 (Mixing is not supported) - */ - - RM_TEST_MSG("allocate_mixing_not_supported_codec2_interactionSound start..."); - - rm_tc_reset_conflict_num(); - rm_tc_reset_conflicted_resources_num(); - const char *user_id = "user1"; - - int handle1 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle1,(char*) user_id)); - - rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); - memset((void*)request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - int handle2 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*) user_id)); - - memset((void*)request, 0, sizeof(rm_category_request_s)); - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG_H; - opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; - - request->request_num = 1; - request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request->category_option[0] = ri_get_capable_audio_category_id(&opt); - request->state[0] = RM_STATE_EXCLUSIVE; - - memset((void*)allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); - EXPECT_EQ(1, rm_tc_get_conflict_num()); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_mixing_not_supported_codec2_interactionSound end..."); -} \ No newline at end of file +/* + * 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" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +TEST(ut_rm_api, allocate_audio_decoder_mpeg_InteractionSound) +{ + rm_tc_clear_audio_decoders(); + + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : No conflict + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : No conflict + * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : Conflict with handle#1 + */ + + RM_TEST_MSG("allocate_audio_decoder_mpeg_InteractionSound start..."); + + const char *app_id = "user1"; + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG + int handle2 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*)app_id)); + + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG + + int handle3 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id)); + + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); + EXPECT_EQ(1, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + EXPECT_EQ(RM_OK, rm_unregister(handle3)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_audio_decoder_mpeg_InteractionSound end..."); +} + +TEST(ut_rm_api, allocate_audio_decoder_mpeg_with_differnt_type_of_resources_InteractionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : No conflict + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : No conflict + * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG (appid : user1)-> Alloc : Conflict with handle#1 + */ + + RM_TEST_MSG("allocate_audio_decoder_mpeg_with_differnt_type_of_resources_InteractionSound start..."); + + const char *app_id = "user1"; + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG + int handle2 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*)app_id)); + + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG + + int handle3 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id)); + + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); + + EXPECT_EQ(1, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + EXPECT_EQ(RM_OK, rm_unregister(handle3)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_audio_decoder_mpeg_with_differnt_type_of_resources_InteractionSound end..."); +} + + +TEST(ut_rm_api, allocate_audio_decoder_ac3_interactionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 (appid : user1) -> Alloc : No conflict + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 (appid : user1) -> Alloc : No conflict + * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 (appid : user1) -> Alloc : Conflict with handle#1 + */ + + RM_TEST_MSG("allocate_audio_decoder_ac3_interactionSound start..."); + + const char *app_id = "user1"; + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_AC3; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 + int handle2 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*)app_id)); + + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_AC3; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_AC3 + + int handle3 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id)); + + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_AC3; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); + + EXPECT_EQ(1, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + EXPECT_EQ(RM_OK, rm_unregister(handle3)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_audio_decoder_ac3_interactionSound end..."); +} + +TEST(ut_rm_api, allocate_audio_decoder_ac4_interactionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_AC4 (appid : user1) -> Alloc : No conflict + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_AC4 (appid : user1) -> Alloc : No conflict + */ + + RM_TEST_MSG("allocate_audio_decoder_ac4_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_AC4 + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_AC4; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + int handle2 = 0; + + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); + + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_AC4; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_audio_decoder_ac4_interactionSound end..."); +} + +TEST(ut_rm_api, allocate_audio_decoder_trueHD_interactionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_TRUEHD (appid : user1) -> Alloc : No conflict + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_TRUEHD (appid : user1) -> Alloc : No conflict + */ + + RM_TEST_MSG("allocate_audio_decoder_trueHD_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_TRUEHD + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_TRUEHD; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + int handle2 = 0; + + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle2, NULL)); + + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_TRUEHD; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_audio_decoder_trueHD_interactionSound end..."); +} + +TEST(ut_rm_api, allocate_audio_decoder_PCM_interactionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_PCM -> Alloc : Alloc (Mixing mode is supported) + */ + + RM_TEST_MSG("allocate_audio_decoder_PCM_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_PCM + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_PCM; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_audio_decodallocate_audio_decoder_PCM_interactionSounder_PCM end..."); +} + + +TEST(ut_rm_api, allocate_audio_decoder_G2Cook_trueHD_interactionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc : No conflict + */ + + RM_TEST_MSG("allocate_audio_decoder_G2Cook_trueHD_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle1, NULL)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_audio_decoder_G2Cook_trueHD_interactionSound end..."); +} + +TEST(ut_rm_api, allocate_audio_decoder_G2Cook_trueHD2_interactionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc (appid : user1) : No conflict + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc (appid : user1) : No conflict + * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_TRUEHD -> Alloc (appid : user2) : Alloc conflict with consumer#1 + */ + + RM_TEST_MSG("allocate_audio_decoder_G2Cook_trueHD2_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + const char *app_id1 = "user1"; + const char *app_id2 = "user2"; + + // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id1)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK + int handle2 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*) app_id1)); + + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_TRUEHD + + int handle3 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id2)); + + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_TRUEHD; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); + EXPECT_EQ(1, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + EXPECT_EQ(RM_OK, rm_unregister(handle3)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_audio_decoder_G2Cook_trueHD2_interactionSound end..."); +} + +TEST(ut_rm_api, allocate_audio_decoder_G2Cook_MPEG_interactionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc (appid : user1) : No conflict + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc (appid : user1) : No conflict + * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG -> Alloc (appid : user2) : Alloc conflict with consumer#1 + */ + + RM_TEST_MSG("allocate_audio_decoder_G2Cook_MPEG_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + const char *app_id1 = "user1"; + const char *app_id2 = "user2"; + + // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id1)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK + int handle2 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*) app_id1)); + + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_AUDIO_CODEC_NAME_MPEG + + int handle3 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id2)); + + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); + + EXPECT_EQ(1, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + EXPECT_EQ(RM_OK, rm_unregister(handle3)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_audio_decoder_G2Cook_MPEG_interactionSound end..."); +} + +TEST(ut_rm_api, allocate_audio_decoder_MPEG_MPEG_interactionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG -> Alloc (appid : user1) : No conflict + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG -> Alloc (appid : user2) : No conflict + */ + + RM_TEST_MSG("allocate_audio_decoder_MPEG_MPEG_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + const char *app_id1 = "user1"; + const char *app_id2 = "user2"; + + // Allocate a RI_CATEGORY_AUDIO_DECODER_MPEG + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)app_id1)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_AUDIO_CODEC_NAME_MPEG + + int handle3 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_set_conflict_flag, NULL, &handle3, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle3, (char*)app_id2)); + + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle3)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_audio_decoder_MPEG_MPEG_interactionSound end..."); +} + + +TEST(ut_rm_api, allocate_multi_audio_decoders_by_same_consumer1_interactionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#1 -> Alloc : No conflict + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_ADPCM with consumer id#1 -> Alloc : No conflict + */ + + RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer1_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + const char *user_id = "user1"; + + // Allocate two RI_CATEGORY_AUDIO_DECODER_G2COOK + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)user_id)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + + // Allocate a RI_CATEGORY_AUDIO_DECODER_ADPCM + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_ADPCM; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer1_interactionSound end..."); +} + +TEST(ut_rm_api, allocate_multi_audio_decoders_by_same_consumer2_interactionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#1 -> Alloc : No conflict + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#1 -> Alloc : No conflict + * 3. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#1 -> Alloc : Fail + */ + + RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer2_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + const char *user_id = "user1"; + + // Allocate two RI_CATEGORY_AUDIO_DECODER_G2COOK + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)user_id)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 2; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + request->category_id[1] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[1] = ri_get_capable_audio_category_id(&opt); + request->state[1] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK + //alloc + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_NE(RM_OK, rm_allocate_resources(handle1, request, allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer2_interactionSound end..."); +} + +TEST(ut_rm_api, allocate_reclaim_resource_had_been_allocated_first_interactionSound) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#1 -> Alloc : No conflict -> main audio decoder + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#2 -> Alloc : No conflict -> sub audio decoder + * 3. Release main audio decoder -> released + * 4. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#3 -> Alloc : No conflict -> main audio decoder + * 5. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with consumer id#4 -> Alloc : conflict with handle#2 -> sub audio decoder + */ + + RM_TEST_MSG("allocate_reclaim_resource_had_been_allocated_first_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + const char *user_id = "user1"; + + // Allocate two RI_CATEGORY_AUDIO_DECODER_G2COOK + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1, (char*)user_id)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, allocated->device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK + + int handle2 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); + + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated->device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + // release main audio decoder + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + + int handle3 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle3, NULL)); + + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, request, allocated)); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, allocated->device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + int handle4 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle4, NULL)); + + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle4, request, allocated)); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated->device_id[0]); + EXPECT_EQ(1, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + EXPECT_EQ(RM_OK, rm_unregister(handle3)); + EXPECT_EQ(RM_OK, rm_unregister(handle4)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_reclaim_resource_had_been_allocated_first_interactionSound end..."); +} + + +TEST(ut_rm_api, allocate_multi_audio_decoders_by_same_consumer_at_once_interactionSound) +{ + /* + * 1. Allocate RI_CATEGORY_AUDIO_DECODER_G2COOK and RI_CATEGORY_AUDIO_DECODER_TRUEHD with consumer id#1 at once -> Alloc + */ + + RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer_at_once_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + const char *user_id = "user1"; + + // Allocate RI_CATEGORY_AUDIO_DECODER_G2COOK and RI_CATEGORY_AUDIO_DECODER_TRUEHD at once. + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1,(char*) user_id)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 2; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + opt.codec_name = RI_AUDIO_CODEC_NAME_TRUEHD; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->category_id[1] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[1] = ri_get_capable_audio_category_id(&opt); + request->state[1] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_multi_audio_decoders_by_same_consumer_at_once_interactionSound end..."); +} + +TEST(ut_rm_api, allocate_mixing_not_supported_codec_interactionSound) +{ + /* + * 1. Allocate RI_CATEGORY_AUDIO_DECODER_MPEG_H -> Alloc (Mixing is not supported but allocate) + */ + + RM_TEST_MSG("allocate_mixing_not_supported_codec_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + const char *user_id = "user1"; + + // Allocate RI_CATEGORY_AUDIO_DECODER_MPEG_H + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1,(char*) user_id)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG_H; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_mixing_not_supported_codec_interactionSound end..."); +} + +TEST(ut_rm_api, allocate_mixing_not_supported_codec2_interactionSound) +{ + /* + * 1. Allocate RI_CATEGORY_AUDIO_DECODER_G2COOK -> Alloc + * 2. Allocate RI_CATEGORY_AUDIO_DECODER_MPEG_H -> Alloc conflict with handle#1 (Mixing is not supported) + */ + + RM_TEST_MSG("allocate_mixing_not_supported_codec2_interactionSound start..."); + + rm_tc_reset_conflict_num(); + rm_tc_reset_conflicted_resources_num(); + const char *user_id = "user1"; + + int handle1 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle1,(char*) user_id)); + + rm_category_request_s *request = (rm_category_request_s*) malloc (sizeof(rm_category_request_s)); + memset((void*)request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s *allocated = (rm_device_return_s*) malloc (sizeof(rm_device_return_s)); + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, request, allocated)); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + int handle2 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle2, (char*) user_id)); + + memset((void*)request, 0, sizeof(rm_category_request_s)); + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_MPEG_H; + opt.mixing_mode = RI_MIXING_MODE_INTERACTION_SOUND; + + request->request_num = 1; + request->category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request->category_option[0] = ri_get_capable_audio_category_id(&opt); + request->state[0] = RM_STATE_EXCLUSIVE; + + memset((void*)allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, request, allocated)); + EXPECT_EQ(1, rm_tc_get_conflict_num()); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_mixing_not_supported_codec2_interactionSound end..."); +} diff --git a/ut/testcase/ut_tc_multiview.cpp b/ut/testcase/ut_tc_multiview.cpp index 740ece1..76b7059 100644 --- a/ut/testcase/ut_tc_multiview.cpp +++ b/ut/testcase/ut_tc_multiview.cpp @@ -1,691 +1,691 @@ -/* - * 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" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - - -TEST(ut_rm_api, alloc_main_audio_dec_p1_multiview) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with main option -> Alloc : No conflict - */ - - RM_TEST_MSG("alloc_main_audio_dec_p1_multiview start..."); - - int handle = 0; - - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_MULTIVIEW; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request.category_option[0] = ri_get_capable_audio_category_id(&opt) | RM_DEVICE_OPT_MAIN; - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, allocated.device_id[0]); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - rm_tc_reset_conflict_num(); - - sleep(RM_TEST_SLEEP_TIME); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_main_audio_dec_p1_multiview end..."); -} - -TEST(ut_rm_api, alloc_sub_audio_dec_p1_multiview) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with sub option -> Alloc : No conflict - */ - - RM_TEST_MSG("alloc_sub_audio_dec_p1_multiview start..."); - - int handle = 0; - - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_audio_category_option_request_s opt; - memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); - - opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; - opt.mixing_mode = RI_MIXING_MODE_MULTIVIEW; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_AUDIO_DECODER_SUB; - request.category_option[0] = ri_get_capable_audio_category_id(&opt) | RM_DEVICE_OPT_SUB; - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated.device_id[0]); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - rm_tc_reset_conflict_num(); - - sleep(RM_TEST_SLEEP_TIME); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_sub_audio_dec_p1_multiview end..."); -} - -TEST(ut_rm_api, alloc_three_video_decoders_in_multiview_p1) -{ - rm_tc_clear_video_decoders(); - - RM_TEST_MSG("alloc_three_video_decoders_in_multiview_p1 start..."); - - int handle1 = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "H264"; - option.color_depth = 8; - option.framerate = 30; - option.h_size = 1920; - option.v_size = 1080; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 2; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = 0; - request.state[0] = RM_STATE_EXCLUSIVE; - - request.category_id[1] = RM_CATEGORY_SCALER; - request.state[1] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, &request, &allocated)); - EXPECT_EQ(2, allocated.allocated_num); - // The mfc0 shall be allocated first - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_MAIN, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - rm_device_request_s req_rel; - memset(&req_rel, 0, sizeof(rm_device_request_s)); - - req_rel.request_num = 1; - req_rel.device_id[0] = allocated.device_id[1]; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle1, &req_rel)); - - int handle2 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); - - memset(&allocated, 0, sizeof(rm_device_return_s)); - - request.request_num = 2; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_capable_video_category_id(&option); - request.state[0] = RM_STATE_EXCLUSIVE; - - request.category_id[1] = RM_CATEGORY_SCALER_SUB; - request.state[1] = RM_STATE_EXCLUSIVE; - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &request, &allocated)); - EXPECT_EQ(2, allocated.allocated_num); - - // The mfc1 shall be allocated later - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_SUB, allocated.device_id[0]); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[1]); - EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[1])); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - int handle3 = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle3, NULL)); - - memset(&allocated, 0, sizeof(rm_device_return_s)); - - request.request_num = 2; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER_SUB; - request.category_option[0] = (ri_get_capable_video_category_id(&option) | RM_DEVICE_OPT_SUB); - request.state[0] = RM_STATE_EXCLUSIVE; - - request.category_id[1] = RM_CATEGORY_SCALER_SUB; - request.state[1] = RM_STATE_EXCLUSIVE; - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, &request, &allocated)); - EXPECT_EQ(2, allocated.allocated_num); - - // The mfc0 shall be allocated - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_SUB, allocated.device_id[0]); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[1]); - EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[1])); - EXPECT_EQ(1, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - EXPECT_EQ(RM_OK, rm_unregister(handle3)); - - RM_TEST_MSG("alloc_three_video_decoders_in_multiview_p1 end..."); -} - -TEST(ut_rm_api, multiview_audio_decoder_conflict_p2) -{ - RM_TEST_MSG("multiview_audio_decoder_conflict_p2 start..."); - - rm_tc_reset_conflict_num(); - - int handle1; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request.category_option[0] = (RI_CATEGORY_AUDIO_DECODER_AAC | RM_DEVICE_OPT_MAIN); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - sleep(2); - - rm_tc_reset_conflict_num(); - int handle2; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); - - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_AUDIO_DECODER_SUB; - request.category_option[0] = 0; - request.state[0] = RM_STATE_EXCLUSIVE; - - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - rm_tc_reset_conflict_num(); - - int handle3; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle3, NULL)); - - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_AUDIO_DECODER_SUB; - request.category_option[0] = 0; - request.state[0] = RM_STATE_EXCLUSIVE; - - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated.device_id[0]); - EXPECT_EQ(1, rm_tc_get_conflict_num()); - - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - EXPECT_EQ(RM_OK, rm_unregister(handle3)); - - RM_TEST_MSG("multiview_audio_decoder_conflict_p2 end..."); -} - -TEST(ut_rm_api, alloc_audio_sub_out_p) -{ - /* - * 1. Allocate the following resource with handle#1 - * RM_CATEGORY_AUDIO_SUB_OUT with RM_STATE_EXCLUSIVE -> Alloc - */ - - RM_TEST_MSG("alloc_audio_sub_out_p start..."); - - rm_tc_reset_conflict_num(); - - int handle = 0; - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - rm_device_return_s allocated_devices; - memset(&allocated_devices, 0, sizeof(rm_device_return_s)); - - request.request_num = 1; - - request.category_id[0] = RM_CATEGORY_AUDIO_SUB_OUT; - request.state[0] = RM_STATE_EXCLUSIVE; - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated_devices)); - - EXPECT_EQ(1, allocated_devices.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, allocated_devices.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("alloc_audio_sub_out_p end..."); -} - -TEST(ut_rm_api, alloc_audio_sub_out_conflict_1) -{ - /* - * 1. Allocate the following resource with handle#1 - * RM_CATEGORY_AUDIO_SUB_OUT with RM_STATE_EXCLUSIVE -> Alloc - * 2. Allocate the following resource with handle#2 - * RM_CATEGORY_AUDIO_MAIN_OUT with RM_STATE_EXCLUSIVE -> Alloc : No conflict - */ - - RM_TEST_MSG("alloc_audio_sub_out_conflict_1 start..."); - - rm_tc_reset_conflict_num(); - - int handle = 0; - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - rm_device_return_s allocated_devices; - memset(&allocated_devices, 0, sizeof(rm_device_return_s)); - - request.request_num = 1; - - request.category_id[0] = RM_CATEGORY_AUDIO_SUB_OUT; - request.state[0] = RM_STATE_EXCLUSIVE; - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated_devices)); - - EXPECT_EQ(1, allocated_devices.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, allocated_devices.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - int handle2 = 0; - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); - - memset(&request, 0, sizeof(rm_category_request_s)); - memset(&allocated_devices, 0, sizeof(rm_device_return_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_AUDIO_MAIN_OUT; - request.state[0] = RM_STATE_EXCLUSIVE; - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &request, &allocated_devices)); - - EXPECT_EQ(1, allocated_devices.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_MAIN_OUT, allocated_devices.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("alloc_audio_sub_out_conflict_1 end..."); -} - -TEST(ut_rm_api, alloc_audio_sub_out_conflict_2) -{ - /* - * 1. Allocate the following resource with handle#1 - * RM_CATEGORY_AUDIO_SUB_OUT with RM_STATE_EXCLUSIVE -> Alloc - * 2. Allocate the following resource with handle#2 - * RM_CATEGORY_AUDIO_MAIN_OUT with RM_STATE_EXCLUSIVE -> Alloc : No conflict - */ - - RM_TEST_MSG("alloc_audio_sub_out_conflict_2 start..."); - - rm_tc_reset_conflict_num(); - - int handle = 0; - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - rm_device_return_s allocated_devices; - memset(&allocated_devices, 0, sizeof(rm_device_return_s)); - - request.request_num = 1; - - request.category_id[0] = RM_CATEGORY_AUDIO_SUB_OUT; - request.state[0] = RM_STATE_EXCLUSIVE; - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated_devices)); - - EXPECT_EQ(1, allocated_devices.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, allocated_devices.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - int handle2 = 0; - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); - - memset(&request, 0, sizeof(rm_category_request_s)); - memset(&allocated_devices, 0, sizeof(rm_device_return_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_AUDIO_MAIN_OUT; - request.state[0] = RM_STATE_EXCLUSIVE; - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &request, &allocated_devices)); - - EXPECT_EQ(1, allocated_devices.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_MAIN_OUT, allocated_devices.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("alloc_audio_sub_out_conflict_2 end..."); -} - - -TEST(ut_rm_api, multiview_scaler_to_main_p1) -{ - RM_TEST_MSG("multiview_scaler_to_main_p1 start..."); - - int handle = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_SCALER; - request.category_option[0] = (RM_CATEGORY_SCALER | RM_FORCE_TO_MAIN); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("multiview_scaler_to_main_p1 end..."); -} - -TEST(ut_rm_api, multiview_scaler_to_main_p2) -{ - RM_TEST_MSG("multiview_scaler_to_main_p2 start..."); - - int handle = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_SCALER_SUB; - request.category_option[0] = (RM_CATEGORY_SCALER_SUB | RM_FORCE_TO_MAIN); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("multiview_scaler_to_main_p2 end..."); -} - -TEST(ut_rm_api, multiview_scaler_to_sub_p1) -{ - RM_TEST_MSG("multiview_scaler_to_sub_p1 start..."); - - int handle = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_SCALER; - request.category_option[0] = (RM_CATEGORY_SCALER | RM_FORCE_TO_SUB); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[0])); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("multiview_scaler_to_sub_p1 end..."); -} - -TEST(ut_rm_api, multiview_audio_out_to_main_p1) -{ - RM_TEST_MSG("multiview_audio_out_to_main_p1 start..."); - - int handle = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_AUDIO_MAIN_OUT; - request.category_option[0] = (RM_CATEGORY_AUDIO_MAIN_OUT | RM_FORCE_TO_MAIN); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_MAIN_OUT, allocated.device_id[0]); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("multiview_audio_out_to_main_p1 end..."); -} - -TEST(ut_rm_api, multiview_audio_out_to_main_p2) -{ - RM_TEST_MSG("multiview_audio_out_to_main_p2 start..."); - - int handle = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_AUDIO_MAIN_OUT; - request.category_option[0] = (RM_CATEGORY_AUDIO_MAIN_OUT | RM_FORCE_TO_SUB); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, allocated.device_id[0]); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("multiview_audio_out_to_main_p2 end..."); -} - -TEST(ut_rm_api, multiview_audio_decoder_main_p1) -{ - RM_TEST_MSG("multiview_audio_decoder_main_p1 start..."); - - int handle = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request.category_option[0] = (RM_CATEGORY_AUDIO_DECODER | RM_DEVICE_OPT_MAIN | RM_FORCE_TO_MAIN); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, allocated.device_id[0]); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("multiview_audio_decoder_main_p1 end..."); -} - -TEST(ut_rm_api, multiview_audio_decoder_main_p2) -{ - RM_TEST_MSG("multiview_audio_decoder_main_p2 start..."); - - int handle = 0; - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_AUDIO_DECODER; - request.category_option[0] = (RM_CATEGORY_AUDIO_DECODER | RM_DEVICE_OPT_SUB | RM_FORCE_TO_SUB); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated.device_id[0]); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("multiview_audio_decoder_main_p2 end..."); -} - -TEST(ut_rm_api, rm_active_audio_out_p1) -{ - RM_TEST_MSG("rm_active_audio_out_p1 start..."); - - TCPlayer *player = new TCPlayer(); - EXPECT_EQ(RM_OK, player->Register()); - - EXPECT_EQ(RM_AUDIO_OUT_NONE, player->GetActiveAudioOut()); - - // Allocate audio main out - player->AddResource(RM_CATEGORY_AUDIO_MAIN_OUT, RM_STATE_EXCLUSIVE); - EXPECT_EQ(RM_OK, player->AllocateResources()); - EXPECT_EQ(RM_AUDIO_OUT_MAIN, player->GetActiveAudioOut()); - - // Allocate audio sub out - player->RemoveResources(); - player->AddResource(RM_CATEGORY_AUDIO_SUB_OUT, RM_STATE_EXCLUSIVE); - EXPECT_EQ(RM_OK, player->AllocateResources()); - EXPECT_EQ((RM_AUDIO_OUT_MAIN | RM_AUDIO_OUT_SUB), player->GetActiveAudioOut()); - - // Release audio main & sub out - player->RemoveResources(); - EXPECT_EQ(RM_OK, player->ReleaseResources()); - EXPECT_EQ(RM_AUDIO_OUT_NONE, player->GetActiveAudioOut()); - - // Allocate audio sub out - player->AddResource(RM_CATEGORY_AUDIO_SUB_OUT, RM_STATE_EXCLUSIVE); - EXPECT_EQ(RM_OK, player->AllocateResources()); - EXPECT_EQ(RM_AUDIO_OUT_SUB, player->GetActiveAudioOut()); - - EXPECT_EQ(RM_OK, player->Unregister()); - delete player; - - RM_TEST_MSG("rm_active_audio_out_p1 end..."); -} +/* + * 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" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +TEST(ut_rm_api, alloc_main_audio_dec_p1_multiview) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with main option -> Alloc : No conflict + */ + + RM_TEST_MSG("alloc_main_audio_dec_p1_multiview start..."); + + int handle = 0; + + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_MULTIVIEW; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request.category_option[0] = ri_get_capable_audio_category_id(&opt) | RM_DEVICE_OPT_MAIN; + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, allocated.device_id[0]); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + rm_tc_reset_conflict_num(); + + sleep(RM_TEST_SLEEP_TIME); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_main_audio_dec_p1_multiview end..."); +} + +TEST(ut_rm_api, alloc_sub_audio_dec_p1_multiview) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER_G2COOK with sub option -> Alloc : No conflict + */ + + RM_TEST_MSG("alloc_sub_audio_dec_p1_multiview start..."); + + int handle = 0; + + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_audio_category_option_request_s opt; + memset(&opt, 0, sizeof(ri_audio_category_option_request_s)); + + opt.codec_name = RI_AUDIO_CODEC_NAME_G2COOK; + opt.mixing_mode = RI_MIXING_MODE_MULTIVIEW; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_AUDIO_DECODER_SUB; + request.category_option[0] = ri_get_capable_audio_category_id(&opt) | RM_DEVICE_OPT_SUB; + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated.device_id[0]); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + rm_tc_reset_conflict_num(); + + sleep(RM_TEST_SLEEP_TIME); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_sub_audio_dec_p1_multiview end..."); +} + +TEST(ut_rm_api, alloc_three_video_decoders_in_multiview_p1) +{ + rm_tc_clear_video_decoders(); + + RM_TEST_MSG("alloc_three_video_decoders_in_multiview_p1 start..."); + + int handle1 = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "H264"; + option.color_depth = 8; + option.framerate = 30; + option.h_size = 1920; + option.v_size = 1080; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 2; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = 0; + request.state[0] = RM_STATE_EXCLUSIVE; + + request.category_id[1] = RM_CATEGORY_SCALER; + request.state[1] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, &request, &allocated)); + EXPECT_EQ(2, allocated.allocated_num); + // The mfc0 shall be allocated first + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_MAIN, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + rm_device_request_s req_rel; + memset(&req_rel, 0, sizeof(rm_device_request_s)); + + req_rel.request_num = 1; + req_rel.device_id[0] = allocated.device_id[1]; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle1, &req_rel)); + + int handle2 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); + + memset(&allocated, 0, sizeof(rm_device_return_s)); + + request.request_num = 2; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_capable_video_category_id(&option); + request.state[0] = RM_STATE_EXCLUSIVE; + + request.category_id[1] = RM_CATEGORY_SCALER_SUB; + request.state[1] = RM_STATE_EXCLUSIVE; + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &request, &allocated)); + EXPECT_EQ(2, allocated.allocated_num); + + // The mfc1 shall be allocated later + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_SUB, allocated.device_id[0]); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[1]); + EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[1])); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + int handle3 = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle3, NULL)); + + memset(&allocated, 0, sizeof(rm_device_return_s)); + + request.request_num = 2; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER_SUB; + request.category_option[0] = (ri_get_capable_video_category_id(&option) | RM_DEVICE_OPT_SUB); + request.state[0] = RM_STATE_EXCLUSIVE; + + request.category_id[1] = RM_CATEGORY_SCALER_SUB; + request.state[1] = RM_STATE_EXCLUSIVE; + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, &request, &allocated)); + EXPECT_EQ(2, allocated.allocated_num); + + // The mfc0 shall be allocated + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_SUB, allocated.device_id[0]); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[1]); + EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[1])); + EXPECT_EQ(1, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + EXPECT_EQ(RM_OK, rm_unregister(handle3)); + + RM_TEST_MSG("alloc_three_video_decoders_in_multiview_p1 end..."); +} + +TEST(ut_rm_api, multiview_audio_decoder_conflict_p2) +{ + RM_TEST_MSG("multiview_audio_decoder_conflict_p2 start..."); + + rm_tc_reset_conflict_num(); + + int handle1; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle1, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request.category_option[0] = (RI_CATEGORY_AUDIO_DECODER_AAC | RM_DEVICE_OPT_MAIN); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + sleep(2); + + rm_tc_reset_conflict_num(); + int handle2; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); + + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_AUDIO_DECODER_SUB; + request.category_option[0] = 0; + request.state[0] = RM_STATE_EXCLUSIVE; + + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + rm_tc_reset_conflict_num(); + + int handle3; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle3, NULL)); + + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_AUDIO_DECODER_SUB; + request.category_option[0] = 0; + request.state[0] = RM_STATE_EXCLUSIVE; + + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated.device_id[0]); + EXPECT_EQ(1, rm_tc_get_conflict_num()); + + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + EXPECT_EQ(RM_OK, rm_unregister(handle3)); + + RM_TEST_MSG("multiview_audio_decoder_conflict_p2 end..."); +} + +TEST(ut_rm_api, alloc_audio_sub_out_p) +{ + /* + * 1. Allocate the following resource with handle#1 + * RM_CATEGORY_AUDIO_SUB_OUT with RM_STATE_EXCLUSIVE -> Alloc + */ + + RM_TEST_MSG("alloc_audio_sub_out_p start..."); + + rm_tc_reset_conflict_num(); + + int handle = 0; + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + rm_device_return_s allocated_devices; + memset(&allocated_devices, 0, sizeof(rm_device_return_s)); + + request.request_num = 1; + + request.category_id[0] = RM_CATEGORY_AUDIO_SUB_OUT; + request.state[0] = RM_STATE_EXCLUSIVE; + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated_devices)); + + EXPECT_EQ(1, allocated_devices.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, allocated_devices.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("alloc_audio_sub_out_p end..."); +} + +TEST(ut_rm_api, alloc_audio_sub_out_conflict_1) +{ + /* + * 1. Allocate the following resource with handle#1 + * RM_CATEGORY_AUDIO_SUB_OUT with RM_STATE_EXCLUSIVE -> Alloc + * 2. Allocate the following resource with handle#2 + * RM_CATEGORY_AUDIO_MAIN_OUT with RM_STATE_EXCLUSIVE -> Alloc : No conflict + */ + + RM_TEST_MSG("alloc_audio_sub_out_conflict_1 start..."); + + rm_tc_reset_conflict_num(); + + int handle = 0; + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + rm_device_return_s allocated_devices; + memset(&allocated_devices, 0, sizeof(rm_device_return_s)); + + request.request_num = 1; + + request.category_id[0] = RM_CATEGORY_AUDIO_SUB_OUT; + request.state[0] = RM_STATE_EXCLUSIVE; + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated_devices)); + + EXPECT_EQ(1, allocated_devices.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, allocated_devices.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + int handle2 = 0; + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); + + memset(&request, 0, sizeof(rm_category_request_s)); + memset(&allocated_devices, 0, sizeof(rm_device_return_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_AUDIO_MAIN_OUT; + request.state[0] = RM_STATE_EXCLUSIVE; + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &request, &allocated_devices)); + + EXPECT_EQ(1, allocated_devices.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_MAIN_OUT, allocated_devices.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("alloc_audio_sub_out_conflict_1 end..."); +} + +TEST(ut_rm_api, alloc_audio_sub_out_conflict_2) +{ + /* + * 1. Allocate the following resource with handle#1 + * RM_CATEGORY_AUDIO_SUB_OUT with RM_STATE_EXCLUSIVE -> Alloc + * 2. Allocate the following resource with handle#2 + * RM_CATEGORY_AUDIO_MAIN_OUT with RM_STATE_EXCLUSIVE -> Alloc : No conflict + */ + + RM_TEST_MSG("alloc_audio_sub_out_conflict_2 start..."); + + rm_tc_reset_conflict_num(); + + int handle = 0; + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + rm_device_return_s allocated_devices; + memset(&allocated_devices, 0, sizeof(rm_device_return_s)); + + request.request_num = 1; + + request.category_id[0] = RM_CATEGORY_AUDIO_SUB_OUT; + request.state[0] = RM_STATE_EXCLUSIVE; + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated_devices)); + + EXPECT_EQ(1, allocated_devices.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, allocated_devices.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + int handle2 = 0; + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle2, NULL)); + + memset(&request, 0, sizeof(rm_category_request_s)); + memset(&allocated_devices, 0, sizeof(rm_device_return_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_AUDIO_MAIN_OUT; + request.state[0] = RM_STATE_EXCLUSIVE; + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &request, &allocated_devices)); + + EXPECT_EQ(1, allocated_devices.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_MAIN_OUT, allocated_devices.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("alloc_audio_sub_out_conflict_2 end..."); +} + + +TEST(ut_rm_api, multiview_scaler_to_main_p1) +{ + RM_TEST_MSG("multiview_scaler_to_main_p1 start..."); + + int handle = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_SCALER; + request.category_option[0] = (RM_CATEGORY_SCALER | RM_FORCE_TO_MAIN); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("multiview_scaler_to_main_p1 end..."); +} + +TEST(ut_rm_api, multiview_scaler_to_main_p2) +{ + RM_TEST_MSG("multiview_scaler_to_main_p2 start..."); + + int handle = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_SCALER_SUB; + request.category_option[0] = (RM_CATEGORY_SCALER_SUB | RM_FORCE_TO_MAIN); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("multiview_scaler_to_main_p2 end..."); +} + +TEST(ut_rm_api, multiview_scaler_to_sub_p1) +{ + RM_TEST_MSG("multiview_scaler_to_sub_p1 start..."); + + int handle = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_SCALER; + request.category_option[0] = (RM_CATEGORY_SCALER | RM_FORCE_TO_SUB); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[0])); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("multiview_scaler_to_sub_p1 end..."); +} + +TEST(ut_rm_api, multiview_audio_out_to_main_p1) +{ + RM_TEST_MSG("multiview_audio_out_to_main_p1 start..."); + + int handle = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_AUDIO_MAIN_OUT; + request.category_option[0] = (RM_CATEGORY_AUDIO_MAIN_OUT | RM_FORCE_TO_MAIN); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_MAIN_OUT, allocated.device_id[0]); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("multiview_audio_out_to_main_p1 end..."); +} + +TEST(ut_rm_api, multiview_audio_out_to_main_p2) +{ + RM_TEST_MSG("multiview_audio_out_to_main_p2 start..."); + + int handle = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_AUDIO_MAIN_OUT; + request.category_option[0] = (RM_CATEGORY_AUDIO_MAIN_OUT | RM_FORCE_TO_SUB); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, allocated.device_id[0]); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("multiview_audio_out_to_main_p2 end..."); +} + +TEST(ut_rm_api, multiview_audio_decoder_main_p1) +{ + RM_TEST_MSG("multiview_audio_decoder_main_p1 start..."); + + int handle = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request.category_option[0] = (RM_CATEGORY_AUDIO_DECODER | RM_DEVICE_OPT_MAIN | RM_FORCE_TO_MAIN); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, allocated.device_id[0]); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("multiview_audio_decoder_main_p1 end..."); +} + +TEST(ut_rm_api, multiview_audio_decoder_main_p2) +{ + RM_TEST_MSG("multiview_audio_decoder_main_p2 start..."); + + int handle = 0; + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_AUDIO_DECODER; + request.category_option[0] = (RM_CATEGORY_AUDIO_DECODER | RM_DEVICE_OPT_SUB | RM_FORCE_TO_SUB); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, allocated.device_id[0]); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("multiview_audio_decoder_main_p2 end..."); +} + +TEST(ut_rm_api, rm_active_audio_out_p1) +{ + RM_TEST_MSG("rm_active_audio_out_p1 start..."); + + TCPlayer *player = new TCPlayer(); + EXPECT_EQ(RM_OK, player->Register()); + + EXPECT_EQ(RM_AUDIO_OUT_NONE, player->GetActiveAudioOut()); + + // Allocate audio main out + player->AddResource(RM_CATEGORY_AUDIO_MAIN_OUT, RM_STATE_EXCLUSIVE); + EXPECT_EQ(RM_OK, player->AllocateResources()); + EXPECT_EQ(RM_AUDIO_OUT_MAIN, player->GetActiveAudioOut()); + + // Allocate audio sub out + player->RemoveResources(); + player->AddResource(RM_CATEGORY_AUDIO_SUB_OUT, RM_STATE_EXCLUSIVE); + EXPECT_EQ(RM_OK, player->AllocateResources()); + EXPECT_EQ((RM_AUDIO_OUT_MAIN | RM_AUDIO_OUT_SUB), player->GetActiveAudioOut()); + + // Release audio main & sub out + player->RemoveResources(); + EXPECT_EQ(RM_OK, player->ReleaseResources()); + EXPECT_EQ(RM_AUDIO_OUT_NONE, player->GetActiveAudioOut()); + + // Allocate audio sub out + player->AddResource(RM_CATEGORY_AUDIO_SUB_OUT, RM_STATE_EXCLUSIVE); + EXPECT_EQ(RM_OK, player->AllocateResources()); + EXPECT_EQ(RM_AUDIO_OUT_SUB, player->GetActiveAudioOut()); + + EXPECT_EQ(RM_OK, player->Unregister()); + delete player; + + RM_TEST_MSG("rm_active_audio_out_p1 end..."); +} diff --git a/ut/testcase/ut_tc_multiview_not_support.cpp b/ut/testcase/ut_tc_multiview_not_support.cpp index 2d47a14..36ab5c7 100644 --- a/ut/testcase/ut_tc_multiview_not_support.cpp +++ b/ut/testcase/ut_tc_multiview_not_support.cpp @@ -1,158 +1,158 @@ -/* - * 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" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -TEST(ut_rm_api, alloc_audio_dec_in_mixing_not_supported_model_p1) -{ - /* - * 1. Allocate an Audio decoder with MultiView mixing mode in mixing not supported model (app_id : app1) -> Alloc : No conflict : Main audio decoder - * 2. Allocate an Audio decoder with MultiView mixing mode in mixing not supported model (app_id : app2) -> Alloc : conflict with player1: Main audio decoder - * 3. Allocate a sub Audio decoder with MultiView mixing mode in mixing not supported model (app_id : app3) -> Alloc : No conflict : Sub audio decoder - * 4. Allocate a sub Audio decoder with MultiView mixing mode in mixing not supported model (app_id : app4) -> Alloc : conflict with player3 : Sub audio decoder - */ - - RM_TEST_MSG("alloc_audio_dec_in_mixing_not_supported_model_p1 start..."); - - ri_audio_category_option_request_s audio_option; - memset(&audio_option, 0, sizeof(ri_audio_category_option_request_s)); - - // player1 - audio_option.codec_name = RI_AUDIO_CODEC_NAME_MPEG; - audio_option.mixing_mode = RI_MIXING_MODE_MULTIVIEW; - - TCPlayer *player = new TCPlayer(); - player->AddResource(RM_CATEGORY_AUDIO_DECODER, (ri_get_capable_audio_category_id(&audio_option) | RM_DEVICE_OPT_MAIN), RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player->Register()); - EXPECT_EQ(RM_OK, player->AllocateResources()); - - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, player->GetAllocatedResourceId(1)); - - // player2 - TCPlayer *player2 = new TCPlayer(); - player2->AddResource(RM_CATEGORY_AUDIO_DECODER, ri_get_capable_audio_category_id(&audio_option), RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player2->Register()); - EXPECT_EQ(RM_OK, player2->AllocateResources()); - - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, player2->GetAllocatedResourceId(1)); - EXPECT_EQ(1, player->GetConflictNum()); - - // player3 - TCPlayer *player3 = new TCPlayer(); - player3->AddResource(RM_CATEGORY_AUDIO_DECODER_SUB, (ri_get_capable_audio_category_id(&audio_option) | RM_DEVICE_OPT_SUB), RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player3->Register()); - EXPECT_EQ(RM_OK, player3->AllocateResources()); - - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, player3->GetAllocatedResourceId(1)); - EXPECT_EQ(1, player->GetConflictNum()); - EXPECT_EQ(0, player2->GetConflictNum()); - - // player4 - TCPlayer *player4 = new TCPlayer(); - player4->AddResource(RM_CATEGORY_AUDIO_DECODER_SUB, ri_get_capable_audio_category_id(&audio_option), RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player4->Register()); - EXPECT_EQ(RM_OK, player4->AllocateResources()); - - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, player4->GetAllocatedResourceId(1)); - EXPECT_EQ(1, player->GetConflictNum()); - EXPECT_EQ(0, player2->GetConflictNum()); - EXPECT_EQ(1, player3->GetConflictNum()); - - EXPECT_EQ(RM_OK, player->Unregister()); - EXPECT_EQ(RM_OK, player2->Unregister()); - EXPECT_EQ(RM_OK, player3->Unregister()); - EXPECT_EQ(RM_OK, player4->Unregister()); - - delete player; - delete player2; - delete player3; - delete player4; - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("alloc_audio_dec_in_mixing_not_supported_model_p1 end..."); -} - -TEST(ut_rm_api, allocate_audio_decoder_with_legacy_one_not_support_multiview) -{ - /* - * 1. Allocate a RI_CATEGORY_AUDIO_DECODER -> Alloc : No conflict -> audio main decoder - * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_WMA -> Alloc : conflict with Consumer#1 -> audio main decoder - * 3. Allocate a RI_CATEGORY_AUDIO_DECODER -> Alloc : conflict with Consumer#2 -> audio main decoder - */ - - RM_TEST_MSG("allocate_audio_decoder_with_legacy_one_not_support_multiview start..."); - - TCPlayer *player = new TCPlayer(); - player->AddResource(RM_CATEGORY_AUDIO_DECODER, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player->Register()); - EXPECT_EQ(RM_OK, player->SetAppId("user1")); - EXPECT_EQ(RM_OK, player->AllocateResources()); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, player->GetAllocatedResourceId(1)); - - // As a resource of GetAudioCategory(), RI_CATEGORY_NONE shall be returned because audio mixing is not supported - TCPlayer *player2 = new TCPlayer(); - player2->AddResource(RM_CATEGORY_AUDIO_DECODER, player2->GetAudioCategory(RI_AUDIO_CODEC_NAME_WMA, 0), RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player2->Register()); - EXPECT_EQ(RM_OK, player2->SetAppId("user2")); - EXPECT_EQ(RM_OK, player2->AllocateResources()); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, player2->GetAllocatedResourceId(1)); - - EXPECT_EQ(1, player->GetConflictNum()); - - TCPlayer *player3 = new TCPlayer(); - player3->AddResource(RM_CATEGORY_AUDIO_DECODER, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player3->Register()); - EXPECT_EQ(RM_OK, player3->SetAppId("user3")); - EXPECT_EQ(RM_OK, player3->AllocateResources()); - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, player3->GetAllocatedResourceId(1)); - - EXPECT_EQ(1, player->GetConflictNum()); - EXPECT_EQ(1, player2->GetConflictNum()); - - EXPECT_EQ(RM_OK, player->Unregister()); - EXPECT_EQ(RM_OK, player2->Unregister()); - EXPECT_EQ(RM_OK, player3->Unregister()); - - delete player; - delete player2; - delete player3; - - sleep(RM_TEST_SLEEP_TIME); - - RM_TEST_MSG("allocate_audio_decoder_with_legacy_one_not_support_multiview end..."); -} +/* + * 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" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +TEST(ut_rm_api, alloc_audio_dec_in_mixing_not_supported_model_p1) +{ + /* + * 1. Allocate an Audio decoder with MultiView mixing mode in mixing not supported model (app_id : app1) -> Alloc : No conflict : Main audio decoder + * 2. Allocate an Audio decoder with MultiView mixing mode in mixing not supported model (app_id : app2) -> Alloc : conflict with player1: Main audio decoder + * 3. Allocate a sub Audio decoder with MultiView mixing mode in mixing not supported model (app_id : app3) -> Alloc : No conflict : Sub audio decoder + * 4. Allocate a sub Audio decoder with MultiView mixing mode in mixing not supported model (app_id : app4) -> Alloc : conflict with player3 : Sub audio decoder + */ + + RM_TEST_MSG("alloc_audio_dec_in_mixing_not_supported_model_p1 start..."); + + ri_audio_category_option_request_s audio_option; + memset(&audio_option, 0, sizeof(ri_audio_category_option_request_s)); + + // player1 + audio_option.codec_name = RI_AUDIO_CODEC_NAME_MPEG; + audio_option.mixing_mode = RI_MIXING_MODE_MULTIVIEW; + + TCPlayer *player = new TCPlayer(); + player->AddResource(RM_CATEGORY_AUDIO_DECODER, (ri_get_capable_audio_category_id(&audio_option) | RM_DEVICE_OPT_MAIN), RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player->Register()); + EXPECT_EQ(RM_OK, player->AllocateResources()); + + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, player->GetAllocatedResourceId(1)); + + // player2 + TCPlayer *player2 = new TCPlayer(); + player2->AddResource(RM_CATEGORY_AUDIO_DECODER, ri_get_capable_audio_category_id(&audio_option), RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player2->Register()); + EXPECT_EQ(RM_OK, player2->AllocateResources()); + + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, player2->GetAllocatedResourceId(1)); + EXPECT_EQ(1, player->GetConflictNum()); + + // player3 + TCPlayer *player3 = new TCPlayer(); + player3->AddResource(RM_CATEGORY_AUDIO_DECODER_SUB, (ri_get_capable_audio_category_id(&audio_option) | RM_DEVICE_OPT_SUB), RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player3->Register()); + EXPECT_EQ(RM_OK, player3->AllocateResources()); + + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, player3->GetAllocatedResourceId(1)); + EXPECT_EQ(1, player->GetConflictNum()); + EXPECT_EQ(0, player2->GetConflictNum()); + + // player4 + TCPlayer *player4 = new TCPlayer(); + player4->AddResource(RM_CATEGORY_AUDIO_DECODER_SUB, ri_get_capable_audio_category_id(&audio_option), RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player4->Register()); + EXPECT_EQ(RM_OK, player4->AllocateResources()); + + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER_SUB, player4->GetAllocatedResourceId(1)); + EXPECT_EQ(1, player->GetConflictNum()); + EXPECT_EQ(0, player2->GetConflictNum()); + EXPECT_EQ(1, player3->GetConflictNum()); + + EXPECT_EQ(RM_OK, player->Unregister()); + EXPECT_EQ(RM_OK, player2->Unregister()); + EXPECT_EQ(RM_OK, player3->Unregister()); + EXPECT_EQ(RM_OK, player4->Unregister()); + + delete player; + delete player2; + delete player3; + delete player4; + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("alloc_audio_dec_in_mixing_not_supported_model_p1 end..."); +} + +TEST(ut_rm_api, allocate_audio_decoder_with_legacy_one_not_support_multiview) +{ + /* + * 1. Allocate a RI_CATEGORY_AUDIO_DECODER -> Alloc : No conflict -> audio main decoder + * 2. Allocate a RI_CATEGORY_AUDIO_DECODER_WMA -> Alloc : conflict with Consumer#1 -> audio main decoder + * 3. Allocate a RI_CATEGORY_AUDIO_DECODER -> Alloc : conflict with Consumer#2 -> audio main decoder + */ + + RM_TEST_MSG("allocate_audio_decoder_with_legacy_one_not_support_multiview start..."); + + TCPlayer *player = new TCPlayer(); + player->AddResource(RM_CATEGORY_AUDIO_DECODER, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player->Register()); + EXPECT_EQ(RM_OK, player->SetAppId("user1")); + EXPECT_EQ(RM_OK, player->AllocateResources()); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, player->GetAllocatedResourceId(1)); + + // As a resource of GetAudioCategory(), RI_CATEGORY_NONE shall be returned because audio mixing is not supported + TCPlayer *player2 = new TCPlayer(); + player2->AddResource(RM_CATEGORY_AUDIO_DECODER, player2->GetAudioCategory(RI_AUDIO_CODEC_NAME_WMA, 0), RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player2->Register()); + EXPECT_EQ(RM_OK, player2->SetAppId("user2")); + EXPECT_EQ(RM_OK, player2->AllocateResources()); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, player2->GetAllocatedResourceId(1)); + + EXPECT_EQ(1, player->GetConflictNum()); + + TCPlayer *player3 = new TCPlayer(); + player3->AddResource(RM_CATEGORY_AUDIO_DECODER, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player3->Register()); + EXPECT_EQ(RM_OK, player3->SetAppId("user3")); + EXPECT_EQ(RM_OK, player3->AllocateResources()); + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, player3->GetAllocatedResourceId(1)); + + EXPECT_EQ(1, player->GetConflictNum()); + EXPECT_EQ(1, player2->GetConflictNum()); + + EXPECT_EQ(RM_OK, player->Unregister()); + EXPECT_EQ(RM_OK, player2->Unregister()); + EXPECT_EQ(RM_OK, player3->Unregister()); + + delete player; + delete player2; + delete player3; + + sleep(RM_TEST_SLEEP_TIME); + + RM_TEST_MSG("allocate_audio_decoder_with_legacy_one_not_support_multiview end..."); +} diff --git a/ut/testcase/ut_tc_resource.cpp b/ut/testcase/ut_tc_resource.cpp index f79eb6d..f4f1c1c 100644 --- a/ut/testcase/ut_tc_resource.cpp +++ b/ut/testcase/ut_tc_resource.cpp @@ -1,676 +1,676 @@ -/* - * 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" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - - -TEST(ut_rm_api, rm_rsc_state_p1) -{ - RM_TEST_MSG("rm_rsc_state_p1 start..."); - - rm_resource_state_e state; - int ret = rm_get_resource_state(RM_DEVICE_AUDIO_ENCODER, &state); - - EXPECT_EQ(RM_OK, ret); - EXPECT_EQ(RM_RSC_STATE_FREE, state); - - RM_TEST_MSG("rm_rsc_state_p1 end..."); -} - -TEST(ut_rm_api, rm_rsc_state_n1) -{ - RM_TEST_MSG("rm_rsc_state_n1 start..."); - - rm_resource_state_e state; - int ret = rm_get_resource_state(9999999, &state); - - EXPECT_NE(RM_OK, ret); - - RM_TEST_MSG("rm_rsc_state_n1 end..."); -} - -TEST(ut_rm_api, rm_rsc_state_n2) -{ - RM_TEST_MSG("rm_rsc_state_n2 start..."); - - rm_resource_state_e state; - int ret = rm_get_resource_state(-1, &state); - - EXPECT_NE(RM_OK, ret); - - RM_TEST_MSG("rm_rsc_state_n2 end..."); -} - -TEST(ut_rm_api, rm_rsc_state_n3) -{ - RM_TEST_MSG("rm_rsc_state_n2 start..."); - - int ret = rm_get_resource_state(RM_DEVICE_AUDIO_ENCODER, NULL); - - EXPECT_NE(RM_OK, ret); - - RM_TEST_MSG("rm_rsc_state_n3 end..."); -} - -TEST(ut_rm_api, rm_rsc_get_resource_list_p1) -{ - RM_TEST_MSG("rm_rsc_get_resource_list_p1 start..."); - - rm_resource_list_h rsc_list; - int ret = rm_get_resource_list(RM_CATEGORY_DEMUX, &rsc_list); - - EXPECT_EQ(RM_OK, ret); - - rm_resource_h resource; - EXPECT_EQ(6, rm_resource_list_get_count(rsc_list)); - - resource = rm_resource_list_get_first(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX0, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux0", rm_resource_get_node(resource)); - - resource = rm_resource_list_get_next(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX1, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux1", rm_resource_get_node(resource)); - - resource = rm_resource_list_get_next(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX2, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux2", rm_resource_get_node(resource)); - - resource = rm_resource_list_get_next(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX3, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux3", rm_resource_get_node(resource)); - - resource = rm_resource_list_get_next(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX4, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux4", rm_resource_get_node(resource)); - - resource = rm_resource_list_get_next(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX5, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux5", rm_resource_get_node(resource)); - - EXPECT_EQ(0, rm_resource_list_get_next(rsc_list)); - - resource = rm_resource_list_get_last(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX5, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux5", rm_resource_get_node(resource)); - - resource = rm_resource_list_get_prev(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX4, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux4", rm_resource_get_node(resource)); - - resource = rm_resource_list_get_prev(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX3, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux3", rm_resource_get_node(resource)); - - resource = rm_resource_list_get_prev(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX2, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux2", rm_resource_get_node(resource)); - - resource = rm_resource_list_get_prev(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX1, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux1", rm_resource_get_node(resource)); - - resource = rm_resource_list_get_prev(rsc_list); - EXPECT_EQ(RM_DEVICE_DEMUX0, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dvb/adapter0/demux0", rm_resource_get_node(resource)); - - EXPECT_EQ(0, rm_resource_list_get_prev(rsc_list)); - - rm_free_resource_list(rsc_list); - - RM_TEST_MSG("rm_rsc_get_resource_list_p1 end..."); -} - -TEST(ut_rm_api, rm_rsc_get_resource_list_p2) -{ - RM_TEST_MSG("rm_rsc_get_resource_list_p2 start..."); - - TCPlayer *player = new TCPlayer(); - player->AddResource(RM_CATEGORY_SCALER, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player->Register()); - EXPECT_EQ(RM_OK, player->AllocateResources()); - - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, player->GetAllocatedResourceId(1)); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(player->GetAllocatedResourceId(1))); - - rm_resource_list_h rsc_list; - int ret = rm_get_resource_list(RM_CATEGORY_SCALER, &rsc_list); - - EXPECT_EQ(RM_OK, ret); - - rm_resource_h resource; - EXPECT_EQ(1, rm_resource_list_get_count(rsc_list)); - resource = rm_resource_list_get_first(rsc_list); - EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dri/card0", rm_resource_get_node(resource)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, rm_resource_get_state(resource)); - - EXPECT_EQ(0, rm_resource_list_get_next(rsc_list)); - - resource = rm_resource_list_get_last(rsc_list); - EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dri/card0", rm_resource_get_node(resource)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, rm_resource_get_state(resource)); - - EXPECT_EQ(0, rm_resource_list_get_prev(rsc_list)); - - rm_free_resource_list(rsc_list); - - EXPECT_EQ(RM_OK, player->Unregister()); - delete player; - - ret = rm_get_resource_list(RM_CATEGORY_SCALER, &rsc_list); - EXPECT_EQ(RM_OK, ret); - - EXPECT_EQ(1, rm_resource_list_get_count(rsc_list)); - resource = rm_resource_list_get_first(rsc_list); - EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dri/card0", rm_resource_get_node(resource)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); - - EXPECT_EQ(0, rm_resource_list_get_next(rsc_list)); - - resource = rm_resource_list_get_last(rsc_list); - EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); - EXPECT_STREQ("/dev/dri/card0", rm_resource_get_node(resource)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); - - EXPECT_EQ(0, rm_resource_list_get_prev(rsc_list)); - - rm_free_resource_list(rsc_list); - - RM_TEST_MSG("rm_rsc_get_resource_list_p2 end..."); -} - -TEST(ut_rm_api, rm_rsc_get_resource_list_p3) -{ - if (!is_support_audio_dual_decoding()) - return; - - RM_TEST_MSG("rm_rsc_get_resource_list_p3 start..."); - - rm_resource_list_h rsc_list; - int ret = rm_get_resource_list(RM_CATEGORY_AUDIO_SUB_OUT, &rsc_list); - - EXPECT_EQ(RM_OK, ret); - - rm_resource_h resource; - EXPECT_EQ(1, rm_resource_list_get_count(rsc_list)); - resource = rm_resource_list_get_first(rsc_list); - EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, rm_resource_get_id(resource)); - EXPECT_STREQ("", rm_resource_get_app_id(resource)); - EXPECT_EQ(0, rm_resource_list_get_next(rsc_list)); - - resource = rm_resource_list_get_last(rsc_list); - EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, rm_resource_get_id(resource)); - - EXPECT_EQ(0, rm_resource_list_get_prev(rsc_list)); - - rm_free_resource_list(rsc_list); - - RM_TEST_MSG("rm_rsc_get_resource_list_p3 end..."); -} - -TEST(ut_rm_api, rm_rsc_get_resource_list_p4) -{ - if (!is_support_audio_dual_decoding()) - return; - - RM_TEST_MSG("rm_rsc_get_resource_list_p4 start..."); - - TCPlayer *player = new TCPlayer(); - player->AddResource(RM_CATEGORY_AUDIO_SUB_OUT, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player->Register()); - EXPECT_EQ(RM_OK, player->SetAppId("org.tizen.viewer")); - EXPECT_EQ(RM_OK, player->AllocateResources()); - - EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, player->GetAllocatedResourceId(1)); - - rm_resource_list_h rsc_list; - int ret = rm_get_resource_list(RM_CATEGORY_AUDIO_SUB_OUT, &rsc_list); - - EXPECT_EQ(RM_OK, ret); - - rm_resource_h resource; - EXPECT_EQ(1, rm_resource_list_get_count(rsc_list)); - resource = rm_resource_list_get_first(rsc_list); - EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, rm_resource_get_id(resource)); - EXPECT_STREQ("org.tizen.viewer", rm_resource_get_app_id(resource)); - EXPECT_EQ(0, rm_resource_list_get_next(rsc_list)); - - resource = rm_resource_list_get_last(rsc_list); - EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, rm_resource_get_id(resource)); - - EXPECT_EQ(0, rm_resource_list_get_prev(rsc_list)); - - rm_free_resource_list(rsc_list); - - EXPECT_EQ(RM_OK, player->Unregister()); - delete player; - - RM_TEST_MSG("rm_rsc_get_resource_list_p4 end..."); -} - - -TEST(ut_rm_api, rm_rsc_get_resource_list_n1) -{ - RM_TEST_MSG("rm_rsc_get_resource_list_n1 start..."); - - rm_resource_list_h rsc_list; - int ret = rm_get_resource_list((rm_rsc_category_e) -10, &rsc_list); - - EXPECT_EQ(RM_OK, ret); - rm_free_resource_list(rsc_list); - - RM_TEST_MSG("rm_rsc_get_resource_list_n1 end..."); -} - -TEST(ut_rm_api, rm_rsc_get_resource_list_n2) -{ - RM_TEST_MSG("rm_rsc_get_resource_list_n2 start..."); - - int ret = rm_get_resource_list(RM_CATEGORY_DEMUX, NULL); - - EXPECT_NE(RM_OK, ret); - - RM_TEST_MSG("rm_rsc_get_resource_list_n2 end..."); -} - -TEST(ut_rm_api, rm_resource_get_id_n1) -{ - RM_TEST_MSG("rm_resource_get_id_n1 start..."); - EXPECT_EQ(-1, rm_resource_get_id(NULL)); - RM_TEST_MSG("rm_resource_get_id_n1 end..."); -} - -TEST(ut_rm_api, rm_resource_get_node_n1) -{ - RM_TEST_MSG("rm_resource_get_node_n1 start..."); - EXPECT_EQ(0, rm_resource_get_node(NULL)); - RM_TEST_MSG("rm_resource_get_node_n1 end..."); -} - -TEST(ut_rm_api, rm_resource_list_get_prev_n1) -{ - RM_TEST_MSG("rm_resource_list_get_prev_n1 start..."); - EXPECT_EQ(0, rm_resource_list_get_prev(NULL)); - rm_resource_list_h list = NULL; - EXPECT_EQ(0, rm_resource_list_get_prev(list)); - RM_TEST_MSG("rm_resource_list_get_prev_n1 end..."); -} - -TEST(ut_rm_api, rm_get_resource_collection_state_p1) -{ - RM_TEST_MSG("rm_get_resource_collection_state_p1 start..."); - - rm_resource_list_h rsc_list = NULL; - - EXPECT_EQ(0, rm_get_resource_collection_state(RM_RSC_COLLECTION_MAIN, &rsc_list)); - - // MFD0, DVDE0, MAIN SCALER, MAIN AUDIO DECODER, MAIN AUDIO OUT - EXPECT_EQ(5, rm_resource_list_get_count(rsc_list)); - - rm_resource_h resource = rm_resource_list_get_first(rsc_list); - - EXPECT_EQ(RM_DEVICE_AUDIO_MAIN_OUT, rm_resource_get_id(resource)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); - EXPECT_EQ(-1, rm_resource_get_consumer(resource)); - EXPECT_STREQ("", rm_resource_get_app_id(resource)); - EXPECT_EQ(RM_CATEGORY_AUDIO_MAIN_OUT, rm_resource_get_category(resource)); - - resource = rm_resource_list_get_next(rsc_list); - - EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); - EXPECT_EQ(-1, rm_resource_get_consumer(resource)); - EXPECT_STREQ("", rm_resource_get_app_id(resource)); - EXPECT_EQ(RM_CATEGORY_SCALER, rm_resource_get_category(resource)); - - resource = rm_resource_list_get_next(rsc_list); - - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, rm_resource_get_id(resource)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); - EXPECT_EQ(-1, rm_resource_get_consumer(resource)); - EXPECT_STREQ("", rm_resource_get_app_id(resource)); - EXPECT_EQ(RM_CATEGORY_AUDIO_DECODER, rm_resource_get_category(resource)); - - resource = rm_resource_list_get_next(rsc_list); - - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_MAIN, rm_resource_get_id(resource)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); - EXPECT_EQ(-1, rm_resource_get_consumer(resource)); - EXPECT_STREQ("", rm_resource_get_app_id(resource)); - EXPECT_LE(RM_CATEGORY_VIDEO_DECODER, rm_resource_get_category(resource)); - - resource = rm_resource_list_get_next(rsc_list); - - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_DVDE0, rm_resource_get_id(resource)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); - EXPECT_EQ(-1, rm_resource_get_consumer(resource)); - EXPECT_STREQ("", rm_resource_get_app_id(resource)); - EXPECT_LE(RM_CATEGORY_VIDEO_DECODER_UHD, rm_resource_get_category(resource)); - - rm_free_resource_list(rsc_list); - - RM_TEST_MSG("rm_get_resource_collection_state_p1 end..."); -} - -TEST(ut_rm_api, rm_get_resource_collection_state_p2) -{ - RM_TEST_MSG("rm_get_resource_collection_state_p2 start..."); - - int handle = 0; - const char *app_id = "org.tizen.test"; - EXPECT_EQ(0, rm_register(rm_cb_set_conflict_flag, NULL, &handle, NULL)); - EXPECT_EQ(0, rm_set_app_id(handle, (char*) app_id)); - - rm_category_request_s req; - memset(&req, 0, sizeof(req)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(allocated)); - - EXPECT_EQ(0, rm_allocate_resources(handle, &req, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - - rm_resource_list_h rsc_list = NULL; - - EXPECT_EQ(0, rm_get_resource_collection_state(RM_RSC_COLLECTION_MAIN, &rsc_list)); - - // MFD0, DVDE0, MAIN SCALER, MAIN AUDIO DECODER, MAIN AUDIO OUT - EXPECT_EQ(5, rm_resource_list_get_count(rsc_list)); - - rm_resource_h resource = rm_resource_list_get_first(rsc_list); - - EXPECT_EQ(RM_DEVICE_AUDIO_MAIN_OUT, rm_resource_get_id(resource)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); - EXPECT_EQ(-1, rm_resource_get_consumer(resource)); - EXPECT_STREQ("", rm_resource_get_app_id(resource)); - EXPECT_EQ(RM_CATEGORY_AUDIO_MAIN_OUT, rm_resource_get_category(resource)); - - resource = rm_resource_list_get_next(rsc_list); - - EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, rm_resource_get_state(resource)); - EXPECT_EQ(handle, rm_resource_get_consumer(resource)); - EXPECT_STREQ(app_id, rm_resource_get_app_id(resource)); - EXPECT_EQ(RM_CATEGORY_SCALER, rm_resource_get_category(resource)); - - resource = rm_resource_list_get_next(rsc_list); - - EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, rm_resource_get_id(resource)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); - EXPECT_EQ(-1, rm_resource_get_consumer(resource)); - EXPECT_STREQ("", rm_resource_get_app_id(resource)); - EXPECT_EQ(RM_CATEGORY_AUDIO_DECODER, rm_resource_get_category(resource)); - - resource = rm_resource_list_get_next(rsc_list); - - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_MAIN, rm_resource_get_id(resource)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); - EXPECT_EQ(-1, rm_resource_get_consumer(resource)); - EXPECT_STREQ("", rm_resource_get_app_id(resource)); - EXPECT_LE(RM_CATEGORY_VIDEO_DECODER, rm_resource_get_category(resource)); - - resource = rm_resource_list_get_next(rsc_list); - - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_DVDE0, rm_resource_get_id(resource)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); - EXPECT_EQ(-1, rm_resource_get_consumer(resource)); - EXPECT_STREQ("", rm_resource_get_app_id(resource)); - EXPECT_LE(RM_CATEGORY_VIDEO_DECODER_UHD, rm_resource_get_category(resource)); - - rm_free_resource_list(rsc_list); - - EXPECT_EQ(0, rm_unregister(handle)); - - RM_TEST_MSG("rm_get_resource_collection_state_p2 end..."); -} - - -static void tc_resource_state_change_cb1(rm_resource_state_h state, void *data) -{ - -} - -static void tc_resource_state_change_cb2(rm_resource_state_h state, void *data) -{ - -} - -static void tc_resource_state_change_cb3(rm_resource_state_h state, void *data) -{ - -} - -TEST(ut_rm_api, rm_resource_state_change_p1) -{ - RM_TEST_MSG("rm_resource_state_change_p1 start..."); - - EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1, NULL)); - EXPECT_EQ(RM_ERROR, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1, NULL)); - EXPECT_EQ(RM_ERROR, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1, NULL)); - EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb2, NULL)); - EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb3, NULL)); - - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb3)); - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb2)); - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1)); - - RM_TEST_MSG("rm_resource_state_change_p1 end..."); -} - -TEST(ut_rm_api, rm_resource_state_change_p2) -{ - RM_TEST_MSG("rm_resource_state_change_p2 start..."); - - EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1, NULL)); - EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER, tc_resource_state_change_cb1, NULL)); - EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER_BG, tc_resource_state_change_cb1, NULL)); - EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER_SUB, tc_resource_state_change_cb1, NULL)); - - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1)); - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER, tc_resource_state_change_cb1)); - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_BG, tc_resource_state_change_cb1)); - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_SUB, tc_resource_state_change_cb1)); - - RM_TEST_MSG("rm_resource_state_change_p2 end..."); -} - -TEST(ut_rm_api, rm_resource_state_change_p3) -{ - RM_TEST_MSG("rm_resource_state_change_p3 start..."); - - EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1)); - EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER, tc_resource_state_change_cb1)); - EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_BG, tc_resource_state_change_cb1)); - EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_SUB, tc_resource_state_change_cb1)); - - EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1, NULL)); - EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER, tc_resource_state_change_cb1, NULL)); - EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER_BG, tc_resource_state_change_cb1, NULL)); - EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER_SUB, tc_resource_state_change_cb1, NULL)); - - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1)); - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER, tc_resource_state_change_cb1)); - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_BG, tc_resource_state_change_cb1)); - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_SUB, tc_resource_state_change_cb1)); - - RM_TEST_MSG("rm_resource_state_change_p3 end..."); -} - -TEST(ut_rm_api, rm_resource_state_change_n1) -{ - RM_TEST_MSG("rm_resource_state_change_n1 start..."); - - EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, NULL)); - EXPECT_EQ(RM_ERROR, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, NULL, NULL)); - - RM_TEST_MSG("rm_resource_state_change_n1 end..."); -} - -typedef struct{ - char *app_id; - int consumer_id; - int device_id; - int category_id; -} expected_conflict_event; - -void conflict_event_cb(rm_conflict_resource_h resource, void *data) -{ - RM_TEST_MSG("conflict event cb invoked!"); - if (!data) - return; - - expected_conflict_event *expected = (expected_conflict_event*) data; - - EXPECT_EQ(expected->category_id, rm_conflict_get_category_id(resource)); - EXPECT_EQ(expected->device_id, rm_conflict_get_device_id(resource)); - EXPECT_EQ(expected->consumer_id, rm_conflict_get_consumer_id(resource)); - EXPECT_STREQ(expected->app_id, rm_conflict_get_app_id(resource)); -} - -void conflict_event_cb2(rm_conflict_resource_h resource, void *data) -{ - -} - -TEST(ut_rm_api, rm_conflict_event_cb_p1) -{ - RM_TEST_MSG("rm_conflict_event_cb_p1 start..."); - - EXPECT_EQ(RM_OK, rm_subscribe_resource_conflict_event(conflict_event_cb, NULL)); - EXPECT_EQ(RM_ERROR, rm_subscribe_resource_conflict_event(conflict_event_cb, NULL)); - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_conflict_event(conflict_event_cb)); - EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_conflict_event(conflict_event_cb)); - - RM_TEST_MSG("rm_conflict_event_cb_p1 end..."); -} - - -rm_cb_result resource_conflict_cb(int handle, rm_callback_type event, rm_device_request_s *info, void *data) -{ - RM_TEST_MSG("resource conflict cb invoked!"); - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); - return RM_CB_RESULT_OK; -} - -TEST(ut_rm_api, rm_conflict_event_cb_p2) -{ - RM_TEST_MSG("rm_conflict_event_cb_p2 start..."); - - int handle1 = 0; - rm_consumer_info *consumer_info1 = (rm_consumer_info*) calloc(1, sizeof(rm_consumer_info)); - snprintf(consumer_info1->app_id, 1024, "%s", "org.tizen.rm.test"); - - EXPECT_EQ(RM_OK, rm_register(resource_conflict_cb, NULL, &handle1, consumer_info1)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_JPEG_DECODER; - request.category_option[0] = ri_get_sub_jpeg_category_id("JPEG", 7680, 4320); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, &request, &allocated)); - - expected_conflict_event *expected = (expected_conflict_event*) calloc(1, sizeof(expected_conflict_event)); - expected->app_id = strdup("org.tizen.rm.test"); - - if (use_unified_jpeg_decoder()) - expected->category_id = RM_CATEGORY_JPEG_DECODER_8K; - else if (is_oscars_unified_jpeg_decoder()) - expected->category_id = RM_CATEGORY_JPEG_DECODER; - else - expected->category_id = RM_CATEGORY_JPEG_DECODER_UHD; - - expected->consumer_id = handle1; - expected->device_id = allocated.device_id[0]; - EXPECT_EQ(RM_OK, rm_subscribe_resource_conflict_event(conflict_event_cb, (void*) expected)); - - int handle2 = 0; - EXPECT_EQ(RM_OK, rm_register(resource_conflict_cb, NULL, &handle2, NULL)); - - memset(&request, 0, sizeof(rm_category_request_s)); - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_JPEG_DECODER; - request.category_option[0] = ri_get_sub_jpeg_category_id("JPEG", 7680, 4320); - request.state[0] = RM_STATE_EXCLUSIVE; - - memset(&allocated, 0, sizeof(rm_device_return_s)); - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &request, &allocated)); - - sleep(5); - - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_conflict_event(conflict_event_cb)); - - free(consumer_info1); - consumer_info1 = NULL; - - EXPECT_EQ(RM_OK, rm_unregister(handle1)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - - RM_TEST_MSG("rm_conflict_event_cb_p2 end..."); -} - -TEST(ut_rm_api, rm_conflict_event_cb_n1) -{ - RM_TEST_MSG("rm_conflict_event_cb_n1 start..."); - - EXPECT_EQ(RM_ERROR, rm_subscribe_resource_conflict_event(NULL, NULL)); - EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_conflict_event(NULL)); - - RM_TEST_MSG("rm_conflict_event_cb_n1 end..."); -} - -TEST(ut_rm_api, rm_conflict_event_cb_p3) -{ - RM_TEST_MSG("rm_conflict_event_cb_p3 start..."); - - EXPECT_EQ(RM_OK, rm_subscribe_resource_conflict_event(conflict_event_cb, NULL)); - EXPECT_EQ(RM_OK, rm_subscribe_resource_conflict_event(conflict_event_cb2, NULL)); - - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_conflict_event(conflict_event_cb2)); - EXPECT_EQ(RM_OK, rm_unsubscribe_resource_conflict_event(conflict_event_cb)); - - RM_TEST_MSG("rm_conflict_event_cb_p3 end..."); -} +/* + * 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" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +TEST(ut_rm_api, rm_rsc_state_p1) +{ + RM_TEST_MSG("rm_rsc_state_p1 start..."); + + rm_resource_state_e state; + int ret = rm_get_resource_state(RM_DEVICE_AUDIO_ENCODER, &state); + + EXPECT_EQ(RM_OK, ret); + EXPECT_EQ(RM_RSC_STATE_FREE, state); + + RM_TEST_MSG("rm_rsc_state_p1 end..."); +} + +TEST(ut_rm_api, rm_rsc_state_n1) +{ + RM_TEST_MSG("rm_rsc_state_n1 start..."); + + rm_resource_state_e state; + int ret = rm_get_resource_state(9999999, &state); + + EXPECT_NE(RM_OK, ret); + + RM_TEST_MSG("rm_rsc_state_n1 end..."); +} + +TEST(ut_rm_api, rm_rsc_state_n2) +{ + RM_TEST_MSG("rm_rsc_state_n2 start..."); + + rm_resource_state_e state; + int ret = rm_get_resource_state(-1, &state); + + EXPECT_NE(RM_OK, ret); + + RM_TEST_MSG("rm_rsc_state_n2 end..."); +} + +TEST(ut_rm_api, rm_rsc_state_n3) +{ + RM_TEST_MSG("rm_rsc_state_n2 start..."); + + int ret = rm_get_resource_state(RM_DEVICE_AUDIO_ENCODER, NULL); + + EXPECT_NE(RM_OK, ret); + + RM_TEST_MSG("rm_rsc_state_n3 end..."); +} + +TEST(ut_rm_api, rm_rsc_get_resource_list_p1) +{ + RM_TEST_MSG("rm_rsc_get_resource_list_p1 start..."); + + rm_resource_list_h rsc_list; + int ret = rm_get_resource_list(RM_CATEGORY_DEMUX, &rsc_list); + + EXPECT_EQ(RM_OK, ret); + + rm_resource_h resource; + EXPECT_EQ(6, rm_resource_list_get_count(rsc_list)); + + resource = rm_resource_list_get_first(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX0, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux0", rm_resource_get_node(resource)); + + resource = rm_resource_list_get_next(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX1, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux1", rm_resource_get_node(resource)); + + resource = rm_resource_list_get_next(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX2, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux2", rm_resource_get_node(resource)); + + resource = rm_resource_list_get_next(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX3, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux3", rm_resource_get_node(resource)); + + resource = rm_resource_list_get_next(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX4, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux4", rm_resource_get_node(resource)); + + resource = rm_resource_list_get_next(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX5, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux5", rm_resource_get_node(resource)); + + EXPECT_EQ(0, rm_resource_list_get_next(rsc_list)); + + resource = rm_resource_list_get_last(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX5, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux5", rm_resource_get_node(resource)); + + resource = rm_resource_list_get_prev(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX4, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux4", rm_resource_get_node(resource)); + + resource = rm_resource_list_get_prev(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX3, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux3", rm_resource_get_node(resource)); + + resource = rm_resource_list_get_prev(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX2, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux2", rm_resource_get_node(resource)); + + resource = rm_resource_list_get_prev(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX1, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux1", rm_resource_get_node(resource)); + + resource = rm_resource_list_get_prev(rsc_list); + EXPECT_EQ(RM_DEVICE_DEMUX0, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dvb/adapter0/demux0", rm_resource_get_node(resource)); + + EXPECT_EQ(0, rm_resource_list_get_prev(rsc_list)); + + rm_free_resource_list(rsc_list); + + RM_TEST_MSG("rm_rsc_get_resource_list_p1 end..."); +} + +TEST(ut_rm_api, rm_rsc_get_resource_list_p2) +{ + RM_TEST_MSG("rm_rsc_get_resource_list_p2 start..."); + + TCPlayer *player = new TCPlayer(); + player->AddResource(RM_CATEGORY_SCALER, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player->Register()); + EXPECT_EQ(RM_OK, player->AllocateResources()); + + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, player->GetAllocatedResourceId(1)); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(player->GetAllocatedResourceId(1))); + + rm_resource_list_h rsc_list; + int ret = rm_get_resource_list(RM_CATEGORY_SCALER, &rsc_list); + + EXPECT_EQ(RM_OK, ret); + + rm_resource_h resource; + EXPECT_EQ(1, rm_resource_list_get_count(rsc_list)); + resource = rm_resource_list_get_first(rsc_list); + EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dri/card0", rm_resource_get_node(resource)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, rm_resource_get_state(resource)); + + EXPECT_EQ(0, rm_resource_list_get_next(rsc_list)); + + resource = rm_resource_list_get_last(rsc_list); + EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dri/card0", rm_resource_get_node(resource)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, rm_resource_get_state(resource)); + + EXPECT_EQ(0, rm_resource_list_get_prev(rsc_list)); + + rm_free_resource_list(rsc_list); + + EXPECT_EQ(RM_OK, player->Unregister()); + delete player; + + ret = rm_get_resource_list(RM_CATEGORY_SCALER, &rsc_list); + EXPECT_EQ(RM_OK, ret); + + EXPECT_EQ(1, rm_resource_list_get_count(rsc_list)); + resource = rm_resource_list_get_first(rsc_list); + EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dri/card0", rm_resource_get_node(resource)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); + + EXPECT_EQ(0, rm_resource_list_get_next(rsc_list)); + + resource = rm_resource_list_get_last(rsc_list); + EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); + EXPECT_STREQ("/dev/dri/card0", rm_resource_get_node(resource)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); + + EXPECT_EQ(0, rm_resource_list_get_prev(rsc_list)); + + rm_free_resource_list(rsc_list); + + RM_TEST_MSG("rm_rsc_get_resource_list_p2 end..."); +} + +TEST(ut_rm_api, rm_rsc_get_resource_list_p3) +{ + if (!is_support_audio_dual_decoding()) + return; + + RM_TEST_MSG("rm_rsc_get_resource_list_p3 start..."); + + rm_resource_list_h rsc_list; + int ret = rm_get_resource_list(RM_CATEGORY_AUDIO_SUB_OUT, &rsc_list); + + EXPECT_EQ(RM_OK, ret); + + rm_resource_h resource; + EXPECT_EQ(1, rm_resource_list_get_count(rsc_list)); + resource = rm_resource_list_get_first(rsc_list); + EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, rm_resource_get_id(resource)); + EXPECT_STREQ("", rm_resource_get_app_id(resource)); + EXPECT_EQ(0, rm_resource_list_get_next(rsc_list)); + + resource = rm_resource_list_get_last(rsc_list); + EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, rm_resource_get_id(resource)); + + EXPECT_EQ(0, rm_resource_list_get_prev(rsc_list)); + + rm_free_resource_list(rsc_list); + + RM_TEST_MSG("rm_rsc_get_resource_list_p3 end..."); +} + +TEST(ut_rm_api, rm_rsc_get_resource_list_p4) +{ + if (!is_support_audio_dual_decoding()) + return; + + RM_TEST_MSG("rm_rsc_get_resource_list_p4 start..."); + + TCPlayer *player = new TCPlayer(); + player->AddResource(RM_CATEGORY_AUDIO_SUB_OUT, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player->Register()); + EXPECT_EQ(RM_OK, player->SetAppId("org.tizen.viewer")); + EXPECT_EQ(RM_OK, player->AllocateResources()); + + EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, player->GetAllocatedResourceId(1)); + + rm_resource_list_h rsc_list; + int ret = rm_get_resource_list(RM_CATEGORY_AUDIO_SUB_OUT, &rsc_list); + + EXPECT_EQ(RM_OK, ret); + + rm_resource_h resource; + EXPECT_EQ(1, rm_resource_list_get_count(rsc_list)); + resource = rm_resource_list_get_first(rsc_list); + EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, rm_resource_get_id(resource)); + EXPECT_STREQ("org.tizen.viewer", rm_resource_get_app_id(resource)); + EXPECT_EQ(0, rm_resource_list_get_next(rsc_list)); + + resource = rm_resource_list_get_last(rsc_list); + EXPECT_EQ(RM_DEVICE_AUDIO_SUB_OUT, rm_resource_get_id(resource)); + + EXPECT_EQ(0, rm_resource_list_get_prev(rsc_list)); + + rm_free_resource_list(rsc_list); + + EXPECT_EQ(RM_OK, player->Unregister()); + delete player; + + RM_TEST_MSG("rm_rsc_get_resource_list_p4 end..."); +} + + +TEST(ut_rm_api, rm_rsc_get_resource_list_n1) +{ + RM_TEST_MSG("rm_rsc_get_resource_list_n1 start..."); + + rm_resource_list_h rsc_list; + int ret = rm_get_resource_list((rm_rsc_category_e) -10, &rsc_list); + + EXPECT_EQ(RM_OK, ret); + rm_free_resource_list(rsc_list); + + RM_TEST_MSG("rm_rsc_get_resource_list_n1 end..."); +} + +TEST(ut_rm_api, rm_rsc_get_resource_list_n2) +{ + RM_TEST_MSG("rm_rsc_get_resource_list_n2 start..."); + + int ret = rm_get_resource_list(RM_CATEGORY_DEMUX, NULL); + + EXPECT_NE(RM_OK, ret); + + RM_TEST_MSG("rm_rsc_get_resource_list_n2 end..."); +} + +TEST(ut_rm_api, rm_resource_get_id_n1) +{ + RM_TEST_MSG("rm_resource_get_id_n1 start..."); + EXPECT_EQ(-1, rm_resource_get_id(NULL)); + RM_TEST_MSG("rm_resource_get_id_n1 end..."); +} + +TEST(ut_rm_api, rm_resource_get_node_n1) +{ + RM_TEST_MSG("rm_resource_get_node_n1 start..."); + EXPECT_EQ(0, rm_resource_get_node(NULL)); + RM_TEST_MSG("rm_resource_get_node_n1 end..."); +} + +TEST(ut_rm_api, rm_resource_list_get_prev_n1) +{ + RM_TEST_MSG("rm_resource_list_get_prev_n1 start..."); + EXPECT_EQ(0, rm_resource_list_get_prev(NULL)); + rm_resource_list_h list = NULL; + EXPECT_EQ(0, rm_resource_list_get_prev(list)); + RM_TEST_MSG("rm_resource_list_get_prev_n1 end..."); +} + +TEST(ut_rm_api, rm_get_resource_collection_state_p1) +{ + RM_TEST_MSG("rm_get_resource_collection_state_p1 start..."); + + rm_resource_list_h rsc_list = NULL; + + EXPECT_EQ(0, rm_get_resource_collection_state(RM_RSC_COLLECTION_MAIN, &rsc_list)); + + // MFD0, DVDE0, MAIN SCALER, MAIN AUDIO DECODER, MAIN AUDIO OUT + EXPECT_EQ(5, rm_resource_list_get_count(rsc_list)); + + rm_resource_h resource = rm_resource_list_get_first(rsc_list); + + EXPECT_EQ(RM_DEVICE_AUDIO_MAIN_OUT, rm_resource_get_id(resource)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); + EXPECT_EQ(-1, rm_resource_get_consumer(resource)); + EXPECT_STREQ("", rm_resource_get_app_id(resource)); + EXPECT_EQ(RM_CATEGORY_AUDIO_MAIN_OUT, rm_resource_get_category(resource)); + + resource = rm_resource_list_get_next(rsc_list); + + EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); + EXPECT_EQ(-1, rm_resource_get_consumer(resource)); + EXPECT_STREQ("", rm_resource_get_app_id(resource)); + EXPECT_EQ(RM_CATEGORY_SCALER, rm_resource_get_category(resource)); + + resource = rm_resource_list_get_next(rsc_list); + + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, rm_resource_get_id(resource)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); + EXPECT_EQ(-1, rm_resource_get_consumer(resource)); + EXPECT_STREQ("", rm_resource_get_app_id(resource)); + EXPECT_EQ(RM_CATEGORY_AUDIO_DECODER, rm_resource_get_category(resource)); + + resource = rm_resource_list_get_next(rsc_list); + + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_MAIN, rm_resource_get_id(resource)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); + EXPECT_EQ(-1, rm_resource_get_consumer(resource)); + EXPECT_STREQ("", rm_resource_get_app_id(resource)); + EXPECT_LE(RM_CATEGORY_VIDEO_DECODER, rm_resource_get_category(resource)); + + resource = rm_resource_list_get_next(rsc_list); + + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_DVDE0, rm_resource_get_id(resource)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); + EXPECT_EQ(-1, rm_resource_get_consumer(resource)); + EXPECT_STREQ("", rm_resource_get_app_id(resource)); + EXPECT_LE(RM_CATEGORY_VIDEO_DECODER_UHD, rm_resource_get_category(resource)); + + rm_free_resource_list(rsc_list); + + RM_TEST_MSG("rm_get_resource_collection_state_p1 end..."); +} + +TEST(ut_rm_api, rm_get_resource_collection_state_p2) +{ + RM_TEST_MSG("rm_get_resource_collection_state_p2 start..."); + + int handle = 0; + const char *app_id = "org.tizen.test"; + EXPECT_EQ(0, rm_register(rm_cb_set_conflict_flag, NULL, &handle, NULL)); + EXPECT_EQ(0, rm_set_app_id(handle, (char*) app_id)); + + rm_category_request_s req; + memset(&req, 0, sizeof(req)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(allocated)); + + EXPECT_EQ(0, rm_allocate_resources(handle, &req, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + + rm_resource_list_h rsc_list = NULL; + + EXPECT_EQ(0, rm_get_resource_collection_state(RM_RSC_COLLECTION_MAIN, &rsc_list)); + + // MFD0, DVDE0, MAIN SCALER, MAIN AUDIO DECODER, MAIN AUDIO OUT + EXPECT_EQ(5, rm_resource_list_get_count(rsc_list)); + + rm_resource_h resource = rm_resource_list_get_first(rsc_list); + + EXPECT_EQ(RM_DEVICE_AUDIO_MAIN_OUT, rm_resource_get_id(resource)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); + EXPECT_EQ(-1, rm_resource_get_consumer(resource)); + EXPECT_STREQ("", rm_resource_get_app_id(resource)); + EXPECT_EQ(RM_CATEGORY_AUDIO_MAIN_OUT, rm_resource_get_category(resource)); + + resource = rm_resource_list_get_next(rsc_list); + + EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(resource)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, rm_resource_get_state(resource)); + EXPECT_EQ(handle, rm_resource_get_consumer(resource)); + EXPECT_STREQ(app_id, rm_resource_get_app_id(resource)); + EXPECT_EQ(RM_CATEGORY_SCALER, rm_resource_get_category(resource)); + + resource = rm_resource_list_get_next(rsc_list); + + EXPECT_EQ(RM_DEVICE_AUDIO_DECODER, rm_resource_get_id(resource)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); + EXPECT_EQ(-1, rm_resource_get_consumer(resource)); + EXPECT_STREQ("", rm_resource_get_app_id(resource)); + EXPECT_EQ(RM_CATEGORY_AUDIO_DECODER, rm_resource_get_category(resource)); + + resource = rm_resource_list_get_next(rsc_list); + + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_MAIN, rm_resource_get_id(resource)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); + EXPECT_EQ(-1, rm_resource_get_consumer(resource)); + EXPECT_STREQ("", rm_resource_get_app_id(resource)); + EXPECT_LE(RM_CATEGORY_VIDEO_DECODER, rm_resource_get_category(resource)); + + resource = rm_resource_list_get_next(rsc_list); + + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_DVDE0, rm_resource_get_id(resource)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(resource)); + EXPECT_EQ(-1, rm_resource_get_consumer(resource)); + EXPECT_STREQ("", rm_resource_get_app_id(resource)); + EXPECT_LE(RM_CATEGORY_VIDEO_DECODER_UHD, rm_resource_get_category(resource)); + + rm_free_resource_list(rsc_list); + + EXPECT_EQ(0, rm_unregister(handle)); + + RM_TEST_MSG("rm_get_resource_collection_state_p2 end..."); +} + + +static void tc_resource_state_change_cb1(rm_resource_state_h state, void *data) +{ + +} + +static void tc_resource_state_change_cb2(rm_resource_state_h state, void *data) +{ + +} + +static void tc_resource_state_change_cb3(rm_resource_state_h state, void *data) +{ + +} + +TEST(ut_rm_api, rm_resource_state_change_p1) +{ + RM_TEST_MSG("rm_resource_state_change_p1 start..."); + + EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1, NULL)); + EXPECT_EQ(RM_ERROR, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1, NULL)); + EXPECT_EQ(RM_ERROR, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1, NULL)); + EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb2, NULL)); + EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb3, NULL)); + + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb3)); + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb2)); + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1)); + + RM_TEST_MSG("rm_resource_state_change_p1 end..."); +} + +TEST(ut_rm_api, rm_resource_state_change_p2) +{ + RM_TEST_MSG("rm_resource_state_change_p2 start..."); + + EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1, NULL)); + EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER, tc_resource_state_change_cb1, NULL)); + EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER_BG, tc_resource_state_change_cb1, NULL)); + EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER_SUB, tc_resource_state_change_cb1, NULL)); + + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1)); + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER, tc_resource_state_change_cb1)); + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_BG, tc_resource_state_change_cb1)); + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_SUB, tc_resource_state_change_cb1)); + + RM_TEST_MSG("rm_resource_state_change_p2 end..."); +} + +TEST(ut_rm_api, rm_resource_state_change_p3) +{ + RM_TEST_MSG("rm_resource_state_change_p3 start..."); + + EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1)); + EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER, tc_resource_state_change_cb1)); + EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_BG, tc_resource_state_change_cb1)); + EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_SUB, tc_resource_state_change_cb1)); + + EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1, NULL)); + EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER, tc_resource_state_change_cb1, NULL)); + EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER_BG, tc_resource_state_change_cb1, NULL)); + EXPECT_EQ(RM_OK, rm_subscribe_resource_state_change(RM_CATEGORY_SCALER_SUB, tc_resource_state_change_cb1, NULL)); + + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, tc_resource_state_change_cb1)); + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER, tc_resource_state_change_cb1)); + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_BG, tc_resource_state_change_cb1)); + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_state_change(RM_CATEGORY_SCALER_SUB, tc_resource_state_change_cb1)); + + RM_TEST_MSG("rm_resource_state_change_p3 end..."); +} + +TEST(ut_rm_api, rm_resource_state_change_n1) +{ + RM_TEST_MSG("rm_resource_state_change_n1 start..."); + + EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_state_change(RM_CATEGORY_CAMERA, NULL)); + EXPECT_EQ(RM_ERROR, rm_subscribe_resource_state_change(RM_CATEGORY_CAMERA, NULL, NULL)); + + RM_TEST_MSG("rm_resource_state_change_n1 end..."); +} + +typedef struct{ + char *app_id; + int consumer_id; + int device_id; + int category_id; +} expected_conflict_event; + +void conflict_event_cb(rm_conflict_resource_h resource, void *data) +{ + RM_TEST_MSG("conflict event cb invoked!"); + if (!data) + return; + + expected_conflict_event *expected = (expected_conflict_event*) data; + + EXPECT_EQ(expected->category_id, rm_conflict_get_category_id(resource)); + EXPECT_EQ(expected->device_id, rm_conflict_get_device_id(resource)); + EXPECT_EQ(expected->consumer_id, rm_conflict_get_consumer_id(resource)); + EXPECT_STREQ(expected->app_id, rm_conflict_get_app_id(resource)); +} + +void conflict_event_cb2(rm_conflict_resource_h resource, void *data) +{ + +} + +TEST(ut_rm_api, rm_conflict_event_cb_p1) +{ + RM_TEST_MSG("rm_conflict_event_cb_p1 start..."); + + EXPECT_EQ(RM_OK, rm_subscribe_resource_conflict_event(conflict_event_cb, NULL)); + EXPECT_EQ(RM_ERROR, rm_subscribe_resource_conflict_event(conflict_event_cb, NULL)); + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_conflict_event(conflict_event_cb)); + EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_conflict_event(conflict_event_cb)); + + RM_TEST_MSG("rm_conflict_event_cb_p1 end..."); +} + + +rm_cb_result resource_conflict_cb(int handle, rm_callback_type event, rm_device_request_s *info, void *data) +{ + RM_TEST_MSG("resource conflict cb invoked!"); + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); + return RM_CB_RESULT_OK; +} + +TEST(ut_rm_api, rm_conflict_event_cb_p2) +{ + RM_TEST_MSG("rm_conflict_event_cb_p2 start..."); + + int handle1 = 0; + rm_consumer_info *consumer_info1 = (rm_consumer_info*) calloc(1, sizeof(rm_consumer_info)); + snprintf(consumer_info1->app_id, 1024, "%s", "org.tizen.rm.test"); + + EXPECT_EQ(RM_OK, rm_register(resource_conflict_cb, NULL, &handle1, consumer_info1)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_JPEG_DECODER; + request.category_option[0] = ri_get_sub_jpeg_category_id("JPEG", 7680, 4320); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle1, &request, &allocated)); + + expected_conflict_event *expected = (expected_conflict_event*) calloc(1, sizeof(expected_conflict_event)); + expected->app_id = strdup("org.tizen.rm.test"); + + if (use_unified_jpeg_decoder()) + expected->category_id = RM_CATEGORY_JPEG_DECODER_8K; + else if (is_oscars_unified_jpeg_decoder()) + expected->category_id = RM_CATEGORY_JPEG_DECODER; + else + expected->category_id = RM_CATEGORY_JPEG_DECODER_UHD; + + expected->consumer_id = handle1; + expected->device_id = allocated.device_id[0]; + EXPECT_EQ(RM_OK, rm_subscribe_resource_conflict_event(conflict_event_cb, (void*) expected)); + + int handle2 = 0; + EXPECT_EQ(RM_OK, rm_register(resource_conflict_cb, NULL, &handle2, NULL)); + + memset(&request, 0, sizeof(rm_category_request_s)); + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_JPEG_DECODER; + request.category_option[0] = ri_get_sub_jpeg_category_id("JPEG", 7680, 4320); + request.state[0] = RM_STATE_EXCLUSIVE; + + memset(&allocated, 0, sizeof(rm_device_return_s)); + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &request, &allocated)); + + sleep(5); + + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_conflict_event(conflict_event_cb)); + + free(consumer_info1); + consumer_info1 = NULL; + + EXPECT_EQ(RM_OK, rm_unregister(handle1)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + + RM_TEST_MSG("rm_conflict_event_cb_p2 end..."); +} + +TEST(ut_rm_api, rm_conflict_event_cb_n1) +{ + RM_TEST_MSG("rm_conflict_event_cb_n1 start..."); + + EXPECT_EQ(RM_ERROR, rm_subscribe_resource_conflict_event(NULL, NULL)); + EXPECT_EQ(RM_ERROR, rm_unsubscribe_resource_conflict_event(NULL)); + + RM_TEST_MSG("rm_conflict_event_cb_n1 end..."); +} + +TEST(ut_rm_api, rm_conflict_event_cb_p3) +{ + RM_TEST_MSG("rm_conflict_event_cb_p3 start..."); + + EXPECT_EQ(RM_OK, rm_subscribe_resource_conflict_event(conflict_event_cb, NULL)); + EXPECT_EQ(RM_OK, rm_subscribe_resource_conflict_event(conflict_event_cb2, NULL)); + + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_conflict_event(conflict_event_cb2)); + EXPECT_EQ(RM_OK, rm_unsubscribe_resource_conflict_event(conflict_event_cb)); + + RM_TEST_MSG("rm_conflict_event_cb_p3 end..."); +} diff --git a/ut/testcase/ut_tc_resource_scaler.cpp b/ut/testcase/ut_tc_resource_scaler.cpp index 9d6de5e..68b0d1e 100644 --- a/ut/testcase/ut_tc_resource_scaler.cpp +++ b/ut/testcase/ut_tc_resource_scaler.cpp @@ -1,253 +1,253 @@ -/* - * 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" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -rm_cb_result rsc_conflict_cb(int handle, rm_callback_type event, rm_device_request_s *info, void *data) -{ - RM_TEST_MSG("resource conflict cb invoked!"); - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); - return RM_CB_RESULT_OK; -} - -TEST(ut_rm_api, rm_get_scaler_state_p1) -{ - RM_TEST_MSG("rm_get_scaler_state_p1 start..."); - - int handle; - - EXPECT_EQ(RM_OK, rm_register(rsc_conflict_cb, NULL, &handle, NULL)); - - rm_category_request_s req; - memset(&req, 0, sizeof(req)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(allocated)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - rm_resource_list_h scaler_list_h; - int result = rm_get_scaler_state(&scaler_list_h); - EXPECT_EQ(RM_OK, result); - - if (result != RM_OK) { - RM_TEST_MSG("rm_get_scaler_state_p1 end..."); - rm_free_resource_list(scaler_list_h); - return; - } - - EXPECT_EQ(2, rm_resource_list_get_count(scaler_list_h)); - - // main scaler - rm_resource_h rsc = rm_resource_list_get_first(scaler_list_h); - EXPECT_EQ(RM_CATEGORY_SCALER, rm_resource_get_category(rsc)); - EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(rsc)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(rsc)); - EXPECT_EQ(-1, rm_resource_get_consumer(rsc)); - EXPECT_STREQ("", rm_resource_get_app_id(rsc)); - - // sub scaler - rsc = rm_resource_list_get_next(scaler_list_h); - EXPECT_EQ(RM_CATEGORY_SCALER_SUB, rm_resource_get_category(rsc)); - EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_resource_get_id(rsc)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(rsc)); - EXPECT_EQ(-1, rm_resource_get_consumer(rsc)); - EXPECT_STREQ("", rm_resource_get_app_id(rsc)); - - rm_free_resource_list(scaler_list_h); - - RM_TEST_MSG("rm_get_scaler_state_p1 end..."); -} - -TEST(ut_rm_api, rm_get_scaler_state_p2) -{ - RM_TEST_MSG("rm_get_scaler_state_p2 start..."); - - int handle; - char *app_id1 = (char*) "org.tizen.rsc.test"; - - EXPECT_EQ(RM_OK, rm_register(rsc_conflict_cb, NULL, &handle, NULL)); - EXPECT_EQ(RM_OK, rm_set_app_id(handle, app_id1)); - - rm_category_request_s req; - memset(&req, 0, sizeof(req)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(allocated)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); - - - rm_resource_list_h scaler_list_h; - int result = rm_get_scaler_state(&scaler_list_h); - EXPECT_EQ(RM_OK, result); - - if (result != RM_OK) { - EXPECT_EQ(RM_OK, rm_unregister(handle)); - rm_free_resource_list(scaler_list_h); - RM_TEST_MSG("rm_get_scaler_state_p2 end..."); - return; - } - - EXPECT_EQ(2, rm_resource_list_get_count(scaler_list_h)); - - // main scaler - rm_resource_h rsc = rm_resource_list_get_first(scaler_list_h); - EXPECT_EQ(RM_CATEGORY_SCALER, rm_resource_get_category(rsc)); - EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(rsc)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, rm_resource_get_state(rsc)); - EXPECT_EQ(handle, rm_resource_get_consumer(rsc)); - EXPECT_STREQ(app_id1, rm_resource_get_app_id(rsc)); - - // sub scaler - rsc = rm_resource_list_get_next(scaler_list_h); - EXPECT_EQ(RM_CATEGORY_SCALER_SUB, rm_resource_get_category(rsc)); - EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_resource_get_id(rsc)); - EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(rsc)); - EXPECT_EQ(-1, rm_resource_get_consumer(rsc)); - EXPECT_STREQ("", rm_resource_get_app_id(rsc)); - - rm_free_resource_list(scaler_list_h); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - RM_TEST_MSG("rm_get_scaler_state_p2 end..."); -} - -/* issue : video decoder(mem cluster) conflict & rsc(sub scaler) conflict - */ -TEST(ut_rm_api, rm_conflict11) -{ - RM_TEST_MSG("rm_conflict11 start..."); - - TCPlayer *player = new TCPlayer(); - player->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_DEVICE_OPT_MAIN, RM_STATE_EXCLUSIVE); - player->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player->Register()); - EXPECT_EQ(RM_OK, player->AllocateResources()); - - TCPlayer *player2 = new TCPlayer(); - player2->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_DEVICE_OPT_MAIN, RM_STATE_EXCLUSIVE); - player2->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player2->Register()); - EXPECT_EQ(RM_OK, player2->AllocateResources()); - - EXPECT_EQ(1, player->GetConflictNum()); - EXPECT_EQ(2, player->GetConflictedResourcesNum()); - - EXPECT_EQ(RM_OK, player->Unregister()); - EXPECT_EQ(RM_OK, player2->Unregister()); - - delete player; - delete player2; - - sleep(RM_TEST_SLEEP_TIME); - RM_TEST_MSG("rm_conflict11 end..."); -} - -/* issue : rsc(sub scaler) conflict - */ -TEST(ut_rm_api, rm_conflict14) -{ - TCPlayer *player = new TCPlayer(); - player->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_DEVICE_OPT_MAIN, RM_STATE_EXCLUSIVE); - player->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player->Register()); - EXPECT_EQ(RM_OK, player->AllocateResources()); - - TCPlayer *player2 = new TCPlayer(); - player2->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_CATEGORY_VIDEO_DECODER_MPEG4_FHD_8BIT_30P, RM_STATE_EXCLUSIVE); - player2->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player2->Register()); - EXPECT_EQ(RM_OK, player2->AllocateResources()); - - EXPECT_EQ(1, player->GetConflictNum()); - EXPECT_EQ(1, player->GetConflictedResourcesNum()); - - EXPECT_EQ(RM_OK, player->Unregister()); - EXPECT_EQ(RM_OK, player2->Unregister()); - - delete player; - delete player2; - - sleep(RM_TEST_SLEEP_TIME); -} - -/* issue : rsc(sub scaler) conflict - */ -TEST(ut_rm_api, rm_conflict16) -{ - TCPlayer *player = new TCPlayer(); - player->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_CATEGORY_VIDEO_DECODER_MPEG4_FHD_8BIT_30P, RM_STATE_EXCLUSIVE); - player->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player->Register()); - EXPECT_EQ(RM_OK, player->AllocateResources()); - - TCPlayer *player2 = new TCPlayer(); - player2->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_CATEGORY_VIDEO_DECODER_MPEG4_FHD_8BIT_30P, RM_STATE_EXCLUSIVE); - player2->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player2->Register()); - EXPECT_EQ(RM_OK, player2->AllocateResources()); - - EXPECT_EQ(1, player->GetConflictNum()); - EXPECT_EQ(1, player->GetConflictedResourcesNum()); - - EXPECT_EQ(RM_OK, player->Unregister()); - EXPECT_EQ(RM_OK, player2->Unregister()); - - delete player; - delete player2; - - sleep(RM_TEST_SLEEP_TIME); -} \ No newline at end of file +/* + * 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" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +rm_cb_result rsc_conflict_cb(int handle, rm_callback_type event, rm_device_request_s *info, void *data) +{ + RM_TEST_MSG("resource conflict cb invoked!"); + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, info)); + return RM_CB_RESULT_OK; +} + +TEST(ut_rm_api, rm_get_scaler_state_p1) +{ + RM_TEST_MSG("rm_get_scaler_state_p1 start..."); + + int handle; + + EXPECT_EQ(RM_OK, rm_register(rsc_conflict_cb, NULL, &handle, NULL)); + + rm_category_request_s req; + memset(&req, 0, sizeof(req)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(allocated)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + rm_resource_list_h scaler_list_h; + int result = rm_get_scaler_state(&scaler_list_h); + EXPECT_EQ(RM_OK, result); + + if (result != RM_OK) { + RM_TEST_MSG("rm_get_scaler_state_p1 end..."); + rm_free_resource_list(scaler_list_h); + return; + } + + EXPECT_EQ(2, rm_resource_list_get_count(scaler_list_h)); + + // main scaler + rm_resource_h rsc = rm_resource_list_get_first(scaler_list_h); + EXPECT_EQ(RM_CATEGORY_SCALER, rm_resource_get_category(rsc)); + EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(rsc)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(rsc)); + EXPECT_EQ(-1, rm_resource_get_consumer(rsc)); + EXPECT_STREQ("", rm_resource_get_app_id(rsc)); + + // sub scaler + rsc = rm_resource_list_get_next(scaler_list_h); + EXPECT_EQ(RM_CATEGORY_SCALER_SUB, rm_resource_get_category(rsc)); + EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_resource_get_id(rsc)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(rsc)); + EXPECT_EQ(-1, rm_resource_get_consumer(rsc)); + EXPECT_STREQ("", rm_resource_get_app_id(rsc)); + + rm_free_resource_list(scaler_list_h); + + RM_TEST_MSG("rm_get_scaler_state_p1 end..."); +} + +TEST(ut_rm_api, rm_get_scaler_state_p2) +{ + RM_TEST_MSG("rm_get_scaler_state_p2 start..."); + + int handle; + char *app_id1 = (char*) "org.tizen.rsc.test"; + + EXPECT_EQ(RM_OK, rm_register(rsc_conflict_cb, NULL, &handle, NULL)); + EXPECT_EQ(RM_OK, rm_set_app_id(handle, app_id1)); + + rm_category_request_s req; + memset(&req, 0, sizeof(req)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(allocated)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); + + + rm_resource_list_h scaler_list_h; + int result = rm_get_scaler_state(&scaler_list_h); + EXPECT_EQ(RM_OK, result); + + if (result != RM_OK) { + EXPECT_EQ(RM_OK, rm_unregister(handle)); + rm_free_resource_list(scaler_list_h); + RM_TEST_MSG("rm_get_scaler_state_p2 end..."); + return; + } + + EXPECT_EQ(2, rm_resource_list_get_count(scaler_list_h)); + + // main scaler + rm_resource_h rsc = rm_resource_list_get_first(scaler_list_h); + EXPECT_EQ(RM_CATEGORY_SCALER, rm_resource_get_category(rsc)); + EXPECT_EQ(RM_DEVICE_SCALER, rm_resource_get_id(rsc)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, rm_resource_get_state(rsc)); + EXPECT_EQ(handle, rm_resource_get_consumer(rsc)); + EXPECT_STREQ(app_id1, rm_resource_get_app_id(rsc)); + + // sub scaler + rsc = rm_resource_list_get_next(scaler_list_h); + EXPECT_EQ(RM_CATEGORY_SCALER_SUB, rm_resource_get_category(rsc)); + EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_resource_get_id(rsc)); + EXPECT_EQ(RM_RSC_STATE_FREE, rm_resource_get_state(rsc)); + EXPECT_EQ(-1, rm_resource_get_consumer(rsc)); + EXPECT_STREQ("", rm_resource_get_app_id(rsc)); + + rm_free_resource_list(scaler_list_h); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + RM_TEST_MSG("rm_get_scaler_state_p2 end..."); +} + +/* issue : video decoder(mem cluster) conflict & rsc(sub scaler) conflict + */ +TEST(ut_rm_api, rm_conflict11) +{ + RM_TEST_MSG("rm_conflict11 start..."); + + TCPlayer *player = new TCPlayer(); + player->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_DEVICE_OPT_MAIN, RM_STATE_EXCLUSIVE); + player->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player->Register()); + EXPECT_EQ(RM_OK, player->AllocateResources()); + + TCPlayer *player2 = new TCPlayer(); + player2->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_DEVICE_OPT_MAIN, RM_STATE_EXCLUSIVE); + player2->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player2->Register()); + EXPECT_EQ(RM_OK, player2->AllocateResources()); + + EXPECT_EQ(1, player->GetConflictNum()); + EXPECT_EQ(2, player->GetConflictedResourcesNum()); + + EXPECT_EQ(RM_OK, player->Unregister()); + EXPECT_EQ(RM_OK, player2->Unregister()); + + delete player; + delete player2; + + sleep(RM_TEST_SLEEP_TIME); + RM_TEST_MSG("rm_conflict11 end..."); +} + +/* issue : rsc(sub scaler) conflict + */ +TEST(ut_rm_api, rm_conflict14) +{ + TCPlayer *player = new TCPlayer(); + player->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_DEVICE_OPT_MAIN, RM_STATE_EXCLUSIVE); + player->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player->Register()); + EXPECT_EQ(RM_OK, player->AllocateResources()); + + TCPlayer *player2 = new TCPlayer(); + player2->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_CATEGORY_VIDEO_DECODER_MPEG4_FHD_8BIT_30P, RM_STATE_EXCLUSIVE); + player2->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player2->Register()); + EXPECT_EQ(RM_OK, player2->AllocateResources()); + + EXPECT_EQ(1, player->GetConflictNum()); + EXPECT_EQ(1, player->GetConflictedResourcesNum()); + + EXPECT_EQ(RM_OK, player->Unregister()); + EXPECT_EQ(RM_OK, player2->Unregister()); + + delete player; + delete player2; + + sleep(RM_TEST_SLEEP_TIME); +} + +/* issue : rsc(sub scaler) conflict + */ +TEST(ut_rm_api, rm_conflict16) +{ + TCPlayer *player = new TCPlayer(); + player->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_CATEGORY_VIDEO_DECODER_MPEG4_FHD_8BIT_30P, RM_STATE_EXCLUSIVE); + player->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player->Register()); + EXPECT_EQ(RM_OK, player->AllocateResources()); + + TCPlayer *player2 = new TCPlayer(); + player2->AddResource(RM_CATEGORY_VIDEO_DECODER, RM_CATEGORY_VIDEO_DECODER_MPEG4_FHD_8BIT_30P, RM_STATE_EXCLUSIVE); + player2->AddResource(RM_CATEGORY_SCALER_SUB, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player2->Register()); + EXPECT_EQ(RM_OK, player2->AllocateResources()); + + EXPECT_EQ(1, player->GetConflictNum()); + EXPECT_EQ(1, player->GetConflictedResourcesNum()); + + EXPECT_EQ(RM_OK, player->Unregister()); + EXPECT_EQ(RM_OK, player2->Unregister()); + + delete player; + delete player2; + + sleep(RM_TEST_SLEEP_TIME); +} diff --git a/ut/testcase/ut_tc_video_dec_ai.cpp b/ut/testcase/ut_tc_video_dec_ai.cpp index e64d593..8361dc6 100644 --- a/ut/testcase/ut_tc_video_dec_ai.cpp +++ b/ut/testcase/ut_tc_video_dec_ai.cpp @@ -1,341 +1,341 @@ -/* - * 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" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -TEST(ut_rm_api, alloc_ai_video_dec_hevc_fhd_p1) -{ - RM_TEST_MSG("alloc_ai_video_dec_hevc_fhd_p1 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "HEVC"; - option.color_depth = 8; - option.framerate = 30; - option.h_size = 1920; - option.v_size = 1080; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_ai_decoder_category_id(ri_get_capable_video_category_id(&option)); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - - int expected = is_support_8k() ? RM_DEVICE_VIDEO_DECODER_HEVC_8K : RM_DEVICE_VIDEO_DECODER_DVDE0; - - EXPECT_EQ(expected, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_ai_video_dec_hevc_fhd_p1 end..."); -} - -TEST(ut_rm_api, alloc_ai_video_dec_hevc_uhd_p1) -{ - RM_TEST_MSG("alloc_ai_video_dec_hevc_uhd_p1 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "HEVC"; - option.color_depth = 8; - option.framerate = 30; - option.h_size = 3840; - option.v_size = 2160; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_ai_decoder_category_id(ri_get_capable_video_category_id(&option)); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - - int expected = is_support_8k() ? RM_DEVICE_VIDEO_DECODER_HEVC_8K : RM_DEVICE_VIDEO_DECODER_DVDE0; - - EXPECT_EQ(expected, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_ai_video_dec_hevc_uhd_p1 end..."); -} - -TEST(ut_rm_api, alloc_ai_video_dec_hevc_8k_p1) -{ - RM_TEST_MSG("alloc_ai_video_dec_hevc_8k_p1 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "HEVC"; - option.color_depth = 8; - option.framerate = 60; - option.h_size = 7680; - option.v_size = 4320; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_capable_video_category_id(&option); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - if (is_support_8k()) { - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_HEVC_8K, allocated.device_id[0]); - } else { - EXPECT_NE(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(0, allocated.allocated_num); - } - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_ai_video_dec_hevc_8k_p1 end..."); -} - -TEST(ut_rm_api, alloc_ai_video_dec_av1_fhd_p1) -{ - RM_TEST_MSG("alloc_ai_video_dec_av1_fhd_p1 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "AV1"; - option.color_depth = 8; - option.framerate = 30; - option.h_size = 1920; - option.v_size = 1080; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_ai_decoder_category_id(ri_get_capable_video_category_id(&option)); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - - int expected = is_support_8k() ? RM_DEVICE_VIDEO_DECODER_HEVC_8K : RM_DEVICE_VIDEO_DECODER_DVDE0; - - EXPECT_EQ(expected, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_ai_video_dec_av1_fhd_p1 end..."); -} - -TEST(ut_rm_api, alloc_ai_video_dec_av1_uhd_p1) -{ - RM_TEST_MSG("alloc_ai_video_dec_av1_uhd_p1 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "AV1"; - option.color_depth = 8; - option.framerate = 30; - option.h_size = 3840; - option.v_size = 2160; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_ai_decoder_category_id(ri_get_capable_video_category_id(&option)); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - - int expected = is_support_8k() ? RM_DEVICE_VIDEO_DECODER_HEVC_8K : RM_DEVICE_VIDEO_DECODER_DVDE0; - - EXPECT_EQ(expected, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_ai_video_dec_av1_uhd_p1 end..."); -} - -TEST(ut_rm_api, alloc_ai_video_dec_av1_8k_p1) -{ - RM_TEST_MSG("alloc_ai_video_dec_av1_8k_p1 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "AV1"; - option.color_depth = 8; - option.framerate = 60; - option.h_size = 7680; - option.v_size = 4320; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_capable_video_category_id(&option); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - if (is_support_8k()) { - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_HEVC_8K, allocated.device_id[0]); - } else { - EXPECT_NE(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(0, allocated.allocated_num); - } - - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_ai_video_dec_av1_8k_p1 end..."); -} - -TEST(ut_rm_api, alloc_ai_video_dec_h264_n1) -{ - RM_TEST_MSG("alloc_ai_video_dec_h264_n1 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "H264"; - option.color_depth = 8; - option.framerate = 30; - option.h_size = 1920; - option.v_size = 1080; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_ai_decoder_category_id(ri_get_capable_video_category_id(&option)); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_NE(RM_DEVICE_VIDEO_DECODER_DVDE0, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_ai_video_dec_h264_n1 end..."); -} +/* + * 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" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +TEST(ut_rm_api, alloc_ai_video_dec_hevc_fhd_p1) +{ + RM_TEST_MSG("alloc_ai_video_dec_hevc_fhd_p1 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "HEVC"; + option.color_depth = 8; + option.framerate = 30; + option.h_size = 1920; + option.v_size = 1080; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_ai_decoder_category_id(ri_get_capable_video_category_id(&option)); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + + int expected = is_support_8k() ? RM_DEVICE_VIDEO_DECODER_HEVC_8K : RM_DEVICE_VIDEO_DECODER_DVDE0; + + EXPECT_EQ(expected, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_ai_video_dec_hevc_fhd_p1 end..."); +} + +TEST(ut_rm_api, alloc_ai_video_dec_hevc_uhd_p1) +{ + RM_TEST_MSG("alloc_ai_video_dec_hevc_uhd_p1 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "HEVC"; + option.color_depth = 8; + option.framerate = 30; + option.h_size = 3840; + option.v_size = 2160; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_ai_decoder_category_id(ri_get_capable_video_category_id(&option)); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + + int expected = is_support_8k() ? RM_DEVICE_VIDEO_DECODER_HEVC_8K : RM_DEVICE_VIDEO_DECODER_DVDE0; + + EXPECT_EQ(expected, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_ai_video_dec_hevc_uhd_p1 end..."); +} + +TEST(ut_rm_api, alloc_ai_video_dec_hevc_8k_p1) +{ + RM_TEST_MSG("alloc_ai_video_dec_hevc_8k_p1 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "HEVC"; + option.color_depth = 8; + option.framerate = 60; + option.h_size = 7680; + option.v_size = 4320; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_capable_video_category_id(&option); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + if (is_support_8k()) { + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_HEVC_8K, allocated.device_id[0]); + } else { + EXPECT_NE(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(0, allocated.allocated_num); + } + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_ai_video_dec_hevc_8k_p1 end..."); +} + +TEST(ut_rm_api, alloc_ai_video_dec_av1_fhd_p1) +{ + RM_TEST_MSG("alloc_ai_video_dec_av1_fhd_p1 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "AV1"; + option.color_depth = 8; + option.framerate = 30; + option.h_size = 1920; + option.v_size = 1080; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_ai_decoder_category_id(ri_get_capable_video_category_id(&option)); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + + int expected = is_support_8k() ? RM_DEVICE_VIDEO_DECODER_HEVC_8K : RM_DEVICE_VIDEO_DECODER_DVDE0; + + EXPECT_EQ(expected, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_ai_video_dec_av1_fhd_p1 end..."); +} + +TEST(ut_rm_api, alloc_ai_video_dec_av1_uhd_p1) +{ + RM_TEST_MSG("alloc_ai_video_dec_av1_uhd_p1 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "AV1"; + option.color_depth = 8; + option.framerate = 30; + option.h_size = 3840; + option.v_size = 2160; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_ai_decoder_category_id(ri_get_capable_video_category_id(&option)); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + + int expected = is_support_8k() ? RM_DEVICE_VIDEO_DECODER_HEVC_8K : RM_DEVICE_VIDEO_DECODER_DVDE0; + + EXPECT_EQ(expected, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_ai_video_dec_av1_uhd_p1 end..."); +} + +TEST(ut_rm_api, alloc_ai_video_dec_av1_8k_p1) +{ + RM_TEST_MSG("alloc_ai_video_dec_av1_8k_p1 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "AV1"; + option.color_depth = 8; + option.framerate = 60; + option.h_size = 7680; + option.v_size = 4320; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_capable_video_category_id(&option); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + if (is_support_8k()) { + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_HEVC_8K, allocated.device_id[0]); + } else { + EXPECT_NE(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(0, allocated.allocated_num); + } + + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_ai_video_dec_av1_8k_p1 end..."); +} + +TEST(ut_rm_api, alloc_ai_video_dec_h264_n1) +{ + RM_TEST_MSG("alloc_ai_video_dec_h264_n1 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "H264"; + option.color_depth = 8; + option.framerate = 30; + option.h_size = 1920; + option.v_size = 1080; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_ai_decoder_category_id(ri_get_capable_video_category_id(&option)); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_NE(RM_DEVICE_VIDEO_DECODER_DVDE0, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_ai_video_dec_h264_n1 end..."); +} diff --git a/ut/testcase/ut_tc_video_dec_portrait.cpp b/ut/testcase/ut_tc_video_dec_portrait.cpp index ff3a0d1..4a0bf9f 100644 --- a/ut/testcase/ut_tc_video_dec_portrait.cpp +++ b/ut/testcase/ut_tc_video_dec_portrait.cpp @@ -1,91 +1,91 @@ -/* - * 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" -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -TEST(ut_rm_api, video_decoder_portrait_dtv_1080_1920) -{ - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "HEVC"; - option.color_depth = 8; - option.framerate = 30; - option.h_size = 1080; - option.v_size = 1920; // Max height supported by mfc is 1080 - option.sampling_format = RI_SAMPLING_FORMAT_420; - - EXPECT_EQ(RI_CATEGORY_VIDEO_DECODER_HEVC_UHD_8BIT_30P , ri_get_capable_video_category_id(&option)); -} - -TEST(ut_rm_api, video_decoder_portrait_dtv_720_1280) -{ - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "HEVC"; - option.color_depth = 8; - option.framerate = 30; - option.h_size = 720; - option.v_size = 1280; // Max height supported by mfc is 1080 - option.sampling_format = RI_SAMPLING_FORMAT_420; - - EXPECT_EQ(RI_CATEGORY_VIDEO_DECODER_HEVC_UHD_8BIT_30P , ri_get_capable_video_category_id(&option)); -} - -TEST(ut_rm_api, video_decoder_portrait_dtv_480_640) -{ - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "HEVC"; - option.color_depth = 8; - option.framerate = 30; - option.h_size = 480; - option.v_size = 640; // Max height supported by mfc is 1080 - option.sampling_format = RI_SAMPLING_FORMAT_420; - - EXPECT_EQ(RI_CATEGORY_VIDEO_DECODER_HEVC_FHD_8BIT_30P , ri_get_capable_video_category_id(&option)); -} - -TEST(ut_rm_api, video_decoder_portrait_dtv_2160_3840) -{ - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "HEVC"; - option.color_depth = 8; - option.framerate = 30; - option.h_size = 2160; - option.v_size = 3840; // Max height supported by dvde is 2160 - option.sampling_format = RI_SAMPLING_FORMAT_420; - - EXPECT_EQ(RI_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED , ri_get_capable_video_category_id(&option)); -} \ No newline at end of file +/* + * 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" +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +TEST(ut_rm_api, video_decoder_portrait_dtv_1080_1920) +{ + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "HEVC"; + option.color_depth = 8; + option.framerate = 30; + option.h_size = 1080; + option.v_size = 1920; // Max height supported by mfc is 1080 + option.sampling_format = RI_SAMPLING_FORMAT_420; + + EXPECT_EQ(RI_CATEGORY_VIDEO_DECODER_HEVC_UHD_8BIT_30P , ri_get_capable_video_category_id(&option)); +} + +TEST(ut_rm_api, video_decoder_portrait_dtv_720_1280) +{ + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "HEVC"; + option.color_depth = 8; + option.framerate = 30; + option.h_size = 720; + option.v_size = 1280; // Max height supported by mfc is 1080 + option.sampling_format = RI_SAMPLING_FORMAT_420; + + EXPECT_EQ(RI_CATEGORY_VIDEO_DECODER_HEVC_UHD_8BIT_30P , ri_get_capable_video_category_id(&option)); +} + +TEST(ut_rm_api, video_decoder_portrait_dtv_480_640) +{ + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "HEVC"; + option.color_depth = 8; + option.framerate = 30; + option.h_size = 480; + option.v_size = 640; // Max height supported by mfc is 1080 + option.sampling_format = RI_SAMPLING_FORMAT_420; + + EXPECT_EQ(RI_CATEGORY_VIDEO_DECODER_HEVC_FHD_8BIT_30P , ri_get_capable_video_category_id(&option)); +} + +TEST(ut_rm_api, video_decoder_portrait_dtv_2160_3840) +{ + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "HEVC"; + option.color_depth = 8; + option.framerate = 30; + option.h_size = 2160; + option.v_size = 3840; // Max height supported by dvde is 2160 + option.sampling_format = RI_SAMPLING_FORMAT_420; + + EXPECT_EQ(RI_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED , ri_get_capable_video_category_id(&option)); +} diff --git a/ut/testcase/ut_tc_virtual_scaler.cpp b/ut/testcase/ut_tc_virtual_scaler.cpp index 26a8676..85ce93a 100644 --- a/ut/testcase/ut_tc_virtual_scaler.cpp +++ b/ut/testcase/ut_tc_virtual_scaler.cpp @@ -1,632 +1,632 @@ -/* - * 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" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -static int cb_handle = 0; -static int cb_time = 0; - -rm_cb_result _conflict_cb(int handle, rm_callback_type event, rm_device_request_s *info, void *data) -{ - cb_handle = handle; - cb_time++; - rm_unregister(handle); - return RM_CB_RESULT_OK; -} - -void _reset_cb_info(void) -{ - cb_handle = -1; - cb_time = 0; -} - -int _get_conflict_num(void) -{ - return cb_time; -} - -int _get_conflict_handle(void) -{ - return cb_handle; -} - -TEST(ut_rm_api, rm_virtual_scaler_p1) -{ - RM_TEST_MSG("rm_virtual_scaler_p1 start..."); - - int handle = 0; - - EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle, NULL)); - - rm_category_request_s req; - memset(&req, 0, sizeof(rm_category_request_s)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); - - rm_resource_state_e state; - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - rm_device_request_s req_release; - memset(&req_release, 0, sizeof(rm_device_request_s)); - - req_release.request_num = 1; - req_release.device_id[0] = allocated.device_id[0]; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, &req_release)); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_FREE, state); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("rm_virtual_scaler_p1 end..."); -} - -TEST(ut_rm_api, rm_virtual_scaler_p2) -{ - RM_TEST_MSG("rm_virtual_scaler_p2 start..."); - - // Step#1 Allocate main scaler - int handle = 0; - - EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle, NULL)); - - rm_category_request_s req; - memset(&req, 0, sizeof(rm_category_request_s)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); - - rm_resource_state_e state; - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - // Step#2 Allocate sub scaler - int handle2 = 0; - - EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle2, NULL)); - - memset(&req, 0, sizeof(rm_category_request_s)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER_SUB; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated2; - memset(&allocated2, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &req, &allocated2)); - - EXPECT_EQ(1, allocated2.allocated_num); - EXPECT_EQ((RI_VIRTUAL_ID_SCALER + 1), allocated2.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated2.device_id[0])); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - // Step#3 Release main scaler - rm_device_request_s req_release; - memset(&req_release, 0, sizeof(rm_device_request_s)); - - req_release.request_num = 1; - req_release.device_id[0] = allocated.device_id[0]; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, &req_release)); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_FREE, state); - - // Step#4 Release sub scaler - memset(&req_release, 0, sizeof(rm_device_request_s)); - - req_release.request_num = 1; - req_release.device_id[0] = allocated2.device_id[0]; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle2, &req_release)); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); - EXPECT_EQ(RM_RSC_STATE_FREE, state); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - - RM_TEST_MSG("rm_virtual_scaler_p2 end..."); -} - -TEST(ut_rm_api, rm_virtual_scaler_p3) -{ - RM_TEST_MSG("rm_virtual_scaler_p3 start..."); - - // Step#1 Allocate sub scaler - int handle = 0; - - EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle, NULL)); - - rm_category_request_s req; - memset(&req, 0, sizeof(rm_category_request_s)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER_SUB; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[0])); - - rm_resource_state_e state; - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - // Step#2 Allocate main scaler - int handle2 = 0; - - EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle2, NULL)); - - memset(&req, 0, sizeof(rm_category_request_s)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated2; - memset(&allocated2, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &req, &allocated2)); - - EXPECT_EQ(1, allocated2.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated2.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated2.device_id[0])); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - // Step#3 Release sub scaler - rm_device_request_s req_release; - memset(&req_release, 0, sizeof(rm_device_request_s)); - - req_release.request_num = 1; - req_release.device_id[0] = allocated.device_id[0]; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, &req_release)); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); - EXPECT_EQ(RM_RSC_STATE_FREE, state); - - // Step#4 Release main scaler - memset(&req_release, 0, sizeof(rm_device_request_s)); - - req_release.request_num = 1; - req_release.device_id[0] = allocated2.device_id[0]; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle2, &req_release)); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_FREE, state); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - - RM_TEST_MSG("rm_virtual_scaler_p3 end..."); -} - -TEST(ut_rm_api, rm_virtual_scaler_p4) -{ - RM_TEST_MSG("rm_virtual_scaler_p4 start..."); - _reset_cb_info(); - - /* TEST SCENARIO - * 1. Allocate main scaler - * 2. Allocate main scaler (conflict with player 1) - */ - - TCPlayer *player = new TCPlayer(); - player->AddResource(RM_CATEGORY_SCALER, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player->Register()); - EXPECT_EQ(RM_OK, player->AllocateResources()); - - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, player->GetAllocatedResourceId(1)); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(player->GetAllocatedResourceId(1))); - - rm_resource_state_e state; - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - TCPlayer *player2 = new TCPlayer(); - player2->AddResource(RM_CATEGORY_SCALER, RM_STATE_EXCLUSIVE); - - EXPECT_EQ(RM_OK, player2->Register()); - EXPECT_EQ(RM_OK, player2->AllocateResources()); - - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, player2->GetAllocatedResourceId(1)); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(player2->GetAllocatedResourceId(1))); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - EXPECT_EQ(1, player->GetConflictNum()); - EXPECT_EQ(1, player->GetConflictedResourcesNum()); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, player->GetConflictedResourceId(1)); - - EXPECT_NE(RM_OK, player->ReleaseResource(1)); - EXPECT_EQ(RM_OK, player2->ReleaseResource(1)); - - EXPECT_EQ(RM_OK, player->Unregister()); - EXPECT_EQ(RM_OK, player2->Unregister()); - - delete player; - delete player2; - - RM_TEST_MSG("rm_virtual_scaler_p4 end..."); -} - -TEST(ut_rm_api, rm_virtual_scaler_swap_p1) -{ - RM_TEST_MSG("rm_virtual_scaler_swap_p1 start..."); - - /************************************************ - * 1. Allocate sub scaler (handle1) - * 2. Allocate main scaler (handle2) - * 3. Swap main scaler with sub - * 4. Release main scaler (handle1) - * 5. Release sub scaler (handle2) - *************************************************/ - - // Step#1 Allocate sub scaler - int handle = 0; - - EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle, NULL)); - - rm_category_request_s req; - memset(&req, 0, sizeof(rm_category_request_s)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER_SUB; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[0])); - - rm_resource_state_e state; - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - // Step#2 Allocate main scaler - int handle2 = 0; - - EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle2, NULL)); - - memset(&req, 0, sizeof(rm_category_request_s)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated2; - memset(&allocated2, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &req, &allocated2)); - - EXPECT_EQ(1, allocated2.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated2.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated2.device_id[0])); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - // Step#3 Swap main scaler with sub - EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); - - // Step#4 Release main scaler - rm_device_request_s req_release; - memset(&req_release, 0, sizeof(rm_device_request_s)); - - req_release.request_num = 1; - req_release.device_id[0] = allocated.device_id[0]; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, &req_release)); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_FREE, state); - - // Step#5 Release sub scaler - memset(&req_release, 0, sizeof(rm_device_request_s)); - - req_release.request_num = 1; - req_release.device_id[0] = allocated2.device_id[0]; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle2, &req_release)); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); - EXPECT_EQ(RM_RSC_STATE_FREE, state); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - - // restore - EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); - - RM_TEST_MSG("rm_virtual_scaler_swap_p1 end..."); -} - -TEST(ut_rm_api, rm_virtual_scaler_swap_p2) -{ - RM_TEST_MSG("rm_virtual_scaler_swap_p2 start..."); - - /************************************************ - * 1. Allocate sub scaler (handle1) 10000:sub - * 2. Allocate main scaler (handle2) 10001:main - * 3. Swap main scaler with sub : 10000:main 10001:sub - * 4. Try to allocate main scaler (handle3) - * - Conflict with handle1 - * 4. Release main scaler (handle3) - * 5. Release sub scaler (handle2) - *************************************************/ - - _reset_cb_info(); - - // Step#1 Allocate sub scaler - int handle = 0; - - EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle, NULL)); - - rm_category_request_s req; - memset(&req, 0, sizeof(rm_category_request_s)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER_SUB; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); - - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[0])); - - rm_resource_state_e state; - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - // Step#2 Allocate main scaler - int handle2 = 0; - - EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle2, NULL)); - - memset(&req, 0, sizeof(rm_category_request_s)); - - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated2; - memset(&allocated2, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &req, &allocated2)); - - EXPECT_EQ(1, allocated2.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated2.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated2.device_id[0])); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - // Step#3 Swap main scaler with sub - EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); - - // Step#4 Try to allocate main scaler (handle3) - int handle3 = 0; - - EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle3, NULL)); - - memset(&req, 0, sizeof(rm_category_request_s)); - req.request_num = 1; - req.category_id[0] = RM_CATEGORY_SCALER; - req.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated3; - memset(&allocated3, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, &req, &allocated3)); - - sleep(1); - - EXPECT_EQ(1, allocated3.allocated_num); - EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated3.device_id[0]); - EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated3.device_id[0])); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); - - EXPECT_EQ(handle, _get_conflict_handle()); - EXPECT_EQ(1, _get_conflict_num()); - - // Step#5 Release main scaler (handle3) - rm_device_request_s req_release; - memset(&req_release, 0, sizeof(rm_device_request_s)); - - req_release.request_num = 1; - req_release.device_id[0] = allocated.device_id[0]; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle3, &req_release)); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); - EXPECT_EQ(RM_RSC_STATE_FREE, state); - - // Step#6 Release sub scaler (handle2) - memset(&req_release, 0, sizeof(rm_device_request_s)); - - req_release.request_num = 1; - req_release.device_id[0] = allocated2.device_id[0]; - - EXPECT_EQ(RM_OK, rm_deallocate_resources(handle2, &req_release)); - - EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); - EXPECT_EQ(RM_RSC_STATE_FREE, state); - - EXPECT_NE(RM_OK, rm_unregister(handle)); // already unregistered by callback - EXPECT_EQ(RM_OK, rm_unregister(handle2)); - EXPECT_EQ(RM_OK, rm_unregister(handle3)); - - //restore - EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); - - RM_TEST_MSG("rm_virtual_scaler_swap_p2 end..."); -} - - - -TEST(ut_rm_api, rm_virtual_scaler_swap_n1) -{ - RM_TEST_MSG("rm_virtual_scaler_swap_n1 start..."); - - EXPECT_NE(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_TUNER)); - - RM_TEST_MSG("rm_virtual_scaler_swap_n1 end..."); -} - -TEST(ut_rm_api, rm_virtual_scaler_swap_n2) -{ - RM_TEST_MSG("rm_virtual_scaler_swap_n2 start..."); - - EXPECT_NE(RM_OK, rm_swap_resources(RM_DEVICE_VIDEO_DECODER_MAIN, RM_DEVICE_VIDEO_DECODER_SUB)); - - RM_TEST_MSG("rm_virtual_scaler_swap_n2 end..."); -} - -TEST(ut_rm_api, rm_scaler_changed_cb_p1) -{ - RM_TEST_MSG("rm_scaler_changed_cb_p1 start..."); - - TCCallbackListener *listener = new TCCallbackListener(); - - EXPECT_EQ(RM_OK, listener->RegisterScalerStateChangeCb()); - EXPECT_EQ(RM_OK, listener->UnregisterScalerStateChangeCb()); - - delete listener; - - RM_TEST_MSG("rm_scaler_changed_cb_p1 end..."); -} - -TEST(ut_rm_api, rm_scaler_changed_cb_n1) -{ - RM_TEST_MSG("rm_scaler_changed_cb_n1 start..."); - - TCCallbackListener *listener = new TCCallbackListener(); - - EXPECT_EQ(RM_OK, listener->RegisterScalerStateChangeCb()); - EXPECT_NE(RM_OK, listener->RegisterScalerStateChangeCb()); - - EXPECT_EQ(RM_OK, listener->UnregisterScalerStateChangeCb()); - EXPECT_NE(RM_OK, listener->UnregisterScalerStateChangeCb()); - - delete listener; - - RM_TEST_MSG("rm_scaler_changed_cb_n1 end..."); -} - -int _get_source_id(int device_id) -{ - if (device_id == RM_DEVICE_SCALER) - return 0; - if (device_id == RM_DEVICE_SCALER_SUB) - return 1; - return 99; -} - -#if 0 // Resource manager server doesn't send a dbus signal (disabled feature) -TEST(ut_rm_api, rm_scaler_changed_cb_p2) -{ - RM_TEST_MSG("rm_scaler_changed_cb_p2 start..."); - - TCCallbackListener *listener = new TCCallbackListener(); - - EXPECT_EQ(RM_OK, listener->RegisterScalerStateChangeCb()); - - EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); - - sleep(2); - - EXPECT_EQ(1, listener->GetNotificationNum()); - EXPECT_EQ(1, listener->IsIncluded(RI_VIRTUAL_ID_SCALER + 1, _get_source_id(RM_DEVICE_SCALER))); - EXPECT_EQ(1, listener->IsIncluded(RI_VIRTUAL_ID_SCALER, _get_source_id(RM_DEVICE_SCALER_SUB))); - - EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); - - sleep(2); - - EXPECT_EQ(2, listener->GetNotificationNum()); - EXPECT_EQ(1, listener->IsIncluded(RI_VIRTUAL_ID_SCALER, _get_source_id(RM_DEVICE_SCALER))); - EXPECT_EQ(1, listener->IsIncluded(RI_VIRTUAL_ID_SCALER + 1, _get_source_id(RM_DEVICE_SCALER_SUB))); - - EXPECT_EQ(RM_OK, listener->UnregisterScalerStateChangeCb()); - - delete listener; - - RM_TEST_MSG("rm_scaler_changed_cb_p2 end..."); -} -#endif//0 +/* + * 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" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static int cb_handle = 0; +static int cb_time = 0; + +rm_cb_result _conflict_cb(int handle, rm_callback_type event, rm_device_request_s *info, void *data) +{ + cb_handle = handle; + cb_time++; + rm_unregister(handle); + return RM_CB_RESULT_OK; +} + +void _reset_cb_info(void) +{ + cb_handle = -1; + cb_time = 0; +} + +int _get_conflict_num(void) +{ + return cb_time; +} + +int _get_conflict_handle(void) +{ + return cb_handle; +} + +TEST(ut_rm_api, rm_virtual_scaler_p1) +{ + RM_TEST_MSG("rm_virtual_scaler_p1 start..."); + + int handle = 0; + + EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle, NULL)); + + rm_category_request_s req; + memset(&req, 0, sizeof(rm_category_request_s)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); + + rm_resource_state_e state; + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + rm_device_request_s req_release; + memset(&req_release, 0, sizeof(rm_device_request_s)); + + req_release.request_num = 1; + req_release.device_id[0] = allocated.device_id[0]; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, &req_release)); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_FREE, state); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("rm_virtual_scaler_p1 end..."); +} + +TEST(ut_rm_api, rm_virtual_scaler_p2) +{ + RM_TEST_MSG("rm_virtual_scaler_p2 start..."); + + // Step#1 Allocate main scaler + int handle = 0; + + EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle, NULL)); + + rm_category_request_s req; + memset(&req, 0, sizeof(rm_category_request_s)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated.device_id[0])); + + rm_resource_state_e state; + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + // Step#2 Allocate sub scaler + int handle2 = 0; + + EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle2, NULL)); + + memset(&req, 0, sizeof(rm_category_request_s)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER_SUB; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated2; + memset(&allocated2, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &req, &allocated2)); + + EXPECT_EQ(1, allocated2.allocated_num); + EXPECT_EQ((RI_VIRTUAL_ID_SCALER + 1), allocated2.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated2.device_id[0])); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + // Step#3 Release main scaler + rm_device_request_s req_release; + memset(&req_release, 0, sizeof(rm_device_request_s)); + + req_release.request_num = 1; + req_release.device_id[0] = allocated.device_id[0]; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, &req_release)); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_FREE, state); + + // Step#4 Release sub scaler + memset(&req_release, 0, sizeof(rm_device_request_s)); + + req_release.request_num = 1; + req_release.device_id[0] = allocated2.device_id[0]; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle2, &req_release)); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); + EXPECT_EQ(RM_RSC_STATE_FREE, state); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + + RM_TEST_MSG("rm_virtual_scaler_p2 end..."); +} + +TEST(ut_rm_api, rm_virtual_scaler_p3) +{ + RM_TEST_MSG("rm_virtual_scaler_p3 start..."); + + // Step#1 Allocate sub scaler + int handle = 0; + + EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle, NULL)); + + rm_category_request_s req; + memset(&req, 0, sizeof(rm_category_request_s)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER_SUB; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[0])); + + rm_resource_state_e state; + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + // Step#2 Allocate main scaler + int handle2 = 0; + + EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle2, NULL)); + + memset(&req, 0, sizeof(rm_category_request_s)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated2; + memset(&allocated2, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &req, &allocated2)); + + EXPECT_EQ(1, allocated2.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated2.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated2.device_id[0])); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + // Step#3 Release sub scaler + rm_device_request_s req_release; + memset(&req_release, 0, sizeof(rm_device_request_s)); + + req_release.request_num = 1; + req_release.device_id[0] = allocated.device_id[0]; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, &req_release)); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); + EXPECT_EQ(RM_RSC_STATE_FREE, state); + + // Step#4 Release main scaler + memset(&req_release, 0, sizeof(rm_device_request_s)); + + req_release.request_num = 1; + req_release.device_id[0] = allocated2.device_id[0]; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle2, &req_release)); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_FREE, state); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + + RM_TEST_MSG("rm_virtual_scaler_p3 end..."); +} + +TEST(ut_rm_api, rm_virtual_scaler_p4) +{ + RM_TEST_MSG("rm_virtual_scaler_p4 start..."); + _reset_cb_info(); + + /* TEST SCENARIO + * 1. Allocate main scaler + * 2. Allocate main scaler (conflict with player 1) + */ + + TCPlayer *player = new TCPlayer(); + player->AddResource(RM_CATEGORY_SCALER, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player->Register()); + EXPECT_EQ(RM_OK, player->AllocateResources()); + + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, player->GetAllocatedResourceId(1)); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(player->GetAllocatedResourceId(1))); + + rm_resource_state_e state; + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + TCPlayer *player2 = new TCPlayer(); + player2->AddResource(RM_CATEGORY_SCALER, RM_STATE_EXCLUSIVE); + + EXPECT_EQ(RM_OK, player2->Register()); + EXPECT_EQ(RM_OK, player2->AllocateResources()); + + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, player2->GetAllocatedResourceId(1)); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(player2->GetAllocatedResourceId(1))); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + EXPECT_EQ(1, player->GetConflictNum()); + EXPECT_EQ(1, player->GetConflictedResourcesNum()); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, player->GetConflictedResourceId(1)); + + EXPECT_NE(RM_OK, player->ReleaseResource(1)); + EXPECT_EQ(RM_OK, player2->ReleaseResource(1)); + + EXPECT_EQ(RM_OK, player->Unregister()); + EXPECT_EQ(RM_OK, player2->Unregister()); + + delete player; + delete player2; + + RM_TEST_MSG("rm_virtual_scaler_p4 end..."); +} + +TEST(ut_rm_api, rm_virtual_scaler_swap_p1) +{ + RM_TEST_MSG("rm_virtual_scaler_swap_p1 start..."); + + /************************************************ + * 1. Allocate sub scaler (handle1) + * 2. Allocate main scaler (handle2) + * 3. Swap main scaler with sub + * 4. Release main scaler (handle1) + * 5. Release sub scaler (handle2) + *************************************************/ + + // Step#1 Allocate sub scaler + int handle = 0; + + EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle, NULL)); + + rm_category_request_s req; + memset(&req, 0, sizeof(rm_category_request_s)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER_SUB; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[0])); + + rm_resource_state_e state; + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + // Step#2 Allocate main scaler + int handle2 = 0; + + EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle2, NULL)); + + memset(&req, 0, sizeof(rm_category_request_s)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated2; + memset(&allocated2, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &req, &allocated2)); + + EXPECT_EQ(1, allocated2.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated2.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated2.device_id[0])); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + // Step#3 Swap main scaler with sub + EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); + + // Step#4 Release main scaler + rm_device_request_s req_release; + memset(&req_release, 0, sizeof(rm_device_request_s)); + + req_release.request_num = 1; + req_release.device_id[0] = allocated.device_id[0]; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle, &req_release)); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_FREE, state); + + // Step#5 Release sub scaler + memset(&req_release, 0, sizeof(rm_device_request_s)); + + req_release.request_num = 1; + req_release.device_id[0] = allocated2.device_id[0]; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle2, &req_release)); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); + EXPECT_EQ(RM_RSC_STATE_FREE, state); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + + // restore + EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); + + RM_TEST_MSG("rm_virtual_scaler_swap_p1 end..."); +} + +TEST(ut_rm_api, rm_virtual_scaler_swap_p2) +{ + RM_TEST_MSG("rm_virtual_scaler_swap_p2 start..."); + + /************************************************ + * 1. Allocate sub scaler (handle1) 10000:sub + * 2. Allocate main scaler (handle2) 10001:main + * 3. Swap main scaler with sub : 10000:main 10001:sub + * 4. Try to allocate main scaler (handle3) + * - Conflict with handle1 + * 4. Release main scaler (handle3) + * 5. Release sub scaler (handle2) + *************************************************/ + + _reset_cb_info(); + + // Step#1 Allocate sub scaler + int handle = 0; + + EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle, NULL)); + + rm_category_request_s req; + memset(&req, 0, sizeof(rm_category_request_s)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER_SUB; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &req, &allocated)); + + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER_SUB, rm_find_device_id(allocated.device_id[0])); + + rm_resource_state_e state; + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + // Step#2 Allocate main scaler + int handle2 = 0; + + EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle2, NULL)); + + memset(&req, 0, sizeof(rm_category_request_s)); + + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated2; + memset(&allocated2, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle2, &req, &allocated2)); + + EXPECT_EQ(1, allocated2.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER, allocated2.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated2.device_id[0])); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + // Step#3 Swap main scaler with sub + EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); + + // Step#4 Try to allocate main scaler (handle3) + int handle3 = 0; + + EXPECT_EQ(RM_OK, rm_register(_conflict_cb, NULL, &handle3, NULL)); + + memset(&req, 0, sizeof(rm_category_request_s)); + req.request_num = 1; + req.category_id[0] = RM_CATEGORY_SCALER; + req.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated3; + memset(&allocated3, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle3, &req, &allocated3)); + + sleep(1); + + EXPECT_EQ(1, allocated3.allocated_num); + EXPECT_EQ(RI_VIRTUAL_ID_SCALER + 1, allocated3.device_id[0]); + EXPECT_EQ(RM_DEVICE_SCALER, rm_find_device_id(allocated3.device_id[0])); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_EXCLUSIVE, state); + + EXPECT_EQ(handle, _get_conflict_handle()); + EXPECT_EQ(1, _get_conflict_num()); + + // Step#5 Release main scaler (handle3) + rm_device_request_s req_release; + memset(&req_release, 0, sizeof(rm_device_request_s)); + + req_release.request_num = 1; + req_release.device_id[0] = allocated.device_id[0]; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle3, &req_release)); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER, &state)); + EXPECT_EQ(RM_RSC_STATE_FREE, state); + + // Step#6 Release sub scaler (handle2) + memset(&req_release, 0, sizeof(rm_device_request_s)); + + req_release.request_num = 1; + req_release.device_id[0] = allocated2.device_id[0]; + + EXPECT_EQ(RM_OK, rm_deallocate_resources(handle2, &req_release)); + + EXPECT_EQ(RM_OK, rm_get_resource_state(RM_DEVICE_SCALER_SUB, &state)); + EXPECT_EQ(RM_RSC_STATE_FREE, state); + + EXPECT_NE(RM_OK, rm_unregister(handle)); // already unregistered by callback + EXPECT_EQ(RM_OK, rm_unregister(handle2)); + EXPECT_EQ(RM_OK, rm_unregister(handle3)); + + //restore + EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); + + RM_TEST_MSG("rm_virtual_scaler_swap_p2 end..."); +} + + + +TEST(ut_rm_api, rm_virtual_scaler_swap_n1) +{ + RM_TEST_MSG("rm_virtual_scaler_swap_n1 start..."); + + EXPECT_NE(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_TUNER)); + + RM_TEST_MSG("rm_virtual_scaler_swap_n1 end..."); +} + +TEST(ut_rm_api, rm_virtual_scaler_swap_n2) +{ + RM_TEST_MSG("rm_virtual_scaler_swap_n2 start..."); + + EXPECT_NE(RM_OK, rm_swap_resources(RM_DEVICE_VIDEO_DECODER_MAIN, RM_DEVICE_VIDEO_DECODER_SUB)); + + RM_TEST_MSG("rm_virtual_scaler_swap_n2 end..."); +} + +TEST(ut_rm_api, rm_scaler_changed_cb_p1) +{ + RM_TEST_MSG("rm_scaler_changed_cb_p1 start..."); + + TCCallbackListener *listener = new TCCallbackListener(); + + EXPECT_EQ(RM_OK, listener->RegisterScalerStateChangeCb()); + EXPECT_EQ(RM_OK, listener->UnregisterScalerStateChangeCb()); + + delete listener; + + RM_TEST_MSG("rm_scaler_changed_cb_p1 end..."); +} + +TEST(ut_rm_api, rm_scaler_changed_cb_n1) +{ + RM_TEST_MSG("rm_scaler_changed_cb_n1 start..."); + + TCCallbackListener *listener = new TCCallbackListener(); + + EXPECT_EQ(RM_OK, listener->RegisterScalerStateChangeCb()); + EXPECT_NE(RM_OK, listener->RegisterScalerStateChangeCb()); + + EXPECT_EQ(RM_OK, listener->UnregisterScalerStateChangeCb()); + EXPECT_NE(RM_OK, listener->UnregisterScalerStateChangeCb()); + + delete listener; + + RM_TEST_MSG("rm_scaler_changed_cb_n1 end..."); +} + +int _get_source_id(int device_id) +{ + if (device_id == RM_DEVICE_SCALER) + return 0; + if (device_id == RM_DEVICE_SCALER_SUB) + return 1; + return 99; +} + +#if 0 // Resource manager server doesn't send a dbus signal (disabled feature) +TEST(ut_rm_api, rm_scaler_changed_cb_p2) +{ + RM_TEST_MSG("rm_scaler_changed_cb_p2 start..."); + + TCCallbackListener *listener = new TCCallbackListener(); + + EXPECT_EQ(RM_OK, listener->RegisterScalerStateChangeCb()); + + EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); + + sleep(2); + + EXPECT_EQ(1, listener->GetNotificationNum()); + EXPECT_EQ(1, listener->IsIncluded(RI_VIRTUAL_ID_SCALER + 1, _get_source_id(RM_DEVICE_SCALER))); + EXPECT_EQ(1, listener->IsIncluded(RI_VIRTUAL_ID_SCALER, _get_source_id(RM_DEVICE_SCALER_SUB))); + + EXPECT_EQ(RM_OK, rm_swap_resources(RM_DEVICE_SCALER, RM_DEVICE_SCALER_SUB)); + + sleep(2); + + EXPECT_EQ(2, listener->GetNotificationNum()); + EXPECT_EQ(1, listener->IsIncluded(RI_VIRTUAL_ID_SCALER, _get_source_id(RM_DEVICE_SCALER))); + EXPECT_EQ(1, listener->IsIncluded(RI_VIRTUAL_ID_SCALER + 1, _get_source_id(RM_DEVICE_SCALER_SUB))); + + EXPECT_EQ(RM_OK, listener->UnregisterScalerStateChangeCb()); + + delete listener; + + RM_TEST_MSG("rm_scaler_changed_cb_p2 end..."); +} +#endif//0 diff --git a/ut/testcase/ut_tc_vr360.cpp b/ut/testcase/ut_tc_vr360.cpp index a4ca039..a0e210a 100644 --- a/ut/testcase/ut_tc_vr360.cpp +++ b/ut/testcase/ut_tc_vr360.cpp @@ -1,242 +1,242 @@ -/* - * 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" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -TEST(ut_rm_api, alloc_video_dec_av1_vr360_p1) -{ - RM_TEST_MSG("alloc_video_dec_av1_vr360_p1 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "AV1_VR360"; - option.color_depth = 8; - option.framerate = 30; - option.h_size = 1920; - option.v_size = 1080; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_capable_video_category_id(&option); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_VR360DEC, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_video_dec_av1_vr360_p1 end..."); -} - -TEST(ut_rm_api, alloc_video_dec_av1_vr360_p2) -{ - RM_TEST_MSG("alloc_video_dec_av1_vr360_p2 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "AV1_VR360"; - option.color_depth = 8; - option.framerate = 60; - option.h_size = 3840; - option.v_size = 2160; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_capable_video_category_id(&option); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - if (is_support_4k()) { - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_VR360DEC, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - } else { - EXPECT_NE(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(0, allocated.allocated_num); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - } - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_video_dec_av1_vr360_p2 end..."); -} - -TEST(ut_rm_api, alloc_video_dec_h264_vr360_p1) -{ - RM_TEST_MSG("alloc_video_dec_h264_vr360_p1 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "H264_VR360"; - option.color_depth = 8; - option.framerate = 60; - option.h_size = 1920; - option.v_size = 1080; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_capable_video_category_id(&option); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_VR360DEC, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_video_dec_h264_vr360_p1 end..."); -} - -TEST(ut_rm_api, alloc_video_dec_vp9_vr360_p1) -{ - RM_TEST_MSG("alloc_video_dec_vp9_vr360_p1 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "VP9_VR360"; - option.color_depth = 8; - option.framerate = 60; - option.h_size = 1920; - option.v_size = 1080; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_capable_video_category_id(&option); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_VR360DEC, allocated.device_id[0]); - EXPECT_STREQ("OMX.SDP.video_decoder.vr360dec", allocated.omx_comp_name[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_video_dec_vp9_vr360_p1 end..."); -} - -TEST(ut_rm_api, alloc_video_dec_hevc_vr360_p1) -{ - RM_TEST_MSG("alloc_video_dec_hevc_vr360_p1 start..."); - - int handle = 0; - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); - - rm_category_request_s request; - memset(&request, 0, sizeof(rm_category_request_s)); - - ri_video_category_option_request_s option; - memset(&option, 0, sizeof(ri_video_category_option_request_s)); - - option.codec_name = "HEVC_VR360"; - option.color_depth = 8; - option.framerate = 60; - option.h_size = 1920; - option.v_size = 1080; - option.sampling_format = RI_SAMPLING_FORMAT_420; - - request.request_num = 1; - request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; - request.category_option[0] = ri_get_capable_video_category_id(&option); - request.state[0] = RM_STATE_EXCLUSIVE; - - rm_device_return_s allocated; - memset(&allocated, 0, sizeof(rm_device_return_s)); - - EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); - EXPECT_EQ(1, allocated.allocated_num); - EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_VR360DEC, allocated.device_id[0]); - EXPECT_EQ(0, rm_tc_get_conflict_num()); - rm_tc_reset_conflict_num(); - - EXPECT_EQ(RM_OK, rm_unregister(handle)); - - RM_TEST_MSG("alloc_video_dec_hevc_vr360_p1 end..."); -} +/* + * 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" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +TEST(ut_rm_api, alloc_video_dec_av1_vr360_p1) +{ + RM_TEST_MSG("alloc_video_dec_av1_vr360_p1 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "AV1_VR360"; + option.color_depth = 8; + option.framerate = 30; + option.h_size = 1920; + option.v_size = 1080; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_capable_video_category_id(&option); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_VR360DEC, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_video_dec_av1_vr360_p1 end..."); +} + +TEST(ut_rm_api, alloc_video_dec_av1_vr360_p2) +{ + RM_TEST_MSG("alloc_video_dec_av1_vr360_p2 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "AV1_VR360"; + option.color_depth = 8; + option.framerate = 60; + option.h_size = 3840; + option.v_size = 2160; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_capable_video_category_id(&option); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + if (is_support_4k()) { + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_VR360DEC, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + } else { + EXPECT_NE(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(0, allocated.allocated_num); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + } + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_video_dec_av1_vr360_p2 end..."); +} + +TEST(ut_rm_api, alloc_video_dec_h264_vr360_p1) +{ + RM_TEST_MSG("alloc_video_dec_h264_vr360_p1 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "H264_VR360"; + option.color_depth = 8; + option.framerate = 60; + option.h_size = 1920; + option.v_size = 1080; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_capable_video_category_id(&option); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_VR360DEC, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_video_dec_h264_vr360_p1 end..."); +} + +TEST(ut_rm_api, alloc_video_dec_vp9_vr360_p1) +{ + RM_TEST_MSG("alloc_video_dec_vp9_vr360_p1 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "VP9_VR360"; + option.color_depth = 8; + option.framerate = 60; + option.h_size = 1920; + option.v_size = 1080; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_capable_video_category_id(&option); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_VR360DEC, allocated.device_id[0]); + EXPECT_STREQ("OMX.SDP.video_decoder.vr360dec", allocated.omx_comp_name[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_video_dec_vp9_vr360_p1 end..."); +} + +TEST(ut_rm_api, alloc_video_dec_hevc_vr360_p1) +{ + RM_TEST_MSG("alloc_video_dec_hevc_vr360_p1 start..."); + + int handle = 0; + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_register(rm_cb_counting_conflicted, NULL, &handle, NULL)); + + rm_category_request_s request; + memset(&request, 0, sizeof(rm_category_request_s)); + + ri_video_category_option_request_s option; + memset(&option, 0, sizeof(ri_video_category_option_request_s)); + + option.codec_name = "HEVC_VR360"; + option.color_depth = 8; + option.framerate = 60; + option.h_size = 1920; + option.v_size = 1080; + option.sampling_format = RI_SAMPLING_FORMAT_420; + + request.request_num = 1; + request.category_id[0] = RM_CATEGORY_VIDEO_DECODER; + request.category_option[0] = ri_get_capable_video_category_id(&option); + request.state[0] = RM_STATE_EXCLUSIVE; + + rm_device_return_s allocated; + memset(&allocated, 0, sizeof(rm_device_return_s)); + + EXPECT_EQ(RM_OK, rm_allocate_resources(handle, &request, &allocated)); + EXPECT_EQ(1, allocated.allocated_num); + EXPECT_EQ(RM_DEVICE_VIDEO_DECODER_VR360DEC, allocated.device_id[0]); + EXPECT_EQ(0, rm_tc_get_conflict_num()); + rm_tc_reset_conflict_num(); + + EXPECT_EQ(RM_OK, rm_unregister(handle)); + + RM_TEST_MSG("alloc_video_dec_hevc_vr360_p1 end..."); +}