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_impl.h" | 5 #include "media/mojo/services/mojo_demuxer_stream_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "media/base/audio_decoder_config.h" | 11 #include "media/base/audio_decoder_config.h" |
11 #include "media/base/decoder_buffer.h" | 12 #include "media/base/decoder_buffer.h" |
12 #include "media/base/video_decoder_config.h" | 13 #include "media/base/video_decoder_config.h" |
13 #include "media/mojo/services/media_type_converters.h" | 14 #include "media/mojo/services/media_type_converters.h" |
14 #include "mojo/public/cpp/system/data_pipe.h" | 15 #include "mojo/public/cpp/system/data_pipe.h" |
15 | 16 |
16 namespace media { | 17 namespace media { |
17 | 18 |
18 MojoDemuxerStreamImpl::MojoDemuxerStreamImpl( | 19 MojoDemuxerStreamImpl::MojoDemuxerStreamImpl( |
19 media::DemuxerStream* stream, | 20 media::DemuxerStream* stream, |
20 mojo::InterfaceRequest<interfaces::DemuxerStream> request) | 21 mojo::InterfaceRequest<interfaces::DemuxerStream> request) |
21 : binding_(this, request.Pass()), stream_(stream), weak_factory_(this) {} | 22 : binding_(this, std::move(request)), |
| 23 stream_(stream), |
| 24 weak_factory_(this) {} |
22 | 25 |
23 MojoDemuxerStreamImpl::~MojoDemuxerStreamImpl() { | 26 MojoDemuxerStreamImpl::~MojoDemuxerStreamImpl() { |
24 } | 27 } |
25 | 28 |
26 // This is called when our DemuxerStreamClient has connected itself and is | 29 // This is called when our DemuxerStreamClient has connected itself and is |
27 // 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 |
28 // we are now ready for business. | 31 // we are now ready for business. |
29 void MojoDemuxerStreamImpl::Initialize(const InitializeCallback& callback) { | 32 void MojoDemuxerStreamImpl::Initialize(const InitializeCallback& callback) { |
30 DVLOG(2) << __FUNCTION__; | 33 DVLOG(2) << __FUNCTION__; |
31 MojoCreateDataPipeOptions options; | 34 MojoCreateDataPipeOptions options; |
32 options.struct_size = sizeof(MojoCreateDataPipeOptions); | 35 options.struct_size = sizeof(MojoCreateDataPipeOptions); |
33 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | 36 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
34 options.element_num_bytes = 1; | 37 options.element_num_bytes = 1; |
35 | 38 |
36 // Allocate DataPipe sizes based on content type to reduce overhead. If this | 39 // Allocate DataPipe sizes based on content type to reduce overhead. If this |
37 // is still too burdensome we can adjust for sample rate or resolution. | 40 // is still too burdensome we can adjust for sample rate or resolution. |
38 if (stream_->type() == media::DemuxerStream::VIDEO) { | 41 if (stream_->type() == media::DemuxerStream::VIDEO) { |
39 // Video can get quite large; at 4K, VP9 delivers packets which are ~1MB in | 42 // Video can get quite large; at 4K, VP9 delivers packets which are ~1MB in |
40 // size; so allow for 50% headroom. | 43 // size; so allow for 50% headroom. |
41 options.capacity_num_bytes = 1.5 * (1024 * 1024); | 44 options.capacity_num_bytes = 1.5 * (1024 * 1024); |
42 } else { | 45 } else { |
43 // Other types don't require a lot of room, so use a smaller pipe. | 46 // Other types don't require a lot of room, so use a smaller pipe. |
44 options.capacity_num_bytes = 512 * 1024; | 47 options.capacity_num_bytes = 512 * 1024; |
45 } | 48 } |
46 | 49 |
47 mojo::DataPipe data_pipe(options); | 50 mojo::DataPipe data_pipe(options); |
48 stream_pipe_ = data_pipe.producer_handle.Pass(); | 51 stream_pipe_ = std::move(data_pipe.producer_handle); |
49 | 52 |
50 // Prepare the initial config. | 53 // Prepare the initial config. |
51 interfaces::AudioDecoderConfigPtr audio_config; | 54 interfaces::AudioDecoderConfigPtr audio_config; |
52 interfaces::VideoDecoderConfigPtr video_config; | 55 interfaces::VideoDecoderConfigPtr video_config; |
53 if (stream_->type() == media::DemuxerStream::AUDIO) { | 56 if (stream_->type() == media::DemuxerStream::AUDIO) { |
54 audio_config = | 57 audio_config = |
55 interfaces::AudioDecoderConfig::From(stream_->audio_decoder_config()); | 58 interfaces::AudioDecoderConfig::From(stream_->audio_decoder_config()); |
56 } else if (stream_->type() == media::DemuxerStream::VIDEO) { | 59 } else if (stream_->type() == media::DemuxerStream::VIDEO) { |
57 video_config = | 60 video_config = |
58 interfaces::VideoDecoderConfig::From(stream_->video_decoder_config()); | 61 interfaces::VideoDecoderConfig::From(stream_->video_decoder_config()); |
59 } else { | 62 } else { |
60 NOTREACHED() << "Unsupported stream type: " << stream_->type(); | 63 NOTREACHED() << "Unsupported stream type: " << stream_->type(); |
61 return; | 64 return; |
62 } | 65 } |
63 | 66 |
64 callback.Run(static_cast<interfaces::DemuxerStream::Type>(stream_->type()), | 67 callback.Run(static_cast<interfaces::DemuxerStream::Type>(stream_->type()), |
65 data_pipe.consumer_handle.Pass(), audio_config.Pass(), | 68 std::move(data_pipe.consumer_handle), std::move(audio_config), |
66 video_config.Pass()); | 69 std::move(video_config)); |
67 } | 70 } |
68 | 71 |
69 void MojoDemuxerStreamImpl::Read(const ReadCallback& callback) { | 72 void MojoDemuxerStreamImpl::Read(const ReadCallback& callback) { |
70 stream_->Read(base::Bind(&MojoDemuxerStreamImpl::OnBufferReady, | 73 stream_->Read(base::Bind(&MojoDemuxerStreamImpl::OnBufferReady, |
71 weak_factory_.GetWeakPtr(), callback)); | 74 weak_factory_.GetWeakPtr(), callback)); |
72 } | 75 } |
73 | 76 |
74 void MojoDemuxerStreamImpl::OnBufferReady( | 77 void MojoDemuxerStreamImpl::OnBufferReady( |
75 const ReadCallback& callback, | 78 const ReadCallback& callback, |
76 media::DemuxerStream::Status status, | 79 media::DemuxerStream::Status status, |
(...skipping 10 matching lines...) Expand all Loading... |
87 interfaces::AudioDecoderConfig::From(stream_->audio_decoder_config()); | 90 interfaces::AudioDecoderConfig::From(stream_->audio_decoder_config()); |
88 } else if (stream_->type() == media::DemuxerStream::VIDEO) { | 91 } else if (stream_->type() == media::DemuxerStream::VIDEO) { |
89 video_config = | 92 video_config = |
90 interfaces::VideoDecoderConfig::From(stream_->video_decoder_config()); | 93 interfaces::VideoDecoderConfig::From(stream_->video_decoder_config()); |
91 } else { | 94 } else { |
92 NOTREACHED() << "Unsupported config change encountered for type: " | 95 NOTREACHED() << "Unsupported config change encountered for type: " |
93 << stream_->type(); | 96 << stream_->type(); |
94 } | 97 } |
95 | 98 |
96 callback.Run(interfaces::DemuxerStream::STATUS_CONFIG_CHANGED, | 99 callback.Run(interfaces::DemuxerStream::STATUS_CONFIG_CHANGED, |
97 interfaces::DecoderBufferPtr(), audio_config.Pass(), | 100 interfaces::DecoderBufferPtr(), std::move(audio_config), |
98 video_config.Pass()); | 101 std::move(video_config)); |
99 return; | 102 return; |
100 } | 103 } |
101 | 104 |
102 if (status == media::DemuxerStream::kAborted) { | 105 if (status == media::DemuxerStream::kAborted) { |
103 callback.Run(interfaces::DemuxerStream::STATUS_ABORTED, | 106 callback.Run(interfaces::DemuxerStream::STATUS_ABORTED, |
104 interfaces::DecoderBufferPtr(), audio_config.Pass(), | 107 interfaces::DecoderBufferPtr(), std::move(audio_config), |
105 video_config.Pass()); | 108 std::move(video_config)); |
106 return; | 109 return; |
107 } | 110 } |
108 | 111 |
109 DCHECK_EQ(status, media::DemuxerStream::kOk); | 112 DCHECK_EQ(status, media::DemuxerStream::kOk); |
110 if (!buffer->end_of_stream()) { | 113 if (!buffer->end_of_stream()) { |
111 DCHECK_GT(buffer->data_size(), 0); | 114 DCHECK_GT(buffer->data_size(), 0); |
112 // Serialize the data section of the DecoderBuffer into our pipe. | 115 // Serialize the data section of the DecoderBuffer into our pipe. |
113 uint32_t num_bytes = buffer->data_size(); | 116 uint32_t num_bytes = buffer->data_size(); |
114 CHECK_EQ(WriteDataRaw(stream_pipe_.get(), buffer->data(), &num_bytes, | 117 CHECK_EQ(WriteDataRaw(stream_pipe_.get(), buffer->data(), &num_bytes, |
115 MOJO_READ_DATA_FLAG_ALL_OR_NONE), | 118 MOJO_READ_DATA_FLAG_ALL_OR_NONE), |
116 MOJO_RESULT_OK); | 119 MOJO_RESULT_OK); |
117 CHECK_EQ(num_bytes, static_cast<uint32_t>(buffer->data_size())); | 120 CHECK_EQ(num_bytes, static_cast<uint32_t>(buffer->data_size())); |
118 } | 121 } |
119 | 122 |
120 // TODO(dalecurtis): Once we can write framed data to the DataPipe, fill via | 123 // TODO(dalecurtis): Once we can write framed data to the DataPipe, fill via |
121 // the producer handle and then read more to keep the pipe full. Waiting for | 124 // the producer handle and then read more to keep the pipe full. Waiting for |
122 // space can be accomplished using an AsyncWaiter. | 125 // space can be accomplished using an AsyncWaiter. |
123 callback.Run(static_cast<interfaces::DemuxerStream::Status>(status), | 126 callback.Run(static_cast<interfaces::DemuxerStream::Status>(status), |
124 interfaces::DecoderBuffer::From(buffer), audio_config.Pass(), | 127 interfaces::DecoderBuffer::From(buffer), std::move(audio_config), |
125 video_config.Pass()); | 128 std::move(video_config)); |
126 } | 129 } |
127 | 130 |
128 } // namespace media | 131 } // namespace media |
OLD | NEW |