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

Side by Side Diff: content/renderer/media/media_stream_dispatcher.h

Issue 7184010: MediaStreamDispatcher (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 6 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
(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/render_view_observer.h"
16
17 // MediaStreamDispatcher is a delegate for the Media Stream API messages.
18 // MediaStreams are used by WebKit to open media devices such as Video Capture
19 // and Audio input devices.
20 // It's the complement of MediaStreamDispatcherHost (owned by
21 // BrowserRenderProcessHost).
22 class MediaStreamDispatcher : public RenderViewObserver {
23 public:
24 class EventHandler {
scherkus (not reviewing) 2011/06/17 03:31:59 as discussed before (not sure if you were on that
Per K 2011/06/17 15:47:54 I heard about the problem with VideoCaptureControl
25 public:
26 // A new media stream have been created.
27 virtual void OnStreamGenerated(
28 int request_id,
29 const std::string &label,
Leandro Graciá Gil 2011/06/16 17:40:01 & in the wrong side.
Per K 2011/06/17 15:47:54 Done.
30 const media_stream::StreamDeviceInfoArray audio_device_array,
Leandro Graciá Gil 2011/06/16 17:40:01 This should be a reference since you're passing an
Per K 2011/06/17 15:47:54 Done.
31 const media_stream::StreamDeviceInfoArray video_device_array) = 0;
32
33 // Creation of a new media stream failed. The user might have denied access
34 // to the requested devices or no device is available.
35 virtual void OnStreamGenerationFailed(int request_id) = 0;
36
37 // An error have occurred on a video device. This is called if a runtime
38 // error occur.
Leandro Graciá Gil 2011/06/16 17:40:01 Minor nit: occurs.
Per K 2011/06/17 15:47:54 Done.
39 virtual void OnVideoDeviceFailed(
40 const std::string &label,
41 int index) = 0;
42
43 // An error have occurred on an audio device. This is called if a runtime
44 // error occur.
Leandro Graciá Gil 2011/06/16 17:40:01 Same as before.
Per K 2011/06/17 15:47:54 Done.
45 virtual void OnAudioDeviceFailed(
46 const std::string &label,
47 int index) = 0;
48
49 protected:
50 virtual ~EventHandler() {}
51 };
52
53 explicit MediaStreamDispatcher(RenderView* render_view);
54 virtual ~MediaStreamDispatcher();
55
56 // Request a new media stream to be created.
57 // This can be used either of WebKit or a plugin.
58 // Note: The event_handler must be valid for as long as the stream exists.
59 void GenerateStream(int request_id,
60 EventHandler* event_handler,
Leandro Graciá Gil 2011/06/16 17:40:01 What is this EventHandler exactly for and who's pr
Per K 2011/06/17 15:47:54 We wanted to make MediaStreamDispatcher independen
61 media_stream::GenerateStreamOptions components,
62 const std::string& security_origin);
63
64 // Stop a started stream. Label is the label provided in OnStreamGenerated.
65 void StopStream(const std::string& label);
66
67 // Returns a StreamDeviceInfoArray given a label. This can be used for
68 // verifying if a label is an opened media stream.
69 const media_stream::StreamDeviceInfoArray* audio_device_array(
scherkus (not reviewing) 2011/06/17 03:31:59 const ptr to an array? if the point is to verify
Per K 2011/06/17 15:47:54 Changed to reference.
70 const std::string& label);
71 const media_stream::StreamDeviceInfoArray* video_device_array(
72 const std::string& label);
scherkus (not reviewing) 2011/06/17 03:31:59 nit: indentation
Per K 2011/06/17 15:47:54 Done.
73
74 private:
75 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, Basic);
76 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, TestFailure);
77
78 typedef int IPC_REQUEST_ID;
scherkus (not reviewing) 2011/06/17 03:31:59 nit: why is this type name ALL_CAPS? we use Camel
Per K 2011/06/17 15:47:54 Done.
79 struct Request {
scherkus (not reviewing) 2011/06/17 03:31:59 this is an example where inner classes is ok :)
Per K 2011/06/17 15:47:54 Done.
80 Request(EventHandler* handler, int request_id, IPC_REQUEST_ID ipc_request)
81 : handler(handler),
82 request_id(request_id),
83 ipc_request(ipc_request) {
84 }
85 EventHandler* handler;
86 int request_id;
87 int ipc_request;
88 };
89
90 // Private class for keeping track of opened devices and who have
91 // opened it.
92 struct Stream {
93 EventHandler* handler;
94 media_stream::StreamDeviceInfoArray audio_array;
95 media_stream::StreamDeviceInfoArray video_array;
96 };
97
98 // Messages from the browser.
99 virtual bool OnMessageReceived(const IPC::Message& message);
100 void OnStreamGenerated(
101 int request_id,
102 const std::string &label,
Leandro Graciá Gil 2011/06/16 17:40:01 This should be const std::string& label (the & on
Per K 2011/06/17 15:47:54 Done.
103 const media_stream::StreamDeviceInfoArray audio_array,
104 const media_stream::StreamDeviceInfoArray video_array);
105 void OnStreamGenerationFailed(int requestId);
106 void OnVideoDeviceFailed(std::string label, int index);
107 void OnAudioDeviceFailed(std::string label, int index);
108
109 IPC_REQUEST_ID next_ipc_id_;
110 typedef std::map<std::string, Stream> LabelStreamMap;
111 LabelStreamMap label_stream_map_;
112
113 // List of calls made to GenerateStream that has not yet completed.
114 typedef std::list <Request> RequestList;
Leandro Graciá Gil 2011/06/16 17:40:01 Not sure, but I think this has an extra space.
scherkus (not reviewing) 2011/06/17 03:31:59 yes it does :)
Per K 2011/06/17 15:47:54 Done.
115 RequestList requests_;
116 MessageLoop* main_message_loop_;
scherkus (not reviewing) 2011/06/17 03:31:59 nit: s/main_message_loop_/message_loop_/ (no need
Per K 2011/06/17 15:47:54 Done.
117
118 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcher);
119 };
120
121 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698