Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: ppapi/proxy/media_stream_video_track_resource.cc

Issue 128683003: [PPAPI] Implement media stream video track API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@video_track_impl_cl
Patch Set: Fix review issues Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ppapi/proxy/media_stream_video_track_resource.h ('k') | ppapi/proxy/plugin_var_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 if (has_ended())
68 return PP_ERROR_FAILED;
69
70 std::map<PP_Resource, scoped_refptr<VideoFrameResource> >::iterator it =
71 frames_.find(frame);
72
73 if (it == frames_.end())
74 return PP_ERROR_BADRESOURCE;
75
76 scoped_refptr<VideoFrameResource> frame_resource = it->second;
77 frames_.erase(it);
78
79 DCHECK(frame_resource->index() >= 0);
80
81 HostEnqueueFrame(frame_resource->index());
82 frame_resource->invalidate();
83 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(
yzshen1 2014/01/10 23:59:43 I see that you take one ref to the keys of |frames
Peng 2014/01/11 00:30:55 I though holding a ref in frames_ can avoid the Vi
Peng 2014/01/12 14:24:31 Done.
84 frame_resource->pp_resource());
85
86 return PP_OK;
87 }
88
89 void MediaStreamVideoTrackResource::Close() {
90 if (has_ended())
91 return;
92
93 if (TrackedCallback::IsPending(get_frame_callback_)) {
94 *get_frame_output_ = 0;
95 get_frame_callback_->PostAbort();
96 get_frame_callback_ = NULL;
97 get_frame_output_ = 0;
98 }
99
100 ReleaseFrames();
101 MediaStreamTrackResourceBase::CloseInternal();
102 }
103
104 void MediaStreamVideoTrackResource::OnNewFrameEnqueued() {
105 if (TrackedCallback::IsPending(get_frame_callback_)) {
106 *get_frame_output_ = GetVideoFrame();
107 get_frame_callback_->PostRun(PP_OK);
108 get_frame_callback_ = NULL;
109 get_frame_output_ = 0;
110 }
111 }
112
113 PP_Resource MediaStreamVideoTrackResource::GetVideoFrame() {
114 int32_t index = frame_buffer()->DequeueFrame();
115 if (index < 0)
116 return 0;
117 MediaStreamFrame::Video* frame =
118 &(frame_buffer()->GetFramePointer(index)->video);
119 scoped_refptr<VideoFrameResource> resource =
120 new VideoFrameResource(pp_instance(), index, frame);
121 frames_.insert(std::pair<PP_Resource, scoped_refptr<VideoFrameResource> >(
122 resource->GetReference(), resource));
yzshen1 2014/01/10 23:59:43 The indent of this line is a bit weird.
Peng 2014/01/12 14:24:31 Done.
123 return resource->GetReference();
124 }
125
126 void MediaStreamVideoTrackResource::ReleaseFrames() {
127 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
128 std::map<PP_Resource, scoped_refptr<VideoFrameResource> >::iterator it =
129 frames_.begin();
130 while (it != frames_.end()) {
131 scoped_refptr<VideoFrameResource> frame_resource = it->second;
132 frame_resource->invalidate();
133 tracker->ReleaseResource(frame_resource->pp_resource());
134 }
135 frames_.clear();
136 }
137
138 } // namespace proxy
139 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/media_stream_video_track_resource.h ('k') | ppapi/proxy/plugin_var_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698