blob: 0943b15c701f5061ee507d88e93a5c9d828c1e10 [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 "src/media/audio/audio_core/audio_renderer_format_info.h"
#include "src/lib/fxl/logging.h"
#include "src/media/audio/audio_core/mixer/constants.h"
namespace media::audio {
AudioRendererFormatInfo::AudioRendererFormatInfo(fuchsia::media::AudioStreamType format)
: format_(format) {
// Precompute some useful timing/format stuff.
// Start with the ratio between frames and nanoseconds.
frames_per_ns_ = TimelineRate(format_.frames_per_second, ZX_SEC(1));
// Figure out the rate we need to scale by in order to produce our fixed point timestamps.
frame_to_media_ratio_ = TimelineRate(1 << kPtsFractionalBits, 1);
// Figure out the total number of bytes in a packed frame.
switch (format_.sample_format) {
case fuchsia::media::AudioSampleFormat::UNSIGNED_8:
bytes_per_frame_ = 1;
case fuchsia::media::AudioSampleFormat::SIGNED_16:
bytes_per_frame_ = 2;
case fuchsia::media::AudioSampleFormat::SIGNED_24_IN_32:
case fuchsia::media::AudioSampleFormat::FLOAT:
bytes_per_frame_ = 4;
// Format filtering was supposed to happen during AudioRendererImpl::SetStreamType. It should
// never be attempting to create a FormatInfo structure with a sample format that we do not
// understand.
FXL_CHECK(false) << "unrecognized sample format";
bytes_per_frame_ = 2;
bytes_per_frame_ *= format_.channels;
// static
fbl::RefPtr<AudioRendererFormatInfo> AudioRendererFormatInfo::Create(
fuchsia::media::AudioStreamType format) {
return fbl::AdoptRef(new AudioRendererFormatInfo(format));
} // namespace media::audio