Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(817)

Unified Diff: media/audio/fake_audio_output_stream.cc

Issue 159167: Refactoring to share MockAudioOutputStream implementations across 3 platforms (Closed)
Patch Set: the same as before Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/fake_audio_output_stream.h ('k') | media/audio/linux/alsa_output.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/fake_audio_output_stream.cc
diff --git a/media/audio/fake_audio_output_stream.cc b/media/audio/fake_audio_output_stream.cc
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..6eb541788861d47fa52871aa418062a2638f9a1d 100644
--- a/media/audio/fake_audio_output_stream.cc
+++ b/media/audio/fake_audio_output_stream.cc
@@ -0,0 +1,72 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/at_exit.h"
+#include "media/audio/fake_audio_output_stream.h"
+
+bool FakeAudioOutputStream::has_created_fake_stream_ = false;
+FakeAudioOutputStream* FakeAudioOutputStream::last_fake_stream_ = NULL;
+
+// static
+AudioOutputStream* FakeAudioOutputStream::MakeFakeStream() {
+ if (!has_created_fake_stream_)
+ base::AtExitManager::RegisterCallback(&DestroyLastFakeStream, NULL);
+ has_created_fake_stream_ = true;
+
+ return new FakeAudioOutputStream();
+}
+
+// static
+FakeAudioOutputStream* FakeAudioOutputStream::GetLastFakeStream() {
+ return last_fake_stream_;
+}
+
+bool FakeAudioOutputStream::Open(size_t packet_size) {
+ if (packet_size < sizeof(int16))
+ return false;
+ packet_size_ = packet_size;
+ buffer_.reset(new char[packet_size_]);
+ return true;
+}
+
+void FakeAudioOutputStream::Start(AudioSourceCallback* callback) {
+ callback_ = callback;
+ memset(buffer_.get(), 0, packet_size_);
+ callback_->OnMoreData(this, buffer_.get(), packet_size_);
+}
+
+void FakeAudioOutputStream::Stop() {
+}
+
+void FakeAudioOutputStream::SetVolume(double left_level, double right_level) {
+ left_volume_ = left_level;
+ right_volume_ = right_level;
+}
+
+void FakeAudioOutputStream::GetVolume(double* left_level, double* right_level) {
+ *left_level = left_volume_;
+ *right_level = right_volume_;
+}
+
+void FakeAudioOutputStream::Close() {
+ callback_->OnClose(this);
+ callback_ = NULL;
+
+ if (last_fake_stream_)
+ delete last_fake_stream_;
+ last_fake_stream_ = this;
+}
+
+FakeAudioOutputStream::FakeAudioOutputStream()
+ : left_volume_(0),
+ right_volume_(0),
+ callback_(NULL),
+ packet_size_(0) {
+}
+
+// static
+void FakeAudioOutputStream::DestroyLastFakeStream(void* param) {
+ if (last_fake_stream_)
+ delete last_fake_stream_;
+}
« no previous file with comments | « media/audio/fake_audio_output_stream.h ('k') | media/audio/linux/alsa_output.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698