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 // A fake media source that generates video and audio frames to a cast | 5 // A fake media source that generates video and audio frames to a cast |
6 // sender. | 6 // sender. |
7 // This class can transcode a WebM file using FFmpeg. It can also | 7 // This class can transcode a WebM file using FFmpeg. It can also |
8 // generate an animation and audio of fixed frequency. | 8 // generate an animation and audio of fixed frequency. |
9 | 9 |
10 #ifndef MEDIA_CAST_TEST_FAKE_MEDIA_SOURCE_H_ | 10 #ifndef MEDIA_CAST_TEST_FAKE_MEDIA_SOURCE_H_ |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 FakeMediaSource(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 50 FakeMediaSource(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
51 base::TickClock* clock, | 51 base::TickClock* clock, |
52 const VideoSenderConfig& video_config, | 52 const VideoSenderConfig& video_config, |
53 bool keep_frames); | 53 bool keep_frames); |
54 ~FakeMediaSource(); | 54 ~FakeMediaSource(); |
55 | 55 |
56 // Transcode this file as the source of video and audio frames. | 56 // Transcode this file as the source of video and audio frames. |
57 // If |override_fps| is non zero then the file is played at the desired rate. | 57 // If |override_fps| is non zero then the file is played at the desired rate. |
58 void SetSourceFile(const base::FilePath& video_file, int override_fps); | 58 void SetSourceFile(const base::FilePath& video_file, int override_fps); |
59 | 59 |
| 60 // Set to true to randomly change the frame size at random points in time. |
| 61 // Only applies when SetSourceFile() is not used. |
| 62 void SetVariableFrameSizeMode(bool enabled); |
| 63 |
60 void Start(scoped_refptr<AudioFrameInput> audio_frame_input, | 64 void Start(scoped_refptr<AudioFrameInput> audio_frame_input, |
61 scoped_refptr<VideoFrameInput> video_frame_input); | 65 scoped_refptr<VideoFrameInput> video_frame_input); |
62 | 66 |
63 const VideoSenderConfig& get_video_config() const { return video_config_; } | 67 const VideoSenderConfig& get_video_config() const { return video_config_; } |
64 | 68 |
65 scoped_refptr<media::VideoFrame> PopOldestInsertedVideoFrame(); | 69 scoped_refptr<media::VideoFrame> PopOldestInsertedVideoFrame(); |
66 | 70 |
67 private: | 71 private: |
68 bool is_transcoding_audio() const { return audio_stream_index_ >= 0; } | 72 bool is_transcoding_audio() const { return audio_stream_index_ >= 0; } |
69 bool is_transcoding_video() const { return video_stream_index_ >= 0; } | 73 bool is_transcoding_video() const { return video_stream_index_ >= 0; } |
70 | 74 |
71 void SendNextFrame(); | 75 void SendNextFrame(); |
72 void SendNextFakeFrame(); | 76 void SendNextFakeFrame(); |
73 | 77 |
| 78 void UpdateNextFrameSize(); |
| 79 |
74 // Return true if a frame was sent. | 80 // Return true if a frame was sent. |
75 bool SendNextTranscodedVideo(base::TimeDelta elapsed_time); | 81 bool SendNextTranscodedVideo(base::TimeDelta elapsed_time); |
76 | 82 |
77 // Return true if a frame was sent. | 83 // Return true if a frame was sent. |
78 bool SendNextTranscodedAudio(base::TimeDelta elapsed_time); | 84 bool SendNextTranscodedAudio(base::TimeDelta elapsed_time); |
79 | 85 |
80 // Helper methods to compute timestamps for the frame number specified. | 86 // Helper methods to compute timestamps for the frame number specified. |
81 base::TimeDelta VideoFrameTime(int frame_number); | 87 base::TimeDelta VideoFrameTime(int frame_number); |
82 | 88 |
83 base::TimeDelta ScaleTimestamp(base::TimeDelta timestamp); | 89 base::TimeDelta ScaleTimestamp(base::TimeDelta timestamp); |
(...skipping 13 matching lines...) Expand all Loading... |
97 void ProvideData(int frame_delay, media::AudioBus* output_bus); | 103 void ProvideData(int frame_delay, media::AudioBus* output_bus); |
98 | 104 |
99 AVStream* av_audio_stream(); | 105 AVStream* av_audio_stream(); |
100 AVStream* av_video_stream(); | 106 AVStream* av_video_stream(); |
101 AVCodecContext* av_audio_context(); | 107 AVCodecContext* av_audio_context(); |
102 AVCodecContext* av_video_context(); | 108 AVCodecContext* av_video_context(); |
103 | 109 |
104 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 110 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
105 const VideoSenderConfig video_config_; | 111 const VideoSenderConfig video_config_; |
106 const bool keep_frames_; | 112 const bool keep_frames_; |
| 113 bool variable_frame_size_mode_; |
| 114 gfx::Size current_frame_size_; |
| 115 base::TimeTicks next_frame_size_change_time_; |
107 scoped_refptr<AudioFrameInput> audio_frame_input_; | 116 scoped_refptr<AudioFrameInput> audio_frame_input_; |
108 scoped_refptr<VideoFrameInput> video_frame_input_; | 117 scoped_refptr<VideoFrameInput> video_frame_input_; |
109 uint8 synthetic_count_; | 118 uint8 synthetic_count_; |
110 base::TickClock* const clock_; // Not owned by this class. | 119 base::TickClock* const clock_; // Not owned by this class. |
111 | 120 |
112 // Time when the stream starts. | 121 // Time when the stream starts. |
113 base::TimeTicks start_time_; | 122 base::TimeTicks start_time_; |
114 | 123 |
115 // The following three members are used only for fake frames. | 124 // The following three members are used only for fake frames. |
116 int audio_frame_count_; // Each audio frame is exactly 10ms. | 125 int audio_frame_count_; // Each audio frame is exactly 10ms. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // NOTE: Weak pointers must be invalidated before all other member variables. | 159 // NOTE: Weak pointers must be invalidated before all other member variables. |
151 base::WeakPtrFactory<FakeMediaSource> weak_factory_; | 160 base::WeakPtrFactory<FakeMediaSource> weak_factory_; |
152 | 161 |
153 DISALLOW_COPY_AND_ASSIGN(FakeMediaSource); | 162 DISALLOW_COPY_AND_ASSIGN(FakeMediaSource); |
154 }; | 163 }; |
155 | 164 |
156 } // namespace cast | 165 } // namespace cast |
157 } // namespace media | 166 } // namespace media |
158 | 167 |
159 #endif // MEDIA_CAST_TEST_FAKE_MEDIA_SOURCE_H_ | 168 #endif // MEDIA_CAST_TEST_FAKE_MEDIA_SOURCE_H_ |
OLD | NEW |