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

Side by Side Diff: webrtc/modules/video_coding/codecs/test/videoprocessor.h

Issue 2697583002: Style fixes: VideoProcessor and corresponding integration test. (Closed)
Patch Set: Fix compile for plot_videoprocessor_integrationtest.cc Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 20 matching lines...) Expand all
31 31
32 // Defines which frame types shall be excluded from packet loss and when. 32 // Defines which frame types shall be excluded from packet loss and when.
33 enum ExcludeFrameTypes { 33 enum ExcludeFrameTypes {
34 // Will exclude the first keyframe in the video sequence from packet loss. 34 // Will exclude the first keyframe in the video sequence from packet loss.
35 // Following keyframes will be targeted for packet loss. 35 // Following keyframes will be targeted for packet loss.
36 kExcludeOnlyFirstKeyFrame, 36 kExcludeOnlyFirstKeyFrame,
37 // Exclude all keyframes from packet loss, no matter where in the video 37 // Exclude all keyframes from packet loss, no matter where in the video
38 // sequence they occur. 38 // sequence they occur.
39 kExcludeAllKeyFrames 39 kExcludeAllKeyFrames
40 }; 40 };
41
41 // Returns a string representation of the enum value. 42 // Returns a string representation of the enum value.
42 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e); 43 const char* ExcludeFrameTypesToStr(ExcludeFrameTypes e);
43 44
44 // Test configuration for a test run 45 // Test configuration for a test run.
45 struct TestConfig { 46 struct TestConfig {
46 TestConfig(); 47 TestConfig();
47 ~TestConfig(); 48 ~TestConfig();
48 49
49 // Name of the test. This is purely metadata and does not affect 50 // Name of the test. This is purely metadata and does not affect
50 // the test in any way. 51 // the test in any way.
51 std::string name; 52 std::string name;
52 53
53 // More detailed description of the test. This is purely metadata and does 54 // More detailed description of the test. This is purely metadata and does
54 // not affect the test in any way. 55 // not affect the test in any way.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 class VideoProcessor { 130 class VideoProcessor {
130 public: 131 public:
131 virtual ~VideoProcessor() {} 132 virtual ~VideoProcessor() {}
132 133
133 // Performs initial calculations about frame size, sets up callbacks etc. 134 // Performs initial calculations about frame size, sets up callbacks etc.
134 // Returns false if an error has occurred, in addition to printing to stderr. 135 // Returns false if an error has occurred, in addition to printing to stderr.
135 virtual bool Init() = 0; 136 virtual bool Init() = 0;
136 137
137 // Processes a single frame. Returns true as long as there's more frames 138 // Processes a single frame. Returns true as long as there's more frames
138 // available in the source clip. 139 // available in the source clip.
139 // Frame number must be an integer >=0. 140 // Frame number must be an integer >= 0.
140 virtual bool ProcessFrame(int frame_number) = 0; 141 virtual bool ProcessFrame(int frame_number) = 0;
141 142
142 // Updates the encoder with the target bit rate and the frame rate. 143 // Updates the encoder with the target bit rate and the frame rate.
143 virtual void SetRates(int bit_rate, int frame_rate) = 0; 144 virtual void SetRates(int bit_rate, int frame_rate) = 0;
144 145
145 // Return the size of the encoded frame in bytes. Dropped frames by the 146 // Return the size of the encoded frame in bytes. Dropped frames by the
146 // encoder are regarded as zero size. 147 // encoder are regarded as zero size.
147 virtual size_t EncodedFrameSize() = 0; 148 virtual size_t EncodedFrameSize() = 0;
148 149
149 // Return the encoded frame type (key or delta). 150 // Return the encoded frame type (key or delta).
(...skipping 13 matching lines...) Expand all
163 FrameReader* frame_reader, 164 FrameReader* frame_reader,
164 FrameWriter* frame_writer, 165 FrameWriter* frame_writer,
165 PacketManipulator* packet_manipulator, 166 PacketManipulator* packet_manipulator,
166 const TestConfig& config, 167 const TestConfig& config,
167 Stats* stats); 168 Stats* stats);
168 virtual ~VideoProcessorImpl(); 169 virtual ~VideoProcessorImpl();
169 bool Init() override; 170 bool Init() override;
170 bool ProcessFrame(int frame_number) override; 171 bool ProcessFrame(int frame_number) override;
171 172
172 private: 173 private:
174 // Callback class required to implement according to the VideoEncoder API.
175 class VideoProcessorEncodeCompleteCallback
176 : public webrtc::EncodedImageCallback {
177 public:
178 explicit VideoProcessorEncodeCompleteCallback(VideoProcessorImpl* vp)
179 : video_processor_(vp) {}
180 Result OnEncodedImage(
181 const webrtc::EncodedImage& encoded_image,
182 const webrtc::CodecSpecificInfo* codec_specific_info,
183 const webrtc::RTPFragmentationHeader* fragmentation) override {
184 // Forward to parent class.
185 RTC_CHECK(codec_specific_info);
186 video_processor_->FrameEncoded(codec_specific_info->codecType,
187 encoded_image, fragmentation);
188 return Result(Result::OK, 0);
189 }
190
191 private:
192 VideoProcessorImpl* const video_processor_;
193 };
194
195 // Callback class required to implement according to the VideoDecoder API.
196 class VideoProcessorDecodeCompleteCallback
197 : public webrtc::DecodedImageCallback {
198 public:
199 explicit VideoProcessorDecodeCompleteCallback(VideoProcessorImpl* vp)
200 : video_processor_(vp) {}
201 int32_t Decoded(webrtc::VideoFrame& image) override {
202 // Forward to parent class.
203 video_processor_->FrameDecoded(image);
204 return 0;
205 }
206 int32_t Decoded(webrtc::VideoFrame& image,
207 int64_t decode_time_ms) override {
208 RTC_NOTREACHED();
209 return -1;
210 }
211 void Decoded(VideoFrame& frame,
212 rtc::Optional<int32_t> decode_time_ms,
213 rtc::Optional<uint8_t> qp) override {
214 RTC_NOTREACHED();
215 }
216
217 private:
218 VideoProcessorImpl* const video_processor_;
219 };
220
173 // Invoked by the callback when a frame has completed encoding. 221 // Invoked by the callback when a frame has completed encoding.
174 void FrameEncoded(webrtc::VideoCodecType codec, 222 void FrameEncoded(webrtc::VideoCodecType codec,
175 const webrtc::EncodedImage& encodedImage, 223 const webrtc::EncodedImage& encodedImage,
176 const webrtc::RTPFragmentationHeader* fragmentation); 224 const webrtc::RTPFragmentationHeader* fragmentation);
225
177 // Invoked by the callback when a frame has completed decoding. 226 // Invoked by the callback when a frame has completed decoding.
178 void FrameDecoded(const webrtc::VideoFrame& image); 227 void FrameDecoded(const webrtc::VideoFrame& image);
228
179 // Used for getting a 32-bit integer representing time 229 // Used for getting a 32-bit integer representing time
180 // (checks the size is within signed 32-bit bounds before casting it) 230 // (checks the size is within signed 32-bit bounds before casting it)
181 int GetElapsedTimeMicroseconds(int64_t start, int64_t stop); 231 int GetElapsedTimeMicroseconds(int64_t start, int64_t stop);
232
182 // Updates the encoder with the target bit rate and the frame rate. 233 // Updates the encoder with the target bit rate and the frame rate.
183 void SetRates(int bit_rate, int frame_rate) override; 234 void SetRates(int bit_rate, int frame_rate) override;
235
184 // Return the size of the encoded frame in bytes. 236 // Return the size of the encoded frame in bytes.
185 size_t EncodedFrameSize() override; 237 size_t EncodedFrameSize() override;
238
186 // Return the encoded frame type (key or delta). 239 // Return the encoded frame type (key or delta).
187 FrameType EncodedFrameType() override; 240 FrameType EncodedFrameType() override;
241
188 // Return the number of dropped frames. 242 // Return the number of dropped frames.
189 int NumberDroppedFrames() override; 243 int NumberDroppedFrames() override;
244
190 // Return the number of spatial resizes. 245 // Return the number of spatial resizes.
191 int NumberSpatialResizes() override; 246 int NumberSpatialResizes() override;
192 247
193 webrtc::VideoEncoder* const encoder_; 248 webrtc::VideoEncoder* const encoder_;
194 webrtc::VideoDecoder* const decoder_; 249 webrtc::VideoDecoder* const decoder_;
195 std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_; 250 std::unique_ptr<VideoBitrateAllocator> bitrate_allocator_;
196 FrameReader* const frame_reader_; 251 FrameReader* const frame_reader_;
197 FrameWriter* const frame_writer_; 252 FrameWriter* const frame_writer_;
198 PacketManipulator* const packet_manipulator_; 253 PacketManipulator* const packet_manipulator_;
199 const TestConfig& config_; 254 const TestConfig& config_;
200 Stats* stats_; 255 Stats* stats_;
201 256
202 std::unique_ptr<EncodedImageCallback> encode_callback_; 257 std::unique_ptr<EncodedImageCallback> encode_callback_;
203 std::unique_ptr<DecodedImageCallback> decode_callback_; 258 std::unique_ptr<DecodedImageCallback> decode_callback_;
259
204 // Keep track of the last successful frame, since we need to write that 260 // Keep track of the last successful frame, since we need to write that
205 // when decoding fails: 261 // when decoding fails.
206 std::unique_ptr<uint8_t[]> last_successful_frame_buffer_; 262 std::unique_ptr<uint8_t[]> last_successful_frame_buffer_;
207 // To keep track of if we have excluded the first key frame from packet loss: 263 // To keep track of if we have excluded the first key frame from packet loss.
208 bool first_key_frame_has_been_excluded_; 264 bool first_key_frame_has_been_excluded_;
209 // To tell the decoder previous frame have been dropped due to packet loss: 265 // To tell the decoder previous frame have been dropped due to packet loss.
210 bool last_frame_missing_; 266 bool last_frame_missing_;
211 // If Init() has executed successfully. 267 // If Init() has executed successfully.
212 bool initialized_; 268 bool initialized_;
213 size_t encoded_frame_size_; 269 size_t encoded_frame_size_;
214 FrameType encoded_frame_type_; 270 FrameType encoded_frame_type_;
215 int prev_time_stamp_; 271 int prev_time_stamp_;
216 int num_dropped_frames_; 272 int num_dropped_frames_;
217 int num_spatial_resizes_; 273 int num_spatial_resizes_;
218 int last_encoder_frame_width_; 274 int last_encoder_frame_width_;
219 int last_encoder_frame_height_; 275 int last_encoder_frame_height_;
220 276
221 // Statistics 277 // Statistics.
222 double bit_rate_factor_; // multiply frame length with this to get bit rate 278 double bit_rate_factor_; // Multiply frame length with this to get bit rate.
223 int64_t encode_start_ns_; 279 int64_t encode_start_ns_;
224 int64_t decode_start_ns_; 280 int64_t decode_start_ns_;
225
226 // Callback class required to implement according to the VideoEncoder API.
227 class VideoProcessorEncodeCompleteCallback
228 : public webrtc::EncodedImageCallback {
229 public:
230 explicit VideoProcessorEncodeCompleteCallback(VideoProcessorImpl* vp)
231 : video_processor_(vp) {}
232 Result OnEncodedImage(
233 const webrtc::EncodedImage& encoded_image,
234 const webrtc::CodecSpecificInfo* codec_specific_info,
235 const webrtc::RTPFragmentationHeader* fragmentation) override;
236
237 private:
238 VideoProcessorImpl* const video_processor_;
239 };
240
241 // Callback class required to implement according to the VideoDecoder API.
242 class VideoProcessorDecodeCompleteCallback
243 : public webrtc::DecodedImageCallback {
244 public:
245 explicit VideoProcessorDecodeCompleteCallback(VideoProcessorImpl* vp)
246 : video_processor_(vp) {}
247 int32_t Decoded(webrtc::VideoFrame& image) override;
248 int32_t Decoded(webrtc::VideoFrame& image,
249 int64_t decode_time_ms) override {
250 RTC_NOTREACHED();
251 return -1;
252 }
253 void Decoded(VideoFrame& frame,
254 rtc::Optional<int32_t> decode_time_ms,
255 rtc::Optional<uint8_t> qp) override {
256 RTC_NOTREACHED();
257 }
258
259 private:
260 VideoProcessorImpl* const video_processor_;
261 };
262 }; 281 };
263 282
264 } // namespace test 283 } // namespace test
265 } // namespace webrtc 284 } // namespace webrtc
266 285
267 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_ 286 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_TEST_VIDEOPROCESSOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698