mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-15 23:01:21 +01:00

In https://webrtc-review.googlesource.com/c/src/+/1560 we moved WebRTC from src/webrtc to src/ (in order to preserve an healthy git history). This CL takes care of fixing header guards, #include paths, etc... NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true TBR=tommi@webrtc.org Bug: chromium:611808 Change-Id: Iea91618212bee0af16aa3f05071eab8f93706578 Reviewed-on: https://webrtc-review.googlesource.com/1561 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Henrik Kjellander <kjellander@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#19846}
96 lines
2.6 KiB
C++
96 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "modules/remote_bitrate_estimator/test/bwe_test_fileutils.h"
|
|
|
|
#ifdef WIN32
|
|
#include <Winsock2.h>
|
|
#else
|
|
#include <arpa/inet.h>
|
|
#endif
|
|
#include <assert.h>
|
|
|
|
#include "modules/remote_bitrate_estimator/test/bwe_test_logging.h"
|
|
#include "test/testsupport/fileutils.h"
|
|
|
|
namespace webrtc {
|
|
namespace testing {
|
|
namespace bwe {
|
|
|
|
ResourceFileReader::~ResourceFileReader() {
|
|
if (file_ != NULL) {
|
|
fclose(file_);
|
|
file_ = NULL;
|
|
}
|
|
}
|
|
|
|
bool ResourceFileReader::IsAtEnd() {
|
|
int32_t current_pos = ftell(file_);
|
|
fseek(file_, 0, SEEK_END);
|
|
int32_t end_pos = ftell(file_);
|
|
fseek(file_, current_pos, SEEK_SET);
|
|
return current_pos == end_pos;
|
|
}
|
|
|
|
bool ResourceFileReader::Read(uint32_t* out) {
|
|
assert(out);
|
|
uint32_t tmp = 0;
|
|
if (fread(&tmp, 1, sizeof(uint32_t), file_) != sizeof(uint32_t)) {
|
|
printf("Error reading!\n");
|
|
return false;
|
|
}
|
|
*out = ntohl(tmp);
|
|
return true;
|
|
}
|
|
|
|
ResourceFileReader* ResourceFileReader::Create(const std::string& filename,
|
|
const std::string& extension) {
|
|
std::string filepath = webrtc::test::ResourcePath(filename, extension);
|
|
FILE* file = fopen(filepath.c_str(), "rb");
|
|
if (file == NULL) {
|
|
BWE_TEST_LOGGING_CONTEXT("ResourceFileReader");
|
|
BWE_TEST_LOGGING_LOG1("Create", "Can't read file: %s", filepath.c_str());
|
|
return 0;
|
|
} else {
|
|
return new ResourceFileReader(file);
|
|
}
|
|
}
|
|
|
|
OutputFileWriter::~OutputFileWriter() {
|
|
if (file_ != NULL) {
|
|
fclose(file_);
|
|
file_ = NULL;
|
|
}
|
|
}
|
|
|
|
bool OutputFileWriter::Write(uint32_t value) {
|
|
uint32_t tmp = htonl(value);
|
|
if (fwrite(&tmp, 1, sizeof(uint32_t), file_) != sizeof(uint32_t)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
OutputFileWriter* OutputFileWriter::Create(const std::string& filename,
|
|
const std::string& extension) {
|
|
std::string filepath = webrtc::test::OutputPath() + filename + "." +
|
|
extension;
|
|
FILE* file = fopen(filepath.c_str(), "wb");
|
|
if (file == NULL) {
|
|
BWE_TEST_LOGGING_CONTEXT("OutputFileWriter");
|
|
BWE_TEST_LOGGING_LOG1("Create", "Can't write file: %s", filepath.c_str());
|
|
return NULL;
|
|
} else {
|
|
return new OutputFileWriter(file);
|
|
}
|
|
}
|
|
} // namespace bwe
|
|
} // namespace testing
|
|
} // namespace webrtc
|