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