• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "chre_api/chre/audio.h"
18 
19 #include "chre/core/event_loop_manager.h"
20 #include "chre/util/macros.h"
21 #include "chre/util/system/napp_permissions.h"
22 
23 #ifdef CHRE_AUDIO_SUPPORT_ENABLED
24 #include "chre/platform/platform_audio.h"
25 #endif  // CHRE_AUDIO_SUPPORT_ENABLED
26 
27 using chre::EventLoopManager;
28 using chre::EventLoopManagerSingleton;
29 using chre::Nanoapp;
30 using chre::NanoappPermissions;
31 
chreAudioGetSource(uint32_t handle,struct chreAudioSource * audioSource)32 DLL_EXPORT bool chreAudioGetSource(uint32_t handle,
33                                    struct chreAudioSource *audioSource) {
34 #ifdef CHRE_AUDIO_SUPPORT_ENABLED
35   bool success = false;
36   if (audioSource != nullptr) {
37     success = EventLoopManagerSingleton::get()
38                   ->getAudioRequestManager()
39                   .getAudioSource(handle, audioSource);
40   }
41 
42   return success;
43 #else
44   UNUSED_VAR(handle);
45   UNUSED_VAR(audioSource);
46   return false;
47 #endif  // CHRE_AUDIO_SUPPORT_ENABLED
48 }
49 
chreAudioConfigureSource(uint32_t handle,bool enable,uint64_t bufferDuration,uint64_t deliveryInterval)50 DLL_EXPORT bool chreAudioConfigureSource(uint32_t handle, bool enable,
51                                          uint64_t bufferDuration,
52                                          uint64_t deliveryInterval) {
53 #ifdef CHRE_AUDIO_SUPPORT_ENABLED
54   Nanoapp *nanoapp = EventLoopManager::validateChreApiCall(__func__);
55   return nanoapp->permitPermissionUse(NanoappPermissions::CHRE_PERMS_AUDIO) &&
56          EventLoopManagerSingleton::get()
57              ->getAudioRequestManager()
58              .configureSource(nanoapp, handle, enable, bufferDuration,
59                               deliveryInterval);
60 #else
61   UNUSED_VAR(handle);
62   UNUSED_VAR(enable);
63   UNUSED_VAR(bufferDuration);
64   UNUSED_VAR(deliveryInterval);
65   return false;
66 #endif  // CHRE_AUDIO_SUPPORT_ENABLED
67 }
68