• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2  **
3  ** Copyright 2012, The Android Open Source Project
4  **
5  ** Licensed under the Apache License, Version 2.0 (the "License");
6  ** you may not use this file except in compliance with the License.
7  ** You may obtain a copy of the License at
8  **
9  **     http://www.apache.org/licenses/LICENSE-2.0
10  **
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  */
17  
18  #ifndef ANDROID_AUDIO_HOTPLUG_THREAD_H
19  #define ANDROID_AUDIO_HOTPLUG_THREAD_H
20  
21  #include <utils/threads.h>
22  
23  namespace android {
24  
25  class AudioHotplugThread : public Thread {
26    public:
27      struct DeviceInfo {
28          unsigned int pcmCard;
29          unsigned int pcmDevice;
30          unsigned int minSampleBits, maxSampleBits;
31          unsigned int minChannelCount, maxChannelCount;
32          unsigned int minSampleRate, maxSampleRate;
33          bool valid;
34          bool forVoiceRecognition;
35      };
36  
37      class Callback {
38        public:
~Callback()39          virtual ~Callback() {}
40          virtual void onDeviceFound(const DeviceInfo& devInfo) = 0;
41          virtual void onDeviceRemoved(unsigned int pcmCard, unsigned int pcmDevice) = 0;
42      };
43  
44      AudioHotplugThread(Callback& callback);
45      virtual ~AudioHotplugThread();
46  
47      bool        start();
48      void        shutdown();
49  
50    private:
51      static const char* kThreadName;
52      static const char* kAlsaDeviceDir;
53      static const char  kDeviceTypeCapture;
54      static bool parseCaptureDeviceName(const char *name, unsigned int *pcmCard,
55                                         unsigned int *pcmDevice);
56      static bool getDeviceInfo(unsigned int pcmCard, unsigned int pcmDevice,
57                                DeviceInfo* info);
58  
59      virtual bool threadLoop();
60  
61      void scanForDevice();
62  
63      Callback& mCallback;
64      int mShutdownEventFD;
65  };
66  
67  }; // namespace android
68  
69  #endif  // ANDROID_AUDIO_HOTPLUG_THREAD_H
70