Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: media/base/android/media_player_bridge.cc

Issue 12595005: Parsing filesystem url before giving it to media player (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase change Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/android/media_player_bridge.h ('k') | media/base/android/media_resource_getter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
13 #include "jni/MediaPlayerBridge_jni.h" 13 #include "jni/MediaPlayerBridge_jni.h"
14 #include "jni/MediaPlayer_jni.h" 14 #include "jni/MediaPlayer_jni.h"
15 #include "media/base/android/cookie_getter.h"
16 #include "media/base/android/media_player_bridge_manager.h" 15 #include "media/base/android/media_player_bridge_manager.h"
16 #include "media/base/android/media_resource_getter.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 static const int kTimeUpdateInterval = 250; 22 static const int kTimeUpdateInterval = 250;
23 23
24 // Because we create the media player lazily on android, the duration of the 24 // Because we create the media player lazily on android, the duration of the
25 // media is initially unknown to us. This makes the user unable to perform 25 // media is initially unknown to us. This makes the user unable to perform
26 // seek. To solve this problem, we use a temporary duration of 100 seconds when 26 // seek. To solve this problem, we use a temporary duration of 100 seconds when
27 // the duration is unknown. And we scale the seek position later when duration 27 // the duration is unknown. And we scale the seek position later when duration
28 // is available. 28 // is available.
29 // TODO(qinmin): create a thread and use android MediaMetadataRetriever 29 // TODO(qinmin): create a thread and use android MediaMetadataRetriever
30 // class to extract the duration. 30 // class to extract the duration.
31 static const int kTemporaryDuration = 100; 31 static const int kTemporaryDuration = 100;
32 32
33 namespace media { 33 namespace media {
34 34
35 MediaPlayerBridge::MediaPlayerBridge( 35 MediaPlayerBridge::MediaPlayerBridge(
36 int player_id, 36 int player_id,
37 const std::string& url, 37 const GURL& url,
38 const std::string& first_party_for_cookies, 38 const GURL& first_party_for_cookies,
39 CookieGetter* cookie_getter, 39 MediaResourceGetter* resource_getter,
40 bool hide_url_log, 40 bool hide_url_log,
41 MediaPlayerBridgeManager* manager, 41 MediaPlayerBridgeManager* manager,
42 const MediaErrorCB& media_error_cb, 42 const MediaErrorCB& media_error_cb,
43 const VideoSizeChangedCB& video_size_changed_cb, 43 const VideoSizeChangedCB& video_size_changed_cb,
44 const BufferingUpdateCB& buffering_update_cb, 44 const BufferingUpdateCB& buffering_update_cb,
45 const MediaPreparedCB& media_prepared_cb, 45 const MediaPreparedCB& media_prepared_cb,
46 const PlaybackCompleteCB& playback_complete_cb, 46 const PlaybackCompleteCB& playback_complete_cb,
47 const SeekCompleteCB& seek_complete_cb, 47 const SeekCompleteCB& seek_complete_cb,
48 const TimeUpdateCB& time_update_cb, 48 const TimeUpdateCB& time_update_cb,
49 const MediaInterruptedCB& media_interrupted_cb) 49 const MediaInterruptedCB& media_interrupted_cb)
50 : media_error_cb_(media_error_cb), 50 : media_error_cb_(media_error_cb),
51 video_size_changed_cb_(video_size_changed_cb), 51 video_size_changed_cb_(video_size_changed_cb),
52 buffering_update_cb_(buffering_update_cb), 52 buffering_update_cb_(buffering_update_cb),
53 media_prepared_cb_(media_prepared_cb), 53 media_prepared_cb_(media_prepared_cb),
54 playback_complete_cb_(playback_complete_cb), 54 playback_complete_cb_(playback_complete_cb),
55 seek_complete_cb_(seek_complete_cb), 55 seek_complete_cb_(seek_complete_cb),
56 media_interrupted_cb_(media_interrupted_cb), 56 media_interrupted_cb_(media_interrupted_cb),
57 time_update_cb_(time_update_cb), 57 time_update_cb_(time_update_cb),
58 player_id_(player_id), 58 player_id_(player_id),
59 prepared_(false), 59 prepared_(false),
60 pending_play_(false), 60 pending_play_(false),
61 url_(url), 61 url_(url),
62 first_party_for_cookies_(first_party_for_cookies), 62 first_party_for_cookies_(first_party_for_cookies),
63 has_cookies_(false),
64 hide_url_log_(hide_url_log), 63 hide_url_log_(hide_url_log),
65 duration_(base::TimeDelta::FromSeconds(kTemporaryDuration)), 64 duration_(base::TimeDelta::FromSeconds(kTemporaryDuration)),
66 width_(0), 65 width_(0),
67 height_(0), 66 height_(0),
68 can_pause_(true), 67 can_pause_(true),
69 can_seek_forward_(true), 68 can_seek_forward_(true),
70 can_seek_backward_(true), 69 can_seek_backward_(true),
71 manager_(manager), 70 manager_(manager),
72 cookie_getter_(cookie_getter), 71 resource_getter_(resource_getter),
73 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)), 72 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)),
74 listener_(base::MessageLoopProxy::current(), 73 listener_(base::MessageLoopProxy::current(),
75 weak_this_.GetWeakPtr()) {} 74 weak_this_.GetWeakPtr()) {
75 has_cookies_ = url_.SchemeIsFileSystem() || url_.SchemeIsFile();
76 }
76 77
77 MediaPlayerBridge::~MediaPlayerBridge() { 78 MediaPlayerBridge::~MediaPlayerBridge() {
78 Release(); 79 Release();
79 } 80 }
80 81
81 void MediaPlayerBridge::InitializePlayer() { 82 void MediaPlayerBridge::InitializePlayer() {
82 JNIEnv* env = base::android::AttachCurrentThread(); 83 JNIEnv* env = base::android::AttachCurrentThread();
83 CHECK(env); 84 CHECK(env);
84 85
85 j_media_player_.Reset(JNI_MediaPlayer::Java_MediaPlayer_Constructor(env)); 86 j_media_player_.Reset(JNI_MediaPlayer::Java_MediaPlayer_Constructor(env));
(...skipping 15 matching lines...) Expand all
101 env, j_media_player_.obj(), surface); 102 env, j_media_player_.obj(), surface);
102 } 103 }
103 104
104 void MediaPlayerBridge::Prepare() { 105 void MediaPlayerBridge::Prepare() {
105 if (j_media_player_.is_null()) 106 if (j_media_player_.is_null())
106 InitializePlayer(); 107 InitializePlayer();
107 108
108 if (has_cookies_) { 109 if (has_cookies_) {
109 GetCookiesCallback(cookies_); 110 GetCookiesCallback(cookies_);
110 } else { 111 } else {
111 cookie_getter_->GetCookies(url_, first_party_for_cookies_, base::Bind( 112 resource_getter_->GetCookies(url_, first_party_for_cookies_, base::Bind(
112 &MediaPlayerBridge::GetCookiesCallback, weak_this_.GetWeakPtr())); 113 &MediaPlayerBridge::GetCookiesCallback, weak_this_.GetWeakPtr()));
113 } 114 }
114 } 115 }
115 116
116 void MediaPlayerBridge::GetCookiesCallback(const std::string& cookies) { 117 void MediaPlayerBridge::GetCookiesCallback(const std::string& cookies) {
117 cookies_ = cookies; 118 cookies_ = cookies;
118 has_cookies_ = true; 119 has_cookies_ = true;
120
119 if (j_media_player_.is_null()) 121 if (j_media_player_.is_null())
120 return; 122 return;
121 123
124 if (url_.SchemeIsFileSystem()) {
125 resource_getter_->GetPlatformPathFromFileSystemURL(url_, base::Bind(
126 &MediaPlayerBridge::SetDataSource, weak_this_.GetWeakPtr()));
127 } else {
128 SetDataSource(url_.spec());
129 }
130 }
131
132 void MediaPlayerBridge::SetDataSource(const std::string& url) {
133 if (j_media_player_.is_null())
134 return;
135
122 JNIEnv* env = base::android::AttachCurrentThread(); 136 JNIEnv* env = base::android::AttachCurrentThread();
123 CHECK(env); 137 CHECK(env);
124 138
125 // Create a Java String for the URL. 139 // Create a Java String for the URL.
126 ScopedJavaLocalRef<jstring> j_url_string = ConvertUTF8ToJavaString(env, url_); 140 ScopedJavaLocalRef<jstring> j_url_string = ConvertUTF8ToJavaString(env, url);
127 ScopedJavaLocalRef<jstring> j_cookies = ConvertUTF8ToJavaString( 141 ScopedJavaLocalRef<jstring> j_cookies = ConvertUTF8ToJavaString(
128 env, cookies_); 142 env, cookies_);
129 143
130 jobject j_context = base::android::GetApplicationContext(); 144 jobject j_context = base::android::GetApplicationContext();
131 DCHECK(j_context); 145 DCHECK(j_context);
132 146
133 if (Java_MediaPlayerBridge_setDataSource( 147 if (Java_MediaPlayerBridge_setDataSource(
134 env, j_media_player_.obj(), j_context, j_url_string.obj(), 148 env, j_media_player_.obj(), j_context, j_url_string.obj(),
135 j_cookies.obj(), hide_url_log_)) { 149 j_cookies.obj(), hide_url_log_)) {
136 if (manager_) 150 if (manager_)
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 368
355 bool MediaPlayerBridge::RegisterMediaPlayerBridge(JNIEnv* env) { 369 bool MediaPlayerBridge::RegisterMediaPlayerBridge(JNIEnv* env) {
356 bool ret = RegisterNativesImpl(env); 370 bool ret = RegisterNativesImpl(env);
357 DCHECK(g_MediaPlayerBridge_clazz); 371 DCHECK(g_MediaPlayerBridge_clazz);
358 if (ret) 372 if (ret)
359 ret = JNI_MediaPlayer::RegisterNativesImpl(env); 373 ret = JNI_MediaPlayer::RegisterNativesImpl(env);
360 return ret; 374 return ret;
361 } 375 }
362 376
363 } // namespace media 377 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_player_bridge.h ('k') | media/base/android/media_resource_getter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698