OLD | NEW |
(Empty) | |
| 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 #ifndef PPAPI_CPP_VIDEO_ENCODER_H_ |
| 6 #define PPAPI_CPP_VIDEO_ENCODER_H_ |
| 7 |
| 8 #include "ppapi/c/ppb_video_encoder.h" |
| 9 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/cpp/graphics_3d.h" |
| 11 #include "ppapi/cpp/resource.h" |
| 12 #include "ppapi/cpp/size.h" |
| 13 |
| 14 /// @file |
| 15 /// This file defines the API to create and use a VideoEncoder resource. |
| 16 |
| 17 struct PP_FileInfo; |
| 18 |
| 19 namespace pp { |
| 20 |
| 21 class InstanceHandle; |
| 22 |
| 23 /// Video encoder interface. |
| 24 /// |
| 25 /// Typical usage: |
| 26 /// - Call Create() to create a new video encoder resource. |
| 27 /// - Call Initialize() to initialize it with a 3d graphics context, the |
| 28 /// desired codec parameters. |
| 29 /// - Call Encode() continuously (waiting for each previous call to complete) to |
| 30 /// push video picture to the encoder. |
| 31 /// - Call Reset() to quickly stop the encoder and wait for the callback before |
| 32 /// restarting encoding. |
| 33 /// - To destroy the encoder, the plugin should release all of its references to |
| 34 /// it. Any pending callbacks will abort before the encoder is destroyed. |
| 35 /// |
| 36 /// Available video codecs vary by platform. |
| 37 class VideoEncoder : public Resource { |
| 38 public: |
| 39 /// Default constructor for creating an is_null() |
| 40 /// <code>VideoEncoder</code> object. |
| 41 VideoEncoder(); |
| 42 |
| 43 /// A constructor used to create a <code>VideoEncoder</code> and associate it |
| 44 /// with the provided <code>Instance</code>. |
| 45 /// @param[in] instance The instance with which this resource will be |
| 46 /// associated. |
| 47 explicit VideoEncoder(const InstanceHandle& instance); |
| 48 |
| 49 /// A constructor used to create a <code>VideoEncoder</code> and associate |
| 50 /// it with the provided <code>PP_Resource</code>. |
| 51 /// @param[in] encoder_resource The resource with which this instance will be |
| 52 /// associated. |
| 53 explicit VideoEncoder(PP_Resource resource); |
| 54 |
| 55 /// The copy constructor for <code>VideoEncoder</code>. |
| 56 /// @param[in] other A reference to a <code>VideoEncoder</code>. |
| 57 VideoEncoder(const VideoEncoder& other); |
| 58 |
| 59 /// Initializes a video encoder resource. This should be called after Create() |
| 60 /// and before any other functions. |
| 61 /// |
| 62 /// @param[in] context A <code>PP_Resource</code> identifying the OpenGL |
| 63 /// context used to access textures. |
| 64 /// @param[in] profile A <code>PP_VideoEncoderParams</code> specifying the |
| 65 /// video encoding parameters. |
| 66 // @param[in] user_data A pointer to a user_data to be passed the |callback|. |
| 67 /// @param[in] callback A <code>CompletionCallback</code> to be called on |
| 68 /// completion. |
| 69 /// |
| 70 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 71 /// Returns PP_ERROR_NOTSUPPORTED if video decoding is not available, or the |
| 72 /// requested profile is not supported. In this case, the client may call |
| 73 /// Initialize() again with different parameters to find a good configuration. |
| 74 int32_t Initialize( |
| 75 const Graphics3D& context, |
| 76 const PP_VideoEncoderParams& params, |
| 77 void* user_data, |
| 78 PPB_VideoEncoder_Ready_Func callback); |
| 79 |
| 80 /// Encodes a picture. The plugin should wait until the encoder signals |
| 81 /// completion by returning PP_OK or by running |callback| before calling |
| 82 /// Encode() again. |
| 83 /// |
| 84 /// If the call to Encode() eventually results in a bitstream buffer, the |
| 85 /// |encode_id| parameter is copied into the returned buffer. The plugin can |
| 86 /// use this to associate bitstream buffers with Encode() calls (e.g. to |
| 87 /// assign timestamps) This value is opaque to the API so the plugin is free |
| 88 /// to pass any value. |
| 89 /// |
| 90 /// @param[in] encode_id An optional value, chosen by the plugin, that can be |
| 91 /// used to associate calls to Encode() with bitstream buffers returned by |
| 92 /// GetBitstreamBuffer(). |
| 93 /// @param[in] picture A video picture to encode. |
| 94 /// @param[in] force_keyframe Force the encoder to produce a key frame. |
| 95 /// @param[in] callback A <code>CompletionCallback</code> to be called on |
| 96 /// completion. |
| 97 /// |
| 98 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 99 /// Returns PP_ERROR_FAILED if the encoder isn't initialized or Reset() call |
| 100 /// is pending. |
| 101 /// Returns PP_ERROR_INPROGRESS if there is another Encode() call pending. |
| 102 /// Returns PP_ERROR_ABORTED when Reset() is called while Encode() is pending. |
| 103 int32_t Encode(uint32_t encode_id, |
| 104 const PP_VideoEncoderPicture& picture, |
| 105 const PP_Bool force_keyframe, |
| 106 const CompletionCallback& callback); |
| 107 |
| 108 /// Resets the encoder as quickly as possible. After Reset() returns, any |
| 109 /// pending calls to Encode() or GetBitstreamBuffer() abort, causing their |
| 110 /// callbacks to run with PP_ERROR_ABORTED. The plugin should not make further |
| 111 /// calls to the encoder until the encoder signals completion by running |
| 112 /// |callback|. |
| 113 /// |
| 114 /// @param[in] callback A <code>CompletionCallback</code> to be called on |
| 115 /// completion. |
| 116 /// |
| 117 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 118 /// Returns PP_ERROR_FAILED if the encoder isn't initialized. |
| 119 int32_t Reset(const CompletionCallback& callback); |
| 120 }; |
| 121 |
| 122 } // namespace pp |
| 123 |
| 124 #endif // PPAPI_CPP_VIDEO_ENCODER_H_ |
OLD | NEW |