| OLD | NEW |
| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "webrtc/base/checks.h" | 14 #include "webrtc/base/checks.h" |
| 15 #include "webrtc/base/timeutils.h" |
| 15 #include "webrtc/common_video/include/video_image.h" | 16 #include "webrtc/common_video/include/video_image.h" |
| 16 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 17 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 18 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
| 18 #include "webrtc/system_wrappers/include/tick_util.h" | |
| 19 #include "webrtc/test/testsupport/fileutils.h" | 19 #include "webrtc/test/testsupport/fileutils.h" |
| 20 #include "webrtc/test/testsupport/metrics/video_metrics.h" | 20 #include "webrtc/test/testsupport/metrics/video_metrics.h" |
| 21 #include "webrtc/tools/simple_command_line_parser.h" | 21 #include "webrtc/tools/simple_command_line_parser.h" |
| 22 #include "webrtc/video_frame.h" | 22 #include "webrtc/video_frame.h" |
| 23 | 23 |
| 24 class Vp8SequenceCoderEncodeCallback : public webrtc::EncodedImageCallback { | 24 class Vp8SequenceCoderEncodeCallback : public webrtc::EncodedImageCallback { |
| 25 public: | 25 public: |
| 26 explicit Vp8SequenceCoderEncodeCallback(FILE* encoded_file) | 26 explicit Vp8SequenceCoderEncodeCallback(FILE* encoded_file) |
| 27 : encoded_file_(encoded_file), encoded_bytes_(0) {} | 27 : encoded_file_(encoded_file), encoded_bytes_(0) {} |
| 28 ~Vp8SequenceCoderEncodeCallback(); | 28 ~Vp8SequenceCoderEncodeCallback(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 std::unique_ptr<uint8_t[]> frame_buffer(new uint8_t[length]); | 151 std::unique_ptr<uint8_t[]> frame_buffer(new uint8_t[length]); |
| 152 | 152 |
| 153 int half_width = (width + 1) / 2; | 153 int half_width = (width + 1) / 2; |
| 154 // Set and register callbacks. | 154 // Set and register callbacks. |
| 155 Vp8SequenceCoderEncodeCallback encoder_callback(encoded_file); | 155 Vp8SequenceCoderEncodeCallback encoder_callback(encoded_file); |
| 156 encoder->RegisterEncodeCompleteCallback(&encoder_callback); | 156 encoder->RegisterEncodeCompleteCallback(&encoder_callback); |
| 157 Vp8SequenceCoderDecodeCallback decoder_callback(output_file); | 157 Vp8SequenceCoderDecodeCallback decoder_callback(output_file); |
| 158 decoder->RegisterDecodeCompleteCallback(&decoder_callback); | 158 decoder->RegisterDecodeCompleteCallback(&decoder_callback); |
| 159 // Read->Encode->Decode sequence. | 159 // Read->Encode->Decode sequence. |
| 160 // num_frames = -1 implies unlimited encoding (entire sequence). | 160 // num_frames = -1 implies unlimited encoding (entire sequence). |
| 161 int64_t starttime = webrtc::TickTime::MillisecondTimestamp(); | 161 int64_t starttime = rtc::TimeMillis(); |
| 162 int frame_cnt = 1; | 162 int frame_cnt = 1; |
| 163 int frames_processed = 0; | 163 int frames_processed = 0; |
| 164 input_frame.CreateEmptyFrame(width, height, width, half_width, half_width); | 164 input_frame.CreateEmptyFrame(width, height, width, half_width, half_width); |
| 165 while (!feof(input_file) && | 165 while (!feof(input_file) && |
| 166 (num_frames == -1 || frames_processed < num_frames)) { | 166 (num_frames == -1 || frames_processed < num_frames)) { |
| 167 if (fread(frame_buffer.get(), 1, length, input_file) != length) | 167 if (fread(frame_buffer.get(), 1, length, input_file) != length) |
| 168 continue; | 168 continue; |
| 169 if (frame_cnt >= start_frame) { | 169 if (frame_cnt >= start_frame) { |
| 170 webrtc::ConvertToI420(webrtc::kI420, frame_buffer.get(), 0, 0, width, | 170 webrtc::ConvertToI420(webrtc::kI420, frame_buffer.get(), 0, 0, width, |
| 171 height, 0, webrtc::kVideoRotation_0, &input_frame); | 171 height, 0, webrtc::kVideoRotation_0, &input_frame); |
| 172 encoder->Encode(input_frame, NULL, NULL); | 172 encoder->Encode(input_frame, NULL, NULL); |
| 173 decoder->Decode(encoder_callback.encoded_image(), false, NULL); | 173 decoder->Decode(encoder_callback.encoded_image(), false, NULL); |
| 174 ++frames_processed; | 174 ++frames_processed; |
| 175 } | 175 } |
| 176 ++frame_cnt; | 176 ++frame_cnt; |
| 177 } | 177 } |
| 178 printf("\nProcessed %d frames\n", frames_processed); | 178 printf("\nProcessed %d frames\n", frames_processed); |
| 179 int64_t endtime = webrtc::TickTime::MillisecondTimestamp(); | 179 int64_t endtime = rtc::TimeMillis(); |
| 180 int64_t totalExecutionTime = endtime - starttime; | 180 int64_t totalExecutionTime = endtime - starttime; |
| 181 printf("Total execution time: %.2lf ms\n", | 181 printf("Total execution time: %.2lf ms\n", |
| 182 static_cast<double>(totalExecutionTime)); | 182 static_cast<double>(totalExecutionTime)); |
| 183 double actual_bit_rate = | 183 double actual_bit_rate = |
| 184 8.0 * encoder_callback.encoded_bytes() / (frame_cnt / inst.maxFramerate); | 184 8.0 * encoder_callback.encoded_bytes() / (frame_cnt / inst.maxFramerate); |
| 185 printf("Actual bitrate: %f kbps\n", actual_bit_rate / 1000); | 185 printf("Actual bitrate: %f kbps\n", actual_bit_rate / 1000); |
| 186 webrtc::test::QualityMetricsResult psnr_result, ssim_result; | 186 webrtc::test::QualityMetricsResult psnr_result, ssim_result; |
| 187 EXPECT_EQ(0, webrtc::test::I420MetricsFromFiles( | 187 EXPECT_EQ(0, webrtc::test::I420MetricsFromFiles( |
| 188 input_file_name.c_str(), output_file_name.c_str(), | 188 input_file_name.c_str(), output_file_name.c_str(), |
| 189 inst.width, inst.height, &psnr_result, &ssim_result)); | 189 inst.width, inst.height, &psnr_result, &ssim_result)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 237 |
| 238 parser.ProcessFlags(); | 238 parser.ProcessFlags(); |
| 239 if (parser.GetFlag("help") == "true") { | 239 if (parser.GetFlag("help") == "true") { |
| 240 parser.PrintUsageMessage(); | 240 parser.PrintUsageMessage(); |
| 241 exit(EXIT_SUCCESS); | 241 exit(EXIT_SUCCESS); |
| 242 } | 242 } |
| 243 parser.PrintEnteredFlags(); | 243 parser.PrintEnteredFlags(); |
| 244 | 244 |
| 245 return SequenceCoder(&parser); | 245 return SequenceCoder(&parser); |
| 246 } | 246 } |
| OLD | NEW |