Home | History | Annotate | Download | only in audio
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROMEOS_AUDIO_AUDIO_DEVICE_H_
      6 #define CHROMEOS_AUDIO_AUDIO_DEVICE_H_
      7 
      8 #include <map>
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/basictypes.h"
     13 #include "chromeos/chromeos_export.h"
     14 #include "chromeos/dbus/audio_node.h"
     15 
     16 namespace chromeos {
     17 
     18 // Ordered from the highest priority to the lowest.
     19 enum AudioDeviceType {
     20   AUDIO_TYPE_HEADPHONE,
     21   AUDIO_TYPE_MIC,
     22   AUDIO_TYPE_USB,
     23   AUDIO_TYPE_BLUETOOTH,
     24   AUDIO_TYPE_HDMI,
     25   AUDIO_TYPE_INTERNAL_SPEAKER,
     26   AUDIO_TYPE_INTERNAL_MIC,
     27   AUDIO_TYPE_KEYBOARD_MIC,
     28   AUDIO_TYPE_OTHER,
     29 };
     30 
     31 struct CHROMEOS_EXPORT AudioDevice {
     32   AudioDevice();
     33   explicit AudioDevice(const AudioNode& node);
     34   std::string ToString() const;
     35 
     36   // Converts between the string type sent via D-Bus and AudioDeviceType.
     37   // Static so they can be used by tests.
     38   static std::string GetTypeString(chromeos::AudioDeviceType type);
     39   static chromeos::AudioDeviceType GetAudioType(const std::string& node_type);
     40 
     41   bool is_input;
     42   uint64 id;
     43   std::string display_name;
     44   std::string device_name;
     45   AudioDeviceType type;
     46   uint8 priority;
     47   bool active;
     48   uint64 plugged_time;
     49 };
     50 
     51 typedef std::vector<AudioDevice> AudioDeviceList;
     52 typedef std::map<uint64, AudioDevice> AudioDeviceMap;
     53 
     54 struct AudioDeviceCompare {
     55   // Rules used to discern which device is higher,
     56   // 1.) Device Type:
     57   //       [Headphones/USB/Bluetooh > HDMI > Internal Speakers]
     58   //       [External Mic/USB Mic/Bluetooth > Internal Mic]
     59   // 2.) Device Plugged in Time:
     60   //       [Later > Earlier]
     61   bool operator()(const chromeos::AudioDevice& a,
     62                   const chromeos::AudioDevice& b) const {
     63     if (a.priority < b.priority) {
     64       return true;
     65     } else if (b.priority < a.priority) {
     66       return false;
     67     } else if (a.plugged_time < b.plugged_time) {
     68       return true;
     69     } else {
     70       return false;
     71     }
     72   }
     73 };
     74 
     75 }  // namespace chromeos
     76 
     77 #endif  // CHROMEOS_AUDIO_AUDIO_DEVICE_H_
     78