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::StreamOptions 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 // Check if the label is a valid stream. | |
| 40 bool IsStream(const std::string& label); | |
| 41 // Get the video session_id given a label. The label identifies a stream. | |
| 42 // index is the index in the video_device_array of the stream. | |
| 43 int video_session_id(const std::string& label, int index); | |
| 44 // Returns an audio session_id given a label and an index. | |
| 45 int audio_session_id(const std::string& label, int index); | |
| 46 | |
| 47 private: | |
| 48 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, Basic); | |
| 49 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, TestFailure); | |
| 50 | |
| 51 typedef int IpcRequestId; | |
|
scherkus (not reviewing)
2011/06/22 22:27:24
nit: is it worth having a typedef?
the Request st
Per K
2011/06/23 07:37:20
Done.
| |
| 52 struct Request { | |
| 53 Request(MediaStreamDispatcherEventHandler* handler, | |
| 54 int request_id, | |
| 55 IpcRequestId ipc_request) | |
| 56 : handler(handler), | |
| 57 request_id(request_id), | |
| 58 ipc_request(ipc_request) { | |
| 59 } | |
| 60 MediaStreamDispatcherEventHandler* handler; | |
| 61 int request_id; | |
| 62 int ipc_request; | |
| 63 }; | |
| 64 | |
| 65 // Private class for keeping track of opened devices and who have | |
| 66 // opened it. | |
| 67 struct Stream { | |
| 68 MediaStreamDispatcherEventHandler* handler; | |
| 69 media_stream::StreamDeviceInfoArray audio_array; | |
| 70 media_stream::StreamDeviceInfoArray video_array; | |
| 71 }; | |
| 72 | |
| 73 // Messages from the browser. | |
| 74 virtual bool OnMessageReceived(const IPC::Message& message); | |
| 75 void OnStreamGenerated( | |
| 76 int request_id, | |
| 77 const std::string& label, | |
| 78 const media_stream::StreamDeviceInfoArray& audio_array, | |
| 79 const media_stream::StreamDeviceInfoArray& video_array); | |
| 80 void OnStreamGenerationFailed(int request_id); | |
| 81 void OnVideoDeviceFailed(const std::string& label, int index); | |
| 82 void OnAudioDeviceFailed(const std::string& label, int index); | |
| 83 | |
| 84 IpcRequestId next_ipc_id_; | |
| 85 typedef std::map<std::string, Stream> LabelStreamMap; | |
| 86 LabelStreamMap label_stream_map_; | |
| 87 | |
| 88 // List of calls made to GenerateStream that has not yet completed. | |
| 89 typedef std::list<Request> RequestList; | |
| 90 RequestList requests_; | |
| 91 MessageLoop* message_loop_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcher); | |
| 94 }; | |
| 95 | |
| 96 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ | |
| OLD | NEW |