已开启
AI扫描问题修改 #549
AI扫描问题修改 #549
已开启
harmonyosgogogo创建于 7月31日
14 个文件变更+94-41
@@ -680,13 +680,13 @@ SharingErrorCode Agent::CheckRunStep(SharingEvent &event, bool &isCached)
680 680 
681void Agent::PopNextStep(AgentRunStep step, AgentRunningStatus status)681void Agent::PopNextStep(AgentRunStep step, AgentRunningStatus status)
682{682{
683- SHARING_LOGD("pop run step, now step: %{public}s, now status: %{public}s, agentId: %{public}u.",
684- std::string(magic_enum::enum_name(runStep_)).c_str(),
685- std::string(magic_enum::enum_name(runningStatus_)).c_str(), GetId());
686 SharingEvent event;683 SharingEvent event;
687 bool ret = false;684 bool ret = false;
688 {685 {
689 std::lock_guard<std::mutex> lock(runStepMutex_);686 std::lock_guard<std::mutex> lock(runStepMutex_);
687+ SHARING_LOGD("pop run step, now step: %{public}s, now status: %{public}s, agentId: %{public}u.",
688+ std::string(magic_enum::enum_name(runStep_)).c_str(),
689+ std::string(magic_enum::enum_name(runningStatus_)).c_str(), GetId());
690 if (step != runStep_) {690 if (step != runStep_) {
691 SHARING_LOGW(691 SHARING_LOGW(
692 "pop run step, set step: %{public}s is not equal to now step: %{public}s, agentId: %{public}u.",692 "pop run step, set step: %{public}s is not equal to now step: %{public}s, agentId: %{public}u.",
@@ -58,9 +58,15 @@ void SinkAgent::OnSessionNotify(SessionStatusMsg::Ptr &statusMsg)
58 case SessionNotifyStatus::STATE_SESSION_DESTROYED:58 case SessionNotifyStatus::STATE_SESSION_DESTROYED:
59 NotifyConsumer(statusMsg, EventType::EVENT_MEDIA_CONSUMER_DESTROY);59 NotifyConsumer(statusMsg, EventType::EVENT_MEDIA_CONSUMER_DESTROY);
60 break;60 break;
61- case SessionNotifyStatus::STATE_SESSION_INTERRUPTED:61+ case SessionNotifyStatus::STATE_SESSION_INTERRUPTED: {
62- PopNextStep(runStep_, AGENT_STATUS_DONE);62+ AgentRunStep runStep = AGENT_STEP_IDLE;
63+ {
64+ std::lock_guard<std::mutex> lock(runStepMutex_);
65+ runStep = runStep_;
66+ }
67+ PopNextStep(runStep, AGENT_STATUS_DONE);
63 break;68 break;
69+ }
64 default:70 default:
65 Agent::OnSessionNotify(statusMsg);71 Agent::OnSessionNotify(statusMsg);
66 break;72 break;
@@ -18,6 +18,7 @@
18 18 
19#include <chrono>19#include <chrono>
20#include <queue>20#include <queue>
21+#include <atomic>
21#include "audio_decoder.h"22#include "audio_decoder.h"
22#include "avcodec_audio_decoder.h"23#include "avcodec_audio_decoder.h"
23 24 
@@ -85,9 +86,9 @@ public:
85 CodecId audioCodecId_ = CODEC_NONE;86 CodecId audioCodecId_ = CODEC_NONE;
86 87 
87private:88private:
88- int64_t firstTimestampUs_{0};89+ std::atomic<int64_t> firstTimestampUs_{0};
89- int64_t lastPlayPts_{0};90+ std::atomic<int64_t> lastPlayPts_{0};
90- int64_t lastRenderTimeUs_{0};91+ std::atomic<int64_t> lastRenderTimeUs_{0};
91 AudioFrameState audioFrameState_ = AudioFrameState::INIT;92 AudioFrameState audioFrameState_ = AudioFrameState::INIT;
92 93 
93 std::atomic<bool> isRenderReady_{false};94 std::atomic<bool> isRenderReady_{false};
@@ -65,6 +65,7 @@ private:
65 bool StopDecoder();65 bool StopDecoder();
66 bool StartDecoder();66 bool StartDecoder();
67 bool SetVideoCallback();67 bool SetVideoCallback();
68+ bool ProcessVideoDataAndQueue(int32_t inputIndex, const char *data, int32_t size, uint64_t pts);
68 69 
69public:70public:
70 bool enableSurface_ = false;71 bool enableSurface_ = false;
@@ -77,13 +78,15 @@ public:
77 std::mutex inMutex_;78 std::mutex inMutex_;
78 std::condition_variable inCond_;79 std::condition_variable inCond_;
79 std::atomic_bool isRunning_ = false;80 std::atomic_bool isRunning_ = false;
80- std::weak_ptr<VideoSinkDecoderListener> videoDecoderListener_;
81 std::shared_ptr<OHOS::MediaAVCodec::AVCodecVideoDecoder> videoDecoder_ = nullptr;81 std::shared_ptr<OHOS::MediaAVCodec::AVCodecVideoDecoder> videoDecoder_ = nullptr;
82 82 
83 VideoTrack videoTrack_;83 VideoTrack videoTrack_;
84 CodecId videoCodecId_ = CODEC_NONE;84 CodecId videoCodecId_ = CODEC_NONE;
85 sptr<OHOS::Surface> surface_ = nullptr;85 sptr<OHOS::Surface> surface_ = nullptr;
86 std::shared_ptr<VideoAudioSync> videoAudioSync_ = nullptr;86 std::shared_ptr<VideoAudioSync> videoAudioSync_ = nullptr;
87+ 
88+private:
89+ std::weak_ptr<VideoSinkDecoderListener> videoDecoderListener_;
87};90};
88} // namespace Sharing91} // namespace Sharing
89} // namespace OHOS92} // namespace OHOS
@@ -71,18 +71,22 @@ int32_t AudioAACDecoder::Init(const AudioTrack &audioTrack)
71 71 
72 if (avcodec_open2(codecCtx_, dec, nullptr) < 0) {72 if (avcodec_open2(codecCtx_, dec, nullptr) < 0) {
73 SHARING_LOGE("Failed to open codec.");73 SHARING_LOGE("Failed to open codec.");
74+ avcodec_free_context(&codecCtx_);
74 return -1;75 return -1;
75 }76 }
76 77 
77 avPacket_ = av_packet_alloc();78 avPacket_ = av_packet_alloc();
78 if (avPacket_ == nullptr) {79 if (avPacket_ == nullptr) {
79 SHARING_LOGE("Failed to alloc packet.");80 SHARING_LOGE("Failed to alloc packet.");
81+ avcodec_free_context(&codecCtx_);
80 return -1;82 return -1;
81 }83 }
82 84 
83 avFrame_ = av_frame_alloc();85 avFrame_ = av_frame_alloc();
84 if (avFrame_ == nullptr) {86 if (avFrame_ == nullptr) {
85 SHARING_LOGE("Failed to alloc frame.");87 SHARING_LOGE("Failed to alloc frame.");
88+ avcodec_free_context(&codecCtx_);
89+ av_packet_free(&avPacket_);
86 return -1;90 return -1;
87 }91 }
88 return 0;92 return 0;
@@ -254,7 +254,7 @@ void AudioAvCodecDecoder::OnOutputBufferAvailable(uint32_t index, MediaAVCodec::
254 SHARING_LOGE("flag is eos.");254 SHARING_LOGE("flag is eos.");
255 return;255 return;
256 }256 }
257- if (!buffer) {257+ if (!buffer || buffer->GetBase() == nullptr) {
258 SHARING_LOGE("buffer is null");258 SHARING_LOGE("buffer is null");
259 return;259 return;
260 }260 }
@@ -268,7 +268,7 @@ void AudioAvCodecDecoder::OnOutputBufferAvailable(uint32_t index, MediaAVCodec::
268 std::chrono::microseconds nowUs =268 std::chrono::microseconds nowUs =
269 std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch());269 std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch());
270 int64_t nowTimeUs = nowUs.count();270 int64_t nowTimeUs = nowUs.count();
271- if (firstTimestampUs_ == 0) {271+ if (firstTimestampUs_.load() == 0) {
272 SHARING_LOGI("decode first audio frame");272 SHARING_LOGI("decode first audio frame");
273 firstTimestampUs_ = info.presentationTimeUs;273 firstTimestampUs_ = info.presentationTimeUs;
274 }274 }
@@ -381,13 +381,13 @@ bool AudioAvCodecDecoder::StartRender()
381int64_t AudioAvCodecDecoder::GetDecoderTimestamp()381int64_t AudioAvCodecDecoder::GetDecoderTimestamp()
382{382{
383 int64_t timestamp = 0;383 int64_t timestamp = 0;
384- if (firstTimestampUs_ == 0) {384+ if (firstTimestampUs_.load() == 0) {
385 return timestamp;385 return timestamp;
386 }386 }
387 387 
388 std::chrono::microseconds nowUs =388 std::chrono::microseconds nowUs =
389 std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch());389 std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch());
390- int64_t diffTime = nowUs.count() - lastRenderTimeUs_;390+ int64_t diffTime = nowUs.count() - lastRenderTimeUs_.load();
391 if (diffTime > NO_AUDIO_FRAME_INTERVAL) {391 if (diffTime > NO_AUDIO_FRAME_INTERVAL) {
392 if (audioFrameState_ == AudioFrameState::INIT || audioFrameState_ == AudioFrameState::HAS_FRAME) {392 if (audioFrameState_ == AudioFrameState::INIT || audioFrameState_ == AudioFrameState::HAS_FRAME) {
393 SHARING_LOGW("no audio frame interval");393 SHARING_LOGW("no audio frame interval");
@@ -399,7 +399,7 @@ int64_t AudioAvCodecDecoder::GetDecoderTimestamp()
399 SHARING_LOGI("has audio frame interval");399 SHARING_LOGI("has audio frame interval");
400 audioFrameState_ = AudioFrameState::HAS_FRAME;400 audioFrameState_ = AudioFrameState::HAS_FRAME;
401 }401 }
402- timestamp = lastPlayPts_ - audioLatency_.load();402+ timestamp = lastPlayPts_.load() - audioLatency_.load();
403 return timestamp;403 return timestamp;
404 }404 }
405}405}
@@ -151,6 +151,8 @@ void VideoSinkDecoder::Stop()
151 std::lock_guard<std::mutex> lock(inMutex_);151 std::lock_guard<std::mutex> lock(inMutex_);
152 std::queue<int32_t> temp;152 std::queue<int32_t> temp;
153 std::swap(temp, inQueue_);153 std::swap(temp, inQueue_);
154+ std::queue<std::shared_ptr<MediaAVCodec::AVSharedMemory>> tempBuff;
155+ std::swap(tempBuff, inBufferQueue_);
154 }156 }
155}157}
156 158 
@@ -244,6 +246,24 @@ bool VideoSinkDecoder::DecodeVideoData(const char *data, int32_t size, uint64_t
244 return false;246 return false;
245 }247 }
246 248 
249+ if (!ProcessVideoDataAndQueue(inputIndex, data, size, pts)) {
250+ return false;
251+ }
252+
253+ lock.lock();
254+ if (inQueue_.empty() || inBufferQueue_.empty()) {
255+ MEDIA_LOGW("decoder has stopper, inQueue is empty");
256+ return true;
257+ }
258+ inQueue_.pop();
259+ inBufferQueue_.pop();
260+ 
261+ MEDIA_LOGD("process data success controlId: %{public}u.", controlId_);
262+ return true;
263+}
264+ 
265+bool VideoSinkDecoder::ProcessVideoDataAndQueue(int32_t inputIndex, const char *data, int32_t size, uint64_t pts)
266+{
247 MediaAVCodec::AVCodecBufferInfo bufferInfo;267 MediaAVCodec::AVCodecBufferInfo bufferInfo;
248 bufferInfo.presentationTimeUs = static_cast<int64_t>(pts);268 bufferInfo.presentationTimeUs = static_cast<int64_t>(pts);
249 bufferInfo.size = size;269 bufferInfo.size = size;
@@ -256,6 +276,7 @@ bool VideoSinkDecoder::DecodeVideoData(const char *data, int32_t size, uint64_t
256 return false;276 return false;
257 }277 }
258 p = *(p + 2) == 0x01 ? p + 3 : p + 4; // 2: offset, 3: offset, 4: offset278 p = *(p + 2) == 0x01 ? p + 3 : p + 4; // 2: offset, 3: offset, 4: offset
279+ int32_t ret = MediaAVCodec::AVCS_ERR_OK;
259 if ((p[0] & 0x1f) == 0x06 || (p[0] & 0x1f) == 0x07 || (p[0] & 0x1f) == 0x08) {280 if ((p[0] & 0x1f) == 0x06 || (p[0] & 0x1f) == 0x07 || (p[0] & 0x1f) == 0x08) {
260 MEDIA_LOGD("media flag codec data controlId: %{public}u.", controlId_);281 MEDIA_LOGD("media flag codec data controlId: %{public}u.", controlId_);
261 ret = videoDecoder_->QueueInputBuffer(inputIndex, bufferInfo, MediaAVCodec::AVCODEC_BUFFER_FLAG_CODEC_DATA);282 ret = videoDecoder_->QueueInputBuffer(inputIndex, bufferInfo, MediaAVCodec::AVCODEC_BUFFER_FLAG_CODEC_DATA);
@@ -268,12 +289,6 @@ bool VideoSinkDecoder::DecodeVideoData(const char *data, int32_t size, uint64_t
268 MEDIA_LOGE("QueueInputBuffer failed error: %{public}d controlId: %{public}u.", ret, controlId_);289 MEDIA_LOGE("QueueInputBuffer failed error: %{public}d controlId: %{public}u.", ret, controlId_);
269 return false;290 return false;
270 }291 }
271-
272- lock.lock();
273- inQueue_.pop();
274- inBufferQueue_.pop();
275- 
276- MEDIA_LOGD("process data success controlId: %{public}u.", controlId_);
277 return true;292 return true;
278}293}
279 294 
@@ -56,6 +56,10 @@ int32_t DataShareHelper::RegisterObserver(const sptr<AAFwk::IDataAbilityObserver
56 56 
57int32_t DataShareHelper::UnregisterObserver(const sptr<AAFwk::IDataAbilityObserver> &observer)57int32_t DataShareHelper::UnregisterObserver(const sptr<AAFwk::IDataAbilityObserver> &observer)
58{58{
59+ if (observer == nullptr) {
60+ SHARING_LOGE("fail to unregister observer, observer is null");
61+ return DATA_SHARE_ERROR;
62+ }
59 if (helper_ == nullptr && !Init()) {63 if (helper_ == nullptr && !Init()) {
60 SHARING_LOGE("fail to unregister observer, helper is null");64 SHARING_LOGE("fail to unregister observer, helper is null");
61 return DATA_SHARE_ERROR;65 return DATA_SHARE_ERROR;
@@ -32,9 +32,10 @@ std::shared_ptr<NativePreferences::Preferences> PreferencesUtil::GetProfiles(con
32 32 
33int PreferencesUtil::PutString(const std::string &key, const std::string &value)33int PreferencesUtil::PutString(const std::string &key, const std::string &value)
34{34{
35- std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode_);35+ int errCode = NativePreferences::E_OK;
36+ std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode);
36 if (ptr == nullptr) {37 if (ptr == nullptr) {
37- SHARING_LOGE("get profiles failed. errcode_ %{public}d.", errCode_);38+ SHARING_LOGE("get profiles failed. errCode %{public}d.", errCode);
38 return NativePreferences::E_ERROR;39 return NativePreferences::E_ERROR;
39 }40 }
40 std::lock_guard<std::mutex> lock(preferencesMutex_);41 std::lock_guard<std::mutex> lock(preferencesMutex_);
@@ -45,9 +46,10 @@ int PreferencesUtil::PutString(const std::string &key, const std::string &value)
45 46 
46std::string PreferencesUtil::GetString(const std::string &key)47std::string PreferencesUtil::GetString(const std::string &key)
47{48{
48- std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode_);49+ int errCode = NativePreferences::E_OK;
50+ std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode);
49 if (ptr == nullptr) {51 if (ptr == nullptr) {
50- SHARING_LOGE("get profiles failed. errcode_ %{public}d.", errCode_);52+ SHARING_LOGE("get profiles failed. errCode %{public}d.", errCode);
51 return "";53 return "";
52 }54 }
53 std::string defaultValue = "";55 std::string defaultValue = "";
@@ -58,9 +60,10 @@ std::string PreferencesUtil::GetString(const std::string &key)
58 60 
59int PreferencesUtil::DeleteKey(const std::string &key)61int PreferencesUtil::DeleteKey(const std::string &key)
60{62{
61- std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode_);63+ int errCode = NativePreferences::E_OK;
64+ std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode);
62 if (ptr == nullptr) {65 if (ptr == nullptr) {
63- SHARING_LOGE("get profiles failed. errcode_ %{public}d.", errCode_);66+ SHARING_LOGE("get profiles failed. errCode %{public}d.", errCode);
64 return NativePreferences::E_ERROR;67 return NativePreferences::E_ERROR;
65 }68 }
66 std::lock_guard<std::mutex> lock(preferencesMutex_);69 std::lock_guard<std::mutex> lock(preferencesMutex_);
@@ -71,9 +74,10 @@ int PreferencesUtil::DeleteKey(const std::string &key)
71 74 
72int PreferencesUtil::Clear()75int PreferencesUtil::Clear()
73{76{
74- std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode_);77+ int errCode = NativePreferences::E_OK;
78+ std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode);
75 if (ptr == nullptr) {79 if (ptr == nullptr) {
76- SHARING_LOGE("get profiles failed. errcode_ %{public}d.", errCode_);80+ SHARING_LOGE("get profiles failed. errCode %{public}d.", errCode);
77 return NativePreferences::E_ERROR;81 return NativePreferences::E_ERROR;
78 }82 }
79 std::lock_guard<std::mutex> lock(preferencesMutex_);83 std::lock_guard<std::mutex> lock(preferencesMutex_);
@@ -84,19 +88,23 @@ int PreferencesUtil::Clear()
84 88 
85void PreferencesUtil::Flush()89void PreferencesUtil::Flush()
86{90{
87- std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode_);91+ int errCode = NativePreferences::E_OK;
92+ std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode);
88 if (ptr != nullptr) {93 if (ptr != nullptr) {
94+ std::lock_guard<std::mutex> lock(preferencesMutex_);
89 ptr->Flush();95 ptr->Flush();
90 }96 }
91}97}
92 98 
93int PreferencesUtil::FlushSync()99int PreferencesUtil::FlushSync()
94{100{
95- std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode_);101+ int errCode = NativePreferences::E_OK;
102+ std::shared_ptr<NativePreferences::Preferences> ptr = GetProfiles(path_, errCode);
96 if (ptr == nullptr) {103 if (ptr == nullptr) {
97- SHARING_LOGE("get profiles failed. errcode_ %{public}d.", errCode_);104+ SHARING_LOGE("get profiles failed. errCode %{public}d.", errCode);
98 return NativePreferences::E_ERROR;105 return NativePreferences::E_ERROR;
99 }106 }
107+ std::lock_guard<std::mutex> lock(preferencesMutex_);
100 return ptr->FlushSync();108 return ptr->FlushSync();
101}109}
102 110 
@@ -39,7 +39,6 @@ private:
39 39 
40private:40private:
41 std::mutex preferencesMutex_;41 std::mutex preferencesMutex_;
42- int errCode_ = NativePreferences::E_OK;
43 std::string path_;42 std::string path_;
44};43};
45} // namespace Sharing44} // namespace Sharing
@@ -34,9 +34,11 @@ public:
34 {34 {
35 MEDIA_LOGD("trace.");35 MEDIA_LOGD("trace.");
36 auto sink = sink_.lock();36 auto sink = sink_.lock();
37- if (sink != nullptr && frame) {37+ if (!sink || !frame || !frame->Data() || frame->Size() <= 0) {
38- sink->Write((uint8_t *)frame->Data(), frame->Size());38+ MEDIA_LOGE("sink or frame is null.");
39+ return;
39 }40 }
41+ sink->Write((uint8_t *)frame->Data(), static_cast<size_t>(frame->Size()));
40 }42 }
41 43 
42private:44private:
@@ -55,6 +55,7 @@ public:
55 void SetMediaController(std::shared_ptr<MediaController> mediaController)55 void SetMediaController(std::shared_ptr<MediaController> mediaController)
56 {56 {
57 SHARING_LOGD("trace.");57 SHARING_LOGD("trace.");
58+ std::lock_guard<std::mutex> lock(mediaControllerMutex_);
58 mediaController_ = mediaController;59 mediaController_ = mediaController;
59 }60 }
60 61 
@@ -81,6 +82,7 @@ private:
81 void StartVideoThread();82 void StartVideoThread();
82 void ProcessVideoData(const char *data, int32_t size, uint64_t pts);83 void ProcessVideoData(const char *data, int32_t size, uint64_t pts);
83 int32_t RenderInCopyMode(const DataBuffer::Ptr decodedData);84 int32_t RenderInCopyMode(const DataBuffer::Ptr decodedData);
85+ std::shared_ptr<MediaController> GetMediaController();
84 86 
85private:87private:
86 bool firstFrame_ = true;88 bool firstFrame_ = true;
@@ -98,6 +100,8 @@ private:
98 std::shared_ptr<VideoSinkDecoder> videoSinkDecoder_ = nullptr;100 std::shared_ptr<VideoSinkDecoder> videoSinkDecoder_ = nullptr;
99 101 
100 VideoTrack videoTrack_;102 VideoTrack videoTrack_;
103+ 
104+ std::mutex mediaControllerMutex_;
101};105};
102 106 
103} // namespace Sharing107} // namespace Sharing
@@ -260,12 +260,13 @@ void VideoPlayController::ProcessVideoData(const char *data, int32_t size, uint6
260 if (videoSinkDecoder_->inQueue_.empty()) {260 if (videoSinkDecoder_->inQueue_.empty()) {
261 while (isVideoRunning_) {261 while (isVideoRunning_) {
262 SHARING_LOGD("try wait, mediachannelId: %{public}u.", mediachannelId_);262 SHARING_LOGD("try wait, mediachannelId: %{public}u.", mediachannelId_);
263- videoSinkDecoder_->inCond_.wait_for(lock, std::chrono::milliseconds(DECODE_WAIT_MILLISECONDS),263+ videoSinkDecoder_->inCond_.wait_for(
264- [this]() { return (!videoSinkDecoder_->inQueue_.empty()); });264+ lock, std::chrono::milliseconds(DECODE_WAIT_MILLISECONDS),
265+ [this]() { return (!videoSinkDecoder_->inQueue_.empty() || !isVideoRunning_); });
265 266 
266- if (videoSinkDecoder_->inQueue_.empty()) {267+ if (videoSinkDecoder_->inQueue_.empty() && isVideoRunning_) {
267 WfdSinkHiSysEvent::GetInstance().ReportError(__func__, "", SinkStage::VIDEO_DECODE,268 WfdSinkHiSysEvent::GetInstance().ReportError(__func__, "", SinkStage::VIDEO_DECODE,
268- SinkErrorCode::WIFI_DISPLAY_VIDEO_DECODE_TIMEOUT);269+ SinkErrorCode::WIFI_DISPLAY_VIDEO_DECODE_TIMEOUT);
269 SHARING_LOGD("index queue empty, mediachannelId: %{public}u.", mediachannelId_);270 SHARING_LOGD("index queue empty, mediachannelId: %{public}u.", mediachannelId_);
270 continue;271 continue;
271 }272 }
@@ -300,7 +301,7 @@ void VideoPlayController::OnVideoDataDecoded(DataBuffer::Ptr decodedData)
300void VideoPlayController::OnError(int32_t errorCode)301void VideoPlayController::OnError(int32_t errorCode)
301{302{
302 SHARING_LOGW("trace mediachannelId: %{public}u.", mediachannelId_);303 SHARING_LOGW("trace mediachannelId: %{public}u.", mediachannelId_);
303- auto mediaController = mediaController_.lock();304+ auto mediaController = GetMediaController();
304 RETURN_IF_NULL(mediaController);305 RETURN_IF_NULL(mediaController);
305 306 
306 auto msg = std::make_shared<EventMsg>();307 auto msg = std::make_shared<EventMsg>();
@@ -392,7 +393,7 @@ int32_t VideoPlayController::RenderInCopyMode(DataBuffer::Ptr decodedData)
392void VideoPlayController::OnAccelerationDoneNotify()393void VideoPlayController::OnAccelerationDoneNotify()
393{394{
394 SHARING_LOGW("mediachannelId: %{public}u!", mediachannelId_);395 SHARING_LOGW("mediachannelId: %{public}u!", mediachannelId_);
395- auto mediaController = mediaController_.lock();396+ auto mediaController = GetMediaController();
396 RETURN_IF_NULL(mediaController);397 RETURN_IF_NULL(mediaController);
397 398 
398 auto msg = std::make_shared<EventMsg>();399 auto msg = std::make_shared<EventMsg>();
@@ -411,7 +412,7 @@ void VideoPlayController::OnAccelerationDoneNotify()
411void VideoPlayController::OnKeyModeNotify(bool enable)412void VideoPlayController::OnKeyModeNotify(bool enable)
412{413{
413 SHARING_LOGW("enable: %{public}d, mediachannelId: %{public}u!", enable, mediachannelId_);414 SHARING_LOGW("enable: %{public}d, mediachannelId: %{public}u!", enable, mediachannelId_);
414- auto mediaController = mediaController_.lock();415+ auto mediaController = GetMediaController();
415 RETURN_IF_NULL(mediaController);416 RETURN_IF_NULL(mediaController);
416 417 
417 auto msg = std::make_shared<EventMsg>();418 auto msg = std::make_shared<EventMsg>();
@@ -439,5 +440,10 @@ void VideoPlayController::SetVideoAudioSync(std::shared_ptr<VideoAudioSync> vide
439 }440 }
440}441}
441 442 
443+std::shared_ptr<MediaController> VideoPlayController::GetMediaController()
444+{
445+ std::lock_guard<std::mutex> lock(mediaControllerMutex_);
446+ return mediaController_.lock();
447+}
442} // namespace Sharing448} // namespace Sharing
443} // namespace OHOS449} // namespace OHOS
@@ -112,6 +112,7 @@ void RtpUnpackImpl::OnRtpSorted(uint16_t seq, const RtpPacket::Ptr &rtp)
112 112 
113void RtpUnpackImpl::OnRtpDecode(int32_t pt, const Frame::Ptr &frame)113void RtpUnpackImpl::OnRtpDecode(int32_t pt, const Frame::Ptr &frame)
114{114{
115+ RETURN_IF_NULL(frame);
115 if (onRtpUnpack_) {116 if (onRtpUnpack_) {
116 onRtpUnpack_(rtpSort_[pt]->GetSSRC(), frame);117 onRtpUnpack_(rtpSort_[pt]->GetSSRC(), frame);
117 }118 }