summaryrefslogtreecommitdiffstats
path: root/content/renderer/media/mock_media_stream_video_source.cc
blob: 19f7b6f74d1f815817e33c037fffe4fecc562082 (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
91
92
93
94
// Copyright 2014 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.

#include "content/renderer/media/mock_media_stream_video_source.h"

#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/location.h"

namespace content {

MockMediaStreamVideoSource::MockMediaStreamVideoSource(
    bool manual_get_supported_formats)
    : manual_get_supported_formats_(manual_get_supported_formats),
      max_requested_height_(0),
      max_requested_width_(0),
      max_requested_frame_rate_(0.0),
      attempted_to_start_(false) {
  supported_formats_.push_back(
      media::VideoCaptureFormat(
          gfx::Size(MediaStreamVideoSource::kDefaultWidth,
                    MediaStreamVideoSource::kDefaultHeight),
          MediaStreamVideoSource::kDefaultFrameRate,
          media::PIXEL_FORMAT_I420));
}

MockMediaStreamVideoSource::~MockMediaStreamVideoSource() {}

void MockMediaStreamVideoSource::StartMockedSource() {
  DCHECK(attempted_to_start_);
  attempted_to_start_ = false;
  OnStartDone(MEDIA_DEVICE_OK);
}

void MockMediaStreamVideoSource::FailToStartMockedSource() {
  DCHECK(attempted_to_start_);
  attempted_to_start_ = false;
  OnStartDone(MEDIA_DEVICE_TRACK_START_FAILURE);
}

void MockMediaStreamVideoSource::CompleteGetSupportedFormats() {
  DCHECK(!formats_callback_.is_null());
  base::ResetAndReturn(&formats_callback_).Run(supported_formats_);
}

void MockMediaStreamVideoSource::GetCurrentSupportedFormats(
    int max_requested_height,
    int max_requested_width,
    double max_requested_frame_rate,
    const VideoCaptureDeviceFormatsCB& callback) {
  DCHECK(formats_callback_.is_null());
  max_requested_height_ = max_requested_height;
  max_requested_width_ = max_requested_width;
  max_requested_frame_rate_ = max_requested_frame_rate;

  if (manual_get_supported_formats_) {
    formats_callback_ = callback;
    return;
  }
  callback.Run(supported_formats_);
}

void MockMediaStreamVideoSource::StartSourceImpl(
    const media::VideoCaptureFormat& format,
    const VideoCaptureDeliverFrameCB& frame_callback) {
  DCHECK(frame_callback_.is_null());
  format_ = format;
  attempted_to_start_ = true;
  frame_callback_ = frame_callback;
}

void MockMediaStreamVideoSource::StopSourceImpl() {
}

void MockMediaStreamVideoSource::DeliverVideoFrame(
    const scoped_refptr<media::VideoFrame>& frame) {
  DCHECK(!frame_callback_.is_null());
  io_message_loop()->PostTask(
      FROM_HERE,
      base::Bind(&MockMediaStreamVideoSource::DeliverVideoFrameOnIO,
                 base::Unretained(this), frame, format_,
                 base::TimeTicks(), frame_callback_));
}

void MockMediaStreamVideoSource::DeliverVideoFrameOnIO(
    const scoped_refptr<media::VideoFrame>& frame,
    media::VideoCaptureFormat format,
    const base::TimeTicks& estimated_capture_time,
    const VideoCaptureDeliverFrameCB& frame_callback) {
  frame_callback.Run(frame, format, estimated_capture_time);
}

}  // namespace content