| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/media_stream_video_track_resource.h" | 5 #include "ppapi/proxy/media_stream_video_track_resource.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/proxy/video_frame_resource.h" | 8 #include "ppapi/proxy/video_frame_resource.h" |
| 9 #include "ppapi/shared_impl/media_stream_frame.h" | 9 #include "ppapi/shared_impl/media_stream_frame.h" |
| 10 #include "ppapi/shared_impl/var.h" | 10 #include "ppapi/shared_impl/var.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 int32_t MediaStreamVideoTrackResource::GetFrame( | 48 int32_t MediaStreamVideoTrackResource::GetFrame( |
| 49 PP_Resource* frame, | 49 PP_Resource* frame, |
| 50 scoped_refptr<TrackedCallback> callback) { | 50 scoped_refptr<TrackedCallback> callback) { |
| 51 if (has_ended()) | 51 if (has_ended()) |
| 52 return PP_ERROR_FAILED; | 52 return PP_ERROR_FAILED; |
| 53 | 53 |
| 54 if (TrackedCallback::IsPending(get_frame_callback_)) | 54 if (TrackedCallback::IsPending(get_frame_callback_)) |
| 55 return PP_ERROR_INPROGRESS; | 55 return PP_ERROR_INPROGRESS; |
| 56 | 56 |
| 57 *frame = GetVideoFrame(); | 57 *frame = GetVideoFrame(-1); |
| 58 if (*frame) | 58 if (*frame) |
| 59 return PP_OK; | 59 return PP_OK; |
| 60 | 60 |
| 61 get_frame_output_ = frame; | 61 get_frame_output_ = frame; |
| 62 get_frame_callback_ = callback; | 62 get_frame_callback_ = callback; |
| 63 return PP_OK_COMPLETIONPENDING; | 63 return PP_OK_COMPLETIONPENDING; |
| 64 } | 64 } |
| 65 | 65 |
| 66 int32_t MediaStreamVideoTrackResource::RecycleFrame(PP_Resource frame) { | 66 int32_t MediaStreamVideoTrackResource::RecycleFrame(PP_Resource frame) { |
| 67 FrameMap::iterator it = frames_.find(frame); | 67 FrameMap::iterator it = frames_.find(frame); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 89 *get_frame_output_ = 0; | 89 *get_frame_output_ = 0; |
| 90 get_frame_callback_->PostAbort(); | 90 get_frame_callback_->PostAbort(); |
| 91 get_frame_callback_ = NULL; | 91 get_frame_callback_ = NULL; |
| 92 get_frame_output_ = 0; | 92 get_frame_output_ = 0; |
| 93 } | 93 } |
| 94 | 94 |
| 95 ReleaseFrames(); | 95 ReleaseFrames(); |
| 96 MediaStreamTrackResourceBase::CloseInternal(); | 96 MediaStreamTrackResourceBase::CloseInternal(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void MediaStreamVideoTrackResource::OnNewFrameEnqueued() { | 99 bool MediaStreamVideoTrackResource::OnNewFramePreEnqueued(int32_t index) { |
| 100 if (TrackedCallback::IsPending(get_frame_callback_)) { | 100 if (!TrackedCallback::IsPending(get_frame_callback_)) |
| 101 *get_frame_output_ = GetVideoFrame(); | 101 return false; |
| 102 get_frame_output_ = NULL; | 102 |
| 103 scoped_refptr<TrackedCallback> callback; | 103 *get_frame_output_ = GetVideoFrame(index); |
| 104 callback.swap(get_frame_callback_); | 104 get_frame_output_ = NULL; |
| 105 callback->Run(PP_OK); | 105 scoped_refptr<TrackedCallback> callback; |
| 106 } | 106 callback.swap(get_frame_callback_); |
| 107 callback->Run(PP_OK); |
| 108 return true; |
| 107 } | 109 } |
| 108 | 110 |
| 109 PP_Resource MediaStreamVideoTrackResource::GetVideoFrame() { | 111 PP_Resource MediaStreamVideoTrackResource::GetVideoFrame(int32_t index) { |
| 110 int32_t index = frame_buffer()->DequeueFrame(); | 112 if (index < 0) { |
| 111 if (index < 0) | 113 index = frame_buffer()->DequeueFrame(); |
| 112 return 0; | 114 if (index < 0) |
| 115 return 0; |
| 116 } |
| 113 MediaStreamFrame* frame = frame_buffer()->GetFramePointer(index); | 117 MediaStreamFrame* frame = frame_buffer()->GetFramePointer(index); |
| 118 DCHECK(frame); |
| 114 scoped_refptr<VideoFrameResource> resource = | 119 scoped_refptr<VideoFrameResource> resource = |
| 115 new VideoFrameResource(pp_instance(), index, frame); | 120 new VideoFrameResource(pp_instance(), index, frame); |
| 116 // Add |pp_resource()| and |resource| into |frames_|. | 121 // Add |pp_resource()| and |resource| into |frames_|. |
| 117 // |frames_| uses scoped_ptr<> to hold a ref of |resource|. It keeps the | 122 // |frames_| uses scoped_ptr<> to hold a ref of |resource|. It keeps the |
| 118 // resource alive. | 123 // resource alive. |
| 119 frames_.insert(FrameMap::value_type(resource->pp_resource(), resource)); | 124 frames_.insert(FrameMap::value_type(resource->pp_resource(), resource)); |
| 120 return resource->GetReference(); | 125 return resource->GetReference(); |
| 121 } | 126 } |
| 122 | 127 |
| 123 void MediaStreamVideoTrackResource::ReleaseFrames() { | 128 void MediaStreamVideoTrackResource::ReleaseFrames() { |
| 124 FrameMap::iterator it = frames_.begin(); | 129 FrameMap::iterator it = frames_.begin(); |
| 125 while (it != frames_.end()) { | 130 while (it != frames_.end()) { |
| 126 // Just invalidate and release VideoFrameResorce, but keep PP_Resource. | 131 // Just invalidate and release VideoFrameResorce, but keep PP_Resource. |
| 127 // So plugin can still use |RecycleFrame()|. | 132 // So plugin can still use |RecycleFrame()|. |
| 128 it->second->Invalidate(); | 133 it->second->Invalidate(); |
| 129 it->second = NULL; | 134 it->second = NULL; |
| 130 } | 135 } |
| 131 } | 136 } |
| 132 | 137 |
| 133 } // namespace proxy | 138 } // namespace proxy |
| 134 } // namespace ppapi | 139 } // namespace ppapi |
| OLD | NEW |