blob: fcb1e0d598090079f8941807afd8654636d60a0d [file] [log] [blame]
// Copyright 2017 The Fuchsia 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 <memory>
#include <fbl/intrusive_wavl_tree.h>
#include <fbl/ref_counted.h>
#include "src/lib/fxl/logging.h"
#include "src/media/audio/audio_core/mixer/mixer.h"
namespace media::audio {
class AudioDevice;
class AudioObject;
struct AudioLinkSourceTag {};
struct AudioLinkDestTag {};
// AudioLink is the base class of two different versions of AudioLinks which join sources of audio
// (AudioRenderers, inputs, outputs-being-looped-back) to destinations (outputs and AudioCapturers).
// TODO(mpuryear): Finish docs.
class AudioLink : public fbl::RefCounted<AudioLink>,
public fbl::ContainableBaseClasses<
fbl::WAVLTreeContainable<fbl::RefPtr<AudioLink>, AudioLinkSourceTag>,
fbl::WAVLTreeContainable<fbl::RefPtr<AudioLink>, AudioLinkDestTag>> {
struct KeyTraits;
using Source = AudioLinkSourceTag;
using Dest = AudioLinkDestTag;
template <typename TagType>
using Set = fbl::TaggedWAVLTree<const AudioLink*, fbl::RefPtr<AudioLink>, TagType>;
enum class SourceType {
virtual ~AudioLink();
const fbl::RefPtr<AudioObject>& GetSource() const { return source_; }
const fbl::RefPtr<AudioObject>& GetDest() const { return dest_; }
SourceType source_type() const { return source_type_; }
// Sources invalidate links when they change format or go away.
void Invalidate() {; }
bool valid() const { return valid_.load(); }
// Bookkeeping access.
const std::unique_ptr<Bookkeeping>& bookkeeping() const { return bookkeeping_; }
void set_bookkeeping(std::unique_ptr<Bookkeeping> bookkeeping) {
FXL_DCHECK(bookkeeping_ == nullptr);
bookkeeping_ = std::move(bookkeeping);
AudioLink(SourceType source_type, fbl::RefPtr<AudioObject> source, fbl::RefPtr<AudioObject> dest);
friend struct fbl::DefaultKeyedObjectTraits<const AudioLink*, AudioLink>;
const AudioLink* GetKey() const { return this; }
const SourceType source_type_;
fbl::RefPtr<AudioObject> source_;
fbl::RefPtr<AudioObject> dest_;
std::unique_ptr<Bookkeeping> bookkeeping_;
std::atomic_bool valid_;
} // namespace media::audio