| 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 | 16 |
| 17 using base::android::ConvertUTF8ToJavaString; | 17 using base::android::ConvertUTF8ToJavaString; |
| 18 using base::android::ScopedJavaLocalRef; | 18 using base::android::ScopedJavaLocalRef; |
| 19 | 19 |
| 20 // Time update happens every 250ms. | 20 // Time update happens every 250ms. |
| 21 static const int kTimeUpdateInterval = 250; | 21 const int kTimeUpdateInterval = 250; |
| 22 |
| 23 // blob url scheme. |
| 24 const char kBlobScheme[] = "blob"; |
| 22 | 25 |
| 23 namespace media { | 26 namespace media { |
| 24 | 27 |
| 25 MediaPlayerBridge::MediaPlayerBridge( | 28 MediaPlayerBridge::MediaPlayerBridge( |
| 26 int player_id, | 29 int player_id, |
| 27 const GURL& url, | 30 const GURL& url, |
| 28 const GURL& first_party_for_cookies, | 31 const GURL& first_party_for_cookies, |
| 29 const std::string& user_agent, | 32 const std::string& user_agent, |
| 30 bool hide_url_log, | 33 bool hide_url_log, |
| 31 MediaPlayerManager* manager) | 34 MediaPlayerManager* manager) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 49 MediaPlayerBridge::~MediaPlayerBridge() { | 52 MediaPlayerBridge::~MediaPlayerBridge() { |
| 50 if (!j_media_player_bridge_.is_null()) { | 53 if (!j_media_player_bridge_.is_null()) { |
| 51 JNIEnv* env = base::android::AttachCurrentThread(); | 54 JNIEnv* env = base::android::AttachCurrentThread(); |
| 52 CHECK(env); | 55 CHECK(env); |
| 53 Java_MediaPlayerBridge_destroy(env, j_media_player_bridge_.obj()); | 56 Java_MediaPlayerBridge_destroy(env, j_media_player_bridge_.obj()); |
| 54 } | 57 } |
| 55 Release(); | 58 Release(); |
| 56 } | 59 } |
| 57 | 60 |
| 58 void MediaPlayerBridge::Initialize() { | 61 void MediaPlayerBridge::Initialize() { |
| 62 cookies_.clear(); |
| 59 if (url_.SchemeIsFile()) { | 63 if (url_.SchemeIsFile()) { |
| 60 cookies_.clear(); | |
| 61 ExtractMediaMetadata(url_.spec()); | 64 ExtractMediaMetadata(url_.spec()); |
| 62 return; | 65 return; |
| 63 } | 66 } |
| 64 | 67 |
| 65 media::MediaResourceGetter* resource_getter = | 68 media::MediaResourceGetter* resource_getter = |
| 66 manager()->GetMediaResourceGetter(); | 69 manager()->GetMediaResourceGetter(); |
| 67 if (url_.SchemeIsFileSystem()) { | 70 if (url_.SchemeIsFileSystem() || url_.SchemeIs(kBlobScheme)) { |
| 68 cookies_.clear(); | 71 resource_getter->GetPlatformPathFromURL(url_, base::Bind( |
| 69 resource_getter->GetPlatformPathFromFileSystemURL(url_, base::Bind( | |
| 70 &MediaPlayerBridge::ExtractMediaMetadata, weak_this_.GetWeakPtr())); | 72 &MediaPlayerBridge::ExtractMediaMetadata, weak_this_.GetWeakPtr())); |
| 71 return; | 73 return; |
| 72 } | 74 } |
| 73 | 75 |
| 74 resource_getter->GetCookies(url_, first_party_for_cookies_, base::Bind( | 76 resource_getter->GetCookies(url_, first_party_for_cookies_, base::Bind( |
| 75 &MediaPlayerBridge::OnCookiesRetrieved, weak_this_.GetWeakPtr())); | 77 &MediaPlayerBridge::OnCookiesRetrieved, weak_this_.GetWeakPtr())); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void MediaPlayerBridge::CreateJavaMediaPlayerBridge() { | 80 void MediaPlayerBridge::CreateJavaMediaPlayerBridge() { |
| 79 JNIEnv* env = base::android::AttachCurrentThread(); | 81 JNIEnv* env = base::android::AttachCurrentThread(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 JNIEnv* env = base::android::AttachCurrentThread(); | 123 JNIEnv* env = base::android::AttachCurrentThread(); |
| 122 CHECK(env); | 124 CHECK(env); |
| 123 | 125 |
| 124 Java_MediaPlayerBridge_setSurface( | 126 Java_MediaPlayerBridge_setSurface( |
| 125 env, j_media_player_bridge_.obj(), surface.j_surface().obj()); | 127 env, j_media_player_bridge_.obj(), surface.j_surface().obj()); |
| 126 } | 128 } |
| 127 | 129 |
| 128 void MediaPlayerBridge::Prepare() { | 130 void MediaPlayerBridge::Prepare() { |
| 129 DCHECK(j_media_player_bridge_.is_null()); | 131 DCHECK(j_media_player_bridge_.is_null()); |
| 130 CreateJavaMediaPlayerBridge(); | 132 CreateJavaMediaPlayerBridge(); |
| 131 if (url_.SchemeIsFileSystem()) { | 133 if (url_.SchemeIsFileSystem() || url_.SchemeIs(kBlobScheme)) { |
| 132 manager()->GetMediaResourceGetter()->GetPlatformPathFromFileSystemURL( | 134 manager()->GetMediaResourceGetter()->GetPlatformPathFromURL( |
| 133 url_, base::Bind(&MediaPlayerBridge::SetDataSource, | 135 url_, base::Bind(&MediaPlayerBridge::SetDataSource, |
| 134 weak_this_.GetWeakPtr())); | 136 weak_this_.GetWeakPtr())); |
| 135 } else { | 137 return; |
| 136 SetDataSource(url_.spec()); | |
| 137 } | 138 } |
| 139 |
| 140 SetDataSource(url_.spec()); |
| 138 } | 141 } |
| 139 | 142 |
| 140 void MediaPlayerBridge::SetDataSource(const std::string& url) { | 143 void MediaPlayerBridge::SetDataSource(const std::string& url) { |
| 141 if (j_media_player_bridge_.is_null()) | 144 if (j_media_player_bridge_.is_null()) |
| 142 return; | 145 return; |
| 143 | 146 |
| 144 JNIEnv* env = base::android::AttachCurrentThread(); | 147 JNIEnv* env = base::android::AttachCurrentThread(); |
| 145 CHECK(env); | 148 CHECK(env); |
| 146 | 149 |
| 147 // Create a Java String for the URL. | 150 // Create a Java String for the URL. |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 | 456 |
| 454 GURL MediaPlayerBridge::GetUrl() { | 457 GURL MediaPlayerBridge::GetUrl() { |
| 455 return url_; | 458 return url_; |
| 456 } | 459 } |
| 457 | 460 |
| 458 GURL MediaPlayerBridge::GetFirstPartyForCookies() { | 461 GURL MediaPlayerBridge::GetFirstPartyForCookies() { |
| 459 return first_party_for_cookies_; | 462 return first_party_for_cookies_; |
| 460 } | 463 } |
| 461 | 464 |
| 462 } // namespace media | 465 } // namespace media |
| OLD | NEW |