1 // Copyright (c) 2012 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_errors.h"
6 #include "ppapi/shared_impl/tracked_callback.h"
7 #include "ppapi/thunk/enter.h"
8 #include "ppapi/thunk/thunk.h"
9 #include "ppapi/thunk/ppb_video_decoder_api.h"
10 #include "ppapi/thunk/resource_creation_api.h"
11
12 namespace ppapi {
13 namespace thunk {
14
15 namespace {
16
17 typedef EnterResource<PPB_VideoDecoder_API> EnterVideoDecoder;
18
Create(PP_Instance instance,PP_Resource graphics_3d,PP_VideoDecoder_Profile profile)19 PP_Resource Create(PP_Instance instance,
20 PP_Resource graphics_3d,
21 PP_VideoDecoder_Profile profile) {
22 EnterResourceCreation enter(instance);
23 if (enter.failed())
24 return 0;
25 return enter.functions()->CreateVideoDecoder(instance, graphics_3d, profile);
26 }
27
IsVideoDecoder(PP_Resource resource)28 PP_Bool IsVideoDecoder(PP_Resource resource) {
29 EnterVideoDecoder enter(resource, false);
30 return PP_FromBool(enter.succeeded());
31 }
32
Decode(PP_Resource video_decoder,const PP_VideoBitstreamBuffer_Dev * bitstream_buffer,PP_CompletionCallback callback)33 int32_t Decode(PP_Resource video_decoder,
34 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
35 PP_CompletionCallback callback) {
36 EnterVideoDecoder enter(video_decoder, callback, true);
37 if (enter.failed())
38 return enter.retval();
39 return enter.SetResult(enter.object()->Decode(bitstream_buffer,
40 enter.callback()));
41 }
42
AssignPictureBuffers(PP_Resource video_decoder,uint32_t no_of_buffers,const PP_PictureBuffer_Dev * buffers)43 void AssignPictureBuffers(PP_Resource video_decoder,
44 uint32_t no_of_buffers,
45 const PP_PictureBuffer_Dev* buffers) {
46 EnterVideoDecoder enter(video_decoder, true);
47 if (enter.succeeded())
48 enter.object()->AssignPictureBuffers(no_of_buffers, buffers);
49 }
50
ReusePictureBuffer(PP_Resource video_decoder,int32_t picture_buffer_id)51 void ReusePictureBuffer(PP_Resource video_decoder, int32_t picture_buffer_id) {
52 EnterVideoDecoder enter(video_decoder, true);
53 if (enter.succeeded())
54 enter.object()->ReusePictureBuffer(picture_buffer_id);
55 }
56
Flush(PP_Resource video_decoder,PP_CompletionCallback callback)57 int32_t Flush(PP_Resource video_decoder, PP_CompletionCallback callback) {
58 EnterVideoDecoder enter(video_decoder, callback, true);
59 if (enter.failed())
60 return enter.retval();
61 return enter.SetResult(enter.object()->Flush(enter.callback()));
62 }
63
Reset(PP_Resource video_decoder,PP_CompletionCallback callback)64 int32_t Reset(PP_Resource video_decoder,
65 PP_CompletionCallback callback) {
66 EnterVideoDecoder enter(video_decoder, callback, true);
67 if (enter.failed())
68 return enter.retval();
69 return enter.SetResult(enter.object()->Reset(enter.callback()));
70 }
71
Destroy(PP_Resource video_decoder)72 void Destroy(PP_Resource video_decoder) {
73 EnterVideoDecoder enter(video_decoder, true);
74 if (enter.succeeded())
75 enter.object()->Destroy();
76 }
77
78 const PPB_VideoDecoder_Dev g_ppb_videodecoder_thunk = {
79 &Create,
80 &IsVideoDecoder,
81 &Decode,
82 &AssignPictureBuffers,
83 &ReusePictureBuffer,
84 &Flush,
85 &Reset,
86 &Destroy
87 };
88
89 } // namespace
90
GetPPB_VideoDecoder_Dev_0_16_Thunk()91 const PPB_VideoDecoder_Dev_0_16* GetPPB_VideoDecoder_Dev_0_16_Thunk() {
92 return &g_ppb_videodecoder_thunk;
93 }
94
95 } // namespace thunk
96 } // namespace ppapi
97