diff --git a/cobalt/dom/html_media_element.cc b/cobalt/dom/html_media_element.cc
index da10b2e91781..dfbfa2a9de66 100644
--- a/cobalt/dom/html_media_element.cc
+++ b/cobalt/dom/html_media_element.cc
@@ -138,7 +138,7 @@ HTMLMediaElement::HTMLMediaElement(Document* document, base::Token tag_name)
ready_state_(WebMediaPlayer::kReadyStateHaveNothing),
ready_state_maximum_(WebMediaPlayer::kReadyStateHaveNothing),
volume_(1.0f),
- last_seek_time_(0),
+ last_seek_time_(0.0),
previous_progress_time_(std::numeric_limits::max()),
duration_(std::numeric_limits::quiet_NaN()),
playing_(false),
@@ -149,7 +149,7 @@ HTMLMediaElement::HTMLMediaElement(Document* document, base::Token tag_name)
resume_frozen_flag_(false),
seeking_(false),
controls_(false),
- last_time_update_event_movie_time_(std::numeric_limits::max()),
+ last_time_update_event_movie_time_(std::numeric_limits::max()),
processing_media_player_callback_(0),
media_source_url_(std::string(kMediaSourceUrlProtocol) + ':' +
base::GenerateGUID()),
@@ -222,7 +222,7 @@ scoped_refptr HTMLMediaElement::buffered() const {
}
player_->UpdateBufferedTimeRanges(
- [&](float start, float end) { buffered->Add(start, end); });
+ [&](double start, double end) { buffered->Add(start, end); });
return buffered;
}
@@ -344,11 +344,11 @@ bool HTMLMediaElement::seeking() const {
return seeking_;
}
-float HTMLMediaElement::current_time(
+double HTMLMediaElement::current_time(
script::ExceptionState* exception_state) const {
if (!player_) {
LOG(INFO) << 0 << " (because player is NULL)";
- return 0;
+ return 0.0;
}
if (seeking_) {
@@ -356,15 +356,14 @@ float HTMLMediaElement::current_time(
return last_seek_time_;
}
- float time = player_->GetCurrentTime();
+ const double time = player_->GetCurrentTime();
MLOG() << time << " (from player)";
return time;
}
void HTMLMediaElement::set_current_time(
- float time, script::ExceptionState* exception_state) {
+ double time, script::ExceptionState* exception_state) {
// 4.8.9.9 Seeking
-
// 1 - If the media element's readyState is
// WebMediaPlayer::kReadyStateHaveNothing, then raise an INVALID_STATE_ERR
// exception.
@@ -377,10 +376,9 @@ void HTMLMediaElement::set_current_time(
Seek(time);
}
-float HTMLMediaElement::duration() const {
+double HTMLMediaElement::duration() const {
MLOG() << duration_;
- // TODO: Turn duration into double.
- return static_cast(duration_);
+ return duration_;
}
base::Time HTMLMediaElement::GetStartDate() const {
@@ -433,7 +431,7 @@ void HTMLMediaElement::set_playback_rate(float rate) {
const scoped_refptr& HTMLMediaElement::played() {
MLOG();
if (playing_) {
- float time = current_time(NULL);
+ const double time = current_time(NULL);
if (time > last_seek_time_) {
AddPlayedRange(last_seek_time_, time);
}
@@ -447,8 +445,8 @@ const scoped_refptr& HTMLMediaElement::played() {
}
scoped_refptr HTMLMediaElement::seekable() const {
- if (player_ && player_->GetMaxTimeSeekable() != 0) {
- double max_time_seekable = player_->GetMaxTimeSeekable();
+ if (player_ && player_->GetMaxTimeSeekable() != 0.0) {
+ const double max_time_seekable = player_->GetMaxTimeSeekable();
MLOG() << "(0, " << max_time_seekable << ")";
return new TimeRanges(0, max_time_seekable);
}
@@ -632,7 +630,7 @@ void HTMLMediaElement::DurationChanged(double duration, bool request_seek) {
ScheduleOwnEvent(base::Tokens::durationchange());
if (request_seek) {
- Seek(static_cast(duration));
+ Seek(duration);
}
}
@@ -775,7 +773,7 @@ void HTMLMediaElement::PrepareForLoad() {
// 2 - Asynchronously await a stable state.
played_time_ranges_ = new TimeRanges;
- last_seek_time_ = 0;
+ last_seek_time_ = 0.0;
ConfigureMediaControls();
}
@@ -1019,8 +1017,8 @@ void HTMLMediaElement::OnProgressEventTimer() {
return;
}
- double time = base::Time::Now().ToDoubleT();
- double time_delta = time - previous_progress_time_;
+ const double time = base::Time::Now().ToDoubleT();
+ const double time_delta = time - previous_progress_time_;
if (player_->DidLoadingProgress()) {
ScheduleOwnEvent(base::Tokens::progress());
@@ -1082,7 +1080,7 @@ void HTMLMediaElement::StopPeriodicTimers() {
void HTMLMediaElement::ScheduleTimeupdateEvent(bool periodic_event) {
// Some media engines make multiple "time changed" callbacks at the same time,
// but we only want one event at a given time so filter here
- float movie_time = current_time(NULL);
+ const double movie_time = current_time(NULL);
if (movie_time != last_time_update_event_movie_time_) {
if (!periodic_event && playback_progress_timer_.IsRunning()) {
playback_progress_timer_.Reset();
@@ -1268,7 +1266,7 @@ void HTMLMediaElement::ChangeNetworkStateFromLoadingToIdle() {
network_state_ = kNetworkIdle;
}
-void HTMLMediaElement::Seek(float time) {
+void HTMLMediaElement::Seek(double time) {
LOG(INFO) << "Seek to " << time << ".";
// 4.8.9.9 Seeking - continued from set_current_time().
@@ -1279,7 +1277,7 @@ void HTMLMediaElement::Seek(float time) {
// Get the current time before setting seeking_, last_seek_time_ is returned
// once it is set.
- float now = current_time(NULL);
+ const double now = current_time(NULL);
// 2 - If the element's seeking IDL attribute is true, then another instance
// of this algorithm is already running. Abort that other instance of the
@@ -1297,7 +1295,7 @@ void HTMLMediaElement::Seek(float time) {
// 6 - If the new playback position is less than the earliest possible
// position, let it be that position instead.
- time = std::max(time, 0.f);
+ time = std::max(time, 0.0);
// 7 - If the (possibly now changed) new playback position is not in one of
// the ranges given in the seekable attribute, then let it be the position in
@@ -1329,7 +1327,7 @@ void HTMLMediaElement::Seek(float time) {
seeking_ = false;
return;
}
- time = static_cast(seekable_ranges->Nearest(time));
+ time = seekable_ranges->Nearest(time);
if (playing_) {
if (last_seek_time_ < now) {
@@ -1361,7 +1359,7 @@ void HTMLMediaElement::FinishSeek() {
ScheduleOwnEvent(base::Tokens::seeked());
}
-void HTMLMediaElement::AddPlayedRange(float start, float end) {
+void HTMLMediaElement::AddPlayedRange(double start, double end) {
if (!played_time_ranges_) {
played_time_ranges_ = new TimeRanges;
}
@@ -1411,7 +1409,7 @@ void HTMLMediaElement::UpdatePlayState() {
playback_progress_timer_.Stop();
playing_ = false;
- float time = current_time(NULL);
+ const double time = current_time(NULL);
if (time > last_seek_time_) {
AddPlayedRange(last_seek_time_, time);
}
@@ -1431,7 +1429,7 @@ bool HTMLMediaElement::PotentiallyPlaying() const {
}
bool HTMLMediaElement::EndedPlayback() const {
- float dur = duration();
+ const double dur = duration();
if (!player_ || std::isnan(dur)) {
return false;
}
@@ -1448,15 +1446,15 @@ bool HTMLMediaElement::EndedPlayback() const {
// direction of playback is forwards, Either the media element does not have a
// loop attribute specified, or the media element has a current media
// controller.
- float now = current_time(NULL);
- if (playback_rate_ > 0) {
- return dur > 0 && now >= dur && !loop();
+ const double now = current_time(NULL);
+ if (playback_rate_ > 0.f) {
+ return dur > 0.0 && now >= dur && !loop();
}
// or the current playback position is the earliest possible position and the
// direction of playback is backwards
- if (playback_rate_ < 0) {
- return now <= 0;
+ if (playback_rate_ < 0.f) {
+ return now <= 0.0;
}
return false;
@@ -1557,14 +1555,14 @@ void HTMLMediaElement::TimeChanged(bool eos_played) {
// already posted one at the current movie time.
ScheduleTimeupdateEvent(false);
- float now = current_time(NULL);
- float dur = duration();
+ const double now = current_time(NULL);
+ const double dur = duration();
// When the current playback position reaches the end of the media resource
// when the direction of playback is forwards, then the user agent must follow
// these steps:
eos_played |=
- !std::isnan(dur) && (0.0f != dur) && now >= dur && playback_rate_ > 0;
+ !std::isnan(dur) && (0.0 != dur) && now >= dur && playback_rate_ > 0.f;
if (eos_played) {
LOG(INFO) << "End of stream is played.";
// If the media element has a loop attribute specified and does not have a
@@ -1573,7 +1571,7 @@ void HTMLMediaElement::TimeChanged(bool eos_played) {
sent_end_event_ = false;
// then seek to the earliest possible position of the media resource and
// abort these steps.
- Seek(0);
+ Seek(0.0);
} else {
// If the media element does not have a current media controller, and the
// media element has still ended playback, and the direction of playback
@@ -1603,7 +1601,7 @@ void HTMLMediaElement::DurationChanged() {
ScheduleOwnEvent(base::Tokens::durationchange());
- double now = current_time(NULL);
+ const double now = current_time(NULL);
// Reset and update |duration_|.
duration_ = std::numeric_limits::quiet_NaN();
if (player_ && ready_state_ >= WebMediaPlayer::kReadyStateHaveMetadata) {
@@ -1611,7 +1609,7 @@ void HTMLMediaElement::DurationChanged() {
}
if (now > duration_) {
- Seek(static_cast(duration_));
+ Seek(duration_);
}
EndProcessingMediaPlayerCallback();
diff --git a/cobalt/dom/html_media_element.h b/cobalt/dom/html_media_element.h
index 612e21cf20bc..db05a0cd7356 100644
--- a/cobalt/dom/html_media_element.h
+++ b/cobalt/dom/html_media_element.h
@@ -105,9 +105,9 @@ class HTMLMediaElement : public HTMLElement,
bool seeking() const;
// Playback state
- float current_time(script::ExceptionState* exception_state) const;
- void set_current_time(float time, script::ExceptionState* exception_state);
- float duration() const;
+ double current_time(script::ExceptionState* exception_state) const;
+ void set_current_time(double time, script::ExceptionState* exception_state);
+ double duration() const;
base::Time GetStartDate() const;
bool paused() const;
bool resume_frozen_flag() const;
@@ -210,10 +210,10 @@ class HTMLMediaElement : public HTMLElement,
void ChangeNetworkStateFromLoadingToIdle();
// Playback
- void Seek(float time);
+ void Seek(double time);
void FinishSeek();
- void AddPlayedRange(float start, float end);
+ void AddPlayedRange(double start, double end);
void UpdateVolume();
void UpdatePlayState();
@@ -269,7 +269,7 @@ class HTMLMediaElement : public HTMLElement,
WebMediaPlayer::ReadyState ready_state_maximum_;
float volume_;
- float last_seek_time_;
+ double last_seek_time_;
double previous_progress_time_;
double duration_;
diff --git a/cobalt/media/player/web_media_player.h b/cobalt/media/player/web_media_player.h
index 459ec6ed0b86..1f8f2646733e 100644
--- a/cobalt/media/player/web_media_player.h
+++ b/cobalt/media/player/web_media_player.h
@@ -41,7 +41,7 @@ class WebMediaPlayer {
// Return true if the punch through box should be rendered. Return false if
// no punch through box should be rendered.
typedef base::Callback SetBoundsCB;
- typedef std::function AddRangeCB;
+ typedef std::function AddRangeCB;
enum NetworkState {
kNetworkStateEmpty,
@@ -109,12 +109,12 @@ class WebMediaPlayer {
// Playback controls.
virtual void Play() = 0;
virtual void Pause() = 0;
- virtual void Seek(float seconds) = 0;
+ virtual void Seek(double seconds) = 0;
virtual void SetRate(float rate) = 0;
virtual void SetVolume(float volume) = 0;
virtual void SetVisible(bool visible) = 0;
virtual void UpdateBufferedTimeRanges(const AddRangeCB& add_range_cb) = 0;
- virtual float GetMaxTimeSeekable() const = 0;
+ virtual double GetMaxTimeSeekable() const = 0;
// Suspend/Resume
virtual void Suspend() = 0;
@@ -136,11 +136,11 @@ class WebMediaPlayer {
// Getters of playback state.
virtual bool IsPaused() const = 0;
virtual bool IsSeeking() const = 0;
- virtual float GetDuration() const = 0;
+ virtual double GetDuration() const = 0;
#if SB_HAS(PLAYER_WITH_URL)
virtual base::Time GetStartDate() const = 0;
#endif // SB_HAS(PLAYER_WITH_URL)
- virtual float GetCurrentTime() const = 0;
+ virtual double GetCurrentTime() const = 0;
virtual float GetPlaybackRate() const = 0;
// Get rate of loading the resource.
@@ -152,7 +152,7 @@ class WebMediaPlayer {
virtual bool DidLoadingProgress() const = 0;
- virtual float MediaTimeForTimeValue(float timeValue) const = 0;
+ virtual double MediaTimeForTimeValue(double timeValue) const = 0;
virtual PlayerStatistics GetStatistics() const = 0;
diff --git a/cobalt/media/player/web_media_player_impl.cc b/cobalt/media/player/web_media_player_impl.cc
index 6941c04d3d83..48218c90d160 100644
--- a/cobalt/media/player/web_media_player_impl.cc
+++ b/cobalt/media/player/web_media_player_impl.cc
@@ -69,12 +69,12 @@ const char* kMediaEme = "Media.EME.";
// end of stream position when the current playback position is also near the
// end of the stream. In this case, "near the end of stream" means "position
// greater than or equal to duration() - kEndOfStreamEpsilonInSeconds".
-const double kEndOfStreamEpsilonInSeconds = 2.;
+const double kEndOfStreamEpsilonInSeconds = 2.0;
DECLARE_INSTANCE_COUNTER(WebMediaPlayerImpl);
bool IsNearTheEndOfStream(const WebMediaPlayerImpl* wmpi, double position) {
- float duration = wmpi->GetDuration();
+ const double duration = wmpi->GetDuration();
if (std::isfinite(duration)) {
// If video is very short, we always treat a position as near the end.
if (duration <= kEndOfStreamEpsilonInSeconds) return true;
@@ -84,19 +84,9 @@ bool IsNearTheEndOfStream(const WebMediaPlayerImpl* wmpi, double position) {
}
#endif // defined(COBALT_SKIP_SEEK_REQUEST_NEAR_END)
-base::TimeDelta ConvertSecondsToTimestamp(float seconds) {
- float microseconds = seconds * base::Time::kMicrosecondsPerSecond;
- float integer = ceilf(microseconds);
- float difference = integer - microseconds;
-
- // Round down if difference is large enough.
- if ((microseconds > 0 && difference > 0.5f) ||
- (microseconds <= 0 && difference >= 0.5f)) {
- integer -= 1.0f;
- }
-
- // Now we can safely cast to int64 microseconds.
- return base::TimeDelta::FromMicroseconds(static_cast(integer));
+base::TimeDelta ConvertSecondsToTimestamp(double seconds) {
+ return base::TimeDelta::FromMicrosecondsD(std::round(
+ seconds * static_cast(base::Time::kMicrosecondsPerSecond)));
}
} // namespace
@@ -340,7 +330,7 @@ void WebMediaPlayerImpl::Pause() {
media_log_->AddEvent<::media::MediaLogEvent::kPause>();
}
-void WebMediaPlayerImpl::Seek(float seconds) {
+void WebMediaPlayerImpl::Seek(double seconds) {
DCHECK_EQ(main_loop_, base::MessageLoop::current());
#if defined(COBALT_SKIP_SEEK_REQUEST_NEAR_END)
@@ -461,20 +451,20 @@ bool WebMediaPlayerImpl::IsSeeking() const {
return state_.seeking;
}
-float WebMediaPlayerImpl::GetDuration() const {
+double WebMediaPlayerImpl::GetDuration() const {
DCHECK_EQ(main_loop_, base::MessageLoop::current());
if (ready_state_ == WebMediaPlayer::kReadyStateHaveNothing)
- return std::numeric_limits::quiet_NaN();
+ return std::numeric_limits::quiet_NaN();
base::TimeDelta duration = pipeline_->GetMediaDuration();
// Return positive infinity if the resource is unbounded.
// http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-media-duration
if (duration == ::media::kInfiniteDuration)
- return std::numeric_limits::infinity();
+ return std::numeric_limits::infinity();
- return static_cast(duration.InSecondsF());
+ return duration.InSecondsF();
}
#if SB_HAS(PLAYER_WITH_URL)
@@ -490,10 +480,12 @@ base::Time WebMediaPlayerImpl::GetStartDate() const {
}
#endif // SB_HAS(PLAYER_WITH_URL)
-float WebMediaPlayerImpl::GetCurrentTime() const {
+double WebMediaPlayerImpl::GetCurrentTime() const {
DCHECK_EQ(main_loop_, base::MessageLoop::current());
- if (state_.paused) return static_cast(state_.paused_time.InSecondsF());
- return static_cast(pipeline_->GetMediaTime().InSecondsF());
+ if (state_.paused) {
+ return state_.paused_time.InSecondsF();
+ }
+ return pipeline_->GetMediaTime().InSecondsF();
}
float WebMediaPlayerImpl::GetPlaybackRate() const {
@@ -533,10 +525,9 @@ void WebMediaPlayerImpl::UpdateBufferedTimeRanges(
}
}
-float WebMediaPlayerImpl::GetMaxTimeSeekable() const {
+double WebMediaPlayerImpl::GetMaxTimeSeekable() const {
DCHECK_EQ(main_loop_, base::MessageLoop::current());
-
- return static_cast(pipeline_->GetMediaDuration().InSecondsF());
+ return pipeline_->GetMediaDuration().InSecondsF();
}
void WebMediaPlayerImpl::Suspend() { pipeline_->Suspend(); }
@@ -554,7 +545,7 @@ bool WebMediaPlayerImpl::DidLoadingProgress() const {
return pipeline_->DidLoadingProgress();
}
-float WebMediaPlayerImpl::MediaTimeForTimeValue(float timeValue) const {
+double WebMediaPlayerImpl::MediaTimeForTimeValue(double timeValue) const {
return ConvertSecondsToTimestamp(timeValue).InSecondsF();
}
diff --git a/cobalt/media/player/web_media_player_impl.h b/cobalt/media/player/web_media_player_impl.h
index adb7ed2a577b..ca85f8120a1a 100644
--- a/cobalt/media/player/web_media_player_impl.h
+++ b/cobalt/media/player/web_media_player_impl.h
@@ -131,12 +131,12 @@ class WebMediaPlayerImpl : public WebMediaPlayer,
// Playback controls.
void Play() override;
void Pause() override;
- void Seek(float seconds) override;
+ void Seek(double seconds) override;
void SetRate(float rate) override;
void SetVolume(float volume) override;
void SetVisible(bool visible) override;
void UpdateBufferedTimeRanges(const AddRangeCB& add_range_cb) override;
- float GetMaxTimeSeekable() const override;
+ double GetMaxTimeSeekable() const override;
// Suspend/Resume
void Suspend() override;
@@ -158,11 +158,11 @@ class WebMediaPlayerImpl : public WebMediaPlayer,
// Getters of playback state.
bool IsPaused() const override;
bool IsSeeking() const override;
- float GetDuration() const override;
+ double GetDuration() const override;
#if SB_HAS(PLAYER_WITH_URL)
base::Time GetStartDate() const override;
#endif // SB_HAS(PLAYER_WITH_URL)
- float GetCurrentTime() const override;
+ double GetCurrentTime() const override;
float GetPlaybackRate() const override;
// Get rate of loading the resource.
@@ -176,7 +176,7 @@ class WebMediaPlayerImpl : public WebMediaPlayer,
bool DidLoadingProgress() const override;
- float MediaTimeForTimeValue(float timeValue) const override;
+ double MediaTimeForTimeValue(double timeValue) const override;
PlayerStatistics GetStatistics() const override;
@@ -264,7 +264,7 @@ class WebMediaPlayerImpl : public WebMediaPlayer,
seeking(false),
playback_rate(0.0f),
pending_seek(false),
- pending_seek_seconds(0.0f),
+ pending_seek_seconds(0.0),
starting(false),
is_progressive(false),
is_media_source(false) {}
@@ -288,7 +288,7 @@ class WebMediaPlayerImpl : public WebMediaPlayer,
// Seek gets pending if another seek is in progress. Only last pending seek
// will have effect.
bool pending_seek;
- float pending_seek_seconds;
+ double pending_seek_seconds;
bool starting;
diff --git a/cobalt/media/sandbox/web_media_player_helper.cc b/cobalt/media/sandbox/web_media_player_helper.cc
index c2364a574518..945c1aa4dfa1 100644
--- a/cobalt/media/sandbox/web_media_player_helper.cc
+++ b/cobalt/media/sandbox/web_media_player_helper.cc
@@ -116,7 +116,7 @@ bool WebMediaPlayerHelper::IsPlaybackFinished() const {
// Use a small epsilon to ensure that the video can finish properly even when
// the audio and video streams are shorter than the duration specified in the
// container.
- return player_->GetCurrentTime() >= player_->GetDuration() - 0.1f;
+ return player_->GetCurrentTime() >= player_->GetDuration() - 0.1;
}
} // namespace sandbox
diff --git a/cobalt/media/sandbox/web_media_player_sandbox.cc b/cobalt/media/sandbox/web_media_player_sandbox.cc
index cfa4a2827475..016444d62a1f 100644
--- a/cobalt/media/sandbox/web_media_player_sandbox.cc
+++ b/cobalt/media/sandbox/web_media_player_sandbox.cc
@@ -329,21 +329,21 @@ class Application {
}
void AppendData(const std::string& id, ScopedFile* file, int64* offset) {
- const float kLowWaterMarkInSeconds = 5.f;
+ const double kLowWaterMarkInSeconds = 5.0;
const int64 kMaxBytesToAppend = 1024 * 1024;
std::vector buffer(kMaxBytesToAppend);
while (*offset < file->GetSize()) {
::media::Ranges ranges = chunk_demuxer_->GetBufferedRanges(id);
- float end_of_buffer =
- ranges.size() == 0 ? 0.f : ranges.end(ranges.size() - 1).InSecondsF();
+ const double end_of_buffer =
+ ranges.size() == 0 ? 0.0 : ranges.end(ranges.size() - 1).InSecondsF();
if (end_of_buffer - player_->GetCurrentTime() > kLowWaterMarkInSeconds) {
break;
}
int64 bytes_to_append =
std::min(kMaxBytesToAppend, file->GetSize() - *offset);
- auto current_time = player_ ? player_->GetCurrentTime() : 0;
+ const double current_time = player_ ? player_->GetCurrentTime() : 0.0;
auto evicted = chunk_demuxer_->EvictCodedFrames(
id, base::TimeDelta::FromSecondsD(current_time), bytes_to_append);
SB_DCHECK(evicted);
diff --git a/cobalt/media_session/media_session_client.cc b/cobalt/media_session/media_session_client.cc
index ab740dead22d..d0640670d866 100644
--- a/cobalt/media_session/media_session_client.cc
+++ b/cobalt/media_session/media_session_client.cc
@@ -58,7 +58,7 @@ void GuessMediaPositionState(MediaSessionState* session_state,
*guess_player = current_player;
MediaPositionState position_state;
- float duration = (*guess_player)->GetDuration();
+ const double duration = (*guess_player)->GetDuration();
if (std::isfinite(duration)) {
position_state.set_duration(duration);
} else if (std::isinf(duration)) {