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