OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/mojo/clients/mojo_demuxer_stream_impl.h" | 5 #include "media/mojo/clients/mojo_demuxer_stream_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 // This is called when our DemuxerStreamClient has connected itself and is | 29 // This is called when our DemuxerStreamClient has connected itself and is |
30 // ready to receive messages. Send an initial config and notify it that | 30 // ready to receive messages. Send an initial config and notify it that |
31 // we are now ready for business. | 31 // we are now ready for business. |
32 void MojoDemuxerStreamImpl::Initialize(const InitializeCallback& callback) { | 32 void MojoDemuxerStreamImpl::Initialize(const InitializeCallback& callback) { |
33 DVLOG(2) << __FUNCTION__; | 33 DVLOG(2) << __FUNCTION__; |
34 | 34 |
35 // Prepare the initial config. | 35 // Prepare the initial config. |
36 mojom::AudioDecoderConfigPtr audio_config; | 36 mojom::AudioDecoderConfigPtr audio_config; |
37 mojom::VideoDecoderConfigPtr video_config; | 37 mojom::VideoDecoderConfigPtr video_config; |
38 if (stream_->type() == media::DemuxerStream::AUDIO) { | 38 if (stream_->type() == Type::AUDIO) { |
39 audio_config = | 39 audio_config = |
40 mojom::AudioDecoderConfig::From(stream_->audio_decoder_config()); | 40 mojom::AudioDecoderConfig::From(stream_->audio_decoder_config()); |
41 } else if (stream_->type() == media::DemuxerStream::VIDEO) { | 41 } else if (stream_->type() == Type::VIDEO) { |
42 video_config = | 42 video_config = |
43 mojom::VideoDecoderConfig::From(stream_->video_decoder_config()); | 43 mojom::VideoDecoderConfig::From(stream_->video_decoder_config()); |
44 } else { | 44 } else { |
45 NOTREACHED() << "Unsupported stream type: " << stream_->type(); | 45 NOTREACHED() << "Unsupported stream type: " << stream_->type(); |
46 return; | 46 return; |
47 } | 47 } |
48 | 48 |
49 mojo::ScopedDataPipeConsumerHandle remote_consumer_handle; | 49 mojo::ScopedDataPipeConsumerHandle remote_consumer_handle; |
50 mojo_decoder_buffer_writer_ = | 50 mojo_decoder_buffer_writer_ = |
51 MojoDecoderBufferWriter::Create(stream_->type(), &remote_consumer_handle); | 51 MojoDecoderBufferWriter::Create(stream_->type(), &remote_consumer_handle); |
52 | 52 |
53 callback.Run(static_cast<mojom::DemuxerStream::Type>(stream_->type()), | 53 callback.Run(stream_->type(), std::move(remote_consumer_handle), |
54 std::move(remote_consumer_handle), std::move(audio_config), | 54 std::move(audio_config), std::move(video_config)); |
55 std::move(video_config)); | |
56 } | 55 } |
57 | 56 |
58 void MojoDemuxerStreamImpl::Read(const ReadCallback& callback) { | 57 void MojoDemuxerStreamImpl::Read(const ReadCallback& callback) { |
59 stream_->Read(base::Bind(&MojoDemuxerStreamImpl::OnBufferReady, | 58 stream_->Read(base::Bind(&MojoDemuxerStreamImpl::OnBufferReady, |
60 weak_factory_.GetWeakPtr(), callback)); | 59 weak_factory_.GetWeakPtr(), callback)); |
61 } | 60 } |
62 | 61 |
63 void MojoDemuxerStreamImpl::EnableBitstreamConverter() { | 62 void MojoDemuxerStreamImpl::EnableBitstreamConverter() { |
64 stream_->EnableBitstreamConverter(); | 63 stream_->EnableBitstreamConverter(); |
65 } | 64 } |
66 | 65 |
67 void MojoDemuxerStreamImpl::OnBufferReady( | 66 void MojoDemuxerStreamImpl::OnBufferReady( |
68 const ReadCallback& callback, | 67 const ReadCallback& callback, |
69 media::DemuxerStream::Status status, | 68 Status status, |
70 const scoped_refptr<media::DecoderBuffer>& buffer) { | 69 const scoped_refptr<media::DecoderBuffer>& buffer) { |
71 mojom::AudioDecoderConfigPtr audio_config; | 70 mojom::AudioDecoderConfigPtr audio_config; |
72 mojom::VideoDecoderConfigPtr video_config; | 71 mojom::VideoDecoderConfigPtr video_config; |
73 | 72 |
74 if (status == media::DemuxerStream::kConfigChanged) { | 73 if (status == Status::kConfigChanged) { |
75 DVLOG(2) << __FUNCTION__ << ": ConfigChange!"; | 74 DVLOG(2) << __FUNCTION__ << ": ConfigChange!"; |
76 // Send the config change so our client can read it once it parses the | 75 // Send the config change so our client can read it once it parses the |
77 // Status obtained via Run() below. | 76 // Status obtained via Run() below. |
78 if (stream_->type() == media::DemuxerStream::AUDIO) { | 77 if (stream_->type() == Type::AUDIO) { |
79 audio_config = | 78 audio_config = |
80 mojom::AudioDecoderConfig::From(stream_->audio_decoder_config()); | 79 mojom::AudioDecoderConfig::From(stream_->audio_decoder_config()); |
81 } else if (stream_->type() == media::DemuxerStream::VIDEO) { | 80 } else if (stream_->type() == Type::VIDEO) { |
82 video_config = | 81 video_config = |
83 mojom::VideoDecoderConfig::From(stream_->video_decoder_config()); | 82 mojom::VideoDecoderConfig::From(stream_->video_decoder_config()); |
84 } else { | 83 } else { |
85 NOTREACHED() << "Unsupported config change encountered for type: " | 84 NOTREACHED() << "Unsupported config change encountered for type: " |
86 << stream_->type(); | 85 << stream_->type(); |
87 } | 86 } |
88 | 87 |
89 callback.Run(mojom::DemuxerStream::Status::CONFIG_CHANGED, | 88 callback.Run(Status::kConfigChanged, mojom::DecoderBufferPtr(), |
90 mojom::DecoderBufferPtr(), std::move(audio_config), | 89 std::move(audio_config), std::move(video_config)); |
91 std::move(video_config)); | |
92 return; | 90 return; |
93 } | 91 } |
94 | 92 |
95 if (status == media::DemuxerStream::kAborted) { | 93 if (status == Status::kAborted) { |
96 callback.Run(mojom::DemuxerStream::Status::ABORTED, | 94 callback.Run(Status::kAborted, mojom::DecoderBufferPtr(), |
97 mojom::DecoderBufferPtr(), std::move(audio_config), | 95 std::move(audio_config), std::move(video_config)); |
98 std::move(video_config)); | |
99 return; | 96 return; |
100 } | 97 } |
101 | 98 |
102 DCHECK_EQ(status, media::DemuxerStream::kOk); | 99 DCHECK_EQ(status, Status::kOk); |
103 | 100 |
104 mojom::DecoderBufferPtr mojo_buffer = | 101 mojom::DecoderBufferPtr mojo_buffer = |
105 mojo_decoder_buffer_writer_->WriteDecoderBuffer(buffer); | 102 mojo_decoder_buffer_writer_->WriteDecoderBuffer(buffer); |
106 if (!mojo_buffer) { | 103 if (!mojo_buffer) { |
107 callback.Run(mojom::DemuxerStream::Status::ABORTED, | 104 callback.Run(Status::kAborted, mojom::DecoderBufferPtr(), |
108 mojom::DecoderBufferPtr(), std::move(audio_config), | 105 std::move(audio_config), std::move(video_config)); |
109 std::move(video_config)); | |
110 return; | 106 return; |
111 } | 107 } |
112 | 108 |
113 // TODO(dalecurtis): Once we can write framed data to the DataPipe, fill via | 109 // TODO(dalecurtis): Once we can write framed data to the DataPipe, fill via |
114 // the producer handle and then read more to keep the pipe full. Waiting for | 110 // the producer handle and then read more to keep the pipe full. Waiting for |
115 // space can be accomplished using an AsyncWaiter. | 111 // space can be accomplished using an AsyncWaiter. |
116 callback.Run(static_cast<mojom::DemuxerStream::Status>(status), | 112 callback.Run(status, std::move(mojo_buffer), std::move(audio_config), |
117 std::move(mojo_buffer), std::move(audio_config), | |
118 std::move(video_config)); | 113 std::move(video_config)); |
119 } | 114 } |
120 | 115 |
121 } // namespace media | 116 } // namespace media |
OLD | NEW |