• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "audio_stream_manager.h"
17 #include "define_multimodal.h"
18 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
19 #include "dfx_hisysevent.h"
20 #endif // OHOS_BUILD_ENABLE_DFX_RADAR
21 #include "error_multimodal.h"
22 #include "input_screen_capture_monitor_listener.h"
23 
24 #undef MMI_LOG_TAG
25 #define MMI_LOG_TAG "InputScreenCapture"
26 
27 namespace OHOS {
28 namespace MMI {
29 #if defined(OHOS_BUILD_ENABLE_MONITOR) && defined(PLAYER_FRAMEWORK_EXISTS)
30 namespace {
31 sptr<InputScreenCaptureMonitorListener> g_screenCaptureMonitorListener { nullptr };
32 }
33 
IsScreenCaptureWorking(int32_t capturePid)34 extern "C" int32_t IsScreenCaptureWorking(int32_t capturePid)
35 {
36     std::list<int32_t> pidList = Media::ScreenCaptureMonitor::GetInstance()->IsScreenCaptureWorking();
37     auto iter = std::find(pidList.begin(), pidList.end(), capturePid);
38     if (iter != pidList.end()) {
39         return true;
40     }
41     return false;
42 }
43 
RegisterListener(ScreenCaptureCallback callback)44 extern "C" void RegisterListener(ScreenCaptureCallback callback)
45 {
46     if (g_screenCaptureMonitorListener == nullptr) {
47         g_screenCaptureMonitorListener = new (std::nothrow) InputScreenCaptureMonitorListener();
48         CHKPV(g_screenCaptureMonitorListener);
49     }
50     g_screenCaptureMonitorListener->SetScreenCaptureCallback(callback);
51     Media::ScreenCaptureMonitor::GetInstance()->RegisterScreenCaptureMonitorListener(g_screenCaptureMonitorListener);
52 }
53 
IsMusicActivate()54 extern "C" bool IsMusicActivate()
55 {
56     CALL_INFO_TRACE;
57     std::vector<std::shared_ptr<AudioStandard::AudioRendererChangeInfo>> rendererChangeInfo;
58 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
59     auto begin = std::chrono::high_resolution_clock::now();
60 #endif // OHOS_BUILD_ENABLE_DFX_RADAR
61     auto ret = AudioStandard::AudioStreamManager::GetInstance()->GetCurrentRendererChangeInfos(rendererChangeInfo);
62 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
63     auto durationMS = std::chrono::duration_cast<std::chrono::milliseconds>(
64         std::chrono::high_resolution_clock::now() - begin).count();
65     DfxHisysevent::ReportApiCallTimes(ApiDurationStatistics::Api::GET_CUR_RENDERER_CHANGE_INFOS, durationMS);
66 #endif // OHOS_BUILD_ENABLE_DFX_RADAR
67     if (ret != ERR_OK) {
68         MMI_HILOGE("Check music activate failed, errnoCode is %{public}d", ret);
69         return false;
70     }
71     if (rendererChangeInfo.empty()) {
72         MMI_HILOGI("Music info empty");
73         return false;
74     }
75     for (const auto &info : rendererChangeInfo) {
76         if (info->rendererState == AudioStandard::RENDERER_RUNNING &&
77             (info->rendererInfo.streamUsage != AudioStandard::STREAM_USAGE_ULTRASONIC ||
78             info->rendererInfo.streamUsage != AudioStandard::STREAM_USAGE_INVALID)) {
79             MMI_HILOGI("Find music activate");
80             return true;
81         }
82     }
83     return false;
84 }
85 #endif
86 }
87 }