Commit 9e807eee authored by Qingwen Pi's avatar Qingwen Pi Committed by Commit Bot

[chromecast] Remove //media dep from AudioFader and AudioClockSimulator.

AudioFader and AudioClockSimulator are used by multizone/sync.

Bug: b/152069660
Change-Id: I0bcf8068c1fa0dacae3330bcdde8aa8878aac253
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2138119
Commit-Queue: Qingwen Pi <qwp@google.com>
Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757153}
parent b0920e58
......@@ -29,6 +29,20 @@ cast_source_set("processing") {
"audio_fader.cc",
"audio_fader.h",
"audio_provider.h",
"cast_audio_bus.cc",
"cast_audio_bus.h",
]
deps = [ "//base" ]
# Use fastest possible float math.
configs -= [ "//build/config/compiler:default_optimization" ]
configs += [ "//build/config/compiler:optimize_speed" ]
cflags = [ "-ffast-math" ]
}
cast_source_set("interleaved_channel_mixer") {
sources = [
"interleaved_channel_mixer.cc",
"interleaved_channel_mixer.h",
]
......@@ -37,11 +51,6 @@ cast_source_set("processing") {
"//base",
"//media",
]
# Use fastest possible float math.
configs -= [ "//build/config/compiler:default_optimization" ]
configs += [ "//build/config/compiler:optimize_speed" ]
cflags = [ "-ffast-math" ]
}
cast_source_set("audio") {
......@@ -164,6 +173,7 @@ cast_source_set("unittests") {
]
deps = [
":interleaved_channel_mixer",
":processing",
"//base",
"//media",
......
......@@ -8,7 +8,6 @@
#include <cmath>
#include "base/logging.h"
#include "media/base/audio_bus.h"
namespace chromecast {
namespace media {
......@@ -23,7 +22,7 @@ AudioClockSimulator::AudioClockSimulator(AudioProvider* provider)
sample_rate_(provider_->sample_rate()),
num_channels_(provider_->num_channels()),
scratch_buffer_(
::media::AudioBus::Create(num_channels_, kInterpolateWindow + 1)) {
CastAudioBus::Create(num_channels_, kInterpolateWindow + 1)) {
DCHECK(provider_);
DCHECK_GT(sample_rate_, 0);
DCHECK_GT(num_channels_, 0u);
......
......@@ -10,10 +10,7 @@
#include <memory>
#include "chromecast/media/audio/audio_provider.h"
namespace media {
class AudioBus;
} // namespace media
#include "chromecast/media/audio/cast_audio_bus.h"
namespace chromecast {
namespace media {
......@@ -122,7 +119,7 @@ class AudioClockSimulator : public AudioProvider {
// to interpolation.
// The |first_frame_filled_| member var tracks whether or not the first frame
// of the |scratch_buffer_| contains valid audio.
std::unique_ptr<::media::AudioBus> scratch_buffer_;
std::unique_ptr<CastAudioBus> scratch_buffer_;
};
} // namespace media
......
......@@ -8,7 +8,6 @@
#include "base/bits.h"
#include "base/logging.h"
#include "media/base/audio_bus.h"
namespace chromecast {
namespace media {
......@@ -42,7 +41,7 @@ AudioFader::AudioFader(AudioProvider* provider,
DCHECK_LE(num_channels_, kMaxChannels);
DCHECK_GT(sample_rate_, 0);
fade_buffer_ = ::media::AudioBus::Create(num_channels_, fade_frames_);
fade_buffer_ = CastAudioBus::Create(num_channels_, fade_frames_);
fade_buffer_->Zero();
}
......
......@@ -11,10 +11,7 @@
#include "base/macros.h"
#include "base/time/time.h"
#include "chromecast/media/audio/audio_provider.h"
namespace media {
class AudioBus;
} // namespace media
#include "chromecast/media/audio/cast_audio_bus.h"
namespace chromecast {
namespace media {
......@@ -87,7 +84,7 @@ class AudioFader : public AudioProvider {
const double playback_rate_;
State state_ = State::kSilent;
std::unique_ptr<::media::AudioBus> fade_buffer_;
std::unique_ptr<CastAudioBus> fade_buffer_;
int buffered_frames_ = 0;
int fade_frames_remaining_ = 0;
......
// Copyright 2020 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 "chromecast/media/audio/cast_audio_bus.h"
#include <cstring>
#include "base/memory/ptr_util.h"
namespace chromecast {
namespace media {
CastAudioBus::CastAudioBus(int channels, int frames) : frames_(frames) {
data_.reset(new float[channels * frames]);
channel_data_.reserve(channels);
for (int i = 0; i < channels; ++i)
channel_data_.push_back(data_.get() + i * frames);
}
CastAudioBus::~CastAudioBus() = default;
// static
std::unique_ptr<CastAudioBus> CastAudioBus::Create(int channels, int frames) {
return base::WrapUnique(new CastAudioBus(channels, frames));
}
void CastAudioBus::Zero() {
std::fill_n(data_.get(), frames() * channels(), 0);
}
} // namespace media
} // namespace chromecast
// Copyright 2020 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.
#ifndef CHROMECAST_MEDIA_AUDIO_CAST_AUDIO_BUS_H_
#define CHROMECAST_MEDIA_AUDIO_CAST_AUDIO_BUS_H_
#include <memory>
#include <vector>
namespace chromecast {
namespace media {
// This class is a simplified version of ::media::AudioBus without any
// dependency on //media.
class CastAudioBus {
public:
// Creates a new CastAudioBus and allocates |channels| of length |frames|.
static std::unique_ptr<CastAudioBus> Create(int channels, int frames);
// Returns a raw pointer to the requested channel.
float* channel(int channel) { return channel_data_[channel]; }
const float* channel(int channel) const { return channel_data_[channel]; }
// Returns the number of channels.
int channels() const { return static_cast<int>(channel_data_.size()); }
// Returns the number of frames.
int frames() const { return frames_; }
// Helper method for zeroing out all channels of audio data.
void Zero();
~CastAudioBus();
private:
CastAudioBus(int channels, int frames);
// Contiguous block of channel memory.
std::unique_ptr<float[]> data_;
// One float pointer per channel pointing to a contiguous block of memory for
// that channel.
std::vector<float*> channel_data_;
int frames_;
};
} // namespace media
} // namespace chromecast
#endif // CHROMECAST_MEDIA_AUDIO_CAST_AUDIO_BUS_H_
......@@ -72,6 +72,7 @@ cast_source_set("mixer") {
"//chromecast/base:chromecast_switches",
"//chromecast/base:thread_health_checker",
"//chromecast/media/audio:audio_io_thread",
"//chromecast/media/audio:interleaved_channel_mixer",
"//chromecast/media/audio:libcast_external_audio_pipeline_1.0",
"//chromecast/media/audio:processing",
"//chromecast/media/audio/mixer_service:common",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment