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

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::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 struct Request {
52 Request(MediaStreamDispatcherEventHandler* handler,
53 int request_id,
54 int 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 request_id);
80 void OnVideoDeviceFailed(const std::string& label, int index);
81 void OnAudioDeviceFailed(const std::string& label, int index);
82
83 int 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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698