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 CHROME_BROWSER_EXTENSIONS_API_AUDIO_AUDIO_SERVICE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_AUDIO_AUDIO_SERVICE_H_ 7 8 #include "base/basictypes.h" 9 #include "base/callback.h" 10 #include "chrome/common/extensions/api/audio.h" 11 12 namespace extensions { 13 14 typedef std::vector<linked_ptr<api::audio::OutputDeviceInfo> > OutputInfo; 15 typedef std::vector<linked_ptr<api::audio::InputDeviceInfo> > InputInfo; 16 typedef std::vector<std::string> DeviceIdList; 17 18 class AudioService { 19 public: 20 class Observer { 21 public: 22 // Called when anything changes to the audio device configuration. 23 virtual void OnDeviceChanged() = 0; 24 25 protected: ~Observer()26 virtual ~Observer() {} 27 }; 28 29 // Callback type for completing to get audio device information. 30 typedef base::Callback<void(const OutputInfo&, const InputInfo&, bool)> 31 GetInfoCallback; 32 33 // Creates a platform-specific AudioService instance. 34 static AudioService* CreateInstance(); 35 ~AudioService()36 virtual ~AudioService() {} 37 38 // Called by listeners to this service to add/remove themselves as observers. 39 virtual void AddObserver(Observer* observer) = 0; 40 virtual void RemoveObserver(Observer* observer) = 0; 41 42 // Start to query audio device information. Should be called on UI thread. 43 // The |callback| will be invoked once the query is completed. 44 virtual void StartGetInfo(const GetInfoCallback& callback) = 0; 45 46 // Sets the active nodes to the nodes specified by |device_list|. 47 // It can pass in the "complete" active node list of either input 48 // nodes, or output nodes, or both. If only input nodes are passed in, 49 // it will only change the input nodes' active status, output nodes will NOT 50 // be changed; similarly for the case if only output nodes are passed. 51 // If the nodes specified in |new_active_ids| are already active, they will 52 // remain active. Otherwise, the old active nodes will be de-activated before 53 // we activate the new nodes with the same type(input/output). 54 virtual void SetActiveDevices(const DeviceIdList& device_list) = 0; 55 56 // Set the muted and volume/gain properties of a device. 57 virtual bool SetDeviceProperties(const std::string& device_id, 58 bool muted, 59 int volume, 60 int gain) = 0; 61 62 protected: AudioService()63 AudioService() {} 64 65 DISALLOW_COPY_AND_ASSIGN(AudioService); 66 }; 67 68 69 } // namespace extensions 70 71 #endif // CHROME_BROWSER_EXTENSIONS_API_AUDIO_AUDIO_SERVICE_H_ 72