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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "media/video/capture/video_capture.h"
15 #include "media/video/capture/video_capture_types.h"
20 class VideoCaptureHandlerProxy;
24 class PepperMediaDeviceManager;
25 class PepperVideoCaptureHost;
27 class VideoCaptureHandle;
29 class PepperPlatformVideoCapture
30 : public media::VideoCapture,
31 public base::RefCounted<PepperPlatformVideoCapture>,
32 public media::VideoCapture::EventHandler {
34 PepperPlatformVideoCapture(
35 const base::WeakPtr<RenderViewImpl>& render_view,
36 const std::string& device_id,
37 const GURL& document_url,
38 PepperVideoCaptureHost* handler);
40 // Detaches the event handler and stops sending notifications to it.
41 void DetachEventHandler();
43 // media::VideoCapture implementation.
44 virtual void StartCapture(
45 media::VideoCapture::EventHandler* handler,
46 const media::VideoCaptureParams& params) OVERRIDE;
47 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE;
48 virtual bool CaptureStarted() OVERRIDE;
49 virtual int CaptureFrameRate() OVERRIDE;
50 virtual void GetDeviceSupportedFormats(
51 const DeviceFormatsCallback& callback) OVERRIDE;
52 virtual void GetDeviceFormatsInUse(
53 const DeviceFormatsInUseCallback& callback) OVERRIDE;
55 // media::VideoCapture::EventHandler implementation
56 virtual void OnStarted(VideoCapture* capture) OVERRIDE;
57 virtual void OnStopped(VideoCapture* capture) OVERRIDE;
58 virtual void OnPaused(VideoCapture* capture) OVERRIDE;
59 virtual void OnError(VideoCapture* capture, int error_code) OVERRIDE;
60 virtual void OnRemoved(VideoCapture* capture) OVERRIDE;
61 virtual void OnFrameReady(
62 VideoCapture* capture,
63 const scoped_refptr<media::VideoFrame>& frame) OVERRIDE;
66 friend class base::RefCounted<PepperPlatformVideoCapture>;
67 virtual ~PepperPlatformVideoCapture();
72 void OnDeviceOpened(int request_id,
74 const std::string& label);
76 PepperMediaDeviceManager* GetMediaDeviceManager();
78 base::WeakPtr<RenderViewImpl> render_view_;
80 std::string device_id_;
84 scoped_ptr<media::VideoCaptureHandlerProxy> handler_proxy_;
86 PepperVideoCaptureHost* handler_;
88 scoped_ptr<VideoCaptureHandle> video_capture_;
90 // StartCapture() must be balanced by StopCapture(), otherwise this object
92 bool unbalanced_start_;
94 // Whether we have a pending request to open a device. We have to make sure
95 // there isn't any pending request before this object goes away.
96 bool pending_open_device_;
97 int pending_open_device_id_;
99 DISALLOW_COPY_AND_ASSIGN(PepperPlatformVideoCapture);
102 } // namespace content
104 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_