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 Close(); | |
| 27 } | |
| 28 | |
| 29 thunk::PPB_MediaStreamVideoTrack_API* | |
| 30 MediaStreamVideoTrackResource::AsPPB_MediaStreamVideoTrack_API() { | |
| 31 return this; | |
| 32 } | |
| 33 | |
| 34 PP_Var MediaStreamVideoTrackResource::GetId() { | |
| 35 return StringVar::StringToPPVar(id()); | |
| 36 } | |
| 37 | |
| 38 PP_Bool MediaStreamVideoTrackResource::HasEnded() { | |
| 39 return PP_FromBool(has_ended()); | |
| 40 } | |
| 41 | |
| 42 int32_t MediaStreamVideoTrackResource::Configure(uint32_t max_buffered_frames) { | |
| 43 // TODO(penghuang): redesign and implement Configure() to support format, | |
| 44 // size, etc. | |
| 45 return PP_ERROR_NOTSUPPORTED; | |
| 46 } | |
| 47 | |
| 48 int32_t MediaStreamVideoTrackResource::GetFrame( | |
| 49 PP_Resource* frame, | |
| 50 scoped_refptr<TrackedCallback> callback) { | |
| 51 if (has_ended()) | |
| 52 return PP_ERROR_FAILED; | |
| 53 | |
| 54 if (TrackedCallback::IsPending(get_frame_callback_)) | |
| 55 return PP_ERROR_INPROGRESS; | |
| 56 | |
| 57 *frame = GetVideoFrame(); | |
| 58 if (*frame) | |
| 59 return PP_OK; | |
| 60 | |
| 61 get_frame_output_ = frame; | |
| 62 get_frame_callback_ = callback; | |
| 63 return PP_OK_COMPLETIONPENDING; | |
| 64 } | |
| 65 | |
| 66 int32_t MediaStreamVideoTrackResource::RecycleFrame(PP_Resource frame) { | |
| 67 FrameMap::iterator it = frames_.find(frame); | |
| 68 if (it == frames_.end()) | |
| 69 return PP_ERROR_BADRESOURCE; | |
| 70 | |
| 71 scoped_refptr<VideoFrameResource> frame_resource = it->second; | |
| 72 frames_.erase(it); | |
| 73 | |
| 74 if (has_ended()) | |
| 75 return PP_OK; | |
| 76 | |
| 77 thunk::EnterResourceNoLock<thunk::PPB_VideoFrame_API> enter(frame, false); | |
|
bbudge
2014/01/14 20:52:11
You can avoid the EnterResource stuff and referenc
Peng
2014/01/14 21:31:35
Done. I like use scoped_refptr<VideoFrameResource>
| |
| 78 DCHECK(enter.succeeded()); | |
| 79 DCHECK(enter.object()->GetFrameBufferIndex() >= 0); | |
| 80 | |
| 81 SendEnqueueFrameMessageToHost(enter.object()->GetFrameBufferIndex()); | |
| 82 enter.object()->Invalidate(); | |
| 83 return PP_OK; | |
| 84 } | |
| 85 | |
| 86 void MediaStreamVideoTrackResource::Close() { | |
| 87 if (has_ended()) | |
| 88 return; | |
| 89 | |
| 90 if (TrackedCallback::IsPending(get_frame_callback_)) { | |
| 91 *get_frame_output_ = 0; | |
| 92 get_frame_callback_->PostAbort(); | |
| 93 get_frame_callback_ = NULL; | |
| 94 get_frame_output_ = 0; | |
| 95 } | |
| 96 | |
| 97 ReleaseFrames(); | |
| 98 MediaStreamTrackResourceBase::CloseInternal(); | |
| 99 } | |
| 100 | |
| 101 void MediaStreamVideoTrackResource::OnNewFrameEnqueued() { | |
| 102 if (TrackedCallback::IsPending(get_frame_callback_)) { | |
| 103 *get_frame_output_ = GetVideoFrame(); | |
| 104 get_frame_callback_->PostRun(PP_OK); | |
|
yzshen1
2014/01/14 20:47:29
This is called by a message handler, plugin code i
Peng
2014/01/14 21:31:35
Thanks for detailed explanation. Now understand wh
| |
| 105 get_frame_callback_ = NULL; | |
| 106 get_frame_output_ = 0; | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 PP_Resource MediaStreamVideoTrackResource::GetVideoFrame() { | |
| 111 int32_t index = frame_buffer()->DequeueFrame(); | |
| 112 if (index < 0) | |
| 113 return 0; | |
| 114 MediaStreamFrame* frame = frame_buffer()->GetFramePointer(index); | |
| 115 scoped_refptr<VideoFrameResource> resource = | |
| 116 new VideoFrameResource(pp_instance(), index, frame); | |
| 117 frames_.insert(FrameMap::value_type(resource->GetReference(), resource)); | |
|
yzshen1
2014/01/14 20:47:29
The current code looks like |frames_| owns a ref t
Peng
2014/01/14 21:31:35
I changed the code to use pp_resource() at map.ins
| |
| 118 return resource->pp_resource(); | |
| 119 } | |
| 120 | |
| 121 void MediaStreamVideoTrackResource::ReleaseFrames() { | |
| 122 FrameMap::iterator it = frames_.begin(); | |
| 123 while (it != frames_.end()) { | |
|
bbudge
2014/01/14 20:52:11
Again, just use the VideoFrameResource directly vi
Peng
2014/01/14 21:31:35
Done.
| |
| 124 thunk::EnterResourceNoLock<thunk::PPB_VideoFrame_API> enter(it->first, | |
| 125 false); | |
| 126 DCHECK(enter.succeeded()); | |
| 127 // Just invalidate and release VideoFrameResorce, but keep PP_Resource. | |
| 128 // So plugin can still use |RecycleFrame()|. | |
| 129 enter.object()->Invalidate(); | |
| 130 it->second = NULL; | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 } // namespace proxy | |
| 135 } // namespace ppapi | |
| OLD | NEW |