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/ppapi_messages.h" | |
8 #include "ppapi/proxy/video_frame_resource.h" | 9 #include "ppapi/proxy/video_frame_resource.h" |
9 #include "ppapi/shared_impl/media_stream_buffer.h" | 10 #include "ppapi/shared_impl/media_stream_buffer.h" |
11 #include "ppapi/shared_impl/media_stream_video_track_shared.h" | |
10 #include "ppapi/shared_impl/var.h" | 12 #include "ppapi/shared_impl/var.h" |
11 | 13 |
12 namespace ppapi { | 14 namespace ppapi { |
13 namespace proxy { | 15 namespace proxy { |
14 | 16 |
15 MediaStreamVideoTrackResource::MediaStreamVideoTrackResource( | 17 MediaStreamVideoTrackResource::MediaStreamVideoTrackResource( |
16 Connection connection, | 18 Connection connection, |
17 PP_Instance instance, | 19 PP_Instance instance, |
18 int pending_renderer_id, | 20 int pending_renderer_id, |
19 const std::string& id) | 21 const std::string& id) |
(...skipping 12 matching lines...) Expand all Loading... | |
32 } | 34 } |
33 | 35 |
34 PP_Var MediaStreamVideoTrackResource::GetId() { | 36 PP_Var MediaStreamVideoTrackResource::GetId() { |
35 return StringVar::StringToPPVar(id()); | 37 return StringVar::StringToPPVar(id()); |
36 } | 38 } |
37 | 39 |
38 PP_Bool MediaStreamVideoTrackResource::HasEnded() { | 40 PP_Bool MediaStreamVideoTrackResource::HasEnded() { |
39 return PP_FromBool(has_ended()); | 41 return PP_FromBool(has_ended()); |
40 } | 42 } |
41 | 43 |
42 | |
43 int32_t MediaStreamVideoTrackResource::Configure( | 44 int32_t MediaStreamVideoTrackResource::Configure( |
44 const int32_t attrib_list[], | 45 const int32_t attrib_list[], |
45 scoped_refptr<TrackedCallback> callback) { | 46 scoped_refptr<TrackedCallback> callback) { |
46 // TODO(penghuang): redesign and implement Configure() to support format, | 47 if (has_ended()) { |
yzshen1
2014/02/13 19:23:26
nit: no need to have {} and line 57.
Peng
2014/02/13 21:28:34
Done.
| |
47 // size, etc. | 48 return PP_ERROR_FAILED; |
48 return PP_ERROR_NOTSUPPORTED; | 49 } |
50 | |
51 if (TrackedCallback::IsPending(configure_callback_) || | |
52 TrackedCallback::IsPending(get_frame_callback_)) { | |
53 return PP_ERROR_INPROGRESS; | |
54 } | |
55 | |
56 // Do not support configure, if frames are hold by plugin. | |
57 if (!frames_.empty()) { | |
58 return PP_ERROR_FAILED; | |
59 } | |
60 | |
61 MediaStreamVideoTrackShared::Attributes attributes; | |
62 int i = 0; | |
63 for (;attrib_list[i] != PP_MEDIASTREAMVIDEOTRACK_ATTRIB_NONE; i += 2) { | |
jschuh
2014/02/13 20:38:46
Which process does this come from, and how do you
Peng
2014/02/13 21:28:34
It is from plugin. And this function is executed i
Peng
2014/02/13 21:28:34
The argument is from plugin. And this function is
| |
64 switch (attrib_list[i]) { | |
65 case PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES: | |
66 attributes.mask |= MediaStreamVideoTrackShared::Attributes::MASK_BUFFERS; | |
67 attributes.buffers = attrib_list[i + 1]; | |
68 break; | |
69 case PP_MEDIASTREAMVIDEOTRACK_ATTRIB_WIDTH: | |
70 attributes.mask |= MediaStreamVideoTrackShared::Attributes::MASK_WIDTH; | |
71 attributes.width = attrib_list[i + 1]; | |
72 break; | |
73 case PP_MEDIASTREAMVIDEOTRACK_ATTRIB_HEIGHT: | |
74 attributes.mask |= MediaStreamVideoTrackShared::Attributes::MASK_HEIGHT; | |
75 attributes.height = attrib_list[i + 1]; | |
76 break; | |
77 case PP_MEDIASTREAMVIDEOTRACK_ATTRIB_FORMAT: | |
78 attributes.mask |= MediaStreamVideoTrackShared::Attributes::MASK_FORMAT; | |
79 attributes.format = static_cast<PP_VideoFrame_Format>(attrib_list[i + 1]); | |
80 break; | |
81 default: | |
82 return PP_ERROR_BADARGUMENT; | |
83 } | |
84 } | |
85 | |
86 if (!MediaStreamVideoTrackShared::VerifyAttributes(attributes)) { | |
87 return PP_ERROR_BADARGUMENT; | |
88 } | |
89 | |
90 if (!attributes.mask) { | |
91 return PP_OK; | |
92 } | |
93 | |
94 configure_callback_ = callback; | |
95 Call<PpapiPluginMsg_MediaStreamVideoTrack_ConfigureReply>( | |
96 RENDERER, | |
97 PpapiHostMsg_MediaStreamVideoTrack_Configure(attributes), | |
98 base::Bind(&MediaStreamVideoTrackResource::OnPluginMsgConfigureReply, | |
99 base::Unretained(this)), | |
100 callback); | |
101 return PP_OK_COMPLETIONPENDING; | |
49 } | 102 } |
50 | 103 |
51 int32_t MediaStreamVideoTrackResource::GetAttrib( | 104 int32_t MediaStreamVideoTrackResource::GetAttrib( |
52 PP_MediaStreamVideoTrack_Attrib attrib, | 105 PP_MediaStreamVideoTrack_Attrib attrib, |
53 int32_t* value) { | 106 int32_t* value) { |
54 // TODO(penghuang): implement this function. | 107 // TODO(penghuang): implement this function. |
55 return PP_ERROR_NOTSUPPORTED; | 108 return PP_ERROR_NOTSUPPORTED; |
56 } | 109 } |
57 | 110 |
58 int32_t MediaStreamVideoTrackResource::GetFrame( | 111 int32_t MediaStreamVideoTrackResource::GetFrame( |
59 PP_Resource* frame, | 112 PP_Resource* frame, |
60 scoped_refptr<TrackedCallback> callback) { | 113 scoped_refptr<TrackedCallback> callback) { |
61 if (has_ended()) | 114 if (has_ended()) |
62 return PP_ERROR_FAILED; | 115 return PP_ERROR_FAILED; |
63 | 116 |
64 if (TrackedCallback::IsPending(get_frame_callback_)) | 117 if (TrackedCallback::IsPending(configure_callback_) || |
118 TrackedCallback::IsPending(get_frame_callback_)) { | |
65 return PP_ERROR_INPROGRESS; | 119 return PP_ERROR_INPROGRESS; |
120 } | |
66 | 121 |
67 *frame = GetVideoFrame(); | 122 *frame = GetVideoFrame(); |
68 if (*frame) | 123 if (*frame) |
69 return PP_OK; | 124 return PP_OK; |
70 | 125 |
71 get_frame_output_ = frame; | 126 get_frame_output_ = frame; |
72 get_frame_callback_ = callback; | 127 get_frame_callback_ = callback; |
73 return PP_OK_COMPLETIONPENDING; | 128 return PP_OK_COMPLETIONPENDING; |
74 } | 129 } |
75 | 130 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 void MediaStreamVideoTrackResource::ReleaseFrames() { | 192 void MediaStreamVideoTrackResource::ReleaseFrames() { |
138 FrameMap::iterator it = frames_.begin(); | 193 FrameMap::iterator it = frames_.begin(); |
139 while (it != frames_.end()) { | 194 while (it != frames_.end()) { |
140 // Just invalidate and release VideoFrameResorce, but keep PP_Resource. | 195 // Just invalidate and release VideoFrameResorce, but keep PP_Resource. |
141 // So plugin can still use |RecycleFrame()|. | 196 // So plugin can still use |RecycleFrame()|. |
142 it->second->Invalidate(); | 197 it->second->Invalidate(); |
143 it->second = NULL; | 198 it->second = NULL; |
144 } | 199 } |
145 } | 200 } |
146 | 201 |
202 void MediaStreamVideoTrackResource::OnPluginMsgConfigureReply( | |
203 const ResourceMessageReplyParams& params) { | |
204 DCHECK(TrackedCallback::IsPending(configure_callback_)); | |
yzshen1
2014/02/13 19:23:26
Please explicitly check if (!IsPending()) return.
Peng
2014/02/13 21:28:34
Done.
| |
205 scoped_refptr<TrackedCallback> callback; | |
206 callback.swap(configure_callback_); | |
207 callback->Run(params.result()); | |
208 } | |
209 | |
147 } // namespace proxy | 210 } // namespace proxy |
148 } // namespace ppapi | 211 } // namespace ppapi |
OLD | NEW |