| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2014 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 |  | 
 | 18 | #ifndef ANDROID_AUDIO_POLICY_H | 
 | 19 | #define ANDROID_AUDIO_POLICY_H | 
 | 20 |  | 
 | 21 | #include <system/audio.h> | 
 | 22 | #include <system/audio_policy.h> | 
 | 23 | #include <binder/Parcel.h> | 
 | 24 | #include <utils/String8.h> | 
 | 25 | #include <utils/Vector.h> | 
 | 26 |  | 
 | 27 | namespace android { | 
 | 28 |  | 
 | 29 | // Keep in sync with AudioMix.java, AudioMixingRule.java, AudioPolicyConfig.java | 
 | 30 | #define RULE_EXCLUSION_MASK 0x8000 | 
| Jean-Michel Trivi | e8deced | 2016-02-11 12:50:39 -0800 | [diff] [blame] | 31 | #define RULE_MATCH_ATTRIBUTE_USAGE           0x1 | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 32 | #define RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET (0x1 << 1) | 
| Jean-Michel Trivi | e8deced | 2016-02-11 12:50:39 -0800 | [diff] [blame] | 33 | #define RULE_MATCH_UID                      (0x1 << 2) | 
 | 34 | #define RULE_EXCLUDE_ATTRIBUTE_USAGE  (RULE_EXCLUSION_MASK|RULE_MATCH_ATTRIBUTE_USAGE) | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 35 | #define RULE_EXCLUDE_ATTRIBUTE_CAPTURE_PRESET \ | 
| Jean-Michel Trivi | e8deced | 2016-02-11 12:50:39 -0800 | [diff] [blame] | 36 |                                       (RULE_EXCLUSION_MASK|RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET) | 
 | 37 | #define RULE_EXCLUDE_UID              (RULE_EXCLUSION_MASK|RULE_MATCH_UID) | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 38 |  | 
 | 39 | #define MIX_TYPE_INVALID -1 | 
 | 40 | #define MIX_TYPE_PLAYERS 0 | 
 | 41 | #define MIX_TYPE_RECORDERS 1 | 
 | 42 |  | 
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 43 | // definition of the different events that can be reported on a dynamic policy from | 
 | 44 | //   AudioSystem's implementation of the AudioPolicyClient interface | 
 | 45 | // keep in sync with AudioSystem.java | 
 | 46 | #define DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE 0 | 
 | 47 |  | 
| Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 48 | #define MIX_STATE_DISABLED -1 | 
 | 49 | #define MIX_STATE_IDLE 0 | 
 | 50 | #define MIX_STATE_MIXING 1 | 
 | 51 |  | 
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 52 | #define MIX_ROUTE_FLAG_RENDER 0x1 | 
 | 53 | #define MIX_ROUTE_FLAG_LOOP_BACK (0x1 << 1) | 
| Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 54 |  | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 55 | #define MAX_MIXES_PER_POLICY 10 | 
 | 56 | #define MAX_CRITERIA_PER_MIX 20 | 
 | 57 |  | 
| Jean-Michel Trivi | e8deced | 2016-02-11 12:50:39 -0800 | [diff] [blame] | 58 | class AudioMixMatchCriterion { | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 59 | public: | 
| Jean-Michel Trivi | e8deced | 2016-02-11 12:50:39 -0800 | [diff] [blame] | 60 |     AudioMixMatchCriterion() {} | 
 | 61 |     AudioMixMatchCriterion(audio_usage_t usage, audio_source_t source, uint32_t rule); | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 62 |  | 
 | 63 |     status_t readFromParcel(Parcel *parcel); | 
 | 64 |     status_t writeToParcel(Parcel *parcel) const; | 
 | 65 |  | 
 | 66 |     union { | 
 | 67 |         audio_usage_t   mUsage; | 
 | 68 |         audio_source_t  mSource; | 
| Jean-Michel Trivi | e8deced | 2016-02-11 12:50:39 -0800 | [diff] [blame] | 69 |         uid_t           mUid; | 
 | 70 |     } mValue; | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 71 |     uint32_t        mRule; | 
 | 72 | }; | 
 | 73 |  | 
 | 74 | class AudioMix { | 
 | 75 | public: | 
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 76 |     // flag on an AudioMix indicating the activity on this mix (IDLE, MIXING) | 
 | 77 |     //   must be reported through the AudioPolicyClient interface | 
 | 78 |     static const uint32_t kCbFlagNotifyActivity = 0x1; | 
 | 79 |  | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 80 |     AudioMix() {} | 
| Jean-Michel Trivi | e8deced | 2016-02-11 12:50:39 -0800 | [diff] [blame] | 81 |     AudioMix(Vector<AudioMixMatchCriterion> criteria, uint32_t mixType, audio_config_t format, | 
| Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 82 |              uint32_t routeFlags, String8 registrationId, uint32_t flags) : | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 83 |         mCriteria(criteria), mMixType(mixType), mFormat(format), | 
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 84 |         mRouteFlags(routeFlags), mRegistrationId(registrationId), mCbFlags(flags){} | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 85 |  | 
 | 86 |     status_t readFromParcel(Parcel *parcel); | 
 | 87 |     status_t writeToParcel(Parcel *parcel) const; | 
 | 88 |  | 
| Jean-Michel Trivi | e8deced | 2016-02-11 12:50:39 -0800 | [diff] [blame] | 89 |     Vector<AudioMixMatchCriterion> mCriteria; | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 90 |     uint32_t        mMixType; | 
 | 91 |     audio_config_t  mFormat; | 
 | 92 |     uint32_t        mRouteFlags; | 
 | 93 |     String8         mRegistrationId; | 
| Jean-Michel Trivi | f613d42 | 2015-04-23 18:41:29 -0700 | [diff] [blame] | 94 |     uint32_t        mCbFlags; // flags indicating which callbacks to use, see kCbFlag* | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 95 | }; | 
 | 96 |  | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 97 |  | 
 | 98 | // definitions for audio recording configuration updates | 
 | 99 | // which update type is reported | 
| Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame^] | 100 | #define RECORD_CONFIG_EVENT_NONE -1 | 
| Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 101 | #define RECORD_CONFIG_EVENT_START 1 | 
 | 102 | #define RECORD_CONFIG_EVENT_STOP  0 | 
 | 103 |  | 
| Eric Laurent | 275e8e9 | 2014-11-30 15:14:47 -0800 | [diff] [blame] | 104 | }; // namespace android | 
 | 105 |  | 
 | 106 | #endif  // ANDROID_AUDIO_POLICY_H |