| Index: services/media/framework/stages/lpcm_transform_stage.cc
|
| diff --git a/services/media/framework/stages/lpcm_transform_stage.cc b/services/media/framework/stages/lpcm_transform_stage.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..17a52fc24fdae6e3f394a13b497775908d07fad9
|
| --- /dev/null
|
| +++ b/services/media/framework/stages/lpcm_transform_stage.cc
|
| @@ -0,0 +1,72 @@
|
| +// 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/stages/lpcm_transform_stage.h"
|
| +
|
| +namespace mojo {
|
| +namespace media {
|
| +
|
| +LpcmTransformStage::LpcmTransformStage(
|
| + LpcmTransformPtr transform) :
|
| + transform_(transform),
|
| + input_packet_is_new_(true) {
|
| + DCHECK(transform_);
|
| + source_frames_.bytes_per_frame_ =
|
| + transform_->input_stream_type().bytes_per_frame();
|
| + output_.set_stream_type(transform_->output_stream_type());
|
| +}
|
| +
|
| +LpcmTransformStage::~LpcmTransformStage() {}
|
| +
|
| +bool LpcmTransformStage::Prepare(UpdateCallback update_callback) {
|
| + output_.Prepare(false);
|
| + input_.Prepare(nullptr, false);
|
| + return false;
|
| +}
|
| +
|
| +void LpcmTransformStage::Update(Engine& engine) {
|
| + PacketPtr& input_packet = input_.packet_from_upstream();
|
| +
|
| + if (input_packet) {
|
| + if (input_packet_is_new_) {
|
| + if (input_packet->size() == 0) {
|
| + if (input_packet->end_of_stream()) {
|
| + output_.supply_frames(true, engine);
|
| + }
|
| + input_packet.reset();
|
| + return;
|
| + }
|
| +
|
| + source_frames_.buffer_ = input_packet->payload();
|
| + source_frames_.frame_count_ = input_packet->duration();
|
| + input_packet_is_new_ = false;
|
| + }
|
| +
|
| + // TODO(dalesat): The transform should inform the demand hint.
|
| + LpcmDemand& demand =
|
| + output_.lpcm_demand_from_downstream(input_packet->duration());
|
| +
|
| + if (demand.frames_.frame_count_ != 0) {
|
| + transform_->TransformFrames(source_frames_, demand.frames_, demand.mix_);
|
| +
|
| + bool end_of_stream = false;
|
| +
|
| + if (source_frames_.frame_count_ == 0) {
|
| + end_of_stream = input_packet->end_of_stream();
|
| + source_frames_.buffer_ = nullptr;
|
| + input_packet.reset();
|
| + input_packet_is_new_ = true;
|
| + }
|
| +
|
| + if (demand.frames_.frame_count_ == 0 || end_of_stream) {
|
| + output_.supply_frames(end_of_stream, engine);
|
| + }
|
| + }
|
| + }
|
| +
|
| + input_.set_demand(output_.demand_from_downstream(), engine);
|
| +}
|
| +
|
| +} // namespace media
|
| +} // namespace mojo
|
|
|