mirror of https://github.com/auygun/kaliber.git
Move AudioSinkDelegate into AudioSink
This commit is contained in:
parent
a39efa5d3c
commit
76fb19ab3a
|
@ -8,7 +8,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "base/closure.h"
|
#include "base/closure.h"
|
||||||
#include "engine/audio/audio_sink_delegate.h"
|
#include "engine/audio/audio_sink.h"
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
class TaskRunner;
|
class TaskRunner;
|
||||||
|
@ -22,7 +22,7 @@ class AudioBus;
|
||||||
// Mix and render audio with low overhead. A platform specific AudioSink
|
// Mix and render audio with low overhead. A platform specific AudioSink
|
||||||
// implementation is expected to periodically call RenderAudio() in a background
|
// implementation is expected to periodically call RenderAudio() in a background
|
||||||
// thread.
|
// thread.
|
||||||
class AudioMixer : public AudioSinkDelegate {
|
class AudioMixer : public AudioSink::Delegate {
|
||||||
public:
|
public:
|
||||||
AudioMixer();
|
AudioMixer();
|
||||||
~AudioMixer();
|
~AudioMixer();
|
||||||
|
@ -91,7 +91,7 @@ class AudioMixer : public AudioSinkDelegate {
|
||||||
|
|
||||||
bool audio_enabled_ = true;
|
bool audio_enabled_ = true;
|
||||||
|
|
||||||
// AudioSinkDelegate implementation
|
// AudioSink::Delegate implementation
|
||||||
int GetChannelCount() final { return kChannelCount; }
|
int GetChannelCount() final { return kChannelCount; }
|
||||||
void RenderAudio(float* output_buffer, size_t num_frames) final;
|
void RenderAudio(float* output_buffer, size_t num_frames) final;
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,19 @@
|
||||||
namespace eng {
|
namespace eng {
|
||||||
|
|
||||||
// Models an audio sink sending mixed audio to the audio driver. Audio data from
|
// Models an audio sink sending mixed audio to the audio driver. Audio data from
|
||||||
// the mixer source is delivered on a pull model using AudioSinkDelegate.
|
// the mixer source is delivered on a pull model using Delegate.
|
||||||
class AudioSink {
|
class AudioSink {
|
||||||
public:
|
public:
|
||||||
|
class Delegate {
|
||||||
|
public:
|
||||||
|
Delegate() = default;
|
||||||
|
virtual ~Delegate() = default;
|
||||||
|
|
||||||
|
virtual int GetChannelCount() = 0;
|
||||||
|
|
||||||
|
virtual void RenderAudio(float* output_buffer, size_t num_frames) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
AudioSink() = default;
|
AudioSink() = default;
|
||||||
virtual ~AudioSink() = default;
|
virtual ~AudioSink() = default;
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,12 @@
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
|
|
||||||
#include "base/log.h"
|
#include "base/log.h"
|
||||||
#include "engine/audio/audio_sink_delegate.h"
|
|
||||||
|
|
||||||
using namespace base;
|
using namespace base;
|
||||||
|
|
||||||
namespace eng {
|
namespace eng {
|
||||||
|
|
||||||
AudioSinkAlsa::AudioSinkAlsa(AudioSinkDelegate* delegate)
|
AudioSinkAlsa::AudioSinkAlsa(AudioSink::Delegate* delegate)
|
||||||
: delegate_(delegate) {}
|
: delegate_(delegate) {}
|
||||||
|
|
||||||
AudioSinkAlsa::~AudioSinkAlsa() {
|
AudioSinkAlsa::~AudioSinkAlsa() {
|
||||||
|
|
|
@ -10,11 +10,9 @@ typedef struct _snd_pcm snd_pcm_t;
|
||||||
|
|
||||||
namespace eng {
|
namespace eng {
|
||||||
|
|
||||||
class AudioSinkDelegate;
|
|
||||||
|
|
||||||
class AudioSinkAlsa final : public AudioSink {
|
class AudioSinkAlsa final : public AudioSink {
|
||||||
public:
|
public:
|
||||||
AudioSinkAlsa(AudioSinkDelegate* delegate);
|
AudioSinkAlsa(AudioSink::Delegate* delegate);
|
||||||
~AudioSinkAlsa() final;
|
~AudioSinkAlsa() final;
|
||||||
|
|
||||||
bool Initialize() final;
|
bool Initialize() final;
|
||||||
|
@ -36,7 +34,7 @@ class AudioSinkAlsa final : public AudioSink {
|
||||||
size_t sample_rate_ = 0;
|
size_t sample_rate_ = 0;
|
||||||
size_t period_size_ = 0;
|
size_t period_size_ = 0;
|
||||||
|
|
||||||
AudioSinkDelegate* delegate_ = nullptr;
|
AudioSink::Delegate* delegate_ = nullptr;
|
||||||
|
|
||||||
void StartAudioThread();
|
void StartAudioThread();
|
||||||
void TerminateAudioThread();
|
void TerminateAudioThread();
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
#ifndef ENGINE_AUDIO_AUDIO_SINK_DELEGATE_H
|
|
||||||
#define ENGINE_AUDIO_AUDIO_SINK_DELEGATE_H
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
namespace eng {
|
|
||||||
|
|
||||||
class AudioSinkDelegate {
|
|
||||||
public:
|
|
||||||
AudioSinkDelegate() = default;
|
|
||||||
virtual ~AudioSinkDelegate() = default;
|
|
||||||
|
|
||||||
virtual int GetChannelCount() = 0;
|
|
||||||
|
|
||||||
virtual void RenderAudio(float* output_buffer, size_t num_frames) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace eng
|
|
||||||
|
|
||||||
#endif // ENGINE_AUDIO_AUDIO_SINK_DELEGATE_H
|
|
|
@ -1,14 +1,13 @@
|
||||||
#include "engine/audio/audio_sink_oboe.h"
|
#include "engine/audio/audio_sink_oboe.h"
|
||||||
|
|
||||||
#include "base/log.h"
|
#include "base/log.h"
|
||||||
#include "engine/audio/audio_sink_delegate.h"
|
|
||||||
#include "third_party/oboe/include/oboe/Oboe.h"
|
#include "third_party/oboe/include/oboe/Oboe.h"
|
||||||
|
|
||||||
using namespace base;
|
using namespace base;
|
||||||
|
|
||||||
namespace eng {
|
namespace eng {
|
||||||
|
|
||||||
AudioSinkOboe::AudioSinkOboe(AudioSinkDelegate* delegate)
|
AudioSinkOboe::AudioSinkOboe(AudioSink::Delegate* delegate)
|
||||||
: callback_(std::make_unique<StreamCallback>(this)), delegate_(delegate) {}
|
: callback_(std::make_unique<StreamCallback>(this)), delegate_(delegate) {}
|
||||||
|
|
||||||
AudioSinkOboe::~AudioSinkOboe() {
|
AudioSinkOboe::~AudioSinkOboe() {
|
||||||
|
|
|
@ -10,11 +10,9 @@
|
||||||
|
|
||||||
namespace eng {
|
namespace eng {
|
||||||
|
|
||||||
class AudioSinkDelegate;
|
|
||||||
|
|
||||||
class AudioSinkOboe final : public AudioSink {
|
class AudioSinkOboe final : public AudioSink {
|
||||||
public:
|
public:
|
||||||
AudioSinkOboe(AudioSinkDelegate* delegate);
|
AudioSinkOboe(AudioSink::Delegate* delegate);
|
||||||
~AudioSinkOboe() final;
|
~AudioSinkOboe() final;
|
||||||
|
|
||||||
bool Initialize() final;
|
bool Initialize() final;
|
||||||
|
@ -44,7 +42,7 @@ class AudioSinkOboe final : public AudioSink {
|
||||||
oboe::ManagedStream stream_;
|
oboe::ManagedStream stream_;
|
||||||
std::unique_ptr<StreamCallback> callback_;
|
std::unique_ptr<StreamCallback> callback_;
|
||||||
|
|
||||||
AudioSinkDelegate* delegate_ = nullptr;
|
AudioSink::Delegate* delegate_ = nullptr;
|
||||||
|
|
||||||
bool RestartStream();
|
bool RestartStream();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue