Delete unused downloads page asset.
[chromium-blink-merge.git] / ppapi / cpp / video_decoder.h
blob50b0ea2596ec84b17bbe186637197f4608549144
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.
5 #ifndef PPAPI_CPP_VIDEO_DECODER_H_
6 #define PPAPI_CPP_VIDEO_DECODER_H_
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"
15 /// @file
16 /// This file defines the API to create and use a VideoDecoder resource.
18 namespace pp {
20 class InstanceHandle;
22 /// Video decoder interface.
23 ///
24 /// Typical usage:
25 /// - Call Create() to create a new video decoder resource.
26 /// - Call Initialize() to initialize it with a 3d graphics context and the
27 /// desired codec profile.
28 /// - Call Decode() continuously (waiting for each previous call to complete) to
29 /// push bitstream buffers to the decoder.
30 /// - Call GetPicture() continuously (waiting for each previous call to
31 /// complete) to pull decoded pictures from the decoder.
32 /// - Call Flush() to signal end of stream to the decoder and perform shutdown
33 /// when it completes.
34 /// - Call Reset() to quickly stop the decoder (e.g. to implement Seek) and wait
35 /// for the callback before restarting decoding at another point.
36 /// - To destroy the decoder, the plugin should release all of its references to
37 /// it. Any pending callbacks will abort before the decoder is destroyed.
38 ///
39 /// Available video codecs vary by platform.
40 /// All: theora, vorbis, vp8.
41 /// Chrome and ChromeOS: aac, h264.
42 /// ChromeOS: mpeg4.
43 class VideoDecoder : public Resource {
44 public:
45 /// Default constructor for creating an is_null() <code>VideoDecoder</code>
46 /// object.
47 VideoDecoder();
49 /// A constructor used to create a <code>VideoDecoder</code> and associate it
50 /// with the provided <code>Instance</code>.
51 /// @param[in] instance The instance with which this resource will be
52 /// associated.
53 explicit VideoDecoder(const InstanceHandle& instance);
55 /// The copy constructor for <code>VideoDecoder</code>.
56 /// @param[in] other A reference to a <code>VideoDecoder</code>.
57 VideoDecoder(const VideoDecoder& other);
59 /// Initializes a video decoder resource. This should be called after Create()
60 /// and before any other functions.
61 ///
62 /// @param[in] graphics3d_context A <code>PPB_Graphics3D</code> resource to
63 /// use during decoding.
64 /// @param[in] profile A <code>PP_VideoProfile</code> specifying the video
65 /// codec profile.
66 /// @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying
67 /// whether to use a hardware accelerated or a software implementation.
68 /// @param[in] min_picture_count A count of pictures the plugin would like to
69 /// have in flight. This is effectively the number of times the plugin can
70 /// call GetPicture() and get a decoded frame without calling
71 /// RecyclePicture(). The decoder has its own internal minimum count, and will
72 /// take the larger of its internal and this value. A client that doesn't care
73 /// can therefore just pass in zero for this argument.
74 /// @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
75 /// completion.
76 ///
77 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
78 /// Returns PP_ERROR_NOTSUPPORTED if video decoding is not available, or the
79 /// requested profile is not supported. In this case, the client may call
80 /// Initialize() again with different parameters to find a good configuration.
81 int32_t Initialize(const Graphics3D& graphics3d_context,
82 PP_VideoProfile profile,
83 PP_HardwareAcceleration acceleration,
84 uint32_t min_picture_count,
85 const CompletionCallback& callback);
87 /// Decodes a bitstream buffer. Copies |size| bytes of data from the plugin's
88 /// |buffer|. The plugin should wait until the decoder signals completion by
89 /// returning PP_OK or by running |callback| before calling Decode() again.
90 ///
91 /// In general, each bitstream buffer should contain a demuxed bitstream frame
92 /// for the selected video codec. For example, H264 decoders expect to receive
93 /// one AnnexB NAL unit, including the 4 byte start code prefix, while VP8
94 /// decoders expect to receive a bitstream frame without the IVF frame header.
95 ///
96 /// If the call to Decode() eventually results in a picture, the |decode_id|
97 /// parameter is copied into the returned picture. The plugin can use this to
98 /// associate decoded pictures with Decode() calls (e.g. to assign timestamps
99 /// or frame numbers to pictures.) This value is opaque to the API so the
100 /// plugin is free to pass any value.
102 /// @param[in] decode_id An optional value, chosen by the plugin, that can be
103 /// used to associate calls to Decode() with decoded pictures returned by
104 /// GetPicture().
105 /// @param[in] size Buffer size in bytes.
106 /// @param[in] buffer Starting address of buffer.
107 /// @param[in] callback A <code>CompletionCallback</code> to be called on
108 /// completion.
110 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
111 /// Returns PP_ERROR_FAILED if the decoder isn't initialized or if a Flush()
112 /// or Reset() call is pending.
113 /// Returns PP_ERROR_INPROGRESS if there is another Decode() call pending.
114 /// Returns PP_ERROR_NOMEMORY if a bitstream buffer can't be created.
115 /// Returns PP_ERROR_ABORTED when Reset() is called while Decode() is pending.
116 int32_t Decode(uint32_t decode_id,
117 uint32_t size,
118 const void* buffer,
119 const CompletionCallback& callback);
121 /// Gets the next picture from the decoder. The picture is valid after the
122 /// decoder signals completion by returning PP_OK or running |callback|. The
123 /// plugin can call GetPicture() again after the decoder signals completion.
124 /// When the plugin is finished using the picture, it should return it to the
125 /// system by calling RecyclePicture().
127 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
128 /// called on completion, and on success, to hold the picture descriptor.
130 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
131 /// Returns PP_ERROR_FAILED if the decoder isn't initialized or if a Reset()
132 /// call is pending.
133 /// Returns PP_ERROR_INPROGRESS if there is another GetPicture() call pending.
134 /// Returns PP_ERROR_ABORTED when Reset() is called, or if a call to Flush()
135 /// completes while GetPicture() is pending.
136 int32_t GetPicture(
137 const CompletionCallbackWithOutput<PP_VideoPicture>& callback);
139 /// Recycles a picture that the plugin has received from the decoder.
140 /// The plugin should call this as soon as it has finished using the texture
141 /// so the decoder can decode more pictures.
143 /// @param[in] picture A <code>PP_VideoPicture</code> to return to the
144 /// decoder.
145 void RecyclePicture(const PP_VideoPicture& picture);
147 /// Flushes the decoder. The plugin should call Flush() when it reaches the
148 /// end of its video stream in order to stop cleanly. The decoder will run any
149 /// pending Decode() call to completion. The plugin should make no further
150 /// calls to the decoder other than GetPicture() and RecyclePicture() until
151 /// the decoder signals completion by running |callback|. Just before
152 /// completion, any pending GetPicture() call will complete by running its
153 /// callback with result PP_ERROR_ABORTED to signal that no more pictures are
154 /// available. Any pictures held by the plugin remain valid during and after
155 /// the flush and should be recycled back to the decoder.
157 /// @param[in] callback A <code>CompletionCallback</code> to be called on
158 /// completion.
160 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
161 /// Returns PP_ERROR_FAILED if the decoder isn't initialized.
162 int32_t Flush(const CompletionCallback& callback);
164 /// Resets the decoder as quickly as possible. The plugin can call Reset() to
165 /// skip to another position in the video stream. After Reset() returns, any
166 /// pending calls to Decode() and GetPicture()) abort, causing their callbacks
167 /// to run with PP_ERROR_ABORTED. The plugin should not make further calls to
168 /// the decoder other than RecyclePicture() until the decoder signals
169 /// completion by running |callback|. Any pictures held by the plugin remain
170 /// valid during and after the reset and should be recycled back to the
171 /// decoder.
173 /// @param[in] callback A <code>CompletionCallback</code> to be called on
174 /// completion.
176 /// @return An int32_t containing an error code from <code>pp_errors.h</code>.
177 /// Returns PP_ERROR_FAILED if the decoder isn't initialized.
178 int32_t Reset(const CompletionCallback& callback);
181 } // namespace pp
183 #endif // PPAPI_CPP_VIDEO_DECODER_H_