1 /* Copyright 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.
7 * Defines the <code>PPB_MediaStreamVideoTrack</code> interface. Used for
8 * receiving video frames from a MediaStream video track in the browser.
14 [channel
=dev
] M34
= 0.1,
16 [channel
=dev
] M36
= 1.0
20 * This enumeration contains video track attributes which are used by
21 * <code>Configure()</code>.
23 enum PP_MediaStreamVideoTrack_Attrib
{
25 * Attribute list terminator.
27 PP_MEDIASTREAMVIDEOTRACK_ATTRIB_NONE
= 0,
30 * The maximum number of frames to hold in the input buffer.
31 * Note: this is only used as advisory; the browser may allocate more or fewer
32 * based on available resources. How many frames to buffer depends on usage -
33 * request at least 2 to make sure latency doesn't cause lost frames. If
34 * the plugin expects to hold on to more than one frame at a time (e.g. to do
35 * multi-frame processing), it should request that many more.
36 * If this attribute is not specified or value 0 is specified for this
37 * attribute, the default value will be used.
39 PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES
= 1,
42 * The width of video frames in pixels. It should be a multiple of 4.
43 * If the specified size is different from the video source (webcam),
44 * frames will be scaled to specified size.
45 * If this attribute is not specified or value 0 is specified, the original
46 * frame size of the video track will be used.
48 * Maximum value: 4096 (4K resolution).
50 PP_MEDIASTREAMVIDEOTRACK_ATTRIB_WIDTH
= 2,
53 * The height of video frames in pixels. It should be a multiple of 4.
54 * If the specified size is different from the video source (webcam),
55 * frames will be scaled to specified size.
56 * If this attribute is not specified or value 0 is specified, the original
57 * frame size of the video track will be used.
59 * Maximum value: 4096 (4K resolution).
61 PP_MEDIASTREAMVIDEOTRACK_ATTRIB_HEIGHT
= 3,
64 * The format of video frames. The attribute value is
65 * a <code>PP_VideoFrame_Format</code>. If the specified format is different
66 * from the video source (webcam), frames will be converted to specified
68 * If this attribute is not specified or value
69 * <code>PP_VIDEOFRAME_FORMAT_UNKNOWN</code> is specified, the orignal frame
70 * format of the video track will be used.
72 PP_MEDIASTREAMVIDEOTRACK_ATTRIB_FORMAT
= 4
76 interface PPB_MediaStreamVideoTrack
{
78 * Creates a PPB_MediaStreamVideoTrack resource for video output. Call this
79 * when you will be creating frames and putting them to the track.
81 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
84 * @return A <code>PP_Resource</code> corresponding to a
85 * PPB_MediaStreamVideoTrack resource if successful, 0 if failed.
88 PP_Resource Create
([in] PP_Instance instance
);
91 * Determines if a resource is a MediaStream video track resource.
93 * @param[in] resource The <code>PP_Resource</code> to test.
95 * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given
96 * resource is a Mediastream video track resource or <code>PP_FALSE</code>
99 PP_Bool IsMediaStreamVideoTrack
([in] PP_Resource resource
);
102 * Configures underlying frame buffers for incoming frames.
103 * If the application doesn't want to drop frames, then the
104 * <code>PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES</code> should be
105 * chosen such that inter-frame processing time variability won't overrun the
106 * input buffer. If the buffer is overfilled, then frames will be dropped.
107 * The application can detect this by examining the timestamp on returned
108 * frames. If some attributes are not specified, default values will be used
109 * for those unspecified attributes. If <code>Configure()</code> is not
110 * called, default settings will be used.
111 * Example usage from plugin code:
113 * int32_t attribs[] = {
114 * PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES, 4,
115 * PP_MEDIASTREAMVIDEOTRACK_ATTRIB_NONE};
116 * track_if->Configure(track, attribs, callback);
119 * @param[in] video_track A <code>PP_Resource</code> corresponding to a video
121 * @param[in] attrib_list A list of attribute name-value pairs in which each
122 * attribute is immediately followed by the corresponding desired value.
123 * The list is terminated by
124 * <code>PP_MEDIASTREAMVIDEOTRACK_ATTRIB_NONE</code>.
125 * @param[in] callback <code>PP_CompletionCallback</code> to be called upon
126 * completion of <code>Configure()</code>.
128 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
129 * Returns <code>PP_ERROR_INPROGRESS</code> if there is a pending call of
130 * <code>Configure()</code> or <code>GetFrame()</code>, or the plugin
131 * holds some frames which are not recycled with <code>RecycleFrame()</code>.
132 * If an error is returned, all attributes and the underlying buffer will not
135 int32_t Configure
([in] PP_Resource video_track
,
136 [in] int32_t
[] attrib_list
,
137 [in] PP_CompletionCallback
callback);
140 * Gets attribute value for a given attribute name.
142 * @param[in] video_track A <code>PP_Resource</code> corresponding to a video
144 * @param[in] attrib A <code>PP_MediaStreamVideoTrack_Attrib</code> for
146 * @param[out] value A int32_t for storing the attribute value on success.
147 * Otherwise, the value will not be changed.
149 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
151 int32_t GetAttrib
([in] PP_Resource video_track
,
152 [in] PP_MediaStreamVideoTrack_Attrib attrib
,
153 [out] int32_t value
);
156 * Returns the track ID of the underlying MediaStream video track.
158 * @param[in] video_track The <code>PP_Resource</code> to check.
160 * @return A <code>PP_Var</code> containing the MediaStream track ID as
163 PP_Var GetId
([in] PP_Resource video_track
);
166 * Checks whether the underlying MediaStream track has ended.
167 * Calls to GetFrame while the track has ended are safe to make and will
168 * complete, but will fail.
170 * @param[in] video_track The <code>PP_Resource</code> to check.
172 * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given
173 * MediaStream track has ended or <code>PP_FALSE</code> otherwise.
176 PP_Bool HasEnded
([in] PP_Resource video_track
);
179 * Gets the next video frame from the MediaStream track.
180 * If internal processing is slower than the incoming frame rate, new frames
181 * will be dropped from the incoming stream. Once the input buffer is full,
182 * frames will be dropped until <code>RecycleFrame()</code> is called to free
183 * a spot for another frame to be buffered.
184 * If there are no frames in the input buffer,
185 * <code>PP_OK_COMPLETIONPENDING</code> will be returned immediately and the
186 * <code>callback</code> will be called when a new frame is received or an
189 * @param[in] video_track A <code>PP_Resource</code> corresponding to a video
191 * @param[out] frame A <code>PP_Resource</code> corresponding to a VideoFrame
193 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
194 * completion of GetFrame().
196 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
197 * Returns PP_ERROR_NOMEMORY if <code>max_buffered_frames</code> frames buffer
198 * was not allocated successfully.
200 int32_t GetFrame
([in] PP_Resource video_track
,
201 [out] PP_Resource frame
,
202 [in] PP_CompletionCallback
callback);
205 * Recycles a frame returned by <code>GetFrame()</code>, so the track can
206 * reuse the underlying buffer of this frame. And the frame will become
207 * invalid. The caller should release all references it holds to
208 * <code>frame</code> and not use it anymore.
210 * @param[in] video_track A <code>PP_Resource</code> corresponding to a video
212 * @param[in] frame A <code>PP_Resource</code> corresponding to a VideoFrame
213 * resource returned by <code>GetFrame()</code>.
215 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
217 int32_t RecycleFrame
([in] PP_Resource video_track
,
218 [in] PP_Resource frame
);
221 * Closes the MediaStream video track and disconnects it from video source.
222 * After calling <code>Close()</code>, no new frames will be received.
224 * @param[in] video_track A <code>PP_Resource</code> corresponding to a
225 * MediaStream video track resource.
227 void Close
([in] PP_Resource video_track
);
230 * Gets a free frame for output. The frame is allocated by
231 * <code>Configure()</code>. The caller should fill it with frame data, and
232 * then use |PutFrame()| to send the frame back.
235 int32_t GetEmptyFrame
([in] PP_Resource video_track
,
236 [out] PP_Resource frame
,
237 [in] PP_CompletionCallback
callback);
240 * Sends a frame returned by |GetEmptyFrame()| to the output track.
241 * After this function, the |frame| should not be used anymore and the
242 * caller should release the reference that it holds.
245 int32_t PutFrame
([in] PP_Resource video_track
, [in] PP_Resource frame
);