OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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 "ppapi/shared_impl/video_decoder_impl.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "gpu/command_buffer/client/gles2_implementation.h" | |
9 #include "ppapi/c/pp_errors.h" | |
10 #include "ppapi/proxy/plugin_resource_tracker.h" | |
11 #include "ppapi/thunk/ppb_context_3d_api.h" | |
12 #include "ppapi/thunk/enter.h" | |
13 #include "webkit/plugins/ppapi/resource_tracker.h" | |
14 | |
15 using ppapi::thunk::PPB_Context3D_API; | |
16 | |
17 namespace ppapi { | |
18 | |
19 VideoDecoderImpl::VideoDecoderImpl(bool in_renderer_process) | |
20 : context3d_id_(0), | |
21 in_renderer_process_(in_renderer_process), | |
22 gles2_impl_(NULL) { | |
23 } | |
24 | |
25 thunk::PPB_VideoDecoder_API* VideoDecoderImpl::AsPPB_VideoDecoder_API() { | |
26 return this; | |
27 } | |
28 | |
29 VideoDecoderImpl::~VideoDecoderImpl() { | |
30 } | |
31 | |
32 bool VideoDecoderImpl::Init(PP_Resource context3d_id, | |
33 const PP_VideoConfigElement* decoder_config) { | |
34 if (!context3d_id || !decoder_config) | |
35 return false; | |
36 | |
37 ppapi::thunk::EnterResourceNoLock<PPB_Context3D_API> | |
38 enter_context(context3d_id, true); | |
39 if (!enter_context.succeeded()) | |
40 return false; | |
41 SetGLES2Impl(enter_context.object()->GetGLES2Impl()); | |
42 | |
43 AddRefResource(context3d_id); | |
44 context3d_id_ = context3d_id; | |
45 return true; | |
46 } | |
47 | |
48 void VideoDecoderImpl::Destroy() { | |
49 context3d_id_ = 0; | |
50 gles2_impl_ = NULL; | |
51 UnrefResource(context3d_id_); | |
52 } | |
53 | |
54 void VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) { | |
55 flush_callback_ = callback; | |
56 } | |
57 | |
58 void VideoDecoderImpl::SetResetCallback(PP_CompletionCallback callback) { | |
59 reset_callback_ = callback; | |
60 } | |
61 | |
62 void VideoDecoderImpl::AddBitstreamBufferCallback( | |
63 int32 bitstream_buffer_id, PP_CompletionCallback callback) { | |
64 DCHECK(bitstream_buffer_callbacks_.insert( | |
piman
2011/08/02 00:40:08
DCHECK(side effect) ??
Very bad idea... The side e
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Yeaaaaah, was supposed to be a CHECK, not a DCHECK
| |
65 std::make_pair(bitstream_buffer_id, callback)).second); | |
66 } | |
67 | |
68 void VideoDecoderImpl::RunFlushCallback() { | |
69 if (flush_callback_.func != NULL) | |
70 PP_RunAndClearCompletionCallback(&flush_callback_, PP_OK); | |
71 } | |
72 | |
73 void VideoDecoderImpl::RunResetCallback() { | |
74 if (reset_callback_.func != NULL) | |
75 PP_RunAndClearCompletionCallback(&reset_callback_, PP_OK); | |
76 } | |
77 | |
78 void VideoDecoderImpl::RunBitstreamBufferCallback(int32 bitstream_buffer_id) { | |
79 CallbackById::iterator it = | |
80 bitstream_buffer_callbacks_.find(bitstream_buffer_id); | |
81 DCHECK(it != bitstream_buffer_callbacks_.end()); | |
82 PP_CompletionCallback cc = it->second; | |
83 bitstream_buffer_callbacks_.erase(it); | |
84 PP_RunCompletionCallback(&cc, PP_OK); | |
85 } | |
86 | |
87 void VideoDecoderImpl::FlushCommandBuffer() { | |
88 if (gles2_impl_) | |
89 gles2_impl_->Flush(); | |
90 } | |
91 | |
92 bool VideoDecoderImpl::CopyConfigsToVector( | |
93 const PP_VideoConfigElement* configs_to_copy, | |
94 std::vector<int32>* out_configs) { | |
95 // TODO(vrk): This is assuming PP_VideoAttributeDictionary and | |
96 // VideoAttributeKey have identical enum values. There is no compiler | |
97 // assert to guarantee this. We either need to add such asserts or | |
98 // merge PP_VideoAttributeDictionary and VideoAttributeKey. | |
piman
2011/08/02 00:40:08
You can add COMPILE_ASSERT for those.
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Moved this comment to PPB_VideoDecoder_Impl::Creat
| |
99 const PP_VideoConfigElement* current = configs_to_copy; | |
100 while (current && *current != PP_VIDEOATTR_DICTIONARY_TERMINATOR) { | |
101 if (!(current + 1)) | |
102 return false; | |
103 | |
104 out_configs->push_back(static_cast<int32>(*current)); | |
piman
2011/08/02 00:40:08
Is the static_cast needed ? enums should cast impl
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Done.
| |
105 out_configs->push_back(static_cast<int32>(*(current + 1))); | |
106 current += 2; | |
107 } | |
108 return true; | |
109 } | |
110 | |
111 void VideoDecoderImpl::SetGLES2Impl( | |
112 gpu::gles2::GLES2Implementation* gles2_impl) { | |
113 DCHECK(!gles2_impl_); | |
114 gles2_impl_ = gles2_impl; | |
115 } | |
116 | |
117 void VideoDecoderImpl::AddRefResource(PP_Resource resource) { | |
118 if (in_renderer_process_) | |
119 ::webkit::ppapi::ResourceTracker::Get()->AddRefResource(resource); | |
120 else | |
121 ::pp::proxy::PluginResourceTracker::GetInstance()->AddRefResource(resource); | |
piman
2011/08/02 00:40:08
That sort of logic is kinda bad. Why not pass the
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Originally that is what I intended to do, but then
| |
122 } | |
123 | |
124 void VideoDecoderImpl::UnrefResource(PP_Resource resource) { | |
125 if (in_renderer_process_) { | |
126 ::webkit::ppapi::ResourceTracker::Get()->UnrefResource(resource); | |
127 } else { | |
128 ::pp::proxy::PluginResourceTracker:: | |
129 GetInstance()->ReleaseResource(resource); | |
130 } | |
131 } | |
132 | |
133 } // namespace ppapi | |
OLD | NEW |