- add sources.
[platform/framework/web/crosswalk.git] / src / ppapi / thunk / ppb_video_source_private_thunk.cc
1 // Copyright (c) 2013 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 #include "ppapi/c/pp_completion_callback.h"
6 #include "ppapi/c/pp_errors.h"
7 #include "ppapi/c/private/pp_video_frame_private.h"
8 #include "ppapi/c/private/ppb_video_source_private.h"
9 #include "ppapi/shared_impl/tracked_callback.h"
10 #include "ppapi/thunk/enter.h"
11 #include "ppapi/thunk/ppb_video_source_private_api.h"
12 #include "ppapi/thunk/resource_creation_api.h"
13 #include "ppapi/thunk/thunk.h"
14
15 namespace ppapi {
16 namespace thunk {
17
18 namespace {
19
20 PP_Resource Create(PP_Instance instance) {
21   EnterResourceCreation enter(instance);
22   if (enter.failed())
23     return 0;
24   return enter.functions()->CreateVideoSource(instance);
25 }
26
27 PP_Bool IsVideoSource(PP_Resource resource) {
28   EnterResource<PPB_VideoSource_Private_API> enter(resource, false);
29   return PP_FromBool(enter.succeeded());
30 }
31
32 int32_t Open(PP_Resource source,
33              PP_Var stream_url,
34              PP_CompletionCallback callback) {
35   EnterResource<PPB_VideoSource_Private_API> enter(source, callback, true);
36   if (enter.failed())
37     return enter.retval();
38   return enter.SetResult(enter.object()->Open(stream_url, enter.callback()));
39 }
40
41 int32_t GetFrame(PP_Resource source,
42                  PP_VideoFrame_Private* frame,
43                  PP_CompletionCallback callback) {
44   EnterResource<PPB_VideoSource_Private_API> enter(source, callback, true);
45   if (enter.failed())
46     return enter.retval();
47   return enter.SetResult(enter.object()->GetFrame(frame, enter.callback()));
48 }
49
50 void Close(PP_Resource source) {
51   EnterResource<PPB_VideoSource_Private_API> enter(source, true);
52   if (enter.succeeded())
53     enter.object()->Close();
54 }
55
56 const PPB_VideoSource_Private_0_1 g_ppb_video_source_private_thunk_0_1 = {
57   &Create,
58   &IsVideoSource,
59   &Open,
60   &GetFrame,
61   &Close
62 };
63
64 }  // namespace
65
66 const PPB_VideoSource_Private_0_1* GetPPB_VideoSource_Private_0_1_Thunk() {
67   return &g_ppb_video_source_private_thunk_0_1;
68 }
69
70 }  // namespace thunk
71 }  // namespace ppapi