From: Jeongmo Yang Date: Tue, 15 Apr 2025 10:00:24 +0000 (+0900) Subject: test: Separate test class for decoder and encoder X-Git-Tag: accepted/tizen/unified/20250530.090452~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=766c6e533dae10ac156e3ce7ce72f2fbb6d53af2;p=platform%2Fhal%2Fapi%2Fcodec.git test: Separate test class for decoder and encoder [Version] 1.3.2 [Issue Type] Test Change-Id: I8e9ca0ac7c0a3eb3625ca11aff042c1d034fd380 Signed-off-by: Jeongmo Yang --- diff --git a/packaging/hal-api-codec.spec b/packaging/hal-api-codec.spec index 3e44768..5b2fc67 100644 --- a/packaging/hal-api-codec.spec +++ b/packaging/hal-api-codec.spec @@ -6,7 +6,7 @@ ### main package ######### Name: %{name} Summary: %{name} interface -Version: 1.3.1 +Version: 1.3.2 Release: 0 Group: Development/Libraries License: Apache-2.0 diff --git a/tests/codec_hal_test.cpp b/tests/codec_hal_test.cpp index 6a840d6..282edfb 100644 --- a/tests/codec_hal_test.cpp +++ b/tests/codec_hal_test.cpp @@ -70,63 +70,14 @@ static bool gDecoderSupported; static bool gEncoderSupported; static void *gHalHandleDec; static void *gHalHandleEnc; -static void *gCurrentHandle; static guint gTimeoutSourceID; static guint gFeedCount; static guint gOutputCount; static GMainLoop *gMainLoop; -/* - * main class - */ -class CodecHalTest : public testing::Test +class CodecHalTest { public: - virtual void SetUp() - { - gDecoderSupported = true; - gEncoderSupported = true; - - dec_ret = hal_codec_init(HAL_CODEC_TYPE_DECODER, &gHalHandleDec); - if (dec_ret == HAL_CODEC_ERROR_NOT_SUPPORTED) { - cout << "Codec HAL[Decoder] Not Supported" << endl; - gDecoderSupported = false; - } else if (dec_ret == HAL_CODEC_ERROR_NONE) { - cout << "Codec HAL[Decoder] init - handle: " << gHalHandleDec << endl; - } else { - cout << "Codec HAL[Decoder] init failed " << dec_ret << endl; - } - - enc_ret = hal_codec_init(HAL_CODEC_TYPE_ENCODER, &gHalHandleEnc); - if (enc_ret == HAL_CODEC_ERROR_NOT_SUPPORTED) { - cout << "Codec HAL[Encoder] Not Supported" << endl; - gDecoderSupported = false; - } else if (enc_ret == HAL_CODEC_ERROR_NONE) { - cout << "Codec HAL[Encoder] init - handle: " << gHalHandleEnc << endl; - } else { - cout << "Codec HAL[Encoder] init failed " << enc_ret << endl; - } - } - - virtual void TearDown() - { - if (gHalHandleDec) { - cout << "Codec HAL[Decoder] deinit - handle: " << gHalHandleDec << endl; - hal_codec_deinit(gHalHandleDec); - gHalHandleDec = nullptr; - } - - if (gHalHandleEnc) { - cout << "Codec HAL[Decoder] deinit - handle: " << gHalHandleEnc << endl; - hal_codec_deinit(gHalHandleEnc); - gHalHandleEnc = nullptr; - } - - ReleaseContents(); - - return; - } - static void DumpBuffer(hal_codec_buffer_s *buffer, const char *dumpPath) { static int dumpCount = 0; @@ -150,13 +101,15 @@ class CodecHalTest : public testing::Test } dumpCount++; - cout << "Dump[count:" << dumpCount << "] buffer size[" << totalWrite << "]" << endl; + cout << "Dump[" << dumpPath << ", count:" << dumpCount << "] buffer size[" << totalWrite << "]" << endl; fout.close(); } static int MessageCb(hal_codec_message_s *message, void *user_data) { + void *halHandle = user_data; + if (!message) { cout << "Codec HAL : NULL message" << endl; return 0; @@ -171,7 +124,7 @@ class CodecHalTest : public testing::Test if (message->buffer->meta.flags & HAL_CODEC_BUFFER_FLAG_EOS) { cout << "[OUTPUT_BUFFER] Got EOS(output count: " << gOutputCount; cout << "), remove timeout source " << gTimeoutSourceID << endl; - hal_codec_release_output_buffer(gCurrentHandle, message->buffer->index); + hal_codec_release_output_buffer(halHandle, message->buffer->index); g_source_remove(gTimeoutSourceID); g_main_loop_quit(gMainLoop); break; @@ -181,13 +134,10 @@ class CodecHalTest : public testing::Test cout << "[OUTPUT_BUFFER] index: " << message->buffer->index << endl; - if (g_dump_decoder_output && gCurrentHandle == gHalHandleDec) + if (g_dump_decoder_output) DumpBuffer(message->buffer, "/home/owner/media/dump.yuv"); - if (g_dump_encoder_output && gCurrentHandle == gHalHandleEnc) - DumpBuffer(message->buffer, "/home/owner/media/dump.h264"); - - hal_codec_release_output_buffer(gCurrentHandle, message->buffer->index); + hal_codec_release_output_buffer(halHandle, message->buffer->index); break; default: cout << "[UNHANDLED MSG] type: " << message->type << endl; @@ -228,6 +178,56 @@ class CodecHalTest : public testing::Test mappedFileContents_ = nullptr; } + bool CheckCurrentState(void *handle, hal_codec_state_e state) + { + hal_codec_state_e state_; + if (hal_codec_get_state(handle, &state_) != HAL_CODEC_ERROR_NONE) { + cout << "get_state failed " << ret << endl; + return false; + } + + return (state_ == state); + } + + GMappedFile *mappedFile_ {}; + gsize mappedFileLength_ {}; + gchar *mappedFileContents_ {}; + gsize mappedFileOffset_ {}; + hal_codec_buffer_s buffer_[CONTENTS_H264_FRAME_NUM + 1] {}; +}; + + +class CodecHalTestDecoder : public testing::Test, public CodecHalTest +{ + public: + virtual void SetUp() + { + gDecoderSupported = true; + + dec_ret = hal_codec_init(HAL_CODEC_TYPE_DECODER, &gHalHandleDec); + if (dec_ret == HAL_CODEC_ERROR_NOT_SUPPORTED) { + cout << "Codec HAL[Decoder] Not Supported" << endl; + gDecoderSupported = false; + } else if (dec_ret == HAL_CODEC_ERROR_NONE) { + cout << "Codec HAL[Decoder] init - handle: " << gHalHandleDec << endl; + } else { + cout << "Codec HAL[Decoder] init failed " << dec_ret << endl; + } + } + + virtual void TearDown() + { + if (gHalHandleDec) { + cout << "Codec HAL[Decoder] deinit - handle: " << gHalHandleDec << endl; + hal_codec_deinit(gHalHandleDec); + gHalHandleDec = nullptr; + } + + ReleaseContents(); + + return; + } + int FeedDataDecode(void) { memset(&buffer_[gFeedCount], 0x0, sizeof(hal_codec_buffer_s)); @@ -264,6 +264,39 @@ class CodecHalTest : public testing::Test return G_SOURCE_CONTINUE; } } +}; + + +class CodecHalTestEncoder : public testing::Test, public CodecHalTest +{ + public: + virtual void SetUp() + { + gEncoderSupported = true; + + enc_ret = hal_codec_init(HAL_CODEC_TYPE_ENCODER, &gHalHandleEnc); + if (enc_ret == HAL_CODEC_ERROR_NOT_SUPPORTED) { + cout << "Codec HAL[Encoder] Not Supported" << endl; + gDecoderSupported = false; + } else if (enc_ret == HAL_CODEC_ERROR_NONE) { + cout << "Codec HAL[Encoder] init - handle: " << gHalHandleEnc << endl; + } else { + cout << "Codec HAL[Encoder] init failed " << enc_ret << endl; + } + } + + virtual void TearDown() + { + if (gHalHandleEnc) { + cout << "Codec HAL[Decoder] deinit - handle: " << gHalHandleEnc << endl; + hal_codec_deinit(gHalHandleEnc); + gHalHandleEnc = nullptr; + } + + ReleaseContents(); + + return; + } void EncodeDataNew(void) { @@ -349,6 +382,7 @@ class CodecHalTest : public testing::Test cout << "[FeedDataEncode] buffer[" << gFeedCount << "] " << &buffer_[gFeedCount] << endl; } else { + buffer_[gFeedCount].memory.num_fd = 0; buffer_[gFeedCount].meta.flags = HAL_CODEC_BUFFER_FLAG_EOS; cout << "[FeedDataEncode] Send EOS" << endl; @@ -367,28 +401,13 @@ class CodecHalTest : public testing::Test return G_SOURCE_CONTINUE; } - bool CheckCurrentState(void *handle, hal_codec_state_e state) - { - hal_codec_state_e state_; - if (hal_codec_get_state(handle, &state_) != HAL_CODEC_ERROR_NONE) { - cout << "get_state failed " << ret << endl; - return false; - } - - return (state_ == state); - } - - GMappedFile *mappedFile_ {}; - gsize mappedFileLength_ {}; - gchar *mappedFileContents_ {}; - gsize mappedFileOffset_ {}; - hal_codec_buffer_s buffer_[CONTENTS_H264_FRAME_NUM + 1] {}; tbm_surface_h tSurface_ {}; tbm_surface_info_s tsInfo_ {}; tbm_bo tBo_[TBM_SURF_PLANE_MAX] {}; int tFd_[TBM_SURF_PLANE_MAX] {}; }; + /** * @testcase DecoderInitP * @since_tizen 9.0 @@ -402,7 +421,7 @@ class CodecHalTest : public testing::Test * @precondition None * @postcondition None */ -TEST_F(CodecHalTest, DecoderInitP) +TEST_F(CodecHalTestDecoder, DecoderInitP) { DECODER_SUPPORT_CHECK; @@ -422,7 +441,7 @@ TEST_F(CodecHalTest, DecoderInitP) * @precondition None * @postcondition None */ -TEST_F(CodecHalTest, DecoderDeinitP) +TEST_F(CodecHalTestDecoder, DecoderDeinitP) { void *hal_handle = nullptr; @@ -451,7 +470,7 @@ TEST_F(CodecHalTest, DecoderDeinitP) * @precondition None * @postcondition None */ -TEST_F(CodecHalTest, DecoderConfigureReleaseP) +TEST_F(CodecHalTestDecoder, DecoderConfigureReleaseP) { DECODER_SUPPORT_CHECK; @@ -479,7 +498,7 @@ TEST_F(CodecHalTest, DecoderConfigureReleaseP) * @precondition None * @postcondition None */ -TEST_F(CodecHalTest, DecoderStartStopP) +TEST_F(CodecHalTestDecoder, DecoderStartStopP) { DECODER_SUPPORT_CHECK; @@ -490,9 +509,7 @@ TEST_F(CodecHalTest, DecoderStartStopP) HAL_CODEC_FORMAT_H264, HAL_CODEC_FORMAT_NV12, false); ASSERT_EQ(ret, HAL_CODEC_ERROR_NONE); - gCurrentHandle = gHalHandleDec; - - ret = hal_codec_start(gHalHandleDec, CodecHalTest::MessageCb, nullptr); + ret = hal_codec_start(gHalHandleDec, CodecHalTestDecoder::MessageCb, gHalHandleDec); ASSERT_EQ(ret, HAL_CODEC_ERROR_NONE); ret = hal_codec_stop(gHalHandleDec); @@ -515,7 +532,7 @@ TEST_F(CodecHalTest, DecoderStartStopP) * @precondition None * @postcondition None */ -TEST_F(CodecHalTest, DecoderDecodeP) +TEST_F(CodecHalTestDecoder, DecoderDecodeP) { DECODER_SUPPORT_CHECK; @@ -528,9 +545,7 @@ TEST_F(CodecHalTest, DecoderDecodeP) ASSERT_EQ(ret, HAL_CODEC_ERROR_NONE); ASSERT_TRUE(CheckCurrentState(gHalHandleDec, HAL_CODEC_STATE_CONFIGURED)); - gCurrentHandle = gHalHandleDec; - - ret = hal_codec_start(gHalHandleDec, CodecHalTest::MessageCb, nullptr); + ret = hal_codec_start(gHalHandleDec, CodecHalTestDecoder::MessageCb, gHalHandleDec); ASSERT_EQ(ret, HAL_CODEC_ERROR_NONE); ASSERT_TRUE(CheckCurrentState(gHalHandleDec, HAL_CODEC_STATE_STARTED)); @@ -543,7 +558,7 @@ TEST_F(CodecHalTest, DecoderDecodeP) gOutputCount = 0; g_timeout_add(50, [](gpointer user_data) -> gboolean { - CodecHalTest *self = (CodecHalTest *)user_data; + CodecHalTestDecoder *self = (CodecHalTestDecoder *)user_data; return self->FeedDataDecode(); }, this); @@ -586,7 +601,7 @@ TEST_F(CodecHalTest, DecoderDecodeP) * @precondition None * @postcondition None */ -TEST_F(CodecHalTest, EncoderInitP) +TEST_F(CodecHalTestEncoder, EncoderInitP) { ENCODER_SUPPORT_CHECK; @@ -606,7 +621,7 @@ TEST_F(CodecHalTest, EncoderInitP) * @precondition None * @postcondition None */ -TEST_F(CodecHalTest, EncoderDeinitP) +TEST_F(CodecHalTestEncoder, EncoderDeinitP) { void *hal_handle = nullptr; @@ -635,7 +650,7 @@ TEST_F(CodecHalTest, EncoderDeinitP) * @precondition None * @postcondition None */ -TEST_F(CodecHalTest, EncoderConfigureReleaseP) +TEST_F(CodecHalTestEncoder, EncoderConfigureReleaseP) { ENCODER_SUPPORT_CHECK; @@ -663,7 +678,7 @@ TEST_F(CodecHalTest, EncoderConfigureReleaseP) * @precondition None * @postcondition None */ -TEST_F(CodecHalTest, EncoderStartStopP) +TEST_F(CodecHalTestEncoder, EncoderStartStopP) { ENCODER_SUPPORT_CHECK; @@ -674,9 +689,7 @@ TEST_F(CodecHalTest, EncoderStartStopP) HAL_CODEC_FORMAT_NV12, HAL_CODEC_FORMAT_H264, false); ASSERT_EQ(ret, HAL_CODEC_ERROR_NONE); - gCurrentHandle = gHalHandleEnc; - - ret = hal_codec_start(gHalHandleEnc, CodecHalTest::MessageCb, nullptr); + ret = hal_codec_start(gHalHandleEnc, CodecHalTestEncoder::MessageCb, gHalHandleEnc); ASSERT_EQ(ret, HAL_CODEC_ERROR_NONE); ret = hal_codec_stop(gHalHandleEnc); @@ -699,7 +712,7 @@ TEST_F(CodecHalTest, EncoderStartStopP) * @precondition None * @postcondition None */ -TEST_F(CodecHalTest, EncoderEncodeP) +TEST_F(CodecHalTestEncoder, EncoderEncodeP) { ENCODER_SUPPORT_CHECK; @@ -712,9 +725,7 @@ TEST_F(CodecHalTest, EncoderEncodeP) ASSERT_EQ(ret, HAL_CODEC_ERROR_NONE); ASSERT_TRUE(CheckCurrentState(gHalHandleEnc, HAL_CODEC_STATE_CONFIGURED)); - gCurrentHandle = gHalHandleEnc; - - ret = hal_codec_start(gHalHandleEnc, CodecHalTest::MessageCb, nullptr); + ret = hal_codec_start(gHalHandleEnc, CodecHalTestEncoder::MessageCb, gHalHandleEnc); ASSERT_EQ(ret, HAL_CODEC_ERROR_NONE); ASSERT_TRUE(CheckCurrentState(gHalHandleEnc, HAL_CODEC_STATE_STARTED)); @@ -729,7 +740,7 @@ TEST_F(CodecHalTest, EncoderEncodeP) gOutputCount = 0; g_timeout_add(50, [](gpointer user_data) -> gboolean { - CodecHalTest *self = (CodecHalTest *)user_data; + CodecHalTestEncoder *self = (CodecHalTestEncoder *)user_data; return self->FeedDataEncode(); }, this);