summaryrefslogtreecommitdiff
path: root/chromium/media/remoting/mock_receiver_controller.h
blob: e4c6da6c37bfd0e494efa30646759bf1a8955ff8 (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
95
96
// Copyright 2020 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 MEDIA_REMOTING_MOCK_RECEIVER_CONTROLLER_H_
#define MEDIA_REMOTING_MOCK_RECEIVER_CONTROLLER_H_

#include <memory>
#include <vector>

#include "base/memory/scoped_refptr.h"
#include "base/no_destructor.h"
#include "media/mojo/mojom/remoting.mojom.h"
#include "media/remoting/receiver_controller.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"

namespace media {

class MojoDecoderBufferWriter;

namespace remoting {

class MockRemotee : public mojom::Remotee {
 public:
  MockRemotee();
  ~MockRemotee() override;

  void BindMojoReceiver(mojo::PendingReceiver<Remotee> receiver);

  void SendAudioFrame(uint32_t frame_count,
                      scoped_refptr<DecoderBuffer> buffer);
  void SendVideoFrame(uint32_t frame_count,
                      scoped_refptr<DecoderBuffer> buffer);

  // mojom::Remotee implementation
  void OnRemotingSinkReady(
      mojo::PendingRemote<mojom::RemotingSink> remoting_sink) override;
  void SendMessageToSource(const std::vector<uint8_t>& message) override;
  void StartDataStreams(
      mojo::PendingRemote<mojom::RemotingDataStreamReceiver> audio_stream,
      mojo::PendingRemote<mojom::RemotingDataStreamReceiver> video_stream)
      override;
  void OnFlushUntil(uint32_t audio_count, uint32_t video_count) override;
  void OnVideoNaturalSizeChange(const gfx::Size& size) override;

  void Reset();

  gfx::Size changed_size() { return changed_size_; }
  uint32_t flush_audio_count() { return flush_audio_count_; }
  uint32_t flush_video_count() { return flush_video_count_; }

  mojo::PendingRemote<mojom::Remotee> BindNewPipeAndPassRemote() {
    return receiver_.BindNewPipeAndPassRemote();
  }

  mojo::Remote<mojom::RemotingDataStreamReceiver> audio_stream_;
  mojo::Remote<mojom::RemotingDataStreamReceiver> video_stream_;

 private:
  gfx::Size changed_size_;

  uint32_t flush_audio_count_{0};
  uint32_t flush_video_count_{0};

  std::unique_ptr<MojoDecoderBufferWriter> audio_buffer_writer_;
  std::unique_ptr<MojoDecoderBufferWriter> video_buffer_writer_;

  mojo::Remote<mojom::RemotingSink> remoting_sink_;
  mojo::Receiver<mojom::Remotee> receiver_{this};
};

class MockReceiverController : public ReceiverController {
 public:
  static MockReceiverController* GetInstance();

  MockRemotee* mock_remotee() { return mock_remotee_.get(); }

 private:
  friend base::NoDestructor<MockReceiverController>;
  friend testing::StrictMock<MockReceiverController>;
  friend testing::NiceMock<MockReceiverController>;

  MockReceiverController();
  ~MockReceiverController() override;

  void OnSendRpc(std::unique_ptr<std::vector<uint8_t>> message);

  std::unique_ptr<MockRemotee> mock_remotee_;
};

}  // namespace remoting
}  // namespace media

#endif  // MEDIA_REMOTING_MOCK_RECEIVER_CONTROLLER_H_