Chromium Code Reviews| Index: ppapi/proxy/media_stream_video_track_resource.cc |
| diff --git a/ppapi/proxy/media_stream_video_track_resource.cc b/ppapi/proxy/media_stream_video_track_resource.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e58529fadedaadbda38fd790cf6745df91b52353 |
| --- /dev/null |
| +++ b/ppapi/proxy/media_stream_video_track_resource.cc |
| @@ -0,0 +1,109 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ppapi/proxy/media_stream_video_track_resource.h" |
| + |
| +#include "ppapi/proxy/video_frame_resource.h" |
| +#include "ppapi/shared_impl/media_stream_frame.h" |
| +#include "ppapi/shared_impl/var.h" |
| +#include "ppapi/thunk/enter.h" |
| + |
| +namespace ppapi { |
| +namespace proxy { |
| + |
| +MediaStreamVideoTrackResource::MediaStreamVideoTrackResource( |
| + Connection connection, |
| + PP_Instance instance, |
| + int pending_renderer_id, |
| + const std::string& id) |
| + : MediaStreamTrackResourceBase( |
| + connection, instance, pending_renderer_id, id), |
| + get_frame_output_(NULL) { |
| +} |
| + |
| +MediaStreamVideoTrackResource::~MediaStreamVideoTrackResource() { |
| +} |
| + |
| +thunk::PPB_MediaStreamVideoTrack_API* |
| +MediaStreamVideoTrackResource::AsPPB_MediaStreamVideoTrack_API() { |
| + return this; |
| +} |
| + |
| +PP_Var MediaStreamVideoTrackResource::GetId() { |
| + return StringVar::StringToPPVar(id()); |
| +} |
| + |
| +PP_Bool MediaStreamVideoTrackResource::HasEnded() { |
| + return PP_FromBool(has_ended()); |
| +} |
| + |
| +int32_t MediaStreamVideoTrackResource::Configure(uint32_t max_buffered_frames) { |
| + // TODO(penghuang): redesign and implement Configure() to support format, |
| + // size, etc. |
| + return PP_ERROR_NOTSUPPORTED; |
| +} |
| + |
| +int32_t MediaStreamVideoTrackResource::GetFrame( |
| + PP_Resource* frame, |
| + scoped_refptr<ppapi::TrackedCallback> callback) { |
| + if (has_ended()) |
| + return PP_ERROR_FAILED; |
| + |
| + if (TrackedCallback::IsPending(get_frame_callback_)) |
| + return PP_ERROR_INPROGRESS; |
| + |
| + *frame = GetVideoFrame(); |
| + if (*frame) |
| + return PP_OK; |
| + |
| + get_frame_output_ = frame; |
| + get_frame_callback_ = callback; |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +int32_t MediaStreamVideoTrackResource::RecycleFrame(PP_Resource frame) { |
| + thunk::EnterResourceNoLock<thunk::PPB_VideoFrame_API>enter_frame(frame, true); |
|
yzshen1
2014/01/10 21:05:17
one space before enter_frame, please.
Peng
2014/01/10 22:46:58
Done.
|
| + if (enter_frame.failed()) |
| + return PP_ERROR_BADRESOURCE; |
| + |
|
yzshen1
2014/01/10 21:05:17
In another file, I mentioned that this class shoul
Peng
2014/01/10 22:46:58
It is a good idea. Done
|
| + VideoFrameResource* frame_resource = |
| + static_cast<VideoFrameResource*>(enter_frame.resource()); |
|
bbudge
2014/01/10 22:57:06
It's unusual to cast to the underlying type when w
Peng
2014/01/13 19:10:15
As yzshen's suggestion, I use a FrameMap here to c
|
| + if (frame_resource->index() < 0) |
| + return PP_ERROR_BADRESOURCE; |
| + |
| + HostEnqueueFrame(frame_resource->index()); |
| + frame_resource->invalidate(); |
| + return PP_OK; |
| +} |
| + |
| +void MediaStreamVideoTrackResource::Close() { |
| + if (TrackedCallback::IsPending(get_frame_callback_)) { |
| + *get_frame_output_ = 0; |
| + get_frame_callback_->PostRun(PP_ERROR_FAILED); |
|
yzshen1
2014/01/10 21:05:17
It is more common to use PostAbort() in this case.
Peng
2014/01/10 22:46:58
Done.
|
| + get_frame_callback_ = NULL; |
| + get_frame_output_ = 0; |
| + } |
| + MediaStreamTrackResourceBase::CloseInternal(); |
| +} |
| + |
| +void MediaStreamVideoTrackResource::OnNewFrameEnqueued() { |
| + if (TrackedCallback::IsPending(get_frame_callback_)) { |
| + *get_frame_output_ = GetVideoFrame(); |
| + get_frame_callback_->PostRun(PP_OK); |
| + get_frame_callback_ = NULL; |
| + get_frame_output_ = 0; |
| + } |
| +} |
| + |
| +PP_Resource MediaStreamVideoTrackResource::GetVideoFrame() { |
| + int32_t index = frame_buffer()->DequeueFrame(); |
| + if (index < 0) |
| + return 0; |
| + MediaStreamFrame::Video* frame = |
| + &(frame_buffer()->GetFramePointer(index)->video); |
| + return (new VideoFrameResource(pp_instance(), index, frame))->GetReference(); |
| +} |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |