From ff1d3d71c8453f28bce3b51d953b61c9c5625bd4 Mon Sep 17 00:00:00 2001 From: vv Date: Tue, 26 Aug 2025 22:44:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E5=B8=83=E5=BC=8F=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=8F=98=E5=8C=96=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: vv --- .../src/av_audio_receiver_engine.cpp | 9 +- .../av_sender/src/av_audio_sender_engine.cpp | 3 + .../src/av_audio_sender_engine_test.cpp | 2 +- .../src/av_sender_engine_test.cpp | 2 +- .../av_trans_audio_decoder_filter.cpp | 22 +- .../av_trans_audio_decoder_filter.h | 3 + .../av_trans_audio_encoder_filter.cpp | 38 ++- .../av_trans_audio_encoder_filter.h | 6 + .../av_trans_audio_input_filter.cpp | 11 +- .../av_trans_bus_input_filter.cpp | 33 ++- .../av_trans_bus_input_filter.h | 2 +- .../dsoftbus_output_filter.cpp | 14 +- .../av_trans_output/dsoftbus_output_filter.h | 2 +- .../av_trans_bus_input_filter_test.cpp | 228 +++++++++++++++- .../av_trans_dsoftbus_output_filter_test.cpp | 9 +- av_transport/common/include/av_trans_buffer.h | 6 + av_transport/common/src/av_trans_buffer.cpp | 19 ++ .../componentmanager/component_manager.h | 9 + .../componentmanager/component_manager.cpp | 239 +++++++++++++++- .../src/distributed_hardware_service.cpp | 1 + .../src/component_manager_test.cpp | 255 ++++++++++++++++++ 21 files changed, 868 insertions(+), 45 deletions(-) diff --git a/av_transport/av_trans_engine/av_receiver/src/av_audio_receiver_engine.cpp b/av_transport/av_trans_engine/av_receiver/src/av_audio_receiver_engine.cpp index 20dbecc7..ee8ef973 100644 --- a/av_transport/av_trans_engine/av_receiver/src/av_audio_receiver_engine.cpp +++ b/av_transport/av_trans_engine/av_receiver/src/av_audio_receiver_engine.cpp @@ -630,11 +630,14 @@ int32_t AVAudioReceiverEngine::HandleOutputBuffer(std::shared_ptr transBuffer = std::make_shared(MetaType::AUDIO); - TRUE_RETURN_V_MSG_E(hisBuffer == nullptr || hisBuffer->memory_ == nullptr, ERR_DH_AVT_NULL_POINTER, - "hisBuffer is invalid"); + TRUE_RETURN_V_MSG_E(hisBuffer == nullptr || hisBuffer->memory_ == nullptr || hisBuffer->meta_ == nullptr, + ERR_DH_AVT_NULL_POINTER, "hisBuffer is invalid"); transBuffer->WrapBufferData(hisBuffer->memory_->GetAddr(), hisBuffer->memory_->GetCapacity(), hisBuffer->memory_->GetSize()); - + transBuffer->SetPts(hisBuffer->pts_); + int64_t ptsSpecial = 0; + hisBuffer->meta_->GetData(Media::Tag::USER_FRAME_PTS, ptsSpecial); + transBuffer->SetPtsSpecial(ptsSpecial); SetCurrentState(StateId::PLAYING); TRUE_RETURN_V(receiverCallback_ == nullptr, ERR_DH_AVT_OUTPUT_DATA_FAILED); return receiverCallback_->OnDataAvailable(transBuffer); diff --git a/av_transport/av_trans_engine/av_sender/src/av_audio_sender_engine.cpp b/av_transport/av_trans_engine/av_sender/src/av_audio_sender_engine.cpp index 7e59e038..8029f8f6 100644 --- a/av_transport/av_trans_engine/av_sender/src/av_audio_sender_engine.cpp +++ b/av_transport/av_trans_engine/av_sender/src/av_audio_sender_engine.cpp @@ -612,6 +612,7 @@ void AVAudioSenderEngine::SetEngineResume(const std::string &value) int32_t AVAudioSenderEngine::PushData(const std::shared_ptr &buffer) { + TRUE_RETURN_V_MSG_E(buffer == nullptr, ERR_DH_AVT_PUSH_DATA_FAILED, "av trans buffer is null"); StateId currentState = GetCurrentState(); bool isErrState = (currentState != StateId::STARTED) && (currentState != StateId::PLAYING); TRUE_RETURN_V_MSG_E(isErrState, ERR_DH_AVT_PUSH_DATA_FAILED, @@ -641,6 +642,8 @@ int32_t AVAudioSenderEngine::PushData(const std::shared_ptr &buff return ERR_DH_AVT_PREPARE_FAILED; } outBuffer->memory_->Write(data->GetAddress(), bufferSize, 0); + outBuffer->pts_ = buffer->GetPts(); + AVTRANS_LOGI("buffer->GetPts(): %{public}" PRId64, buffer->GetPts()); producer->PushBuffer(outBuffer, true); SetCurrentState(StateId::PLAYING); return DH_AVT_SUCCESS; diff --git a/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/src/av_audio_sender_engine_test.cpp b/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/src/av_audio_sender_engine_test.cpp index 08eceec3..78fe2f49 100644 --- a/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/src/av_audio_sender_engine_test.cpp +++ b/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/src/av_audio_sender_engine_test.cpp @@ -165,7 +165,7 @@ HWTEST_F(AvAudioSenderEngineTest, Start_003, testing::ext::TestSize.Level1) sender->dhFwkKit_ = std::make_shared(); int32_t ret = sender->Start(); sender->Stop(); - EXPECT_EQ(ERR_DH_AVT_CREATE_CHANNEL_FAILED, ret); + EXPECT_EQ(DH_AVT_SUCCESS, ret); } HWTEST_F(AvAudioSenderEngineTest, Start_004, testing::ext::TestSize.Level1) diff --git a/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/src/av_sender_engine_test.cpp b/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/src/av_sender_engine_test.cpp index 04c31bf4..4c746afd 100644 --- a/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/src/av_sender_engine_test.cpp +++ b/av_transport/av_trans_engine/av_sender/test/unittest/av_sender_engine/src/av_sender_engine_test.cpp @@ -178,7 +178,7 @@ HWTEST_F(AvSenderEngineTest, Start_003, testing::ext::TestSize.Level1) sender->dhFwkKit_ = std::make_shared(); int32_t ret = sender->Start(); sender->Stop(); - EXPECT_EQ(ERR_DH_AVT_CREATE_CHANNEL_FAILED, ret); + EXPECT_EQ(DH_AVT_SUCCESS, ret); } HWTEST_F(AvSenderEngineTest, Start_004, testing::ext::TestSize.Level1) diff --git a/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_decoder_filter.cpp b/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_decoder_filter.cpp index d747dd5f..8fcd9cfc 100644 --- a/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_decoder_filter.cpp +++ b/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_decoder_filter.cpp @@ -548,10 +548,18 @@ Status AudioDecoderFilter::ProcessData(std::shared_ptr audioDat TRUE_RETURN_V_MSG_E(err != EOK, Status::ERROR_INVALID_OPERATION, "memcpy_s err: %{public}d, memSize: %{public}d", err, memSize); int64_t pts = 0; - audioData->meta_->GetData(Media::Tag::USER_FRAME_PTS, pts); + pts = audioData->pts_; { std::lock_guard lock(ptsMutex_); - ptsMap_.insert(std::make_pair(index, pts)); + ptsMap_[frameInIndex_] = pts; + frameInIndex_++; + AVTRANS_LOGI("frameInIndex_: %{public}" PRIu64 " pts: %{public}" PRId64, frameInIndex_, pts); + } + if (frameInIndex_ == INDEX_FLAG) { + audioData->meta_->GetData(Media::Tag::USER_FRAME_PTS, pts); + ptsMap_[INDEX_FLAG] = pts; + AVTRANS_LOGI("the fifth special process pts: %{public}" PRId64, pts); + frameInIndex_ = 0; } codecMem->buffer_->pts_ = pts; codecMem->buffer_->meta_->SetData(Media::Tag::USER_FRAME_PTS, pts); @@ -616,14 +624,22 @@ void AudioDecoderFilter::OnDecOutputBufferAvailable(uint32_t index, OH_AVBuffer int64_t pts = 0; { std::lock_guard lock(ptsMutex_); - auto iter = ptsMap_.find(index); + auto iter = ptsMap_.find(frameOutIndex_); if (iter != ptsMap_.end()) { pts = iter->second; ptsMap_.erase(iter); } + frameOutIndex_++; } outBuffer->pts_ = pts; meta->SetData(Media::Tag::USER_FRAME_PTS, pts); + AVTRANS_LOGI("after AudioDecoderFilter index %{public}" PRIu64", pts: %{public}" PRId64, frameOutIndex_, pts); + + if (frameOutIndex_ == INDEX_FLAG) { + meta->SetData(Media::Tag::USER_FRAME_PTS, ptsMap_[INDEX_FLAG]); + AVTRANS_LOGI("the fifth special process pts: %{public}" PRId64, ptsMap_[INDEX_FLAG]); + frameOutIndex_ = 0; + } outBuffer->memory_->Write(buffer->buffer_->memory_->GetAddr(), buffer->buffer_->memory_->GetSize(), 0); outputProducer_->PushBuffer(outBuffer, true); auto ret = OH_AudioCodec_FreeOutputBuffer(audioDecoder_, index); diff --git a/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_decoder_filter.h b/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_decoder_filter.h index 07c70e91..7071b284 100644 --- a/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_decoder_filter.h +++ b/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_decoder_filter.h @@ -112,6 +112,7 @@ private: constexpr static int32_t SAMPLE_RATE_MIN = 8000; constexpr static int32_t SAMPLE_RATE_MAX = 96000; constexpr static int32_t BITRATE_OPUS = 32000; + constexpr static int32_t INDEX_FLAG = 15; std::shared_ptr nextFilter_ {nullptr}; std::shared_ptr eventReceiver_ {nullptr}; @@ -148,6 +149,8 @@ private: std::queue> inputDataBufferQueue_; std::map ptsMap_; std::mutex ptsMutex_; + uint64_t frameInIndex_ = 0; + uint64_t frameOutIndex_ = 0; }; } // namespace Pipeline } // namespace DistributedHardware diff --git a/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_encoder_filter.cpp b/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_encoder_filter.cpp index 37624f16..5b2a0c70 100644 --- a/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_encoder_filter.cpp +++ b/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_encoder_filter.cpp @@ -547,7 +547,17 @@ Status AudioEncoderFilter::ProcessData(std::shared_ptr audioDat "memcpy_s err: %{public}d, memSize: %{public}d", err, memSize); int64_t pts = 0; audioData->meta_->GetData(Media::Tag::USER_FRAME_PTS, pts); + { + std::lock_guard lock(ptsMutex_); + ptsMap_[frameInIndex_] = pts; + AVTRANS_LOGI("ProcessData frameInIndex_ %{public}" PRId64", pts: %{public}" PRId64, frameInIndex_, pts); + frameInIndex_++; + if (frameInIndex_ % FRAME_OUTINDEX_FLAG == 0) { + frameInIndex_ = 0; + } + } codecMem->buffer_->meta_->SetData(Media::Tag::USER_FRAME_PTS, pts); + AVTRANS_LOGI("before AudioEncoderFilter index %{public}u, pts: %{public}" PRId64, index, pts); codecMem->buffer_->flag_ = MediaAVCodec::AVCODEC_BUFFER_FLAG_NONE; auto ret = OH_AudioCodec_PushInputBuffer(audioEncoder_, index); TRUE_RETURN_V_MSG_E(ret != AV_ERR_OK, Status::ERROR_INVALID_OPERATION, @@ -586,9 +596,7 @@ void AudioEncoderFilter::OnEncInputBufferAvailable(uint32_t index, OH_AVBuffer * void AudioEncoderFilter::OnEncOutputBufferAvailable(uint32_t index, OH_AVBuffer *buffer) { - AVTRANS_LOGD("enter"); - TRUE_RETURN(audioEncoder_ == nullptr || !isEncoderRunning_.load(), - "Encoder is not runnnig, isEncoderRunning_: %{public}d", isEncoderRunning_.load()); + TRUE_RETURN(audioEncoder_ == nullptr || !isEncoderRunning_.load(), "running:%{public}d", isEncoderRunning_.load()); TRUE_RETURN(buffer == nullptr || buffer->buffer_ == nullptr || buffer->buffer_->memory_ == nullptr || buffer->buffer_->memory_->GetSize() <= 0 || buffer->buffer_->meta_ == nullptr, "audioData is invaild"); TRUE_RETURN(outputProducer_ == nullptr, "input queue is nullptr"); @@ -607,9 +615,31 @@ void AudioEncoderFilter::OnEncOutputBufferAvailable(uint32_t index, OH_AVBuffer return; } int64_t pts = 0; - buffer->buffer_->meta_->GetData(Media::Tag::USER_FRAME_PTS, pts); + { + std::lock_guard lock(ptsMutex_); + auto iter = ptsMap_.find(frameOutIndex_); + if (iter != ptsMap_.end()) { + pts = iter->second; + ptsMap_.erase(iter); + } + frameOutIndex_++; + } outBuffer->pts_ = pts; meta->SetData(Media::Tag::USER_FRAME_PTS, pts); + AVTRANS_LOGD("index:%{public}u,outIndex_:%{public}" PRIu64",pts:%{public}" PRId64, index, frameOutIndex_, pts); + if (frameOutIndex_ == INDEX_FLAG) { + { + std::lock_guard lock(ptsMutex_); + auto iter = ptsMap_.find(frameOutIndex_); + if (iter != ptsMap_.end()) { + pts = iter->second; + ptsMap_.erase(iter); + } + } + AVTRANS_LOGD("the fifth special process index %{public}" PRIu64", pts: %{public}" PRId64, frameOutIndex_, pts); + meta->SetData(Media::Tag::USER_FRAME_PTS, pts); + frameOutIndex_ = 0; + } meta->SetData(Media::Tag::AUDIO_OBJECT_NUMBER, index); outBuffer->memory_->Write(buffer->buffer_->memory_->GetAddr(), buffer->buffer_->memory_->GetSize(), 0); outputProducer_->PushBuffer(outBuffer, true); diff --git a/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_encoder_filter.h b/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_encoder_filter.h index aff40982..a8b66711 100644 --- a/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_encoder_filter.h +++ b/av_transport/av_trans_engine/filters/av_trans_coder/av_trans_audio_encoder_filter.h @@ -111,6 +111,8 @@ private: constexpr static int32_t SAMPLE_RATE_MIN = 8000; constexpr static int32_t SAMPLE_RATE_MAX = 96000; constexpr static int32_t BITRATE_OPUS = 32000; + constexpr static int32_t INDEX_FLAG = 15; + constexpr static int32_t FRAME_OUTINDEX_FLAG = 16; std::shared_ptr nextFilter_ {nullptr}; std::shared_ptr eventReceiver_ {nullptr}; @@ -144,6 +146,10 @@ private: std::queue codecBufQueue_; std::queue codecIndexQueue_; std::queue> inputDataBufferQueue_; + std::map ptsMap_; + std::mutex ptsMutex_; + uint64_t frameInIndex_ = 0; + uint64_t frameOutIndex_ = 0; }; } // namespace Pipeline } // namespace DistributedHardware diff --git a/av_transport/av_trans_engine/filters/av_trans_input/av_trans_audio_input_filter.cpp b/av_transport/av_trans_engine/filters/av_trans_input/av_trans_audio_input_filter.cpp index c3bbdc85..719fc6d6 100644 --- a/av_transport/av_trans_engine/filters/av_trans_input/av_trans_audio_input_filter.cpp +++ b/av_transport/av_trans_engine/filters/av_trans_input/av_trans_audio_input_filter.cpp @@ -30,16 +30,7 @@ namespace Pipeline { namespace { constexpr int32_t DEFAULT_BUFFER_NUM = 8; constexpr int32_t MAX_TIME_OUT_MS = 1; -constexpr int64_t MS_ONE_S = 1000; -constexpr int64_t NS_ONE_S = 1000000; const std::string INPUT_BUFFER_QUEUE_NAME = "AVTransAudioInputBufferQueue"; - -int64_t GetCurrentTime() -{ - struct timespec time = { 0, 0 }; - clock_gettime(CLOCK_MONOTONIC, &time); - return time.tv_sec * MS_ONE_S + time.tv_nsec / NS_ONE_S; -} } static AutoRegisterFilter g_registerAudioEncoderFilter("builtin.avtrans.audio.input", @@ -264,7 +255,7 @@ Status AVTransAudioInputFilter::ProcessAndSendBuffer(const std::shared_ptrpts_ = GetCurrentTime(); + outBuffer->pts_ = buffer->pts_; meta->SetData(Media::Tag::USER_FRAME_PTS, outBuffer->pts_); outBuffer->memory_->Write(buffer->memory_->GetAddr(), buffer->memory_->GetSize(), 0); outputBufQueProducer_->PushBuffer(outBuffer, true); diff --git a/av_transport/av_trans_engine/filters/av_trans_input/av_trans_bus_input_filter.cpp b/av_transport/av_trans_engine/filters/av_trans_input/av_trans_bus_input_filter.cpp index 0dfcccd7..cf74ab43 100644 --- a/av_transport/av_trans_engine/filters/av_trans_input/av_trans_bus_input_filter.cpp +++ b/av_transport/av_trans_engine/filters/av_trans_input/av_trans_bus_input_filter.cpp @@ -35,6 +35,8 @@ constexpr int32_t DEFAULT_BUFFER_NUM = 8; constexpr int32_t MAX_TIME_OUT_MS = 1; const std::string INPUT_BUFFER_QUEUE_NAME = "AVTransBusInputBufferQueue"; const std::string META_TIMESTAMP = "meta_timestamp"; +const std::string META_TIMESTAMP_STRING = "meta_timestamp_string"; +const std::string META_TIMESTAMP_SPECIAL = "meta_timestamp_special"; bool IsUInt32(const cJSON *jsonObj, const std::string &key) { @@ -417,7 +419,7 @@ void AVTransBusInputFilter::OnStreamReceived(const StreamData *data, const Strea cJSON_Delete(resMsg); } -bool AVTransBusInputFilter::UnmarshalAudioMeta(const std::string& jsonStr, int64_t& pts) +bool AVTransBusInputFilter::UnmarshalAudioMeta(const std::string& jsonStr, int64_t& pts, int64_t& ptsSpecial) { cJSON *metaJson = cJSON_Parse(jsonStr.c_str()); if (metaJson == nullptr) { @@ -429,6 +431,29 @@ bool AVTransBusInputFilter::UnmarshalAudioMeta(const std::string& jsonStr, int64 return false; } pts = static_cast(ptsObj->valueint); + cJSON *ptsStringObj = cJSON_GetObjectItemCaseSensitive(metaJson, META_TIMESTAMP_STRING.c_str()); + if (ptsStringObj == nullptr || !cJSON_IsString(ptsStringObj)) { + cJSON_Delete(metaJson); + return false; + } + auto ptsStr = std::string(ptsStringObj->valuestring); + if (ptsStr.empty()) { + cJSON_Delete(metaJson); + return false; + } + pts = std::stoll(ptsStr); + cJSON *ptsSpecialObj = cJSON_GetObjectItemCaseSensitive(metaJson, META_TIMESTAMP_SPECIAL.c_str()); + if (ptsSpecialObj == nullptr || !cJSON_IsString(ptsSpecialObj)) { + cJSON_Delete(metaJson); + return false; + } + auto ptsSpecialStr = std::string(ptsSpecialObj->valuestring); + if (ptsSpecialStr.empty()) { + cJSON_Delete(metaJson); + return false; + } + ptsSpecial = std::stoll(ptsSpecialStr); + AVTRANS_LOGD("pts: %{public}" PRId64", ptsSpecial: %{public}" PRId64, pts, ptsSpecial); cJSON_Delete(metaJson); return true; } @@ -458,9 +483,11 @@ void AVTransBusInputFilter::StreamDataEnqueue(const StreamData *data, const cJSO return; } int64_t ptsValue = 0; - UnmarshalAudioMeta(std::string(paramItem->valuestring), ptsValue); + int64_t ptsSpecialValue = 0; + UnmarshalAudioMeta(std::string(paramItem->valuestring), ptsValue, ptsSpecialValue); + AVTRANS_LOGI("buffer->GetPts(): %{public}" PRId64, ptsValue); outBuffer->pts_ = ptsValue; - meta->SetData(Media::Tag::USER_FRAME_PTS, ptsValue); + meta->SetData(Media::Tag::USER_FRAME_PTS, ptsSpecialValue); outBuffer->memory_->Write(reinterpret_cast(data->buf), data->bufLen, 0); outputBufQueProducer_->PushBuffer(outBuffer, true); } diff --git a/av_transport/av_trans_engine/filters/av_trans_input/av_trans_bus_input_filter.h b/av_transport/av_trans_engine/filters/av_trans_input/av_trans_bus_input_filter.h index bfeb26a4..4c0f80bf 100644 --- a/av_transport/av_trans_engine/filters/av_trans_input/av_trans_bus_input_filter.h +++ b/av_transport/av_trans_engine/filters/av_trans_input/av_trans_bus_input_filter.h @@ -79,7 +79,7 @@ private: Status ProcessAndSendBuffer(const std::shared_ptr buffer); void StreamDataEnqueue(const StreamData *data, const cJSON *extMsg); std::string TransName2PkgName(const std::string &ownerName); - bool UnmarshalAudioMeta(const std::string& jsonStr, int64_t& pts); + bool UnmarshalAudioMeta(const std::string& jsonStr, int64_t& pts, int64_t& ptsSpecial); private: std::shared_ptr configureParam_ {nullptr}; diff --git a/av_transport/av_trans_engine/filters/av_trans_output/dsoftbus_output_filter.cpp b/av_transport/av_trans_engine/filters/av_trans_output/dsoftbus_output_filter.cpp index 432a4909..a0eb332a 100644 --- a/av_transport/av_trans_engine/filters/av_trans_output/dsoftbus_output_filter.cpp +++ b/av_transport/av_trans_engine/filters/av_trans_output/dsoftbus_output_filter.cpp @@ -33,6 +33,8 @@ namespace Pipeline { constexpr int32_t DEFAULT_BUFFER_NUM = 8; const std::string META_DATA_TYPE = "meta_data_type"; const std::string META_TIMESTAMP = "meta_timestamp"; +const std::string META_TIMESTAMP_STRING = "meta_timestamp_string"; +const std::string META_TIMESTAMP_SPECIAL = "meta_timestamp_special"; const std::string META_FRAME_NUMBER = "meta_frame_number"; const std::string META_EXT_TIMESTAMP = "meta_ext_timestamp"; const std::string META_EXT_FRAME_NUMBER = "meta_ext_frame_number"; @@ -260,7 +262,8 @@ Status DSoftbusOutputFilter::DoProcessOutputBuffer(int recvArg, bool dropFrame, return Status::OK; } -std::string DSoftbusOutputFilter::MarshalAudioMeta(BufferDataType dataType, int64_t pts, uint32_t frameNumber) +std::string DSoftbusOutputFilter::MarshalAudioMeta(BufferDataType dataType, + int64_t pts, int64_t ptsSpecail, uint32_t frameNumber) { cJSON *metaJson = cJSON_CreateObject(); if (metaJson == nullptr) { @@ -269,6 +272,8 @@ std::string DSoftbusOutputFilter::MarshalAudioMeta(BufferDataType dataType, int6 cJSON_AddNumberToObject(metaJson, META_DATA_TYPE.c_str(), static_cast(dataType)); cJSON_AddNumberToObject(metaJson, META_TIMESTAMP.c_str(), pts); cJSON_AddNumberToObject(metaJson, META_FRAME_NUMBER.c_str(), frameNumber); + cJSON_AddStringToObject(metaJson, META_TIMESTAMP_STRING.c_str(), std::to_string(pts).c_str()); + cJSON_AddStringToObject(metaJson, META_TIMESTAMP_SPECIAL.c_str(), std::to_string(ptsSpecail).c_str()); char *data = cJSON_PrintUnformatted(metaJson); if (data == nullptr) { cJSON_Delete(metaJson); @@ -288,12 +293,15 @@ Status DSoftbusOutputFilter::ProcessAndSendBuffer(const std::shared_ptrmemory_; int64_t pts = 0; + int64_t ptsSpecail = 0; uint32_t frameNumber = 0; - buffer->meta_->GetData(Media::Tag::USER_FRAME_PTS, pts); + pts = buffer->pts_; + AVTRANS_LOGD("AVBuffer pts is %{public}" PRId64, pts); + buffer->meta_->GetData(Media::Tag::USER_FRAME_PTS, ptsSpecail); buffer->meta_->GetData(Media::Tag::AUDIO_OBJECT_NUMBER, frameNumber); BufferDataType dataType; meta_->GetData(Media::Tag::MEDIA_STREAM_TYPE, dataType); - auto dataParam = MarshalAudioMeta(dataType, pts, frameNumber); + auto dataParam = MarshalAudioMeta(dataType, pts, ptsSpecail, frameNumber); cJSON *jsonObj = cJSON_CreateObject(); if (jsonObj == nullptr) { return Status::ERROR_NULL_POINTER; diff --git a/av_transport/av_trans_engine/filters/av_trans_output/dsoftbus_output_filter.h b/av_transport/av_trans_engine/filters/av_trans_output/dsoftbus_output_filter.h index 7313d1fb..6740c18d 100644 --- a/av_transport/av_trans_engine/filters/av_trans_output/dsoftbus_output_filter.h +++ b/av_transport/av_trans_engine/filters/av_trans_output/dsoftbus_output_filter.h @@ -75,7 +75,7 @@ public: private: void PrepareInputBuffer(); Status ProcessAndSendBuffer(const std::shared_ptr buffer); - std::string MarshalAudioMeta(BufferDataType dataType, int64_t pts, uint32_t frameNumber); + std::string MarshalAudioMeta(BufferDataType dataType, int64_t pts, int64_t ptsSpecail, uint32_t frameNumber); std::shared_ptr meta_ {nullptr}; std::shared_ptr nextFilter_ {nullptr}; diff --git a/av_transport/av_trans_engine/filters/test/av_trans_input_filter_test/av_trans_bus_input_filter_test.cpp b/av_transport/av_trans_engine/filters/test/av_trans_input_filter_test/av_trans_bus_input_filter_test.cpp index ef66331b..05953e3d 100644 --- a/av_transport/av_trans_engine/filters/test/av_trans_input_filter_test/av_trans_bus_input_filter_test.cpp +++ b/av_transport/av_trans_engine/filters/test/av_trans_input_filter_test/av_trans_bus_input_filter_test.cpp @@ -425,7 +425,8 @@ HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_001, testing::ext::Te Pipeline::FilterType::AUDIO_DATA_SOURCE); ASSERT_TRUE(avBusInputTest_ != nullptr); int64_t pts= 0; - bool ret = avBusInputTest_->UnmarshalAudioMeta("", pts); + int64_t ptsSpecial= 0; + bool ret = avBusInputTest_->UnmarshalAudioMeta("", pts, ptsSpecial); EXPECT_EQ(false, ret); } @@ -436,10 +437,233 @@ HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_002, testing::ext::Te Pipeline::FilterType::AUDIO_DATA_SOURCE); ASSERT_TRUE(avBusInputTest_ != nullptr); int64_t pts= 1; - bool ret = avBusInputTest_->UnmarshalAudioMeta("AUDIO", pts); + int64_t ptsSpecial= 1; + bool ret = avBusInputTest_->UnmarshalAudioMeta("AUDIO", pts, ptsSpecial); EXPECT_EQ(false, ret); } +HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr avBusInputTest_ = + std::make_shared("builtin.avtrans.softbus.input", + Pipeline::FilterType::AUDIO_DATA_SOURCE); + ASSERT_TRUE(avBusInputTest_ != nullptr); + int64_t pts = 0; + int64_t ptsSpecial = 0; + + cJSON *jsonObj = cJSON_CreateObject(); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_string", "123456"); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_special", "789012"); + char *jsonStr = cJSON_PrintUnformatted(jsonObj); + + bool ret = avBusInputTest_->UnmarshalAudioMeta(std::string(jsonStr), pts, ptsSpecial); + EXPECT_EQ(false, ret); + + cJSON_free(jsonStr); + cJSON_Delete(jsonObj); +} + +HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr avBusInputTest_ = + std::make_shared("builtin.avtrans.softbus.input", + Pipeline::FilterType::AUDIO_DATA_SOURCE); + ASSERT_TRUE(avBusInputTest_ != nullptr); + int64_t pts = 0; + int64_t ptsSpecial = 0; + + cJSON *jsonObj = cJSON_CreateObject(); + cJSON_AddStringToObject(jsonObj, "meta_timestamp", "not_a_number"); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_string", "123456"); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_special", "789012"); + char *jsonStr = cJSON_PrintUnformatted(jsonObj); + + bool ret = avBusInputTest_->UnmarshalAudioMeta(std::string(jsonStr), pts, ptsSpecial); + EXPECT_EQ(false, ret); + + cJSON_free(jsonStr); + cJSON_Delete(jsonObj); +} + +HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr avBusInputTest_ = + std::make_shared("builtin.avtrans.softbus.input", + Pipeline::FilterType::AUDIO_DATA_SOURCE); + ASSERT_TRUE(avBusInputTest_ != nullptr); + int64_t pts = 0; + int64_t ptsSpecial = 0; + + cJSON *jsonObj = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObj, "meta_timestamp", 123456); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_special", "789012"); + char *jsonStr = cJSON_PrintUnformatted(jsonObj); + + bool ret = avBusInputTest_->UnmarshalAudioMeta(std::string(jsonStr), pts, ptsSpecial); + EXPECT_EQ(false, ret); + + cJSON_free(jsonStr); + cJSON_Delete(jsonObj); +} + +HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_006, testing::ext::TestSize.Level1) +{ + std::shared_ptr avBusInputTest_ = + std::make_shared("builtin.avtrans.softbus.input", + Pipeline::FilterType::AUDIO_DATA_SOURCE); + ASSERT_TRUE(avBusInputTest_ != nullptr); + int64_t pts = 0; + int64_t ptsSpecial = 0; + + cJSON *jsonObj = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObj, "meta_timestamp", 123456); + cJSON_AddNumberToObject(jsonObj, "meta_timestamp_string", 123456); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_special", "789012"); + char *jsonStr = cJSON_PrintUnformatted(jsonObj); + + bool ret = avBusInputTest_->UnmarshalAudioMeta(std::string(jsonStr), pts, ptsSpecial); + EXPECT_EQ(false, ret); + + cJSON_free(jsonStr); + cJSON_Delete(jsonObj); +} + +HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_007, testing::ext::TestSize.Level1) +{ + std::shared_ptr avBusInputTest_ = + std::make_shared("builtin.avtrans.softbus.input", + Pipeline::FilterType::AUDIO_DATA_SOURCE); + ASSERT_TRUE(avBusInputTest_ != nullptr); + int64_t pts = 0; + int64_t ptsSpecial = 0; + + cJSON *jsonObj = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObj, "meta_timestamp", 123456); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_string", ""); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_special", "789012"); + char *jsonStr = cJSON_PrintUnformatted(jsonObj); + + bool ret = avBusInputTest_->UnmarshalAudioMeta(std::string(jsonStr), pts, ptsSpecial); + EXPECT_EQ(false, ret); + + cJSON_free(jsonStr); + cJSON_Delete(jsonObj); +} + +HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_008, testing::ext::TestSize.Level1) +{ + std::shared_ptr avBusInputTest_ = + std::make_shared("builtin.avtrans.softbus.input", + Pipeline::FilterType::AUDIO_DATA_SOURCE); + ASSERT_TRUE(avBusInputTest_ != nullptr); + int64_t pts = 0; + int64_t ptsSpecial = 0; + + cJSON *jsonObj = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObj, "meta_timestamp", 123456); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_string", "123456"); + char *jsonStr = cJSON_PrintUnformatted(jsonObj); + + bool ret = avBusInputTest_->UnmarshalAudioMeta(std::string(jsonStr), pts, ptsSpecial); + EXPECT_EQ(false, ret); + + cJSON_free(jsonStr); + cJSON_Delete(jsonObj); +} + + +HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_009, testing::ext::TestSize.Level1) +{ + std::shared_ptr avBusInputTest_ = + std::make_shared("builtin.avtrans.softbus.input", + Pipeline::FilterType::AUDIO_DATA_SOURCE); + ASSERT_TRUE(avBusInputTest_ != nullptr); + int64_t pts = 0; + int64_t ptsSpecial = 0; + + cJSON *jsonObj = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObj, "meta_timestamp", 123456); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_string", "123456"); + cJSON_AddNumberToObject(jsonObj, "meta_timestamp_special", 789012); + char *jsonStr = cJSON_PrintUnformatted(jsonObj); + + bool ret = avBusInputTest_->UnmarshalAudioMeta(std::string(jsonStr), pts, ptsSpecial); + EXPECT_EQ(false, ret); + + cJSON_free(jsonStr); + cJSON_Delete(jsonObj); +} + +HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_010, testing::ext::TestSize.Level1) +{ + std::shared_ptr avBusInputTest_ = + std::make_shared("builtin.avtrans.softbus.input", + Pipeline::FilterType::AUDIO_DATA_SOURCE); + ASSERT_TRUE(avBusInputTest_ != nullptr); + int64_t pts = 0; + int64_t ptsSpecial = 0; + + cJSON *jsonObj = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObj, "meta_timestamp", 123456); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_string", "123456"); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_special", ""); + char *jsonStr = cJSON_PrintUnformatted(jsonObj); + + bool ret = avBusInputTest_->UnmarshalAudioMeta(std::string(jsonStr), pts, ptsSpecial); + EXPECT_EQ(false, ret); + + cJSON_free(jsonStr); + cJSON_Delete(jsonObj); +} + +HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_011, testing::ext::TestSize.Level1) +{ + std::shared_ptr avBusInputTest_ = + std::make_shared("builtin.avtrans.softbus.input", + Pipeline::FilterType::AUDIO_DATA_SOURCE); + ASSERT_TRUE(avBusInputTest_ != nullptr); + int64_t pts = 0; + int64_t ptsSpecial = 0; + + cJSON *jsonObj = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObj, "meta_timestamp", 123456); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_string", "123456"); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_special", "789012"); + char *jsonStr = cJSON_PrintUnformatted(jsonObj); + + bool ret = avBusInputTest_->UnmarshalAudioMeta(std::string(jsonStr), pts, ptsSpecial); + EXPECT_EQ(true, ret); + EXPECT_EQ(123456, pts); + EXPECT_EQ(789012, ptsSpecial); + + cJSON_free(jsonStr); + cJSON_Delete(jsonObj); +} + +HWTEST_F(AvTransportBusInputFilterTest, UnmarshalAudioMeta_012, testing::ext::TestSize.Level1) +{ + std::shared_ptr avBusInputTest_ = + std::make_shared("builtin.avtrans.softbus.input", + Pipeline::FilterType::AUDIO_DATA_SOURCE); + ASSERT_TRUE(avBusInputTest_ != nullptr); + int64_t pts = 0; + int64_t ptsSpecial = 0; + + cJSON *jsonObj = cJSON_CreateObject(); + cJSON_AddNumberToObject(jsonObj, "meta_timestamp", 9876543210LL); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_string", "9876543210"); + cJSON_AddStringToObject(jsonObj, "meta_timestamp_special", "1234567890"); + char *jsonStr = cJSON_PrintUnformatted(jsonObj); + + bool ret = avBusInputTest_->UnmarshalAudioMeta(std::string(jsonStr), pts, ptsSpecial); + EXPECT_EQ(true, ret); + EXPECT_EQ(9876543210LL, pts); + EXPECT_EQ(1234567890LL, ptsSpecial); + + cJSON_free(jsonStr); + cJSON_Delete(jsonObj); +} + HWTEST_F(AvTransportBusInputFilterTest, TransName2PkgName_001, testing::ext::TestSize.Level1) { std::shared_ptr avBusInputTest_ = diff --git a/av_transport/av_trans_engine/filters/test/av_trans_output_filter_test/av_trans_dsoftbus_output_filter_test.cpp b/av_transport/av_trans_engine/filters/test/av_trans_output_filter_test/av_trans_dsoftbus_output_filter_test.cpp index ce18bfbe..313f3690 100644 --- a/av_transport/av_trans_engine/filters/test/av_trans_output_filter_test/av_trans_dsoftbus_output_filter_test.cpp +++ b/av_transport/av_trans_engine/filters/test/av_trans_output_filter_test/av_trans_dsoftbus_output_filter_test.cpp @@ -261,8 +261,13 @@ HWTEST_F(AvTransportAudioOutputFilterTest, DoPrepare_002, testing::ext::TestSize HWTEST_F(AvTransportAudioOutputFilterTest, MarshalAudioMeta_001, testing::ext::TestSize.Level1) { ASSERT_TRUE(dSoftbusOutputTest_ != nullptr); - std::string json = dSoftbusOutputTest_->MarshalAudioMeta(BufferDataType::AUDIO, 1000, 1); - EXPECT_EQ(json, R"({"meta_data_type":0,"meta_timestamp":1000,"meta_frame_number":1})"); + std::string json = dSoftbusOutputTest_->MarshalAudioMeta(BufferDataType::AUDIO, 1000, 2000, 1); + std::string json1 = std::string(R"({"meta_data_type":0,)") + + std::string(R"("meta_timestamp":1000,)") + + std::string(R"("meta_frame_number":1,)") + + std::string(R"("meta_timestamp_string":"1000",)") + + std::string(R"("meta_timestamp_special":"2000"})"); + EXPECT_EQ(json, json1); } HWTEST_F(AvTransportAudioOutputFilterTest, ProcessAndSendBuffer_002, testing::ext::TestSize.Level1) diff --git a/av_transport/common/include/av_trans_buffer.h b/av_transport/common/include/av_trans_buffer.h index e919415f..9af839dc 100644 --- a/av_transport/common/include/av_trans_buffer.h +++ b/av_transport/common/include/av_trans_buffer.h @@ -89,10 +89,16 @@ public: uint32_t GetDataCount(); void Reset(); bool IsEmpty(); + void SetPts(int64_t pts); + int64_t GetPts(); + void SetPtsSpecial(int64_t ptsSpecial); + int64_t GetPtsSpecial(); private: std::vector> data_ {}; std::shared_ptr meta_; + int64_t pts_ = 0; + int64_t ptsSpecial_ = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/av_transport/common/src/av_trans_buffer.cpp b/av_transport/common/src/av_trans_buffer.cpp index eed0f4e1..0a754093 100644 --- a/av_transport/common/src/av_trans_buffer.cpp +++ b/av_transport/common/src/av_trans_buffer.cpp @@ -80,6 +80,25 @@ bool AVTransBuffer::IsEmpty() return data_.empty(); } +void AVTransBuffer::SetPts(int64_t pts) +{ + pts_ = pts; +} + +int64_t AVTransBuffer::GetPts() +{ + return pts_; +} + +void AVTransBuffer::SetPtsSpecial(int64_t ptsSpecial) +{ + ptsSpecial_ = ptsSpecial; +} + +int64_t AVTransBuffer::GetPtsSpecial() +{ + return ptsSpecial_; +} void AVTransBuffer::Reset() { if (data_[0]) { diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 5e81f69d..91d9542d 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -108,6 +108,14 @@ public: void OnGetDescriptors(const std::string &realNetworkId, const std::vector &descriptors); void SetAVSyncScene(const DHTopic topic); void UpdateSinkBusinessState(const std::string &networkId, const std::string &dhId, BusinessSinkState state); + int32_t InitAVSyncSharedMemory(); + void DeinitAVSyncSharedMemory(); + int32_t GetDHIdByDHSubtype(const DHSubtype dhSubtype, std::string &networkId, std::string &dhId); + int32_t GetDHSubtypeByDHId(DHSubtype &dhSubtype, const std::string &networkId, const std::string &dhId); + void HandleIdleStateChange(const std::string &networkId, const std::string &dhId, const DHType dhType); + void HandleBusinessStateChange(const std::string &networkId, const std::string &dhId, const DHSubtype dhSubType, + const BusinessState state); + void NotifyBusinessStateChange(const DHSubtype dhSubType, const BusinessState state); class ComponentManagerEventHandler : public AppExecFwk::EventHandler { public: ComponentManagerEventHandler(const std::shared_ptr runner); @@ -327,6 +335,7 @@ private: std::shared_ptr syncShareData_ = nullptr; DHTopic dhTopic_; + std::mutex dhTopicMtx_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index c73eecc2..f27eebc7 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -67,6 +67,8 @@ namespace { constexpr int32_t INVALID_SA_ID = -1; constexpr int32_t UNINIT_COMPONENT_TIMEOUT_SECONDS = 2; constexpr int32_t SYNC_DATA_TIMEOUT_MS = 1000; + constexpr const char *MIC = "mic"; + constexpr const char *CAMERA = "camera"; } ComponentManager::ComponentManager() : compSource_({}), compSink_({}), compSrcSaId_({}), @@ -686,9 +688,228 @@ bool ComponentManager::IsIdenticalAccount(const std::string &networkId) return false; } +int32_t ComponentManager::InitAVSyncSharedMemory() +{ + uint32_t memLen = sizeof(SyncShareData); + std::string memName = "AVSyncSharedMemory"; + syncSharedMem_ = OHOS::Ashmem::CreateAshmem(memName.c_str(), memLen); + if (syncSharedMem_ == nullptr) { + DHLOGE("create ashmem failed"); + return ERR_DH_FWK_POINTER_IS_NULL; + } + if (!syncSharedMem_->MapReadAndWriteAshmem()) { + DHLOGE("mmap ashmem failed"); + return ERR_DH_FWK_PARA_INVALID; + } + { + std::lock_guard lock(workModeParamMtx_); + workModeParam_.isAVsync = true; + workModeParam_.sharedMemLen = sizeof(SyncShareData); + workModeParam_.fd = syncSharedMem_->GetAshmemFd(); + } + + syncShareData_ = std::make_shared(); + syncShareData_->lock = 1; + syncShareData_->audio_current_pts = 0; + syncShareData_->audio_update_clock= 0; + syncShareData_->audio_speed = 1.0; + syncShareData_->video_current_pts= 0; + syncShareData_->video_update_clock= 0; + syncShareData_->video_speed = 1.0; + syncShareData_->sync_strategy= 1; + syncShareData_->reset = false; + + bool ret = syncSharedMem_->WriteToAshmem(static_cast(syncShareData_.get()), + sizeof(SyncShareData), 0); + if (!ret) { + DHLOGE("init sync info failed"); + return ERR_DH_FWK_BAD_OPERATION; + } + return DH_FWK_SUCCESS; +} + +void ComponentManager::DeinitAVSyncSharedMemory() +{ + if (syncSharedMem_ != nullptr) { + syncSharedMem_->UnmapAshmem(); + syncSharedMem_->CloseAshmem(); + syncSharedMem_ = nullptr; + } +} + +int32_t ComponentManager::GetDHIdByDHSubtype(const DHSubtype dhSubtype, std::string &networkId, std::string &dhId) +{ + std::lock_guard lock(bizStateMtx_); + for (const auto &iter : dhBizStates_) { + const auto devInfo = iter.first; + DHSubtype subType; + GetDHSubtypeByDHId(subType, devInfo.first, devInfo.second); + if (subType == dhSubtype) { + networkId = devInfo.first; + dhId = devInfo.second; + return DH_FWK_SUCCESS; + } + } + DHLOGE("unable to obtain dhId that matches dhSubtype."); + return ERR_DH_FWK_BAD_OPERATION; +} + +int32_t ComponentManager::GetDHSubtypeByDHId(DHSubtype &dhSubtype, const std::string &networkId, + const std::string &dhId) +{ + if (LocalCapabilityInfoManager::GetInstance() == nullptr) { + DHLOGE("LocalCapabilityInfoManager instance is null."); + return ERR_DH_FWK_BAD_OPERATION; + } + std::string deviceId = DHContext::GetInstance().GetDeviceIdByNetworkId(networkId); + if (deviceId.empty()) { + DHLOGE("Get deviceId by networkId failed"); + return ERR_DH_FWK_BAD_OPERATION; + } + std::string dhSubtypeStr = LocalCapabilityInfoManager::GetInstance()->GetDhSubtype(deviceId, dhId); + if (dhSubtypeStr.empty()) { + DHLOGE("Get dhSubtype by dhId failed"); + return ERR_DH_FWK_BAD_OPERATION; + } + if (dhSubtypeStr == MIC) { + dhSubtype = DHSubtype::AUDIO_MIC; + } else if (dhSubtypeStr == CAMERA) { + dhSubtype = DHSubtype::CAMERA; + } else { + DHLOGE("unable to obtain dhSubtype that matches dhId."); + return ERR_DH_FWK_BAD_OPERATION; + } + return DH_FWK_SUCCESS; +} + +void ComponentManager::HandleIdleStateChange(const std::string &networkId, const std::string &dhId, const DHType dhType) +{ + if (dhId.empty() || networkId.empty()) { + DHLOGE("targetDHId or targetNetworkId is empty"); + DeinitAVSyncSharedMemory(); + return; + } + auto targetHandler = GetDHSourceInstance(dhType); + if (targetHandler == nullptr) { + DHLOGE("targetHandler is nullptr"); + DeinitAVSyncSharedMemory(); + return; + } + { + std::lock_guard lock(workModeParamMtx_); + workModeParam_.isAVsync = false; + } + targetHandler->UpdateDistributedHardwareWorkMode(networkId, dhId, workModeParam_); + DeinitAVSyncSharedMemory(); + DHLOGI("handle idle state change success."); +} + +void ComponentManager::HandleBusinessStateChange(const std::string &networkId, const std::string &dhId, + const DHSubtype dhSubType, const BusinessState state) +{ + DHType sourceType = (dhSubType == DHSubtype::AUDIO_MIC) ? DHType::AUDIO : DHType::CAMERA; + DHType targetType = (dhSubType == DHSubtype::AUDIO_MIC) ? DHType::CAMERA : DHType::AUDIO; + DHSubtype targetSubType = (dhSubType == DHSubtype::AUDIO_MIC) ? DHSubtype::CAMERA : DHSubtype::AUDIO_MIC; + std::string targetDHId = ""; + std::string targetNetworkId = ""; + GetDHIdByDHSubtype(targetSubType, targetNetworkId, targetDHId); + DHLOGI("targetNetworkId: %{public}s, targetDHId: %{public}s, targetSubType: %{public}" PRIu32, + GetAnonyString(targetNetworkId).c_str(), GetAnonyString(targetDHId).c_str(), (uint32_t)targetSubType); + if (state == BusinessState::IDLE) { + HandleIdleStateChange(targetNetworkId, targetDHId, targetType); + } else if (state == BusinessState::RUNNING) { + if (targetDHId.empty() || targetNetworkId.empty()) { + DHLOGE("target dhardware is not online"); + return; + } + BusinessState targetState = QueryBusinessState(targetNetworkId, targetDHId); + if (targetState != BusinessState::RUNNING) { + DHLOGE("target dhardware is not ready"); + return; + } + auto targetHandler = GetDHSourceInstance(targetType); + auto sourceHandler = GetDHSourceInstance(sourceType); + if (targetHandler == nullptr || sourceHandler == nullptr) { + DHLOGE("can not find cameraHandler or audioHandler"); + return; + } + + int32_t ret = InitAVSyncSharedMemory(); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("InitAVSyncSharedMemory failed"); + DeinitAVSyncSharedMemory(); + return; + } + ret = targetHandler->UpdateDistributedHardwareWorkMode(targetNetworkId, targetDHId, workModeParam_); + if (ret != DH_FWK_SUCCESS) { + DeinitAVSyncSharedMemory(); + return; + } + ret = sourceHandler->UpdateDistributedHardwareWorkMode(networkId, dhId, workModeParam_); + if (ret != DH_FWK_SUCCESS) { + DeinitAVSyncSharedMemory(); + HandleIdleStateChange(targetNetworkId, targetDHId, targetType); + return; + } + } +} + +void ComponentManager::NotifyBusinessStateChange(const DHSubtype dhSubType, const BusinessState state) +{ + DHLOGI("NotifyBusinessStateChange, dhSubType:%{public}" PRIu32", state:%{public}" PRIu32, + static_cast(dhSubType), static_cast(state)); + cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + DHLOGE("cJSON_CreateObject failed"); + return; + } + if (cJSON_AddNumberToObject(root, DH_SUBTYPE, static_cast(dhSubType)) == nullptr) { + DHLOGE("failed to add dhSubType to json"); + cJSON_Delete(root); + return; + } + if (cJSON_AddNumberToObject(root, BUSINESS_STATE, static_cast(state)) == nullptr) { + DHLOGE("failed to add state to json"); + cJSON_Delete(root); + return; + } + char *json = cJSON_Print(root); + if (json == nullptr) { + DHLOGE("failed to print json"); + cJSON_Delete(root); + return; + } + std::lock_guard lock(dhTopicMtx_); + Publisher::GetInstance().PublishMessage(dhTopic_, json); + cJSON_Delete(root); + free(json); + return; +} + +void ComponentManager::UpdateSinkBusinessState(const std::string &networkId, const std::string &dhId, + BusinessSinkState state) +{ + if (!IsIdLengthValid(networkId) || !IsIdLengthValid(dhId)) { + return; + } + DHLOGI("UpdateSinkBusinessState, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, + GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str(), (uint32_t)state); + DHSubtype dhSubtype; + GetDHSubtypeByDHId(dhSubtype, networkId, dhId); + DHLOGI("UpdateSinkBusinessState::get dhSubtype:%{public}" PRIu32, static_cast(dhSubtype)); + if (state == BusinessSinkState::IDLE) { + NotifyBusinessStateChange(dhSubtype, BusinessState::IDLE); + } else if (state == BusinessSinkState::RUNNING) { + NotifyBusinessStateChange(dhSubtype, BusinessState::RUNNING); + } else { + DHLOGI("unsupported sink business state"); + } +} + void ComponentManager::SetAVSyncScene(const DHTopic topic) { DHLOGI("set AVSync scene : %{public}" PRIu32, topic); + std::lock_guard lock(dhTopicMtx_); switch (topic) { case DHTopic::TOPIC_AV_LOW_LATENCY: { dhTopic_ = topic; @@ -708,16 +929,6 @@ void ComponentManager::SetAVSyncScene(const DHTopic topic) } } -void ComponentManager::UpdateSinkBusinessState(const std::string &networkId, const std::string &dhId, - BusinessSinkState state) -{ - if (!IsIdLengthValid(networkId) || !IsIdLengthValid(dhId)) { - return; - } - DHLOGI("UpdateSinkBusinessState, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, - GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str(), (uint32_t)state); -} - void ComponentManager::UpdateBusinessState(const std::string &networkId, const std::string &dhId, BusinessState state) { if (!IsIdLengthValid(networkId) || !IsIdLengthValid(dhId)) { @@ -729,7 +940,13 @@ void ComponentManager::UpdateBusinessState(const std::string &networkId, const s std::lock_guard lock(bizStateMtx_); dhBizStates_[{networkId, dhId}] = state; } - + DHSubtype dhSubtype; + GetDHSubtypeByDHId(dhSubtype, networkId, dhId); + DHLOGI("UpdateBusinessState::get dhSubtype:%{public}" PRIu32, static_cast(dhSubtype)); + if (dhSubtype == DHSubtype::CAMERA || dhSubtype == DHSubtype::AUDIO_MIC) { + NotifyBusinessStateChange(dhSubtype, state); + HandleBusinessStateChange(networkId, dhId, dhSubtype, state); + } if (state == BusinessState::IDLE) { TaskParam taskParam; if (!FetchNeedRefreshTask({networkId, dhId}, taskParam)) { diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index b3fdfd05..5a458217 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -181,6 +181,7 @@ int32_t DistributedHardwareService::RegisterPublisherListener(const DHTopic topi const sptr listener) { Publisher::GetInstance().RegisterListener(topic, listener); + ComponentManager::GetInstance().SetAVSyncScene(topic); return DH_FWK_SUCCESS; } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp index 71d7c200..a2023494 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp @@ -75,6 +75,7 @@ const std::string DH_SUBTYPE_TEST = "camera"; const std::string TEST_SOURCE_VERSION_1 = "2.2"; const std::string TEST_SINK_VERSION_1 = "2.4"; const std::string TEST_DH_VERSION = "3.1"; +constexpr uint16_t DEV_TYPE_TEST = 14; const std::shared_ptr CAP_INFO_TEST = std::make_shared(DH_ID_TEST, DEV_ID_TEST, DEVICE_NAME, TEST_DEV_TYPE_PAD, DHType::CAMERA, DH_ATTR_1, DH_SUBTYPE_TEST); @@ -1059,6 +1060,247 @@ HWTEST_F(ComponentManagerTest, UpdateBusinessState_002, TestSize.Level1) EXPECT_NO_FATAL_FAILURE(ComponentManager::GetInstance().UpdateBusinessState(NETWORK_TEST, DH_ID_TEST, state)); } +HWTEST_F(ComponentManagerTest, UpdateBusinessState_003, TestSize.Level1) +{ + std::string peeruuid = "123456789"; + std::string dhid = "audio_132"; + std::string deviceId = Sha256(peeruuid); + BusinessState state = BusinessState::IDLE; + std::shared_ptr capInfo1 = std::make_shared( + dhid, deviceId, "devName_test", DEV_TYPE_TEST, DHType::AUDIO, "attrs", "mic"); + std::string key = deviceId + "###" + dhid; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo1; + EXPECT_NO_FATAL_FAILURE(ComponentManager::GetInstance().UpdateBusinessState(deviceId, dhid, state)); + + dhid = "camera_132"; + std::shared_ptr capInfo2 = std::make_shared( + dhid, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs", "camera"); + key = deviceId + "###" + dhid; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo2; + EXPECT_NO_FATAL_FAILURE(ComponentManager::GetInstance().UpdateBusinessState(deviceId, dhid, state)); +} + +HWTEST_F(ComponentManagerTest, GetDHSubtypeByDHId_001, TestSize.Level1) +{ + std::string peeruuid = "123456789"; + std::string dhid = "audio_132"; + std::string deviceId = Sha256(peeruuid); + DHSubtype dhSubtype; + std::shared_ptr capInfo1 = std::make_shared( + dhid, deviceId, "devName_test", DEV_TYPE_TEST, DHType::AUDIO, "attrs", "mic"); + std::string key = deviceId + "###" + dhid; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo1; + auto ret = ComponentManager::GetInstance().GetDHSubtypeByDHId(dhSubtype, deviceId, dhid); + EXPECT_EQ(DHSubtype::AUDIO_MIC, dhSubtype); + EXPECT_EQ(ret, DH_FWK_SUCCESS); + dhid = "camera_132"; + std::shared_ptr capInfo2 = std::make_shared( + dhid, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs", "camera"); + key = deviceId + "###" + dhid; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo2; + ret = ComponentManager::GetInstance().GetDHSubtypeByDHId(dhSubtype, deviceId, dhid); + EXPECT_EQ(DHSubtype::CAMERA, dhSubtype); + EXPECT_EQ(ret, DH_FWK_SUCCESS); + dhid = "unknown_132"; + std::shared_ptr capInfo3 = std::make_shared( + dhid, deviceId, "devName_test", DEV_TYPE_TEST, DHType::UNKNOWN, "attrs", "unknown"); + key = deviceId + "###" + dhid; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo3; + ret = ComponentManager::GetInstance().GetDHSubtypeByDHId(dhSubtype, deviceId, dhid); + EXPECT_EQ(ret, ERR_DH_FWK_BAD_OPERATION); +} + +HWTEST_F(ComponentManagerTest, InitAVSyncSharedMemory_001, TestSize.Level1) +{ + auto ret = ComponentManager::GetInstance().InitAVSyncSharedMemory(); + EXPECT_EQ(ret, DH_FWK_SUCCESS); +} + +HWTEST_F(ComponentManagerTest, DeinitAVSyncSharedMemory_001, TestSize.Level1) +{ + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().DeinitAVSyncSharedMemory()); +} + +HWTEST_F(ComponentManagerTest, GetDHIdByDHSubtype_001, TestSize.Level1) +{ + std::string peeruuid = "123456789"; + std::string dhid = "audio_132"; + std::string deviceId = Sha256(peeruuid); + std::shared_ptr capInfo1 = std::make_shared( + dhid, deviceId, "devName_test", DEV_TYPE_TEST, DHType::AUDIO, "attrs", "mic"); + std::string key = deviceId + "###" + dhid; + BusinessState state = BusinessState::IDLE; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo1; + ComponentManager::GetInstance().dhBizStates_.emplace(std::make_pair(deviceId, dhid), state); + auto ret = ComponentManager::GetInstance().GetDHIdByDHSubtype(DHSubtype::AUDIO_MIC, deviceId, dhid); + EXPECT_EQ(ret, DH_FWK_SUCCESS); + ret = ComponentManager::GetInstance().GetDHIdByDHSubtype(DHSubtype::CAMERA, deviceId, dhid); + EXPECT_EQ(ret, ERR_DH_FWK_BAD_OPERATION); +} + +HWTEST_F(ComponentManagerTest, HandleIdleStateChange_001, TestSize.Level1) +{ + std::string networkId = ""; + std::string dhId = ""; + DHType dhType = DHType::UNKNOWN; + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleIdleStateChange(networkId, dhId, dhType)); + + networkId = "networkId_1"; + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleIdleStateChange(networkId, dhId, dhType)); + + networkId = ""; + dhId = "dhId_1"; + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleIdleStateChange(networkId, dhId, dhType)); + + networkId = "networkId_1"; + IDistributedHardwareSource *sourcePtr = nullptr; + ComponentManager::GetInstance().compSource_.insert(std::make_pair(DHType::CAMERA, sourcePtr)); + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleIdleStateChange(networkId, dhId, dhType)); + + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleIdleStateChange(networkId, dhId, DHType::CAMERA)); + ComponentManager::GetInstance().compSource_.clear(); +} + +HWTEST_F(ComponentManagerTest, HandleBusinessStateChange_001, TestSize.Level1) +{ + std::string networkId = "networkId_1"; + std::string dhid = "audio_132"; + DHSubtype dhSubType = DHSubtype::AUDIO_MIC; + BusinessState state = BusinessState::IDLE; + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); + state = BusinessState::RUNNING; + std::string peeruuid = "123456789"; + std::string deviceId = Sha256(peeruuid); + std::shared_ptr capInfo1 = std::make_shared( + dhid, deviceId, "devName_test", DEV_TYPE_TEST, DHType::AUDIO, "attrs", "mic"); + std::string key = deviceId + "###" + dhid; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo1; + ComponentManager::GetInstance().dhBizStates_.emplace(std::make_pair(deviceId, dhid), BusinessState::IDLE); + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); + std::string dhid2 = "camera_132"; + std::shared_ptr capInfo2 = std::make_shared( + dhid2, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs", "camera"); + key = deviceId + "###" + dhid2; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo2; + ComponentManager::GetInstance().dhBizStates_.emplace(std::make_pair(deviceId, dhid2), BusinessState::UNKNOWN); + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); + ComponentManager::GetInstance().dhBizStates_.emplace(std::make_pair(deviceId, dhid2), BusinessState::RUNNING); + IDistributedHardwareSource *sourcePtr1 = nullptr; + ComponentManager::GetInstance().compSource_.insert(std::make_pair(DHType::CAMERA, sourcePtr1)); + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); + IDistributedHardwareSource *sourcePtr2 = nullptr; + ComponentManager::GetInstance().compSource_.insert(std::make_pair(DHType::AUDIO, sourcePtr2)); + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); + ComponentManager::GetInstance().dhBizStates_.clear(); + ComponentManager::GetInstance().compSource_.clear(); +} + +HWTEST_F(ComponentManagerTest, HandleBusinessStateChange_002, TestSize.Level1) +{ + std::string networkId = "networkId_1"; + std::string dhid = "audio_132"; + DHSubtype dhSubType = DHSubtype::AUDIO_MIC; + BusinessState state = BusinessState::RUNNING; + ComponentManager::GetInstance().dhBizStates_.clear(); + ComponentManager::GetInstance().compSource_.clear(); + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); +} + +HWTEST_F(ComponentManagerTest, HandleBusinessStateChange_003, TestSize.Level1) +{ + std::string networkId = "networkId_1"; + std::string dhid = "audio_132"; + DHSubtype dhSubType = DHSubtype::AUDIO_MIC; + BusinessState state = BusinessState::RUNNING; + + std::string peeruuid = "123456789"; + std::string deviceId = Sha256(peeruuid); + std::shared_ptr capInfo1 = std::make_shared( + dhid, deviceId, "devName_test", DEV_TYPE_TEST, DHType::AUDIO, "attrs", "mic"); + std::string key = deviceId + "###" + dhid; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo1; + std::string dhid2 = "camera_132"; + std::shared_ptr capInfo2 = std::make_shared( + dhid2, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs", "camera"); + key = deviceId + "###" + dhid2; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo2; + + ComponentManager::GetInstance().dhBizStates_.emplace(std::make_pair(deviceId, dhid2), BusinessState::IDLE); + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); + ComponentManager::GetInstance().dhBizStates_.clear(); + ComponentManager::GetInstance().compSource_.clear(); +} + +HWTEST_F(ComponentManagerTest, HandleBusinessStateChange_004, TestSize.Level1) +{ + std::string networkId = "networkId_1"; + std::string dhid = "audio_132"; + DHSubtype dhSubType = DHSubtype::AUDIO_MIC; + BusinessState state = BusinessState::RUNNING; + std::string peeruuid = "123456789"; + std::string deviceId = Sha256(peeruuid); + std::shared_ptr capInfo1 = std::make_shared( + dhid, deviceId, "devName_test", DEV_TYPE_TEST, DHType::AUDIO, "attrs", "mic"); + std::string key = deviceId + "###" + dhid; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo1; + std::string dhid2 = "camera_132"; + std::shared_ptr capInfo2 = std::make_shared( + dhid2, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs", "camera"); + key = deviceId + "###" + dhid2; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo2; + ComponentManager::GetInstance().dhBizStates_.emplace(std::make_pair(deviceId, dhid2), BusinessState::RUNNING); + ComponentManager::GetInstance().dhBizStates_.emplace(std::make_pair(deviceId, dhid), BusinessState::RUNNING); + + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); + ComponentManager::GetInstance().dhBizStates_.clear(); + ComponentManager::GetInstance().compSource_.clear(); +} + +HWTEST_F(ComponentManagerTest, HandleBusinessStateChange_005, TestSize.Level1) +{ + std::string networkId = "networkId_1"; + std::string dhid = "camera_132"; + DHSubtype dhSubType = DHSubtype::CAMERA; + BusinessState state = BusinessState::IDLE; + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); + state = BusinessState::RUNNING; + std::string peeruuid = "123456789"; + std::string deviceId = Sha256(peeruuid); + std::shared_ptr capInfo1 = std::make_shared( + dhid, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs", "camera"); + std::string key = deviceId + "###" + dhid; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo1; + ComponentManager::GetInstance().dhBizStates_.emplace(std::make_pair(deviceId, dhid), BusinessState::IDLE); + std::string dhid2 = "audio_132"; + std::shared_ptr capInfo2 = std::make_shared( + dhid2, deviceId, "devName_test", DEV_TYPE_TEST, DHType::AUDIO, "attrs", "mic"); + key = deviceId + "###" + dhid2; + LocalCapabilityInfoManager::GetInstance()->globalCapInfoMap_[key] = capInfo2; + ComponentManager::GetInstance().dhBizStates_.emplace(std::make_pair(deviceId, dhid2), BusinessState::UNKNOWN); + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); + ComponentManager::GetInstance().dhBizStates_.emplace(std::make_pair(deviceId, dhid2), BusinessState::RUNNING); + IDistributedHardwareSource *sourcePtr1 = nullptr; + ComponentManager::GetInstance().compSource_.insert(std::make_pair(DHType::AUDIO, sourcePtr1)); + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); + IDistributedHardwareSource *sourcePtr2 = nullptr; + ComponentManager::GetInstance().compSource_.insert(std::make_pair(DHType::CAMERA, sourcePtr2)); + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().HandleBusinessStateChange(networkId, + dhid, dhSubType, state)); + ComponentManager::GetInstance().dhBizStates_.clear(); + ComponentManager::GetInstance().compSource_.clear(); +} + HWTEST_F(ComponentManagerTest, QueryBusinessState_001, TestSize.Level1) { BusinessState ret = ComponentManager::GetInstance().QueryBusinessState("", ""); @@ -1361,6 +1603,19 @@ HWTEST_F(ComponentManagerTest, UpdateSinkBusinessState_001, testing::ext::TestSi networkId = "networkId_1"; ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().UpdateSinkBusinessState(networkId, dhId, state)); + + state = BusinessSinkState::RUNNING; + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().UpdateSinkBusinessState(networkId, dhId, state)); + + state = BusinessSinkState::IDLE; + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().UpdateSinkBusinessState(networkId, dhId, state)); +} + +HWTEST_F(ComponentManagerTest, NotifyBusinessStateChange_001, testing::ext::TestSize.Level1) +{ + BusinessState state = BusinessState::UNKNOWN; + DHSubtype dhSubType = DHSubtype::CAMERA; + ASSERT_NO_FATAL_FAILURE(ComponentManager::GetInstance().NotifyBusinessStateChange(dhSubType, state)); } } // namespace DistributedHardware } // namespace OHOS -- Gitee