Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(792)

Side by Side Diff: ppapi/cpp/video_encoder.h

Issue 842293003: Pepper: Define PPB_VideoEncoder API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update and add comments. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #ifndef PPAPI_CPP_VIDEO_ENCODER_H_
6 #define PPAPI_CPP_VIDEO_ENCODER_H_
7
8 #include "ppapi/c/pp_codecs.h"
9 #include "ppapi/c/pp_size.h"
10 #include "ppapi/cpp/completion_callback.h"
11 #include "ppapi/cpp/graphics_3d.h"
12 #include "ppapi/cpp/resource.h"
13 #include "ppapi/cpp/size.h"
14 #include "ppapi/cpp/video_frame.h"
15
16 /// @file
17 /// This file defines the API to create and use a VideoEncoder resource.
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 GetSupportedFormats() to determine which codecs and profiles are
28 /// available.
29 /// - Call Initialize() to initialize the encoder for a supported profile.
30 /// - Call GetVideoFrame() to get a blank frame and fill it in, or get a video
31 /// frame from another resource, e.g. <code>PPB_MediaStreamVideoTrack</code>.
32 /// - Call Encode() to push the video frame to the encoder. If an external frame
33 /// is pushed, wait for completion to recycle the frame.
34 /// - Call GetBitstreamBuffer() continuously (waiting for each previous call to
35 /// complete) to pull encoded pictures from the encoder.
36 /// - Call RecycleBitstreamBuffer() after consuming the data in the bitstream
37 /// buffer.
38 /// - To destroy the encoder, the plugin should release all of its references to
39 /// it. Any pending callbacks will abort before the encoder is destroyed.
40 ///
41 /// Available video codecs vary by platform.
42 /// All: theora, vorbis, vp8.
43 /// Chrome and ChromeOS: h264.
44 /// ChromeOS: mpeg4.
45 class VideoEncoder : public Resource {
46 public:
47 /// Default constructor for creating an is_null() <code>VideoEncoder</code>
48 /// object.
49 VideoEncoder();
50
51 /// A constructor used to create a <code>VideoEncoder</code> and associate it
52 /// with the provided <code>Instance</code>.
53 /// @param[in] instance The instance with which this resource will be
54 /// associated.
55 explicit VideoEncoder(const InstanceHandle& instance);
56
57 /// The copy constructor for <code>VideoEncoder</code>.
58 /// @param[in] other A reference to a <code>VideoEncoder</code>.
59 VideoEncoder(const VideoEncoder& other);
60
61 /// Gets an array of supported video encoder profiles.
62 /// These can be used to choose a profile before calling Initialize().
63 ///
64 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
65 /// called upon completion with the PP_SupportedVideoProfile structs.
66 ///
67 /// @return If >= 0, the number of supported profiles returned, otherwise an
68 /// error code from <code>pp_errors.h</code>.
69 int32_t GetSupportedProfiles(
70 const CompletionCallbackWithOutput<
71 std::vector<PP_SupportedVideoProfile> >& cc);
72
73 /// Initializes a video encoder resource. This should be called after
74 /// GetSupportedProfiles() and before any functions below.
75 ///
76 /// @param[in] input_format The <code>PP_VideoFrame_Format</code> of the
77 /// frames which will be encoded.
78 /// @param[in] input_visible_size A <code>PP_Size</code> specifying the
79 /// dimensions of the visible part of the input frames.
80 /// @param[in] output_profile A <code>PP_VideoProfile</code> specifying the
81 /// codec profile of the encoded output stream.
82 /// @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying
83 /// whether to use a hardware accelerated or a software implementation.
84 /// @param[in] callback A <code>CompletionCallback</code> to be called upon
85 /// completion.
86 ///
87 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
88 /// Returns PP_ERROR_NOTSUPPORTED if video encoding is not available, or the
89 /// requested codec profile is not supported.
90 /// Returns PP_ERROR_NOMEMORY if frame and bitstream buffers can't be created.
91 int32_t Initialize(const PP_VideoFrame_Format& input_format,
92 const PP_Size& input_visible_size,
93 const PP_VideoProfile& output_profile,
94 const uint32_t initial_bitrate,
95 PP_HardwareAcceleration acceleration,
96 const CompletionCallback& cc);
97
98 /// Gets the number of input video frames that the encoder may hold while
99 /// encoding. If the plugin is providing the video frames, it should have at
100 /// least this many available. This must be called after Initialize().
101 ///
102 /// @return An int32_t containing the number of frames required, or an error
103 /// code from <code>pp_errors.h</code>.
104 int32_t GetInputFramesRequired();
105
106 /// Gets a blank video frame which can be filled with video data and passed
107 /// to the encoder.
108 ///
109 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
110 /// called upon completion with the blank <code>VideoFrame</code> resource.
111 ///
112 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
113 int32_t GetVideoFrame(
114 const CompletionCallbackWithOutput<VideoFrame>& cc);
115
116 /// Encodes a video frame.
117 ///
118 /// @param[in] video_frame The <code>VideoFrame</code> to be encoded.
119 /// @param[in] force_keyframe A <code>PP_Bool> specifying whether the encoder
120 /// should emit a key frame for this video frame.
121 /// @param[in] callback A <code>CompletionCallback</code> to be called upon
122 /// completion. Plugins that pass <code>VideoFrame</code> resources owned
123 /// by other resources should wait for completion before reusing them.
124 ///
125 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
126 int32_t Encode(
127 const VideoFrame& video_frame,
128 bool force_keyframe,
129 const CompletionCallback& cc);
130
131 /// Gets the next encoded bitstream buffer from the encoder.
132 ///
133 /// @param[out] bitstream_buffer A <code>PP_BitstreamBuffer</code> containing
134 /// encoded video data.
135 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
136 /// called upon completion with the next bitstream buffer. The plugin can call
137 /// GetBitstreamBuffer from the callback in order to continuously "pull"
138 /// bitstream buffers from the encoder.
139 ///
140 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
141 int32_t GetBitstreamBuffer(
142 const CompletionCallbackWithOutput<PP_BitstreamBuffer>& cc);
143
144 /// Recycles a bitstream buffer back to the encoder.
145 ///
146 /// @param[in] bitstream_buffer A <code>PP_BitstreamBuffer</code> that is no
147 /// longer needed by the plugin.
148 void RecycleBitstreamBuffer(
149 const PP_BitstreamBuffer& bitstream_buffer);
150
151 /// Requests a change to encoding parameters. This is only a request,
152 /// fulfilled on a best-effort basis.
153 ///
154 /// @param[in] bitrate The requested new bitrate, in bits per second.
155 /// @param[in] framerate The requested new framerate, in frames per second.
156 void RequestEncodingParametersChange(
157 uint32_t bitrate,
158 uint32_t framerate);
159 };
160
161 } // namespace pp
162
163 #endif // PPAPI_CPP_VIDEO_ENCODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698