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(const CompletionCallbackWithOutput< |
| 39 std::vector<PP_SupportedVideoProfile>>& cc) { |
| 40 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 41 return get_interface<PPB_VideoEncoder_0_1>()->GetSupportedProfiles( |
| 42 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 43 } |
| 44 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 45 } |
| 46 |
| 47 int32_t VideoEncoder::Initialize(const PP_VideoFrame_Format& input_format, |
| 48 const Size& input_visible_size, |
| 49 const PP_VideoProfile& output_profile, |
| 50 const uint32_t initial_bitrate, |
| 51 PP_HardwareAcceleration acceleration, |
| 52 const CompletionCallback& cc) { |
| 53 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 54 return get_interface<PPB_VideoEncoder_0_1>()->Initialize( |
| 55 pp_resource(), input_format, &input_visible_size.pp_size(), |
| 56 output_profile, initial_bitrate, acceleration, |
| 57 cc.pp_completion_callback()); |
| 58 } |
| 59 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 60 } |
| 61 |
| 62 int32_t VideoEncoder::GetFramesRequired() { |
| 63 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 64 return get_interface<PPB_VideoEncoder_0_1>()->GetFramesRequired( |
| 65 pp_resource()); |
| 66 } |
| 67 return PP_ERROR_NOINTERFACE; |
| 68 } |
| 69 |
| 70 int32_t VideoEncoder::GetFrameCodedSize(Size* coded_size) { |
| 71 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 72 return get_interface<PPB_VideoEncoder_0_1>()->GetFrameCodedSize( |
| 73 pp_resource(), &coded_size->pp_size()); |
| 74 } |
| 75 return PP_ERROR_NOINTERFACE; |
| 76 } |
| 77 |
| 78 int32_t VideoEncoder::GetVideoFrame( |
| 79 const CompletionCallbackWithOutput<VideoFrame>& cc) { |
| 80 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 81 return get_interface<PPB_VideoEncoder_0_1>()->GetVideoFrame( |
| 82 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 83 } |
| 84 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 85 } |
| 86 |
| 87 int32_t VideoEncoder::Encode(const VideoFrame& video_frame, |
| 88 bool force_keyframe, |
| 89 const CompletionCallback& cc) { |
| 90 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 91 return get_interface<PPB_VideoEncoder_0_1>()->Encode( |
| 92 pp_resource(), video_frame.pp_resource(), PP_FromBool(force_keyframe), |
| 93 cc.pp_completion_callback()); |
| 94 } |
| 95 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 96 } |
| 97 |
| 98 int32_t VideoEncoder::GetBitstreamBuffer( |
| 99 const CompletionCallbackWithOutput<PP_BitstreamBuffer>& cc) { |
| 100 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 101 return get_interface<PPB_VideoEncoder_0_1>()->GetBitstreamBuffer( |
| 102 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 103 } |
| 104 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 105 } |
| 106 |
| 107 void VideoEncoder::RecycleBitstreamBuffer( |
| 108 const PP_BitstreamBuffer& bitstream_buffer) { |
| 109 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 110 get_interface<PPB_VideoEncoder_0_1>()->RecycleBitstreamBuffer( |
| 111 pp_resource(), &bitstream_buffer); |
| 112 } |
| 113 } |
| 114 |
| 115 void VideoEncoder::RequestEncodingParametersChange(uint32_t bitrate, |
| 116 uint32_t framerate) { |
| 117 if (has_interface<PPB_VideoEncoder_0_1>()) { |
| 118 get_interface<PPB_VideoEncoder_0_1>()->RequestEncodingParametersChange( |
| 119 pp_resource(), bitrate, framerate); |
| 120 } |
| 121 } |
| 122 |
| 123 } // namespace pp |
OLD | NEW |