OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "ppapi/cpp/dev/video_decoder_dev.h" | 5 #include "ppapi/cpp/dev/video_decoder_dev.h" |
6 | 6 |
7 #include <algorithm> | |
8 | |
7 #include "ppapi/c/dev/ppb_video_decoder_dev.h" | 9 #include "ppapi/c/dev/ppb_video_decoder_dev.h" |
8 #include "ppapi/c/dev/ppp_video_decoder_dev.h" | 10 #include "ppapi/c/dev/ppp_video_decoder_dev.h" |
9 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/cpp/common.h" | 12 #include "ppapi/cpp/common.h" |
11 #include "ppapi/cpp/instance.h" | 13 #include "ppapi/cpp/instance.h" |
12 #include "ppapi/cpp/module.h" | 14 #include "ppapi/cpp/module.h" |
13 #include "ppapi/cpp/module_impl.h" | 15 #include "ppapi/cpp/module_impl.h" |
14 | 16 |
15 using std::vector; | 17 using std::vector; |
16 | 18 |
17 namespace pp { | 19 namespace pp { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 template <> const char* interface_name<PPB_VideoDecoder_Dev>() { | 23 template <> const char* interface_name<PPB_VideoDecoder_Dev>() { |
22 return PPB_VIDEODECODER_DEV_INTERFACE; | 24 return PPB_VIDEODECODER_DEV_INTERFACE; |
23 } | 25 } |
24 | 26 |
25 } // namespace | 27 } // namespace |
26 | 28 |
27 VideoDecoder::VideoDecoder(const Instance* /* instance */, | 29 VideoDecoder::VideoDecoder(const Instance* instance, |
28 const std::vector<uint32_t>& /* config */, | 30 const std::vector<uint32_t>& config, |
29 CompletionCallback /* callback */, | 31 CompletionCallback callback, |
30 Client* client) | 32 Client* client) |
31 : client_(client) { | 33 : client_(client) { |
32 if (!has_interface<PPB_VideoDecoder_Dev>()) | 34 if (!has_interface<PPB_VideoDecoder_Dev>()) |
33 return; | 35 return; |
34 // TODO(vmr): Implement. | 36 PP_VideoConfigElement* c_config = new PP_VideoConfigElement[config.size()]; |
37 std::copy(config.begin(), config.end(), c_config); | |
brettw
2011/05/31 12:46:44
I don't really understand what you're doing here.
Ville-Mikko Rautio
2011/05/31 13:33:14
Done.
| |
38 PassRefFromConstructor(get_interface<PPB_VideoDecoder_Dev>()->Create( | |
39 instance->pp_instance(), c_config, callback.pp_completion_callback())); | |
40 delete [] c_config; | |
brettw
2011/05/31 12:46:44
Normally I think we don't put a space in delete[].
Ville-Mikko Rautio
2011/05/31 13:33:14
Done.
| |
35 } | 41 } |
36 | 42 |
37 VideoDecoder::~VideoDecoder() {} | 43 VideoDecoder::~VideoDecoder() {} |
38 | 44 |
39 vector<uint32_t> VideoDecoder::GetConfigs( | 45 vector<uint32_t> VideoDecoder::GetConfigs( |
40 Instance* /* instance */, | 46 Instance* instance, |
41 const vector<uint32_t>& /* prototype_config */) { | 47 const vector<uint32_t>& prototype_config) { |
brettw
2011/05/31 12:46:44
You're not very consistent about std:: vs. not. I'
Ville-Mikko Rautio
2011/05/31 13:33:14
Done.
| |
42 // TODO(vmr): Implement. | |
43 vector<uint32_t> matching_configs; | 48 vector<uint32_t> matching_configs; |
44 if (!has_interface<PPB_VideoDecoder_Dev>()) | 49 if (!has_interface<PPB_VideoDecoder_Dev>()) |
45 return matching_configs; | 50 return matching_configs; |
51 // Convert prototype config into C-array and ask how many matching configs | |
52 // there are. | |
53 PP_VideoConfigElement* c_proto = NULL; | |
54 if (prototype_config.size() > 0) { | |
55 c_proto = new PP_VideoConfigElement[prototype_config.size()]; | |
56 if (c_proto == NULL) | |
57 return matching_configs; | |
58 std::copy(prototype_config.begin(), prototype_config.end(), c_proto); | |
brettw
2011/05/31 12:46:44
Is this copy necessary? Why not just pass &prototy
Ville-Mikko Rautio
2011/05/31 13:33:14
I changed this as well. From now on, we are absolu
| |
59 } | |
60 uint32_t num_of_matching_configs = 0; | |
61 get_interface<PPB_VideoDecoder_Dev>()->GetConfigs( | |
62 instance->pp_instance(), c_proto, NULL, 0, &num_of_matching_configs); | |
63 if (num_of_matching_configs == 0) { | |
64 delete[] c_proto; | |
65 return matching_configs; | |
66 } | |
67 // Then ask the actually matching configs and copy them to the return vector. | |
68 PP_VideoConfigElement* c_matching_configs = | |
69 new PP_VideoConfigElement[num_of_matching_configs]; | |
brettw
2011/05/31 12:46:44
You can also copy straight into the vector and avo
Ville-Mikko Rautio
2011/05/31 13:33:14
Done.
| |
70 get_interface<PPB_VideoDecoder_Dev>()->GetConfigs( | |
71 instance->pp_instance(), c_proto, c_matching_configs, | |
72 num_of_matching_configs, &num_of_matching_configs); | |
73 std::copy(c_matching_configs, | |
74 c_matching_configs + num_of_matching_configs, | |
75 matching_configs.end()); | |
76 delete[] c_proto; | |
77 delete[] c_matching_configs; | |
46 return matching_configs; | 78 return matching_configs; |
47 } | 79 } |
48 | 80 |
49 void VideoDecoder::AssignGLESBuffers(uint32_t /* no_of_buffers */, | 81 void VideoDecoder::AssignGLESBuffers( |
50 const PP_GLESBuffer_Dev& /* buffers */) { | 82 const std::vector<PP_GLESBuffer_Dev> buffers) { |
51 // TODO(vmr): Implement. | 83 if (!has_interface<PPB_VideoDecoder_Dev>() || !pp_resource()) |
84 return; | |
85 PP_GLESBuffer_Dev* gles_buffers = new PP_GLESBuffer_Dev[buffers.size()]; | |
86 if (!gles_buffers) { | |
brettw
2011/05/31 12:46:44
We don't normally check for OOM (and neither do yo
Ville-Mikko Rautio
2011/05/31 13:33:14
Done.
| |
87 assert(!"Out of memory."); | |
88 return; | |
89 } | |
90 std::copy(buffers.begin(), buffers.end(), gles_buffers); | |
brettw
2011/05/31 12:46:44
I think you can avoid this copy.
Ville-Mikko Rautio
2011/05/31 13:33:14
Done.
| |
91 get_interface<PPB_VideoDecoder_Dev>()->AssignGLESBuffers( | |
92 pp_resource(), buffers.size(), gles_buffers); | |
93 delete[] gles_buffers; | |
52 } | 94 } |
53 | 95 |
54 void VideoDecoder::AssignSysmemBuffers( | 96 void VideoDecoder::AssignSysmemBuffers( |
55 uint32_t /* no_of_buffers */, | 97 const std::vector<PP_SysmemBuffer_Dev> buffers) { |
56 const PP_SysmemBuffer_Dev& /* buffers */) { | 98 if (!has_interface<PPB_VideoDecoder_Dev>() || !pp_resource()) |
57 // TODO(vmr): Implement. | 99 return; |
100 PP_SysmemBuffer_Dev* sysmem_buffers = new PP_SysmemBuffer_Dev[buffers.size()]; | |
101 if (!sysmem_buffers) { | |
102 assert(!"Out of memory."); | |
103 return; | |
104 } | |
105 std::copy(buffers.begin(), buffers.end(), sysmem_buffers); | |
106 get_interface<PPB_VideoDecoder_Dev>()->AssignSysmemBuffers( | |
107 pp_resource(), buffers.size(), sysmem_buffers); | |
108 delete[] sysmem_buffers; | |
58 } | 109 } |
59 | 110 |
60 bool VideoDecoder::Decode( | 111 bool VideoDecoder::Decode( |
61 const PP_VideoBitstreamBuffer_Dev& /* bitstream_buffer */, | 112 const PP_VideoBitstreamBuffer_Dev& bitstream_buffer, |
62 CompletionCallback /* callback */) { | 113 CompletionCallback callback) { |
63 // TODO(vmr): Implement. | |
64 if (!has_interface<PPB_VideoDecoder_Dev>() || !pp_resource()) | 114 if (!has_interface<PPB_VideoDecoder_Dev>() || !pp_resource()) |
65 return false; | 115 return false; |
66 return false; | 116 return PPBoolToBool(get_interface<PPB_VideoDecoder_Dev>()->Decode( |
117 pp_resource(), | |
118 const_cast<PP_VideoBitstreamBuffer_Dev*>(&bitstream_buffer), | |
119 callback.pp_completion_callback())); | |
67 } | 120 } |
68 | 121 |
69 void VideoDecoder::ReusePictureBuffer(int32_t /* picture_buffer_id */) { | 122 void VideoDecoder::ReusePictureBuffer(int32_t picture_buffer_id) { |
70 // TODO(vmr): Implement. | 123 if (!has_interface<PPB_VideoDecoder_Dev>() || !pp_resource()) |
124 return; | |
125 get_interface<PPB_VideoDecoder_Dev>()->ReusePictureBuffer( | |
126 pp_resource(), picture_buffer_id); | |
71 } | 127 } |
72 | 128 |
73 bool VideoDecoder::Flush(CompletionCallback /* callback */) { | 129 bool VideoDecoder::Flush(CompletionCallback callback) { |
74 // TODO(vmr): Implement. | 130 if (!has_interface<PPB_VideoDecoder_Dev>() || !pp_resource()) |
75 if (!has_interface<PPB_VideoDecoder_Dev>()) | |
76 return false; | 131 return false; |
77 return true; | 132 return PPBoolToBool(get_interface<PPB_VideoDecoder_Dev>()->Flush( |
133 pp_resource(), callback.pp_completion_callback())); | |
78 } | 134 } |
79 | 135 |
80 bool VideoDecoder::Abort(CompletionCallback /* callback */) { | 136 bool VideoDecoder::Abort(CompletionCallback callback) { |
81 // TODO(vmr): Implement. | 137 if (!has_interface<PPB_VideoDecoder_Dev>() || !pp_resource()) |
82 if (!has_interface<PPB_VideoDecoder_Dev>()) | |
83 return false; | 138 return false; |
84 return true; | 139 return PPBoolToBool(get_interface<PPB_VideoDecoder_Dev>()->Abort( |
140 pp_resource(), callback.pp_completion_callback())); | |
85 } | 141 } |
86 | 142 |
87 } // namespace pp | 143 } // namespace pp |
OLD | NEW |