Roll src/third_party/skia b9ed884:8566539
[chromium-blink-merge.git] / ppapi / cpp / video_encoder.cc
bloba8c03f297e1869d276772d855b11acfbd930c3e1
1 // Copyright 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.
5 #include "ppapi/cpp/video_encoder.h"
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"
14 namespace pp {
16 namespace {
18 template <>
19 const char* interface_name<PPB_VideoEncoder_0_1>() {
20 return PPB_VIDEOENCODER_INTERFACE_0_1;
23 } // namespace
25 VideoEncoder::VideoEncoder() {
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()));
35 VideoEncoder::VideoEncoder(const VideoEncoder& other) : Resource(other) {
38 int32_t VideoEncoder::GetSupportedProfiles(const CompletionCallbackWithOutput<
39 std::vector<PP_VideoProfileDescription> >& 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());
44 return cc.MayForce(PP_ERROR_NOINTERFACE);
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());
59 return cc.MayForce(PP_ERROR_NOINTERFACE);
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());
67 return PP_ERROR_NOINTERFACE;
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());
75 return PP_ERROR_NOINTERFACE;
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());
84 return cc.MayForce(PP_ERROR_NOINTERFACE);
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());
95 return cc.MayForce(PP_ERROR_NOINTERFACE);
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());
104 return cc.MayForce(PP_ERROR_NOINTERFACE);
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);
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);
123 void VideoEncoder::Close() {
124 if (has_interface<PPB_VideoEncoder_0_1>()) {
125 get_interface<PPB_VideoEncoder_0_1>()->Close(pp_resource());
129 } // namespace pp