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

Side by Side Diff: Source/core/html/HTMLMediaElement.cpp

Issue 370203004: Eliminate MediaPlayer abstraction(play/pause, other APIs) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: updated as per the comment Created 6 years, 5 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
« no previous file with comments | « Source/core/html/HTMLMediaElement.h ('k') | Source/platform/graphics/media/MediaPlayer.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 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 void HTMLMediaElement::addPlayedRange(double start, double end) 1871 void HTMLMediaElement::addPlayedRange(double start, double end)
1872 { 1872 {
1873 WTF_LOG(Media, "HTMLMediaElement::addPlayedRange(%f, %f)", start, end); 1873 WTF_LOG(Media, "HTMLMediaElement::addPlayedRange(%f, %f)", start, end);
1874 if (!m_playedTimeRanges) 1874 if (!m_playedTimeRanges)
1875 m_playedTimeRanges = TimeRanges::create(); 1875 m_playedTimeRanges = TimeRanges::create();
1876 m_playedTimeRanges->add(start, end); 1876 m_playedTimeRanges->add(start, end);
1877 } 1877 }
1878 1878
1879 bool HTMLMediaElement::supportsSave() const 1879 bool HTMLMediaElement::supportsSave() const
1880 { 1880 {
1881 return m_player ? m_player->supportsSave() : false; 1881 return webMediaPlayer() && webMediaPlayer()->supportsSave();
1882 } 1882 }
1883 1883
1884 void HTMLMediaElement::prepareToPlay() 1884 void HTMLMediaElement::prepareToPlay()
1885 { 1885 {
1886 WTF_LOG(Media, "HTMLMediaElement::prepareToPlay(%p)", this); 1886 WTF_LOG(Media, "HTMLMediaElement::prepareToPlay(%p)", this);
1887 if (m_havePreparedToPlay) 1887 if (m_havePreparedToPlay)
1888 return; 1888 return;
1889 m_havePreparedToPlay = true; 1889 m_havePreparedToPlay = true;
1890 1890
1891 if (loadIsDeferred()) 1891 if (loadIsDeferred())
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 time = std::min(time, duration()); 1927 time = std::min(time, duration());
1928 1928
1929 // 6 - If the new playback position is less than the earliest possible posit ion, let it be that position instead. 1929 // 6 - If the new playback position is less than the earliest possible posit ion, let it be that position instead.
1930 time = std::max(time, 0.0); 1930 time = std::max(time, 0.0);
1931 1931
1932 // Ask the media engine for the time value in the movie's time scale before comparing with current time. This 1932 // Ask the media engine for the time value in the movie's time scale before comparing with current time. This
1933 // is necessary because if the seek time is not equal to currentTime but the delta is less than the movie's 1933 // is necessary because if the seek time is not equal to currentTime but the delta is less than the movie's
1934 // time scale, we will ask the media engine to "seek" to the current movie t ime, which may be a noop and 1934 // time scale, we will ask the media engine to "seek" to the current movie t ime, which may be a noop and
1935 // not generate a timechanged callback. This means m_seeking will never be c leared and we will never 1935 // not generate a timechanged callback. This means m_seeking will never be c leared and we will never
1936 // fire a 'seeked' event. 1936 // fire a 'seeked' event.
1937 double mediaTime = webMediaPlayer()->mediaTimeForTimeValue(time);
1938 if (time != mediaTime) {
1937 #if !LOG_DISABLED 1939 #if !LOG_DISABLED
1938 double mediaTime = m_player->mediaTimeForTimeValue(time);
1939 if (time != mediaTime)
1940 WTF_LOG(Media, "HTMLMediaElement::seek(%f) - media timeline equivalent i s %f", time, mediaTime); 1940 WTF_LOG(Media, "HTMLMediaElement::seek(%f) - media timeline equivalent i s %f", time, mediaTime);
1941 #endif 1941 #endif
1942 time = m_player->mediaTimeForTimeValue(time); 1942 time = mediaTime;
1943 }
1943 1944
1944 // 7 - If the (possibly now changed) new playback position is not in one of the ranges given in the 1945 // 7 - If the (possibly now changed) new playback position is not in one of the ranges given in the
1945 // seekable attribute, then let it be the position in one of the ranges give n in the seekable attribute 1946 // seekable attribute, then let it be the position in one of the ranges give n in the seekable attribute
1946 // that is the nearest to the new playback position. ... If there are no ran ges given in the seekable 1947 // that is the nearest to the new playback position. ... If there are no ran ges given in the seekable
1947 // attribute then set the seeking IDL attribute to false and abort these ste ps. 1948 // attribute then set the seeking IDL attribute to false and abort these ste ps.
1948 RefPtr<TimeRanges> seekableRanges = seekable(); 1949 RefPtr<TimeRanges> seekableRanges = seekable();
1949 1950
1950 // Short circuit seeking to the current time by just firing the events if no seek is required. 1951 // Short circuit seeking to the current time by just firing the events if no seek is required.
1951 // Don't skip calling the media engine if we are in poster mode because a se ek should always 1952 // Don't skip calling the media engine if we are in poster mode because a se ek should always
1952 // cancel poster display. 1953 // cancel poster display.
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after
3100 seek(duration, IGNORE_EXCEPTION); 3101 seek(duration, IGNORE_EXCEPTION);
3101 } 3102 }
3102 3103
3103 void HTMLMediaElement::mediaPlayerPlaybackStateChanged() 3104 void HTMLMediaElement::mediaPlayerPlaybackStateChanged()
3104 { 3105 {
3105 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerPlaybackStateChanged"); 3106 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerPlaybackStateChanged");
3106 3107
3107 if (!m_player || m_pausedInternal) 3108 if (!m_player || m_pausedInternal)
3108 return; 3109 return;
3109 3110
3110 if (m_player->paused()) 3111 if (webMediaPlayer()->paused())
3111 pause(); 3112 pause();
3112 else 3113 else
3113 playInternal(); 3114 playInternal();
3114 } 3115 }
3115 3116
3116 void HTMLMediaElement::mediaPlayerRequestFullscreen() 3117 void HTMLMediaElement::mediaPlayerRequestFullscreen()
3117 { 3118 {
3118 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerRequestFullscreen"); 3119 WTF_LOG(Media, "HTMLMediaElement::mediaPlayerRequestFullscreen");
3119 3120
3120 // The player is responsible for only invoking this callback in response to 3121 // The player is responsible for only invoking this callback in response to
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
3263 } 3264 }
3264 3265
3265 return shouldMute ? 0 : m_volume * volumeMultiplier; 3266 return shouldMute ? 0 : m_volume * volumeMultiplier;
3266 } 3267 }
3267 3268
3268 void HTMLMediaElement::updatePlayState() 3269 void HTMLMediaElement::updatePlayState()
3269 { 3270 {
3270 if (!m_player) 3271 if (!m_player)
3271 return; 3272 return;
3272 3273
3274 bool isPlaying = webMediaPlayer() && !webMediaPlayer()->paused();
3273 if (m_pausedInternal) { 3275 if (m_pausedInternal) {
3274 if (!m_player->paused()) 3276 if (isPlaying)
3275 m_player->pause(); 3277 webMediaPlayer()->pause();
3276 refreshCachedTime(); 3278 refreshCachedTime();
3277 m_playbackProgressTimer.stop(); 3279 m_playbackProgressTimer.stop();
3278 if (hasMediaControls()) 3280 if (hasMediaControls())
3279 mediaControls()->playbackStopped(); 3281 mediaControls()->playbackStopped();
3280 return; 3282 return;
3281 } 3283 }
3282 3284
3283 bool shouldBePlaying = potentiallyPlaying(); 3285 bool shouldBePlaying = potentiallyPlaying();
3284 bool playerPaused = m_player->paused();
3285 3286
3286 WTF_LOG(Media, "HTMLMediaElement::updatePlayState - shouldBePlaying = %s, pl ayerPaused = %s", 3287 WTF_LOG(Media, "HTMLMediaElement::updatePlayState - shouldBePlaying = %s, is Playing = %s",
3287 boolString(shouldBePlaying), boolString(playerPaused)); 3288 boolString(shouldBePlaying), boolString(isPlaying));
3288 3289
3289 if (shouldBePlaying) { 3290 if (shouldBePlaying) {
3290 setDisplayMode(Video); 3291 setDisplayMode(Video);
3291 invalidateCachedTime(); 3292 invalidateCachedTime();
3292 3293
3293 if (playerPaused) { 3294 if (!isPlaying) {
3294 // Set rate, muted before calling play in case they were set before the media engine was setup. 3295 // Set rate, muted before calling play in case they were set before the media engine was setup.
3295 // The media engine should just stash the rate and muted values sinc e it isn't already playing. 3296 // The media engine should just stash the rate and muted values sinc e it isn't already playing.
3296 webMediaPlayer()->setRate(effectivePlaybackRate()); 3297 webMediaPlayer()->setRate(effectivePlaybackRate());
3297 updateVolume(); 3298 updateVolume();
3298 3299 webMediaPlayer()->play();
3299 m_player->play();
3300 } 3300 }
3301 3301
3302 if (hasMediaControls()) 3302 if (hasMediaControls())
3303 mediaControls()->playbackStarted(); 3303 mediaControls()->playbackStarted();
3304 startPlaybackProgressTimer(); 3304 startPlaybackProgressTimer();
3305 m_playing = true; 3305 m_playing = true;
3306 3306
3307 } else { // Should not be playing right now 3307 } else { // Should not be playing right now
3308 if (!playerPaused) 3308 if (isPlaying)
3309 m_player->pause(); 3309 webMediaPlayer()->pause();
3310 refreshCachedTime(); 3310 refreshCachedTime();
3311 3311
3312 m_playbackProgressTimer.stop(); 3312 m_playbackProgressTimer.stop();
3313 m_playing = false; 3313 m_playing = false;
3314 double time = currentTime(); 3314 double time = currentTime();
3315 if (time > m_lastSeekTime) 3315 if (time > m_lastSeekTime)
3316 addPlayedRange(m_lastSeekTime, time); 3316 addPlayedRange(m_lastSeekTime, time);
3317 3317
3318 if (couldPlayIfEnoughData()) 3318 if (couldPlayIfEnoughData())
3319 prepareToPlay(); 3319 prepareToPlay();
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
3969 3969
3970 #if ENABLE(WEB_AUDIO) 3970 #if ENABLE(WEB_AUDIO)
3971 void HTMLMediaElement::clearWeakMembers(Visitor* visitor) 3971 void HTMLMediaElement::clearWeakMembers(Visitor* visitor)
3972 { 3972 {
3973 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider()) 3973 if (!visitor->isAlive(m_audioSourceNode) && audioSourceProvider())
3974 audioSourceProvider()->setClient(0); 3974 audioSourceProvider()->setClient(0);
3975 } 3975 }
3976 #endif 3976 #endif
3977 3977
3978 } 3978 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLMediaElement.h ('k') | Source/platform/graphics/media/MediaPlayer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698