OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <media/base/android/media_url_interceptor.h> | |
qinmin
2014/07/24 21:05:27
remote this, the file is included below
Ignacio Solla
2014/07/25 10:35:07
Done.
| |
5 #include "media/base/android/media_player_bridge.h" | 6 #include "media/base/android/media_player_bridge.h" |
6 | 7 |
7 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "jni/MediaPlayerBridge_jni.h" | 14 #include "jni/MediaPlayerBridge_jni.h" |
14 #include "media/base/android/media_player_manager.h" | 15 #include "media/base/android/media_player_manager.h" |
15 #include "media/base/android/media_resource_getter.h" | 16 #include "media/base/android/media_resource_getter.h" |
17 #include "media/base/android/media_url_interceptor.h" | |
16 | 18 |
17 using base::android::ConvertUTF8ToJavaString; | 19 using base::android::ConvertUTF8ToJavaString; |
18 using base::android::ScopedJavaLocalRef; | 20 using base::android::ScopedJavaLocalRef; |
19 | 21 |
20 // Time update happens every 250ms. | 22 // Time update happens every 250ms. |
21 const int kTimeUpdateInterval = 250; | 23 const int kTimeUpdateInterval = 250; |
22 | 24 |
23 // blob url scheme. | 25 // blob url scheme. |
24 const char kBlobScheme[] = "blob"; | 26 const char kBlobScheme[] = "blob"; |
25 | 27 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 SetDataSource(url_.spec()); | 159 SetDataSource(url_.spec()); |
158 } | 160 } |
159 | 161 |
160 void MediaPlayerBridge::SetDataSource(const std::string& url) { | 162 void MediaPlayerBridge::SetDataSource(const std::string& url) { |
161 if (j_media_player_bridge_.is_null()) | 163 if (j_media_player_bridge_.is_null()) |
162 return; | 164 return; |
163 | 165 |
164 JNIEnv* env = base::android::AttachCurrentThread(); | 166 JNIEnv* env = base::android::AttachCurrentThread(); |
165 CHECK(env); | 167 CHECK(env); |
166 | 168 |
167 // Create a Java String for the URL. | 169 media::MediaUrlInterceptor* url_interceptor = |
168 ScopedJavaLocalRef<jstring> j_url_string = ConvertUTF8ToJavaString(env, url); | 170 manager()->GetMediaUrlInterceptor(); |
169 ScopedJavaLocalRef<jstring> j_cookies = ConvertUTF8ToJavaString( | 171 int fd; |
170 env, cookies_); | 172 int64 offset; |
171 ScopedJavaLocalRef<jstring> j_user_agent = ConvertUTF8ToJavaString( | 173 int64 size; |
172 env, user_agent_); | 174 if (url_interceptor && url_interceptor->Intercept(url, &fd, &offset, &size)) { |
175 if (!Java_MediaPlayerBridge_setDataSourceFromFd( | |
mnaganov (inactive)
2014/07/25 08:17:49
I recommend initializing fd, offset and size to "i
Ignacio Solla
2014/07/25 10:35:07
Done (and moved to private method to avoid duplica
| |
176 env, j_media_player_bridge_.obj(), fd, offset, size)) { | |
177 OnMediaError(MEDIA_ERROR_FORMAT); | |
178 return; | |
179 } | |
180 } else { | |
181 // Create a Java String for the URL. | |
182 ScopedJavaLocalRef<jstring> j_url_string = | |
183 ConvertUTF8ToJavaString(env, url); | |
184 ScopedJavaLocalRef<jstring> j_cookies = ConvertUTF8ToJavaString( | |
qinmin
2014/07/24 21:05:27
j_cookies and j_user_agent declaration can be move
Ignacio Solla
2014/07/25 10:35:07
Done.
| |
185 env, cookies_); | |
186 ScopedJavaLocalRef<jstring> j_user_agent = ConvertUTF8ToJavaString( | |
187 env, user_agent_); | |
173 | 188 |
174 jobject j_context = base::android::GetApplicationContext(); | 189 jobject j_context = base::android::GetApplicationContext(); |
175 DCHECK(j_context); | 190 DCHECK(j_context); |
176 | 191 |
177 const std::string data_uri_prefix("data:"); | 192 const std::string data_uri_prefix("data:"); |
178 if (StartsWithASCII(url, data_uri_prefix, true)) { | 193 if (StartsWithASCII(url, data_uri_prefix, true)) { |
179 if (!Java_MediaPlayerBridge_setDataUriDataSource( | 194 if (!Java_MediaPlayerBridge_setDataUriDataSource( |
180 env, j_media_player_bridge_.obj(), j_context, j_url_string.obj())) { | 195 env, j_media_player_bridge_.obj(), j_context, j_url_string.obj())) { |
196 OnMediaError(MEDIA_ERROR_FORMAT); | |
197 } | |
198 return; | |
199 } | |
200 | |
201 if (!Java_MediaPlayerBridge_setDataSource( | |
202 env, j_media_player_bridge_.obj(), j_context, j_url_string.obj(), | |
203 j_cookies.obj(), j_user_agent.obj(), hide_url_log_)) { | |
181 OnMediaError(MEDIA_ERROR_FORMAT); | 204 OnMediaError(MEDIA_ERROR_FORMAT); |
205 return; | |
182 } | 206 } |
183 return; | |
184 } | |
185 | |
186 if (!Java_MediaPlayerBridge_setDataSource( | |
187 env, j_media_player_bridge_.obj(), j_context, j_url_string.obj(), | |
188 j_cookies.obj(), j_user_agent.obj(), hide_url_log_)) { | |
189 OnMediaError(MEDIA_ERROR_FORMAT); | |
190 return; | |
191 } | 207 } |
192 | 208 |
193 request_media_resources_cb_.Run(player_id()); | 209 request_media_resources_cb_.Run(player_id()); |
194 if (!Java_MediaPlayerBridge_prepareAsync(env, j_media_player_bridge_.obj())) | 210 if (!Java_MediaPlayerBridge_prepareAsync(env, j_media_player_bridge_.obj())) |
195 OnMediaError(MEDIA_ERROR_FORMAT); | 211 OnMediaError(MEDIA_ERROR_FORMAT); |
196 } | 212 } |
197 | 213 |
198 void MediaPlayerBridge::OnDidSetDataUriDataSource(JNIEnv* env, jobject obj, | 214 void MediaPlayerBridge::OnDidSetDataUriDataSource(JNIEnv* env, jobject obj, |
199 jboolean success) { | 215 jboolean success) { |
200 if (!success) { | 216 if (!success) { |
(...skipping 20 matching lines...) Expand all Loading... | |
221 if (!username.empty()) { | 237 if (!username.empty()) { |
222 replacements.SetUsernameStr(username); | 238 replacements.SetUsernameStr(username); |
223 if (!password.empty()) | 239 if (!password.empty()) |
224 replacements.SetPasswordStr(password); | 240 replacements.SetPasswordStr(password); |
225 url_ = url_.ReplaceComponents(replacements); | 241 url_ = url_.ReplaceComponents(replacements); |
226 } | 242 } |
227 ExtractMediaMetadata(url_.spec()); | 243 ExtractMediaMetadata(url_.spec()); |
228 } | 244 } |
229 | 245 |
230 void MediaPlayerBridge::ExtractMediaMetadata(const std::string& url) { | 246 void MediaPlayerBridge::ExtractMediaMetadata(const std::string& url) { |
231 manager()->GetMediaResourceGetter()->ExtractMediaMetadata( | 247 media::MediaUrlInterceptor* url_interceptor = |
232 url, | 248 manager()->GetMediaUrlInterceptor(); |
233 cookies_, | 249 int fd; |
234 user_agent_, | 250 int64 offset; |
235 base::Bind(&MediaPlayerBridge::OnMediaMetadataExtracted, | 251 int64 size; |
236 weak_factory_.GetWeakPtr())); | 252 if (url_interceptor && url_interceptor->Intercept(url, &fd, &offset, &size)) { |
253 manager()->GetMediaResourceGetter()->ExtractMediaMetadata( | |
254 fd, offset, size, | |
mnaganov (inactive)
2014/07/25 08:17:49
nit: 'ExtractMediaMetadata' arguments alignment is
Ignacio Solla
2014/07/25 10:35:07
Done.
| |
255 base::Bind(&MediaPlayerBridge::OnMediaMetadataExtracted, | |
256 weak_factory_.GetWeakPtr())); | |
257 } else { | |
258 manager()->GetMediaResourceGetter()->ExtractMediaMetadata( | |
259 url, cookies_, user_agent_, | |
260 base::Bind(&MediaPlayerBridge::OnMediaMetadataExtracted, | |
261 weak_factory_.GetWeakPtr())); | |
262 } | |
237 } | 263 } |
238 | 264 |
239 void MediaPlayerBridge::OnMediaMetadataExtracted( | 265 void MediaPlayerBridge::OnMediaMetadataExtracted( |
240 base::TimeDelta duration, int width, int height, bool success) { | 266 base::TimeDelta duration, int width, int height, bool success) { |
241 if (success) { | 267 if (success) { |
242 duration_ = duration; | 268 duration_ = duration; |
243 width_ = width; | 269 width_ = width; |
244 height_ = height; | 270 height_ = height; |
245 } | 271 } |
246 manager()->OnMediaMetadataChanged( | 272 manager()->OnMediaMetadataChanged( |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 | 522 |
497 GURL MediaPlayerBridge::GetFirstPartyForCookies() { | 523 GURL MediaPlayerBridge::GetFirstPartyForCookies() { |
498 return first_party_for_cookies_; | 524 return first_party_for_cookies_; |
499 } | 525 } |
500 | 526 |
501 bool MediaPlayerBridge::IsSurfaceInUse() const { | 527 bool MediaPlayerBridge::IsSurfaceInUse() const { |
502 return is_surface_in_use_; | 528 return is_surface_in_use_; |
503 } | 529 } |
504 | 530 |
505 } // namespace media | 531 } // namespace media |
OLD | NEW |