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

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

Powered by Google App Engine
This is Rietveld 408576698