From 0b7d0ada29ff6e34ec5195d5a7d3e10d83f76e7e Mon Sep 17 00:00:00 2001 From: ruanmeng Date: Thu, 16 Dec 2021 09:54:28 +0800 Subject: [PATCH] =?UTF-8?q?seek=20=E6=A0=A1=E9=AA=8C=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20Signed-off-by:=20NOBUGGERS=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ruanmeng --- .../player/include/TestPlayer.h | 2 + .../player/src/TestParamsConfig.cpp | 21 ---------- .../player/src/TestPlayer.cpp | 39 ++++++++++++++++--- 3 files changed, 35 insertions(+), 27 deletions(-) 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 5c862c06d..59bd650e7 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 fe917855a..5a7dbdccd 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 ebbc2345f..42ea8b8e0 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); -- GitLab