Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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. | |
| 4 | |
| 5 #include "ppapi/proxy/media_stream_video_track_resource.h" | |
| 6 | |
| 7 #include "ppapi/proxy/video_frame_resource.h" | |
| 8 #include "ppapi/shared_impl/media_stream_frame.h" | |
| 9 #include "ppapi/shared_impl/var.h" | |
| 10 #include "ppapi/thunk/enter.h" | |
| 11 | |
| 12 namespace ppapi { | |
| 13 namespace proxy { | |
| 14 | |
| 15 MediaStreamVideoTrackResource::MediaStreamVideoTrackResource( | |
| 16 Connection connection, | |
| 17 PP_Instance instance, | |
| 18 int pending_renderer_id, | |
| 19 const std::string& id) | |
| 20 : MediaStreamTrackResourceBase( | |
| 21 connection, instance, pending_renderer_id, id), | |
| 22 get_frame_output_(NULL) { | |
| 23 } | |
| 24 | |
| 25 MediaStreamVideoTrackResource::~MediaStreamVideoTrackResource() { | |
| 26 } | |
| 27 | |
| 28 thunk::PPB_MediaStreamVideoTrack_API* | |
| 29 MediaStreamVideoTrackResource::AsPPB_MediaStreamVideoTrack_API() { | |
| 30 return this; | |
| 31 } | |
| 32 | |
| 33 PP_Var MediaStreamVideoTrackResource::GetId() { | |
| 34 return StringVar::StringToPPVar(id()); | |
| 35 } | |
| 36 | |
| 37 PP_Bool MediaStreamVideoTrackResource::HasEnded() { | |
| 38 return PP_FromBool(has_ended()); | |
| 39 } | |
| 40 | |
| 41 int32_t MediaStreamVideoTrackResource::Configure(uint32_t max_buffered_frames) { | |
| 42 // TODO(penghuang): redesign and implement Configure() to support format, | |
| 43 // size, etc. | |
| 44 return PP_ERROR_NOTSUPPORTED; | |
| 45 } | |
| 46 | |
| 47 int32_t MediaStreamVideoTrackResource::GetFrame( | |
| 48 PP_Resource* frame, | |
| 49 scoped_refptr<ppapi::TrackedCallback> callback) { | |
| 50 if (has_ended()) | |
| 51 return PP_ERROR_FAILED; | |
| 52 | |
| 53 if (TrackedCallback::IsPending(get_frame_callback_)) | |
| 54 return PP_ERROR_INPROGRESS; | |
| 55 | |
| 56 *frame = GetVideoFrame(); | |
| 57 if (*frame) | |
| 58 return PP_OK; | |
| 59 | |
| 60 get_frame_output_ = frame; | |
| 61 get_frame_callback_ = callback; | |
| 62 return PP_OK_COMPLETIONPENDING; | |
| 63 } | |
| 64 | |
| 65 int32_t MediaStreamVideoTrackResource::RecycleFrame(PP_Resource frame) { | |
| 66 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.
| |
| 67 if (enter_frame.failed()) | |
| 68 return PP_ERROR_BADRESOURCE; | |
| 69 | |
|
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
| |
| 70 VideoFrameResource* frame_resource = | |
| 71 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
| |
| 72 if (frame_resource->index() < 0) | |
| 73 return PP_ERROR_BADRESOURCE; | |
| 74 | |
| 75 HostEnqueueFrame(frame_resource->index()); | |
| 76 frame_resource->invalidate(); | |
| 77 return PP_OK; | |
| 78 } | |
| 79 | |
| 80 void MediaStreamVideoTrackResource::Close() { | |
| 81 if (TrackedCallback::IsPending(get_frame_callback_)) { | |
| 82 *get_frame_output_ = 0; | |
| 83 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.
| |
| 84 get_frame_callback_ = NULL; | |
| 85 get_frame_output_ = 0; | |
| 86 } | |
| 87 MediaStreamTrackResourceBase::CloseInternal(); | |
| 88 } | |
| 89 | |
| 90 void MediaStreamVideoTrackResource::OnNewFrameEnqueued() { | |
| 91 if (TrackedCallback::IsPending(get_frame_callback_)) { | |
| 92 *get_frame_output_ = GetVideoFrame(); | |
| 93 get_frame_callback_->PostRun(PP_OK); | |
| 94 get_frame_callback_ = NULL; | |
| 95 get_frame_output_ = 0; | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 PP_Resource MediaStreamVideoTrackResource::GetVideoFrame() { | |
| 100 int32_t index = frame_buffer()->DequeueFrame(); | |
| 101 if (index < 0) | |
| 102 return 0; | |
| 103 MediaStreamFrame::Video* frame = | |
| 104 &(frame_buffer()->GetFramePointer(index)->video); | |
| 105 return (new VideoFrameResource(pp_instance(), index, frame))->GetReference(); | |
| 106 } | |
| 107 | |
| 108 } // namespace proxy | |
| 109 } // namespace ppapi | |
| OLD | NEW |