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 ui::ScopedMakeCurrent scoped_make_current(context_.get(), surface_.get()); |
| 24 if (scoped_make_current.Succeeded()) |
| 25 glDeleteTextures(1, &surface_texture_service_id_); |
| 26 } |
21 | 27 |
22 void AVDASharedState::SignalFrameAvailable() { | 28 void AVDASharedState::SignalFrameAvailable() { |
23 frame_available_event_.Signal(); | 29 frame_available_event_.Signal(); |
24 } | 30 } |
25 | 31 |
26 void AVDASharedState::WaitForFrameAvailable() { | 32 void AVDASharedState::WaitForFrameAvailable() { |
27 DCHECK(!release_time_.is_null()); | 33 DCHECK(!release_time_.is_null()); |
28 | 34 |
29 // 5msec covers >99.9% of cases, so just wait for up to that much before | 35 // 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. | 36 // 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"); | 52 SCOPED_UMA_HISTOGRAM_TIMER("Media.AvdaCodecImage.WaitTimeForFrame"); |
47 if (!frame_available_event_.TimedWait(remaining)) { | 53 if (!frame_available_event_.TimedWait(remaining)) { |
48 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: " | 54 DVLOG(1) << "WaitForFrameAvailable() timed out, elapsed: " |
49 << elapsed.InMillisecondsF() | 55 << elapsed.InMillisecondsF() |
50 << "ms, additionally waited: " << remaining.InMillisecondsF() | 56 << "ms, additionally waited: " << remaining.InMillisecondsF() |
51 << "ms, total: " << (elapsed + remaining).InMillisecondsF() | 57 << "ms, total: " << (elapsed + remaining).InMillisecondsF() |
52 << "ms"; | 58 << "ms"; |
53 } | 59 } |
54 } | 60 } |
55 | 61 |
56 void AVDASharedState::DidAttachSurfaceTexture() { | 62 void AVDASharedState::SetSurfaceTexture( |
| 63 scoped_refptr<gl::SurfaceTexture> surface_texture, |
| 64 GLuint attached_service_id) { |
| 65 surface_texture_ = surface_texture; |
| 66 surface_texture_service_id_ = attached_service_id; |
57 context_ = gl::GLContext::GetCurrent(); | 67 context_ = gl::GLContext::GetCurrent(); |
58 surface_ = gl::GLSurface::GetCurrent(); | 68 surface_ = gl::GLSurface::GetCurrent(); |
59 DCHECK(context_); | 69 DCHECK(context_); |
60 DCHECK(surface_); | 70 DCHECK(surface_); |
61 | |
62 surface_texture_is_attached_ = true; | |
63 } | 71 } |
64 | 72 |
65 void AVDASharedState::CodecChanged(media::MediaCodecBridge* codec) { | 73 void AVDASharedState::CodecChanged(media::MediaCodecBridge* codec) { |
66 for (auto& image_kv : codec_images_) | 74 for (auto& image_kv : codec_images_) |
67 image_kv.second->CodecChanged(codec); | 75 image_kv.second->CodecChanged(codec); |
68 release_time_ = base::TimeTicks(); | 76 release_time_ = base::TimeTicks(); |
69 } | 77 } |
70 | 78 |
71 void AVDASharedState::SetImageForPicture(int picture_buffer_id, | 79 void AVDASharedState::SetImageForPicture(int picture_buffer_id, |
72 AVDACodecImage* image) { | 80 AVDACodecImage* image) { |
(...skipping 16 matching lines...) Expand all Loading... |
89 void AVDASharedState::RenderCodecBufferToSurfaceTexture( | 97 void AVDASharedState::RenderCodecBufferToSurfaceTexture( |
90 media::MediaCodecBridge* codec, | 98 media::MediaCodecBridge* codec, |
91 int codec_buffer_index) { | 99 int codec_buffer_index) { |
92 if (!release_time_.is_null()) | 100 if (!release_time_.is_null()) |
93 WaitForFrameAvailable(); | 101 WaitForFrameAvailable(); |
94 codec->ReleaseOutputBuffer(codec_buffer_index, true); | 102 codec->ReleaseOutputBuffer(codec_buffer_index, true); |
95 release_time_ = base::TimeTicks::Now(); | 103 release_time_ = base::TimeTicks::Now(); |
96 } | 104 } |
97 | 105 |
98 } // namespace media | 106 } // namespace media |
OLD | NEW |