Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ppapi / thunk / ppb_video_decoder_thunk.cc
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
3 // found in the LICENSE file.
4
5 // From ppb_video_decoder.idl modified Tue May  6 05:06:35 2014.
6
7 #include "ppapi/c/pp_completion_callback.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/ppb_video_decoder.h"
10 #include "ppapi/shared_impl/tracked_callback.h"
11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/ppapi_thunk_export.h"
13 #include "ppapi/thunk/ppb_video_decoder_api.h"
14
15 namespace ppapi {
16 namespace thunk {
17
18 namespace {
19
20 PP_Resource Create(PP_Instance instance) {
21   VLOG(4) << "PPB_VideoDecoder::Create()";
22   EnterResourceCreation enter(instance);
23   if (enter.failed())
24     return 0;
25   return enter.functions()->CreateVideoDecoder(instance);
26 }
27
28 PP_Bool IsVideoDecoder(PP_Resource resource) {
29   VLOG(4) << "PPB_VideoDecoder::IsVideoDecoder()";
30   EnterResource<PPB_VideoDecoder_API> enter(resource, false);
31   return PP_FromBool(enter.succeeded());
32 }
33
34 int32_t Initialize(PP_Resource video_decoder,
35                    PP_Resource graphics3d_context,
36                    PP_VideoProfile profile,
37                    PP_Bool allow_software_fallback,
38                    struct PP_CompletionCallback callback) {
39   VLOG(4) << "PPB_VideoDecoder::Initialize()";
40   EnterResource<PPB_VideoDecoder_API> enter(video_decoder, callback, true);
41   if (enter.failed())
42     return enter.retval();
43   return enter.SetResult(enter.object()->Initialize(graphics3d_context,
44                                                     profile,
45                                                     allow_software_fallback,
46                                                     enter.callback()));
47 }
48
49 int32_t Decode(PP_Resource video_decoder,
50                uint32_t decode_id,
51                uint32_t size,
52                const void* buffer,
53                struct PP_CompletionCallback callback) {
54   VLOG(4) << "PPB_VideoDecoder::Decode()";
55   EnterResource<PPB_VideoDecoder_API> enter(video_decoder, callback, true);
56   if (enter.failed())
57     return enter.retval();
58   return enter.SetResult(enter.object()->Decode(decode_id,
59                                                 size,
60                                                 buffer,
61                                                 enter.callback()));
62 }
63
64 int32_t GetPicture(PP_Resource video_decoder,
65                    struct PP_VideoPicture* picture,
66                    struct PP_CompletionCallback callback) {
67   VLOG(4) << "PPB_VideoDecoder::GetPicture()";
68   EnterResource<PPB_VideoDecoder_API> enter(video_decoder, callback, true);
69   if (enter.failed())
70     return enter.retval();
71   return enter.SetResult(enter.object()->GetPicture(picture, enter.callback()));
72 }
73
74 void RecyclePicture(PP_Resource video_decoder,
75                     const struct PP_VideoPicture* picture) {
76   VLOG(4) << "PPB_VideoDecoder::RecyclePicture()";
77   EnterResource<PPB_VideoDecoder_API> enter(video_decoder, true);
78   if (enter.failed())
79     return;
80   enter.object()->RecyclePicture(picture);
81 }
82
83 int32_t Flush(PP_Resource video_decoder,
84               struct PP_CompletionCallback callback) {
85   VLOG(4) << "PPB_VideoDecoder::Flush()";
86   EnterResource<PPB_VideoDecoder_API> enter(video_decoder, callback, true);
87   if (enter.failed())
88     return enter.retval();
89   return enter.SetResult(enter.object()->Flush(enter.callback()));
90 }
91
92 int32_t Reset(PP_Resource video_decoder,
93               struct PP_CompletionCallback callback) {
94   VLOG(4) << "PPB_VideoDecoder::Reset()";
95   EnterResource<PPB_VideoDecoder_API> enter(video_decoder, callback, true);
96   if (enter.failed())
97     return enter.retval();
98   return enter.SetResult(enter.object()->Reset(enter.callback()));
99 }
100
101 const PPB_VideoDecoder_0_1 g_ppb_videodecoder_thunk_0_1 = {
102   &Create,
103   &IsVideoDecoder,
104   &Initialize,
105   &Decode,
106   &GetPicture,
107   &RecyclePicture,
108   &Flush,
109   &Reset
110 };
111
112 }  // namespace
113
114 PPAPI_THUNK_EXPORT const PPB_VideoDecoder_0_1*
115     GetPPB_VideoDecoder_0_1_Thunk() {
116   return &g_ppb_videodecoder_thunk_0_1;
117 }
118
119 }  // namespace thunk
120 }  // namespace ppapi