| 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/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/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 | 59 |
| 60 decoder_->Initialize( | 60 decoder_->Initialize( |
| 61 config.To<VideoDecoderConfig>(), low_delay, nullptr, | 61 config.To<VideoDecoderConfig>(), low_delay, nullptr, |
| 62 base::Bind(&MojoVideoDecoderService::OnDecoderInitialized, weak_this_, | 62 base::Bind(&MojoVideoDecoderService::OnDecoderInitialized, weak_this_, |
| 63 callback), | 63 callback), |
| 64 base::Bind(&MojoVideoDecoderService::OnDecoderOutput, weak_this_)); | 64 base::Bind(&MojoVideoDecoderService::OnDecoderOutput, weak_this_)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void MojoVideoDecoderService::OnDecoderInitialized( | |
| 68 const InitializeCallback& callback, | |
| 69 bool success) { | |
| 70 DVLOG(1) << __FUNCTION__; | |
| 71 callback.Run(success); | |
| 72 } | |
| 73 | |
| 74 void MojoVideoDecoderService::OnDecoderOutput( | |
| 75 const scoped_refptr<VideoFrame>& frame) { | |
| 76 DVLOG(1) << __FUNCTION__; | |
| 77 DCHECK(client_); | |
| 78 client_->OnVideoFrameDecoded(mojom::VideoFrame::From(frame)); | |
| 79 } | |
| 80 | |
| 81 void MojoVideoDecoderService::Decode(mojom::DecoderBufferPtr buffer, | 67 void MojoVideoDecoderService::Decode(mojom::DecoderBufferPtr buffer, |
| 82 const DecodeCallback& callback) { | 68 const DecodeCallback& callback) { |
| 83 DVLOG(1) << __FUNCTION__; | 69 DVLOG(1) << __FUNCTION__; |
| 84 | 70 |
| 85 if (!decoder_) { | 71 if (!decoder_) { |
| 86 callback.Run(mojom::DecodeStatus::DECODE_ERROR); | 72 callback.Run(DecodeStatus::DECODE_ERROR); |
| 87 return; | 73 return; |
| 88 } | 74 } |
| 89 | 75 |
| 90 // TODO(sandersd): After a decode error, we should enter an error state and | 76 // TODO(sandersd): After a decode error, we should enter an error state and |
| 91 // reject all future method calls. | 77 // reject all future method calls. |
| 92 scoped_refptr<DecoderBuffer> media_buffer = | 78 scoped_refptr<DecoderBuffer> media_buffer = |
| 93 mojo_decoder_buffer_reader_->ReadDecoderBuffer(buffer); | 79 mojo_decoder_buffer_reader_->ReadDecoderBuffer(buffer); |
| 94 if (!media_buffer) { | 80 if (!media_buffer) { |
| 95 callback.Run(mojom::DecodeStatus::DECODE_ERROR); | 81 callback.Run(DecodeStatus::DECODE_ERROR); |
| 96 return; | 82 return; |
| 97 } | 83 } |
| 98 | 84 |
| 99 decoder_->Decode(media_buffer, | 85 decoder_->Decode(media_buffer, |
| 100 base::Bind(&MojoVideoDecoderService::OnDecoderDecoded, | 86 base::Bind(&MojoVideoDecoderService::OnDecoderDecoded, |
| 101 weak_this_, callback)); | 87 weak_this_, callback)); |
| 102 } | 88 } |
| 103 | 89 |
| 104 void MojoVideoDecoderService::OnDecoderDecoded(const DecodeCallback& callback, | |
| 105 DecodeStatus status) { | |
| 106 DVLOG(1) << __FUNCTION__; | |
| 107 callback.Run(static_cast<mojom::DecodeStatus>(status)); | |
| 108 } | |
| 109 | |
| 110 void MojoVideoDecoderService::Reset(const ResetCallback& callback) { | 90 void MojoVideoDecoderService::Reset(const ResetCallback& callback) { |
| 111 DVLOG(1) << __FUNCTION__; | 91 DVLOG(1) << __FUNCTION__; |
| 112 | 92 |
| 113 if (!decoder_) { | 93 if (!decoder_) { |
| 114 callback.Run(); | 94 callback.Run(); |
| 115 return; | 95 return; |
| 116 } | 96 } |
| 117 | 97 |
| 118 decoder_->Reset(base::Bind(&MojoVideoDecoderService::OnDecoderReset, | 98 decoder_->Reset(base::Bind(&MojoVideoDecoderService::OnDecoderReset, |
| 119 weak_this_, callback)); | 99 weak_this_, callback)); |
| 120 } | 100 } |
| 121 | 101 |
| 102 void MojoVideoDecoderService::OnDecoderInitialized( |
| 103 const InitializeCallback& callback, |
| 104 bool success) { |
| 105 DVLOG(1) << __FUNCTION__; |
| 106 callback.Run(success); |
| 107 } |
| 108 |
| 109 void MojoVideoDecoderService::OnDecoderDecoded(const DecodeCallback& callback, |
| 110 DecodeStatus status) { |
| 111 DVLOG(1) << __FUNCTION__; |
| 112 callback.Run(status); |
| 113 } |
| 114 |
| 122 void MojoVideoDecoderService::OnDecoderReset(const ResetCallback& callback) { | 115 void MojoVideoDecoderService::OnDecoderReset(const ResetCallback& callback) { |
| 123 DVLOG(1) << __FUNCTION__; | 116 DVLOG(1) << __FUNCTION__; |
| 124 callback.Run(); | 117 callback.Run(); |
| 125 } | 118 } |
| 126 | 119 |
| 120 void MojoVideoDecoderService::OnDecoderOutput( |
| 121 const scoped_refptr<VideoFrame>& frame) { |
| 122 DVLOG(1) << __FUNCTION__; |
| 123 DCHECK(client_); |
| 124 client_->OnVideoFrameDecoded(mojom::VideoFrame::From(frame)); |
| 125 } |
| 126 |
| 127 } // namespace media | 127 } // namespace media |
| OLD | NEW |