Home | History | Annotate | Download | only in cpp
      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 #include "ppapi/cpp/video_decoder.h"
      6 
      7 #include "ppapi/c/pp_errors.h"
      8 #include "ppapi/c/ppb_video_decoder.h"
      9 #include "ppapi/cpp/completion_callback.h"
     10 #include "ppapi/cpp/instance_handle.h"
     11 #include "ppapi/cpp/module.h"
     12 #include "ppapi/cpp/module_impl.h"
     13 
     14 namespace pp {
     15 
     16 namespace {
     17 
     18 template <>
     19 const char* interface_name<PPB_VideoDecoder_0_1>() {
     20   return PPB_VIDEODECODER_INTERFACE_0_1;
     21 }
     22 
     23 }  // namespace
     24 
     25 VideoDecoder::VideoDecoder() {
     26 }
     27 
     28 VideoDecoder::VideoDecoder(const InstanceHandle& instance) {
     29   if (has_interface<PPB_VideoDecoder_0_1>()) {
     30     PassRefFromConstructor(
     31         get_interface<PPB_VideoDecoder_0_1>()->Create(instance.pp_instance()));
     32   }
     33 }
     34 
     35 VideoDecoder::VideoDecoder(const VideoDecoder& other) : Resource(other) {
     36 }
     37 
     38 int32_t VideoDecoder::Initialize(const Graphics3D& context,
     39                                  PP_VideoProfile profile,
     40                                  bool allow_software_fallback,
     41                                  const CompletionCallback& cc) {
     42   if (has_interface<PPB_VideoDecoder_0_1>()) {
     43     return get_interface<PPB_VideoDecoder_0_1>()->Initialize(
     44         pp_resource(),
     45         context.pp_resource(),
     46         profile,
     47         PP_FromBool(allow_software_fallback),
     48         cc.pp_completion_callback());
     49   }
     50   return cc.MayForce(PP_ERROR_NOINTERFACE);
     51 }
     52 
     53 int32_t VideoDecoder::Decode(uint32_t decode_id,
     54                              uint32_t size,
     55                              const void* buffer,
     56                              const CompletionCallback& cc) {
     57   if (has_interface<PPB_VideoDecoder_0_1>()) {
     58     return get_interface<PPB_VideoDecoder_0_1>()->Decode(
     59         pp_resource(), decode_id, size, buffer, cc.pp_completion_callback());
     60   }
     61   return cc.MayForce(PP_ERROR_NOINTERFACE);
     62 }
     63 
     64 int32_t VideoDecoder::GetPicture(
     65     const CompletionCallbackWithOutput<PP_VideoPicture>& cc) {
     66   if (has_interface<PPB_VideoDecoder_0_1>()) {
     67     return get_interface<PPB_VideoDecoder_0_1>()->GetPicture(
     68         pp_resource(), cc.output(), cc.pp_completion_callback());
     69   }
     70   return cc.MayForce(PP_ERROR_NOINTERFACE);
     71 }
     72 
     73 void VideoDecoder::RecyclePicture(const PP_VideoPicture& picture) {
     74   if (has_interface<PPB_VideoDecoder_0_1>()) {
     75     get_interface<PPB_VideoDecoder_0_1>()->RecyclePicture(pp_resource(),
     76                                                           &picture);
     77   }
     78 }
     79 
     80 int32_t VideoDecoder::Flush(const CompletionCallback& cc) {
     81   if (has_interface<PPB_VideoDecoder_0_1>()) {
     82     return get_interface<PPB_VideoDecoder_0_1>()->Flush(
     83         pp_resource(), cc.pp_completion_callback());
     84   }
     85   return cc.MayForce(PP_ERROR_NOINTERFACE);
     86 }
     87 
     88 int32_t VideoDecoder::Reset(const CompletionCallback& cc) {
     89   if (has_interface<PPB_VideoDecoder_0_1>()) {
     90     return get_interface<PPB_VideoDecoder_0_1>()->Reset(
     91         pp_resource(), cc.pp_completion_callback());
     92   }
     93   return cc.MayForce(PP_ERROR_NOINTERFACE);
     94 }
     95 
     96 }  // namespace pp
     97