• 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 #ifndef DAUDIO_SCRENE_INTERNAL_H
17 #define DAUDIO_SCRENE_INTERNAL_H
18 
19 #include "audio_types.h"
20 
21 #include "daudio_errorcode.h"
22 
23 #undef DH_LOG_TAG
24 #define DH_LOG_TAG "AudioSceneInternal"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
28 using namespace OHOS::HDI::DistributedAudio::Audio::V1_0;
29 
30 template<typename T>
31 class AudioSceneInternal final {
32 public:
33     static int32_t CheckSceneCapability(AudioHandle handle, const struct ::AudioSceneDescriptor *scene,
34         bool *supported);
35     static int32_t SelectScene(AudioHandle handle, const struct ::AudioSceneDescriptor *scene);
36 };
37 
38 template<typename T>
SelectScene(AudioHandle handle,const struct::AudioSceneDescriptor * scene)39 int32_t AudioSceneInternal<T>::SelectScene(AudioHandle handle, const struct ::AudioSceneDescriptor *scene)
40 {
41     if (handle == nullptr || scene == nullptr) {
42         DHLOGE("The parameter is empty.");
43         return ERR_DH_AUDIO_HDI_INVALID_PARAM;
44     }
45 
46     T *context = reinterpret_cast<T *>(handle);
47     AudioSceneDescriptor sceneHAL = {
48         .scene.id = scene->scene.id,
49         .desc.portId = scene->desc.portId,
50         .desc.pins = static_cast<AudioPortPin>(scene->desc.pins),
51     };
52     if (scene->desc.desc == nullptr) {
53         sceneHAL.desc.desc = "";
54     } else {
55         sceneHAL.desc.desc = scene->desc.desc;
56     }
57     return (context == nullptr || context->proxy_ == nullptr) ?
58         ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->SelectScene(sceneHAL);
59 }
60 
61 template<typename T>
CheckSceneCapability(AudioHandle handle,const struct::AudioSceneDescriptor * scene,bool * supported)62 int32_t AudioSceneInternal<T>::CheckSceneCapability(AudioHandle handle, const struct ::AudioSceneDescriptor *scene,
63     bool *supported)
64 {
65     if (handle == nullptr || scene == nullptr || supported == nullptr) {
66         DHLOGE("The parameter is empty.");
67         return ERR_DH_AUDIO_HDI_INVALID_PARAM;
68     }
69 
70     T *context = reinterpret_cast<T *>(handle);
71     AudioSceneDescriptor sceneHAL = {
72         .scene.id = scene->scene.id,
73         .desc.portId = scene->desc.portId,
74         .desc.pins = static_cast<AudioPortPin>(scene->desc.pins),
75     };
76 
77     if (scene->desc.desc == nullptr) {
78         sceneHAL.desc.desc = "";
79     } else {
80         sceneHAL.desc.desc = scene->desc.desc;
81     }
82 
83     return (context == nullptr || context->proxy_ == nullptr) ?
84         ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->CheckSceneCapability(sceneHAL, *supported);
85 }
86 } // namespace DistributedHardware
87 } // namespace OHOS
88 #endif // DAUDIO_SCRENE_INTERNAL_H
89