OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 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_encoder.h" |
| 6 |
| 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/ppb_video_encoder.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_VideoEncoder_0_1>() { |
| 20 return PPB_VIDEOENCODER_INTERFACE_0_1; |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
| 25 VideoEncoder::VideoEncoder() { |
| 26 } |
| 27 |
| 28 VideoEncoder::VideoEncoder(const InstanceHandle& instance) { |
| 29 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 30 PassRefFromConstructor( |
| 31 get_interface<PPB_VideoEncoder_0_1>()->Create(instance.pp_instance())); |
| 32 } |
| 33 } |
| 34 |
| 35 VideoEncoder::VideoEncoder(const VideoEncoder& other) : Resource(other) { |
| 36 } |
| 37 |
| 38 int32_t VideoEncoder::GetSupportedProfiles( |
| 39 const CompletionCallbackWithOutput< |
| 40 std::vector<PP_SupportedVideoProfile> >& cc) { |
| 41 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 42 return get_interface<PPB_VideoEncoder_0_1>()->GetSupportedProfiles( |
| 43 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 44 } |
| 45 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 46 } |
| 47 |
| 48 int32_t VideoEncoder::Initialize(const PP_VideoFrame_Format& input_format, |
| 49 const PP_Size& input_visible_size, |
| 50 const PP_VideoProfile& output_profile, |
| 51 const uint32_t initial_bitrate, |
| 52 PP_HardwareAcceleration acceleration, |
| 53 const CompletionCallback& cc) { |
| 54 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 55 return get_interface<PPB_VideoEncoder_0_1>()->Initialize( |
| 56 pp_resource(), input_format, &input_visible_size, output_profile, |
| 57 initial_bitrate, acceleration, cc.pp_completion_callback()); |
| 58 } |
| 59 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 60 } |
| 61 |
| 62 int32_t VideoEncoder::GetVideoFrame( |
| 63 const CompletionCallbackWithOutput<VideoFrame>& cc) { |
| 64 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 65 return get_interface<PPB_VideoEncoder_0_1>()->GetVideoFrame( |
| 66 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 67 } |
| 68 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 69 } |
| 70 |
| 71 int32_t VideoEncoder::Encode( |
| 72 const VideoFrame& video_frame, |
| 73 bool force_keyframe, |
| 74 const CompletionCallback& cc) { |
| 75 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 76 return get_interface<PPB_VideoEncoder_0_1>()->Encode( |
| 77 pp_resource(), video_frame.pp_resource(), PP_FromBool(force_keyframe), |
| 78 cc.pp_completion_callback()); |
| 79 } |
| 80 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 81 } |
| 82 |
| 83 int32_t VideoEncoder::GetBitstreamBuffer( |
| 84 const CompletionCallbackWithOutput<PP_BitstreamBuffer>& cc) { |
| 85 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 86 return get_interface<PPB_VideoEncoder_0_1>()->GetBitstreamBuffer( |
| 87 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 88 } |
| 89 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 90 } |
| 91 |
| 92 void VideoEncoder::RecycleBitstreamBuffer( |
| 93 const PP_BitstreamBuffer& bitstream_buffer) { |
| 94 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 95 get_interface<PPB_VideoEncoder_0_1>()->RecycleBitstreamBuffer( |
| 96 pp_resource(), &bitstream_buffer); |
| 97 } |
| 98 } |
| 99 |
| 100 void VideoEncoder::RequestEncodingParametersChange( |
| 101 uint32_t bitrate, |
| 102 uint32_t framerate) { |
| 103 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 104 get_interface<PPB_VideoEncoder_0_1>()->RequestEncodingParametersChange( |
| 105 pp_resource(), bitrate, framerate); |
| 106 } |
| 107 } |
| 108 |
| 109 } // namespace pp |
OLD | NEW |