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
27namespace android {
28
29// Keep in sync with AudioMix.java, AudioMixingRule.java, AudioPolicyConfig.java
30#define RULE_EXCLUSION_MASK 0x8000
31#define RULE_MATCH_ATTRIBUTE_USAGE 0x1
32#define RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET (0x1 << 1)
33#define RULE_EXCLUDE_ATTRIBUTE_USAGE (RULE_EXCLUSION_MASK|RULE_MATCH_ATTRIBUTE_USAGE)
34#define RULE_EXCLUDE_ATTRIBUTE_CAPTURE_PRESET \
35    (RULE_EXCLUSION_MASK|RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET)
36
37#define MIX_TYPE_INVALID -1
38#define MIX_TYPE_PLAYERS 0
39#define MIX_TYPE_RECORDERS 1
40
41// definition of the different events that can be reported on a dynamic policy from
42//   AudioSystem's implementation of the AudioPolicyClient interface
43// keep in sync with AudioSystem.java
44#define DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE 0
45
46#define MIX_STATE_DISABLED -1
47#define MIX_STATE_IDLE 0
48#define MIX_STATE_MIXING 1
49
50#define MIX_ROUTE_FLAG_RENDER 0x1
51#define MIX_ROUTE_FLAG_LOOP_BACK (0x1 << 1)
52
53#define MAX_MIXES_PER_POLICY 10
54#define MAX_CRITERIA_PER_MIX 20
55
56class AttributeMatchCriterion {
57public:
58    AttributeMatchCriterion() {}
59    AttributeMatchCriterion(audio_usage_t usage, audio_source_t source, uint32_t rule);
60
61    status_t readFromParcel(Parcel *parcel);
62    status_t writeToParcel(Parcel *parcel) const;
63
64    union {
65        audio_usage_t   mUsage;
66        audio_source_t  mSource;
67    } mAttr;
68    uint32_t        mRule;
69};
70
71class AudioMix {
72public:
73    // flag on an AudioMix indicating the activity on this mix (IDLE, MIXING)
74    //   must be reported through the AudioPolicyClient interface
75    static const uint32_t kCbFlagNotifyActivity = 0x1;
76
77    AudioMix() {}
78    AudioMix(Vector<AttributeMatchCriterion> criteria, uint32_t mixType, audio_config_t format,
79             uint32_t routeFlags, String8 registrationId, uint32_t flags) :
80        mCriteria(criteria), mMixType(mixType), mFormat(format),
81        mRouteFlags(routeFlags), mRegistrationId(registrationId), mCbFlags(flags){}
82
83    status_t readFromParcel(Parcel *parcel);
84    status_t writeToParcel(Parcel *parcel) const;
85
86    Vector<AttributeMatchCriterion> mCriteria;
87    uint32_t        mMixType;
88    audio_config_t  mFormat;
89    uint32_t        mRouteFlags;
90    String8         mRegistrationId;
91    uint32_t        mCbFlags; // flags indicating which callbacks to use, see kCbFlag*
92};
93
94}; // namespace android
95
96#endif  // ANDROID_AUDIO_POLICY_H
97