Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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 CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ | |
| 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <map> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/message_loop.h" | |
| 14 #include "content/common/media/media_stream_options.h" | |
| 15 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | |
| 16 #include "content/renderer/render_view_observer.h" | |
| 17 | |
| 18 // MediaStreamDispatcher is a delegate for the Media Stream API messages. | |
| 19 // MediaStreams are used by WebKit to open media devices such as Video Capture | |
| 20 // and Audio input devices. | |
| 21 // It's the complement of MediaStreamDispatcherHost (owned by | |
| 22 // BrowserRenderProcessHost). | |
| 23 class MediaStreamDispatcher : public RenderViewObserver { | |
| 24 public: | |
| 25 explicit MediaStreamDispatcher(RenderView* render_view); | |
| 26 virtual ~MediaStreamDispatcher(); | |
| 27 | |
| 28 // Request a new media stream to be created. | |
| 29 // This can be used either of WebKit or a plugin. | |
| 30 // Note: The event_handler must be valid for as long as the stream exists. | |
| 31 void GenerateStream(int request_id, | |
| 32 MediaStreamDispatcherEventHandler* event_handler, | |
| 33 media_stream::GenerateStreamOptions components, | |
| 34 const std::string& security_origin); | |
| 35 | |
| 36 // Stop a started stream. Label is the label provided in OnStreamGenerated. | |
| 37 void StopStream(const std::string& label); | |
| 38 | |
| 39 // Returns a StreamDeviceInfoArray given a label. This can be used for | |
| 40 // verifying if a label is an opened media stream. | |
| 41 const media_stream::StreamDeviceInfoArray& audio_device_array( | |
|
scherkus (not reviewing)
2011/06/17 17:42:13
this isn't any better since it's too easy to have
Per K
2011/06/18 19:53:59
The purpose of these two methods are for the media
| |
| 42 const std::string& label); | |
| 43 const media_stream::StreamDeviceInfoArray& video_device_array( | |
| 44 const std::string& label); | |
| 45 | |
| 46 private: | |
| 47 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, Basic); | |
| 48 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, TestFailure); | |
| 49 | |
| 50 typedef int IpcRequestId; | |
| 51 struct Request { | |
| 52 Request(MediaStreamDispatcherEventHandler* handler, | |
| 53 int request_id, | |
| 54 IpcRequestId ipc_request) | |
| 55 : handler(handler), | |
| 56 request_id(request_id), | |
| 57 ipc_request(ipc_request) { | |
| 58 } | |
| 59 MediaStreamDispatcherEventHandler* handler; | |
| 60 int request_id; | |
| 61 int ipc_request; | |
| 62 }; | |
| 63 | |
| 64 // Private class for keeping track of opened devices and who have | |
| 65 // opened it. | |
| 66 struct Stream { | |
| 67 MediaStreamDispatcherEventHandler* handler; | |
| 68 media_stream::StreamDeviceInfoArray audio_array; | |
| 69 media_stream::StreamDeviceInfoArray video_array; | |
| 70 }; | |
| 71 | |
| 72 // Messages from the browser. | |
| 73 virtual bool OnMessageReceived(const IPC::Message& message); | |
| 74 void OnStreamGenerated( | |
| 75 int request_id, | |
| 76 const std::string& label, | |
| 77 const media_stream::StreamDeviceInfoArray& audio_array, | |
| 78 const media_stream::StreamDeviceInfoArray& video_array); | |
| 79 void OnStreamGenerationFailed(int requestId); | |
|
scherkus (not reviewing)
2011/06/17 17:42:13
requestId -> request_id
Per K
2011/06/18 19:53:59
Hard do change an old habit... Done.
| |
| 80 void OnVideoDeviceFailed(const std::string& label, int index); | |
| 81 void OnAudioDeviceFailed(const std::string& label, int index); | |
| 82 | |
| 83 IpcRequestId next_ipc_id_; | |
| 84 typedef std::map<std::string, Stream> LabelStreamMap; | |
| 85 LabelStreamMap label_stream_map_; | |
| 86 | |
| 87 // List of calls made to GenerateStream that has not yet completed. | |
| 88 typedef std::list<Request> RequestList; | |
| 89 RequestList requests_; | |
| 90 MessageLoop* message_loop_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcher); | |
| 93 }; | |
| 94 | |
| 95 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ | |
| OLD | NEW |