| Index: media/mojo/services/mojo_demuxer_stream_adapter.cc
|
| diff --git a/media/mojo/services/mojo_demuxer_stream_adapter.cc b/media/mojo/services/mojo_demuxer_stream_adapter.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0e9c246e0504b8a6885eafffa04c263fe8f02338
|
| --- /dev/null
|
| +++ b/media/mojo/services/mojo_demuxer_stream_adapter.cc
|
| @@ -0,0 +1,102 @@
|
| +// Copyright 2014 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 "media/mojo/services/mojo_demuxer_stream_adapter.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/callback_helpers.h"
|
| +#include "media/base/decoder_buffer.h"
|
| +#include "media/mojo/services/media_type_converters.h"
|
| +
|
| +namespace media {
|
| +
|
| +MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter(
|
| + mojo::DemuxerStreamPtr stream,
|
| + const base::Closure& stream_ready) : demuxer_stream_(stream.Pass()),
|
| + stream_ready_callback_(stream_ready),
|
| + weak_factory_(this) {
|
| + demuxer_stream_.set_client(this);
|
| +}
|
| +
|
| +MojoDemuxerStreamAdapter::~MojoDemuxerStreamAdapter() {
|
| +}
|
| +
|
| +void MojoDemuxerStreamAdapter::Read(const DemuxerStream::ReadCB& read_cb) {
|
| + // We shouldn't be holding on to a previous callback if a new Read() came in.
|
| + DCHECK(on_config_change_cb_.is_null());
|
| + demuxer_stream_->Read(base::Bind(&MojoDemuxerStreamAdapter::OnBufferReady,
|
| + weak_factory_.GetWeakPtr(),
|
| + read_cb));
|
| +}
|
| +
|
| +AudioDecoderConfig MojoDemuxerStreamAdapter::audio_decoder_config() {
|
| + DCHECK(!config_queue_.empty());
|
| + return config_queue_.front();
|
| +}
|
| +
|
| +VideoDecoderConfig MojoDemuxerStreamAdapter::video_decoder_config() {
|
| + DCHECK(false); // TODO(tim): Video unsupported.
|
| + return VideoDecoderConfig();
|
| +}
|
| +
|
| +media::DemuxerStream::Type MojoDemuxerStreamAdapter::type() {
|
| + return media::DemuxerStream::AUDIO;
|
| +}
|
| +
|
| +void MojoDemuxerStreamAdapter::EnableBitstreamConverter() {
|
| + NOTIMPLEMENTED();
|
| +}
|
| +
|
| +bool MojoDemuxerStreamAdapter::SupportsConfigChanges() {
|
| + return true;
|
| +}
|
| +
|
| +VideoRotation MojoDemuxerStreamAdapter::video_rotation() {
|
| + NOTIMPLEMENTED();
|
| + return VIDEO_ROTATION_0;
|
| +}
|
| +
|
| +void MojoDemuxerStreamAdapter::OnStreamReady(
|
| + mojo::ScopedDataPipeConsumerHandle pipe) {
|
| + // TODO(tim): We don't support pipe streaming yet.
|
| + DCHECK(!pipe.is_valid());
|
| + DCHECK(!config_queue_.empty());
|
| + stream_ready_callback_.Run();
|
| +}
|
| +
|
| +void MojoDemuxerStreamAdapter::OnAudioDecoderConfigChanged(
|
| + mojo::AudioDecoderConfigPtr config) {
|
| + config_queue_.push(config.To<media::AudioDecoderConfig>());
|
| +
|
| + if (!on_config_change_cb_.is_null())
|
| + base::ResetAndReturn(&on_config_change_cb_).Run();
|
| +}
|
| +
|
| +void MojoDemuxerStreamAdapter::OnBufferReady(
|
| + const ReadCB& read_cb,
|
| + mojo::DemuxerStream::Status status,
|
| + mojo::MediaDecoderBufferPtr buffer) {
|
| + DCHECK(on_config_change_cb_.is_null());
|
| + DCHECK(!config_queue_.empty());
|
| +
|
| + media::DemuxerStream::Status media_status(
|
| + static_cast<media::DemuxerStream::Status>(status));
|
| + scoped_refptr<media::DecoderBuffer> media_buffer(
|
| + buffer.To<scoped_refptr<media::DecoderBuffer> >());
|
| +
|
| + if (status == mojo::DemuxerStream::STATUS_CONFIG_CHANGED) {
|
| + DCHECK_GE(config_queue_.size(), 1U);
|
| + config_queue_.pop();
|
| +
|
| + // If the |config_queue_| is empty we need to wait for
|
| + // OnAudioDecoderConfigChanged before invoking |read_cb|.
|
| + if (config_queue_.empty()) {
|
| + on_config_change_cb_ = base::Bind(read_cb, media_status, media_buffer);
|
| + return;
|
| + }
|
| + }
|
| + read_cb.Run(media_status, media_buffer);
|
| +}
|
| +
|
| +} // namespace media
|
|
|