1 /*
2  * Copyright (C) 2015 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 #ifndef ANDROID_AUDIO_IO_DESCRIPTOR_H
18 #define ANDROID_AUDIO_IO_DESCRIPTOR_H
19 
20 namespace android {
21 
22 enum audio_io_config_event {
23     AUDIO_OUTPUT_REGISTERED,
24     AUDIO_OUTPUT_OPENED,
25     AUDIO_OUTPUT_CLOSED,
26     AUDIO_OUTPUT_CONFIG_CHANGED,
27     AUDIO_INPUT_REGISTERED,
28     AUDIO_INPUT_OPENED,
29     AUDIO_INPUT_CLOSED,
30     AUDIO_INPUT_CONFIG_CHANGED,
31 };
32 
33 // audio input/output descriptor used to cache output configurations in client process to avoid
34 // frequent calls through IAudioFlinger
35 class AudioIoDescriptor : public RefBase {
36 public:
AudioIoDescriptor()37     AudioIoDescriptor() :
38         mIoHandle(AUDIO_IO_HANDLE_NONE),
39         mSamplingRate(0), mFormat(AUDIO_FORMAT_DEFAULT), mChannelMask(AUDIO_CHANNEL_NONE),
40         mFrameCount(0), mFrameCountHAL(0), mLatency(0)
41     {
42         memset(&mPatch, 0, sizeof(struct audio_patch));
43     }
44 
~AudioIoDescriptor()45     virtual ~AudioIoDescriptor() {}
46 
getDeviceId()47     audio_port_handle_t getDeviceId() {
48         if (mPatch.num_sources != 0 && mPatch.num_sinks != 0) {
49             if (mPatch.sources[0].type == AUDIO_PORT_TYPE_MIX) {
50                 // this is an output mix
51                 // FIXME: the API only returns the first device in case of multiple device selection
52                 return mPatch.sinks[0].id;
53             } else {
54                 // this is an input mix
55                 return mPatch.sources[0].id;
56             }
57         }
58         return AUDIO_PORT_HANDLE_NONE;
59     }
60 
61     audio_io_handle_t       mIoHandle;
62     struct audio_patch      mPatch;
63     uint32_t                mSamplingRate;
64     audio_format_t          mFormat;
65     audio_channel_mask_t    mChannelMask;
66     size_t                  mFrameCount;
67     size_t                  mFrameCountHAL;
68     uint32_t                mLatency;   // only valid for output
69 };
70 
71 
72 };  // namespace android
73 
74 #endif  /*ANDROID_AUDIO_IO_DESCRIPTOR_H*/
75