| 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_player_bridge.h" | 5 #include "media/base/android/media_player_bridge.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "jni/MediaPlayerBridge_jni.h" | 13 #include "jni/MediaPlayerBridge_jni.h" |
| 14 #include "media/base/android/media_player_manager.h" | 14 #include "media/base/android/media_player_manager.h" |
| 15 #include "media/base/android/media_resource_getter.h" | 15 #include "media/base/android/media_resource_getter.h" |
| 16 #include "media/base/android/media_url_interceptor.h" | 16 #include "media/base/android/media_url_interceptor.h" |
| 17 | 17 |
| 18 using base::android::ConvertUTF8ToJavaString; | 18 using base::android::ConvertUTF8ToJavaString; |
| 19 using base::android::ScopedJavaLocalRef; | 19 using base::android::ScopedJavaLocalRef; |
| 20 | 20 |
| 21 // Time update happens every 250ms. | 21 // Time update happens every 250ms. |
| 22 const int kTimeUpdateInterval = 250; | 22 const int kTimeUpdateInterval = 250; |
| 23 | 23 |
| 24 // blob url scheme. | |
| 25 const char kBlobScheme[] = "blob"; | |
| 26 | |
| 27 namespace media { | 24 namespace media { |
| 28 | 25 |
| 29 MediaPlayerBridge::MediaPlayerBridge( | 26 MediaPlayerBridge::MediaPlayerBridge( |
| 30 int player_id, | 27 int player_id, |
| 31 const GURL& url, | 28 const GURL& url, |
| 32 const GURL& first_party_for_cookies, | 29 const GURL& first_party_for_cookies, |
| 33 const std::string& user_agent, | 30 const std::string& user_agent, |
| 34 bool hide_url_log, | 31 bool hide_url_log, |
| 35 MediaPlayerManager* manager, | 32 MediaPlayerManager* manager, |
| 36 const RequestMediaResourcesCB& request_media_resources_cb, | 33 const RequestMediaResourcesCB& request_media_resources_cb, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 69 |
| 73 void MediaPlayerBridge::Initialize() { | 70 void MediaPlayerBridge::Initialize() { |
| 74 cookies_.clear(); | 71 cookies_.clear(); |
| 75 if (url_.SchemeIsFile()) { | 72 if (url_.SchemeIsFile()) { |
| 76 ExtractMediaMetadata(url_.spec()); | 73 ExtractMediaMetadata(url_.spec()); |
| 77 return; | 74 return; |
| 78 } | 75 } |
| 79 | 76 |
| 80 media::MediaResourceGetter* resource_getter = | 77 media::MediaResourceGetter* resource_getter = |
| 81 manager()->GetMediaResourceGetter(); | 78 manager()->GetMediaResourceGetter(); |
| 82 if (url_.SchemeIsFileSystem() || url_.SchemeIs(kBlobScheme)) { | 79 if (url_.SchemeIsFileSystem() || url_.SchemeIsBlob()) { |
| 83 resource_getter->GetPlatformPathFromURL( | 80 resource_getter->GetPlatformPathFromURL( |
| 84 url_, | 81 url_, |
| 85 base::Bind(&MediaPlayerBridge::ExtractMediaMetadata, | 82 base::Bind(&MediaPlayerBridge::ExtractMediaMetadata, |
| 86 weak_factory_.GetWeakPtr())); | 83 weak_factory_.GetWeakPtr())); |
| 87 return; | 84 return; |
| 88 } | 85 } |
| 89 | 86 |
| 90 // Start extracting the metadata immediately if the request is anonymous. | 87 // Start extracting the metadata immediately if the request is anonymous. |
| 91 // Otherwise, wait for user credentials to be retrieved first. | 88 // Otherwise, wait for user credentials to be retrieved first. |
| 92 if (!allow_credentials_) { | 89 if (!allow_credentials_) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 JNIEnv* env = base::android::AttachCurrentThread(); | 146 JNIEnv* env = base::android::AttachCurrentThread(); |
| 150 CHECK(env); | 147 CHECK(env); |
| 151 is_surface_in_use_ = true; | 148 is_surface_in_use_ = true; |
| 152 Java_MediaPlayerBridge_setSurface( | 149 Java_MediaPlayerBridge_setSurface( |
| 153 env, j_media_player_bridge_.obj(), surface.j_surface().obj()); | 150 env, j_media_player_bridge_.obj(), surface.j_surface().obj()); |
| 154 } | 151 } |
| 155 | 152 |
| 156 void MediaPlayerBridge::Prepare() { | 153 void MediaPlayerBridge::Prepare() { |
| 157 DCHECK(j_media_player_bridge_.is_null()); | 154 DCHECK(j_media_player_bridge_.is_null()); |
| 158 CreateJavaMediaPlayerBridge(); | 155 CreateJavaMediaPlayerBridge(); |
| 159 if (url_.SchemeIsFileSystem() || url_.SchemeIs(kBlobScheme)) { | 156 if (url_.SchemeIsFileSystem() || url_.SchemeIsBlob()) { |
| 160 manager()->GetMediaResourceGetter()->GetPlatformPathFromURL( | 157 manager()->GetMediaResourceGetter()->GetPlatformPathFromURL( |
| 161 url_, | 158 url_, |
| 162 base::Bind(&MediaPlayerBridge::SetDataSource, | 159 base::Bind(&MediaPlayerBridge::SetDataSource, |
| 163 weak_factory_.GetWeakPtr())); | 160 weak_factory_.GetWeakPtr())); |
| 164 return; | 161 return; |
| 165 } | 162 } |
| 166 | 163 |
| 167 SetDataSource(url_.spec()); | 164 SetDataSource(url_.spec()); |
| 168 } | 165 } |
| 169 | 166 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 | 543 |
| 547 GURL MediaPlayerBridge::GetFirstPartyForCookies() { | 544 GURL MediaPlayerBridge::GetFirstPartyForCookies() { |
| 548 return first_party_for_cookies_; | 545 return first_party_for_cookies_; |
| 549 } | 546 } |
| 550 | 547 |
| 551 bool MediaPlayerBridge::IsSurfaceInUse() const { | 548 bool MediaPlayerBridge::IsSurfaceInUse() const { |
| 552 return is_surface_in_use_; | 549 return is_surface_in_use_; |
| 553 } | 550 } |
| 554 | 551 |
| 555 } // namespace media | 552 } // namespace media |
| OLD | NEW |