OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_VIDEO_CAPTURE_DEVICE_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_VIDEO_CAPTURE_DEVICE_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_VIDEO_CAPTURE_DEVICE_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_VIDEO_CAPTURE_DEVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 #include "media/video/capture/video_capture_device.h" | 13 #include "media/video/capture/video_capture_device.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 class CaptureMachine; // Defined in web_contents_video_capture_device.cc. | 17 class CaptureMachine; // Defined in web_contents_video_capture_device.cc. |
18 class RenderWidgetHost; | 18 class RenderWidgetHost; |
19 | 19 |
20 // A virtualized VideoCaptureDevice that mirrors the displayed contents of a | 20 // A virtualized VideoCaptureDevice that mirrors the displayed contents of a |
21 // tab (accessed via its associated WebContents instance), producing a stream of | 21 // tab (accessed via its associated WebContents instance), producing a stream of |
22 // video frames. | 22 // video frames. |
23 // | 23 // |
24 // An instance is created by providing a device_id. The device_id contains the | 24 // An instance is created by providing a device_id. The device_id contains the |
25 // routing ID for a RenderViewHost, and from the RenderViewHost instance, a | 25 // routing ID for a RenderViewHost, and from the RenderViewHost instance, a |
26 // reference to its associated WebContents instance is acquired. From then on, | 26 // reference to its associated WebContents instance is acquired. From then on, |
27 // WebContentsVideoCaptureDevice will capture from whatever render view is | 27 // WebContentsVideoCaptureDevice will capture from whatever render view is |
28 // currently associated with that WebContents instance. This allows the | 28 // currently associated with that WebContents instance. This allows the |
29 // underlying render view to be swapped out (e.g., due to navigation or | 29 // underlying render view to be swapped out (e.g., due to navigation or |
30 // crashes/reloads), without any interrpution in capturing. | 30 // crashes/reloads), without any interruption in capturing. |
31 class CONTENT_EXPORT WebContentsVideoCaptureDevice | 31 class CONTENT_EXPORT WebContentsVideoCaptureDevice |
32 : public media::VideoCaptureDevice { | 32 : public media::VideoCaptureDevice { |
33 public: | 33 public: |
34 // Construct from the a |device_id| string of the form: | 34 // Construct from a |device_id| string of the form: |
35 // "render_process_id:render_view_id" | 35 // "virtual-media-stream://render_process_id:render_view_id", where |
36 static media::VideoCaptureDevice* Create(const std::string& device_id); | 36 // |render_process_id| and |render_view_id| are decimal integers. |
37 | 37 // |destroy_cb| is invoked on an outside thread once all outstanding objects |
38 // Construct an instance with the following |test_source| injected for testing | 38 // are completely destroyed -- this will be some time after the |
39 // purposes. |destroy_cb| is invoked once all outstanding objects are | 39 // WebContentsVideoCaptureDevice is itself deleted. |
40 // completely destroyed. | |
41 // TODO(miu): Passing a destroy callback suggests needing to revisit the | 40 // TODO(miu): Passing a destroy callback suggests needing to revisit the |
42 // design philosophy of an asynchronous DeAllocate(). http://crbug.com/158641 | 41 // design philosophy of an asynchronous DeAllocate(). http://crbug.com/158641 |
43 static media::VideoCaptureDevice* CreateForTesting( | 42 static media::VideoCaptureDevice* Create(const std::string& device_id, |
44 RenderWidgetHost* test_source, const base::Closure& destroy_cb); | 43 const base::Closure& destroy_cb); |
45 | 44 |
46 virtual ~WebContentsVideoCaptureDevice(); | 45 virtual ~WebContentsVideoCaptureDevice(); |
47 | 46 |
48 // VideoCaptureDevice implementation. | 47 // VideoCaptureDevice implementation. |
49 virtual void Allocate(int width, | 48 virtual void Allocate(int width, |
50 int height, | 49 int height, |
51 int frame_rate, | 50 int frame_rate, |
52 VideoCaptureDevice::EventHandler* consumer) OVERRIDE; | 51 VideoCaptureDevice::EventHandler* consumer) OVERRIDE; |
53 virtual void Start() OVERRIDE; | 52 virtual void Start() OVERRIDE; |
54 virtual void Stop() OVERRIDE; | 53 virtual void Stop() OVERRIDE; |
55 virtual void DeAllocate() OVERRIDE; | 54 virtual void DeAllocate() OVERRIDE; |
56 | 55 |
57 // Note: The following is just a pass-through of the device_id provided to the | 56 // Note: The following is just a pass-through of the device_id provided to the |
58 // constructor. It does not change when the content of the page changes | 57 // constructor. It does not change when the content of the page changes |
59 // (e.g., due to navigation), or when the underlying RenderView is | 58 // (e.g., due to navigation), or when the underlying RenderView is |
60 // swapped-out. | 59 // swapped-out. |
61 virtual const Name& device_name() OVERRIDE; | 60 virtual const Name& device_name() OVERRIDE; |
62 | 61 |
63 private: | 62 private: |
64 // Constructors. The latter is used for testing. | 63 WebContentsVideoCaptureDevice(const Name& name, |
65 WebContentsVideoCaptureDevice( | 64 int render_process_id, |
66 const Name& name, int render_process_id, int render_view_id); | 65 int render_view_id, |
67 WebContentsVideoCaptureDevice(RenderWidgetHost* test_source, | |
68 const base::Closure& destroy_cb); | 66 const base::Closure& destroy_cb); |
69 | 67 |
70 Name device_name_; | 68 Name device_name_; |
71 scoped_refptr<CaptureMachine> capturer_; | 69 scoped_refptr<CaptureMachine> capturer_; |
72 | 70 |
73 DISALLOW_COPY_AND_ASSIGN(WebContentsVideoCaptureDevice); | 71 DISALLOW_COPY_AND_ASSIGN(WebContentsVideoCaptureDevice); |
74 }; | 72 }; |
75 | 73 |
76 } // namespace content | 74 } // namespace content |
77 | 75 |
78 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_VIDEO_CAPTURE_DEVICE
_H_ | 76 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_VIDEO_CAPTURE_DEVICE
_H_ |
OLD | NEW |