Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: media/cast/test/fake_media_source.h

Issue 900913004: [cast/test] Use AudioConverter in FakeMediaSource to play back 6-channel WEBM's. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/cast/test/fake_media_source.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_
11 #define MEDIA_CAST_TEST_FAKE_MEDIA_SOURCE_H_ 11 #define MEDIA_CAST_TEST_FAKE_MEDIA_SOURCE_H_
12 12
13 #include <queue> 13 #include <queue>
14 14
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/memory_mapped_file.h" 16 #include "base/files/memory_mapped_file.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/time/tick_clock.h" 20 #include "base/time/tick_clock.h"
21 #include "media/audio/audio_parameters.h" 21 #include "media/audio/audio_parameters.h"
22 #include "media/base/audio_converter.h"
22 #include "media/cast/cast_config.h" 23 #include "media/cast/cast_config.h"
23 #include "media/filters/audio_renderer_algorithm.h" 24 #include "media/filters/audio_renderer_algorithm.h"
24 #include "media/filters/ffmpeg_demuxer.h" 25 #include "media/filters/ffmpeg_demuxer.h"
25 26
26 struct AVCodecContext; 27 struct AVCodecContext;
27 struct AVFormatContext; 28 struct AVFormatContext;
28 29
29 namespace media { 30 namespace media {
30 31
31 class AudioBus; 32 class AudioBus;
33 class AudioConverter;
32 class AudioFifo; 34 class AudioFifo;
33 class AudioTimestampHelper; 35 class AudioTimestampHelper;
34 class FFmpegGlue; 36 class FFmpegGlue;
35 class InMemoryUrlProtocol; 37 class InMemoryUrlProtocol;
36 class MultiChannelResampler;
37 38
38 namespace cast { 39 namespace cast {
39 40
40 class AudioFrameInput; 41 class AudioFrameInput;
41 class VideoFrameInput; 42 class VideoFrameInput;
42 class TestAudioBusFactory; 43 class TestAudioBusFactory;
43 44
44 class FakeMediaSource { 45 class FakeMediaSource : public media::AudioConverter::InputCallback {
45 public: 46 public:
46 // |task_runner| is to schedule decoding tasks. 47 // |task_runner| is to schedule decoding tasks.
47 // |clock| is used by this source but is not owned. 48 // |clock| is used by this source but is not owned.
49 // |audio_config| is the desired audio config.
48 // |video_config| is the desired video config. 50 // |video_config| is the desired video config.
49 // |keep_frames| is true if all VideoFrames are saved in a queue. 51 // |keep_frames| is true if all VideoFrames are saved in a queue.
50 FakeMediaSource(scoped_refptr<base::SingleThreadTaskRunner> task_runner, 52 FakeMediaSource(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
51 base::TickClock* clock, 53 base::TickClock* clock,
54 const AudioSenderConfig& audio_config,
52 const VideoSenderConfig& video_config, 55 const VideoSenderConfig& video_config,
53 bool keep_frames); 56 bool keep_frames);
54 ~FakeMediaSource(); 57 ~FakeMediaSource() override;
55 58
56 // Transcode this file as the source of video and audio frames. 59 // 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. 60 // 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); 61 void SetSourceFile(const base::FilePath& video_file, int override_fps);
59 62
60 // Set to true to randomly change the frame size at random points in time. 63 // Set to true to randomly change the frame size at random points in time.
61 // Only applies when SetSourceFile() is not used. 64 // Only applies when SetSourceFile() is not used.
62 void SetVariableFrameSizeMode(bool enabled); 65 void SetVariableFrameSizeMode(bool enabled);
63 66
64 void Start(scoped_refptr<AudioFrameInput> audio_frame_input, 67 void Start(scoped_refptr<AudioFrameInput> audio_frame_input,
(...skipping 28 matching lines...) Expand all
93 // Go to the beginning of the stream. 96 // Go to the beginning of the stream.
94 void Rewind(); 97 void Rewind();
95 98
96 // Call FFmpeg to fetch one packet. 99 // Call FFmpeg to fetch one packet.
97 ScopedAVPacket DemuxOnePacket(bool* audio); 100 ScopedAVPacket DemuxOnePacket(bool* audio);
98 101
99 void DecodeAudio(ScopedAVPacket packet); 102 void DecodeAudio(ScopedAVPacket packet);
100 void DecodeVideo(ScopedAVPacket packet); 103 void DecodeVideo(ScopedAVPacket packet);
101 void Decode(bool decode_audio); 104 void Decode(bool decode_audio);
102 105
103 void ProvideData(int frame_delay, media::AudioBus* output_bus); 106 // media::AudioConverter::InputCallback implementation.
107 double ProvideInput(media::AudioBus* output_bus, base::TimeDelta buffer_delay)
108 override;
104 109
105 AVStream* av_audio_stream(); 110 AVStream* av_audio_stream();
106 AVStream* av_video_stream(); 111 AVStream* av_video_stream();
107 AVCodecContext* av_audio_context(); 112 AVCodecContext* av_audio_context();
108 AVCodecContext* av_video_context(); 113 AVCodecContext* av_video_context();
109 114
110 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 115 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
116 const media::AudioParameters output_audio_params_;
111 const VideoSenderConfig video_config_; 117 const VideoSenderConfig video_config_;
112 const bool keep_frames_; 118 const bool keep_frames_;
113 bool variable_frame_size_mode_; 119 bool variable_frame_size_mode_;
114 gfx::Size current_frame_size_; 120 gfx::Size current_frame_size_;
115 base::TimeTicks next_frame_size_change_time_; 121 base::TimeTicks next_frame_size_change_time_;
116 scoped_refptr<AudioFrameInput> audio_frame_input_; 122 scoped_refptr<AudioFrameInput> audio_frame_input_;
117 scoped_refptr<VideoFrameInput> video_frame_input_; 123 scoped_refptr<VideoFrameInput> video_frame_input_;
118 uint8 synthetic_count_; 124 uint8 synthetic_count_;
119 base::TickClock* const clock_; // Not owned by this class. 125 base::TickClock* const clock_; // Not owned by this class.
120 126
121 // Time when the stream starts. 127 // Time when the stream starts.
122 base::TimeTicks start_time_; 128 base::TimeTicks start_time_;
123 129
124 // The following three members are used only for fake frames. 130 // The following three members are used only for fake frames.
125 int audio_frame_count_; // Each audio frame is exactly 10ms. 131 int audio_frame_count_; // Each audio frame is exactly 10ms.
126 int video_frame_count_; 132 int video_frame_count_;
127 scoped_ptr<TestAudioBusFactory> audio_bus_factory_; 133 scoped_ptr<TestAudioBusFactory> audio_bus_factory_;
128 134
129 base::MemoryMappedFile file_data_; 135 base::MemoryMappedFile file_data_;
130 scoped_ptr<InMemoryUrlProtocol> protocol_; 136 scoped_ptr<InMemoryUrlProtocol> protocol_;
131 scoped_ptr<FFmpegGlue> glue_; 137 scoped_ptr<FFmpegGlue> glue_;
132 AVFormatContext* av_format_context_; 138 AVFormatContext* av_format_context_;
133 139
134 int audio_stream_index_; 140 int audio_stream_index_;
135 AudioParameters audio_params_; 141 AudioParameters source_audio_params_;
136 double playback_rate_; 142 double playback_rate_;
137 143
138 int video_stream_index_; 144 int video_stream_index_;
139 int video_frame_rate_numerator_; 145 int video_frame_rate_numerator_;
140 int video_frame_rate_denominator_; 146 int video_frame_rate_denominator_;
141 147
142 // These are used for audio resampling. 148 // These are used for audio resampling.
143 scoped_ptr<media::MultiChannelResampler> audio_resampler_; 149 scoped_ptr<media::AudioConverter> audio_converter_;
144 scoped_ptr<media::AudioFifo> audio_fifo_; 150 scoped_ptr<media::AudioFifo> audio_fifo_;
145 scoped_ptr<media::AudioBus> audio_fifo_input_bus_; 151 scoped_ptr<media::AudioBus> audio_fifo_input_bus_;
146 media::AudioRendererAlgorithm audio_algo_; 152 media::AudioRendererAlgorithm audio_algo_;
147 153
148 // Track the timestamp of audio sent to the receiver. 154 // Track the timestamp of audio sent to the receiver.
149 scoped_ptr<media::AudioTimestampHelper> audio_sent_ts_; 155 scoped_ptr<media::AudioTimestampHelper> audio_sent_ts_;
150 156
151 std::queue<scoped_refptr<VideoFrame> > video_frame_queue_; 157 std::queue<scoped_refptr<VideoFrame> > video_frame_queue_;
152 std::queue<scoped_refptr<VideoFrame> > inserted_video_frame_queue_; 158 std::queue<scoped_refptr<VideoFrame> > inserted_video_frame_queue_;
153 int64 video_first_pts_; 159 int64 video_first_pts_;
154 bool video_first_pts_set_; 160 bool video_first_pts_set_;
155 base::TimeDelta last_video_frame_timestamp_; 161 base::TimeDelta last_video_frame_timestamp_;
156 162
157 std::queue<AudioBus*> audio_bus_queue_; 163 std::queue<AudioBus*> audio_bus_queue_;
158 164
159 // NOTE: Weak pointers must be invalidated before all other member variables. 165 // NOTE: Weak pointers must be invalidated before all other member variables.
160 base::WeakPtrFactory<FakeMediaSource> weak_factory_; 166 base::WeakPtrFactory<FakeMediaSource> weak_factory_;
161 167
162 DISALLOW_COPY_AND_ASSIGN(FakeMediaSource); 168 DISALLOW_COPY_AND_ASSIGN(FakeMediaSource);
163 }; 169 };
164 170
165 } // namespace cast 171 } // namespace cast
166 } // namespace media 172 } // namespace media
167 173
168 #endif // MEDIA_CAST_TEST_FAKE_MEDIA_SOURCE_H_ 174 #endif // MEDIA_CAST_TEST_FAKE_MEDIA_SOURCE_H_
OLDNEW
« no previous file with comments | « no previous file | media/cast/test/fake_media_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698