OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_CAST_TEST_FAKE_MOCK_VIDEO_ENCODE_ACCELERATOR_H_ | 5 #ifndef MEDIA_VIDEO_FAKE_VIDEO_ENCODE_ACCELERATOR_H_ |
6 #define MEDIA_CAST_TEST_FAKE_MOCK_VIDEO_ENCODE_ACCELERATOR_H_ | 6 #define MEDIA_VIDEO_FAKE_VIDEO_ENCODE_ACCELERATOR_H_ |
7 | |
8 #include "media/video/video_encode_accelerator.h" | |
9 | 7 |
10 #include <list> | 8 #include <list> |
| 9 #include <queue> |
11 #include <vector> | 10 #include <vector> |
12 | 11 |
13 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
14 #include "media/base/bitstream_buffer.h" | 13 #include "media/base/bitstream_buffer.h" |
| 14 #include "media/base/media_export.h" |
| 15 #include "media/video/video_encode_accelerator.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
| 18 |
17 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 20 |
18 } // namespace base | 21 } // namespace base |
19 | 22 |
20 namespace media { | 23 namespace media { |
21 namespace cast { | |
22 namespace test { | |
23 | 24 |
24 class FakeVideoEncodeAccelerator : public VideoEncodeAccelerator { | 25 class MEDIA_EXPORT FakeVideoEncodeAccelerator : public VideoEncodeAccelerator { |
25 public: | 26 public: |
26 explicit FakeVideoEncodeAccelerator( | 27 explicit FakeVideoEncodeAccelerator( |
27 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 28 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
28 std::vector<uint32>* stored_bitrates); | |
29 ~FakeVideoEncodeAccelerator() override; | 29 ~FakeVideoEncodeAccelerator() override; |
30 | 30 |
31 std::vector<VideoEncodeAccelerator::SupportedProfile> GetSupportedProfiles() | 31 std::vector<VideoEncodeAccelerator::SupportedProfile> GetSupportedProfiles() |
32 override; | 32 override; |
33 bool Initialize(media::VideoFrame::Format input_format, | 33 bool Initialize(VideoFrame::Format input_format, |
34 const gfx::Size& input_visible_size, | 34 const gfx::Size& input_visible_size, |
35 VideoCodecProfile output_profile, | 35 VideoCodecProfile output_profile, |
36 uint32 initial_bitrate, | 36 uint32 initial_bitrate, |
37 Client* client) override; | 37 Client* client) override; |
38 | |
39 void Encode(const scoped_refptr<VideoFrame>& frame, | 38 void Encode(const scoped_refptr<VideoFrame>& frame, |
40 bool force_keyframe) override; | 39 bool force_keyframe) override; |
41 | |
42 void UseOutputBitstreamBuffer(const BitstreamBuffer& buffer) override; | 40 void UseOutputBitstreamBuffer(const BitstreamBuffer& buffer) override; |
43 | |
44 void RequestEncodingParametersChange(uint32 bitrate, | 41 void RequestEncodingParametersChange(uint32 bitrate, |
45 uint32 framerate) override; | 42 uint32 framerate) override; |
46 | |
47 void Destroy() override; | 43 void Destroy() override; |
48 | 44 |
| 45 const std::vector<uint32>& stored_bitrates() const { |
| 46 return stored_bitrates_; |
| 47 } |
49 void SendDummyFrameForTesting(bool key_frame); | 48 void SendDummyFrameForTesting(bool key_frame); |
50 void SetWillInitializationSucceed(bool will_initialization_succeed) { | 49 void SetWillInitializationSucceed(bool will_initialization_succeed); |
51 will_initialization_succeed_ = will_initialization_succeed; | |
52 } | |
53 | 50 |
54 private: | 51 private: |
55 void DoRequireBitstreamBuffers(unsigned int input_count, | 52 void DoRequireBitstreamBuffers(unsigned int input_count, |
56 const gfx::Size& input_coded_size, | 53 const gfx::Size& input_coded_size, |
57 size_t output_buffer_size) const; | 54 size_t output_buffer_size) const; |
| 55 void EncodeTask(); |
58 void DoBitstreamBufferReady(int32 bitstream_buffer_id, | 56 void DoBitstreamBufferReady(int32 bitstream_buffer_id, |
59 size_t payload_size, | 57 size_t payload_size, |
60 bool key_frame) const; | 58 bool key_frame) const; |
61 | 59 |
| 60 // Our original (constructor) calling message loop used for all tasks. |
62 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 61 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
63 std::vector<uint32>* const stored_bitrates_; | 62 std::vector<uint32> stored_bitrates_; |
64 VideoEncodeAccelerator::Client* client_; | |
65 bool first_; | |
66 bool will_initialization_succeed_; | 63 bool will_initialization_succeed_; |
67 | 64 |
68 std::list<int32> available_buffer_ids_; | 65 VideoEncodeAccelerator::Client* client_; |
| 66 |
| 67 // Keeps track of if the current frame is the first encoded frame. This |
| 68 // is used to force a fake key frame for the first encoded frame. |
| 69 bool next_frame_is_first_frame_; |
| 70 |
| 71 // A queue containing the necessary data for incoming frames. The boolean |
| 72 // represent whether the queued frame should force a key frame. |
| 73 std::queue<bool> queued_frames_; |
| 74 |
| 75 // A list of buffers available for putting fake encoded frames in. |
| 76 std::list<BitstreamBuffer> available_buffers_; |
69 | 77 |
70 base::WeakPtrFactory<FakeVideoEncodeAccelerator> weak_this_factory_; | 78 base::WeakPtrFactory<FakeVideoEncodeAccelerator> weak_this_factory_; |
71 | 79 |
72 DISALLOW_COPY_AND_ASSIGN(FakeVideoEncodeAccelerator); | 80 DISALLOW_COPY_AND_ASSIGN(FakeVideoEncodeAccelerator); |
73 }; | 81 }; |
74 | 82 |
75 } // namespace test | |
76 } // namespace cast | |
77 } // namespace media | 83 } // namespace media |
78 | 84 |
79 #endif // MEDIA_CAST_TEST_FAKE_MOCK_VIDEO_ENCODE_ACCELERATOR_H_ | 85 #endif // MEDIA_VIDEO_FAKE_VIDEO_ENCODE_ACCELERATOR_H_ |
OLD | NEW |