| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/media/android/webmediaplayer_android.h" | 5 #include "content/renderer/media/android/webmediaplayer_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight); | 138 SkImageInfo info = SkImageInfo::MakeN32Premul(desc.fWidth, desc.fHeight); |
| 139 SkGrPixelRef* pixel_ref = new SkGrPixelRef(info, texture.get()); | 139 SkGrPixelRef* pixel_ref = new SkGrPixelRef(info, texture.get()); |
| 140 if (!pixel_ref) | 140 if (!pixel_ref) |
| 141 return false; | 141 return false; |
| 142 bitmap->setInfo(info); | 142 bitmap->setInfo(info); |
| 143 bitmap->setPixelRef(pixel_ref)->unref(); | 143 bitmap->setPixelRef(pixel_ref)->unref(); |
| 144 return true; | 144 return true; |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool IsSuspendResumeEnabled() { |
| 148 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 149 switches::kDisableMediaSuspend); |
| 150 } |
| 151 |
| 147 class SyncTokenClientImpl : public media::VideoFrame::SyncTokenClient { | 152 class SyncTokenClientImpl : public media::VideoFrame::SyncTokenClient { |
| 148 public: | 153 public: |
| 149 explicit SyncTokenClientImpl( | 154 explicit SyncTokenClientImpl( |
| 150 blink::WebGraphicsContext3D* web_graphics_context) | 155 blink::WebGraphicsContext3D* web_graphics_context) |
| 151 : web_graphics_context_(web_graphics_context) {} | 156 : web_graphics_context_(web_graphics_context) {} |
| 152 ~SyncTokenClientImpl() override {} | 157 ~SyncTokenClientImpl() override {} |
| 153 void GenerateSyncToken(gpu::SyncToken* sync_token) override { | 158 void GenerateSyncToken(gpu::SyncToken* sync_token) override { |
| 154 const blink::WGC3Duint64 fence_sync = | 159 const blink::WGC3Duint64 fence_sync = |
| 155 web_graphics_context_->insertFenceSyncCHROMIUM(); | 160 web_graphics_context_->insertFenceSyncCHROMIUM(); |
| 156 web_graphics_context_->shallowFlushCHROMIUM(); | 161 web_graphics_context_->shallowFlushCHROMIUM(); |
| (...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1506 | 1511 |
| 1507 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { | 1512 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { |
| 1508 encrypted_client_->didBlockPlaybackWaitingForKey(); | 1513 encrypted_client_->didBlockPlaybackWaitingForKey(); |
| 1509 | 1514 |
| 1510 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called | 1515 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
| 1511 // when a key has been successfully added (e.g. OnSessionKeysChange() with | 1516 // when a key has been successfully added (e.g. OnSessionKeysChange() with |
| 1512 // |has_additional_usable_key| = true). http://crbug.com/461903 | 1517 // |has_additional_usable_key| = true). http://crbug.com/461903 |
| 1513 encrypted_client_->didResumePlaybackBlockedForKey(); | 1518 encrypted_client_->didResumePlaybackBlockedForKey(); |
| 1514 } | 1519 } |
| 1515 | 1520 |
| 1516 void WebMediaPlayerAndroid::OnHidden(bool must_suspend) { | 1521 void WebMediaPlayerAndroid::OnHidden() { |
| 1517 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1522 if (!IsSuspendResumeEnabled()) |
| 1518 switches::kDisableMediaSuspend)) { | |
| 1519 return; | 1523 return; |
| 1520 } | |
| 1521 | 1524 |
| 1522 // If we're idle or playing video, pause and release resources; audio only | 1525 // If we're idle or playing video, pause and release resources; audio only |
| 1523 // players are allowed to continue playing in the background unless indicated | 1526 // players are allowed to continue playing in the background unless indicated |
| 1524 // otherwise by the call. | 1527 // otherwise by the call. |
| 1525 if (must_suspend || (paused() && playback_completed_) || hasVideo()) | 1528 if ((paused() && playback_completed_) || hasVideo()) |
| 1526 SuspendAndReleaseResources(); | 1529 SuspendAndReleaseResources(); |
| 1527 } | 1530 } |
| 1528 | 1531 |
| 1529 void WebMediaPlayerAndroid::OnShown() {} | 1532 void WebMediaPlayerAndroid::OnShown() {} |
| 1530 | 1533 |
| 1534 void WebMediaPlayerAndroid::OnSuspend(bool must_suspend) { |
| 1535 if (must_suspend) |
| 1536 SuspendAndReleaseResources(); |
| 1537 } |
| 1538 |
| 1531 void WebMediaPlayerAndroid::OnPlay() { | 1539 void WebMediaPlayerAndroid::OnPlay() { |
| 1532 play(); | 1540 play(); |
| 1533 client_->playbackStateChanged(); | 1541 client_->playbackStateChanged(); |
| 1534 } | 1542 } |
| 1535 | 1543 |
| 1536 void WebMediaPlayerAndroid::OnPause() { | 1544 void WebMediaPlayerAndroid::OnPause() { |
| 1537 pause(); | 1545 pause(); |
| 1538 client_->playbackStateChanged(); | 1546 client_->playbackStateChanged(); |
| 1539 } | 1547 } |
| 1540 | 1548 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; | 1671 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; |
| 1664 } else if (is_hls_url == is_hls) { | 1672 } else if (is_hls_url == is_hls) { |
| 1665 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; | 1673 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; |
| 1666 } | 1674 } |
| 1667 UMA_HISTOGRAM_ENUMERATION( | 1675 UMA_HISTOGRAM_ENUMERATION( |
| 1668 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", | 1676 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", |
| 1669 result, PREDICTION_RESULT_MAX); | 1677 result, PREDICTION_RESULT_MAX); |
| 1670 } | 1678 } |
| 1671 | 1679 |
| 1672 } // namespace content | 1680 } // namespace content |
| OLD | NEW |