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

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

Issue 1963773003: Merge to M51: Various fixes to prevent playback hang on MotoX. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: 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
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 "content/common/gpu/media/avda_shared_state.h" 5 #include "content/common/gpu/media/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"
9 #include "content/common/gpu/media/avda_codec_image.h"
8 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
9 #include "ui/gl/scoped_make_current.h" 11 #include "ui/gl/scoped_make_current.h"
10 12
11 namespace content { 13 namespace content {
12 14
13 AVDASharedState::AVDASharedState() 15 AVDASharedState::AVDASharedState()
14 : surface_texture_service_id_(0), 16 : surface_texture_service_id_(0),
15 frame_available_event_(false, false), 17 frame_available_event_(false, false),
16 surface_texture_is_attached_(false) {} 18 surface_texture_is_attached_(false) {}
17 19
18 AVDASharedState::~AVDASharedState() {} 20 AVDASharedState::~AVDASharedState() {}
19 21
20 void AVDASharedState::SignalFrameAvailable() { 22 void AVDASharedState::SignalFrameAvailable() {
21 frame_available_event_.Signal(); 23 frame_available_event_.Signal();
22 } 24 }
23 25
24 void AVDASharedState::WaitForFrameAvailable() { 26 void AVDASharedState::WaitForFrameAvailable() {
25 // 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
26 // 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.
27 const base::TimeDelta max_wait_time(base::TimeDelta::FromMilliseconds(10)); 31 const base::TimeDelta max_wait = base::TimeDelta::FromMilliseconds(5);
28 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 }
29 } 54 }
30 55
31 void AVDASharedState::DidAttachSurfaceTexture() { 56 void AVDASharedState::DidAttachSurfaceTexture() {
32 context_ = gfx::GLContext::GetCurrent(); 57 context_ = gfx::GLContext::GetCurrent();
33 surface_ = gfx::GLSurface::GetCurrent(); 58 surface_ = gfx::GLSurface::GetCurrent();
34 DCHECK(context_); 59 DCHECK(context_);
35 DCHECK(surface_); 60 DCHECK(surface_);
36 61
37 surface_texture_is_attached_ = true; 62 surface_texture_is_attached_ = true;
38 } 63 }
39 64
40 void AVDASharedState::DidDetachSurfaceTexture() { 65 void AVDASharedState::DidDetachSurfaceTexture() {
41 context_ = nullptr; 66 context_ = nullptr;
42 surface_ = nullptr; 67 surface_ = nullptr;
43 surface_texture_is_attached_ = false; 68 surface_texture_is_attached_ = false;
44 } 69 }
45 70
71 void AVDASharedState::CodecChanged(media::MediaCodecBridge* codec) {
72 for (auto& image_kv : codec_images_)
73 image_kv.second->CodecChanged(codec);
74 release_time_ = base::TimeTicks();
75 }
76
77 void AVDASharedState::SetImageForPicture(int picture_buffer_id,
78 AVDACodecImage* image) {
79 if (!image) {
80 DCHECK(codec_images_.find(picture_buffer_id) != codec_images_.end());
81 codec_images_.erase(picture_buffer_id);
82 return;
83 }
84
85 DCHECK(codec_images_.find(picture_buffer_id) == codec_images_.end());
86 codec_images_[picture_buffer_id] = image;
87 }
88
89 AVDACodecImage* AVDASharedState::GetImageForPicture(
90 int picture_buffer_id) const {
91 auto it = codec_images_.find(picture_buffer_id);
92 return it == codec_images_.end() ? nullptr : it->second;
93 }
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
46 } // namespace content 104 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/avda_shared_state.h ('k') | content/common/gpu/media/gpu_video_decode_accelerator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698