• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "recorder_profiles_server.h"
17 #include "media_log.h"
18 #include "media_errors.h"
19 #include "engine_factory_repo.h"
20 #include "recorder_profiles_ability_singleton.h"
21 
22 namespace {
23     constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_RECORDER, "RecorderProfilesServer"};
24 }
25 
26 namespace OHOS {
27 namespace Media {
Create()28 std::shared_ptr<IRecorderProfilesService> RecorderProfilesServer::Create()
29 {
30     std::shared_ptr<RecorderProfilesServer> server = std::make_shared<RecorderProfilesServer>();
31     return server;
32 }
33 
RecorderProfilesServer()34 RecorderProfilesServer::RecorderProfilesServer()
35 {
36     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
37 }
38 
~RecorderProfilesServer()39 RecorderProfilesServer::~RecorderProfilesServer()
40 {
41     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
42 }
43 
IsAudioRecorderConfigSupported(const RecorderProfilesData & profile)44 bool RecorderProfilesServer::IsAudioRecorderConfigSupported(const RecorderProfilesData &profile)
45 {
46     std::lock_guard<std::mutex> lock(mutex_);
47     bool ret = false;
48     std::vector<RecorderProfilesData> capabilityDataArray = GetCapabilityInfos();
49     for (auto iter = capabilityDataArray.begin(); iter != capabilityDataArray.end(); ++iter) {
50         RecorderProfilesData compareProfileData = (*iter);
51         if (compareProfileData.mediaProfileType == RECORDER_TYPE_PROFILE) {
52             if (CompareProfile(compareProfileData, profile)) {
53                 ret = true;
54                 break;
55             }
56         }
57     }
58     return ret;
59 }
60 
HasVideoRecorderProfile(int32_t sourceId,int32_t qualityLevel)61 bool RecorderProfilesServer::HasVideoRecorderProfile(int32_t sourceId, int32_t qualityLevel)
62 {
63     std::lock_guard<std::mutex> lock(mutex_);
64     bool ret = false;
65     std::vector<RecorderProfilesData> capabilityDataArray = GetCapabilityInfos();
66     for (auto iter = capabilityDataArray.begin(); iter != capabilityDataArray.end(); ++iter) {
67         if (iter->mediaProfileType == RECORDER_TYPE_PROFILE) {
68             if ((sourceId == iter->sourceId) && (qualityLevel == iter->recorderProfile.qualityLevel)) {
69                 ret = true;
70                 break;
71             }
72         }
73     }
74     return ret;
75 }
76 
GetVideoRecorderProfileInfo(int32_t sourceId,int32_t qualityLevel)77 RecorderProfilesData RecorderProfilesServer::GetVideoRecorderProfileInfo(int32_t sourceId, int32_t qualityLevel)
78 {
79     std::lock_guard<std::mutex> lock(mutex_);
80     RecorderProfilesData capabilityData;
81     std::vector<RecorderProfilesData> capabilityDataArray = GetCapabilityInfos();
82     for (auto iter = capabilityDataArray.begin(); iter != capabilityDataArray.end(); ++iter) {
83         if (iter->mediaProfileType == RECORDER_TYPE_PROFILE) {
84             if ((sourceId == iter->sourceId) && (qualityLevel == iter->recorderProfile.qualityLevel)) {
85                 capabilityData = (*iter);
86                 break;
87             }
88         }
89     }
90     return capabilityData;
91 }
92 
GetAudioRecorderCapsInfo()93 std::vector<RecorderProfilesData> RecorderProfilesServer::GetAudioRecorderCapsInfo()
94 {
95     std::lock_guard<std::mutex> lock(mutex_);
96     std::vector<RecorderProfilesData> capabilityDataArray = GetCapabilityInfos();
97     for (auto iter = capabilityDataArray.begin(); iter != capabilityDataArray.end();) {
98         if (iter->mediaProfileType == RECORDER_TYPE_AUDIO_CAPS) {
99             ++iter;
100         } else {
101             iter = capabilityDataArray.erase(iter);
102         }
103     }
104     return capabilityDataArray;
105 }
106 
GetVideoRecorderCapsInfo()107 std::vector<RecorderProfilesData> RecorderProfilesServer::GetVideoRecorderCapsInfo()
108 {
109     std::lock_guard<std::mutex> lock(mutex_);
110     std::vector<RecorderProfilesData> capabilityDataArray = GetCapabilityInfos();
111     for (auto iter = capabilityDataArray.begin(); iter != capabilityDataArray.end();) {
112         if (iter->mediaProfileType == RECORDER_TYPE_VIDEO_CAPS) {
113             ++iter;
114         } else {
115             iter = capabilityDataArray.erase(iter);
116         }
117     }
118     return capabilityDataArray;
119 }
120 
GetCapabilityInfos()121 std::vector<RecorderProfilesData> RecorderProfilesServer::GetCapabilityInfos()
122 {
123     RecorderProfilesAbilitySingleton& mediaProfileAbilityInstance = RecorderProfilesAbilitySingleton::GetInstance();
124     return mediaProfileAbilityInstance.GetCapabilityDataArray();
125 }
126 
CompareProfile(const RecorderProfilesData & compareProfile,const RecorderProfilesData & profile)127 bool RecorderProfilesServer::CompareProfile(
128     const RecorderProfilesData &compareProfile, const RecorderProfilesData &profile)
129 {
130     bool ret = false;
131     if ((profile.recorderProfile.containerFormatType == compareProfile.recorderProfile.containerFormatType) &&
132         (profile.recorderProfile.audioCodec == compareProfile.recorderProfile.audioCodec) &&
133         (profile.recorderProfile.audioBitrate == compareProfile.recorderProfile.audioBitrate) &&
134         (profile.recorderProfile.audioSampleRate == compareProfile.recorderProfile.audioSampleRate) &&
135         (profile.recorderProfile.audioChannels == compareProfile.recorderProfile.audioChannels)) {
136         ret = true;
137     }
138     return ret;
139 }
140 }  // namespace Media
141 }  // namespace OHOS
142