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