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

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

Issue 2643713003: Allow to use the DefaultRendererFactory from a Utility Process (Closed)
Patch Set: Rebase Created 3 years, 10 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_renderer_sink_impl.h ('k') | media/mojo/common/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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/clients/mojo_video_renderer_sink_impl.h"
6
7 #include "media/mojo/common/media_type_converters.h"
8
9 namespace media {
10
11 MojoVideoRendererSinkImpl::MojoVideoRendererSinkImpl(
12 const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner,
13 media::VideoRendererSink* sink,
14 mojo::InterfaceRequest<mojom::VideoRendererSink> request)
15 : media_task_runner_(media_task_runner),
16 compositor_task_runner_(nullptr),
17 binding_(this, std::move(request)),
18 sink_(sink),
19 started_(false) {
20 CHECK(media_task_runner_->BelongsToCurrentThread());
21 }
22
23 MojoVideoRendererSinkImpl::~MojoVideoRendererSinkImpl() {
24 CHECK(media_task_runner_->BelongsToCurrentThread());
25
26 if (started_) {
27 sink_->Stop();
28 started_ = false;
29 }
30 }
31
32 scoped_refptr<VideoFrame> MojoVideoRendererSinkImpl::Render(
33 base::TimeTicks deadline_min,
34 base::TimeTicks deadline_max,
35 bool background_rendering) {
36 if (!callback_.is_bound()) {
37 callback_.Bind(std::move(callback_info_));
38
39 if (!compositor_task_runner_) {
40 compositor_task_runner_ = base::ThreadTaskRunnerHandle::Get();
41 CHECK(compositor_task_runner_ != media_task_runner_);
42 }
43 }
44
45 CHECK(compositor_task_runner_->BelongsToCurrentThread());
46
47 mojom::VideoFramePtr mojo_frame;
48 callback_->Render(deadline_min, deadline_max, background_rendering,
49 &mojo_frame);
50
51 // This ensures that the callback_ is reset in the compoistor thread.
52 // It would be wrong to get it released as MojoVideoRendererSinkImpl is
53 // destroyed because ~MojoVideoRendererSinkImpl is called from another thread,
54 // i.e. the media thread.
55 // An alternative would be to bind it to the media thread and use a
56 // post/cond/wait/signal.
57 callback_info_ = callback_.PassInterface();
58
59 if (!mojo_frame)
60 return nullptr;
61
62 return mojo_frame.To<scoped_refptr<VideoFrame>>();
63 }
64
65 void MojoVideoRendererSinkImpl::OnFrameDropped() {
66 CHECK(compositor_task_runner_->BelongsToCurrentThread());
67
68 if (!callback_.is_bound())
69 callback_.Bind(std::move(callback_info_));
70
71 callback_->OnFrameDropped();
72
73 // Same reason than above.
74 callback_info_ = callback_.PassInterface();
75 }
76
77 void MojoVideoRendererSinkImpl::Start(
78 mojom::VideoRendererSinkRenderCallbackAssociatedPtrInfo callback) {
79 CHECK(media_task_runner_->BelongsToCurrentThread());
80 CHECK(!started_);
81 callback_info_ = std::move(callback);
82 started_ = true;
83
84 sink_->Start(this);
85 }
86
87 void MojoVideoRendererSinkImpl::Stop() {
88 CHECK(media_task_runner_->BelongsToCurrentThread());
89 CHECK(started_);
90 started_ = false;
91 sink_->Stop();
92 }
93
94 void MojoVideoRendererSinkImpl::PaintSingleFrame(
95 mojom::VideoFramePtr mojo_frame,
96 bool repaint_duplicate_frame) {
97 CHECK(media_task_runner_->BelongsToCurrentThread());
98 if (!mojo_frame)
99 return;
100
101 sink_->PaintSingleFrame(mojo_frame.To<scoped_refptr<VideoFrame>>(),
102 repaint_duplicate_frame);
103 }
104
105 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/clients/mojo_video_renderer_sink_impl.h ('k') | media/mojo/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698