| 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 "webkit/media/webmediaplayer_impl.h" | 5 #include "webkit/media/webmediaplayer_impl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 30 #include "v8/include/v8.h" | 30 #include "v8/include/v8.h" |
| 31 #include "webkit/media/buffered_data_source.h" | 31 #include "webkit/media/buffered_data_source.h" |
| 32 #include "webkit/media/filter_helpers.h" | 32 #include "webkit/media/filter_helpers.h" |
| 33 #include "webkit/media/webmediaplayer_delegate.h" | 33 #include "webkit/media/webmediaplayer_delegate.h" |
| 34 #include "webkit/media/webmediaplayer_proxy.h" | 34 #include "webkit/media/webmediaplayer_proxy.h" |
| 35 #include "webkit/media/webmediaplayer_util.h" |
| 35 #include "webkit/media/webvideoframe_impl.h" | 36 #include "webkit/media/webvideoframe_impl.h" |
| 36 | 37 |
| 37 using WebKit::WebCanvas; | 38 using WebKit::WebCanvas; |
| 38 using WebKit::WebRect; | 39 using WebKit::WebRect; |
| 39 using WebKit::WebSize; | 40 using WebKit::WebSize; |
| 40 using media::NetworkEvent; | 41 using media::NetworkEvent; |
| 41 using media::PipelineStatus; | 42 using media::PipelineStatus; |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 | 45 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 64 // | 65 // |
| 65 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems | 66 // A very slow speed, ie 0.00000001x, causes the machine to lock up. (It seems |
| 66 // like a busy loop). It gets unresponsive, although its not completely dead. | 67 // like a busy loop). It gets unresponsive, although its not completely dead. |
| 67 // | 68 // |
| 68 // Also our timers are not very accurate (especially for ogg), which becomes | 69 // Also our timers are not very accurate (especially for ogg), which becomes |
| 69 // evident at low speeds and on Vista. Since other speeds are risky and outside | 70 // evident at low speeds and on Vista. Since other speeds are risky and outside |
| 70 // the norms, we think 1/16x to 16x is a safe and useful range for now. | 71 // the norms, we think 1/16x to 16x is a safe and useful range for now. |
| 71 const float kMinRate = 0.0625f; | 72 const float kMinRate = 0.0625f; |
| 72 const float kMaxRate = 16.0f; | 73 const float kMaxRate = 16.0f; |
| 73 | 74 |
| 74 // Platform independent method for converting and rounding floating point | |
| 75 // seconds to an int64 timestamp. | |
| 76 // | |
| 77 // Refer to https://bugs.webkit.org/show_bug.cgi?id=52697 for details. | |
| 78 base::TimeDelta ConvertSecondsToTimestamp(float seconds) { | |
| 79 float microseconds = seconds * base::Time::kMicrosecondsPerSecond; | |
| 80 float integer = ceilf(microseconds); | |
| 81 float difference = integer - microseconds; | |
| 82 | |
| 83 // Round down if difference is large enough. | |
| 84 if ((microseconds > 0 && difference > 0.5f) || | |
| 85 (microseconds <= 0 && difference >= 0.5f)) { | |
| 86 integer -= 1.0f; | |
| 87 } | |
| 88 | |
| 89 // Now we can safely cast to int64 microseconds. | |
| 90 return base::TimeDelta::FromMicroseconds(static_cast<int64>(integer)); | |
| 91 } | |
| 92 | |
| 93 } // namespace | 75 } // namespace |
| 94 | 76 |
| 95 namespace webkit_media { | 77 namespace webkit_media { |
| 96 | 78 |
| 97 WebMediaPlayerImpl::WebMediaPlayerImpl( | 79 WebMediaPlayerImpl::WebMediaPlayerImpl( |
| 98 WebKit::WebFrame* frame, | 80 WebKit::WebFrame* frame, |
| 99 WebKit::WebMediaPlayerClient* client, | 81 WebKit::WebMediaPlayerClient* client, |
| 100 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 82 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
| 101 media::FilterCollection* collection, | 83 media::FilterCollection* collection, |
| 102 WebKit::WebAudioSourceProvider* audio_source_provider, | 84 WebKit::WebAudioSourceProvider* audio_source_provider, |
| (...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 return audio_source_provider_; | 896 return audio_source_provider_; |
| 915 } | 897 } |
| 916 | 898 |
| 917 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 899 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
| 918 DCHECK_EQ(main_loop_, MessageLoop::current()); | 900 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 919 incremented_externally_allocated_memory_ = true; | 901 incremented_externally_allocated_memory_ = true; |
| 920 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 902 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
| 921 } | 903 } |
| 922 | 904 |
| 923 } // namespace webkit_media | 905 } // namespace webkit_media |
| OLD | NEW |