Home | History | Annotate | Download | only in pepper
      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.
      4 
      5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_
      6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_
      7 
      8 #include <string>
      9 
     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"
     16 
     17 class GURL;
     18 
     19 namespace media {
     20 class VideoCaptureHandlerProxy;
     21 }
     22 
     23 namespace content {
     24 class PepperMediaDeviceManager;
     25 class PepperVideoCaptureHost;
     26 class RenderViewImpl;
     27 
     28 class PepperPlatformVideoCapture
     29     : public media::VideoCapture,
     30       public base::RefCounted<PepperPlatformVideoCapture>,
     31       public media::VideoCapture::EventHandler {
     32  public:
     33   PepperPlatformVideoCapture(
     34       const base::WeakPtr<RenderViewImpl>& render_view,
     35       const std::string& device_id,
     36       const GURL& document_url,
     37       PepperVideoCaptureHost* handler);
     38 
     39   // Detaches the event handler and stops sending notifications to it.
     40   void DetachEventHandler();
     41 
     42   // media::VideoCapture implementation.
     43   virtual void StartCapture(
     44       media::VideoCapture::EventHandler* handler,
     45       const media::VideoCaptureCapability& capability) OVERRIDE;
     46   virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE;
     47   virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE;
     48   virtual bool CaptureStarted() OVERRIDE;
     49   virtual int CaptureWidth() OVERRIDE;
     50   virtual int CaptureHeight() OVERRIDE;
     51   virtual int CaptureFrameRate() 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 OnBufferReady(VideoCapture* capture,
     60                              scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE;
     61   virtual void OnDeviceInfoReceived(
     62       VideoCapture* capture,
     63       const media::VideoCaptureParams& device_info) OVERRIDE;
     64 
     65  protected:
     66   friend class base::RefCounted<PepperPlatformVideoCapture>;
     67   virtual ~PepperPlatformVideoCapture();
     68 
     69  private:
     70   void Initialize();
     71 
     72   void OnDeviceOpened(int request_id,
     73                       bool succeeded,
     74                       const std::string& label);
     75 
     76   PepperMediaDeviceManager* GetMediaDeviceManager();
     77 
     78   base::WeakPtr<RenderViewImpl> render_view_;
     79 
     80   std::string device_id_;
     81   std::string label_;
     82   int session_id_;
     83 
     84   scoped_ptr<media::VideoCaptureHandlerProxy> handler_proxy_;
     85 
     86   PepperVideoCaptureHost* handler_;
     87 
     88   media::VideoCapture* video_capture_;
     89 
     90   // StartCapture() must be balanced by StopCapture(), otherwise this object
     91   // will leak.
     92   bool unbalanced_start_;
     93 
     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_;
     98 
     99   DISALLOW_COPY_AND_ASSIGN(PepperPlatformVideoCapture);
    100 };
    101 
    102 }  // namespace content
    103 
    104 #endif  // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_
    105