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 | |
64 void Start(scoped_refptr<AudioFrameInput> audio_frame_input, | 60 void Start(scoped_refptr<AudioFrameInput> audio_frame_input, |
65 scoped_refptr<VideoFrameInput> video_frame_input); | 61 scoped_refptr<VideoFrameInput> video_frame_input); |
66 | 62 |
67 const VideoSenderConfig& get_video_config() const { return video_config_; } | 63 const VideoSenderConfig& get_video_config() const { return video_config_; } |
68 | 64 |
69 scoped_refptr<media::VideoFrame> PopOldestInsertedVideoFrame(); | 65 scoped_refptr<media::VideoFrame> PopOldestInsertedVideoFrame(); |
70 | 66 |
71 private: | 67 private: |
72 bool is_transcoding_audio() const { return audio_stream_index_ >= 0; } | 68 bool is_transcoding_audio() const { return audio_stream_index_ >= 0; } |
73 bool is_transcoding_video() const { return video_stream_index_ >= 0; } | 69 bool is_transcoding_video() const { return video_stream_index_ >= 0; } |
74 | 70 |
75 void SendNextFrame(); | 71 void SendNextFrame(); |
76 void SendNextFakeFrame(); | 72 void SendNextFakeFrame(); |
77 | 73 |
78 void UpdateNextFrameSize(); | |
79 | |
80 // Return true if a frame was sent. | 74 // Return true if a frame was sent. |
81 bool SendNextTranscodedVideo(base::TimeDelta elapsed_time); | 75 bool SendNextTranscodedVideo(base::TimeDelta elapsed_time); |
82 | 76 |
83 // Return true if a frame was sent. | 77 // Return true if a frame was sent. |
84 bool SendNextTranscodedAudio(base::TimeDelta elapsed_time); | 78 bool SendNextTranscodedAudio(base::TimeDelta elapsed_time); |
85 | 79 |
86 // Helper methods to compute timestamps for the frame number specified. | 80 // Helper methods to compute timestamps for the frame number specified. |
87 base::TimeDelta VideoFrameTime(int frame_number); | 81 base::TimeDelta VideoFrameTime(int frame_number); |
88 | 82 |
89 base::TimeDelta ScaleTimestamp(base::TimeDelta timestamp); | 83 base::TimeDelta ScaleTimestamp(base::TimeDelta timestamp); |
(...skipping 13 matching lines...) Expand all Loading... |
103 void ProvideData(int frame_delay, media::AudioBus* output_bus); | 97 void ProvideData(int frame_delay, media::AudioBus* output_bus); |
104 | 98 |
105 AVStream* av_audio_stream(); | 99 AVStream* av_audio_stream(); |
106 AVStream* av_video_stream(); | 100 AVStream* av_video_stream(); |
107 AVCodecContext* av_audio_context(); | 101 AVCodecContext* av_audio_context(); |
108 AVCodecContext* av_video_context(); | 102 AVCodecContext* av_video_context(); |
109 | 103 |
110 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 104 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
111 const VideoSenderConfig video_config_; | 105 const VideoSenderConfig video_config_; |
112 const bool keep_frames_; | 106 const bool keep_frames_; |
113 bool variable_frame_size_mode_; | |
114 gfx::Size current_frame_size_; | |
115 base::TimeTicks next_frame_size_change_time_; | |
116 scoped_refptr<AudioFrameInput> audio_frame_input_; | 107 scoped_refptr<AudioFrameInput> audio_frame_input_; |
117 scoped_refptr<VideoFrameInput> video_frame_input_; | 108 scoped_refptr<VideoFrameInput> video_frame_input_; |
118 uint8 synthetic_count_; | 109 uint8 synthetic_count_; |
119 base::TickClock* const clock_; // Not owned by this class. | 110 base::TickClock* const clock_; // Not owned by this class. |
120 | 111 |
121 // Time when the stream starts. | 112 // Time when the stream starts. |
122 base::TimeTicks start_time_; | 113 base::TimeTicks start_time_; |
123 | 114 |
124 // The following three members are used only for fake frames. | 115 // The following three members are used only for fake frames. |
125 int audio_frame_count_; // Each audio frame is exactly 10ms. | 116 int audio_frame_count_; // Each audio frame is exactly 10ms. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // NOTE: Weak pointers must be invalidated before all other member variables. | 150 // NOTE: Weak pointers must be invalidated before all other member variables. |
160 base::WeakPtrFactory<FakeMediaSource> weak_factory_; | 151 base::WeakPtrFactory<FakeMediaSource> weak_factory_; |
161 | 152 |
162 DISALLOW_COPY_AND_ASSIGN(FakeMediaSource); | 153 DISALLOW_COPY_AND_ASSIGN(FakeMediaSource); |
163 }; | 154 }; |
164 | 155 |
165 } // namespace cast | 156 } // namespace cast |
166 } // namespace media | 157 } // namespace media |
167 | 158 |
168 #endif // MEDIA_CAST_TEST_FAKE_MEDIA_SOURCE_H_ | 159 #endif // MEDIA_CAST_TEST_FAKE_MEDIA_SOURCE_H_ |
OLD | NEW |