Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / media / audio_device_factory.h
blobe3f263102da11c351bc038903be0d061b3f68800
1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_
6 #define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "content/common/content_export.h"
15 namespace media {
16 class AudioInputDevice;
17 class AudioOutputDevice;
20 namespace url {
21 class Origin;
24 namespace content {
26 // A factory for creating AudioOutputDevices and AudioInputDevices. There is a
27 // global factory function that can be installed for the purposes of testing to
28 // provide specialized implementations.
29 class CONTENT_EXPORT AudioDeviceFactory {
30 public:
31 // Creates an AudioOutputDevice.
32 // |render_frame_id| refers to the RenderFrame containing the entity
33 // producing the audio. If |session_id| is nonzero, it is used by the browser
34 // to select the correct input device ID and its associated output device, if
35 // it exists. If |session_id| is zero, |device_id| and |security_origin|
36 // identify the output device to use.
37 // If |session_id| is zero and |device_id| and |security_origin| are empty,
38 // the default output device will be selected.
39 static scoped_refptr<media::AudioOutputDevice> NewOutputDevice(
40 int render_frame_id,
41 int session_id,
42 const std::string& device_id,
43 const url::Origin& security_origin);
45 // Creates an AudioInputDevice using the currently registered factory.
46 // |render_frame_id| refers to the RenderFrame containing the entity
47 // consuming the audio.
48 static scoped_refptr<media::AudioInputDevice> NewInputDevice(
49 int render_frame_id);
51 protected:
52 AudioDeviceFactory();
53 virtual ~AudioDeviceFactory();
55 // You can derive from this class and specify an implementation for these
56 // functions to provide alternate audio device implementations.
57 // If the return value of either of these function is NULL, we fall back
58 // on the default implementation.
59 virtual media::AudioOutputDevice* CreateOutputDevice(
60 int render_frame_id,
61 int sesssion_id,
62 const std::string& device_id,
63 const url::Origin& security_origin) = 0;
64 virtual media::AudioInputDevice* CreateInputDevice(int render_frame_id) = 0;
66 private:
67 // The current globally registered factory. This is NULL when we should
68 // create the default AudioRendererSinks.
69 static AudioDeviceFactory* factory_;
71 DISALLOW_COPY_AND_ASSIGN(AudioDeviceFactory);
74 } // namespace content
76 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_