| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 "webrtc/modules/remote_bitrate_estimator/test/bwe_test_baselinefile.h" | 11 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_baselinefile.h" |
| 12 | 12 |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 #include <memory> |
| 16 #include <vector> | 17 #include <vector> |
| 17 | 18 |
| 18 #include "webrtc/base/constructormagic.h" | 19 #include "webrtc/base/constructormagic.h" |
| 19 #include "webrtc/base/scoped_ptr.h" | |
| 20 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_fileutils.h" | 20 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_fileutils.h" |
| 21 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" | 21 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" |
| 22 #include "webrtc/test/testsupport/fileutils.h" | 22 #include "webrtc/test/testsupport/fileutils.h" |
| 23 | 23 |
| 24 namespace webrtc { | 24 namespace webrtc { |
| 25 namespace testing { | 25 namespace testing { |
| 26 namespace bwe { | 26 namespace bwe { |
| 27 | 27 |
| 28 // The format of BWE test baseline files is extremely simple: | 28 // The format of BWE test baseline files is extremely simple: |
| 29 // 1. All read/written entities are 32-bit unsigned integers in network byte | 29 // 1. All read/written entities are 32-bit unsigned integers in network byte |
| 30 // order (Big Endian). | 30 // order (Big Endian). |
| 31 // 2. Files beging with a 2 word header containing a magic marker and file | 31 // 2. Files beging with a 2 word header containing a magic marker and file |
| 32 // format version indicator. The Magic marker reads "BWE!" in a hex dump. | 32 // format version indicator. The Magic marker reads "BWE!" in a hex dump. |
| 33 // 3. Each estimate is logged as a pair of words: time in milliseconds and | 33 // 3. Each estimate is logged as a pair of words: time in milliseconds and |
| 34 // estimated bit rate, in bits per second. | 34 // estimated bit rate, in bits per second. |
| 35 const uint32_t kMagicMarker = 0x42574521; | 35 const uint32_t kMagicMarker = 0x42574521; |
| 36 const uint32_t kFileVersion1 = 0x00000001; | 36 const uint32_t kFileVersion1 = 0x00000001; |
| 37 const char kResourceSubDir[] = "remote_bitrate_estimator"; | 37 const char kResourceSubDir[] = "remote_bitrate_estimator"; |
| 38 | 38 |
| 39 class BaseLineFileVerify : public BaseLineFileInterface { | 39 class BaseLineFileVerify : public BaseLineFileInterface { |
| 40 public: | 40 public: |
| 41 // If |allow_missing_file| is set, VerifyOrWrite() will return true even if | 41 // If |allow_missing_file| is set, VerifyOrWrite() will return true even if |
| 42 // the baseline file is missing. This is the default when verifying files, but | 42 // the baseline file is missing. This is the default when verifying files, but |
| 43 // not when updating (i.e. we always write it out if missing). | 43 // not when updating (i.e. we always write it out if missing). |
| 44 BaseLineFileVerify(const std::string& filepath, bool allow_missing_file) | 44 BaseLineFileVerify(const std::string& filepath, bool allow_missing_file) |
| 45 : reader_(), | 45 : reader_(), |
| 46 fail_to_read_response_(false) { | 46 fail_to_read_response_(false) { |
| 47 rtc::scoped_ptr<ResourceFileReader> reader; | 47 std::unique_ptr<ResourceFileReader> reader; |
| 48 reader.reset(ResourceFileReader::Create(filepath, "bin")); | 48 reader.reset(ResourceFileReader::Create(filepath, "bin")); |
| 49 if (!reader.get()) { | 49 if (!reader.get()) { |
| 50 printf("WARNING: Missing baseline file for BWE test: %s.bin\n", | 50 printf("WARNING: Missing baseline file for BWE test: %s.bin\n", |
| 51 filepath.c_str()); | 51 filepath.c_str()); |
| 52 fail_to_read_response_ = allow_missing_file; | 52 fail_to_read_response_ = allow_missing_file; |
| 53 } else { | 53 } else { |
| 54 uint32_t magic_marker = 0; | 54 uint32_t magic_marker = 0; |
| 55 uint32_t file_version = 0; | 55 uint32_t file_version = 0; |
| 56 if (reader->Read(&magic_marker) && magic_marker == kMagicMarker && | 56 if (reader->Read(&magic_marker) && magic_marker == kMagicMarker && |
| 57 reader->Read(&file_version) && file_version == kFileVersion1) { | 57 reader->Read(&file_version) && file_version == kFileVersion1) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 84 return true; | 84 return true; |
| 85 } else { | 85 } else { |
| 86 printf("ERROR: Baseline file contains more data!\n"); | 86 printf("ERROR: Baseline file contains more data!\n"); |
| 87 return false; | 87 return false; |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 return fail_to_read_response_; | 90 return fail_to_read_response_; |
| 91 } | 91 } |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 rtc::scoped_ptr<ResourceFileReader> reader_; | 94 std::unique_ptr<ResourceFileReader> reader_; |
| 95 bool fail_to_read_response_; | 95 bool fail_to_read_response_; |
| 96 | 96 |
| 97 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BaseLineFileVerify); | 97 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BaseLineFileVerify); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 class BaseLineFileUpdate : public BaseLineFileInterface { | 100 class BaseLineFileUpdate : public BaseLineFileInterface { |
| 101 public: | 101 public: |
| 102 BaseLineFileUpdate(const std::string& filepath, | 102 BaseLineFileUpdate(const std::string& filepath, |
| 103 BaseLineFileInterface* verifier) | 103 BaseLineFileInterface* verifier) |
| 104 : verifier_(verifier), | 104 : verifier_(verifier), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 115 output_content_.push_back(estimate_bps); | 115 output_content_.push_back(estimate_bps); |
| 116 } | 116 } |
| 117 | 117 |
| 118 virtual bool VerifyOrWrite() { | 118 virtual bool VerifyOrWrite() { |
| 119 if (!verifier_->VerifyOrWrite()) { | 119 if (!verifier_->VerifyOrWrite()) { |
| 120 std::string dir_path = webrtc::test::OutputPath() + kResourceSubDir; | 120 std::string dir_path = webrtc::test::OutputPath() + kResourceSubDir; |
| 121 if (!webrtc::test::CreateDir(dir_path)) { | 121 if (!webrtc::test::CreateDir(dir_path)) { |
| 122 printf("WARNING: Cannot create output dir: %s\n", dir_path.c_str()); | 122 printf("WARNING: Cannot create output dir: %s\n", dir_path.c_str()); |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 rtc::scoped_ptr<OutputFileWriter> writer; | 125 std::unique_ptr<OutputFileWriter> writer; |
| 126 writer.reset(OutputFileWriter::Create(filepath_, "bin")); | 126 writer.reset(OutputFileWriter::Create(filepath_, "bin")); |
| 127 if (!writer.get()) { | 127 if (!writer.get()) { |
| 128 printf("WARNING: Cannot create output file: %s.bin\n", | 128 printf("WARNING: Cannot create output file: %s.bin\n", |
| 129 filepath_.c_str()); | 129 filepath_.c_str()); |
| 130 return false; | 130 return false; |
| 131 } | 131 } |
| 132 printf("NOTE: Writing baseline file for BWE test: %s.bin\n", | 132 printf("NOTE: Writing baseline file for BWE test: %s.bin\n", |
| 133 filepath_.c_str()); | 133 filepath_.c_str()); |
| 134 for (std::vector<uint32_t>::iterator it = output_content_.begin(); | 134 for (std::vector<uint32_t>::iterator it = output_content_.begin(); |
| 135 it != output_content_.end(); ++it) { | 135 it != output_content_.end(); ++it) { |
| 136 writer->Write(*it); | 136 writer->Write(*it); |
| 137 } | 137 } |
| 138 return true; | 138 return true; |
| 139 } | 139 } |
| 140 printf("NOTE: No change, not writing: %s\n", filepath_.c_str()); | 140 printf("NOTE: No change, not writing: %s\n", filepath_.c_str()); |
| 141 return true; | 141 return true; |
| 142 } | 142 } |
| 143 | 143 |
| 144 private: | 144 private: |
| 145 rtc::scoped_ptr<BaseLineFileInterface> verifier_; | 145 std::unique_ptr<BaseLineFileInterface> verifier_; |
| 146 std::vector<uint32_t> output_content_; | 146 std::vector<uint32_t> output_content_; |
| 147 std::string filepath_; | 147 std::string filepath_; |
| 148 | 148 |
| 149 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BaseLineFileUpdate); | 149 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BaseLineFileUpdate); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 BaseLineFileInterface* BaseLineFileInterface::Create( | 152 BaseLineFileInterface* BaseLineFileInterface::Create( |
| 153 const std::string& filename, bool write_output_file) { | 153 const std::string& filename, bool write_output_file) { |
| 154 std::string filepath = filename; | 154 std::string filepath = filename; |
| 155 std::replace(filepath.begin(), filepath.end(), '/', '_'); | 155 std::replace(filepath.begin(), filepath.end(), '/', '_'); |
| 156 filepath = std::string(kResourceSubDir) + "/" + filepath; | 156 filepath = std::string(kResourceSubDir) + "/" + filepath; |
| 157 | 157 |
| 158 rtc::scoped_ptr<BaseLineFileInterface> result; | 158 std::unique_ptr<BaseLineFileInterface> result; |
| 159 result.reset(new BaseLineFileVerify(filepath, !write_output_file)); | 159 result.reset(new BaseLineFileVerify(filepath, !write_output_file)); |
| 160 if (write_output_file) { | 160 if (write_output_file) { |
| 161 // Takes ownership of the |verifier| instance. | 161 // Takes ownership of the |verifier| instance. |
| 162 result.reset(new BaseLineFileUpdate(filepath, result.release())); | 162 result.reset(new BaseLineFileUpdate(filepath, result.release())); |
| 163 } | 163 } |
| 164 return result.release(); | 164 return result.release(); |
| 165 } | 165 } |
| 166 } // namespace bwe | 166 } // namespace bwe |
| 167 } // namespace testing | 167 } // namespace testing |
| 168 } // namespace webrtc | 168 } // namespace webrtc |
| OLD | NEW |