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