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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/android/context_utils.h" | 9 #include "base/android/context_utils.h" |
10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/android/scoped_java_ref.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
15 #include "jni/MediaPlayerBridge_jni.h" | 16 #include "jni/MediaPlayerBridge_jni.h" |
16 #include "media/base/android/media_common_android.h" | 17 #include "media/base/android/media_common_android.h" |
17 #include "media/base/android/media_player_manager.h" | 18 #include "media/base/android/media_player_manager.h" |
18 #include "media/base/android/media_resource_getter.h" | 19 #include "media/base/android/media_resource_getter.h" |
19 #include "media/base/android/media_url_interceptor.h" | 20 #include "media/base/android/media_url_interceptor.h" |
20 #include "media/base/timestamp_constants.h" | 21 #include "media/base/timestamp_constants.h" |
21 | 22 |
22 using base::android::ConvertUTF8ToJavaString; | 23 using base::android::ConvertUTF8ToJavaString; |
23 using base::android::JavaParamRef; | 24 using base::android::JavaParamRef; |
| 25 using base::android::JavaRef; |
24 using base::android::ScopedJavaLocalRef; | 26 using base::android::ScopedJavaLocalRef; |
25 | 27 |
26 namespace media { | 28 namespace media { |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 enum UMAExitStatus { | 32 enum UMAExitStatus { |
31 UMA_EXIT_SUCCESS = 0, | 33 UMA_EXIT_SUCCESS = 0, |
32 UMA_EXIT_ERROR, | 34 UMA_EXIT_ERROR, |
33 UMA_EXIT_STATUS_MAX = UMA_EXIT_ERROR, | 35 UMA_EXIT_STATUS_MAX = UMA_EXIT_ERROR, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 118 |
117 void MediaPlayerBridge::CreateJavaMediaPlayerBridge() { | 119 void MediaPlayerBridge::CreateJavaMediaPlayerBridge() { |
118 JNIEnv* env = base::android::AttachCurrentThread(); | 120 JNIEnv* env = base::android::AttachCurrentThread(); |
119 CHECK(env); | 121 CHECK(env); |
120 | 122 |
121 j_media_player_bridge_.Reset(Java_MediaPlayerBridge_create( | 123 j_media_player_bridge_.Reset(Java_MediaPlayerBridge_create( |
122 env, reinterpret_cast<intptr_t>(this))); | 124 env, reinterpret_cast<intptr_t>(this))); |
123 | 125 |
124 UpdateEffectiveVolume(); | 126 UpdateEffectiveVolume(); |
125 | 127 |
126 AttachListener(j_media_player_bridge_.obj()); | 128 AttachListener(j_media_player_bridge_); |
127 } | 129 } |
128 | 130 |
129 void MediaPlayerBridge::SetDuration(base::TimeDelta duration) { | 131 void MediaPlayerBridge::SetDuration(base::TimeDelta duration) { |
130 duration_ = duration; | 132 duration_ = duration; |
131 } | 133 } |
132 | 134 |
133 void MediaPlayerBridge::SetVideoSurface(gl::ScopedJavaSurface surface) { | 135 void MediaPlayerBridge::SetVideoSurface(gl::ScopedJavaSurface surface) { |
134 surface_ = std::move(surface); | 136 surface_ = std::move(surface); |
135 | 137 |
136 if (j_media_player_bridge_.is_null()) | 138 if (j_media_player_bridge_.is_null()) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 if (!Java_MediaPlayerBridge_setDataSourceFromFd( | 173 if (!Java_MediaPlayerBridge_setDataSourceFromFd( |
172 env, j_media_player_bridge_.obj(), fd, offset, size)) { | 174 env, j_media_player_bridge_.obj(), fd, offset, size)) { |
173 OnMediaError(MEDIA_ERROR_FORMAT); | 175 OnMediaError(MEDIA_ERROR_FORMAT); |
174 return; | 176 return; |
175 } | 177 } |
176 } else { | 178 } else { |
177 // Create a Java String for the URL. | 179 // Create a Java String for the URL. |
178 ScopedJavaLocalRef<jstring> j_url_string = | 180 ScopedJavaLocalRef<jstring> j_url_string = |
179 ConvertUTF8ToJavaString(env, url); | 181 ConvertUTF8ToJavaString(env, url); |
180 | 182 |
181 jobject j_context = base::android::GetApplicationContext(); | 183 const JavaRef<jobject>& j_context = base::android::GetApplicationContext(); |
182 DCHECK(j_context); | |
183 | 184 |
184 const std::string data_uri_prefix("data:"); | 185 const std::string data_uri_prefix("data:"); |
185 if (base::StartsWith(url, data_uri_prefix, base::CompareCase::SENSITIVE)) { | 186 if (base::StartsWith(url, data_uri_prefix, base::CompareCase::SENSITIVE)) { |
186 if (!Java_MediaPlayerBridge_setDataUriDataSource( | 187 if (!Java_MediaPlayerBridge_setDataUriDataSource( |
187 env, j_media_player_bridge_.obj(), j_context, j_url_string.obj())) { | 188 env, j_media_player_bridge_.obj(), j_context, j_url_string.obj())) { |
188 OnMediaError(MEDIA_ERROR_FORMAT); | 189 OnMediaError(MEDIA_ERROR_FORMAT); |
189 } | 190 } |
190 return; | 191 return; |
191 } | 192 } |
192 | 193 |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 | 600 |
600 GURL MediaPlayerBridge::GetUrl() { | 601 GURL MediaPlayerBridge::GetUrl() { |
601 return url_; | 602 return url_; |
602 } | 603 } |
603 | 604 |
604 GURL MediaPlayerBridge::GetFirstPartyForCookies() { | 605 GURL MediaPlayerBridge::GetFirstPartyForCookies() { |
605 return first_party_for_cookies_; | 606 return first_party_for_cookies_; |
606 } | 607 } |
607 | 608 |
608 } // namespace media | 609 } // namespace media |
OLD | NEW |