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

Side by Side Diff: media/gpu/android_video_surface_chooser_impl.cc

Issue 2856253004: removed AndroidOverlayFactory (Closed)
Patch Set: removed some java refs Created 3 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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/gpu/android_video_surface_chooser_impl.h" 5 #include "media/gpu/android_video_surface_chooser_impl.h"
6 6
7 namespace media { 7 namespace media {
8 8
9 AndroidVideoSurfaceChooserImpl::AndroidVideoSurfaceChooserImpl() 9 AndroidVideoSurfaceChooserImpl::AndroidVideoSurfaceChooserImpl()
10 : weak_factory_(this) {} 10 : weak_factory_(this) {}
11 11
12 AndroidVideoSurfaceChooserImpl::~AndroidVideoSurfaceChooserImpl() {} 12 AndroidVideoSurfaceChooserImpl::~AndroidVideoSurfaceChooserImpl() {}
13 13
14 void AndroidVideoSurfaceChooserImpl::Initialize( 14 void AndroidVideoSurfaceChooserImpl::Initialize(
15 UseOverlayCB use_overlay_cb, 15 UseOverlayCB use_overlay_cb,
16 UseSurfaceTextureCB use_surface_texture_cb, 16 UseSurfaceTextureCB use_surface_texture_cb,
17 StopUsingOverlayImmediatelyCB stop_immediately_cb, 17 StopUsingOverlayImmediatelyCB stop_immediately_cb,
18 std::unique_ptr<AndroidOverlayFactory> initial_factory) { 18 AndroidOverlayFactoryCB initial_factory) {
19 use_overlay_cb_ = std::move(use_overlay_cb); 19 use_overlay_cb_ = std::move(use_overlay_cb);
20 use_surface_texture_cb_ = std::move(use_surface_texture_cb); 20 use_surface_texture_cb_ = std::move(use_surface_texture_cb);
21 stop_immediately_cb_ = std::move(stop_immediately_cb); 21 stop_immediately_cb_ = std::move(stop_immediately_cb);
22 22
23 if (initial_factory) { 23 if (!initial_factory.is_null()) {
tguilbert 2017/05/04 21:52:05 NIT: Same "is_null() can be ommitted" comment.
liberato (no reviews please) 2017/05/05 16:50:23 Done.
24 // We requested an overlay. Wait to see if it succeeds or fails, since 24 // We requested an overlay. Wait to see if it succeeds or fails, since
25 // hopefully this will be fast. On M+, we could ask it to start with a 25 // hopefully this will be fast. On M+, we could ask it to start with a
26 // SurfaceTexture either way. Before M, we can't switch surfaces. In that 26 // SurfaceTexture either way. Before M, we can't switch surfaces. In that
27 // case, it's important not to request a SurfaceTexture if we have an 27 // case, it's important not to request a SurfaceTexture if we have an
28 // overlay pending, so that we know not to transition to SurfaceTexture. 28 // overlay pending, so that we know not to transition to SurfaceTexture.
29 client_notification_pending_ = true; 29 client_notification_pending_ = true;
30 ReplaceOverlayFactory(std::move(initial_factory)); 30 ReplaceOverlayFactory(std::move(initial_factory));
31 } 31 }
32 32
33 if (!overlay_) { 33 if (!overlay_) {
34 // We haven't requested an overlay yet. Just ask the client to start with 34 // We haven't requested an overlay yet. Just ask the client to start with
35 // SurfaceTexture now. 35 // SurfaceTexture now.
36 use_surface_texture_cb_.Run(); 36 use_surface_texture_cb_.Run();
37 return; 37 return;
38 } 38 }
39 } 39 }
40 40
41 void AndroidVideoSurfaceChooserImpl::ReplaceOverlayFactory( 41 void AndroidVideoSurfaceChooserImpl::ReplaceOverlayFactory(
42 std::unique_ptr<AndroidOverlayFactory> factory) { 42 AndroidOverlayFactoryCB factory) {
43 // If we have an overlay, then we should transition away from it. It 43 // If we have an overlay, then we should transition away from it. It
44 // doesn't matter if we have a new factory or no factory; the old overlay goes 44 // doesn't matter if we have a new factory or no factory; the old overlay goes
45 // with the old factory. 45 // with the old factory.
46 46
47 // Notify the client to transition to SurfaceTexture, which it might already 47 // Notify the client to transition to SurfaceTexture, which it might already
48 // be using. If |!client_notification_pending_|, then we're still during 48 // be using. If |!client_notification_pending_|, then we're still during
49 // initial startup, so we don't switch the client. Otherwise, we'd cause 49 // initial startup, so we don't switch the client. Otherwise, we'd cause
50 // pre-M to break, since we'd start with a SurfaceTexture in all cases. 50 // pre-M to break, since we'd start with a SurfaceTexture in all cases.
51 if (!client_notification_pending_) 51 if (!client_notification_pending_)
52 use_surface_texture_cb_.Run(); 52 use_surface_texture_cb_.Run();
53 53
54 // If we started construction of an overlay, but it's not ready yet, then 54 // If we started construction of an overlay, but it's not ready yet, then
55 // just drop it. 55 // just drop it.
56 if (overlay_) 56 if (overlay_)
57 overlay_ = nullptr; 57 overlay_ = nullptr;
58 58
59 overlay_factory_ = std::move(factory); 59 overlay_factory_ = std::move(factory);
60 60
61 // If we don't have a new factory, then just stop here. 61 // If we don't have a new factory, then just stop here.
62 if (!overlay_factory_) 62 if (overlay_factory_.is_null())
63 return; 63 return;
64 64
65 // We just got an overlay factory. Get an overlay immediately. This is 65 // We just got an overlay factory. Get an overlay immediately. This is
66 // the right behavior to match what AVDA does with CVV. For DS, we should 66 // the right behavior to match what AVDA does with CVV. For DS, we should
67 // probably check to see if it's a good idea, at least on M+. 67 // probably check to see if it's a good idea, at least on M+.
68 // Also note that for pre-M, AVDA depends on this behavior, else it will get 68 // Also note that for pre-M, AVDA depends on this behavior, else it will get
69 // a SurfaceTexture then be unable to switch. Perhaps there should be a 69 // a SurfaceTexture then be unable to switch. Perhaps there should be a
70 // pre-M implementation of this class that guarantees that it won't change 70 // pre-M implementation of this class that guarantees that it won't change
71 // between the two. 71 // between the two.
72 AndroidOverlay::Config config; 72 AndroidOverlayConfig config;
73 // We bind all of our callbacks with weak ptrs, since we don't know how long 73 // We bind all of our callbacks with weak ptrs, since we don't know how long
74 // the client will hold on to overlays. They could, in principle, show up 74 // the client will hold on to overlays. They could, in principle, show up
75 // long after the client is destroyed too, if codec destruction hangs. 75 // long after the client is destroyed too, if codec destruction hangs.
76 config.ready_cb = base::Bind(&AndroidVideoSurfaceChooserImpl::OnOverlayReady, 76 config.ready_cb = base::Bind(&AndroidVideoSurfaceChooserImpl::OnOverlayReady,
77 weak_factory_.GetWeakPtr()); 77 weak_factory_.GetWeakPtr());
78 config.failed_cb = 78 config.failed_cb =
79 base::Bind(&AndroidVideoSurfaceChooserImpl::OnOverlayFailed, 79 base::Bind(&AndroidVideoSurfaceChooserImpl::OnOverlayFailed,
80 weak_factory_.GetWeakPtr()); 80 weak_factory_.GetWeakPtr());
81 config.destroyed_cb = 81 config.destroyed_cb =
82 base::Bind(&AndroidVideoSurfaceChooserImpl::OnSurfaceDestroyed, 82 base::Bind(&AndroidVideoSurfaceChooserImpl::OnSurfaceDestroyed,
83 weak_factory_.GetWeakPtr()); 83 weak_factory_.GetWeakPtr());
84 // TODO(liberato): where do we get the initial size from? For CVV, it's 84 // TODO(liberato): where do we get the initial size from? For CVV, it's
85 // set via the natural size, and this is ignored anyway. The client should 85 // set via the natural size, and this is ignored anyway. The client should
86 // provide this. 86 // provide this.
87 config.rect = gfx::Rect(0, 0, 1, 1); 87 config.rect = gfx::Rect(0, 0, 1, 1);
88 overlay_ = overlay_factory_->CreateOverlay(config); 88 overlay_ = overlay_factory_.Run(std::move(config));
89 } 89 }
90 90
91 void AndroidVideoSurfaceChooserImpl::OnOverlayReady(AndroidOverlay* overlay) { 91 void AndroidVideoSurfaceChooserImpl::OnOverlayReady(AndroidOverlay* overlay) {
92 // |overlay_| is the only overlay for which we haven't gotten a ready callback 92 // |overlay_| is the only overlay for which we haven't gotten a ready callback
93 // back yet. 93 // back yet.
94 DCHECK_EQ(overlay, overlay_.get()); 94 DCHECK_EQ(overlay, overlay_.get());
95 95
96 // If we haven't sent the client notification yet, we're doing so now. 96 // If we haven't sent the client notification yet, we're doing so now.
97 client_notification_pending_ = false; 97 client_notification_pending_ = false;
98 98
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 // Also remember that we don't know when the client drops the overlay, after 133 // Also remember that we don't know when the client drops the overlay, after
134 // we revoke it. We can get callbacks until that happens, even if (for 134 // we revoke it. We can get callbacks until that happens, even if (for
135 // example), the overlay is waiting for MediaCodec destruction. So, it's 135 // example), the overlay is waiting for MediaCodec destruction. So, it's
136 // likely that we'll send callbacks for overlays that the client is already 136 // likely that we'll send callbacks for overlays that the client is already
137 // not using. 137 // not using.
138 stop_immediately_cb_.Run(overlay); 138 stop_immediately_cb_.Run(overlay);
139 } 139 }
140 140
141 } // namespace media 141 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698