summaryrefslogtreecommitdiffstats
path: root/media/base/synchronizer.h
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-30 04:56:46 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-30 04:56:46 +0000
commit7663e411f3f65fb232093cb3b078a5ef733562e6 (patch)
treed66fd4f5601890e64f104eec26814fe912ff899d /media/base/synchronizer.h
parent6dd72b0e175e27c261ff887e1f760649d8665136 (diff)
downloadchromium_src-7663e411f3f65fb232093cb3b078a5ef733562e6.zip
chromium_src-7663e411f3f65fb232093cb3b078a5ef733562e6.tar.gz
chromium_src-7663e411f3f65fb232093cb3b078a5ef733562e6.tar.bz2
Checking in media::Synchronizer, a utility class to facilitate A/V synchronization.
Review URL: http://codereview.chromium.org/19693 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8950 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/synchronizer.h')
-rw-r--r--media/base/synchronizer.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/media/base/synchronizer.h b/media/base/synchronizer.h
new file mode 100644
index 0000000..122c32f
--- /dev/null
+++ b/media/base/synchronizer.h
@@ -0,0 +1,59 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Utility class for video renderers to help synchronize against a reference
+// clock while also taking rendering duration into account.
+//
+// Video renderers should maintain an instance of this object for the entire
+// lifetime since Synchronizer maintains internal state to improve playback.
+//
+// VideoRenderer usage is as follows:
+// Receive a new frame from the decoder
+// Call StartRendering
+// Perform colour space conversion and render the frame
+// Call StopRendering
+// Call CalculateDelay passing in the rendered frame and optional next frame
+// Issue delayed task or sleep on thread for returned amount of time
+
+#ifndef MEDIA_BASE_SYNCHRONIZER_H_
+#define MEDIA_BASE_SYNCHRONIZER_H_
+
+#include "base/basictypes.h"
+#include "base/time.h"
+#include "media/base/buffers.h"
+
+namespace media {
+
+class Synchronizer {
+ public:
+ Synchronizer();
+ ~Synchronizer();
+
+ // Starts the rendering timer.
+ void StartRendering();
+
+ // Stops the rendering timer.
+ void StopRendering();
+
+ // Calculates the appropriate amount of delay in microseconds given the
+ // current time, the current sample and the next sample (may be NULL,
+ // but is recommended to pass in for smoother playback).
+ void CalculateDelay(base::TimeDelta time, const StreamSample* now,
+ const StreamSample* next, base::TimeDelta* delay_out,
+ bool* should_skip_out);
+
+ private:
+ static const int64 kMinFrameDelayUs;
+ static const int64 kMaxFrameDelayUs;
+
+ base::TimeTicks rendering_start_;
+ base::TimeTicks rendering_stop_;
+ base::TimeDelta last_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(Synchronizer);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_SYNCHRONIZER_H_