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

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

Issue 1924973004: Avoid waiting on the SurfaceTexture until we need to. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment fix. 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
« no previous file with comments | « media/gpu/avda_shared_state.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/avda_shared_state.h" 5 #include "media/gpu/avda_shared_state.h"
6 6
7 #include "base/metrics/histogram_macros.h"
7 #include "base/time/time.h" 8 #include "base/time/time.h"
8 #include "media/gpu/avda_codec_image.h" 9 #include "media/gpu/avda_codec_image.h"
9 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
10 #include "ui/gl/scoped_make_current.h" 11 #include "ui/gl/scoped_make_current.h"
11 12
12 namespace media { 13 namespace media {
13 14
14 AVDASharedState::AVDASharedState() 15 AVDASharedState::AVDASharedState()
15 : surface_texture_service_id_(0), 16 : surface_texture_service_id_(0),
16 frame_available_event_(false, false), 17 frame_available_event_(false, false),
17 surface_texture_is_attached_(false) {} 18 surface_texture_is_attached_(false) {}
18 19
19 AVDASharedState::~AVDASharedState() {} 20 AVDASharedState::~AVDASharedState() {}
20 21
21 void AVDASharedState::SignalFrameAvailable() { 22 void AVDASharedState::SignalFrameAvailable() {
22 frame_available_event_.Signal(); 23 frame_available_event_.Signal();
23 } 24 }
24 25
25 void AVDASharedState::WaitForFrameAvailable() { 26 void AVDASharedState::WaitForFrameAvailable() {
26 // 10msec covers >99.9% of cases, so just wait for up to that much before 27 DCHECK(!release_time_.is_null());
28
29 // 5msec covers >99.9% of cases, so just wait for up to that much before
27 // giving up. If an error occurs, we might not ever get a notification. 30 // giving up. If an error occurs, we might not ever get a notification.
28 const base::TimeDelta max_wait_time(base::TimeDelta::FromMilliseconds(10)); 31 const base::TimeDelta max_wait = base::TimeDelta::FromMilliseconds(5);
29 frame_available_event_.TimedWait(max_wait_time); 32 const base::TimeTicks call_time = base::TimeTicks::Now();
33 const base::TimeDelta elapsed = call_time - release_time_;
34 const base::TimeDelta remaining = max_wait - elapsed;
35 release_time_ = base::TimeTicks();
36
37 if (remaining <= base::TimeDelta()) {
38 if (!frame_available_event_.IsSignaled()) {
39 DVLOG(1) << "Deferred WaitForFrameAvailable() timed out, elapsed: "
40 << elapsed.InMillisecondsF() << "ms";
41 }
42 return;
43 }
44
45 DCHECK_LE(remaining, max_wait);
46 SCOPED_UMA_HISTOGRAM_TIMER("Media.AvdaCodecImage.WaitTimeForFrame");
47 if (!frame_available_event_.TimedWait(remaining)) {
48 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: "
49 << elapsed.InMillisecondsF()
50 << "ms, additionally waited: " << remaining.InMillisecondsF()
51 << "ms, total: " << (elapsed + remaining).InMillisecondsF()
52 << "ms";
53 }
30 } 54 }
31 55
32 void AVDASharedState::DidAttachSurfaceTexture() { 56 void AVDASharedState::DidAttachSurfaceTexture() {
33 context_ = gfx::GLContext::GetCurrent(); 57 context_ = gfx::GLContext::GetCurrent();
34 surface_ = gfx::GLSurface::GetCurrent(); 58 surface_ = gfx::GLSurface::GetCurrent();
35 DCHECK(context_); 59 DCHECK(context_);
36 DCHECK(surface_); 60 DCHECK(surface_);
37 61
38 surface_texture_is_attached_ = true; 62 surface_texture_is_attached_ = true;
39 } 63 }
40 64
41 void AVDASharedState::DidDetachSurfaceTexture() { 65 void AVDASharedState::DidDetachSurfaceTexture() {
42 context_ = nullptr; 66 context_ = nullptr;
43 surface_ = nullptr; 67 surface_ = nullptr;
44 surface_texture_is_attached_ = false; 68 surface_texture_is_attached_ = false;
45 } 69 }
46 70
47 void AVDASharedState::CodecChanged(media::MediaCodecBridge* codec) { 71 void AVDASharedState::CodecChanged(media::MediaCodecBridge* codec) {
48 for (auto& image_kv : codec_images_) 72 for (auto& image_kv : codec_images_)
49 image_kv.second->CodecChanged(codec); 73 image_kv.second->CodecChanged(codec);
74 release_time_ = base::TimeTicks();
50 } 75 }
51 76
52 void AVDASharedState::SetImageForPicture(int picture_buffer_id, 77 void AVDASharedState::SetImageForPicture(int picture_buffer_id,
53 AVDACodecImage* image) { 78 AVDACodecImage* image) {
54 if (!image) { 79 if (!image) {
55 DCHECK(codec_images_.find(picture_buffer_id) != codec_images_.end()); 80 DCHECK(codec_images_.find(picture_buffer_id) != codec_images_.end());
56 codec_images_.erase(picture_buffer_id); 81 codec_images_.erase(picture_buffer_id);
57 return; 82 return;
58 } 83 }
59 84
60 DCHECK(codec_images_.find(picture_buffer_id) == codec_images_.end()); 85 DCHECK(codec_images_.find(picture_buffer_id) == codec_images_.end());
61 codec_images_[picture_buffer_id] = image; 86 codec_images_[picture_buffer_id] = image;
62 } 87 }
63 88
64 AVDACodecImage* AVDASharedState::GetImageForPicture( 89 AVDACodecImage* AVDASharedState::GetImageForPicture(
65 int picture_buffer_id) const { 90 int picture_buffer_id) const {
66 auto it = codec_images_.find(picture_buffer_id); 91 auto it = codec_images_.find(picture_buffer_id);
67 return it == codec_images_.end() ? nullptr : it->second; 92 return it == codec_images_.end() ? nullptr : it->second;
68 } 93 }
69 94
95 void AVDASharedState::RenderCodecBufferToSurfaceTexture(
96 media::MediaCodecBridge* codec,
97 int codec_buffer_index) {
98 if (!release_time_.is_null())
99 WaitForFrameAvailable();
100 codec->ReleaseOutputBuffer(codec_buffer_index, true);
101 release_time_ = base::TimeTicks::Now();
102 }
103
70 } // namespace media 104 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/avda_shared_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698