Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: content/browser/renderer_host/media/audio_input_device_manager.h

Issue 12440027: Do not pass the string device_id via IPC message to create an audio input stream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changed the pepper code to use OpenDevice() for default device, and fixed a minor mistake in MediaS… Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // AudioInputDeviceManager manages the audio input devices. In particular it 5 // AudioInputDeviceManager manages the audio input devices. In particular it
6 // communicates with MediaStreamManager and AudioInputRendererHost on the 6 // communicates with MediaStreamManager and AudioInputRendererHost on the
7 // browser IO thread, handles queries like enumerate/open/close from 7 // browser IO thread, handles queries like
8 // MediaStreamManager and start/stop from AudioInputRendererHost. 8 // enumerate/open/close/GetOpenedDeviceInfoById from MediaStreamManager and
9 // GetOpenedDeviceInfoById from AudioInputRendererHost.
9 // The work for enumerate/open/close is handled asynchronously on Media Stream 10 // The work for enumerate/open/close is handled asynchronously on Media Stream
10 // device thread, while start/stop are synchronous on the IO thread. 11 // device thread, while GetOpenedDeviceInfoById is synchronous on the IO thread.
11 12
12 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ 13 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_
13 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ 14 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_
14 15
15 #include <map> 16 #include <map>
16 17
17 #include "base/basictypes.h" 18 #include "base/basictypes.h"
18 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
19 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
20 #include "content/browser/renderer_host/media/media_stream_provider.h" 21 #include "content/browser/renderer_host/media/media_stream_provider.h"
21 #include "content/common/content_export.h" 22 #include "content/common/content_export.h"
22 #include "content/common/media/media_stream_options.h" 23 #include "content/common/media/media_stream_options.h"
23 #include "content/public/common/media_stream_request.h" 24 #include "content/public/common/media_stream_request.h"
24 25
25 namespace media { 26 namespace media {
26 class AudioManager; 27 class AudioManager;
27 } 28 }
28 29
29 namespace content { 30 namespace content {
30 31
31 class AudioInputDeviceManagerEventHandler;
32
33 class CONTENT_EXPORT AudioInputDeviceManager : public MediaStreamProvider { 32 class CONTENT_EXPORT AudioInputDeviceManager : public MediaStreamProvider {
34 public: 33 public:
35 // Calling Start() with this kFakeOpenSessionId will open the default device, 34 // Calling Start() with this kFakeOpenSessionId will open the default device,
36 // even though Open() has not been called. This is used to be able to use the 35 // even though Open() has not been called. This is used to be able to use the
37 // AudioInputDeviceManager before MediaStream is implemented. 36 // AudioInputDeviceManager before MediaStream is implemented.
38 static const int kFakeOpenSessionId; 37 static const int kFakeOpenSessionId;
39 38
40 explicit AudioInputDeviceManager(media::AudioManager* audio_manager); 39 explicit AudioInputDeviceManager(media::AudioManager* audio_manager);
41 40
41 // Gets the opened device info by |session_id|. If the device is not
42 // opened, it will return an empty object, called on IO thread.
43 StreamDeviceInfo GetOpenedDeviceInfoById(int session_id);
miu 2013/03/18 23:19:05 nit: Consider returning a bool and having the call
no longer working on chromium 2013/03/19 14:06:49 Then I think it might be clearer to return a const
44
42 // MediaStreamProvider implementation, called on IO thread. 45 // MediaStreamProvider implementation, called on IO thread.
43 virtual void Register(MediaStreamProviderListener* listener, 46 virtual void Register(MediaStreamProviderListener* listener,
44 base::MessageLoopProxy* device_thread_loop) OVERRIDE; 47 base::MessageLoopProxy* device_thread_loop) OVERRIDE;
45 virtual void Unregister() OVERRIDE; 48 virtual void Unregister() OVERRIDE;
46 virtual void EnumerateDevices(MediaStreamType stream_type) OVERRIDE; 49 virtual void EnumerateDevices(MediaStreamType stream_type) OVERRIDE;
47 virtual int Open(const StreamDeviceInfo& device) OVERRIDE; 50 virtual int Open(const StreamDeviceInfo& device) OVERRIDE;
48 virtual void Close(int session_id) OVERRIDE; 51 virtual void Close(int session_id) OVERRIDE;
49 52
50 // Functions used by AudioInputRenderHost, called on IO thread.
51 // Starts the device referenced by the session id.
52 void Start(int session_id, AudioInputDeviceManagerEventHandler* handler);
53 // Stops the device referenced by the session id.
54 void Stop(int session_id);
55
56 void UseFakeDevice(); 53 void UseFakeDevice();
57 bool ShouldUseFakeDevice() const; 54 bool ShouldUseFakeDevice() const;
58 55
59 private: 56 private:
60 typedef std::map<int, AudioInputDeviceManagerEventHandler*> EventHandlerMap; 57 typedef std::vector<StreamDeviceInfo> StreamDeviceList;
61 typedef std::map<int, StreamDeviceInfo> StreamDeviceMap;
62 virtual ~AudioInputDeviceManager(); 58 virtual ~AudioInputDeviceManager();
63 59
64 // Enumerates audio input devices on media stream device thread. 60 // Enumerates audio input devices on media stream device thread.
65 void EnumerateOnDeviceThread(MediaStreamType stream_type); 61 void EnumerateOnDeviceThread(MediaStreamType stream_type);
66 // Opens the device on media stream device thread. 62 // Opens the device on media stream device thread.
67 void OpenOnDeviceThread(int session_id, const StreamDeviceInfo& device); 63 void OpenOnDeviceThread(int session_id, const StreamDeviceInfo& info);
68 // Closes the deivce on the media stream device thread.
69 void CloseOnDeviceThread(int session_id);
70 64
71 // Callback used by EnumerateOnDeviceThread(), called with a list of 65 // Callback used by EnumerateOnDeviceThread(), called with a list of
72 // enumerated devices on IO thread. 66 // enumerated devices on IO thread.
73 void DevicesEnumeratedOnIOThread(MediaStreamType stream_type, 67 void DevicesEnumeratedOnIOThread(MediaStreamType stream_type,
74 scoped_ptr<StreamDeviceInfoArray> devices); 68 scoped_ptr<StreamDeviceInfoArray> devices);
75 // Callback used by OpenOnDeviceThread(), called with the session_id 69 // Callback used by OpenOnDeviceThread(), called with the session_id
76 // referencing the opened device on IO thread. 70 // referencing the opened device on IO thread.
77 void OpenedOnIOThread(MediaStreamType type, int session_id); 71 void OpenedOnIOThread(int session_id, const StreamDeviceInfo& info);
78 // Callback used by CloseOnDeviceThread(), called with the session_id 72 // Callback used by CloseOnDeviceThread(), called with the session_id
79 // referencing the closed device on IO thread. 73 // referencing the closed device on IO thread.
80 void ClosedOnIOThread(MediaStreamType type, int session_id); 74 void ClosedOnIOThread(MediaStreamType type, int session_id);
81 75
82 // Verifies that the calling thread is media stream device thread. 76 // Verifies that the calling thread is media stream device thread.
83 bool IsOnDeviceThread() const; 77 bool IsOnDeviceThread() const;
84 78
79 // Helper to return iterator to the device referenced by |session_id|. If no
80 // device is found, it will return devices_.end().
81 StreamDeviceList::iterator GetDevice(int session_id);
miu 2013/03/18 23:19:05 Suggest you return a StreamDeviceInfo* instead of
no longer working on chromium 2013/03/19 14:06:49 This iterator returned by GetDevice() is used by C
82
85 // Only accessed on Browser::IO thread. 83 // Only accessed on Browser::IO thread.
86 MediaStreamProviderListener* listener_; 84 MediaStreamProviderListener* listener_;
87 int next_capture_session_id_; 85 int next_capture_session_id_;
88 EventHandlerMap event_handlers_;
89 bool use_fake_device_; 86 bool use_fake_device_;
87 StreamDeviceList devices_;
90 88
91 // Only accessed from media stream device thread. 89 media::AudioManager* const audio_manager_; // Weak.
92 StreamDeviceMap devices_;
93 media::AudioManager* const audio_manager_;
94 90
95 // The message loop of media stream device thread that this object runs on. 91 // The message loop of media stream device thread that this object runs on.
96 scoped_refptr<base::MessageLoopProxy> device_loop_; 92 scoped_refptr<base::MessageLoopProxy> device_loop_;
97 93
98 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager); 94 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager);
99 }; 95 };
100 96
101 } // namespace content 97 } // namespace content
102 98
103 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ 99 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698