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

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

Issue 2362683002: New helper function test::ReadI420Buffer, refactor FrameReader to use it. (Closed)
Patch Set: Another try to fix the 64-bit windows build. Created 4 years, 2 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 Stats* stats) 49 Stats* stats)
50 : encoder_(encoder), 50 : encoder_(encoder),
51 decoder_(decoder), 51 decoder_(decoder),
52 frame_reader_(frame_reader), 52 frame_reader_(frame_reader),
53 frame_writer_(frame_writer), 53 frame_writer_(frame_writer),
54 packet_manipulator_(packet_manipulator), 54 packet_manipulator_(packet_manipulator),
55 config_(config), 55 config_(config),
56 stats_(stats), 56 stats_(stats),
57 encode_callback_(NULL), 57 encode_callback_(NULL),
58 decode_callback_(NULL), 58 decode_callback_(NULL),
59 source_buffer_(NULL),
60 first_key_frame_has_been_excluded_(false), 59 first_key_frame_has_been_excluded_(false),
61 last_frame_missing_(false), 60 last_frame_missing_(false),
62 initialized_(false), 61 initialized_(false),
63 encoded_frame_size_(0), 62 encoded_frame_size_(0),
64 encoded_frame_type_(kVideoFrameKey), 63 encoded_frame_type_(kVideoFrameKey),
65 prev_time_stamp_(0), 64 prev_time_stamp_(0),
66 num_dropped_frames_(0), 65 num_dropped_frames_(0),
67 num_spatial_resizes_(0), 66 num_spatial_resizes_(0),
68 last_encoder_frame_width_(0), 67 last_encoder_frame_width_(0),
69 last_encoder_frame_height_(0) { 68 last_encoder_frame_height_(0) {
70 assert(encoder); 69 assert(encoder);
71 assert(decoder); 70 assert(decoder);
72 assert(frame_reader); 71 assert(frame_reader);
73 assert(frame_writer); 72 assert(frame_writer);
74 assert(packet_manipulator); 73 assert(packet_manipulator);
75 assert(stats); 74 assert(stats);
76 } 75 }
77 76
78 bool VideoProcessorImpl::Init() { 77 bool VideoProcessorImpl::Init() {
79 // Calculate a factor used for bit rate calculations: 78 // Calculate a factor used for bit rate calculations:
80 bit_rate_factor_ = config_.codec_settings->maxFramerate * 0.001 * 8; // bits 79 bit_rate_factor_ = config_.codec_settings->maxFramerate * 0.001 * 8; // bits
81 80
82 // Initialize data structures used by the encoder/decoder APIs 81 // Initialize data structures used by the encoder/decoder APIs
83 size_t frame_length_in_bytes = frame_reader_->FrameLength(); 82 size_t frame_length_in_bytes = frame_reader_->FrameLength();
84 source_buffer_ = new uint8_t[frame_length_in_bytes];
85 last_successful_frame_buffer_ = new uint8_t[frame_length_in_bytes]; 83 last_successful_frame_buffer_ = new uint8_t[frame_length_in_bytes];
86 // Set fixed properties common for all frames. 84 // Set fixed properties common for all frames.
87 // To keep track of spatial resize actions by encoder. 85 // To keep track of spatial resize actions by encoder.
88 last_encoder_frame_width_ = config_.codec_settings->width; 86 last_encoder_frame_width_ = config_.codec_settings->width;
89 last_encoder_frame_height_ = config_.codec_settings->height; 87 last_encoder_frame_height_ = config_.codec_settings->height;
90 88
91 // Setup required callbacks for the encoder/decoder: 89 // Setup required callbacks for the encoder/decoder:
92 encode_callback_ = new VideoProcessorEncodeCompleteCallback(this); 90 encode_callback_ = new VideoProcessorEncodeCompleteCallback(this);
93 decode_callback_ = new VideoProcessorDecodeCompleteCallback(this); 91 decode_callback_ = new VideoProcessorDecodeCompleteCallback(this);
94 int32_t register_result = 92 int32_t register_result =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 printf(" Start bitrate : %d kbps\n", 134 printf(" Start bitrate : %d kbps\n",
137 config_.codec_settings->startBitrate); 135 config_.codec_settings->startBitrate);
138 printf(" Width : %d\n", config_.codec_settings->width); 136 printf(" Width : %d\n", config_.codec_settings->width);
139 printf(" Height : %d\n", config_.codec_settings->height); 137 printf(" Height : %d\n", config_.codec_settings->height);
140 } 138 }
141 initialized_ = true; 139 initialized_ = true;
142 return true; 140 return true;
143 } 141 }
144 142
145 VideoProcessorImpl::~VideoProcessorImpl() { 143 VideoProcessorImpl::~VideoProcessorImpl() {
146 delete[] source_buffer_;
147 delete[] last_successful_frame_buffer_; 144 delete[] last_successful_frame_buffer_;
148 encoder_->RegisterEncodeCompleteCallback(NULL); 145 encoder_->RegisterEncodeCompleteCallback(NULL);
149 delete encode_callback_; 146 delete encode_callback_;
150 decoder_->RegisterDecodeCompleteCallback(NULL); 147 decoder_->RegisterDecodeCompleteCallback(NULL);
151 delete decode_callback_; 148 delete decode_callback_;
152 } 149 }
153 150
154 void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) { 151 void VideoProcessorImpl::SetRates(int bit_rate, int frame_rate) {
155 int set_rates_result = encoder_->SetRates(bit_rate, frame_rate); 152 int set_rates_result = encoder_->SetRates(bit_rate, frame_rate);
156 assert(set_rates_result >= 0); 153 assert(set_rates_result >= 0);
(...skipping 26 matching lines...) Expand all
183 bool VideoProcessorImpl::ProcessFrame(int frame_number) { 180 bool VideoProcessorImpl::ProcessFrame(int frame_number) {
184 assert(frame_number >= 0); 181 assert(frame_number >= 0);
185 if (!initialized_) { 182 if (!initialized_) {
186 fprintf(stderr, "Attempting to use uninitialized VideoProcessor!\n"); 183 fprintf(stderr, "Attempting to use uninitialized VideoProcessor!\n");
187 return false; 184 return false;
188 } 185 }
189 // |prev_time_stamp_| is used for getting number of dropped frames. 186 // |prev_time_stamp_| is used for getting number of dropped frames.
190 if (frame_number == 0) { 187 if (frame_number == 0) {
191 prev_time_stamp_ = -1; 188 prev_time_stamp_ = -1;
192 } 189 }
193 if (frame_reader_->ReadFrame(source_buffer_)) { 190 rtc::scoped_refptr<VideoFrameBuffer> buffer(frame_reader_->ReadFrame());
194 // Copy the source frame to the newly read frame data. 191 if (buffer) {
195 source_frame_.CreateFrame(source_buffer_, config_.codec_settings->width, 192 // Use the frame number as "timestamp" to identify frames
196 config_.codec_settings->height, kVideoRotation_0); 193 VideoFrame source_frame(buffer, frame_number, 0, webrtc::kVideoRotation_0);
197 194
198 // Ensure we have a new statistics data object we can fill: 195 // Ensure we have a new statistics data object we can fill:
199 FrameStatistic& stat = stats_->NewFrame(frame_number); 196 FrameStatistic& stat = stats_->NewFrame(frame_number);
200 197
201 encode_start_ns_ = rtc::TimeNanos(); 198 encode_start_ns_ = rtc::TimeNanos();
202 // Use the frame number as "timestamp" to identify frames
203 source_frame_.set_timestamp(frame_number);
204 199
205 // Decide if we're going to force a keyframe: 200 // Decide if we're going to force a keyframe:
206 std::vector<FrameType> frame_types(1, kVideoFrameDelta); 201 std::vector<FrameType> frame_types(1, kVideoFrameDelta);
207 if (config_.keyframe_interval > 0 && 202 if (config_.keyframe_interval > 0 &&
208 frame_number % config_.keyframe_interval == 0) { 203 frame_number % config_.keyframe_interval == 0) {
209 frame_types[0] = kVideoFrameKey; 204 frame_types[0] = kVideoFrameKey;
210 } 205 }
211 206
212 // For dropped frames, we regard them as zero size encoded frames. 207 // For dropped frames, we regard them as zero size encoded frames.
213 encoded_frame_size_ = 0; 208 encoded_frame_size_ = 0;
214 encoded_frame_type_ = kVideoFrameDelta; 209 encoded_frame_type_ = kVideoFrameDelta;
215 210
216 int32_t encode_result = encoder_->Encode(source_frame_, NULL, &frame_types); 211 int32_t encode_result = encoder_->Encode(source_frame, NULL, &frame_types);
217 212
218 if (encode_result != WEBRTC_VIDEO_CODEC_OK) { 213 if (encode_result != WEBRTC_VIDEO_CODEC_OK) {
219 fprintf(stderr, "Failed to encode frame %d, return code: %d\n", 214 fprintf(stderr, "Failed to encode frame %d, return code: %d\n",
220 frame_number, encode_result); 215 frame_number, encode_result);
221 } 216 }
222 stat.encode_return_code = encode_result; 217 stat.encode_return_code = encode_result;
223 return true; 218 return true;
224 } else { 219 } else {
225 return false; // we've reached the last frame 220 return false; // we've reached the last frame
226 } 221 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 419 }
425 int32_t VideoProcessorImpl::VideoProcessorDecodeCompleteCallback::Decoded( 420 int32_t VideoProcessorImpl::VideoProcessorDecodeCompleteCallback::Decoded(
426 VideoFrame& image) { 421 VideoFrame& image) {
427 // Forward to parent class. 422 // Forward to parent class.
428 video_processor_->FrameDecoded(image); 423 video_processor_->FrameDecoded(image);
429 return 0; 424 return 0;
430 } 425 }
431 426
432 } // namespace test 427 } // namespace test
433 } // namespace webrtc 428 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698