Extend WavReader and WavWriter API.

Add ability to read and write wav files using rtc::PlatformFile instead
of file name.

Bug: webrtc:8946
Change-Id: If18d9465f2155a33547f800edbdac45971a0e878
Reviewed-on: https://webrtc-review.googlesource.com/61424
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22497}
This commit is contained in:
Artem Titov
2018-03-19 15:40:00 +01:00
committed by Commit Bot
parent 451dfdf6db
commit e62f600c42
11 changed files with 249 additions and 16 deletions

View File

@ -23,17 +23,21 @@
namespace rtc {
FILE* FdopenPlatformFileForWriting(PlatformFile file) {
return FdopenPlatformFile(file, "w");
}
#if defined(WEBRTC_WIN)
const PlatformFile kInvalidPlatformFileValue = INVALID_HANDLE_VALUE;
FILE* FdopenPlatformFileForWriting(PlatformFile file) {
FILE* FdopenPlatformFile(PlatformFile file, const char* modes) {
if (file == kInvalidPlatformFileValue)
return nullptr;
int fd = _open_osfhandle(reinterpret_cast<intptr_t>(file), 0);
if (fd < 0)
return nullptr;
return _fdopen(fd, "w");
return _fdopen(fd, modes);
}
bool ClosePlatformFile(PlatformFile file) {
@ -49,6 +53,11 @@ PlatformFile OpenPlatformFile(const std::string& path) {
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
}
PlatformFile OpenPlatformFileReadOnly(const std::string& path) {
return ::CreateFile(ToUtf16(path).c_str(), GENERIC_READ, FILE_SHARE_READ,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
}
PlatformFile CreatePlatformFile(const std::string& path) {
return ::CreateFile(ToUtf16(path).c_str(), GENERIC_READ | GENERIC_WRITE, 0,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
@ -58,8 +67,8 @@ PlatformFile CreatePlatformFile(const std::string& path) {
const PlatformFile kInvalidPlatformFileValue = -1;
FILE* FdopenPlatformFileForWriting(PlatformFile file) {
return fdopen(file, "w");
FILE* FdopenPlatformFile(PlatformFile file, const char* modes) {
return fdopen(file, modes);
}
bool ClosePlatformFile(PlatformFile file) {
@ -74,6 +83,10 @@ PlatformFile OpenPlatformFile(const std::string& path) {
return ::open(path.c_str(), O_RDWR);
}
PlatformFile OpenPlatformFileReadOnly(const std::string& path) {
return ::open(path.c_str(), O_RDONLY);
}
PlatformFile CreatePlatformFile(const std::string& path) {
return ::open(path.c_str(), O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
}