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/services/mojo_demuxer_stream_adapter.h" | 5 #include "media/mojo/services/mojo_demuxer_stream_adapter.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" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
13 #include "media/base/decoder_buffer.h" | 13 #include "media/base/decoder_buffer.h" |
14 #include "media/mojo/common/media_type_converters.h" | 14 #include "media/mojo/common/media_type_converters.h" |
15 #include "mojo/public/cpp/system/data_pipe.h" | 15 #include "mojo/public/cpp/system/data_pipe.h" |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 | 18 |
19 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter( | 19 MojoDemuxerStreamAdapter::MojoDemuxerStreamAdapter( |
20 interfaces::DemuxerStreamPtr demuxer_stream, | 20 mojom::DemuxerStreamPtr demuxer_stream, |
21 const base::Closure& stream_ready_cb) | 21 const base::Closure& stream_ready_cb) |
22 : demuxer_stream_(std::move(demuxer_stream)), | 22 : demuxer_stream_(std::move(demuxer_stream)), |
23 stream_ready_cb_(stream_ready_cb), | 23 stream_ready_cb_(stream_ready_cb), |
24 type_(DemuxerStream::UNKNOWN), | 24 type_(DemuxerStream::UNKNOWN), |
25 weak_factory_(this) { | 25 weak_factory_(this) { |
26 DVLOG(1) << __FUNCTION__; | 26 DVLOG(1) << __FUNCTION__; |
27 demuxer_stream_->Initialize(base::Bind( | 27 demuxer_stream_->Initialize(base::Bind( |
28 &MojoDemuxerStreamAdapter::OnStreamReady, weak_factory_.GetWeakPtr())); | 28 &MojoDemuxerStreamAdapter::OnStreamReady, weak_factory_.GetWeakPtr())); |
29 } | 29 } |
30 | 30 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 return true; | 65 return true; |
66 } | 66 } |
67 | 67 |
68 VideoRotation MojoDemuxerStreamAdapter::video_rotation() { | 68 VideoRotation MojoDemuxerStreamAdapter::video_rotation() { |
69 NOTIMPLEMENTED(); | 69 NOTIMPLEMENTED(); |
70 return VIDEO_ROTATION_0; | 70 return VIDEO_ROTATION_0; |
71 } | 71 } |
72 | 72 |
73 // TODO(xhwang): Pass liveness here. | 73 // TODO(xhwang): Pass liveness here. |
74 void MojoDemuxerStreamAdapter::OnStreamReady( | 74 void MojoDemuxerStreamAdapter::OnStreamReady( |
75 interfaces::DemuxerStream::Type type, | 75 mojom::DemuxerStream::Type type, |
76 mojo::ScopedDataPipeConsumerHandle pipe, | 76 mojo::ScopedDataPipeConsumerHandle pipe, |
77 interfaces::AudioDecoderConfigPtr audio_config, | 77 mojom::AudioDecoderConfigPtr audio_config, |
78 interfaces::VideoDecoderConfigPtr video_config) { | 78 mojom::VideoDecoderConfigPtr video_config) { |
79 DVLOG(1) << __FUNCTION__; | 79 DVLOG(1) << __FUNCTION__; |
80 DCHECK(pipe.is_valid()); | 80 DCHECK(pipe.is_valid()); |
81 DCHECK_EQ(DemuxerStream::UNKNOWN, type_); | 81 DCHECK_EQ(DemuxerStream::UNKNOWN, type_); |
82 | 82 |
83 type_ = static_cast<DemuxerStream::Type>(type); | 83 type_ = static_cast<DemuxerStream::Type>(type); |
84 stream_pipe_ = std::move(pipe); | 84 stream_pipe_ = std::move(pipe); |
85 UpdateConfig(std::move(audio_config), std::move(video_config)); | 85 UpdateConfig(std::move(audio_config), std::move(video_config)); |
86 | 86 |
87 stream_ready_cb_.Run(); | 87 stream_ready_cb_.Run(); |
88 } | 88 } |
89 | 89 |
90 void MojoDemuxerStreamAdapter::OnBufferReady( | 90 void MojoDemuxerStreamAdapter::OnBufferReady( |
91 interfaces::DemuxerStream::Status status, | 91 mojom::DemuxerStream::Status status, |
92 interfaces::DecoderBufferPtr buffer, | 92 mojom::DecoderBufferPtr buffer, |
93 interfaces::AudioDecoderConfigPtr audio_config, | 93 mojom::AudioDecoderConfigPtr audio_config, |
94 interfaces::VideoDecoderConfigPtr video_config) { | 94 mojom::VideoDecoderConfigPtr video_config) { |
95 DVLOG(3) << __FUNCTION__; | 95 DVLOG(3) << __FUNCTION__; |
96 DCHECK(!read_cb_.is_null()); | 96 DCHECK(!read_cb_.is_null()); |
97 DCHECK_NE(type_, DemuxerStream::UNKNOWN); | 97 DCHECK_NE(type_, DemuxerStream::UNKNOWN); |
98 DCHECK(stream_pipe_.is_valid()); | 98 DCHECK(stream_pipe_.is_valid()); |
99 | 99 |
100 if (status == interfaces::DemuxerStream::Status::CONFIG_CHANGED) { | 100 if (status == mojom::DemuxerStream::Status::CONFIG_CHANGED) { |
101 UpdateConfig(std::move(audio_config), std::move(video_config)); | 101 UpdateConfig(std::move(audio_config), std::move(video_config)); |
102 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kConfigChanged, nullptr); | 102 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kConfigChanged, nullptr); |
103 return; | 103 return; |
104 } | 104 } |
105 | 105 |
106 if (status == interfaces::DemuxerStream::Status::ABORTED) { | 106 if (status == mojom::DemuxerStream::Status::ABORTED) { |
107 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, nullptr); | 107 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, nullptr); |
108 return; | 108 return; |
109 } | 109 } |
110 | 110 |
111 DCHECK_EQ(status, interfaces::DemuxerStream::Status::OK); | 111 DCHECK_EQ(status, mojom::DemuxerStream::Status::OK); |
112 scoped_refptr<DecoderBuffer> media_buffer( | 112 scoped_refptr<DecoderBuffer> media_buffer( |
113 buffer.To<scoped_refptr<DecoderBuffer>>()); | 113 buffer.To<scoped_refptr<DecoderBuffer>>()); |
114 | 114 |
115 if (!media_buffer->end_of_stream()) { | 115 if (!media_buffer->end_of_stream()) { |
116 DCHECK_GT(media_buffer->data_size(), 0u); | 116 DCHECK_GT(media_buffer->data_size(), 0u); |
117 | 117 |
118 // Wait for the data to become available in the DataPipe. | 118 // Wait for the data to become available in the DataPipe. |
119 MojoHandleSignalsState state; | 119 MojoHandleSignalsState state; |
120 CHECK_EQ(MOJO_RESULT_OK, | 120 CHECK_EQ(MOJO_RESULT_OK, |
121 MojoWait(stream_pipe_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 121 MojoWait(stream_pipe_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, |
122 MOJO_DEADLINE_INDEFINITE, &state)); | 122 MOJO_DEADLINE_INDEFINITE, &state)); |
123 CHECK_EQ(MOJO_HANDLE_SIGNAL_READABLE, state.satisfied_signals); | 123 CHECK_EQ(MOJO_HANDLE_SIGNAL_READABLE, state.satisfied_signals); |
124 | 124 |
125 // Read the inner data for the DecoderBuffer from our DataPipe. | 125 // Read the inner data for the DecoderBuffer from our DataPipe. |
126 uint32_t bytes_to_read = | 126 uint32_t bytes_to_read = |
127 base::checked_cast<uint32_t>(media_buffer->data_size()); | 127 base::checked_cast<uint32_t>(media_buffer->data_size()); |
128 uint32_t bytes_read = bytes_to_read; | 128 uint32_t bytes_read = bytes_to_read; |
129 CHECK_EQ(ReadDataRaw(stream_pipe_.get(), media_buffer->writable_data(), | 129 CHECK_EQ(ReadDataRaw(stream_pipe_.get(), media_buffer->writable_data(), |
130 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), | 130 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE), |
131 MOJO_RESULT_OK); | 131 MOJO_RESULT_OK); |
132 CHECK_EQ(bytes_to_read, bytes_read); | 132 CHECK_EQ(bytes_to_read, bytes_read); |
133 } | 133 } |
134 | 134 |
135 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kOk, media_buffer); | 135 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kOk, media_buffer); |
136 } | 136 } |
137 | 137 |
138 void MojoDemuxerStreamAdapter::UpdateConfig( | 138 void MojoDemuxerStreamAdapter::UpdateConfig( |
139 interfaces::AudioDecoderConfigPtr audio_config, | 139 mojom::AudioDecoderConfigPtr audio_config, |
140 interfaces::VideoDecoderConfigPtr video_config) { | 140 mojom::VideoDecoderConfigPtr video_config) { |
141 DCHECK_NE(type_, DemuxerStream::UNKNOWN); | 141 DCHECK_NE(type_, DemuxerStream::UNKNOWN); |
142 | 142 |
143 switch(type_) { | 143 switch(type_) { |
144 case DemuxerStream::AUDIO: | 144 case DemuxerStream::AUDIO: |
145 DCHECK(audio_config && !video_config); | 145 DCHECK(audio_config && !video_config); |
146 audio_config_ = audio_config.To<AudioDecoderConfig>(); | 146 audio_config_ = audio_config.To<AudioDecoderConfig>(); |
147 break; | 147 break; |
148 case DemuxerStream::VIDEO: | 148 case DemuxerStream::VIDEO: |
149 DCHECK(video_config && !audio_config); | 149 DCHECK(video_config && !audio_config); |
150 video_config_ = video_config.To<VideoDecoderConfig>(); | 150 video_config_ = video_config.To<VideoDecoderConfig>(); |
151 break; | 151 break; |
152 default: | 152 default: |
153 NOTREACHED(); | 153 NOTREACHED(); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 } // namespace media | 157 } // namespace media |
OLD | NEW |