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,
19 * This enumeration contains video track attributes which are used by
20 * <code>Configure()</code>.
22 enum PP_MediaStreamVideoTrack_Attrib
{
24 * Attribute list terminator.
26 PP_MEDIASTREAMVIDEOTRACK_ATTRIB_NONE
= 0,
29 * The maximum number of frames to hold in the input buffer.
30 * Note: this is only used as advisory; the browser may allocate more or fewer
31 * based on available resources. How many frames to buffer depends on usage -
32 * request at least 2 to make sure latency doesn't cause lost frames. If
33 * the plugin expects to hold on to more than one frame at a time (e.g. to do
34 * multi-frame processing), it should request that many more.
35 * If this attribute is not specified or value 0 is specified for this
36 * attribute, the default value will be used.
38 PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES
= 1,
41 * The width of video frames in pixels. It should be a multiple of 4.
42 * If the specified size is different from the video source (webcam),
43 * frames will be scaled to specified size.
44 * If this attribute is not specified or value 0 is specified, the original
45 * frame size of the video track will be used.
47 * Maximum value: 4096 (4K resolution).
49 PP_MEDIASTREAMVIDEOTRACK_ATTRIB_WIDTH
= 2,
52 * The height of video frames in pixels. It should be a multiple of 4.
53 * If the specified size is different from the video source (webcam),
54 * frames will be scaled to specified size.
55 * If this attribute is not specified or value 0 is specified, the original
56 * frame size of the video track will be used.
58 * Maximum value: 4096 (4K resolution).
60 PP_MEDIASTREAMVIDEOTRACK_ATTRIB_HEIGHT
= 3,
63 * The format of video frames. The attribute value is
64 * a <code>PP_VideoFrame_Format</code>. If the specified format is different
65 * from the video source (webcam), frames will be converted to specified
67 * If this attribute is not specified or value
68 * <code>PP_VIDEOFRAME_FORMAT_UNKNOWN</code> is specified, the orignal frame
69 * format of the video track will be used.
71 PP_MEDIASTREAMVIDEOTRACK_ATTRIB_FORMAT
= 4
75 interface PPB_MediaStreamVideoTrack
{
77 * Determines if a resource is a MediaStream video track resource.
79 * @param[in] resource The <code>PP_Resource</code> to test.
81 * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given
82 * resource is a Mediastream video track resource or <code>PP_FALSE</code>
85 PP_Bool IsMediaStreamVideoTrack
([in] PP_Resource resource
);
88 * Configures underlying frame buffers for incoming frames.
89 * If the application doesn't want to drop frames, then the
90 * <code>PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES</code> should be
91 * chosen such that inter-frame processing time variability won't overrun the
92 * input buffer. If the buffer is overfilled, then frames will be dropped.
93 * The application can detect this by examining the timestamp on returned
94 * frames. If some attributes are not specified, default values will be used
95 * for those unspecified attributes. If <code>Configure()</code> is not
96 * called, default settings will be used.
97 * Example usage from plugin code:
99 * int32_t attribs[] = {
100 * PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES, 4,
101 * PP_MEDIASTREAMVIDEOTRACK_ATTRIB_NONE};
102 * track_if->Configure(track, attribs, callback);
105 * @param[in] video_track A <code>PP_Resource</code> corresponding to a video
107 * @param[in] attrib_list A list of attribute name-value pairs in which each
108 * attribute is immediately followed by the corresponding desired value.
109 * The list is terminated by
110 * <code>PP_MEDIASTREAMVIDEOTRACK_ATTRIB_NONE</code>.
111 * @param[in] callback <code>PP_CompletionCallback</code> to be called upon
112 * completion of <code>Configure()</code>.
114 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
115 * Returns <code>PP_ERROR_INPROGRESS</code> if there is a pending call of
116 * <code>Configure()</code> or <code>GetFrame()</code>, or the plugin
117 * holds some frames which are not recycled with <code>RecycleFrame()</code>.
118 * If an error is returned, all attributes and the underlying buffer will not
121 int32_t Configure
([in] PP_Resource video_track
,
122 [in] int32_t
[] attrib_list
,
123 [in] PP_CompletionCallback
callback);
126 * Gets attribute value for a given attribute name.
128 * @param[in] video_track A <code>PP_Resource</code> corresponding to a video
130 * @param[in] attrib A <code>PP_MediaStreamVideoTrack_Attrib</code> for
132 * @param[out] value A int32_t for storing the attribute value on success.
133 * Otherwise, the value will not be changed.
135 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
137 int32_t GetAttrib
([in] PP_Resource video_track
,
138 [in] PP_MediaStreamVideoTrack_Attrib attrib
,
139 [out] int32_t value
);
142 * Returns the track ID of the underlying MediaStream video track.
144 * @param[in] video_track The <code>PP_Resource</code> to check.
146 * @return A <code>PP_Var</code> containing the MediaStream track ID as
149 PP_Var GetId
([in] PP_Resource video_track
);
152 * Checks whether the underlying MediaStream track has ended.
153 * Calls to GetFrame while the track has ended are safe to make and will
154 * complete, but will fail.
156 * @param[in] video_track The <code>PP_Resource</code> to check.
158 * @return A <code>PP_Bool</code> with <code>PP_TRUE</code> if the given
159 * MediaStream track has ended or <code>PP_FALSE</code> otherwise.
162 PP_Bool HasEnded
([in] PP_Resource video_track
);
165 * Gets the next video frame from the MediaStream track.
166 * If internal processing is slower than the incoming frame rate, new frames
167 * will be dropped from the incoming stream. Once the input buffer is full,
168 * frames will be dropped until <code>RecycleFrame()</code> is called to free
169 * a spot for another frame to be buffered.
170 * If there are no frames in the input buffer,
171 * <code>PP_OK_COMPLETIONPENDING</code> will be returned immediately and the
172 * <code>callback</code> will be called when a new frame is received or an
175 * @param[in] video_track A <code>PP_Resource</code> corresponding to a video
177 * @param[out] frame A <code>PP_Resource</code> corresponding to a VideoFrame
179 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
180 * completion of GetFrame().
182 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
183 * Returns PP_ERROR_NOMEMORY if <code>max_buffered_frames</code> frames buffer
184 * was not allocated successfully.
186 int32_t GetFrame
([in] PP_Resource video_track
,
187 [out] PP_Resource frame
,
188 [in] PP_CompletionCallback
callback);
191 * Recycles a frame returned by <code>GetFrame()</code>, so the track can
192 * reuse the underlying buffer of this frame. And the frame will become
193 * invalid. The caller should release all references it holds to
194 * <code>frame</code> and not use it anymore.
196 * @param[in] video_track A <code>PP_Resource</code> corresponding to a video
198 * @param[in] frame A <code>PP_Resource</code> corresponding to a VideoFrame
199 * resource returned by <code>GetFrame()</code>.
201 * @return An int32_t containing a result code from <code>pp_errors.h</code>.
203 int32_t RecycleFrame
([in] PP_Resource video_track
,
204 [in] PP_Resource frame
);
207 * Closes the MediaStream video track and disconnects it from video source.
208 * After calling <code>Close()</code>, no new frames will be received.
210 * @param[in] video_track A <code>PP_Resource</code> corresponding to a
211 * MediaStream video track resource.
213 void Close
([in] PP_Resource video_track
);