OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Ericsson AB. All rights reserved. | 2 * Copyright (C) 2011 Ericsson AB. All rights reserved. |
3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
39 #include "core/dom/SpaceSplitString.h" | 39 #include "core/dom/SpaceSplitString.h" |
40 #include "modules/mediastream/MediaConstraintsImpl.h" | 40 #include "modules/mediastream/MediaConstraintsImpl.h" |
41 #include "modules/mediastream/MediaStream.h" | 41 #include "modules/mediastream/MediaStream.h" |
42 #include "modules/mediastream/UserMediaController.h" | 42 #include "modules/mediastream/UserMediaController.h" |
43 #include "platform/mediastream/MediaStreamCenter.h" | 43 #include "platform/mediastream/MediaStreamCenter.h" |
44 #include "platform/mediastream/MediaStreamDescriptor.h" | 44 #include "platform/mediastream/MediaStreamDescriptor.h" |
45 | 45 |
46 namespace WebCore { | 46 namespace WebCore { |
47 | 47 |
| 48 DEFINE_GC_INFO(UserMediaRequest); |
| 49 |
48 static blink::WebMediaConstraints parseOptions(const Dictionary& options, const
String& mediaType, ExceptionState& exceptionState) | 50 static blink::WebMediaConstraints parseOptions(const Dictionary& options, const
String& mediaType, ExceptionState& exceptionState) |
49 { | 51 { |
50 blink::WebMediaConstraints constraints; | 52 blink::WebMediaConstraints constraints; |
51 | 53 |
52 Dictionary constraintsDictionary; | 54 Dictionary constraintsDictionary; |
53 bool ok = options.get(mediaType, constraintsDictionary); | 55 bool ok = options.get(mediaType, constraintsDictionary); |
54 if (ok && !constraintsDictionary.isUndefinedOrNull()) | 56 if (ok && !constraintsDictionary.isUndefinedOrNull()) |
55 constraints = MediaConstraintsImpl::create(constraintsDictionary, except
ionState); | 57 constraints = MediaConstraintsImpl::create(constraintsDictionary, except
ionState); |
56 else { | 58 else { |
57 bool mediaRequested = false; | 59 bool mediaRequested = false; |
58 options.get(mediaType, mediaRequested); | 60 options.get(mediaType, mediaRequested); |
59 if (mediaRequested) | 61 if (mediaRequested) |
60 constraints = MediaConstraintsImpl::create(); | 62 constraints = MediaConstraintsImpl::create(); |
61 } | 63 } |
62 | 64 |
63 return constraints; | 65 return constraints; |
64 } | 66 } |
65 | 67 |
66 PassRefPtr<UserMediaRequest> UserMediaRequest::create(ExecutionContext* context,
UserMediaController* controller, const Dictionary& options, PassOwnPtr<Navigato
rUserMediaSuccessCallback> successCallback, PassOwnPtr<NavigatorUserMediaErrorCa
llback> errorCallback, ExceptionState& exceptionState) | 68 PassRefPtrWillBeRawPtr<UserMediaRequest> UserMediaRequest::create(ExecutionConte
xt* context, UserMediaController* controller, const Dictionary& options, PassOwn
Ptr<NavigatorUserMediaSuccessCallback> successCallback, PassOwnPtr<NavigatorUser
MediaErrorCallback> errorCallback, ExceptionState& exceptionState) |
67 { | 69 { |
68 blink::WebMediaConstraints audio = parseOptions(options, "audio", exceptionS
tate); | 70 blink::WebMediaConstraints audio = parseOptions(options, "audio", exceptionS
tate); |
69 if (exceptionState.hadException()) | 71 if (exceptionState.hadException()) |
70 return 0; | 72 return 0; |
71 | 73 |
72 blink::WebMediaConstraints video = parseOptions(options, "video", exceptionS
tate); | 74 blink::WebMediaConstraints video = parseOptions(options, "video", exceptionS
tate); |
73 if (exceptionState.hadException()) | 75 if (exceptionState.hadException()) |
74 return 0; | 76 return 0; |
75 | 77 |
76 if (audio.isNull() && video.isNull()) | 78 if (audio.isNull() && video.isNull()) |
77 return 0; | 79 return 0; |
78 | 80 |
79 return adoptRef(new UserMediaRequest(context, controller, audio, video, succ
essCallback, errorCallback)); | 81 return adoptRefWillBeNoop(new UserMediaRequest(context, controller, audio, v
ideo, successCallback, errorCallback)); |
80 } | 82 } |
81 | 83 |
82 UserMediaRequest::UserMediaRequest(ExecutionContext* context, UserMediaControlle
r* controller, blink::WebMediaConstraints audio, blink::WebMediaConstraints vide
o, PassOwnPtr<NavigatorUserMediaSuccessCallback> successCallback, PassOwnPtr<Nav
igatorUserMediaErrorCallback> errorCallback) | 84 UserMediaRequest::UserMediaRequest(ExecutionContext* context, UserMediaControlle
r* controller, blink::WebMediaConstraints audio, blink::WebMediaConstraints vide
o, PassOwnPtr<NavigatorUserMediaSuccessCallback> successCallback, PassOwnPtr<Nav
igatorUserMediaErrorCallback> errorCallback) |
83 : ContextLifecycleObserver(context) | 85 : ContextLifecycleObserver(context) |
84 , m_audio(audio) | 86 , m_audio(audio) |
85 , m_video(video) | 87 , m_video(video) |
86 , m_controller(controller) | 88 , m_controller(controller) |
87 , m_successCallback(successCallback) | 89 , m_successCallback(successCallback) |
88 , m_errorCallback(errorCallback) | 90 , m_errorCallback(errorCallback) |
89 { | 91 { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 { | 128 { |
127 if (m_controller) | 129 if (m_controller) |
128 m_controller->requestUserMedia(this); | 130 m_controller->requestUserMedia(this); |
129 } | 131 } |
130 | 132 |
131 void UserMediaRequest::succeed(PassRefPtr<MediaStreamDescriptor> streamDescripto
r) | 133 void UserMediaRequest::succeed(PassRefPtr<MediaStreamDescriptor> streamDescripto
r) |
132 { | 134 { |
133 if (!executionContext()) | 135 if (!executionContext()) |
134 return; | 136 return; |
135 | 137 |
136 RefPtr<MediaStream> stream = MediaStream::create(executionContext(), streamD
escriptor); | 138 RefPtrWillBeRawPtr<MediaStream> stream = MediaStream::create(executionContex
t(), streamDescriptor); |
137 | 139 |
138 MediaStreamTrackVector audioTracks = stream->getAudioTracks(); | 140 MediaStreamTrackVector audioTracks = stream->getAudioTracks(); |
139 for (MediaStreamTrackVector::iterator iter = audioTracks.begin(); iter != au
dioTracks.end(); ++iter) { | 141 for (MediaStreamTrackVector::iterator iter = audioTracks.begin(); iter != au
dioTracks.end(); ++iter) { |
140 (*iter)->component()->source()->setConstraints(m_audio); | 142 (*iter)->component()->source()->setConstraints(m_audio); |
141 } | 143 } |
142 | 144 |
143 MediaStreamTrackVector videoTracks = stream->getVideoTracks(); | 145 MediaStreamTrackVector videoTracks = stream->getVideoTracks(); |
144 for (MediaStreamTrackVector::iterator iter = videoTracks.begin(); iter != vi
deoTracks.end(); ++iter) { | 146 for (MediaStreamTrackVector::iterator iter = videoTracks.begin(); iter != vi
deoTracks.end(); ++iter) { |
145 (*iter)->component()->source()->setConstraints(m_video); | 147 (*iter)->component()->source()->setConstraints(m_video); |
146 } | 148 } |
147 | 149 |
148 m_successCallback->handleEvent(stream.get()); | 150 m_successCallback->handleEvent(stream.get()); |
149 } | 151 } |
150 | 152 |
151 void UserMediaRequest::fail(const String& description) | 153 void UserMediaRequest::fail(const String& description) |
152 { | 154 { |
153 if (!executionContext()) | 155 if (!executionContext()) |
154 return; | 156 return; |
155 | 157 |
156 if (m_errorCallback) { | 158 if (m_errorCallback) { |
157 RefPtr<NavigatorUserMediaError> error = NavigatorUserMediaError::create(
NavigatorUserMediaError::NamePermissionDenied, description, String()); | 159 RefPtrWillBeRawPtr<NavigatorUserMediaError> error = NavigatorUserMediaEr
ror::create(NavigatorUserMediaError::NamePermissionDenied, description, String()
); |
158 m_errorCallback->handleEvent(error.get()); | 160 m_errorCallback->handleEvent(error.get()); |
159 } | 161 } |
160 } | 162 } |
161 | 163 |
162 void UserMediaRequest::failConstraint(const String& constraintName, const String
& description) | 164 void UserMediaRequest::failConstraint(const String& constraintName, const String
& description) |
163 { | 165 { |
164 ASSERT(!constraintName.isEmpty()); | 166 ASSERT(!constraintName.isEmpty()); |
165 if (!executionContext()) | 167 if (!executionContext()) |
166 return; | 168 return; |
167 | 169 |
168 if (m_errorCallback) { | 170 if (m_errorCallback) { |
169 RefPtr<NavigatorUserMediaError> error = NavigatorUserMediaError::create(
NavigatorUserMediaError::NameConstraintNotSatisfied, description, constraintName
); | 171 RefPtrWillBeRawPtr<NavigatorUserMediaError> error = NavigatorUserMediaEr
ror::create(NavigatorUserMediaError::NameConstraintNotSatisfied, description, co
nstraintName); |
170 m_errorCallback->handleEvent(error.get()); | 172 m_errorCallback->handleEvent(error.get()); |
171 } | 173 } |
172 } | 174 } |
173 | 175 |
174 void UserMediaRequest::contextDestroyed() | 176 void UserMediaRequest::contextDestroyed() |
175 { | 177 { |
176 RefPtr<UserMediaRequest> protect(this); | 178 RefPtrWillBeRawPtr<UserMediaRequest> protect(this); |
177 | 179 |
178 if (m_controller) { | 180 if (m_controller) { |
179 m_controller->cancelUserMediaRequest(this); | 181 m_controller->cancelUserMediaRequest(this); |
180 m_controller = 0; | 182 m_controller = 0; |
181 } | 183 } |
182 | 184 |
183 ContextLifecycleObserver::contextDestroyed(); | 185 ContextLifecycleObserver::contextDestroyed(); |
184 } | 186 } |
185 | 187 |
186 } // namespace WebCore | 188 } // namespace WebCore |
OLD | NEW |