summaryrefslogtreecommitdiffstats
path: root/content/renderer/pepper/pepper_platform_video_capture_impl.h
blob: a198133d0a46e594e631208804bdbc1b5b23d4bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_IMPL_H_
#define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_IMPL_H_

#include <string>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "media/video/capture/video_capture.h"
#include "media/video/capture/video_capture_types.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"

namespace media {
class VideoCaptureHandlerProxy;
}

namespace content {

class PepperPluginDelegateImpl;

class PepperPlatformVideoCaptureImpl
    : public webkit::ppapi::PluginDelegate::PlatformVideoCapture,
      public media::VideoCapture::EventHandler {
 public:
  PepperPlatformVideoCaptureImpl(
      const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate,
      const std::string& device_id,
      webkit::ppapi::PluginDelegate::PlatformVideoCaptureEventHandler* handler);

  // webkit::ppapi::PluginDelegate::PlatformVideoCapture implementation.
  virtual void StartCapture(
      media::VideoCapture::EventHandler* handler,
      const media::VideoCaptureCapability& capability) OVERRIDE;
  virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE;
  virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE;
  virtual bool CaptureStarted() OVERRIDE;
  virtual int CaptureWidth() OVERRIDE;
  virtual int CaptureHeight() OVERRIDE;
  virtual int CaptureFrameRate() OVERRIDE;
  virtual void DetachEventHandler() OVERRIDE;

  // media::VideoCapture::EventHandler implementation
  virtual void OnStarted(VideoCapture* capture) OVERRIDE;
  virtual void OnStopped(VideoCapture* capture) OVERRIDE;
  virtual void OnPaused(VideoCapture* capture) OVERRIDE;
  virtual void OnError(VideoCapture* capture, int error_code) OVERRIDE;
  virtual void OnRemoved(VideoCapture* capture) OVERRIDE;
  virtual void OnBufferReady(VideoCapture* capture,
                             scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE;
  virtual void OnDeviceInfoReceived(
      VideoCapture* capture,
      const media::VideoCaptureParams& device_info) OVERRIDE;

 protected:
  virtual ~PepperPlatformVideoCaptureImpl();

 private:
  void Initialize();

  void OnDeviceOpened(int request_id,
                      bool succeeded,
                      const std::string& label);

  base::WeakPtr<PepperPluginDelegateImpl> plugin_delegate_;

  std::string device_id_;
  std::string label_;
  int session_id_;

  scoped_ptr<media::VideoCaptureHandlerProxy> handler_proxy_;

  webkit::ppapi::PluginDelegate::PlatformVideoCaptureEventHandler* handler_;

  media::VideoCapture* video_capture_;

  // StartCapture() must be balanced by StopCapture(), otherwise this object
  // will leak.
  bool unbalanced_start_;

  DISALLOW_COPY_AND_ASSIGN(PepperPlatformVideoCaptureImpl);
};

}  // namespace content

#endif  // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_IMPL_H_