Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: media/mojo/clients/mojo_video_decoder.cc

Issue 2429723006: MojoVideoDecoder: Plumb metadata methods. (Closed)
Patch Set: Actually early return. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/mojo/clients/mojo_video_decoder.h ('k') | media/mojo/interfaces/video_decoder.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_video_decoder.h" 5 #include "media/mojo/clients/mojo_video_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 14 matching lines...) Expand all
25 : task_runner_(task_runner), 25 : task_runner_(task_runner),
26 gpu_factories_(gpu_factories), 26 gpu_factories_(gpu_factories),
27 remote_decoder_info_(remote_decoder.PassInterface()), 27 remote_decoder_info_(remote_decoder.PassInterface()),
28 client_binding_(this) { 28 client_binding_(this) {
29 (void)gpu_factories_; 29 (void)gpu_factories_;
30 DVLOG(1) << __FUNCTION__; 30 DVLOG(1) << __FUNCTION__;
31 } 31 }
32 32
33 MojoVideoDecoder::~MojoVideoDecoder() { 33 MojoVideoDecoder::~MojoVideoDecoder() {
34 DVLOG(1) << __FUNCTION__; 34 DVLOG(1) << __FUNCTION__;
35 Stop();
35 } 36 }
36 37
37 std::string MojoVideoDecoder::GetDisplayName() const { 38 std::string MojoVideoDecoder::GetDisplayName() const {
39 // TODO(sandersd): Build the name including information from the remote end.
38 return "MojoVideoDecoder"; 40 return "MojoVideoDecoder";
39 } 41 }
40 42
41 void MojoVideoDecoder::Initialize(const VideoDecoderConfig& config, 43 void MojoVideoDecoder::Initialize(const VideoDecoderConfig& config,
42 bool low_delay, 44 bool low_delay,
43 CdmContext* cdm_context, 45 CdmContext* cdm_context,
44 const InitCB& init_cb, 46 const InitCB& init_cb,
45 const OutputCB& output_cb) { 47 const OutputCB& output_cb) {
46 DVLOG(1) << __FUNCTION__; 48 DVLOG(1) << __FUNCTION__;
47 DCHECK(task_runner_->BelongsToCurrentThread()); 49 DCHECK(task_runner_->BelongsToCurrentThread());
48 DCHECK(!cdm_context); 50 DCHECK(!cdm_context);
49 51
50 if (!remote_decoder_bound_) 52 if (!remote_decoder_bound_)
51 BindRemoteDecoder(); 53 BindRemoteDecoder();
52 54
53 if (has_connection_error_) { 55 if (has_connection_error_) {
54 task_runner_->PostTask(FROM_HERE, base::Bind(init_cb, false)); 56 task_runner_->PostTask(FROM_HERE, base::Bind(init_cb, false));
55 return; 57 return;
56 } 58 }
57 59
60 initialized_ = false;
58 init_cb_ = init_cb; 61 init_cb_ = init_cb;
59 output_cb_ = output_cb; 62 output_cb_ = output_cb;
60 remote_decoder_->Initialize( 63 remote_decoder_->Initialize(
61 mojom::VideoDecoderConfig::From(config), low_delay, 64 mojom::VideoDecoderConfig::From(config), low_delay,
62 base::Bind(&MojoVideoDecoder::OnInitializeDone, base::Unretained(this))); 65 base::Bind(&MojoVideoDecoder::OnInitializeDone, base::Unretained(this)));
63 } 66 }
64 67
65 // TODO(sandersd): Remove this indirection once a working decoder has been 68 void MojoVideoDecoder::OnInitializeDone(bool status,
66 // brought up. 69 bool needs_bitstream_conversion,
67 void MojoVideoDecoder::OnInitializeDone(bool status) { 70 int32_t max_decode_requests) {
68 DVLOG(1) << __FUNCTION__; 71 DVLOG(1) << __FUNCTION__;
69 DCHECK(task_runner_->BelongsToCurrentThread()); 72 DCHECK(task_runner_->BelongsToCurrentThread());
73 initialized_ = status;
74 needs_bitstream_conversion_ = needs_bitstream_conversion;
75 max_decode_requests_ = max_decode_requests;
70 base::ResetAndReturn(&init_cb_).Run(status); 76 base::ResetAndReturn(&init_cb_).Run(status);
71 } 77 }
72 78
73 void MojoVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer, 79 void MojoVideoDecoder::Decode(const scoped_refptr<DecoderBuffer>& buffer,
74 const DecodeCB& decode_cb) { 80 const DecodeCB& decode_cb) {
75 DVLOG(1) << __FUNCTION__; 81 DVLOG(2) << __FUNCTION__;
76 DCHECK(task_runner_->BelongsToCurrentThread()); 82 DCHECK(task_runner_->BelongsToCurrentThread());
77 83
78 if (has_connection_error_) { 84 if (has_connection_error_) {
79 task_runner_->PostTask(FROM_HERE, 85 task_runner_->PostTask(FROM_HERE,
80 base::Bind(decode_cb, DecodeStatus::DECODE_ERROR)); 86 base::Bind(decode_cb, DecodeStatus::DECODE_ERROR));
81 return; 87 return;
82 } 88 }
83 89
84 mojom::DecoderBufferPtr mojo_buffer = 90 mojom::DecoderBufferPtr mojo_buffer =
85 mojo_decoder_buffer_writer_->WriteDecoderBuffer(buffer); 91 mojo_decoder_buffer_writer_->WriteDecoderBuffer(buffer);
86 if (!mojo_buffer) { 92 if (!mojo_buffer) {
87 task_runner_->PostTask(FROM_HERE, 93 task_runner_->PostTask(FROM_HERE,
88 base::Bind(decode_cb, DecodeStatus::DECODE_ERROR)); 94 base::Bind(decode_cb, DecodeStatus::DECODE_ERROR));
89 return; 95 return;
90 } 96 }
91 97
92 // TODO(sandersd): Support more than one decode at a time. 98 uint64_t decode_id = decode_counter_++;
93 decode_cb_ = decode_cb; 99 pending_decodes_[decode_id] = decode_cb;
94 remote_decoder_->Decode( 100 remote_decoder_->Decode(std::move(mojo_buffer),
95 std::move(mojo_buffer), 101 base::Bind(&MojoVideoDecoder::OnDecodeDone,
96 base::Bind(&MojoVideoDecoder::OnDecodeDone, base::Unretained(this))); 102 base::Unretained(this), decode_id));
97 } 103 }
98 104
99 void MojoVideoDecoder::OnVideoFrameDecoded(mojom::VideoFramePtr frame) { 105 void MojoVideoDecoder::OnVideoFrameDecoded(mojom::VideoFramePtr frame) {
100 DVLOG(1) << __FUNCTION__; 106 DVLOG(2) << __FUNCTION__;
101 DCHECK(task_runner_->BelongsToCurrentThread()); 107 DCHECK(task_runner_->BelongsToCurrentThread());
102 output_cb_.Run(frame.To<scoped_refptr<VideoFrame>>()); 108 output_cb_.Run(frame.To<scoped_refptr<VideoFrame>>());
103 } 109 }
104 110
105 void MojoVideoDecoder::OnDecodeDone(DecodeStatus status) { 111 void MojoVideoDecoder::OnDecodeDone(uint64_t decode_id, DecodeStatus status) {
106 DVLOG(1) << __FUNCTION__; 112 DVLOG(2) << __FUNCTION__;
107 DCHECK(task_runner_->BelongsToCurrentThread()); 113 DCHECK(task_runner_->BelongsToCurrentThread());
108 base::ResetAndReturn(&decode_cb_).Run(status); 114
115 auto it = pending_decodes_.find(decode_id);
116 if (it == pending_decodes_.end()) {
117 DLOG(ERROR) << "Decode request " << decode_id << " not found";
118 Stop();
119 return;
120 }
121 DecodeCB decode_cb = it->second;
122 pending_decodes_.erase(it);
123 decode_cb.Run(status);
109 } 124 }
110 125
111 void MojoVideoDecoder::Reset(const base::Closure& reset_cb) { 126 void MojoVideoDecoder::Reset(const base::Closure& reset_cb) {
112 DVLOG(1) << __FUNCTION__; 127 DVLOG(1) << __FUNCTION__;
113 DCHECK(task_runner_->BelongsToCurrentThread()); 128 DCHECK(task_runner_->BelongsToCurrentThread());
114 129
115 if (has_connection_error_) { 130 if (has_connection_error_) {
116 task_runner_->PostTask(FROM_HERE, reset_cb); 131 task_runner_->PostTask(FROM_HERE, reset_cb);
117 return; 132 return;
118 } 133 }
119 134
120 reset_cb_ = reset_cb; 135 reset_cb_ = reset_cb;
121 remote_decoder_->Reset( 136 remote_decoder_->Reset(
122 base::Bind(&MojoVideoDecoder::OnResetDone, base::Unretained(this))); 137 base::Bind(&MojoVideoDecoder::OnResetDone, base::Unretained(this)));
123 } 138 }
124 139
125 void MojoVideoDecoder::OnResetDone() { 140 void MojoVideoDecoder::OnResetDone() {
126 DVLOG(1) << __FUNCTION__; 141 DVLOG(1) << __FUNCTION__;
127 DCHECK(task_runner_->BelongsToCurrentThread()); 142 DCHECK(task_runner_->BelongsToCurrentThread());
128 base::ResetAndReturn(&reset_cb_).Run(); 143 base::ResetAndReturn(&reset_cb_).Run();
129 } 144 }
130 145
131 bool MojoVideoDecoder::NeedsBitstreamConversion() const { 146 bool MojoVideoDecoder::NeedsBitstreamConversion() const {
132 DVLOG(1) << __FUNCTION__; 147 DVLOG(3) << __FUNCTION__;
133 return false; 148 DCHECK(initialized_);
149 return needs_bitstream_conversion_;
134 } 150 }
135 151
136 bool MojoVideoDecoder::CanReadWithoutStalling() const { 152 bool MojoVideoDecoder::CanReadWithoutStalling() const {
137 DVLOG(1) << __FUNCTION__; 153 DVLOG(3) << __FUNCTION__;
138 return true; 154 return true;
139 } 155 }
140 156
141 int MojoVideoDecoder::GetMaxDecodeRequests() const { 157 int MojoVideoDecoder::GetMaxDecodeRequests() const {
142 DVLOG(1) << __FUNCTION__; 158 DVLOG(3) << __FUNCTION__;
143 return 1; 159 DCHECK(initialized_);
160 return max_decode_requests_;
144 } 161 }
145 162
146 void MojoVideoDecoder::BindRemoteDecoder() { 163 void MojoVideoDecoder::BindRemoteDecoder() {
147 DVLOG(1) << __FUNCTION__; 164 DVLOG(3) << __FUNCTION__;
148 DCHECK(task_runner_->BelongsToCurrentThread()); 165 DCHECK(task_runner_->BelongsToCurrentThread());
149 DCHECK(!remote_decoder_bound_); 166 DCHECK(!remote_decoder_bound_);
150 167
151 remote_decoder_.Bind(std::move(remote_decoder_info_)); 168 remote_decoder_.Bind(std::move(remote_decoder_info_));
152 remote_decoder_bound_ = true; 169 remote_decoder_bound_ = true;
153 170
154 remote_decoder_.set_connection_error_handler( 171 remote_decoder_.set_connection_error_handler(
155 base::Bind(&MojoVideoDecoder::OnConnectionError, base::Unretained(this))); 172 base::Bind(&MojoVideoDecoder::Stop, base::Unretained(this)));
156 173
174 // TODO(sandersd): Does this need its own error handler?
157 mojom::VideoDecoderClientAssociatedPtrInfo client_ptr_info; 175 mojom::VideoDecoderClientAssociatedPtrInfo client_ptr_info;
158 client_binding_.Bind(&client_ptr_info, remote_decoder_.associated_group()); 176 client_binding_.Bind(&client_ptr_info, remote_decoder_.associated_group());
159 177
160 // TODO(sandersd): Better buffer sizing. 178 // TODO(sandersd): Better buffer sizing.
161 mojo::ScopedDataPipeConsumerHandle remote_consumer_handle; 179 mojo::ScopedDataPipeConsumerHandle remote_consumer_handle;
162 mojo_decoder_buffer_writer_ = MojoDecoderBufferWriter::Create( 180 mojo_decoder_buffer_writer_ = MojoDecoderBufferWriter::Create(
163 DemuxerStream::VIDEO, &remote_consumer_handle); 181 DemuxerStream::VIDEO, &remote_consumer_handle);
164 182
165 remote_decoder_->Construct(std::move(client_ptr_info), 183 remote_decoder_->Construct(std::move(client_ptr_info),
166 std::move(remote_consumer_handle)); 184 std::move(remote_consumer_handle));
167 } 185 }
168 186
169 void MojoVideoDecoder::OnConnectionError() { 187 void MojoVideoDecoder::Stop() {
170 DVLOG(1) << __FUNCTION__; 188 DVLOG(2) << __FUNCTION__;
171 DCHECK(task_runner_->BelongsToCurrentThread()); 189 DCHECK(task_runner_->BelongsToCurrentThread());
172 190
173 has_connection_error_ = true; 191 has_connection_error_ = true;
174 192
175 // TODO(sandersd): Write a wrapper class (like BindToCurrentLoop) that handles
176 // the lifetime of callbacks like this.
177 if (!init_cb_.is_null()) 193 if (!init_cb_.is_null())
178 base::ResetAndReturn(&init_cb_).Run(false); 194 base::ResetAndReturn(&init_cb_).Run(false);
179 // TODO(sandersd): If there is a pending reset, should these be aborted? 195
180 if (!decode_cb_.is_null()) 196 for (const auto& pending_decode : pending_decodes_)
181 base::ResetAndReturn(&decode_cb_).Run(DecodeStatus::DECODE_ERROR); 197 pending_decode.second.Run(DecodeStatus::DECODE_ERROR);
198 pending_decodes_.clear();
199
182 if (!reset_cb_.is_null()) 200 if (!reset_cb_.is_null())
183 base::ResetAndReturn(&reset_cb_).Run(); 201 base::ResetAndReturn(&reset_cb_).Run();
184 } 202 }
185 203
186 } // namespace media 204 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/clients/mojo_video_decoder.h ('k') | media/mojo/interfaces/video_decoder.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698