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 <> |
| 24 const char* interface_name<PPB_VideoDecoder_0_2>() { |
| 25 return PPB_VIDEODECODER_INTERFACE_0_2; |
| 26 } |
| 27 |
23 } // namespace | 28 } // namespace |
24 | 29 |
25 VideoDecoder::VideoDecoder() { | 30 VideoDecoder::VideoDecoder() { |
26 } | 31 } |
27 | 32 |
28 VideoDecoder::VideoDecoder(const InstanceHandle& instance) { | 33 VideoDecoder::VideoDecoder(const InstanceHandle& instance) { |
29 if (has_interface<PPB_VideoDecoder_0_1>()) { | 34 if (has_interface<PPB_VideoDecoder_0_1>()) { |
30 PassRefFromConstructor( | 35 PassRefFromConstructor( |
31 get_interface<PPB_VideoDecoder_0_1>()->Create(instance.pp_instance())); | 36 get_interface<PPB_VideoDecoder_0_1>()->Create(instance.pp_instance())); |
32 } | 37 } |
33 } | 38 } |
34 | 39 |
35 VideoDecoder::VideoDecoder(const VideoDecoder& other) : Resource(other) { | 40 VideoDecoder::VideoDecoder(const VideoDecoder& other) : Resource(other) { |
36 } | 41 } |
37 | 42 |
38 int32_t VideoDecoder::Initialize(const Graphics3D& context, | 43 int32_t VideoDecoder::Initialize(const Graphics3D& context, |
39 PP_VideoProfile profile, | 44 PP_VideoProfile profile, |
40 bool allow_software_fallback, | 45 PP_HardwareAcceleration acceleration, |
41 const CompletionCallback& cc) { | 46 const CompletionCallback& cc) { |
| 47 if (has_interface<PPB_VideoDecoder_0_2>()) { |
| 48 return get_interface<PPB_VideoDecoder_0_2>()->Initialize( |
| 49 pp_resource(), |
| 50 context.pp_resource(), |
| 51 profile, |
| 52 acceleration, |
| 53 cc.pp_completion_callback()); |
| 54 } |
42 if (has_interface<PPB_VideoDecoder_0_1>()) { | 55 if (has_interface<PPB_VideoDecoder_0_1>()) { |
| 56 if (acceleration == PP_HARDWAREACCELERATION_NONE) |
| 57 return cc.MayForce(PP_ERROR_NOTSUPPORTED); |
43 return get_interface<PPB_VideoDecoder_0_1>()->Initialize( | 58 return get_interface<PPB_VideoDecoder_0_1>()->Initialize( |
44 pp_resource(), | 59 pp_resource(), |
45 context.pp_resource(), | 60 context.pp_resource(), |
46 profile, | 61 profile, |
47 PP_FromBool(allow_software_fallback), | 62 acceleration == PP_HARDWAREACCELERATION_WITHFALLBACK |
| 63 ? PP_TRUE |
| 64 : PP_FALSE, |
48 cc.pp_completion_callback()); | 65 cc.pp_completion_callback()); |
49 } | 66 } |
50 return cc.MayForce(PP_ERROR_NOINTERFACE); | 67 return cc.MayForce(PP_ERROR_NOINTERFACE); |
51 } | 68 } |
52 | 69 |
53 int32_t VideoDecoder::Decode(uint32_t decode_id, | 70 int32_t VideoDecoder::Decode(uint32_t decode_id, |
54 uint32_t size, | 71 uint32_t size, |
55 const void* buffer, | 72 const void* buffer, |
56 const CompletionCallback& cc) { | 73 const CompletionCallback& cc) { |
| 74 if (has_interface<PPB_VideoDecoder_0_2>()) { |
| 75 return get_interface<PPB_VideoDecoder_0_2>()->Decode( |
| 76 pp_resource(), decode_id, size, buffer, cc.pp_completion_callback()); |
| 77 } |
57 if (has_interface<PPB_VideoDecoder_0_1>()) { | 78 if (has_interface<PPB_VideoDecoder_0_1>()) { |
58 return get_interface<PPB_VideoDecoder_0_1>()->Decode( | 79 return get_interface<PPB_VideoDecoder_0_1>()->Decode( |
59 pp_resource(), decode_id, size, buffer, cc.pp_completion_callback()); | 80 pp_resource(), decode_id, size, buffer, cc.pp_completion_callback()); |
60 } | 81 } |
61 return cc.MayForce(PP_ERROR_NOINTERFACE); | 82 return cc.MayForce(PP_ERROR_NOINTERFACE); |
62 } | 83 } |
63 | 84 |
64 int32_t VideoDecoder::GetPicture( | 85 int32_t VideoDecoder::GetPicture( |
65 const CompletionCallbackWithOutput<PP_VideoPicture>& cc) { | 86 const CompletionCallbackWithOutput<PP_VideoPicture>& cc) { |
| 87 if (has_interface<PPB_VideoDecoder_0_2>()) { |
| 88 return get_interface<PPB_VideoDecoder_0_2>()->GetPicture( |
| 89 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 90 } |
66 if (has_interface<PPB_VideoDecoder_0_1>()) { | 91 if (has_interface<PPB_VideoDecoder_0_1>()) { |
67 return get_interface<PPB_VideoDecoder_0_1>()->GetPicture( | 92 return get_interface<PPB_VideoDecoder_0_1>()->GetPicture( |
68 pp_resource(), cc.output(), cc.pp_completion_callback()); | 93 pp_resource(), cc.output(), cc.pp_completion_callback()); |
69 } | 94 } |
70 return cc.MayForce(PP_ERROR_NOINTERFACE); | 95 return cc.MayForce(PP_ERROR_NOINTERFACE); |
71 } | 96 } |
72 | 97 |
73 void VideoDecoder::RecyclePicture(const PP_VideoPicture& picture) { | 98 void VideoDecoder::RecyclePicture(const PP_VideoPicture& picture) { |
74 if (has_interface<PPB_VideoDecoder_0_1>()) { | 99 if (has_interface<PPB_VideoDecoder_0_2>()) { |
| 100 get_interface<PPB_VideoDecoder_0_2>()->RecyclePicture(pp_resource(), |
| 101 &picture); |
| 102 } else if (has_interface<PPB_VideoDecoder_0_1>()) { |
75 get_interface<PPB_VideoDecoder_0_1>()->RecyclePicture(pp_resource(), | 103 get_interface<PPB_VideoDecoder_0_1>()->RecyclePicture(pp_resource(), |
76 &picture); | 104 &picture); |
77 } | 105 } |
78 } | 106 } |
79 | 107 |
80 int32_t VideoDecoder::Flush(const CompletionCallback& cc) { | 108 int32_t VideoDecoder::Flush(const CompletionCallback& cc) { |
| 109 if (has_interface<PPB_VideoDecoder_0_2>()) { |
| 110 return get_interface<PPB_VideoDecoder_0_2>()->Flush( |
| 111 pp_resource(), cc.pp_completion_callback()); |
| 112 } |
81 if (has_interface<PPB_VideoDecoder_0_1>()) { | 113 if (has_interface<PPB_VideoDecoder_0_1>()) { |
82 return get_interface<PPB_VideoDecoder_0_1>()->Flush( | 114 return get_interface<PPB_VideoDecoder_0_1>()->Flush( |
83 pp_resource(), cc.pp_completion_callback()); | 115 pp_resource(), cc.pp_completion_callback()); |
84 } | 116 } |
85 return cc.MayForce(PP_ERROR_NOINTERFACE); | 117 return cc.MayForce(PP_ERROR_NOINTERFACE); |
86 } | 118 } |
87 | 119 |
88 int32_t VideoDecoder::Reset(const CompletionCallback& cc) { | 120 int32_t VideoDecoder::Reset(const CompletionCallback& cc) { |
| 121 if (has_interface<PPB_VideoDecoder_0_2>()) { |
| 122 return get_interface<PPB_VideoDecoder_0_2>()->Reset( |
| 123 pp_resource(), cc.pp_completion_callback()); |
| 124 } |
89 if (has_interface<PPB_VideoDecoder_0_1>()) { | 125 if (has_interface<PPB_VideoDecoder_0_1>()) { |
90 return get_interface<PPB_VideoDecoder_0_1>()->Reset( | 126 return get_interface<PPB_VideoDecoder_0_1>()->Reset( |
91 pp_resource(), cc.pp_completion_callback()); | 127 pp_resource(), cc.pp_completion_callback()); |
92 } | 128 } |
93 return cc.MayForce(PP_ERROR_NOINTERFACE); | 129 return cc.MayForce(PP_ERROR_NOINTERFACE); |
94 } | 130 } |
95 | 131 |
96 } // namespace pp | 132 } // namespace pp |
OLD | NEW |