blob: 22cbe75613aebb2cbf4a307db926017579d61c53 [file] [log] [blame]
// Copyright 2018 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 "src/media/audio/audio_core/audio_packet_ref.h"
#include "src/lib/fxl/logging.h"
#include "src/media/audio/audio_core/audio_core_impl.h"
namespace media::audio {
AudioPacketRef::AudioPacketRef(
fbl::RefPtr<RefCountedVmoMapper> vmo_ref,
fuchsia::media::AudioRenderer::SendPacketCallback callback,
fuchsia::media::StreamPacket packet, AudioCoreImpl* service,
uint32_t frac_frame_len, int64_t start_pts)
: vmo_ref_(std::move(vmo_ref)),
callback_(std::move(callback)),
packet_(packet),
service_(service),
frac_frame_len_(frac_frame_len),
start_pts_(start_pts),
end_pts_(start_pts + frac_frame_len) {
FXL_DCHECK(service_);
FXL_DCHECK(vmo_ref_ != nullptr);
}
void AudioPacketRef::fbl_recycle() {
// If the packet is dying for the first time, and we successfully queue it for
// cleanup, allow it to live on until the cleanup actually runs. Otherwise
// the object is at its end of life.
if (!was_recycled_) {
was_recycled_ = true;
if (NeedsCleanup()) {
FXL_DCHECK(service_);
service_->SchedulePacketCleanup(std::unique_ptr<AudioPacketRef>(this));
return;
}
}
delete this;
}
} // namespace media::audio