OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/common/gpu/media/avda_shared_state.h" | |
6 | |
7 #include "base/time/time.h" | |
8 #include "content/common/gpu/media/avda_codec_image.h" | |
9 #include "ui/gl/gl_bindings.h" | |
10 #include "ui/gl/scoped_make_current.h" | |
11 | |
12 namespace content { | |
13 | |
14 AVDASharedState::AVDASharedState() | |
15 : surface_texture_service_id_(0), | |
16 frame_available_event_(false, false), | |
17 surface_texture_is_attached_(false) {} | |
18 | |
19 AVDASharedState::~AVDASharedState() {} | |
20 | |
21 void AVDASharedState::SignalFrameAvailable() { | |
22 frame_available_event_.Signal(); | |
23 } | |
24 | |
25 void AVDASharedState::WaitForFrameAvailable() { | |
26 // 10msec 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. | |
28 const base::TimeDelta max_wait_time(base::TimeDelta::FromMilliseconds(10)); | |
29 frame_available_event_.TimedWait(max_wait_time); | |
30 } | |
31 | |
32 void AVDASharedState::DidAttachSurfaceTexture() { | |
33 context_ = gfx::GLContext::GetCurrent(); | |
34 surface_ = gfx::GLSurface::GetCurrent(); | |
35 DCHECK(context_); | |
36 DCHECK(surface_); | |
37 | |
38 surface_texture_is_attached_ = true; | |
39 } | |
40 | |
41 void AVDASharedState::DidDetachSurfaceTexture() { | |
42 context_ = nullptr; | |
43 surface_ = nullptr; | |
44 surface_texture_is_attached_ = false; | |
45 } | |
46 | |
47 void AVDASharedState::CodecChanged(media::MediaCodecBridge* codec) { | |
48 for (auto& image_kv : codec_images_) | |
49 image_kv.second->CodecChanged(codec); | |
50 } | |
51 | |
52 void AVDASharedState::SetImageForPicture(int picture_buffer_id, | |
53 AVDACodecImage* image) { | |
54 if (!image) { | |
55 DCHECK(codec_images_.find(picture_buffer_id) != codec_images_.end()); | |
56 codec_images_.erase(picture_buffer_id); | |
57 return; | |
58 } | |
59 | |
60 DCHECK(codec_images_.find(picture_buffer_id) == codec_images_.end()); | |
61 codec_images_[picture_buffer_id] = image; | |
62 } | |
63 | |
64 AVDACodecImage* AVDASharedState::GetImageForPicture( | |
65 int picture_buffer_id) const { | |
66 auto it = codec_images_.find(picture_buffer_id); | |
67 return it == codec_images_.end() ? nullptr : it->second; | |
68 } | |
69 | |
70 } // namespace content | |
OLD | NEW |