Home | History | Annotate | Download | only in base
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef MEDIA_BASE_TIME_SOURCE_H_
      6 #define MEDIA_BASE_TIME_SOURCE_H_
      7 
      8 #include "base/time/time.h"
      9 #include "media/base/media_export.h"
     10 
     11 namespace media {
     12 
     13 // A TimeSource is capable of providing the current media time.
     14 class MEDIA_EXPORT TimeSource {
     15  public:
     16   TimeSource() {}
     17   virtual ~TimeSource() {}
     18 
     19   // Signal the time source to start ticking. It is expected that values from
     20   // CurrentMediaTime() will start increasing.
     21   virtual void StartTicking() = 0;
     22 
     23   // Signal the time source to stop ticking. It is expected that values from
     24   // CurrentMediaTime() will remain constant.
     25   virtual void StopTicking() = 0;
     26 
     27   // Updates the current playback rate. It is expected that values from
     28   // CurrentMediaTime() will eventually reflect the new playback rate (e.g., the
     29   // media time will advance at half speed if the rate was set to 0.5f).
     30   virtual void SetPlaybackRate(float playback_rate) = 0;
     31 
     32   // Sets the media time to start ticking from. Only valid to call while the
     33   // time source is not ticking.
     34   virtual void SetMediaTime(base::TimeDelta time) = 0;
     35 
     36   // Returns the current media time.
     37   //
     38   // Values returned are intended for informational purposes, such as displaying
     39   // UI with the current minute and second count. While it is guaranteed values
     40   // will never go backwards, the frequency at which they update may be low.
     41   virtual base::TimeDelta CurrentMediaTime() = 0;
     42 
     43   // Returns the current media time for use with synchronizing video.
     44   //
     45   // Differences from CurrentMediaTime():
     46   //   - Values returned update at a much higher frequency (e.g., suitable for
     47   //     playback of 60 FPS content).
     48   //   - As a result, values may go slightly backwards depending on the
     49   //     implementation (e.g., uses interpolation).
     50   //
     51   // TODO(scherkus): Replace with a method that returns wall clock time for a
     52   // given media time for use with VideoFrameScheduler http://crbug.com/110814
     53   virtual base::TimeDelta CurrentMediaTimeForSyncingVideo() = 0;
     54 };
     55 
     56 }  // namespace media
     57 
     58 #endif  // MEDIA_BASE_TIME_SOURCE_H_
     59