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()) |
47 // size, etc. | 48 return PP_ERROR_FAILED; |
48 return PP_ERROR_NOTSUPPORTED; | 49 |
| 50 if (TrackedCallback::IsPending(configure_callback_) || |
| 51 TrackedCallback::IsPending(get_frame_callback_)) { |
| 52 return PP_ERROR_INPROGRESS; |
| 53 } |
| 54 |
| 55 // Do not support configure, if frames are hold by plugin. |
| 56 if (!frames_.empty()) |
| 57 return PP_ERROR_INPROGRESS; |
| 58 |
| 59 MediaStreamVideoTrackShared::Attributes attributes; |
| 60 int i = 0; |
| 61 for (;attrib_list[i] != PP_MEDIASTREAMVIDEOTRACK_ATTRIB_NONE; i += 2) { |
| 62 switch (attrib_list[i]) { |
| 63 case PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES: |
| 64 attributes.buffers = attrib_list[i + 1]; |
| 65 break; |
| 66 case PP_MEDIASTREAMVIDEOTRACK_ATTRIB_WIDTH: |
| 67 attributes.width = attrib_list[i + 1]; |
| 68 break; |
| 69 case PP_MEDIASTREAMVIDEOTRACK_ATTRIB_HEIGHT: |
| 70 attributes.height = attrib_list[i + 1]; |
| 71 break; |
| 72 case PP_MEDIASTREAMVIDEOTRACK_ATTRIB_FORMAT: |
| 73 attributes.format = static_cast<PP_VideoFrame_Format>(attrib_list[i + 1]); |
| 74 break; |
| 75 default: |
| 76 return PP_ERROR_BADARGUMENT; |
| 77 } |
| 78 } |
| 79 |
| 80 if (!MediaStreamVideoTrackShared::VerifyAttributes(attributes)) |
| 81 return PP_ERROR_BADARGUMENT; |
| 82 |
| 83 configure_callback_ = callback; |
| 84 Call<PpapiPluginMsg_MediaStreamVideoTrack_ConfigureReply>( |
| 85 RENDERER, |
| 86 PpapiHostMsg_MediaStreamVideoTrack_Configure(attributes), |
| 87 base::Bind(&MediaStreamVideoTrackResource::OnPluginMsgConfigureReply, |
| 88 base::Unretained(this)), |
| 89 callback); |
| 90 return PP_OK_COMPLETIONPENDING; |
49 } | 91 } |
50 | 92 |
51 int32_t MediaStreamVideoTrackResource::GetAttrib( | 93 int32_t MediaStreamVideoTrackResource::GetAttrib( |
52 PP_MediaStreamVideoTrack_Attrib attrib, | 94 PP_MediaStreamVideoTrack_Attrib attrib, |
53 int32_t* value) { | 95 int32_t* value) { |
54 // TODO(penghuang): implement this function. | 96 // TODO(penghuang): implement this function. |
55 return PP_ERROR_NOTSUPPORTED; | 97 return PP_ERROR_NOTSUPPORTED; |
56 } | 98 } |
57 | 99 |
58 int32_t MediaStreamVideoTrackResource::GetFrame( | 100 int32_t MediaStreamVideoTrackResource::GetFrame( |
59 PP_Resource* frame, | 101 PP_Resource* frame, |
60 scoped_refptr<TrackedCallback> callback) { | 102 scoped_refptr<TrackedCallback> callback) { |
61 if (has_ended()) | 103 if (has_ended()) |
62 return PP_ERROR_FAILED; | 104 return PP_ERROR_FAILED; |
63 | 105 |
64 if (TrackedCallback::IsPending(get_frame_callback_)) | 106 if (TrackedCallback::IsPending(configure_callback_) || |
| 107 TrackedCallback::IsPending(get_frame_callback_)) { |
65 return PP_ERROR_INPROGRESS; | 108 return PP_ERROR_INPROGRESS; |
| 109 } |
66 | 110 |
67 *frame = GetVideoFrame(); | 111 *frame = GetVideoFrame(); |
68 if (*frame) | 112 if (*frame) |
69 return PP_OK; | 113 return PP_OK; |
70 | 114 |
71 get_frame_output_ = frame; | 115 get_frame_output_ = frame; |
72 get_frame_callback_ = callback; | 116 get_frame_callback_ = callback; |
73 return PP_OK_COMPLETIONPENDING; | 117 return PP_OK_COMPLETIONPENDING; |
74 } | 118 } |
75 | 119 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 void MediaStreamVideoTrackResource::ReleaseFrames() { | 181 void MediaStreamVideoTrackResource::ReleaseFrames() { |
138 FrameMap::iterator it = frames_.begin(); | 182 FrameMap::iterator it = frames_.begin(); |
139 while (it != frames_.end()) { | 183 while (it != frames_.end()) { |
140 // Just invalidate and release VideoFrameResorce, but keep PP_Resource. | 184 // Just invalidate and release VideoFrameResorce, but keep PP_Resource. |
141 // So plugin can still use |RecycleFrame()|. | 185 // So plugin can still use |RecycleFrame()|. |
142 it->second->Invalidate(); | 186 it->second->Invalidate(); |
143 it->second = NULL; | 187 it->second = NULL; |
144 } | 188 } |
145 } | 189 } |
146 | 190 |
| 191 void MediaStreamVideoTrackResource::OnPluginMsgConfigureReply( |
| 192 const ResourceMessageReplyParams& params) { |
| 193 if (TrackedCallback::IsPending(configure_callback_)) { |
| 194 scoped_refptr<TrackedCallback> callback; |
| 195 callback.swap(configure_callback_); |
| 196 callback->Run(params.result()); |
| 197 } |
| 198 } |
| 199 |
147 } // namespace proxy | 200 } // namespace proxy |
148 } // namespace ppapi | 201 } // namespace ppapi |
OLD | NEW |