| Index: services/media/framework/stages/lpcm_stage_input.cc
|
| diff --git a/services/media/framework/stages/lpcm_stage_input.cc b/services/media/framework/stages/lpcm_stage_input.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..33366cac1f5790c26341ad7ad0ae5c9681005671
|
| --- /dev/null
|
| +++ b/services/media/framework/stages/lpcm_stage_input.cc
|
| @@ -0,0 +1,110 @@
|
| +// Copyright 2016 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 "services/media/framework/engine.h"
|
| +#include "services/media/framework/stages/lpcm_stage_input.h"
|
| +#include "services/media/framework/stages/lpcm_stage_output.h"
|
| +#include "services/media/framework/stages/stage.h"
|
| +
|
| +namespace mojo {
|
| +namespace media {
|
| +
|
| +LpcmStageInput::LpcmStageInput() :
|
| + frames_supplied_(false),
|
| + end_of_stream_(false),
|
| + remaining_packet_buffer_(nullptr),
|
| + remaining_packet_frames_(0) {}
|
| +
|
| +LpcmStageInput::~LpcmStageInput() {}
|
| +
|
| +void LpcmStageInput::set_lpcm_demand(
|
| + void* buffer,
|
| + uint64_t frames,
|
| + bool mix,
|
| + Engine& engine) {
|
| + DCHECK(connected());
|
| +
|
| + frames_supplied_ = false;
|
| + end_of_stream_ = false;
|
| +
|
| + LpcmStageOutput* lpcm_mate = mate().get_lpcm();
|
| + if (lpcm_mate != nullptr) {
|
| + // The upstream output is lpcm.
|
| + if (lpcm_mate->update_lpcm_demand_internal(buffer, frames, mix)) {
|
| + engine.PushToDemandBacklog(upstream_stage());
|
| + }
|
| + return;
|
| + }
|
| +
|
| + // The upstream output isn't lpcm. We need to get our frames from packets.
|
| + lpcm_demand_.frames_.buffer_ = buffer;
|
| + lpcm_demand_.frames_.frame_count_ = frames;
|
| + lpcm_demand_.mix_ = mix;
|
| + SupplyFramesFromPacket();
|
| +}
|
| +
|
| +bool LpcmStageInput::update_packet_internal(PacketPtr packet) {
|
| + StageInput::update_packet_internal(std::move(packet));
|
| + remaining_packet_frames_ = packet_from_upstream()->duration();
|
| + remaining_packet_buffer_ = packet_from_upstream()->payload();
|
| + return SupplyFramesFromPacket();
|
| +}
|
| +
|
| +LpcmStageInput* LpcmStageInput::get_lpcm() {
|
| + return this;
|
| +}
|
| +
|
| +bool LpcmStageInput::SupplyFramesFromPacket() {
|
| + if (lpcm_demand_.frames_.frame_count_ == 0 || remaining_packet_frames_ == 0) {
|
| + return false;
|
| + }
|
| +
|
| + uint64_t frames = std::min(
|
| + lpcm_demand_.frames_.frame_count_,
|
| + remaining_packet_frames_);
|
| + uint64_t bytes = frames * lpcm_demand_.frames_.bytes_per_frame_;
|
| +
|
| + if (lpcm_demand_.mix_) {
|
| + lpcm_util_->Mix(
|
| + remaining_packet_buffer_,
|
| + lpcm_demand_.frames_.buffer_,
|
| + frames);
|
| + } else {
|
| + lpcm_util_->Copy(
|
| + remaining_packet_buffer_,
|
| + lpcm_demand_.frames_.buffer_,
|
| + frames);
|
| + }
|
| +
|
| + lpcm_demand_.frames_.advance(frames);
|
| + remaining_packet_frames_ -= frames;
|
| + remaining_packet_buffer_ =
|
| + reinterpret_cast<uint8_t*>(remaining_packet_buffer_) + bytes;
|
| +
|
| + bool end_of_stream = false;
|
| +
|
| + if (remaining_packet_frames_ == 0) {
|
| + end_of_stream = packet_from_upstream()->end_of_stream();
|
| + if (end_of_stream && lpcm_demand_.frames_.frame_count_ != 0) {
|
| + if (!lpcm_demand_.mix_) {
|
| + lpcm_util_->Silence(
|
| + lpcm_demand_.frames_.buffer_,
|
| + lpcm_demand_.frames_.frame_count_);
|
| + }
|
| + lpcm_demand_.frames_.frame_count_ = 0;
|
| + }
|
| + packet_from_upstream().reset();
|
| + remaining_packet_buffer_ = nullptr;
|
| + }
|
| +
|
| + if (lpcm_demand_.frames_.frame_count_ == 0) {
|
| + lpcm_demand_.frames_.buffer_ = nullptr;
|
| + return supply_frames_internal(end_of_stream);
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| +} // namespace media
|
| +} // namespace mojo
|
|
|