summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhenrikg@webrtc.org <henrikg@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2013-12-06 16:05:17 +0000
committerhenrikg@webrtc.org <henrikg@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d>2013-12-06 16:05:17 +0000
commit7b72264dd14dcffb873d096339de6ed47015ac43 (patch)
treec651b094eec9d2f99ba613d8714b20d7228c6609
parent4383539b27ae877337679901c1cc9120f3a83fef (diff)
downloadwebrtc-7b72264dd14dcffb873d096339de6ed47015ac43.tar.gz
Allow opening an AEC dump from an existing file handle.
This is necessary for Chromium to be able enable the dump with the sanbox enabled. It will open the file in the browser process and pass the handle to the render process. This changes FileWrapper to deal with the case were the file handle is not managed by the wrapper. BUG=2567 R=andrew@webrtc.org, henrika@webrtc.org, perkj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/4649004 git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@5239 4adac7df-926f-26a2-2b94-8c16560cd09d
-rw-r--r--modules/audio_processing/audio_processing_impl.cc29
-rw-r--r--modules/audio_processing/audio_processing_impl.h1
-rw-r--r--modules/audio_processing/include/audio_processing.h5
-rw-r--r--modules/audio_processing/test/audio_processing_unittest.cc36
-rw-r--r--system_wrappers/interface/file_wrapper.h9
-rw-r--r--system_wrappers/source/file_impl.cc35
-rw-r--r--system_wrappers/source/file_impl.h6
-rw-r--r--voice_engine/include/voe_audio_processing.h6
-rw-r--r--voice_engine/voe_audio_processing_impl.cc11
-rw-r--r--voice_engine/voe_audio_processing_impl.h1
10 files changed, 134 insertions, 5 deletions
diff --git a/modules/audio_processing/audio_processing_impl.cc b/modules/audio_processing/audio_processing_impl.cc
index 2eb97bfd..4d36ff7e 100644
--- a/modules/audio_processing/audio_processing_impl.cc
+++ b/modules/audio_processing/audio_processing_impl.cc
@@ -540,6 +540,35 @@ int AudioProcessingImpl::StartDebugRecording(
#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
}
+int AudioProcessingImpl::StartDebugRecording(FILE* handle) {
+ CriticalSectionScoped crit_scoped(crit_);
+
+ if (handle == NULL) {
+ return kNullPointerError;
+ }
+
+#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
+ // Stop any ongoing recording.
+ if (debug_file_->Open()) {
+ if (debug_file_->CloseFile() == -1) {
+ return kFileError;
+ }
+ }
+
+ if (debug_file_->OpenFromFileHandle(handle, true, false) == -1) {
+ return kFileError;
+ }
+
+ int err = WriteInitMessage();
+ if (err != kNoError) {
+ return err;
+ }
+ return kNoError;
+#else
+ return kUnsupportedFunctionError;
+#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
+}
+
int AudioProcessingImpl::StopDebugRecording() {
CriticalSectionScoped crit_scoped(crit_);
diff --git a/modules/audio_processing/audio_processing_impl.h b/modules/audio_processing/audio_processing_impl.h
index 6c228781..e48a2c18 100644
--- a/modules/audio_processing/audio_processing_impl.h
+++ b/modules/audio_processing/audio_processing_impl.h
@@ -79,6 +79,7 @@ class AudioProcessingImpl : public AudioProcessing {
virtual int delay_offset_ms() const OVERRIDE;
virtual int StartDebugRecording(
const char filename[kMaxFilenameSize]) OVERRIDE;
+ virtual int StartDebugRecording(FILE* handle) OVERRIDE;
virtual int StopDebugRecording() OVERRIDE;
virtual EchoCancellation* echo_cancellation() const OVERRIDE;
virtual EchoControlMobile* echo_control_mobile() const OVERRIDE;
diff --git a/modules/audio_processing/include/audio_processing.h b/modules/audio_processing/include/audio_processing.h
index 82976499..b5c856de 100644
--- a/modules/audio_processing/include/audio_processing.h
+++ b/modules/audio_processing/include/audio_processing.h
@@ -12,6 +12,7 @@
#define WEBRTC_MODULES_AUDIO_PROCESSING_INCLUDE_AUDIO_PROCESSING_H_
#include <stddef.h> // size_t
+#include <stdio.h> // FILE
#include "webrtc/common.h"
#include "webrtc/modules/interface/module.h"
@@ -234,6 +235,10 @@ class AudioProcessing : public Module {
static const size_t kMaxFilenameSize = 1024;
virtual int StartDebugRecording(const char filename[kMaxFilenameSize]) = 0;
+ // Same as above but uses an existing file handle. Takes ownership
+ // of |handle| and closes it at StopDebugRecording().
+ virtual int StartDebugRecording(FILE* handle) = 0;
+
// Stops recording debugging information, and closes the file. Recording
// cannot be resumed in the same file (without overwriting it).
virtual int StopDebugRecording() = 0;
diff --git a/modules/audio_processing/test/audio_processing_unittest.cc b/modules/audio_processing/test/audio_processing_unittest.cc
index bb6bc2eb..a69574e0 100644
--- a/modules/audio_processing/test/audio_processing_unittest.cc
+++ b/modules/audio_processing/test/audio_processing_unittest.cc
@@ -1356,7 +1356,8 @@ TEST_F(ApmTest, SplittingFilter) {
// TODO(andrew): expand test to verify output.
TEST_F(ApmTest, DebugDump) {
const std::string filename = webrtc::test::OutputPath() + "debug.aec";
- EXPECT_EQ(apm_->kNullPointerError, apm_->StartDebugRecording(NULL));
+ EXPECT_EQ(apm_->kNullPointerError,
+ apm_->StartDebugRecording(static_cast<const char*>(NULL)));
#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
// Stopping without having started should be OK.
@@ -1384,6 +1385,39 @@ TEST_F(ApmTest, DebugDump) {
#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
}
+// TODO(andrew): expand test to verify output.
+TEST_F(ApmTest, DebugDumpFromFileHandle) {
+ FILE* fid = NULL;
+ EXPECT_EQ(apm_->kNullPointerError, apm_->StartDebugRecording(fid));
+ const std::string filename = webrtc::test::OutputPath() + "debug.aec";
+ fid = fopen(filename.c_str(), "w");
+ ASSERT_TRUE(fid);
+
+#ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP
+ // Stopping without having started should be OK.
+ EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
+
+ EXPECT_EQ(apm_->kNoError, apm_->StartDebugRecording(fid));
+ EXPECT_EQ(apm_->kNoError, apm_->AnalyzeReverseStream(revframe_));
+ EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
+ EXPECT_EQ(apm_->kNoError, apm_->StopDebugRecording());
+
+ // Verify the file has been written.
+ fid = fopen(filename.c_str(), "r");
+ ASSERT_TRUE(fid != NULL);
+
+ // Clean it up.
+ ASSERT_EQ(0, fclose(fid));
+ ASSERT_EQ(0, remove(filename.c_str()));
+#else
+ EXPECT_EQ(apm_->kUnsupportedFunctionError,
+ apm_->StartDebugRecording(fid));
+ EXPECT_EQ(apm_->kUnsupportedFunctionError, apm_->StopDebugRecording());
+
+ ASSERT_EQ(0, fclose(fid));
+#endif // WEBRTC_AUDIOPROC_DEBUG_DUMP
+}
+
// TODO(andrew): Add a test to process a few frames with different combinations
// of enabled components.
diff --git a/system_wrappers/interface/file_wrapper.h b/system_wrappers/interface/file_wrapper.h
index 5de6774a..68dc0050 100644
--- a/system_wrappers/interface/file_wrapper.h
+++ b/system_wrappers/interface/file_wrapper.h
@@ -12,6 +12,7 @@
#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FILE_WRAPPER_H_
#include <stddef.h>
+#include <stdio.h>
#include "webrtc/common_types.h"
#include "webrtc/typedefs.h"
@@ -37,6 +38,14 @@ class FileWrapper : public InStream, public OutStream {
bool loop = false,
bool text = false) = 0;
+ // Initializes the wrapper from an existing handle. |read_only| must match in
+ // the mode the file was opened in. If |manage_file| is true, the wrapper
+ // takes ownership of |handle| and closes it in CloseFile().
+ virtual int OpenFromFileHandle(FILE* handle,
+ bool manage_file,
+ bool read_only,
+ bool loop = false) = 0;
+
virtual int CloseFile() = 0;
// Limits the file size to |bytes|. Writing will fail after the cap
diff --git a/system_wrappers/source/file_impl.cc b/system_wrappers/source/file_impl.cc
index 190f3995..8b21b96e 100644
--- a/system_wrappers/source/file_impl.cc
+++ b/system_wrappers/source/file_impl.cc
@@ -30,6 +30,7 @@ FileWrapper* FileWrapper::Create() {
FileWrapperImpl::FileWrapperImpl()
: rw_lock_(RWLockWrapper::CreateRWLock()),
id_(NULL),
+ managed_file_handle_(true),
open_(false),
looping_(false),
read_only_(false),
@@ -39,7 +40,7 @@ FileWrapperImpl::FileWrapperImpl()
}
FileWrapperImpl::~FileWrapperImpl() {
- if (id_ != NULL) {
+ if (id_ != NULL && managed_file_handle_) {
fclose(id_);
}
}
@@ -71,8 +72,7 @@ int FileWrapperImpl::Flush() {
return FlushImpl();
}
-int FileWrapperImpl::FileName(char* file_name_utf8,
- size_t size) const {
+int FileWrapperImpl::FileName(char* file_name_utf8, size_t size) const {
ReadLockScoped read(*rw_lock_);
size_t length = strlen(file_name_utf8_);
if (length > kMaxFileNameSize) {
@@ -100,6 +100,8 @@ bool FileWrapperImpl::Open() const {
int FileWrapperImpl::OpenFile(const char* file_name_utf8, bool read_only,
bool loop, bool text) {
WriteLockScoped write(*rw_lock_);
+ if (id_ != NULL && !managed_file_handle_)
+ return -1;
size_t length = strlen(file_name_utf8);
if (length > kMaxFileNameSize - 1) {
return -1;
@@ -154,6 +156,7 @@ int FileWrapperImpl::OpenFile(const char* file_name_utf8, bool read_only,
fclose(id_);
}
id_ = tmp_id;
+ managed_file_handle_ = true;
looping_ = loop;
open_ = true;
return 0;
@@ -161,6 +164,29 @@ int FileWrapperImpl::OpenFile(const char* file_name_utf8, bool read_only,
return -1;
}
+int FileWrapperImpl::OpenFromFileHandle(FILE* handle,
+ bool manage_file,
+ bool read_only,
+ bool loop) {
+ WriteLockScoped write(*rw_lock_);
+ if (!handle)
+ return -1;
+
+ if (id_ != NULL) {
+ if (managed_file_handle_)
+ fclose(id_);
+ else
+ return -1;
+ }
+
+ id_ = handle;
+ managed_file_handle_ = manage_file;
+ read_only_ = read_only;
+ looping_ = loop;
+ open_ = true;
+ return 0;
+}
+
int FileWrapperImpl::Read(void* buf, int length) {
WriteLockScoped write(*rw_lock_);
if (length < 0)
@@ -233,7 +259,8 @@ bool FileWrapperImpl::Write(const void* buf, int length) {
int FileWrapperImpl::CloseFileImpl() {
if (id_ != NULL) {
- fclose(id_);
+ if (managed_file_handle_)
+ fclose(id_);
id_ = NULL;
}
memset(file_name_utf8_, 0, kMaxFileNameSize);
diff --git a/system_wrappers/source/file_impl.h b/system_wrappers/source/file_impl.h
index 8cc0979c..1abf0101 100644
--- a/system_wrappers/source/file_impl.h
+++ b/system_wrappers/source/file_impl.h
@@ -35,6 +35,11 @@ class FileWrapperImpl : public FileWrapper {
bool loop = false,
bool text = false) OVERRIDE;
+ virtual int OpenFromFileHandle(FILE* handle,
+ bool manage_file,
+ bool read_only,
+ bool loop = false) OVERRIDE;
+
virtual int CloseFile() OVERRIDE;
virtual int SetMaxFileSize(size_t bytes) OVERRIDE;
virtual int Flush() OVERRIDE;
@@ -51,6 +56,7 @@ class FileWrapperImpl : public FileWrapper {
scoped_ptr<RWLockWrapper> rw_lock_;
FILE* id_;
+ bool managed_file_handle_;
bool open_;
bool looping_;
bool read_only_;
diff --git a/voice_engine/include/voe_audio_processing.h b/voice_engine/include/voe_audio_processing.h
index 3ba7b1a2..8b40360a 100644
--- a/voice_engine/include/voe_audio_processing.h
+++ b/voice_engine/include/voe_audio_processing.h
@@ -35,6 +35,8 @@
#ifndef WEBRTC_VOICE_ENGINE_VOE_AUDIO_PROCESSING_H
#define WEBRTC_VOICE_ENGINE_VOE_AUDIO_PROCESSING_H
+#include <stdio.h>
+
#include "webrtc/common_types.h"
namespace webrtc {
@@ -191,6 +193,10 @@ public:
// The file can later be used for off-line analysis of the AP performance.
virtual int StartDebugRecording(const char* fileNameUTF8) = 0;
+ // Same as above but sets and uses an existing file handle. Takes ownership
+ // of |file_handle| and passes it on to the audio processing module.
+ virtual int StartDebugRecording(FILE* file_handle) = 0;
+
// Disables recording of AP debugging information.
virtual int StopDebugRecording() = 0;
diff --git a/voice_engine/voe_audio_processing_impl.cc b/voice_engine/voe_audio_processing_impl.cc
index a57ede93..63a4ed76 100644
--- a/voice_engine/voe_audio_processing_impl.cc
+++ b/voice_engine/voe_audio_processing_impl.cc
@@ -972,6 +972,17 @@ int VoEAudioProcessingImpl::StartDebugRecording(const char* fileNameUTF8) {
return _shared->audio_processing()->StartDebugRecording(fileNameUTF8);
}
+int VoEAudioProcessingImpl::StartDebugRecording(FILE* file_handle) {
+ WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
+ "StartDebugRecording()");
+ if (!_shared->statistics().Initialized()) {
+ _shared->SetLastError(VE_NOT_INITED, kTraceError);
+ return -1;
+ }
+
+ return _shared->audio_processing()->StartDebugRecording(file_handle);
+}
+
int VoEAudioProcessingImpl::StopDebugRecording() {
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"StopDebugRecording()");
diff --git a/voice_engine/voe_audio_processing_impl.h b/voice_engine/voe_audio_processing_impl.h
index 309d997b..524439d5 100644
--- a/voice_engine/voe_audio_processing_impl.h
+++ b/voice_engine/voe_audio_processing_impl.h
@@ -79,6 +79,7 @@ class VoEAudioProcessingImpl : public VoEAudioProcessing {
virtual int GetEcDelayMetrics(int& delay_median, int& delay_std);
virtual int StartDebugRecording(const char* fileNameUTF8);
+ virtual int StartDebugRecording(FILE* file_handle);
virtual int StopDebugRecording();