Commit ee85a118 authored by amogh.bihani's avatar amogh.bihani Committed by Commit bot

Updating buffered duration of local resource in android

OnBufferingUpdate does not work for local resources. Because of this
the buffered range does not get updated. This patch updates the bufferd
range atleast untill the video has played so that media controls can be
painted properly.

TBR=abarth@chromium.org
BUG=405474

Review URL: https://codereview.chromium.org/496683002

Cr-Commit-Position: refs/heads/master@{#292837}
parent dd5a6c66
...@@ -147,6 +147,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( ...@@ -147,6 +147,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid(
media_log_(media_log), media_log_(media_log),
web_cdm_(NULL), web_cdm_(NULL),
allow_stored_credentials_(false), allow_stored_credentials_(false),
is_local_resource_(false),
weak_factory_(this) { weak_factory_(this) {
DCHECK(player_manager_); DCHECK(player_manager_);
DCHECK(cdm_manager_); DCHECK(cdm_manager_);
...@@ -217,6 +218,7 @@ void WebMediaPlayerAndroid::load(LoadType load_type, ...@@ -217,6 +218,7 @@ void WebMediaPlayerAndroid::load(LoadType load_type,
} }
url_ = url; url_ = url;
is_local_resource_ = IsLocalResource();
int demuxer_client_id = 0; int demuxer_client_id = 0;
if (player_type_ != MEDIA_PLAYER_TYPE_URL) { if (player_type_ != MEDIA_PLAYER_TYPE_URL) {
RendererDemuxerAndroid* demuxer = RendererDemuxerAndroid* demuxer =
...@@ -280,6 +282,19 @@ void WebMediaPlayerAndroid::DidLoadMediaInfo( ...@@ -280,6 +282,19 @@ void WebMediaPlayerAndroid::DidLoadMediaInfo(
UpdateNetworkState(WebMediaPlayer::NetworkStateIdle); UpdateNetworkState(WebMediaPlayer::NetworkStateIdle);
} }
bool WebMediaPlayerAndroid::IsLocalResource() {
if (url_.SchemeIsFile() || url_.SchemeIsBlob())
return true;
std::string host = url_.host();
if (!host.compare("localhost") || !host.compare("127.0.0.1") ||
!host.compare("[::1]")) {
return true;
}
return false;
}
void WebMediaPlayerAndroid::play() { void WebMediaPlayerAndroid::play() {
DCHECK(main_thread_checker_.CalledOnValidThread()); DCHECK(main_thread_checker_.CalledOnValidThread());
...@@ -693,7 +708,7 @@ void WebMediaPlayerAndroid::OnMediaMetadataChanged( ...@@ -693,7 +708,7 @@ void WebMediaPlayerAndroid::OnMediaMetadataChanged(
DCHECK(main_thread_checker_.CalledOnValidThread()); DCHECK(main_thread_checker_.CalledOnValidThread());
bool need_to_signal_duration_changed = false; bool need_to_signal_duration_changed = false;
if (url_.SchemeIs("file")) if (is_local_resource_)
UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded);
// Update duration, if necessary, prior to ready state updates that may // Update duration, if necessary, prior to ready state updates that may
...@@ -851,6 +866,8 @@ void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) { ...@@ -851,6 +866,8 @@ void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) {
void WebMediaPlayerAndroid::OnTimeUpdate(const base::TimeDelta& current_time) { void WebMediaPlayerAndroid::OnTimeUpdate(const base::TimeDelta& current_time) {
DCHECK(main_thread_checker_.CalledOnValidThread()); DCHECK(main_thread_checker_.CalledOnValidThread());
current_time_ = current_time.InSecondsF(); current_time_ = current_time.InSecondsF();
if (is_local_resource_ && current_time_ <= duration())
buffered_[0].end = current_time_;
} }
void WebMediaPlayerAndroid::OnConnectedToRemoteDevice( void WebMediaPlayerAndroid::OnConnectedToRemoteDevice(
......
...@@ -287,6 +287,7 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer, ...@@ -287,6 +287,7 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer,
const GURL& first_party_for_cookies, const GURL& first_party_for_cookies,
bool allow_stored_credentials); bool allow_stored_credentials);
bool IsKeySystemSupported(const std::string& key_system); bool IsKeySystemSupported(const std::string& key_system);
bool IsLocalResource();
// Actually do the work for generateKeyRequest/addKey so they can easily // Actually do the work for generateKeyRequest/addKey so they can easily
// report results to UMA. // report results to UMA.
...@@ -489,6 +490,9 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer, ...@@ -489,6 +490,9 @@ class WebMediaPlayerAndroid : public blink::WebMediaPlayer,
// Whether stored credentials are allowed to be passed to the server. // Whether stored credentials are allowed to be passed to the server.
bool allow_stored_credentials_; bool allow_stored_credentials_;
// Whether the resource is local.
bool is_local_resource_;
// NOTE: Weak pointers must be invalidated before all other member variables. // NOTE: Weak pointers must be invalidated before all other member variables.
base::WeakPtrFactory<WebMediaPlayerAndroid> weak_factory_; base::WeakPtrFactory<WebMediaPlayerAndroid> weak_factory_;
......
...@@ -21,9 +21,6 @@ using base::android::ScopedJavaLocalRef; ...@@ -21,9 +21,6 @@ using base::android::ScopedJavaLocalRef;
// Time update happens every 250ms. // Time update happens every 250ms.
const int kTimeUpdateInterval = 250; const int kTimeUpdateInterval = 250;
// blob url scheme.
const char kBlobScheme[] = "blob";
namespace media { namespace media {
MediaPlayerBridge::MediaPlayerBridge( MediaPlayerBridge::MediaPlayerBridge(
...@@ -79,7 +76,7 @@ void MediaPlayerBridge::Initialize() { ...@@ -79,7 +76,7 @@ void MediaPlayerBridge::Initialize() {
media::MediaResourceGetter* resource_getter = media::MediaResourceGetter* resource_getter =
manager()->GetMediaResourceGetter(); manager()->GetMediaResourceGetter();
if (url_.SchemeIsFileSystem() || url_.SchemeIs(kBlobScheme)) { if (url_.SchemeIsFileSystem() || url_.SchemeIsBlob()) {
resource_getter->GetPlatformPathFromURL( resource_getter->GetPlatformPathFromURL(
url_, url_,
base::Bind(&MediaPlayerBridge::ExtractMediaMetadata, base::Bind(&MediaPlayerBridge::ExtractMediaMetadata,
...@@ -156,7 +153,7 @@ void MediaPlayerBridge::SetVideoSurface(gfx::ScopedJavaSurface surface) { ...@@ -156,7 +153,7 @@ void MediaPlayerBridge::SetVideoSurface(gfx::ScopedJavaSurface surface) {
void MediaPlayerBridge::Prepare() { void MediaPlayerBridge::Prepare() {
DCHECK(j_media_player_bridge_.is_null()); DCHECK(j_media_player_bridge_.is_null());
CreateJavaMediaPlayerBridge(); CreateJavaMediaPlayerBridge();
if (url_.SchemeIsFileSystem() || url_.SchemeIs(kBlobScheme)) { if (url_.SchemeIsFileSystem() || url_.SchemeIsBlob()) {
manager()->GetMediaResourceGetter()->GetPlatformPathFromURL( manager()->GetMediaResourceGetter()->GetPlatformPathFromURL(
url_, url_,
base::Bind(&MediaPlayerBridge::SetDataSource, base::Bind(&MediaPlayerBridge::SetDataSource,
......
...@@ -236,6 +236,11 @@ class URL_EXPORT GURL { ...@@ -236,6 +236,11 @@ class URL_EXPORT GURL {
(SchemeIsFileSystem() && inner_url() && inner_url()->SchemeIsSecure()); (SchemeIsFileSystem() && inner_url() && inner_url()->SchemeIsSecure());
} }
// Returns true if the scheme is "blob".
bool SchemeIsBlob() const {
return SchemeIs(url::kBlobScheme);
}
// The "content" of the URL is everything after the scheme (skipping the // The "content" of the URL is everything after the scheme (skipping the
// scheme delimiting colon). It is an error to get the origin of an invalid // scheme delimiting colon). It is an error to get the origin of an invalid
// URL. The result will be an empty string. // URL. The result will be an empty string.
......
...@@ -635,4 +635,10 @@ TEST(GURLTest, SchemeIsWSOrWSS) { ...@@ -635,4 +635,10 @@ TEST(GURLTest, SchemeIsWSOrWSS) {
EXPECT_FALSE(GURL("http://bar/").SchemeIsWSOrWSS()); EXPECT_FALSE(GURL("http://bar/").SchemeIsWSOrWSS());
} }
TEST(GURLTest, SchemeIsBlob) {
EXPECT_TRUE(GURL("BLOB://BAR/").SchemeIsBlob());
EXPECT_TRUE(GURL("blob://bar/").SchemeIsBlob());
EXPECT_FALSE(GURL("http://bar/").SchemeIsBlob());
}
} // namespace url } // namespace url
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment