Revert "[M120 Migration]Fix for crash during chrome exit"
[platform/framework/web/chromium-efl.git] / media / remoting / mock_receiver_controller.h
1 // Copyright 2020 The Chromium Authors
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 MEDIA_REMOTING_MOCK_RECEIVER_CONTROLLER_H_
6 #define MEDIA_REMOTING_MOCK_RECEIVER_CONTROLLER_H_
7
8 #include <memory>
9 #include <vector>
10
11 #include "base/memory/scoped_refptr.h"
12 #include "base/no_destructor.h"
13 #include "media/mojo/mojom/media_types.mojom.h"
14 #include "media/mojo/mojom/remoting.mojom.h"
15 #include "media/remoting/receiver_controller.h"
16 #include "mojo/public/cpp/bindings/receiver.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/gfx/geometry/size.h"
20
21 namespace media {
22
23 class MojoDecoderBufferWriter;
24
25 namespace remoting {
26
27 class MockRemotee : public mojom::Remotee {
28  public:
29   MockRemotee();
30   ~MockRemotee() override;
31
32   void BindMojoReceiver(mojo::PendingReceiver<Remotee> receiver);
33
34   void SendAudioFrame(uint32_t frame_count,
35                       scoped_refptr<DecoderBuffer> buffer);
36   void SendVideoFrame(uint32_t frame_count,
37                       scoped_refptr<DecoderBuffer> buffer);
38
39   // mojom::Remotee implementation
40   void OnRemotingSinkReady(
41       mojo::PendingRemote<mojom::RemotingSink> remoting_sink) override;
42   void SendMessageToSource(const std::vector<uint8_t>& message) override;
43   void StartDataStreams(
44       mojo::PendingRemote<mojom::RemotingDataStreamReceiver> audio_stream,
45       mojo::PendingRemote<mojom::RemotingDataStreamReceiver> video_stream)
46       override;
47   void OnFlushUntil(uint32_t audio_count, uint32_t video_count) override;
48   void OnVideoNaturalSizeChange(const gfx::Size& size) override;
49
50   void Reset();
51
52   gfx::Size changed_size() { return changed_size_; }
53   uint32_t flush_audio_count() { return flush_audio_count_; }
54   uint32_t flush_video_count() { return flush_video_count_; }
55
56   mojo::PendingRemote<mojom::Remotee> BindNewPipeAndPassRemote() {
57     return receiver_.BindNewPipeAndPassRemote();
58   }
59
60   mojo::Remote<mojom::RemotingDataStreamReceiver> audio_stream_;
61   mojo::Remote<mojom::RemotingDataStreamReceiver> video_stream_;
62
63  private:
64   gfx::Size changed_size_;
65
66   uint32_t flush_audio_count_{0};
67   uint32_t flush_video_count_{0};
68
69   std::unique_ptr<MojoDecoderBufferWriter> audio_buffer_writer_;
70   std::unique_ptr<MojoDecoderBufferWriter> video_buffer_writer_;
71
72   mojo::Remote<mojom::RemotingSink> remoting_sink_;
73   mojo::Receiver<mojom::Remotee> receiver_{this};
74 };
75
76 class MockReceiverController : public ReceiverController {
77  public:
78   static MockReceiverController* GetInstance();
79
80   MockRemotee* mock_remotee() { return mock_remotee_.get(); }
81
82  private:
83   friend base::NoDestructor<MockReceiverController>;
84   friend testing::StrictMock<MockReceiverController>;
85   friend testing::NiceMock<MockReceiverController>;
86
87   MockReceiverController();
88   ~MockReceiverController() override;
89
90   void OnSendRpc(std::vector<uint8_t> message);
91
92   std::unique_ptr<MockRemotee> mock_remotee_;
93 };
94
95 }  // namespace remoting
96 }  // namespace media
97
98 #endif  // MEDIA_REMOTING_MOCK_RECEIVER_CONTROLLER_H_