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

Unified Diff: content/browser/renderer_host/media/media_stream_manager.h

Issue 10662049: Move the device enumerate/open/close work to device thread from IO thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: small changes to fix the trybots' failure Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/media_stream_manager.h
diff --git a/content/browser/renderer_host/media/media_stream_manager.h b/content/browser/renderer_host/media/media_stream_manager.h
index 17f863e90fda9b5140ee47983298bb4f17ac1026..3082ac0f76fd6ec5434b6a81657bcb4ba6849261 100644
--- a/content/browser/renderer_host/media/media_stream_manager.h
+++ b/content/browser/renderer_host/media/media_stream_manager.h
@@ -29,19 +29,15 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/ref_counted.h"
-#include "base/supports_user_data.h"
+#include "base/threading/thread.h"
+#include "base/win/scoped_com_initializer.h"
#include "content/browser/renderer_host/media/media_stream_provider.h"
#include "content/browser/renderer_host/media/media_stream_settings_requester.h"
#include "content/common/media/media_stream_options.h"
#include "content/common/content_export.h"
+#include "content/public/browser/browser_thread.h"
-namespace content {
-class ResourceContext;
-}
-
-namespace media {
-class AudioManager;
-}
+using base::win::ScopedCOMInitializer;
namespace media_stream {
@@ -50,22 +46,31 @@ class MediaStreamDeviceSettings;
class MediaStreamRequester;
class VideoCaptureManager;
+// Thread that enters MTA on windows, and is base::Thread on linux and mac.
+class DeviceThread : public base::Thread {
+ public:
+ explicit DeviceThread(const char* name)
+ : base::Thread(name),
+ com_init_(ScopedCOMInitializer::kMTA) {}
+
+ private:
+ ScopedCOMInitializer com_init_;
+ DISALLOW_COPY_AND_ASSIGN(DeviceThread);
+};
+
// MediaStreamManager is used to generate and close new media devices, not to
// start the media flow.
// The classes requesting new media streams are answered using
// MediaStreamManager::Listener.
class CONTENT_EXPORT MediaStreamManager
: public MediaStreamProviderListener,
- public SettingsRequester,
- public base::SupportsUserData::Data {
+ public SettingsRequester {
public:
- // Returns the MediaStreamManager for the given ResourceContext. If it hasn't
- // been created yet, it will be constructed with the given AudioManager.
- static MediaStreamManager* GetForResourceContext(
- content::ResourceContext* resource_context,
- media::AudioManager* audio_manager);
+ // This class takes the ownerships of the |audio_input_device_manager|
+ // and |video_capture_manager|.
+ MediaStreamManager(AudioInputDeviceManager* audio_input_device_manager,
+ VideoCaptureManager* video_capture_manager);
- explicit MediaStreamManager(media::AudioManager* audio_manager);
virtual ~MediaStreamManager();
// Used to access VideoCaptureManager.
@@ -130,6 +135,8 @@ class CONTENT_EXPORT MediaStreamManager
// Used by unit test to make sure fake devices are used instead of a real
// devices, which is needed for server based testing.
+ // TODO(xians): Remove this hack since we can create our own
+ // MediaStreamManager in our unit tests.
void UseFakeDevice();
private:
@@ -149,9 +156,16 @@ class CONTENT_EXPORT MediaStreamManager
void StartEnumeration(DeviceRequest* new_request,
std::string* label);
+ // Helper to ensure the device thread and pass the message loop to device
+ // managers, it also register itself as the listener to the device managers.
+ void EnsureDeviceThreadAndListener();
+
+ // Device thread shared by VideoCaptureManager and AudioInputDeviceManager.
+ scoped_ptr<base::Thread> device_thread_;
+
scoped_ptr<MediaStreamDeviceSettings> device_settings_;
- scoped_refptr<VideoCaptureManager> video_capture_manager_;
scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_;
+ scoped_refptr<VideoCaptureManager> video_capture_manager_;
// Keeps track of device types currently being enumerated to not enumerate
// when not necessary.
@@ -160,7 +174,6 @@ class CONTENT_EXPORT MediaStreamManager
// All non-closed request.
typedef std::map<std::string, DeviceRequest> DeviceRequests;
DeviceRequests requests_;
- media::AudioManager* audio_manager_;
DISALLOW_COPY_AND_ASSIGN(MediaStreamManager);
};

Powered by Google App Engine
This is Rietveld 408576698