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_buffer.h" |
10 #include "ppapi/shared_impl/var.h" | 10 #include "ppapi/shared_impl/var.h" |
11 | 11 |
12 namespace ppapi { | 12 namespace ppapi { |
13 namespace proxy { | 13 namespace proxy { |
14 | 14 |
15 MediaStreamVideoTrackResource::MediaStreamVideoTrackResource( | 15 MediaStreamVideoTrackResource::MediaStreamVideoTrackResource( |
16 Connection connection, | 16 Connection connection, |
17 PP_Instance instance, | 17 PP_Instance instance, |
18 int pending_renderer_id, | 18 int pending_renderer_id, |
19 const std::string& id) | 19 const std::string& id) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 FrameMap::iterator it = frames_.find(frame); | 77 FrameMap::iterator it = frames_.find(frame); |
78 if (it == frames_.end()) | 78 if (it == frames_.end()) |
79 return PP_ERROR_BADRESOURCE; | 79 return PP_ERROR_BADRESOURCE; |
80 | 80 |
81 scoped_refptr<VideoFrameResource> frame_resource = it->second; | 81 scoped_refptr<VideoFrameResource> frame_resource = it->second; |
82 frames_.erase(it); | 82 frames_.erase(it); |
83 | 83 |
84 if (has_ended()) | 84 if (has_ended()) |
85 return PP_OK; | 85 return PP_OK; |
86 | 86 |
87 DCHECK_GE(frame_resource->GetFrameBufferIndex(), 0); | 87 DCHECK_GE(frame_resource->GetBufferIndex(), 0); |
88 | 88 |
89 SendEnqueueFrameMessageToHost(frame_resource->GetFrameBufferIndex()); | 89 SendEnqueueBufferMessageToHost(frame_resource->GetBufferIndex()); |
90 frame_resource->Invalidate(); | 90 frame_resource->Invalidate(); |
91 return PP_OK; | 91 return PP_OK; |
92 } | 92 } |
93 | 93 |
94 void MediaStreamVideoTrackResource::Close() { | 94 void MediaStreamVideoTrackResource::Close() { |
95 if (has_ended()) | 95 if (has_ended()) |
96 return; | 96 return; |
97 | 97 |
98 if (TrackedCallback::IsPending(get_frame_callback_)) { | 98 if (TrackedCallback::IsPending(get_frame_callback_)) { |
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 void MediaStreamVideoTrackResource::OnNewBufferEnqueued() { |
110 if (!TrackedCallback::IsPending(get_frame_callback_)) | 110 if (!TrackedCallback::IsPending(get_frame_callback_)) |
111 return; | 111 return; |
112 | 112 |
113 *get_frame_output_ = GetVideoFrame(); | 113 *get_frame_output_ = GetVideoFrame(); |
114 int32_t result = *get_frame_output_ ? PP_OK : PP_ERROR_FAILED; | 114 int32_t result = *get_frame_output_ ? PP_OK : PP_ERROR_FAILED; |
115 get_frame_output_ = NULL; | 115 get_frame_output_ = NULL; |
116 scoped_refptr<TrackedCallback> callback; | 116 scoped_refptr<TrackedCallback> callback; |
117 callback.swap(get_frame_callback_); | 117 callback.swap(get_frame_callback_); |
118 callback->Run(result); | 118 callback->Run(result); |
119 } | 119 } |
120 | 120 |
121 PP_Resource MediaStreamVideoTrackResource::GetVideoFrame() { | 121 PP_Resource MediaStreamVideoTrackResource::GetVideoFrame() { |
122 int32_t index = frame_buffer()->DequeueFrame(); | 122 int32_t index = buffer_manager()->DequeueBuffer(); |
123 if (index < 0) | 123 if (index < 0) |
124 return 0; | 124 return 0; |
125 | 125 |
126 MediaStreamFrame* frame = frame_buffer()->GetFramePointer(index); | 126 MediaStreamBuffer* buffer = buffer_manager()->GetBufferPointer(index); |
127 DCHECK(frame); | 127 DCHECK(buffer); |
128 scoped_refptr<VideoFrameResource> resource = | 128 scoped_refptr<VideoFrameResource> resource = |
129 new VideoFrameResource(pp_instance(), index, frame); | 129 new VideoFrameResource(pp_instance(), index, buffer); |
130 // Add |pp_resource()| and |resource| into |frames_|. | 130 // Add |pp_resource()| and |resource| into |frames_|. |
131 // |frames_| uses scoped_ptr<> to hold a ref of |resource|. It keeps the | 131 // |frames_| uses scoped_ptr<> to hold a ref of |resource|. It keeps the |
132 // resource alive. | 132 // resource alive. |
133 frames_.insert(FrameMap::value_type(resource->pp_resource(), resource)); | 133 frames_.insert(FrameMap::value_type(resource->pp_resource(), resource)); |
134 return resource->GetReference(); | 134 return resource->GetReference(); |
135 } | 135 } |
136 | 136 |
137 void MediaStreamVideoTrackResource::ReleaseFrames() { | 137 void MediaStreamVideoTrackResource::ReleaseFrames() { |
138 FrameMap::iterator it = frames_.begin(); | 138 FrameMap::iterator it = frames_.begin(); |
139 while (it != frames_.end()) { | 139 while (it != frames_.end()) { |
140 // Just invalidate and release VideoFrameResorce, but keep PP_Resource. | 140 // Just invalidate and release VideoFrameResorce, but keep PP_Resource. |
141 // So plugin can still use |RecycleFrame()|. | 141 // So plugin can still use |RecycleFrame()|. |
142 it->second->Invalidate(); | 142 it->second->Invalidate(); |
143 it->second = NULL; | 143 it->second = NULL; |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 } // namespace proxy | 147 } // namespace proxy |
148 } // namespace ppapi | 148 } // namespace ppapi |
OLD | NEW |