From: Jeongmo Yang Date: Wed, 9 Jun 2021 03:52:27 +0000 (+0900) Subject: Initial release X-Git-Tag: submit/tizen/20210614.015451^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58f172cb7f4d05432c3fbaba90e79fe5147d941c;p=platform%2Fhal%2Fapi%2Fcodec.git Initial release - The "codec-haltests" is only included in this package, because there is no codec HAL interface, but GStreamer codec plugin is used for HAL. [Version] 0.0.1 [Issue Type] Initial release Change-Id: I58074e4fb13dd68dc6a8b75664288f6adcbc04ec Signed-off-by: Jeongmo Yang --- diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..95b7275 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,4 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +ADD_SUBDIRECTORY(tests) + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c5455bc --- /dev/null +++ b/LICENSE @@ -0,0 +1,203 @@ +Copyright (c) 2000 - 2021 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/hal-api-codec-haltests.manifest b/hal-api-codec-haltests.manifest new file mode 100644 index 0000000..81ace0c --- /dev/null +++ b/hal-api-codec-haltests.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/packaging/hal-api-codec.spec b/packaging/hal-api-codec.spec new file mode 100644 index 0000000..fa71e35 --- /dev/null +++ b/packaging/hal-api-codec.spec @@ -0,0 +1,64 @@ +%define module_name codec +%define name hal-api-%{module_name} +%define res_path /testcase/res/codec + +### main package ######### +Name: %{name} +Summary: %{name} interface +Version: 0.0.1 +Release: 0 +Group: Development/Libraries +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gmock) +BuildRequires: pkgconfig(gstreamer-1.0) +BuildRequires: pkgconfig(gstreamer-plugins-base-1.0) +BuildRequires: pkgconfig(iniparser) +BuildRequires: pkgconfig(libtbm) + +%description +%{name} interface package for product vendor developer + + +### test package ######### +%package haltests +Summary: tests for %{name} + +%description haltests +Haltests for %{name} + + +### build and install ######### +%prep +%setup -q +export CXXFLAGS+=" -D_LARGEFILE64_SOURCE -DSYSCONFDIR=\\\"%{_hal_sysconfdir}\\\" -DTEST_FILES_PATH=\\\"%{_datadir}%{res_path}\\\"" +%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_LIBDIR_PREFIX=%{_libdir} -DTESTCASE_RES_DIR=%{_datadir}%{res_path} + +%build +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +install -d -m 755 %{buildroot}%{_datadir}%{res_path} +install -m 644 tests/res/* %{buildroot}%{_datadir}%{res_path} +%make_install + +%clean +rm -rf %{buildroot} + +%post +/sbin/ldconfig + +%postun +/sbin/ldconfig + + +%files haltests +%manifest %{name}-haltests.manifest +%{_bindir}/hal/codec-haltests +%{_datadir}%{res_path}/* diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..a5f7081 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,24 @@ +SET(HAL_CODEC_TEST "codec-haltests") + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "${CMAKE_INSTALL_PREFIX}/bin") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Werror") + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ HALTEST_SRCS) +ADD_EXECUTABLE(${HAL_CODEC_TEST} ${HALTEST_SRCS}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(${HAL_CODEC_TEST} REQUIRED glib-2.0 gmock gstreamer-1.0 gstreamer-plugins-base-1.0 iniparser libtbm) + +FOREACH(flag ${${HAL_CODEC_TEST}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIC -pie -Wall") + +TARGET_LINK_LIBRARIES(${HAL_CODEC_TEST} ${${HAL_CODEC_TEST}_LDFLAGS}) +SET_TARGET_PROPERTIES(${HAL_CODEC_TEST} PROPERTIES COMPILE_FLAGS "-fPIE") +SET_TARGET_PROPERTIES(${HAL_CODEC_TEST} PROPERTIES LINK_FLAGS "-pie") + +INSTALL(TARGETS ${HAL_CODEC_TEST} DESTINATION ${EXEC_PREFIX}/hal/) + diff --git a/tests/codec_hal_test.cpp b/tests/codec_hal_test.cpp new file mode 100644 index 0000000..63b78f2 --- /dev/null +++ b/tests/codec_hal_test.cpp @@ -0,0 +1,773 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Jeongmo Yang + * + * 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 + +using namespace std; +typedef struct _codec_list_t codec_list_t; +#define CNAME_SIZE 512 +#define CODEC_INI_MAX_STRLEN 256 +#define DEFAULT_PORT "GST_PORT" +#define CODEC_INI_DEFAULT_PATH SYSCONFDIR"/multimedia/mmfw_media_codec.ini" + +#define CODEC_INI_GET_STRING(x_dict, x_item, x_ini, x_default) \ +do {\ + const char *str = iniparser_getstring(x_dict, x_ini, x_default); \ + \ + if (str && \ + (strlen(str) > 0) && \ + (strlen(str) < CODEC_INI_MAX_STRLEN)) \ + strncpy(x_item, str, strlen(str) + 1); \ + else \ + strncpy(x_item, x_default, strlen(x_default) + 1); \ +} while (0) + +typedef enum { + H263, + H264, + MPEG4 +} codec_list_e; + +struct _codec_list_t { + codec_list_e ename; + char cname[CODEC_INI_MAX_STRLEN]; + char plugins[2][CODEC_INI_MAX_STRLEN]; +}; + +static codec_list_t codec_list[] = { + { H263, "h263", }, + { H264, "h264", }, + { MPEG4, "mpeg4" }, +}; + +void get_plugins_list_from_ini(dictionary *dict, codec_list_t *codec_list, int codec_num) +{ + int i, j; + int index = 0; + char *token = NULL; + char *usr_ptr = NULL; + const char *delimiters = " ,"; + size_t len; + char port_name[CNAME_SIZE]; + char temp[CNAME_SIZE]; + char cname[CNAME_SIZE]; + const char *type[2]; + type[0] = ":hw_decoder"; + type[1] = ":hw_encoder"; + + CODEC_INI_GET_STRING(dict, port_name, (char *)"port_in_use:media_codec_port", (char *)DEFAULT_PORT); + + if (strcmp(port_name, DEFAULT_PORT) == 0) { + for (i = 0; i < 2; i++) { + for (j = 0; j < codec_num; j++) { + index = 0; + + snprintf(cname, CNAME_SIZE, "%s", codec_list[j].cname); + len = strlen(cname); + snprintf(cname + len, CNAME_SIZE - len, "%s", type[i]); + CODEC_INI_GET_STRING(dict, temp, cname, (char *)""); + token = strtok_r(temp, delimiters, &usr_ptr); + + while (token) { + if (token && index == 0) + strncpy(codec_list[j].plugins[i], token, strlen(token) + 1); + token = strtok_r(NULL, delimiters, &usr_ptr); + index++; + } + } + } + } +} + +static void +pad_added_cb(GstElement * demux, GstPad * pad, GstBin * pipeline) +{ + GstElement *sink, *parse, *codec; + GstCaps *caps; + + GST_INFO_OBJECT(pad, "got pad"); + + caps = gst_pad_query_caps(pad, NULL); + gchar *caps_str = gst_caps_to_string(caps); + gst_caps_unref(caps); + + if (strstr(caps_str, "h264")) { + parse = gst_element_factory_make("h264parse", NULL); + codec = gst_element_factory_make(codec_list[H264].plugins[0], NULL); + } else if (strstr(caps_str, "h263")) { + parse = gst_element_factory_make("h263parse", NULL); + codec = gst_element_factory_make(codec_list[H263].plugins[0], NULL); + } else if (strstr(caps_str, "video/mpeg")) { + parse = gst_element_factory_make("mpeg4videoparse", NULL); + codec = gst_element_factory_make(codec_list[MPEG4].plugins[0], NULL); + } else { + GST_WARNING_OBJECT(pad, "non video pad"); + g_free(caps_str); + return; + } + + sink = gst_element_factory_make("fakesink", NULL); + gst_bin_add_many(GST_BIN(pipeline), parse, codec, sink, NULL); + gst_element_link_many(demux, parse, codec, sink, NULL); + + gst_element_set_state(parse, GST_STATE_PAUSED); + gst_element_set_state(codec, GST_STATE_PAUSED); + gst_element_set_state(sink, GST_STATE_PAUSED); + g_free(caps_str); +} + +static GstBusSyncReply +error_cb(GstBus * bus, GstMessage * msg, gpointer user_data) +{ + if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_ERROR) { + const gchar *file = (const gchar *)user_data; + GError *err = NULL; + gchar *dbg = NULL; + + gst_message_parse_error(msg, &err, &dbg); + g_error("ERROR for %s: %s\n%s\n", file, err->message, dbg); + } + + return GST_BUS_PASS; +} + +gboolean bus_callback(GstBus *bus, GstMessage *msg, gpointer data) +{ + switch (GST_MESSAGE_TYPE(msg)) { + case GST_MESSAGE_EOS: + break; + case GST_MESSAGE_ERROR: + break; + default: + break; + } + return TRUE; +} + +void buffer_add(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer data) +{ +} + +/* + * main class + */ +class CodecHalTest : public testing::Test +{ + public: + + virtual void SetUp() + { + return; + } + + virtual void TearDown() + { + + return; + } + +}; + +/** + * @testcase InitH263DecoderP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Initialize H.263 Decoder Plugin + * @apicovered N/A + * @passcase when h263 decoder plugin exists pipeline can be changed to GST_STATE_PAUSED + * @failcase when the state is not changed to GST_STATE_PAUSED + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, InitH263DecoderP) +{ + GstElement *sink, *src, *codec, *pipeline; + GstStateChangeReturn ret; + + pipeline = gst_pipeline_new("pipeline"); + src = gst_element_factory_make("fakesrc", NULL); + codec = gst_element_factory_make(codec_list[H263].plugins[0], NULL); + sink = gst_element_factory_make("fakesink", NULL); + + gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL); + + ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE); + + gst_object_unref(pipeline); +} + +/** + * @testcase InitH264DecoderP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Initialize H.263 Decoder Plugin + * @apicovered N/A + * @passcase when h264 decoder plugin exists pipeline can be changed to GST_STATE_PAUSED + * @failcase when the state is not changed to GST_STATE_PAUSED + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, InitH264DecoderP) +{ + GstElement *sink, *src, *codec, *pipeline; + GstStateChangeReturn ret; + + pipeline = gst_pipeline_new("pipeline"); + src = gst_element_factory_make("fakesrc", NULL); + codec = gst_element_factory_make(codec_list[H264].plugins[0], NULL); + sink = gst_element_factory_make("fakesink", NULL); + + gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL); + + ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE); + + gst_object_unref(pipeline); +} + +/** + * @testcase InitMpeg4DecoderP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Initialize MPEG4 Decoder Plugin + * @apicovered N/A + * @passcase when MPEG4 decoder plugin exists pipeline can be changed to GST_STATE_PAUSED + * @failcase when the state is not changed to GST_STATE_PAUSED + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, InitMpeg4DecoderP) +{ + GstElement *sink, *src, *codec, *pipeline; + GstStateChangeReturn ret; + + pipeline = gst_pipeline_new("pipeline"); + src = gst_element_factory_make("fakesrc", NULL); + codec = gst_element_factory_make(codec_list[MPEG4].plugins[0], NULL); + sink = gst_element_factory_make("fakesink", NULL); + + gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL); + + ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE); + + gst_object_unref(pipeline); +} + +/** + * @testcase InitH263EncoderP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Initialize H.263 Encoder Plugin + * @apicovered N/A + * @passcase when H.263 encoder plugin exists pipeline can be changed to GST_STATE_PAUSED + * @failcase when the state is not changed to GST_STATE_PAUSED + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, InitH263EncoderP) +{ + GstElement *sink, *src, *codec, *pipeline; + GstStateChangeReturn ret; + + pipeline = gst_pipeline_new("pipeline"); + src = gst_element_factory_make("fakesrc", NULL); + codec = gst_element_factory_make(codec_list[H263].plugins[1], NULL); + sink = gst_element_factory_make("fakesink", NULL); + + gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL); + + ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE); + + gst_object_unref(pipeline); +} + +/** + * @testcase InitH264EncoderP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Initialize H.264 Encoder Plugin + * @apicovered N/A + * @passcase when H.264 encoder plugin exists pipeline can be changed to GST_STATE_PAUSED + * @failcase when the state is not changed to GST_STATE_PAUSED + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, InitH264EncoderP) +{ + GstElement *sink, *src, *codec, *pipeline; + GstStateChangeReturn ret; + + pipeline = gst_pipeline_new("pipeline"); + src = gst_element_factory_make("fakesrc", NULL); + codec = gst_element_factory_make(codec_list[H264].plugins[1], NULL); + sink = gst_element_factory_make("fakesink", NULL); + + gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL); + + ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE); + + gst_object_unref(pipeline); +} + +/** + * @testcase InitMPEG4EncoderP + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Initialize H.264 Encoder Plugin + * @apicovered N/A + * @passcase when MPEG4 encoder plugin exists pipeline can be changed to GST_STATE_PAUSED + * @failcase when the state is not changed to GST_STATE_PAUSED + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, InitMpeg4EncoderP) +{ + GstElement *sink, *src, *codec, *pipeline; + GstStateChangeReturn ret; + + pipeline = gst_pipeline_new("pipeline"); + src = gst_element_factory_make("fakesrc", NULL); + codec = gst_element_factory_make(codec_list[MPEG4].plugins[1], NULL); + sink = gst_element_factory_make("fakesink", NULL); + + gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL); + + ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + EXPECT_NE(ret, GST_STATE_CHANGE_FAILURE); + + gst_object_unref(pipeline); +} + +/** + * @testcase DecodeH264P + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Decode H.264 Decoder Plugin + * @apicovered N/A + * @passcase when h264 decoder decode stream, pipeline can be changed to GST_STATE_PLAYING + * @failcase when the state is not changed to GST_STATE_PLAYING + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, DecodeH264P) +{ + GstStateChangeReturn state_ret; + GstElement *src, *demux, *pipeline; + GstMessage *msg; + GstBus *bus; + gchar *path; + + pipeline = gst_pipeline_new("pipeline"); + + src = gst_element_factory_make("filesrc", NULL); + + demux = gst_element_factory_make("qtdemux", NULL); + + bus = gst_element_get_bus(pipeline); + + /* kids, don't use a sync handler for this at home, really; we do because + * we just want to abort and nothing else */ + gst_bus_set_sync_handler(bus, error_cb, (gpointer) "meerkat.mp4", NULL); + + gst_bin_add_many(GST_BIN(pipeline), src, demux, NULL); + + gst_element_link(src, demux); + + path = g_build_filename(TEST_FILES_PATH, "meerkat.mp4", NULL); + GST_INFO("reading file '%s'", path); + g_object_set(src, "location", path, NULL); + + /* can't link uridecodebin and sink yet, do that later */ + g_signal_connect(demux, "pad-added", G_CALLBACK(pad_added_cb), pipeline); + + state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + + if (state_ret == GST_STATE_CHANGE_ASYNC) { + GST_INFO("waiting for pipeline to reach PAUSED state"); + state_ret = gst_element_get_state(pipeline, NULL, NULL, -1); + } + + state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING); + EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE); + + GST_INFO("PAUSED, let's decode"); + msg = gst_bus_timed_pop_filtered(bus, 10 * GST_SECOND, GST_MESSAGE_EOS); + GST_INFO("Done, got EOS message"); + + gst_message_unref(msg); + gst_object_unref(bus); + + gst_element_set_state(pipeline, GST_STATE_NULL); + EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS); + + gst_object_unref(pipeline); + g_free(path); +} + +/** + * @testcase DecodeH263P + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Decode H.263 Decoder Plugin + * @apicovered N/A + * @passcase when h263 decoder decode stream, pipeline can be changed to GST_STATE_PLAYING + * @failcase when the state is not changed to GST_STATE_PLAYING + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, DecodeH263P) +{ + GstStateChangeReturn state_ret; + GstElement *src, *demux, *pipeline; + GstMessage *msg; + GstBus *bus; + gchar *path; + + pipeline = gst_pipeline_new("pipeline"); + + src = gst_element_factory_make("filesrc", NULL); + + demux = gst_element_factory_make("qtdemux", NULL); + + bus = gst_element_get_bus(pipeline); + + /* kids, don't use a sync handler for this at home, really; we do because + * we just want to abort and nothing else */ + gst_bus_set_sync_handler(bus, error_cb, (gpointer)"she.3gp", NULL); + + gst_bin_add_many(GST_BIN(pipeline), src, demux, NULL); + + gst_element_link(src, demux); + + path = g_build_filename(TEST_FILES_PATH, "she.3gp", NULL); + GST_INFO("reading file '%s'", path); + g_object_set(src, "location", path, NULL); + + /* can't link uridecodebin and sink yet, do that later */ + g_signal_connect(demux, "pad-added", G_CALLBACK(pad_added_cb), pipeline); + + state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + + if (state_ret == GST_STATE_CHANGE_ASYNC) { + GST_INFO("waiting for pipeline to reach PAUSED state"); + state_ret = gst_element_get_state(pipeline, NULL, NULL, -1); + } + + state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING); + EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE); + + GST_INFO("PAUSED, let's decode"); + msg = gst_bus_timed_pop_filtered(bus, 10 * GST_SECOND, GST_MESSAGE_EOS); + GST_INFO("Done, got EOS message"); + + gst_message_unref(msg); + gst_object_unref(bus); + + state_ret = gst_element_set_state(pipeline, GST_STATE_NULL); + EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS); + gst_object_unref(pipeline); + + g_free(path); +} + +/** + * @testcase DecodeMPEG4P + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Decode MPEG4 Decoder Plugin + * @apicovered N/A + * @passcase when MPEG4 decoder decode stream, pipeline can be changed to GST_STATE_PLAYING + * @failcase when the state is not changed to GST_STATE_PLAYING + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, DecodeMPEG4P) +{ + GstStateChangeReturn state_ret; + GstElement *src, *demux, *pipeline; + GstMessage *msg; + GstBus *bus; + gchar *path; + + pipeline = gst_pipeline_new("pipeline"); + + src = gst_element_factory_make("filesrc", NULL); + + demux = gst_element_factory_make("qtdemux", NULL); + + bus = gst_element_get_bus(pipeline); + + /* kids, don't use a sync handler for this at home, really; we do because + * we just want to abort and nothing else */ + gst_bus_set_sync_handler(bus, error_cb, (gpointer)"mv.MP4", NULL); + + gst_bin_add_many(GST_BIN(pipeline), src, demux, NULL); + + gst_element_link(src, demux); + + path = g_build_filename(TEST_FILES_PATH, "mv.MP4", NULL); + GST_INFO("reading file '%s'", path); + g_object_set(src, "location", path, NULL); + + /* can't link uridecodebin and sink yet, do that later */ + g_signal_connect(demux, "pad-added", G_CALLBACK(pad_added_cb), pipeline); + + state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + + if (state_ret == GST_STATE_CHANGE_ASYNC) { + GST_INFO("waiting for pipeline to reach PAUSED state"); + state_ret = gst_element_get_state(pipeline, NULL, NULL, -1); + } + + state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING); + EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE); + + GST_INFO("PAUSED, let's decode"); + msg = gst_bus_timed_pop_filtered(bus, 10 * GST_SECOND, GST_MESSAGE_EOS); + GST_INFO("Done, got EOS message"); + + gst_message_unref(msg); + gst_object_unref(bus); + + state_ret = gst_element_set_state(pipeline, GST_STATE_NULL); + EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS); + gst_object_unref(pipeline); + + g_free(path); +} + +#if 0 +/** + * @testcase EncodeH264P + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Encode H.264 Decoder Plugin + * @apicovered N/A + * @passcase when H.264 encoder encode buffer, outbuffer will be dequed + * @failcase when the state is not changed to GST_STATE_PLAYING or the error occur + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, EncodeH264P) +{ + GstStateChangeReturn state_ret; + GstElement *sink, *src, *codec, *pipeline; + GstMessage *msg; + GstBus *bus; + gchar *path; + gint bus_watch_id; + gulong signal_handoff; + GstBuffer *buffer; + GstAllocator *allocator; + GstMemory *mem; + GstVideoInfo vinfo; + tbm_surface_h surface; + int i; + int ret; + + pipeline = gst_pipeline_new("pipeline"); + + src = gst_element_factory_make("appsrc", NULL); + + codec = gst_element_factory_make(codec_list[H264].plugins[1], NULL); + + bus = gst_element_get_bus(pipeline); + bus_watch_id = gst_bus_add_watch(bus, bus_callback, NULL); + gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL); + gst_element_link_many(src, codec, sink, NULL); + + signal_handoff = g_signal_connect(sink, "handoff", G_CALLBACK(buffer_add), NULL); + state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + + if (state_ret == GST_STATE_CHANGE_ASYNC) { + GST_INFO("waiting for pipeline to reach PAUSED state"); + state_ret = gst_element_get_state(pipeline, NULL, NULL, -1); + } + + state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING); + EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE); + + allocator = gst_tizen_allocator_new(); + + for (i = 0; i < 5; i++) { + surface = tbm_surface_internal_create_with_flags(640, 480, TBM_FORMAT_NV12, TBM_BO_NONCACHABLE); + mem = gst_tizen_allocator_alloc_surface(allocator, &vinfo, surface, NULL, NULL); + gst_buffer_append_memory(buffer, mem); + ret = gst_app_src_push_buffer((GstAppSrc*)src, buffer); + } + + g_signal_handler_disconnect(sink, signal_handoff); + gst_object_unref(bus); + + state_ret = gst_element_set_state(pipeline, GST_STATE_NULL); + EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS); + + gst_object_unref(pipeline); +} + +/** + * @testcase EncodeH263P + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Encode H.263 Decoder Plugin + * @apicovered N/A + * @passcase when H.263 encoder encode buffer, outbuffer will be dequed + * @failcase when the state is not changed to GST_STATE_PLAYING or the error occur + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, EncodeH263P) +{ + GstStateChangeReturn state_ret; + GstElement *sink, *src, *codec, *pipeline; + GstMessage *msg; + GstBus *bus; + gchar *path; + gint bus_watch_id; + + pipeline = gst_pipeline_new("pipeline"); + + src = gst_element_factory_make("appsrc", NULL); + + codec = gst_element_factory_make(codec_list[H263].plugins[1], NULL); + + bus = gst_element_get_bus(pipeline); + bus_watch_id = gst_bus_add_watch(bus, bus_callback, NULL); + gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL); + gst_element_link_many(src, codec, sink, NULL); + + state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + + if (state_ret == GST_STATE_CHANGE_ASYNC) { + GST_INFO("waiting for pipeline to reach PAUSED state"); + state_ret = gst_element_get_state(pipeline, NULL, NULL, -1); + } + + state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING); + EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE); + + GST_INFO("PAUSED, let's encode"); + gst_object_unref(bus); + + state_ret = gst_element_set_state(pipeline, GST_STATE_NULL); + EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS); + gst_object_unref(pipeline); +} + +/** + * @testcase EncodeMPEG4P + * @since_tizen 6.5 + * @author SR(jm80.yang) + * @reviewer SR(heechul.jeon) + * @type auto + * @description Positive, Encode MPEG4 Decoder Plugin + * @apicovered N/A + * @passcase when MPEG4 encoder encode buffer, outbuffer will be dequed + * @failcase when the state is not changed to GST_STATE_PLAYING or the error occur + * @precondition None + * @postcondition None + */ +TEST_F(CodecHalTest, EncodeMPEG4P) +{ + GstStateChangeReturn state_ret; + GstElement *sink, *src, *codec, *pipeline; + GstMessage *msg; + GstBus *bus; + gchar *path; + gint bus_watch_id; + + pipeline = gst_pipeline_new("pipeline"); + + src = gst_element_factory_make("appsrc", NULL); + + codec = gst_element_factory_make(codec_list[MPEG4].plugins[1], NULL); + + bus = gst_element_get_bus(pipeline); + bus_watch_id = gst_bus_add_watch(bus, bus_callback, NULL); + gst_bin_add_many(GST_BIN(pipeline), src, codec, sink, NULL); + gst_element_link_many(src, codec, sink, NULL); + + state_ret = gst_element_set_state(pipeline, GST_STATE_PAUSED); + + if (state_ret == GST_STATE_CHANGE_ASYNC) { + GST_INFO("waiting for pipeline to reach PAUSED state"); + state_ret = gst_element_get_state(pipeline, NULL, NULL, -1); + } + + state_ret = gst_element_set_state(pipeline, GST_STATE_PLAYING); + EXPECT_NE(state_ret, GST_STATE_CHANGE_FAILURE); + + GST_INFO("PAUSED, let's encode"); + gst_object_unref(bus); + + state_ret = gst_element_set_state(pipeline, GST_STATE_NULL); + EXPECT_EQ(state_ret, GST_STATE_CHANGE_SUCCESS); + gst_object_unref(pipeline); +} +#endif + +int main(int argc, char **argv) +{ + int codec_num; + dictionary *dict; + + gst_init(&argc, &argv); + dict = iniparser_load(CODEC_INI_DEFAULT_PATH); + + codec_num = sizeof(codec_list) / sizeof(codec_list[0]); + get_plugins_list_from_ini(dict, codec_list, codec_num); + iniparser_freedict(dict); + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/tests/res/meerkat.mp4 b/tests/res/meerkat.mp4 new file mode 100644 index 0000000..69270dc Binary files /dev/null and b/tests/res/meerkat.mp4 differ diff --git a/tests/res/mv.MP4 b/tests/res/mv.MP4 new file mode 100644 index 0000000..15b0e54 Binary files /dev/null and b/tests/res/mv.MP4 differ diff --git a/tests/res/she.3gp b/tests/res/she.3gp new file mode 100644 index 0000000..419d465 Binary files /dev/null and b/tests/res/she.3gp differ