1 /*
2  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_FACTORY_H_
12 #define MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_FACTORY_H_
13 
14 #include <memory>
15 
16 #include "api/task_queue/task_queue_factory.h"
17 #include "modules/audio_device/include/audio_device.h"
18 
19 namespace webrtc {
20 
21 // Creates an AudioDeviceModule (ADM) for Windows based on the Core Audio API.
22 // The creating thread must be a COM thread; otherwise nullptr will be returned.
23 // By default |automatic_restart| is set to true and it results in support for
24 // automatic restart of audio if e.g. the existing device is removed. If set to
25 // false, no attempt to restart audio is performed under these conditions.
26 //
27 // Example (assuming webrtc namespace):
28 //
29 //  public:
30 //   rtc::scoped_refptr<AudioDeviceModule> CreateAudioDevice() {
31 //     task_queue_factory_ = CreateDefaultTaskQueueFactory();
32 //     // Tell COM that this thread shall live in the MTA.
33 //     com_initializer_ = std::make_unique<webrtc_win::ScopedCOMInitializer>(
34 //         webrtc_win::ScopedCOMInitializer::kMTA);
35 //     if (!com_initializer_->Succeeded()) {
36 //       return nullptr;
37 //     }
38 //     // Create the ADM with support for automatic restart if devices are
39 //     // unplugged.
40 //     return CreateWindowsCoreAudioAudioDeviceModule(
41 //         task_queue_factory_.get());
42 //   }
43 //
44 //   private:
45 //    std::unique_ptr<webrtc_win::ScopedCOMInitializer> com_initializer_;
46 //    std::unique_ptr<TaskQueueFactory> task_queue_factory_;
47 //
48 rtc::scoped_refptr<AudioDeviceModule> CreateWindowsCoreAudioAudioDeviceModule(
49     TaskQueueFactory* task_queue_factory,
50     bool automatic_restart = true);
51 
52 rtc::scoped_refptr<AudioDeviceModuleForTest>
53 CreateWindowsCoreAudioAudioDeviceModuleForTest(
54     TaskQueueFactory* task_queue_factory,
55     bool automatic_restart = true);
56 
57 }  // namespace webrtc
58 
59 #endif  //  MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_FACTORY_H_
60