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