OLD | NEW |
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/metrics/histogram_macros.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "media/gpu/avda_codec_image.h" | 9 #include "media/gpu/avda_codec_image.h" |
| 10 #include "ui/gl/android/surface_texture.h" |
10 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
11 #include "ui/gl/scoped_make_current.h" | 12 #include "ui/gl/scoped_make_current.h" |
12 | 13 |
13 namespace media { | 14 namespace media { |
14 | 15 |
15 AVDASharedState::AVDASharedState() | 16 AVDASharedState::AVDASharedState() |
16 : surface_texture_service_id_(0), | 17 : surface_texture_service_id_(0), frame_available_event_(false, false) {} |
17 frame_available_event_(false, false), | |
18 surface_texture_is_attached_(false) {} | |
19 | 18 |
20 AVDASharedState::~AVDASharedState() {} | 19 AVDASharedState::~AVDASharedState() { |
| 20 if (!surface_texture_service_id_) |
| 21 return; |
| 22 |
| 23 // XXX: Does this work in all the tear down paths? Should we be using the |
| 24 // MakeContextCurrent callback that GVDA gives us, which observes stub |
| 25 // destruction? |
| 26 std::unique_ptr<ui::ScopedMakeCurrent> scoped_make_current; |
| 27 if (!context_->IsCurrent(NULL)) { |
| 28 scoped_make_current.reset( |
| 29 new ui::ScopedMakeCurrent(context_.get(), surface_.get())); |
| 30 } |
| 31 if (!scoped_make_current || scoped_make_current->Succeeded()) |
| 32 glDeleteTextures(1, &surface_texture_service_id_); |
| 33 } |
21 | 34 |
22 void AVDASharedState::SignalFrameAvailable() { | 35 void AVDASharedState::SignalFrameAvailable() { |
23 frame_available_event_.Signal(); | 36 frame_available_event_.Signal(); |
24 } | 37 } |
25 | 38 |
26 void AVDASharedState::WaitForFrameAvailable() { | 39 void AVDASharedState::WaitForFrameAvailable() { |
27 DCHECK(!release_time_.is_null()); | 40 DCHECK(!release_time_.is_null()); |
28 | 41 |
29 // 5msec covers >99.9% of cases, so just wait for up to that much before | 42 // 5msec covers >99.9% of cases, so just wait for up to that much before |
30 // giving up. If an error occurs, we might not ever get a notification. | 43 // giving up. If an error occurs, we might not ever get a notification. |
(...skipping 15 matching lines...) Expand all Loading... |
46 SCOPED_UMA_HISTOGRAM_TIMER("Media.AvdaCodecImage.WaitTimeForFrame"); | 59 SCOPED_UMA_HISTOGRAM_TIMER("Media.AvdaCodecImage.WaitTimeForFrame"); |
47 if (!frame_available_event_.TimedWait(remaining)) { | 60 if (!frame_available_event_.TimedWait(remaining)) { |
48 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: " | 61 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: " |
49 << elapsed.InMillisecondsF() | 62 << elapsed.InMillisecondsF() |
50 << "ms, additionally waited: " << remaining.InMillisecondsF() | 63 << "ms, additionally waited: " << remaining.InMillisecondsF() |
51 << "ms, total: " << (elapsed + remaining).InMillisecondsF() | 64 << "ms, total: " << (elapsed + remaining).InMillisecondsF() |
52 << "ms"; | 65 << "ms"; |
53 } | 66 } |
54 } | 67 } |
55 | 68 |
56 void AVDASharedState::DidAttachSurfaceTexture() { | 69 void AVDASharedState::SetSurfaceTexture( |
| 70 scoped_refptr<gfx::SurfaceTexture> surface_texture, |
| 71 GLuint attached_service_id) { |
| 72 surface_texture_ = surface_texture; |
| 73 surface_texture_service_id_ = attached_service_id; |
57 context_ = gfx::GLContext::GetCurrent(); | 74 context_ = gfx::GLContext::GetCurrent(); |
58 surface_ = gfx::GLSurface::GetCurrent(); | 75 surface_ = gfx::GLSurface::GetCurrent(); |
59 DCHECK(context_); | 76 DCHECK(context_); |
60 DCHECK(surface_); | 77 DCHECK(surface_); |
61 | |
62 surface_texture_is_attached_ = true; | |
63 } | 78 } |
64 | 79 |
65 void AVDASharedState::CodecChanged(media::MediaCodecBridge* codec) { | 80 void AVDASharedState::CodecChanged(media::MediaCodecBridge* codec) { |
66 for (auto& image_kv : codec_images_) | 81 for (auto& image_kv : codec_images_) |
67 image_kv.second->CodecChanged(codec); | 82 image_kv.second->CodecChanged(codec); |
68 release_time_ = base::TimeTicks(); | 83 release_time_ = base::TimeTicks(); |
69 } | 84 } |
70 | 85 |
71 void AVDASharedState::SetImageForPicture(int picture_buffer_id, | 86 void AVDASharedState::SetImageForPicture(int picture_buffer_id, |
72 AVDACodecImage* image) { | 87 AVDACodecImage* image) { |
(...skipping 16 matching lines...) Expand all Loading... |
89 void AVDASharedState::RenderCodecBufferToSurfaceTexture( | 104 void AVDASharedState::RenderCodecBufferToSurfaceTexture( |
90 media::MediaCodecBridge* codec, | 105 media::MediaCodecBridge* codec, |
91 int codec_buffer_index) { | 106 int codec_buffer_index) { |
92 if (!release_time_.is_null()) | 107 if (!release_time_.is_null()) |
93 WaitForFrameAvailable(); | 108 WaitForFrameAvailable(); |
94 codec->ReleaseOutputBuffer(codec_buffer_index, true); | 109 codec->ReleaseOutputBuffer(codec_buffer_index, true); |
95 release_time_ = base::TimeTicks::Now(); | 110 release_time_ = base::TimeTicks::Now(); |
96 } | 111 } |
97 | 112 |
98 } // namespace media | 113 } // namespace media |
OLD | NEW |