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_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_ |
6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 #include "media/video/capture/video_capture.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "content/common/media/video_capture.h" |
15 #include "media/video/capture/video_capture_types.h" | 17 #include "media/video/capture/video_capture_types.h" |
16 | 18 |
17 class GURL; | 19 class GURL; |
18 | 20 |
19 namespace media { | |
20 class VideoCaptureHandlerProxy; | |
21 } | |
22 | |
23 namespace content { | 21 namespace content { |
24 class PepperMediaDeviceManager; | 22 class PepperMediaDeviceManager; |
25 class PepperVideoCaptureHost; | 23 class PepperVideoCaptureHost; |
26 class RenderViewImpl; | 24 class RenderViewImpl; |
27 class VideoCaptureHandle; | |
28 | 25 |
29 class PepperPlatformVideoCapture | 26 // This is a render thread only object. All methods must be accessed on |
30 : public media::VideoCapture, | 27 // the render thread including cosntructor and destructor. |
31 public base::RefCounted<PepperPlatformVideoCapture>, | 28 class PepperPlatformVideoCapture { |
32 public media::VideoCapture::EventHandler { | |
33 public: | 29 public: |
34 PepperPlatformVideoCapture(const base::WeakPtr<RenderViewImpl>& render_view, | 30 PepperPlatformVideoCapture(const base::WeakPtr<RenderViewImpl>& render_view, |
35 const std::string& device_id, | 31 const std::string& device_id, |
36 const GURL& document_url, | 32 const GURL& document_url, |
37 PepperVideoCaptureHost* handler); | 33 PepperVideoCaptureHost* handler); |
| 34 virtual ~PepperPlatformVideoCapture(); |
38 | 35 |
39 // Detaches the event handler and stops sending notifications to it. | 36 // Detaches the event handler and stops sending notifications to it. |
40 void DetachEventHandler(); | 37 void DetachEventHandler(); |
41 | 38 |
42 // media::VideoCapture implementation. | 39 void StartCapture(const media::VideoCaptureParams& params); |
43 virtual void StartCapture(media::VideoCapture::EventHandler* handler, | 40 void StopCapture(); |
44 const media::VideoCaptureParams& params) OVERRIDE; | |
45 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; | |
46 virtual bool CaptureStarted() OVERRIDE; | |
47 virtual int CaptureFrameRate() OVERRIDE; | |
48 virtual void GetDeviceSupportedFormats(const DeviceFormatsCallback& callback) | |
49 OVERRIDE; | |
50 virtual void GetDeviceFormatsInUse(const DeviceFormatsInUseCallback& callback) | |
51 OVERRIDE; | |
52 | |
53 // media::VideoCapture::EventHandler implementation | |
54 virtual void OnStarted(VideoCapture* capture) OVERRIDE; | |
55 virtual void OnStopped(VideoCapture* capture) OVERRIDE; | |
56 virtual void OnPaused(VideoCapture* capture) OVERRIDE; | |
57 virtual void OnError(VideoCapture* capture, int error_code) OVERRIDE; | |
58 virtual void OnRemoved(VideoCapture* capture) OVERRIDE; | |
59 virtual void OnFrameReady(VideoCapture* capture, | |
60 const scoped_refptr<media::VideoFrame>& frame) | |
61 OVERRIDE; | |
62 | |
63 protected: | |
64 friend class base::RefCounted<PepperPlatformVideoCapture>; | |
65 virtual ~PepperPlatformVideoCapture(); | |
66 | 41 |
67 private: | 42 private: |
68 void Initialize(); | |
69 | |
70 void OnDeviceOpened(int request_id, bool succeeded, const std::string& label); | 43 void OnDeviceOpened(int request_id, bool succeeded, const std::string& label); |
| 44 void OnStateUpdate(VideoCaptureState state); |
| 45 void OnFrameReady( |
| 46 const scoped_refptr<media::VideoFrame>& frame, |
| 47 const media::VideoCaptureFormat& format, |
| 48 const base::TimeTicks& timestamp); |
71 | 49 |
72 PepperMediaDeviceManager* GetMediaDeviceManager(); | 50 PepperMediaDeviceManager* GetMediaDeviceManager(); |
73 | 51 |
74 base::WeakPtr<RenderViewImpl> render_view_; | 52 base::WeakPtr<RenderViewImpl> render_view_; |
75 | 53 |
76 std::string device_id_; | 54 std::string device_id_; |
77 std::string label_; | 55 std::string label_; |
78 int session_id_; | 56 int session_id_; |
79 | 57 base::Closure release_device_cb_; |
80 scoped_ptr<media::VideoCaptureHandlerProxy> handler_proxy_; | 58 base::Closure stop_capture_cb_; |
81 | 59 |
82 PepperVideoCaptureHost* handler_; | 60 PepperVideoCaptureHost* handler_; |
83 | 61 |
84 scoped_ptr<VideoCaptureHandle> video_capture_; | |
85 | |
86 // StartCapture() must be balanced by StopCapture(), otherwise this object | |
87 // will leak. | |
88 bool unbalanced_start_; | |
89 | |
90 // Whether we have a pending request to open a device. We have to make sure | 62 // Whether we have a pending request to open a device. We have to make sure |
91 // there isn't any pending request before this object goes away. | 63 // there isn't any pending request before this object goes away. |
92 bool pending_open_device_; | 64 bool pending_open_device_; |
93 int pending_open_device_id_; | 65 int pending_open_device_id_; |
94 | 66 |
| 67 base::ThreadChecker thread_checker_; |
| 68 |
| 69 base::WeakPtrFactory<PepperPlatformVideoCapture> weak_factory_; |
| 70 |
95 DISALLOW_COPY_AND_ASSIGN(PepperPlatformVideoCapture); | 71 DISALLOW_COPY_AND_ASSIGN(PepperPlatformVideoCapture); |
96 }; | 72 }; |
97 | 73 |
98 } // namespace content | 74 } // namespace content |
99 | 75 |
100 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_ | 76 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_ |
OLD | NEW |