summaryrefslogtreecommitdiffstats
path: root/content/renderer/media/rtc_video_capturer.h
blob: 5fb72a46cfa3e56528d3e8c55ca416eb11e89757 (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
// 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_MEDIA_RTC_VIDEO_CAPTURER_H_
#define CONTENT_RENDERER_MEDIA_RTC_VIDEO_CAPTURER_H_

#include <vector>

#include "base/compiler_specific.h"
#include "content/renderer/media/rtc_video_capture_delegate.h"
#include "third_party/libjingle/source/talk/media/base/videocapturer.h"

class VideoCaptureImplManager;

// RtcVideoCapturer implements a simple cricket::VideoCapturer that is used for
// VideoCapturing in libJingle and especially in PeerConnections.
// The class is created and destroyed on the main render thread.
// PeerConnection access cricket::VideoCapturer from a libJingle worker thread.
// The video frames are delivered in OnFrameCaptured on a thread owned by
// Chrome's video capture implementation.
class RtcVideoCapturer
    : public cricket::VideoCapturer {
 public:
  RtcVideoCapturer(const media::VideoCaptureSessionId id,
                   VideoCaptureImplManager* vc_manager,
                   bool is_screencast);
  virtual ~RtcVideoCapturer();

  // cricket::VideoCapturer implementation.
  // These methods are accessed from a libJingle worker thread.
  virtual cricket::CaptureState Start(
      const cricket::VideoFormat& capture_format) OVERRIDE;
  virtual void Stop() OVERRIDE;
  virtual bool IsRunning() OVERRIDE;
  virtual bool GetPreferredFourccs(std::vector<uint32>* fourccs) OVERRIDE;
  virtual bool GetBestCaptureFormat(const cricket::VideoFormat& desired,
                                    cricket::VideoFormat* best_format) OVERRIDE;
  virtual bool IsScreencast() OVERRIDE;

 private:
  // Frame captured callback method.
  virtual void OnFrameCaptured(
      const media::VideoCapture::VideoFrameBuffer& frame);

  // State change callback, must be called on same thread as Start is called.
  void OnStateChange(RtcVideoCaptureDelegate::CaptureState state);

  const bool is_screencast_;
  scoped_refptr<RtcVideoCaptureDelegate> delegate_;
  video_capture::State state_;
  base::Time start_time_;

  DISALLOW_COPY_AND_ASSIGN(RtcVideoCapturer);
};

#endif  // CONTENT_RENDERER_MEDIA_RTC_VIDEO_CAPTURER_H_