diff options
Diffstat (limited to 'ppapi/cpp')
-rw-r--r-- | ppapi/cpp/media_stream_video_track.cc | 73 | ||||
-rw-r--r-- | ppapi/cpp/media_stream_video_track.h | 15 |
2 files changed, 80 insertions, 8 deletions
diff --git a/ppapi/cpp/media_stream_video_track.cc b/ppapi/cpp/media_stream_video_track.cc index 38065a3..47ff140 100644 --- a/ppapi/cpp/media_stream_video_track.cc +++ b/ppapi/cpp/media_stream_video_track.cc @@ -15,6 +15,10 @@ namespace pp { namespace { +template <> const char* interface_name<PPB_MediaStreamVideoTrack_1_0>() { + return PPB_MEDIASTREAMVIDEOTRACK_INTERFACE_1_0; +} + template <> const char* interface_name<PPB_MediaStreamVideoTrack_0_1>() { return PPB_MEDIASTREAMVIDEOTRACK_INTERFACE_0_1; } @@ -33,6 +37,16 @@ MediaStreamVideoTrack::MediaStreamVideoTrack(const Resource& resource) PP_DCHECK(IsMediaStreamVideoTrack(resource)); } +MediaStreamVideoTrack::MediaStreamVideoTrack(const InstanceHandle& instance) { + if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) { + PassRefFromConstructor( + get_interface<PPB_MediaStreamVideoTrack_1_0>()->Create( + instance.pp_instance())); + return; + } + PP_DCHECK(false); +} + MediaStreamVideoTrack::MediaStreamVideoTrack(PassRef, PP_Resource resource) : Resource(PASS_REF, resource) { } @@ -43,7 +57,10 @@ MediaStreamVideoTrack::~MediaStreamVideoTrack() { int32_t MediaStreamVideoTrack::Configure( const int32_t attributes[], const CompletionCallback& callback) { - if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { + if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) { + return get_interface<PPB_MediaStreamVideoTrack_1_0>()->Configure( + pp_resource(), attributes, callback.pp_completion_callback()); + } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { return get_interface<PPB_MediaStreamVideoTrack_0_1>()->Configure( pp_resource(), attributes, callback.pp_completion_callback()); } @@ -52,7 +69,10 @@ int32_t MediaStreamVideoTrack::Configure( int32_t MediaStreamVideoTrack::GetAttrib(PP_MediaStreamVideoTrack_Attrib attrib, int32_t* value) { - if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { + if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) { + return get_interface<PPB_MediaStreamVideoTrack_1_0>()->GetAttrib( + pp_resource(), attrib, value); + } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { return get_interface<PPB_MediaStreamVideoTrack_0_1>()->GetAttrib( pp_resource(), attrib, value); } @@ -60,7 +80,12 @@ int32_t MediaStreamVideoTrack::GetAttrib(PP_MediaStreamVideoTrack_Attrib attrib, } std::string MediaStreamVideoTrack::GetId() const { - if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { + if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) { + pp::Var id(PASS_REF, get_interface<PPB_MediaStreamVideoTrack_1_0>()->GetId( + pp_resource())); + if (id.is_string()) + return id.AsString(); + } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { pp::Var id(PASS_REF, get_interface<PPB_MediaStreamVideoTrack_0_1>()->GetId( pp_resource())); if (id.is_string()) @@ -70,7 +95,10 @@ std::string MediaStreamVideoTrack::GetId() const { } bool MediaStreamVideoTrack::HasEnded() const { - if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { + if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) { + return PP_ToBool(get_interface<PPB_MediaStreamVideoTrack_1_0>()->HasEnded( + pp_resource())); + } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { return PP_ToBool(get_interface<PPB_MediaStreamVideoTrack_0_1>()->HasEnded( pp_resource())); } @@ -79,7 +107,10 @@ bool MediaStreamVideoTrack::HasEnded() const { int32_t MediaStreamVideoTrack::GetFrame( const CompletionCallbackWithOutput<VideoFrame>& callback) { - if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { + if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) { + return get_interface<PPB_MediaStreamVideoTrack_1_0>()->GetFrame( + pp_resource(), callback.output(), callback.pp_completion_callback()); + } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { return get_interface<PPB_MediaStreamVideoTrack_0_1>()->GetFrame( pp_resource(), callback.output(), callback.pp_completion_callback()); } @@ -87,7 +118,10 @@ int32_t MediaStreamVideoTrack::GetFrame( } int32_t MediaStreamVideoTrack::RecycleFrame(const VideoFrame& frame) { - if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { + if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) { + return get_interface<PPB_MediaStreamVideoTrack_1_0>()->RecycleFrame( + pp_resource(), frame.pp_resource()); + } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { return get_interface<PPB_MediaStreamVideoTrack_0_1>()->RecycleFrame( pp_resource(), frame.pp_resource()); } @@ -95,12 +129,35 @@ int32_t MediaStreamVideoTrack::RecycleFrame(const VideoFrame& frame) { } void MediaStreamVideoTrack::Close() { - if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) + if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) + get_interface<PPB_MediaStreamVideoTrack_1_0>()->Close(pp_resource()); + else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) get_interface<PPB_MediaStreamVideoTrack_0_1>()->Close(pp_resource()); + +} + +int32_t MediaStreamVideoTrack::GetEmptyFrame( + const CompletionCallbackWithOutput<VideoFrame>& callback) { + if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) { + return get_interface<PPB_MediaStreamVideoTrack_1_0>()->GetEmptyFrame( + pp_resource(), callback.output(), callback.pp_completion_callback()); + } + return callback.MayForce(PP_ERROR_NOINTERFACE); +} + +int32_t MediaStreamVideoTrack::PutFrame(const VideoFrame& frame) { + if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) { + return get_interface<PPB_MediaStreamVideoTrack_1_0>()->PutFrame( + pp_resource(), frame.pp_resource()); + } + return PP_ERROR_NOINTERFACE; } bool MediaStreamVideoTrack::IsMediaStreamVideoTrack(const Resource& resource) { - if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { + if (has_interface<PPB_MediaStreamVideoTrack_1_0>()) { + return PP_ToBool(get_interface<PPB_MediaStreamVideoTrack_1_0>()-> + IsMediaStreamVideoTrack(resource.pp_resource())); + } else if (has_interface<PPB_MediaStreamVideoTrack_0_1>()) { return PP_ToBool(get_interface<PPB_MediaStreamVideoTrack_0_1>()-> IsMediaStreamVideoTrack(resource.pp_resource())); } diff --git a/ppapi/cpp/media_stream_video_track.h b/ppapi/cpp/media_stream_video_track.h index 6975986..5d03745 100644 --- a/ppapi/cpp/media_stream_video_track.h +++ b/ppapi/cpp/media_stream_video_track.h @@ -41,6 +41,10 @@ class MediaStreamVideoTrack : public Resource { /// @param[in] resource A <code>PPB_MediaStreamVideoTrack</code> resource. explicit MediaStreamVideoTrack(const Resource& resource); + /// Constructs a <code>MediaStreamVideoTrack</code> that outputs given frames + /// to a new video track, which will be consumed by Javascript. + explicit MediaStreamVideoTrack(const InstanceHandle& instance); + /// A constructor used when you have received a <code>PP_Resource</code> as a /// return value that has had 1 ref added for you. /// @@ -134,6 +138,17 @@ class MediaStreamVideoTrack : public Resource { /// After calling <code>Close()</code>, no new frames will be received. void Close(); + // Gets a free frame for output. The frame is allocated by + // <code>Configure()</code>. The caller should fill it with frame data, and + // then use |PutFrame()| to send the frame back. + int32_t GetEmptyFrame( + const CompletionCallbackWithOutput<VideoFrame>& callback); + + // Sends a frame returned by |GetEmptyFrame()| to the output track. + // After this function, the |frame| should not be used anymore and the + // caller should release the reference that it holds. + int32_t PutFrame(const VideoFrame& frame); + /// Checks whether a <code>Resource</code> is a MediaStream video track, /// to test whether it is appropriate for use with the /// <code>MediaStreamVideoTrack</code> constructor. |