7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/ppb_video_decoder.h"
19 const char* interface_name<PPB_VideoDecoder_0_1>() {
20 return PPB_VIDEODECODER_INTERFACE_0_1;
24 const char* interface_name<PPB_VideoDecoder_0_2>() {
25 return PPB_VIDEODECODER_INTERFACE_0_2;
29 const char* interface_name<PPB_VideoDecoder_1_0>() {
30 return PPB_VIDEODECODER_INTERFACE_1_0;
34 const char* interface_name<PPB_VideoDecoder_1_1>() {
35 return PPB_VIDEODECODER_INTERFACE_1_1;
41 struct CallbackData_0_1 {
42 explicit CallbackData_0_1(
43 const CompletionCallbackWithOutput<PP_VideoPicture>& cc)
44 : original_picture(cc.output()),
45 original_callback(cc.pp_completion_callback()) {}
46 PP_VideoPicture_0_1 picture;
47 PP_VideoPicture* original_picture;
48 PP_CompletionCallback original_callback;
52 void CallbackConverter(
void* user_data,
int32_t result) {
53 CallbackData_0_1* data =
static_cast<CallbackData_0_1*
>(user_data);
54 if (result == PP_OK) {
55 PP_VideoPicture_0_1* picture = &data->picture;
56 PP_VideoPicture* original_picture = data->original_picture;
57 original_picture->decode_id = picture->decode_id;
58 original_picture->texture_id = picture->texture_id;
59 original_picture->texture_target = picture->texture_target;
60 original_picture->texture_size = picture->texture_size;
62 original_picture->visible_rect = PP_MakeRectFromXYWH(
63 0, 0, picture->texture_size.width, picture->texture_size.height);
67 PP_RunCompletionCallback(&data->original_callback, result);
77 if (has_interface<PPB_VideoDecoder_1_1>()) {
79 get_interface<PPB_VideoDecoder_1_1>()->Create(instance.
pp_instance()));
80 }
else if (has_interface<PPB_VideoDecoder_1_0>()) {
82 get_interface<PPB_VideoDecoder_1_0>()->Create(instance.
pp_instance()));
83 }
else if (has_interface<PPB_VideoDecoder_0_2>()) {
85 get_interface<PPB_VideoDecoder_0_2>()->Create(instance.
pp_instance()));
86 }
else if (has_interface<PPB_VideoDecoder_0_1>()) {
88 get_interface<PPB_VideoDecoder_0_1>()->Create(instance.
pp_instance()));
96 PP_VideoProfile profile,
97 PP_HardwareAcceleration acceleration,
98 uint32_t min_picture_count,
100 if (has_interface<PPB_VideoDecoder_1_1>()) {
101 return get_interface<PPB_VideoDecoder_1_1>()->
Initialize(
105 if (has_interface<PPB_VideoDecoder_1_0>()) {
106 if (min_picture_count != 0)
107 return cc.
MayForce(PP_ERROR_NOTSUPPORTED);
108 return get_interface<PPB_VideoDecoder_1_0>()->
Initialize(
112 if (has_interface<PPB_VideoDecoder_0_2>()) {
113 if (min_picture_count != 0)
114 return cc.
MayForce(PP_ERROR_NOTSUPPORTED);
115 return get_interface<PPB_VideoDecoder_0_2>()->
Initialize(
119 if (has_interface<PPB_VideoDecoder_0_1>()) {
120 if (min_picture_count != 0)
121 return cc.
MayForce(PP_ERROR_NOTSUPPORTED);
122 if (acceleration == PP_HARDWAREACCELERATION_NONE)
123 return cc.
MayForce(PP_ERROR_NOTSUPPORTED);
124 return get_interface<PPB_VideoDecoder_0_1>()->
Initialize(
128 acceleration == PP_HARDWAREACCELERATION_WITHFALLBACK
133 return cc.
MayForce(PP_ERROR_NOINTERFACE);
140 if (has_interface<PPB_VideoDecoder_1_0>()) {
141 return get_interface<PPB_VideoDecoder_1_0>()->
Decode(
144 if (has_interface<PPB_VideoDecoder_0_2>()) {
145 return get_interface<PPB_VideoDecoder_0_2>()->
Decode(
148 if (has_interface<PPB_VideoDecoder_0_1>()) {
149 return get_interface<PPB_VideoDecoder_0_1>()->
Decode(
152 return cc.
MayForce(PP_ERROR_NOINTERFACE);
157 if (has_interface<PPB_VideoDecoder_1_0>()) {
158 return get_interface<PPB_VideoDecoder_1_0>()->
GetPicture(
161 if (has_interface<PPB_VideoDecoder_0_2>()) {
163 CallbackData_0_1* data =
new CallbackData_0_1(cc);
164 return get_interface<PPB_VideoDecoder_0_2>()->
GetPicture(
166 PP_MakeCompletionCallback(&CallbackConverter, data));
168 if (has_interface<PPB_VideoDecoder_0_1>()) {
170 CallbackData_0_1* data =
new CallbackData_0_1(cc);
171 return get_interface<PPB_VideoDecoder_0_1>()->
GetPicture(
173 PP_MakeCompletionCallback(&CallbackConverter, data));
175 return cc.
MayForce(PP_ERROR_NOINTERFACE);
179 if (has_interface<PPB_VideoDecoder_1_0>()) {
182 }
else if (has_interface<PPB_VideoDecoder_0_2>()) {
185 }
else if (has_interface<PPB_VideoDecoder_0_1>()) {
192 if (has_interface<PPB_VideoDecoder_1_0>()) {
193 return get_interface<PPB_VideoDecoder_1_0>()->
Flush(
196 if (has_interface<PPB_VideoDecoder_0_2>()) {
197 return get_interface<PPB_VideoDecoder_0_2>()->
Flush(
200 if (has_interface<PPB_VideoDecoder_0_1>()) {
201 return get_interface<PPB_VideoDecoder_0_1>()->
Flush(
204 return cc.
MayForce(PP_ERROR_NOINTERFACE);
208 if (has_interface<PPB_VideoDecoder_1_0>()) {
209 return get_interface<PPB_VideoDecoder_1_0>()->
Reset(
212 if (has_interface<PPB_VideoDecoder_0_2>()) {
213 return get_interface<PPB_VideoDecoder_0_2>()->
Reset(
216 if (has_interface<PPB_VideoDecoder_0_1>()) {
217 return get_interface<PPB_VideoDecoder_0_1>()->
Reset(
220 return cc.
MayForce(PP_ERROR_NOINTERFACE);
void PassRefFromConstructor(PP_Resource resource)
APIArgType output() const
int32_t MayForce(int32_t result) const
const PP_CompletionCallback & pp_completion_callback() const
This class represents a 3D rendering context in the browser.
int32_t Initialize(const Graphics3D &graphics3d_context, PP_VideoProfile profile, PP_HardwareAcceleration acceleration, uint32_t min_picture_count, const CompletionCallback &callback)
int32_t Flush(const CompletionCallback &callback)
void RecyclePicture(const PP_VideoPicture &picture)
int32_t Decode(uint32_t decode_id, uint32_t size, const void *buffer, const CompletionCallback &callback)
PP_Resource pp_resource() const
int32_t GetPicture(const CompletionCallbackWithOutput< PP_VideoPicture > &callback)
int32_t Reset(const CompletionCallback &callback)
Returns PP_ERROR_FAILED if the decoder isn't initialized.
PP_Instance pp_instance() const
A reference counted module resource.