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.
5 #ifndef PPAPI_CPP_MEDIA_STREAM_VIDEO_TRACK_H_
6 #define PPAPI_CPP_MEDIA_STREAM_VIDEO_TRACK_H_
10 #include "ppapi/c/ppb_media_stream_video_track.h"
11 #include "ppapi/cpp/resource.h"
12 #include "ppapi/cpp/var.h"
15 /// This file defines the <code>MediaStreamVideoTrack</code> interface for a
16 /// video source resource, which receives video frames from a MediaStream video
17 /// track in the browser.
22 class CompletionCallback
;
23 template <typename T
> class CompletionCallbackWithOutput
;
25 /// The <code>MediaStreamVideoTrack</code> class contains methods for
26 /// receiving video frames from a MediaStream video track in the browser.
27 class MediaStreamVideoTrack
: public Resource
{
29 /// Default constructor for creating an is_null()
30 /// <code>MediaStreamVideoTrack</code> object.
31 MediaStreamVideoTrack();
33 /// The copy constructor for <code>MediaStreamVideoTrack</code>.
35 /// @param[in] other A reference to a <code>MediaStreamVideoTrack</code>.
36 MediaStreamVideoTrack(const MediaStreamVideoTrack
& other
);
38 /// Constructs a <code>MediaStreamVideoTrack</code> from
39 /// a <code>Resource</code>.
41 /// @param[in] resource A <code>PPB_MediaStreamVideoTrack</code> resource.
42 explicit MediaStreamVideoTrack(const Resource
& resource
);
44 /// A constructor used when you have received a <code>PP_Resource</code> as a
45 /// return value that has had 1 ref added for you.
47 /// @param[in] resource A <code>PPB_MediaStreamVideoTrack</code> resource.
48 MediaStreamVideoTrack(PassRef
, PP_Resource resource
);
50 ~MediaStreamVideoTrack();
52 /// Configures underlying frame buffers for incoming frames.
53 /// If the application doesn't want to drop frames, then the
54 /// <code>PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES</code> should be
55 /// chosen such that inter-frame processing time variability won't overrun the
56 /// input buffer. If the buffer is overfilled, then frames will be dropped.
57 /// The application can detect this by examining the timestamp on returned
58 /// frames. If some attributes are not specified, default values will be used
59 /// for those unspecified attributes. If <code>Configure()</code> is not
60 /// called, default settings will be used.
61 /// Example usage from plugin code:
63 /// int32_t attribs[] = {
64 /// PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES, 4,
65 /// PP_MEDIASTREAMVIDEOTRACK_ATTRIB_NONE};
66 /// track.Configure(attribs, callback);
69 /// @param[in] attrib_list A list of attribute name-value pairs in which each
70 /// attribute is immediately followed by the corresponding desired value.
71 /// The list is terminated by
72 /// <code>PP_MEDIASTREAMVIDEOTRACK_ATTRIB_NONE</code>.
73 /// @param[in] callback A <code>CompletionCallback</code> to be called upon
74 /// completion of <code>Configure()</code>.
76 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
77 /// Returns <code>PP_ERROR_INPROGRESS</code> if there is a pending call of
78 /// <code>Configure()</code> or <code>GetFrame()</code>, or the plugin
79 /// holds some frames which are not recycled with <code>RecycleFrame()</code>.
80 /// If an error is returned, all attributes and the underlying buffer will not
82 int32_t Configure(const int32_t attributes
[],
83 const CompletionCallback
& callback
);
85 /// Gets attribute value for a given attribute name.
87 /// @param[in] attrib A <code>PP_MediaStreamVideoTrack_Attrib</code> for
89 /// @param[out] value A int32_t for storing the attribute value.
91 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
92 int32_t GetAttrib(PP_MediaStreamVideoTrack_Attrib attrib
,
95 /// Returns the track ID of the underlying MediaStream video track.
96 std::string
GetId() const;
98 /// Checks whether the underlying MediaStream track has ended.
99 /// Calls to GetFrame while the track has ended are safe to make and will
100 /// complete, but will fail.
101 bool HasEnded() const;
103 /// Gets the next video frame from the MediaStream track.
104 /// If internal processing is slower than the incoming frame rate, new frames
105 /// will be dropped from the incoming stream. Once the input buffer is full,
106 /// frames will be dropped until <code>RecycleFrame()</code> is called to free
107 /// a spot for another frame to be buffered.
108 /// If there are no frames in the input buffer,
109 /// <code>PP_OK_COMPLETIONPENDING</code> will be returned immediately and the
110 /// <code>callback</code> will be called when a new frame is received or some
113 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be
114 /// called upon completion of <code>GetFrame()</code>. If success,
115 /// a VideoFrame will be passed into the completion callback function.
117 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
118 /// Returns PP_ERROR_NOMEMORY if <code>max_buffered_frames</code> frames
119 /// buffer was not allocated successfully.
121 const CompletionCallbackWithOutput
<VideoFrame
>& callback
);
123 /// Recycles a frame returned by <code>GetFrame()</code>, so the track can
124 /// reuse the underlying buffer of this frame. And the frame will become
125 /// invalid. The caller should release all references it holds to
126 /// <code>frame</code> and not use it anymore.
128 /// @param[in] frame A VideoFrame returned by <code>GetFrame()</code>.
130 /// @return An int32_t containing a result code from <code>pp_errors.h</code>.
131 int32_t RecycleFrame(const VideoFrame
& frame
);
133 /// Closes the MediaStream video track, and disconnects it from video source.
134 /// After calling <code>Close()</code>, no new frames will be received.
137 /// Checks whether a <code>Resource</code> is a MediaStream video track,
138 /// to test whether it is appropriate for use with the
139 /// <code>MediaStreamVideoTrack</code> constructor.
141 /// @param[in] resource A <code>Resource</code> to test.
143 /// @return True if <code>resource</code> is a MediaStream video track.
144 static bool IsMediaStreamVideoTrack(const Resource
& resource
);
149 #endif // PPAPI_CPP_MEDIA_STREAM_VIDEO_TRACK_H_