diff --git a/multimedia/media/media_cpp_test_standard/player/include/TestPlayer.h b/multimedia/media/media_cpp_test_standard/player/include/TestPlayer.h index 5c862c06d0268ff7088b51db8834dd079486c1e6..59bd650e73773d97fcf9dcf9ee2b1f51fb256b84 100644 --- a/multimedia/media/media_cpp_test_standard/player/include/TestPlayer.h +++ b/multimedia/media/media_cpp_test_standard/player/include/TestPlayer.h @@ -48,6 +48,7 @@ public: PlayerStates state_ = PLAYER_IDLE; int32_t seekPosition_; bool seekDoneFlag_; + PlayerSeekMode seekMode_ = PlayerSeekMode::SEEK_CLOSEST; bool mutexFlag_ = true; std::mutex mutexSeek_; std::mutex mutexReset_; @@ -107,6 +108,7 @@ public: void OnError(PlayerErrorType errorType, int32_t errorCode); int WaitForSeekDone(int32_t currentPosition); void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody = {}); + void SeekNotify(int32_t extra, const Format &infoBody); int WaitForState(PlayerStates state); private: void PrintState(PlayerStates state); diff --git a/multimedia/media/media_cpp_test_standard/player/src/TestParamsConfig.cpp b/multimedia/media/media_cpp_test_standard/player/src/TestParamsConfig.cpp index fe917855a1587480d35c3ac457d91df5c98974c2..5a7dbdccda0c019ceafb3cf7953b5e7c2549528e 100644 --- a/multimedia/media/media_cpp_test_standard/player/src/TestParamsConfig.cpp +++ b/multimedia/media/media_cpp_test_standard/player/src/TestParamsConfig.cpp @@ -51,27 +51,6 @@ void TestParamsConfig::InitMountPath() bool TestParamsConfig::CompareTime(int32_t expectTime, int32_t realTime, OHOS::Media::PlayerSeekMode seekMode) { MEDIA_INFO_LOG("CompareTime: expectTime %d, realTime %d", expectTime, realTime); - if (seekMode == PlayerSeekMode::SEEK_CLOSEST) { - if (std::abs(expectTime - realTime) < CLOSEST_DELTA_TIME) { - return true; - } else { - return false; - } - } - if (seekMode == PlayerSeekMode::SEEK_NEXT_SYNC) { - if (realTime - expectTime < DELTA_TIME && realTime - expectTime >= 0) { - return true; - } else { - return false; - } - } - if (seekMode == PlayerSeekMode::SEEK_PREVIOUS_SYNC) { - if (expectTime - realTime < DELTA_TIME && expectTime - realTime > -CLOSEST_DELTA_TIME) { - return true; - } else { - return false; - } - } if (std::abs(expectTime - realTime) < DELTA_TIME) { return true; } diff --git a/multimedia/media/media_cpp_test_standard/player/src/TestPlayer.cpp b/multimedia/media/media_cpp_test_standard/player/src/TestPlayer.cpp index ebbc2345f4e0bb7c9cf832f7591db99a0c2bbe37..42ea8b8e03114aa93de15867bba46a9062c20aa8 100644 --- a/multimedia/media/media_cpp_test_standard/player/src/TestPlayer.cpp +++ b/multimedia/media/media_cpp_test_standard/player/src/TestPlayer.cpp @@ -146,7 +146,16 @@ int32_t TestPlayer::Seek(int32_t mseconds, PlayerSeekMode mode) { MEDIA_DEBUG_LOG("%s", __FUNCTION__); test_->seekDoneFlag_ = false; - test_->seekPosition_ = mseconds; + int32_t duration = 0; + player_->GetDuration(duration); + if (mseconds < 0) { + test_->seekPosition_ = 0; + } else if (mseconds > duration){ + test_->seekPosition_ = duration; + } else { + test_->seekPosition_ = mseconds; + } + test_->seekMode_ = mode; int32_t ret = player_->Seek(mseconds, mode); if (ret == RET_OK && test_->mutexFlag_ == true && test_->seekDoneFlag_ == false) { std::unique_lock lockSeek(test_->mutexSeek_); @@ -268,6 +277,28 @@ void TestPlayerCallback::OnError(PlayerErrorType errorType, int32_t errorCode) errorTypeMsg.c_str(), errorCodeMsg.c_str()); } +void TestPlayerCallback::SeekNotify(int32_t extra, const Format &infoBody) +{ + if (test_->seekMode_ == PlayerSeekMode::SEEK_CLOSEST) { + if (test_->seekPosition_ == extra) { + test_->condVarSeek_.notify_all(); + } + } else if (test_->seekMode_ == PlayerSeekMode::SEEK_PREVIOUS_SYNC) { + if (test_->seekPosition_ - extra < DELTA_TIME && extra - test_->seekPosition_ >= 0) { + test_->condVarSeek_.notify_all(); + } + } else if (test_->seekMode_ == PlayerSeekMode::SEEK_NEXT_SYNC) { + if (extra - test_->seekPosition_ < DELTA_TIME && test_->seekPosition_ - extra >= 0) { + test_->condVarSeek_.notify_all(); + } + } else if (abs(test_->seekPosition_ - extra) <= DELTA_TIME) { + test_->condVarSeek_.notify_all(); + } else { + test_->SetSeekResult(false); + } + return; +} + void TestPlayerCallback::OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) { switch (type) { @@ -275,11 +306,7 @@ void TestPlayerCallback::OnInfo(PlayerOnInfoType type, int32_t extra, const Form seekDoneFlag_ = true; test_->SetSeekResult(true); MEDIA_INFO_LOG("TestPlayerCallback: OnSeekDone currentPosition is %d", extra); - if (abs(test_->seekPosition_ - extra) <= DELTA_TIME) { - test_->condVarSeek_.notify_all(); - } else { - test_->SetSeekResult(false); - } + SeekNotify(extra, infoBody); break; case INFO_TYPE_EOS: MEDIA_INFO_LOG("TestPlayerCallback: OnEndOfStream isLooping is %d", extra);