OLD | NEW |
---|---|
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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/video_decoder.h" | 5 #include "ppapi/cpp/video_decoder.h" |
6 | 6 |
7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
8 #include "ppapi/c/ppb_video_decoder.h" | 8 #include "ppapi/c/ppb_video_decoder.h" |
9 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
10 #include "ppapi/cpp/instance_handle.h" | 10 #include "ppapi/cpp/instance_handle.h" |
11 #include "ppapi/cpp/module.h" | 11 #include "ppapi/cpp/module.h" |
12 #include "ppapi/cpp/module_impl.h" | 12 #include "ppapi/cpp/module_impl.h" |
13 | 13 |
14 namespace pp { | 14 namespace pp { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 template <> | 18 template <> |
19 const char* interface_name<PPB_VideoDecoder_0_1>() { | 19 const char* interface_name<PPB_VideoDecoder_0_1>() { |
20 return PPB_VIDEODECODER_INTERFACE_0_1; | 20 return PPB_VIDEODECODER_INTERFACE_0_1; |
21 } | 21 } |
22 | 22 |
23 template <> | 23 template <> |
24 const char* interface_name<PPB_VideoDecoder_0_2>() { | 24 const char* interface_name<PPB_VideoDecoder_0_2>() { |
25 return PPB_VIDEODECODER_INTERFACE_0_2; | 25 return PPB_VIDEODECODER_INTERFACE_0_2; |
26 } | 26 } |
27 | 27 |
28 template <> | |
29 const char* interface_name<PPB_VideoDecoder_1_0>() { | |
30 return PPB_VIDEODECODER_INTERFACE_1_0; | |
31 } | |
32 | |
33 struct CallbackData_0_1 { | |
dmichael (off chromium)
2014/11/05 23:06:04
An overarching comment about the strategy here mig
bbudge
2014/11/06 00:26:36
Done.
| |
34 CallbackData_0_1(const CompletionCallbackWithOutput<PP_VideoPicture>& cc) | |
dmichael (off chromium)
2014/11/05 23:06:04
super nitty nit: explicit
bbudge
2014/11/06 00:26:36
Done.
| |
35 : original_picture(cc.output()), | |
dmichael (off chromium)
2014/11/05 23:06:04
nit: May be good to also add:
picture(),
...to get
bbudge
2014/11/06 00:26:36
It's a micro-optimization. It is an 'out' paramete
| |
36 original_callback(cc.pp_completion_callback()) {} | |
37 PP_VideoPicture_0_1 picture; | |
38 PP_VideoPicture* original_picture; | |
39 PP_CompletionCallback original_callback; | |
40 }; | |
41 | |
42 // static | |
43 void CallbackConverter(void* user_data, int32_t result) { | |
44 CallbackData_0_1* data = static_cast<CallbackData_0_1*>(user_data); | |
45 if (result == PP_OK) { | |
46 PP_VideoPicture_0_1* picture = &data->picture; | |
47 PP_VideoPicture* original_picture = data->original_picture; | |
48 original_picture->decode_id = picture->decode_id; | |
49 original_picture->texture_id = picture->texture_id; | |
50 original_picture->texture_target = picture->texture_target; | |
51 original_picture->texture_size = picture->texture_size; | |
52 // Return an empty rect, since we have no knowledge of texture size. | |
dmichael (off chromium)
2014/11/05 23:06:04
You mean a full-size rect? I.e., the same size as
bbudge
2014/11/06 00:26:36
Gah, comment is stale. Done.
| |
53 original_picture->visible_rect = PP_MakeRectFromXYWH( | |
54 0, 0, picture->texture_size.width, picture->texture_size.height); | |
55 } | |
56 | |
57 // Now execute the original callback. | |
58 PP_RunCompletionCallback(&data->original_callback, result); | |
59 delete data; | |
60 } | |
61 | |
28 } // namespace | 62 } // namespace |
29 | 63 |
30 VideoDecoder::VideoDecoder() { | 64 VideoDecoder::VideoDecoder() { |
31 } | 65 } |
32 | 66 |
33 VideoDecoder::VideoDecoder(const InstanceHandle& instance) { | 67 VideoDecoder::VideoDecoder(const InstanceHandle& instance) { |
34 if (has_interface<PPB_VideoDecoder_0_1>()) { | 68 if (has_interface<PPB_VideoDecoder_0_1>()) { |
35 PassRefFromConstructor( | 69 PassRefFromConstructor( |
36 get_interface<PPB_VideoDecoder_0_1>()->Create(instance.pp_instance())); | 70 get_interface<PPB_VideoDecoder_0_1>()->Create(instance.pp_instance())); |
37 } | 71 } |
38 } | 72 } |
39 | 73 |
40 VideoDecoder::VideoDecoder(const VideoDecoder& other) : Resource(other) { | 74 VideoDecoder::VideoDecoder(const VideoDecoder& other) : Resource(other) { |
41 } | 75 } |
42 | 76 |
43 int32_t VideoDecoder::Initialize(const Graphics3D& context, | 77 int32_t VideoDecoder::Initialize(const Graphics3D& context, |
44 PP_VideoProfile profile, | 78 PP_VideoProfile profile, |
45 PP_HardwareAcceleration acceleration, | 79 PP_HardwareAcceleration acceleration, |
46 const CompletionCallback& cc) { | 80 const CompletionCallback& cc) { |
81 if (has_interface<PPB_VideoDecoder_1_0>()) { | |
82 return get_interface<PPB_VideoDecoder_1_0>()->Initialize( | |
83 pp_resource(), context.pp_resource(), profile, acceleration, | |
84 cc.pp_completion_callback()); | |
85 } | |
47 if (has_interface<PPB_VideoDecoder_0_2>()) { | 86 if (has_interface<PPB_VideoDecoder_0_2>()) { |
48 return get_interface<PPB_VideoDecoder_0_2>()->Initialize( | 87 return get_interface<PPB_VideoDecoder_0_2>()->Initialize( |
49 pp_resource(), | 88 pp_resource(), context.pp_resource(), profile, acceleration, |
50 context.pp_resource(), | |
51 profile, | |
52 acceleration, | |
53 cc.pp_completion_callback()); | 89 cc.pp_completion_callback()); |
54 } | 90 } |
55 if (has_interface<PPB_VideoDecoder_0_1>()) { | 91 if (has_interface<PPB_VideoDecoder_0_1>()) { |
56 if (acceleration == PP_HARDWAREACCELERATION_NONE) | 92 if (acceleration == PP_HARDWAREACCELERATION_NONE) |
57 return cc.MayForce(PP_ERROR_NOTSUPPORTED); | 93 return cc.MayForce(PP_ERROR_NOTSUPPORTED); |
58 return get_interface<PPB_VideoDecoder_0_1>()->Initialize( | 94 return get_interface<PPB_VideoDecoder_0_1>()->Initialize( |
59 pp_resource(), | 95 pp_resource(), |
60 context.pp_resource(), | 96 context.pp_resource(), |
61 profile, | 97 profile, |
62 acceleration == PP_HARDWAREACCELERATION_WITHFALLBACK | 98 acceleration == PP_HARDWAREACCELERATION_WITHFALLBACK |
63 ? PP_TRUE | 99 ? PP_TRUE |
64 : PP_FALSE, | 100 : PP_FALSE, |
65 cc.pp_completion_callback()); | 101 cc.pp_completion_callback()); |
66 } | 102 } |
67 return cc.MayForce(PP_ERROR_NOINTERFACE); | 103 return cc.MayForce(PP_ERROR_NOINTERFACE); |
68 } | 104 } |
69 | 105 |
70 int32_t VideoDecoder::Decode(uint32_t decode_id, | 106 int32_t VideoDecoder::Decode(uint32_t decode_id, |
71 uint32_t size, | 107 uint32_t size, |
72 const void* buffer, | 108 const void* buffer, |
73 const CompletionCallback& cc) { | 109 const CompletionCallback& cc) { |
110 if (has_interface<PPB_VideoDecoder_1_0>()) { | |
111 return get_interface<PPB_VideoDecoder_1_0>()->Decode( | |
112 pp_resource(), decode_id, size, buffer, cc.pp_completion_callback()); | |
113 } | |
74 if (has_interface<PPB_VideoDecoder_0_2>()) { | 114 if (has_interface<PPB_VideoDecoder_0_2>()) { |
75 return get_interface<PPB_VideoDecoder_0_2>()->Decode( | 115 return get_interface<PPB_VideoDecoder_0_2>()->Decode( |
76 pp_resource(), decode_id, size, buffer, cc.pp_completion_callback()); | 116 pp_resource(), decode_id, size, buffer, cc.pp_completion_callback()); |
77 } | 117 } |
78 if (has_interface<PPB_VideoDecoder_0_1>()) { | 118 if (has_interface<PPB_VideoDecoder_0_1>()) { |
79 return get_interface<PPB_VideoDecoder_0_1>()->Decode( | 119 return get_interface<PPB_VideoDecoder_0_1>()->Decode( |
80 pp_resource(), decode_id, size, buffer, cc.pp_completion_callback()); | 120 pp_resource(), decode_id, size, buffer, cc.pp_completion_callback()); |
81 } | 121 } |
82 return cc.MayForce(PP_ERROR_NOINTERFACE); | 122 return cc.MayForce(PP_ERROR_NOINTERFACE); |
83 } | 123 } |
84 | 124 |
85 int32_t VideoDecoder::GetPicture( | 125 int32_t VideoDecoder::GetPicture( |
86 const CompletionCallbackWithOutput<PP_VideoPicture>& cc) { | 126 const CompletionCallbackWithOutput<PP_VideoPicture>& cc) { |
87 if (has_interface<PPB_VideoDecoder_0_2>()) { | 127 if (has_interface<PPB_VideoDecoder_1_0>()) { |
88 return get_interface<PPB_VideoDecoder_0_2>()->GetPicture( | 128 return get_interface<PPB_VideoDecoder_1_0>()->GetPicture( |
89 pp_resource(), cc.output(), cc.pp_completion_callback()); | 129 pp_resource(), cc.output(), cc.pp_completion_callback()); |
90 } | 130 } |
131 if (has_interface<PPB_VideoDecoder_0_2>()) { | |
132 // Data for our callback wrapper. The callback handler will delete it. | |
133 CallbackData_0_1* data = new CallbackData_0_1(cc); | |
134 return get_interface<PPB_VideoDecoder_0_2>()->GetPicture( | |
135 pp_resource(), &data->picture, | |
136 PP_MakeCompletionCallback(&CallbackConverter, data)); | |
137 } | |
91 if (has_interface<PPB_VideoDecoder_0_1>()) { | 138 if (has_interface<PPB_VideoDecoder_0_1>()) { |
139 // Data for our callback wrapper. The callback handler will delete it. | |
140 CallbackData_0_1* data = new CallbackData_0_1(cc); | |
92 return get_interface<PPB_VideoDecoder_0_1>()->GetPicture( | 141 return get_interface<PPB_VideoDecoder_0_1>()->GetPicture( |
93 pp_resource(), cc.output(), cc.pp_completion_callback()); | 142 pp_resource(), &data->picture, |
143 PP_MakeCompletionCallback(&CallbackConverter, data)); | |
94 } | 144 } |
95 return cc.MayForce(PP_ERROR_NOINTERFACE); | 145 return cc.MayForce(PP_ERROR_NOINTERFACE); |
96 } | 146 } |
97 | 147 |
98 void VideoDecoder::RecyclePicture(const PP_VideoPicture& picture) { | 148 void VideoDecoder::RecyclePicture(const PP_VideoPicture& picture) { |
99 if (has_interface<PPB_VideoDecoder_0_2>()) { | 149 if (has_interface<PPB_VideoDecoder_1_0>()) { |
150 get_interface<PPB_VideoDecoder_1_0>()->RecyclePicture(pp_resource(), | |
151 &picture); | |
152 } else if (has_interface<PPB_VideoDecoder_0_2>()) { | |
100 get_interface<PPB_VideoDecoder_0_2>()->RecyclePicture(pp_resource(), | 153 get_interface<PPB_VideoDecoder_0_2>()->RecyclePicture(pp_resource(), |
101 &picture); | 154 &picture); |
102 } else if (has_interface<PPB_VideoDecoder_0_1>()) { | 155 } else if (has_interface<PPB_VideoDecoder_0_1>()) { |
103 get_interface<PPB_VideoDecoder_0_1>()->RecyclePicture(pp_resource(), | 156 get_interface<PPB_VideoDecoder_0_1>()->RecyclePicture(pp_resource(), |
104 &picture); | 157 &picture); |
105 } | 158 } |
106 } | 159 } |
107 | 160 |
108 int32_t VideoDecoder::Flush(const CompletionCallback& cc) { | 161 int32_t VideoDecoder::Flush(const CompletionCallback& cc) { |
162 if (has_interface<PPB_VideoDecoder_1_0>()) { | |
163 return get_interface<PPB_VideoDecoder_1_0>()->Flush( | |
164 pp_resource(), cc.pp_completion_callback()); | |
165 } | |
109 if (has_interface<PPB_VideoDecoder_0_2>()) { | 166 if (has_interface<PPB_VideoDecoder_0_2>()) { |
110 return get_interface<PPB_VideoDecoder_0_2>()->Flush( | 167 return get_interface<PPB_VideoDecoder_0_2>()->Flush( |
111 pp_resource(), cc.pp_completion_callback()); | 168 pp_resource(), cc.pp_completion_callback()); |
112 } | 169 } |
113 if (has_interface<PPB_VideoDecoder_0_1>()) { | 170 if (has_interface<PPB_VideoDecoder_0_1>()) { |
114 return get_interface<PPB_VideoDecoder_0_1>()->Flush( | 171 return get_interface<PPB_VideoDecoder_0_1>()->Flush( |
115 pp_resource(), cc.pp_completion_callback()); | 172 pp_resource(), cc.pp_completion_callback()); |
116 } | 173 } |
117 return cc.MayForce(PP_ERROR_NOINTERFACE); | 174 return cc.MayForce(PP_ERROR_NOINTERFACE); |
118 } | 175 } |
119 | 176 |
120 int32_t VideoDecoder::Reset(const CompletionCallback& cc) { | 177 int32_t VideoDecoder::Reset(const CompletionCallback& cc) { |
178 if (has_interface<PPB_VideoDecoder_1_0>()) { | |
179 return get_interface<PPB_VideoDecoder_1_0>()->Reset( | |
180 pp_resource(), cc.pp_completion_callback()); | |
181 } | |
121 if (has_interface<PPB_VideoDecoder_0_2>()) { | 182 if (has_interface<PPB_VideoDecoder_0_2>()) { |
122 return get_interface<PPB_VideoDecoder_0_2>()->Reset( | 183 return get_interface<PPB_VideoDecoder_0_2>()->Reset( |
123 pp_resource(), cc.pp_completion_callback()); | 184 pp_resource(), cc.pp_completion_callback()); |
124 } | 185 } |
125 if (has_interface<PPB_VideoDecoder_0_1>()) { | 186 if (has_interface<PPB_VideoDecoder_0_1>()) { |
126 return get_interface<PPB_VideoDecoder_0_1>()->Reset( | 187 return get_interface<PPB_VideoDecoder_0_1>()->Reset( |
127 pp_resource(), cc.pp_completion_callback()); | 188 pp_resource(), cc.pp_completion_callback()); |
128 } | 189 } |
129 return cc.MayForce(PP_ERROR_NOINTERFACE); | 190 return cc.MayForce(PP_ERROR_NOINTERFACE); |
130 } | 191 } |
131 | 192 |
132 } // namespace pp | 193 } // namespace pp |
OLD | NEW |