| 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/android/surface_texture.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 // Protects changes to listener_. | 55 // Protects changes to listener_. |
| 56 base::Lock lock_; | 56 base::Lock lock_; |
| 57 | 57 |
| 58 // The AVDASharedState that wants the OnFrameAvailable callback. | 58 // The AVDASharedState that wants the OnFrameAvailable callback. |
| 59 AVDASharedState* listener_; | 59 AVDASharedState* listener_; |
| 60 | 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(OnFrameAvailableHandler); | 61 DISALLOW_COPY_AND_ASSIGN(OnFrameAvailableHandler); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 AVDASharedState::AVDASharedState() | 64 AVDASharedState::AVDASharedState() |
| 65 : surface_texture_service_id_(0), | 65 : frame_available_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 66 frame_available_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 67 base::WaitableEvent::InitialState::NOT_SIGNALED), | 66 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 68 | 67 |
| 69 gl_matrix_{ | 68 gl_matrix_{ |
| 70 1, 0, 0, 0, // Default to a sane guess just in case we can't get the | 69 1, 0, 0, 0, // Default to a sane guess just in case we can't get the |
| 71 0, 1, 0, 0, // matrix on the first call. Will be Y-flipped later. | 70 0, 1, 0, 0, // matrix on the first call. Will be Y-flipped later. |
| 72 0, 0, 1, 0, // | 71 0, 0, 1, 0, // |
| 73 0, 0, 0, 1, // Comment preserves 4x4 formatting. | 72 0, 0, 0, 1, // Comment preserves 4x4 formatting. |
| 74 } {} | 73 } {} |
| 75 | 74 |
| 76 AVDASharedState::~AVDASharedState() { | 75 AVDASharedState::~AVDASharedState() { |
| 77 if (!surface_texture_service_id_) | 76 if (!surface_texture_) |
| 78 return; | 77 return; |
| 79 | 78 |
| 80 on_frame_available_handler_->ClearListener(); | 79 on_frame_available_handler_->ClearListener(); |
| 81 ui::ScopedMakeCurrent scoped_make_current(context_.get(), surface_.get()); | |
| 82 if (scoped_make_current.Succeeded()) { | |
| 83 glDeleteTextures(1, &surface_texture_service_id_); | |
| 84 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | |
| 85 } | |
| 86 } | 80 } |
| 87 | 81 |
| 88 void AVDASharedState::SignalFrameAvailable() { | 82 void AVDASharedState::SignalFrameAvailable() { |
| 89 frame_available_event_.Signal(); | 83 frame_available_event_.Signal(); |
| 90 } | 84 } |
| 91 | 85 |
| 92 void AVDASharedState::WaitForFrameAvailable() { | 86 void AVDASharedState::WaitForFrameAvailable() { |
| 93 DCHECK(!release_time_.is_null()); | 87 DCHECK(!release_time_.is_null()); |
| 94 | 88 |
| 95 // 5msec covers >99.9% of cases, so just wait for up to that much before | 89 // 5msec covers >99.9% of cases, so just wait for up to that much before |
| (...skipping 17 matching lines...) Expand all Loading... |
| 113 if (!frame_available_event_.TimedWait(remaining)) { | 107 if (!frame_available_event_.TimedWait(remaining)) { |
| 114 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: " | 108 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: " |
| 115 << elapsed.InMillisecondsF() | 109 << elapsed.InMillisecondsF() |
| 116 << "ms, additionally waited: " << remaining.InMillisecondsF() | 110 << "ms, additionally waited: " << remaining.InMillisecondsF() |
| 117 << "ms, total: " << (elapsed + remaining).InMillisecondsF() | 111 << "ms, total: " << (elapsed + remaining).InMillisecondsF() |
| 118 << "ms"; | 112 << "ms"; |
| 119 } | 113 } |
| 120 } | 114 } |
| 121 | 115 |
| 122 void AVDASharedState::SetSurfaceTexture( | 116 void AVDASharedState::SetSurfaceTexture( |
| 123 scoped_refptr<gl::SurfaceTexture> surface_texture, | 117 scoped_refptr<SurfaceTextureGLOwner> surface_texture) { |
| 124 GLuint attached_service_id) { | |
| 125 DCHECK(surface_texture); | 118 DCHECK(surface_texture); |
| 126 DCHECK(attached_service_id); | |
| 127 surface_texture_ = surface_texture; | 119 surface_texture_ = surface_texture; |
| 128 surface_texture_service_id_ = attached_service_id; | |
| 129 context_ = gl::GLContext::GetCurrent(); | |
| 130 surface_ = gl::GLSurface::GetCurrent(); | |
| 131 DCHECK(context_); | |
| 132 DCHECK(surface_); | |
| 133 on_frame_available_handler_ = | 120 on_frame_available_handler_ = |
| 134 new OnFrameAvailableHandler(this, surface_texture_.get()); | 121 new OnFrameAvailableHandler(this, surface_texture_.get()); |
| 135 } | 122 } |
| 136 | 123 |
| 137 void AVDASharedState::RenderCodecBufferToSurfaceTexture( | 124 void AVDASharedState::RenderCodecBufferToSurfaceTexture( |
| 138 MediaCodecBridge* codec, | 125 MediaCodecBridge* codec, |
| 139 int codec_buffer_index) { | 126 int codec_buffer_index) { |
| 140 if (!release_time_.is_null()) | 127 if (!release_time_.is_null()) |
| 141 WaitForFrameAvailable(); | 128 WaitForFrameAvailable(); |
| 142 codec->ReleaseOutputBuffer(codec_buffer_index, true); | 129 codec->ReleaseOutputBuffer(codec_buffer_index, true); |
| 143 release_time_ = base::TimeTicks::Now(); | 130 release_time_ = base::TimeTicks::Now(); |
| 144 } | 131 } |
| 145 | 132 |
| 146 void AVDASharedState::UpdateTexImage() { | 133 void AVDASharedState::UpdateTexImage() { |
| 147 surface_texture_->UpdateTexImage(); | 134 surface_texture_->UpdateTexImage(); |
| 148 // Helpfully, this is already column major. | 135 // Helpfully, this is already column major. |
| 149 surface_texture_->GetTransformMatrix(gl_matrix_); | 136 surface_texture_->GetTransformMatrix(gl_matrix_); |
| 150 } | 137 } |
| 151 | 138 |
| 152 void AVDASharedState::GetTransformMatrix(float matrix[16]) const { | 139 void AVDASharedState::GetTransformMatrix(float matrix[16]) const { |
| 153 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_)); | 140 memcpy(matrix, gl_matrix_, sizeof(gl_matrix_)); |
| 154 } | 141 } |
| 155 | 142 |
| 156 } // namespace media | 143 } // namespace media |
| OLD | NEW |