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

Side by Side Diff: media/mojo/services/mojo_video_decoder_service.cc

Issue 2951233002: media: Implement MojoVideoDecoder::CanReadWithoutStalling(). (Closed)
Patch Set: Created 3 years, 6 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/interfaces/video_decoder.mojom ('k') | no next file » | 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/services/mojo_video_decoder_service.h" 5 #include "media/mojo/services/mojo_video_decoder_service.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/logging.h" 9 #include "base/logging.h"
10 #include "base/optional.h" 10 #include "base/optional.h"
(...skipping 18 matching lines...) Expand all
29 } 29 }
30 30
31 MojoVideoDecoderService::~MojoVideoDecoderService() {} 31 MojoVideoDecoderService::~MojoVideoDecoderService() {}
32 32
33 void MojoVideoDecoderService::Construct( 33 void MojoVideoDecoderService::Construct(
34 mojom::VideoDecoderClientAssociatedPtrInfo client, 34 mojom::VideoDecoderClientAssociatedPtrInfo client,
35 mojo::ScopedDataPipeConsumerHandle decoder_buffer_pipe, 35 mojo::ScopedDataPipeConsumerHandle decoder_buffer_pipe,
36 mojom::CommandBufferIdPtr command_buffer_id) { 36 mojom::CommandBufferIdPtr command_buffer_id) {
37 DVLOG(1) << __func__; 37 DVLOG(1) << __func__;
38 38
39 // TODO(sandersd): Close the channel. 39 if (decoder_) {
40 if (decoder_) 40 // TODO(sandersd): Close the channel.
41 return; 41 return;
42 }
42 43
43 decoder_ = mojo_media_client_->CreateVideoDecoder( 44 decoder_ = mojo_media_client_->CreateVideoDecoder(
44 base::ThreadTaskRunnerHandle::Get(), std::move(command_buffer_id), 45 base::ThreadTaskRunnerHandle::Get(), std::move(command_buffer_id),
45 base::Bind(&MojoVideoDecoderService::OnDecoderOutput, weak_this_)); 46 base::Bind(&MojoVideoDecoderService::OnDecoderOutput, weak_this_));
46 47
47 client_.Bind(std::move(client)); 48 client_.Bind(std::move(client));
48 49
49 mojo_decoder_buffer_reader_.reset( 50 mojo_decoder_buffer_reader_.reset(
50 new MojoDecoderBufferReader(std::move(decoder_buffer_pipe))); 51 new MojoDecoderBufferReader(std::move(decoder_buffer_pipe)));
51 } 52 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 bool success) { 100 bool success) {
100 DVLOG(1) << __func__; 101 DVLOG(1) << __func__;
101 DCHECK(decoder_); 102 DCHECK(decoder_);
102 callback.Run(success, decoder_->NeedsBitstreamConversion(), 103 callback.Run(success, decoder_->NeedsBitstreamConversion(),
103 decoder_->GetMaxDecodeRequests()); 104 decoder_->GetMaxDecodeRequests());
104 } 105 }
105 106
106 void MojoVideoDecoderService::OnDecoderRead( 107 void MojoVideoDecoderService::OnDecoderRead(
107 const DecodeCallback& callback, 108 const DecodeCallback& callback,
108 scoped_refptr<DecoderBuffer> buffer) { 109 scoped_refptr<DecoderBuffer> buffer) {
109 // TODO(sandersd): Close the channel.
110 if (!buffer) { 110 if (!buffer) {
111 // TODO(sandersd): Close the channel.
111 callback.Run(DecodeStatus::DECODE_ERROR); 112 callback.Run(DecodeStatus::DECODE_ERROR);
112 return; 113 return;
113 } 114 }
114 115
115 decoder_->Decode( 116 decoder_->Decode(
116 buffer, base::Bind(&MojoVideoDecoderService::OnDecoderDecoded, weak_this_, 117 buffer, base::Bind(&MojoVideoDecoderService::OnDecoderDecoded, weak_this_,
117 callback)); 118 callback));
118 } 119 }
119 120
120 void MojoVideoDecoderService::OnDecoderDecoded(const DecodeCallback& callback, 121 void MojoVideoDecoderService::OnDecoderDecoded(const DecodeCallback& callback,
121 DecodeStatus status) { 122 DecodeStatus status) {
122 DVLOG(2) << __func__; 123 DVLOG(2) << __func__;
123 DCHECK(decoder_);
124 DCHECK(decoder_->CanReadWithoutStalling());
125 callback.Run(status); 124 callback.Run(status);
126 } 125 }
127 126
128 void MojoVideoDecoderService::OnDecoderReset(const ResetCallback& callback) { 127 void MojoVideoDecoderService::OnDecoderReset(const ResetCallback& callback) {
129 DVLOG(1) << __func__; 128 DVLOG(1) << __func__;
130 callback.Run(); 129 callback.Run();
131 } 130 }
132 131
133 void MojoVideoDecoderService::OnDecoderOutput( 132 void MojoVideoDecoderService::OnDecoderOutput(
134 MojoMediaClient::ReleaseMailboxCB release_cb, 133 MojoMediaClient::ReleaseMailboxCB release_cb,
135 const scoped_refptr<VideoFrame>& frame) { 134 const scoped_refptr<VideoFrame>& frame) {
136 DVLOG(2) << __func__; 135 DVLOG(2) << __func__;
137 DCHECK(client_); 136 DCHECK(client_);
137 DCHECK(decoder_);
138 138
139 base::Optional<base::UnguessableToken> release_token; 139 base::Optional<base::UnguessableToken> release_token;
140 if (release_cb) { 140 if (release_cb) {
141 release_token = base::UnguessableToken::Create(); 141 release_token = base::UnguessableToken::Create();
142 release_mailbox_cbs_[*release_token] = std::move(release_cb); 142 release_mailbox_cbs_[*release_token] = std::move(release_cb);
143 } 143 }
144 144
145 client_->OnVideoFrameDecoded(frame, std::move(release_token)); 145 client_->OnVideoFrameDecoded(frame, decoder_->CanReadWithoutStalling(),
146 std::move(release_token));
146 } 147 }
147 148
148 void MojoVideoDecoderService::OnReleaseMailbox( 149 void MojoVideoDecoderService::OnReleaseMailbox(
149 const base::UnguessableToken& release_token, 150 const base::UnguessableToken& release_token,
150 const gpu::SyncToken& release_sync_token) { 151 const gpu::SyncToken& release_sync_token) {
151 DVLOG(2) << __func__; 152 DVLOG(2) << __func__;
152 153
153 // TODO(sandersd): Is it a serious error for the client to call 154 // TODO(sandersd): Is it a serious error for the client to call
154 // OnReleaseMailbox() with an invalid |release_token|? 155 // OnReleaseMailbox() with an invalid |release_token|?
155 auto it = release_mailbox_cbs_.find(release_token); 156 auto it = release_mailbox_cbs_.find(release_token);
156 if (it == release_mailbox_cbs_.end()) 157 if (it == release_mailbox_cbs_.end())
157 return; 158 return;
158 159
159 MojoMediaClient::ReleaseMailboxCB cb = std::move(it->second); 160 MojoMediaClient::ReleaseMailboxCB cb = std::move(it->second);
160 release_mailbox_cbs_.erase(it); 161 release_mailbox_cbs_.erase(it);
161 std::move(cb).Run(release_sync_token); 162 std::move(cb).Run(release_sync_token);
162 } 163 }
163 164
164 } // namespace media 165 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/interfaces/video_decoder.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698