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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 int32_t MediaStreamVideoTrackResource::GetFrame( | 58 int32_t MediaStreamVideoTrackResource::GetFrame( |
59 PP_Resource* frame, | 59 PP_Resource* frame, |
60 scoped_refptr<TrackedCallback> callback) { | 60 scoped_refptr<TrackedCallback> callback) { |
61 if (has_ended()) | 61 if (has_ended()) |
62 return PP_ERROR_FAILED; | 62 return PP_ERROR_FAILED; |
63 | 63 |
64 if (TrackedCallback::IsPending(get_frame_callback_)) | 64 if (TrackedCallback::IsPending(get_frame_callback_)) |
65 return PP_ERROR_INPROGRESS; | 65 return PP_ERROR_INPROGRESS; |
66 | 66 |
67 *frame = GetVideoFrame(); | 67 *frame = GetVideoFrame(-1); |
68 if (*frame) | 68 if (*frame) |
69 return PP_OK; | 69 return PP_OK; |
70 | 70 |
71 get_frame_output_ = frame; | 71 get_frame_output_ = frame; |
72 get_frame_callback_ = callback; | 72 get_frame_callback_ = callback; |
73 return PP_OK_COMPLETIONPENDING; | 73 return PP_OK_COMPLETIONPENDING; |
74 } | 74 } |
75 | 75 |
76 int32_t MediaStreamVideoTrackResource::RecycleFrame(PP_Resource frame) { | 76 int32_t MediaStreamVideoTrackResource::RecycleFrame(PP_Resource frame) { |
77 FrameMap::iterator it = frames_.find(frame); | 77 FrameMap::iterator it = frames_.find(frame); |
(...skipping 21 matching lines...) Expand all Loading... |
99 *get_frame_output_ = 0; | 99 *get_frame_output_ = 0; |
100 get_frame_callback_->PostAbort(); | 100 get_frame_callback_->PostAbort(); |
101 get_frame_callback_ = NULL; | 101 get_frame_callback_ = NULL; |
102 get_frame_output_ = 0; | 102 get_frame_output_ = 0; |
103 } | 103 } |
104 | 104 |
105 ReleaseFrames(); | 105 ReleaseFrames(); |
106 MediaStreamTrackResourceBase::CloseInternal(); | 106 MediaStreamTrackResourceBase::CloseInternal(); |
107 } | 107 } |
108 | 108 |
109 void MediaStreamVideoTrackResource::OnNewFrameEnqueued() { | 109 bool MediaStreamVideoTrackResource::OnNewFramePreEnqueued(int32_t index) { |
110 if (TrackedCallback::IsPending(get_frame_callback_)) { | 110 if (!TrackedCallback::IsPending(get_frame_callback_)) |
111 *get_frame_output_ = GetVideoFrame(); | 111 return false; |
112 get_frame_output_ = NULL; | 112 |
113 scoped_refptr<TrackedCallback> callback; | 113 *get_frame_output_ = GetVideoFrame(index); |
114 callback.swap(get_frame_callback_); | 114 get_frame_output_ = NULL; |
115 callback->Run(PP_OK); | 115 scoped_refptr<TrackedCallback> callback; |
116 } | 116 callback.swap(get_frame_callback_); |
| 117 callback->Run(PP_OK); |
| 118 return true; |
117 } | 119 } |
118 | 120 |
119 PP_Resource MediaStreamVideoTrackResource::GetVideoFrame() { | 121 PP_Resource MediaStreamVideoTrackResource::GetVideoFrame(int32_t index) { |
120 int32_t index = frame_buffer()->DequeueFrame(); | 122 if (index < 0) { |
121 if (index < 0) | 123 index = frame_buffer()->DequeueFrame(); |
122 return 0; | 124 if (index < 0) |
| 125 return 0; |
| 126 } |
123 MediaStreamFrame* frame = frame_buffer()->GetFramePointer(index); | 127 MediaStreamFrame* frame = frame_buffer()->GetFramePointer(index); |
| 128 DCHECK(frame); |
124 scoped_refptr<VideoFrameResource> resource = | 129 scoped_refptr<VideoFrameResource> resource = |
125 new VideoFrameResource(pp_instance(), index, frame); | 130 new VideoFrameResource(pp_instance(), index, frame); |
126 // Add |pp_resource()| and |resource| into |frames_|. | 131 // Add |pp_resource()| and |resource| into |frames_|. |
127 // |frames_| uses scoped_ptr<> to hold a ref of |resource|. It keeps the | 132 // |frames_| uses scoped_ptr<> to hold a ref of |resource|. It keeps the |
128 // resource alive. | 133 // resource alive. |
129 frames_.insert(FrameMap::value_type(resource->pp_resource(), resource)); | 134 frames_.insert(FrameMap::value_type(resource->pp_resource(), resource)); |
130 return resource->GetReference(); | 135 return resource->GetReference(); |
131 } | 136 } |
132 | 137 |
133 void MediaStreamVideoTrackResource::ReleaseFrames() { | 138 void MediaStreamVideoTrackResource::ReleaseFrames() { |
134 FrameMap::iterator it = frames_.begin(); | 139 FrameMap::iterator it = frames_.begin(); |
135 while (it != frames_.end()) { | 140 while (it != frames_.end()) { |
136 // Just invalidate and release VideoFrameResorce, but keep PP_Resource. | 141 // Just invalidate and release VideoFrameResorce, but keep PP_Resource. |
137 // So plugin can still use |RecycleFrame()|. | 142 // So plugin can still use |RecycleFrame()|. |
138 it->second->Invalidate(); | 143 it->second->Invalidate(); |
139 it->second = NULL; | 144 it->second = NULL; |
140 } | 145 } |
141 } | 146 } |
142 | 147 |
143 } // namespace proxy | 148 } // namespace proxy |
144 } // namespace ppapi | 149 } // namespace ppapi |
OLD | NEW |