OLD | NEW |
---|---|
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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/unguessable_token.h" | 13 #include "base/unguessable_token.h" |
14 #include "media/base/bind_to_current_loop.h" | |
14 #include "media/base/decoder_buffer.h" | 15 #include "media/base/decoder_buffer.h" |
15 #include "media/base/demuxer_stream.h" | 16 #include "media/base/demuxer_stream.h" |
16 #include "media/base/video_frame.h" | 17 #include "media/base/video_frame.h" |
17 #include "media/mojo/common/media_type_converters.h" | 18 #include "media/mojo/common/media_type_converters.h" |
18 #include "media/mojo/common/mojo_decoder_buffer_converter.h" | 19 #include "media/mojo/common/mojo_decoder_buffer_converter.h" |
19 #include "media/mojo/interfaces/media_types.mojom.h" | 20 #include "media/mojo/interfaces/media_types.mojom.h" |
20 #include "media/renderers/gpu_video_accelerator_factories.h" | 21 #include "media/renderers/gpu_video_accelerator_factories.h" |
21 | 22 |
22 namespace media { | 23 namespace media { |
23 | 24 |
24 MojoVideoDecoder::MojoVideoDecoder( | 25 MojoVideoDecoder::MojoVideoDecoder( |
25 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 26 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
26 GpuVideoAcceleratorFactories* gpu_factories, | 27 GpuVideoAcceleratorFactories* gpu_factories, |
27 mojom::VideoDecoderPtr remote_decoder) | 28 mojom::VideoDecoderPtr remote_decoder) |
28 : task_runner_(task_runner), | 29 : task_runner_(task_runner), |
29 remote_decoder_info_(remote_decoder.PassInterface()), | 30 remote_decoder_info_(remote_decoder.PassInterface()), |
30 gpu_factories_(gpu_factories), | 31 gpu_factories_(gpu_factories), |
31 client_binding_(this) { | 32 client_binding_(this), |
33 weak_factory_(this) { | |
32 DVLOG(1) << __func__; | 34 DVLOG(1) << __func__; |
33 } | 35 } |
34 | 36 |
35 MojoVideoDecoder::~MojoVideoDecoder() { | 37 MojoVideoDecoder::~MojoVideoDecoder() { |
36 DVLOG(1) << __func__; | 38 DVLOG(1) << __func__; |
37 Stop(); | 39 Stop(); |
38 } | 40 } |
39 | 41 |
40 std::string MojoVideoDecoder::GetDisplayName() const { | 42 std::string MojoVideoDecoder::GetDisplayName() const { |
41 // TODO(sandersd): Build the name including information from the remote end. | 43 // TODO(sandersd): Build the name including information from the remote end. |
42 return "MojoVideoDecoder"; | 44 return "MojoVideoDecoder"; |
43 } | 45 } |
44 | 46 |
45 void MojoVideoDecoder::Initialize(const VideoDecoderConfig& config, | 47 void MojoVideoDecoder::Initialize(const VideoDecoderConfig& config, |
46 bool low_delay, | 48 bool low_delay, |
47 CdmContext* cdm_context, | 49 CdmContext* cdm_context, |
48 const InitCB& init_cb, | 50 const InitCB& init_cb, |
49 const OutputCB& output_cb) { | 51 const OutputCB& output_cb) { |
50 DVLOG(1) << __func__; | 52 DVLOG(1) << __func__; |
51 DCHECK(task_runner_->BelongsToCurrentThread()); | 53 DCHECK(task_runner_->BelongsToCurrentThread()); |
52 DCHECK(!cdm_context); | 54 DCHECK(!cdm_context); |
53 | 55 |
56 if (!weak_this_) | |
57 weak_this_ = weak_factory_.GetWeakPtr(); | |
58 | |
54 if (!remote_decoder_bound_) | 59 if (!remote_decoder_bound_) |
55 BindRemoteDecoder(); | 60 BindRemoteDecoder(); |
56 | 61 |
57 if (has_connection_error_) { | 62 if (has_connection_error_) { |
58 task_runner_->PostTask(FROM_HERE, base::Bind(init_cb, false)); | 63 task_runner_->PostTask(FROM_HERE, base::Bind(init_cb, false)); |
59 return; | 64 return; |
60 } | 65 } |
61 | 66 |
62 initialized_ = false; | 67 initialized_ = false; |
63 init_cb_ = init_cb; | 68 init_cb_ = init_cb; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 return; | 102 return; |
98 } | 103 } |
99 | 104 |
100 uint64_t decode_id = decode_counter_++; | 105 uint64_t decode_id = decode_counter_++; |
101 pending_decodes_[decode_id] = decode_cb; | 106 pending_decodes_[decode_id] = decode_cb; |
102 remote_decoder_->Decode(std::move(mojo_buffer), | 107 remote_decoder_->Decode(std::move(mojo_buffer), |
103 base::Bind(&MojoVideoDecoder::OnDecodeDone, | 108 base::Bind(&MojoVideoDecoder::OnDecodeDone, |
104 base::Unretained(this), decode_id)); | 109 base::Unretained(this), decode_id)); |
105 } | 110 } |
106 | 111 |
107 void MojoVideoDecoder::OnVideoFrameDecoded(mojom::VideoFramePtr frame) { | 112 void MojoVideoDecoder::OnVideoFrameDecoded( |
nasko
2017/02/16 21:37:29
Can this be called on multiple threads?
sandersd (OOO until July 31)
2017/02/25 01:19:38
No, it is a Mojo IPC callback and so should only b
| |
113 mojom::VideoFramePtr frame, | |
114 const base::Optional<base::UnguessableToken>& release_token) { | |
108 DVLOG(2) << __func__; | 115 DVLOG(2) << __func__; |
109 DCHECK(task_runner_->BelongsToCurrentThread()); | 116 DCHECK(task_runner_->BelongsToCurrentThread()); |
110 output_cb_.Run(frame.To<scoped_refptr<VideoFrame>>()); | 117 |
118 scoped_refptr<VideoFrame> video_frame = frame.To<scoped_refptr<VideoFrame>>(); | |
119 if (release_token) { | |
120 video_frame->SetReleaseMailboxCB( | |
121 BindToCurrentLoop(base::Bind(&MojoVideoDecoder::OnReleaseMailbox, | |
122 weak_this_, release_token.value()))); | |
123 } | |
124 output_cb_.Run(std::move(video_frame)); | |
125 } | |
126 | |
127 void MojoVideoDecoder::OnReleaseMailbox( | |
128 const base::UnguessableToken& release_token, | |
129 const gpu::SyncToken& release_sync_token) { | |
130 DCHECK(task_runner_->BelongsToCurrentThread()); | |
131 remote_decoder_->OnReleaseMailbox(release_token, release_sync_token); | |
111 } | 132 } |
112 | 133 |
113 void MojoVideoDecoder::OnDecodeDone(uint64_t decode_id, DecodeStatus status) { | 134 void MojoVideoDecoder::OnDecodeDone(uint64_t decode_id, DecodeStatus status) { |
114 DVLOG(2) << __func__; | 135 DVLOG(2) << __func__; |
115 DCHECK(task_runner_->BelongsToCurrentThread()); | 136 DCHECK(task_runner_->BelongsToCurrentThread()); |
116 | 137 |
117 auto it = pending_decodes_.find(decode_id); | 138 auto it = pending_decodes_.find(decode_id); |
118 if (it == pending_decodes_.end()) { | 139 if (it == pending_decodes_.end()) { |
119 DLOG(ERROR) << "Decode request " << decode_id << " not found"; | 140 DLOG(ERROR) << "Decode request " << decode_id << " not found"; |
120 Stop(); | 141 Stop(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 | 229 |
209 for (const auto& pending_decode : pending_decodes_) | 230 for (const auto& pending_decode : pending_decodes_) |
210 pending_decode.second.Run(DecodeStatus::DECODE_ERROR); | 231 pending_decode.second.Run(DecodeStatus::DECODE_ERROR); |
211 pending_decodes_.clear(); | 232 pending_decodes_.clear(); |
212 | 233 |
213 if (!reset_cb_.is_null()) | 234 if (!reset_cb_.is_null()) |
214 base::ResetAndReturn(&reset_cb_).Run(); | 235 base::ResetAndReturn(&reset_cb_).Run(); |
215 } | 236 } |
216 | 237 |
217 } // namespace media | 238 } // namespace media |
OLD | NEW |