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

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

Issue 1899363002: Finish plumbing MojoVideoDecoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 7 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/mojo/services/mojo_video_decoder_service.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/logging.h"
10 #include "media/base/decoder_buffer.h"
11 #include "media/base/video_decoder.h"
12 #include "media/base/video_decoder_config.h"
13 #include "media/base/video_frame.h"
14 #include "media/mojo/common/media_type_converters.h"
15 #include "media/mojo/services/mojo_media_client.h"
16 #include "mojo/public/c/system/types.h"
17 #include "mojo/public/cpp/system/buffer.h"
18 #include "mojo/public/cpp/system/handle.h"
19
20 namespace media {
21
22 MojoVideoDecoderService::MojoVideoDecoderService(
23 mojo::InterfaceRequest<interfaces::VideoDecoder> request,
24 MojoMediaClient* mojo_media_client)
25 : binding_(this, std::move(request)),
26 mojo_media_client_(mojo_media_client),
27 weak_factory_(this) {
28 weak_this_ = weak_factory_.GetWeakPtr();
29 }
30
31 MojoVideoDecoderService::~MojoVideoDecoderService() {}
32
33 void MojoVideoDecoderService::Construct(
34 interfaces::VideoDecoderClientPtr client,
35 mojo::ScopedDataPipeConsumerHandle decoder_buffer_pipe) {
36 DVLOG(1) << __FUNCTION__;
37 CHECK(!decoder_);
38
39 // TODO(sandersd): Provide callback for requesting a stub.
40 decoder_ = mojo_media_client_->CreateVideoDecoder(
41 base::ThreadTaskRunnerHandle::Get());
42
43 client_ = std::move(client);
44 decoder_buffer_pipe_ = std::move(decoder_buffer_pipe);
45 }
46
47 void MojoVideoDecoderService::Initialize(
48 interfaces::VideoDecoderConfigPtr config,
49 bool low_delay,
50 const InitializeCallback& callback) {
51 DVLOG(1) << __FUNCTION__;
52
53 if (!decoder_) {
54 callback.Run(false);
55 return;
56 }
57
58 decoder_->Initialize(
59 config.To<VideoDecoderConfig>(), low_delay, nullptr,
60 base::Bind(&MojoVideoDecoderService::OnDecoderInitialized, weak_this_,
61 callback),
62 base::Bind(&MojoVideoDecoderService::OnDecoderOutput, weak_this_));
63 }
64
65 void MojoVideoDecoderService::OnDecoderInitialized(
66 const InitializeCallback& callback,
67 bool success) {
68 DVLOG(1) << __FUNCTION__;
69 callback.Run(success);
70 }
71
72 void MojoVideoDecoderService::OnDecoderOutput(
73 const scoped_refptr<VideoFrame>& frame) {
74 DVLOG(1) << __FUNCTION__;
75 client_->OnVideoFrameDecoded(interfaces::VideoFrame::From(frame));
76 }
77
78 void MojoVideoDecoderService::Decode(interfaces::DecoderBufferPtr buffer,
79 const DecodeCallback& callback) {
80 DVLOG(1) << __FUNCTION__;
81
82 if (!decoder_) {
83 callback.Run(interfaces::DecodeStatus::DECODE_ERROR);
84 return;
85 }
86
87 scoped_refptr<DecoderBuffer> media_buffer(
88 buffer.To<scoped_refptr<DecoderBuffer>>());
89 if (!media_buffer->end_of_stream()) {
90 MojoHandleSignalsState state;
91 CHECK_EQ(
92 MojoWait(decoder_buffer_pipe_.get().value(),
93 MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, &state),
94 MOJO_RESULT_OK);
95 CHECK_EQ(state.satisfied_signals, MOJO_HANDLE_SIGNAL_READABLE);
96 uint32_t data_size =
97 base::checked_cast<uint32_t>(media_buffer->data_size());
dcheng 2016/05/17 06:32:29 This shouldn't be a checked_cast: it's in the GPU
sandersd (OOO until July 31) 2016/05/17 23:05:00 Done.
98 DCHECK_GT(data_size, 0u);
99 uint32_t bytes_read = data_size;
100 CHECK_EQ(
dcheng 2016/05/17 06:32:29 Ditto for this and the other CHECKs in this file w
sandersd (OOO until July 31) 2016/05/17 23:05:00 Done. I also updated MojoAudioDecoderService, alt
101 ReadDataRaw(decoder_buffer_pipe_.get(), media_buffer->writable_data(),
102 &bytes_read, MOJO_READ_DATA_FLAG_ALL_OR_NONE),
103 MOJO_RESULT_OK);
104 CHECK_EQ(bytes_read, data_size);
105 }
106
107 decoder_->Decode(media_buffer,
108 base::Bind(&MojoVideoDecoderService::OnDecoderDecoded,
109 weak_this_, callback));
110 }
111
112 void MojoVideoDecoderService::OnDecoderDecoded(const DecodeCallback& callback,
113 DecodeStatus status) {
114 DVLOG(1) << __FUNCTION__;
115 callback.Run(static_cast<interfaces::DecodeStatus>(status));
116 }
117
118 void MojoVideoDecoderService::Reset(const ResetCallback& callback) {
119 DVLOG(1) << __FUNCTION__;
120 if (!decoder_) {
121 callback.Run();
122 return;
123 }
124 decoder_->Reset(base::Bind(&MojoVideoDecoderService::OnDecoderReset,
125 weak_this_, callback));
126 }
127
128 void MojoVideoDecoderService::OnDecoderReset(const ResetCallback& callback) {
129 DVLOG(1) << __FUNCTION__;
130 callback.Run();
131 }
132
133 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/services/mojo_video_decoder_service.h ('k') | media/mojo/services/service_factory_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698