Commit 075c9e95 authored by Antonio Rivera's avatar Antonio Rivera Committed by Commit Bot

Move monotonic clock logic out of MediaPipelineBackendForMixer.

Currently there are two nearly-identical declarations/definitions of
MonotonicClockNow: one in MediaPipelineBackendForMixer, and one in
internal chromecast code. With this change, we can use the same function
for both use cases to avoid repeated code.

Test: cast_audio_backend_unittests pass
Bug: b/139928913
Change-Id: Ibe2216b92a0a8f6529297c7ffe35220cad871046
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1771053Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Commit-Queue: Antonio Rivera <antoniori@google.com>
Auto-Submit: Antonio Rivera <antoniori@google.com>
Cr-Commit-Position: refs/heads/master@{#690830}
parent 0cd9b778
......@@ -2,9 +2,16 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/buildflag_header.gni")
import("//chromecast/chromecast.gni")
import("//third_party/widevine/cdm/widevine.gni")
buildflag_header("buildflags") {
header = "buildflags.h"
flags = [ "MEDIA_CLOCK_MONOTONIC_RAW=$media_clock_monotonic_raw" ]
}
cast_source_set("key_systems") {
sources = [
"key_systems_common.cc",
......@@ -109,3 +116,14 @@ cast_source_set("video_plane_controller") {
"//ui/gfx/geometry",
]
}
cast_source_set("monotonic_clock") {
sources = [
"monotonic_clock.cc",
"monotonic_clock.h",
]
deps = [
":buildflags",
"//base",
]
}
// Copyright 2019 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.
#include "chromecast/media/base/monotonic_clock.h"
#include <time.h>
#include "base/time/time.h"
#include "build/build_config.h"
#if defined(OS_ANDROID) || defined(OS_LINUX)
#include "chromecast/media/base/buildflags.h"
#endif // defined(OS_ANDROID) || defined(OS_LINUX)
#if defined(OS_FUCHSIA)
#include <zircon/syscalls.h>
#endif // defined(OS_FUCHSIA)
namespace chromecast {
namespace media {
#if defined(OS_ANDROID) || defined(OS_LINUX)
int64_t MonotonicClockNow() {
timespec now = {0, 0};
#if BUILDFLAG(MEDIA_CLOCK_MONOTONIC_RAW)
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
#else
clock_gettime(CLOCK_MONOTONIC, &now);
#endif // MEDIA_CLOCK_MONOTONIC_RAW
return base::TimeDelta::FromTimeSpec(now).InMicroseconds();
}
#elif defined(OS_FUCHSIA)
int64_t MonotonicClockNow() {
return zx_clock_get_monotonic() / 1000;
}
#endif
DefaultMonotonicClock::DefaultMonotonicClock() = default;
DefaultMonotonicClock::~DefaultMonotonicClock() = default;
int64_t DefaultMonotonicClock::Now() {
return MonotonicClockNow();
}
} // namespace media
} // namespace chromecast
// Copyright 2019 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.
#ifndef CHROMECAST_MEDIA_BASE_MONOTONIC_CLOCK_H_
#define CHROMECAST_MEDIA_BASE_MONOTONIC_CLOCK_H_
#include <stdint.h>
namespace chromecast {
namespace media {
// Returns the monotonic time (from CLOCK_MONOTONIC) in microseconds.
// Why not use base::TimeTicks? Because we explicitly need time from
// CLOCK_MONOTONIC to match the timestamps from CMA GetRenderingDelay(), and
// base::TimeTicks has no guarantees about which clock it uses (and it could
// change whenever they feel like it upstream).
int64_t MonotonicClockNow();
// Interface that provides the monotonic time.
class MonotonicClock {
public:
virtual ~MonotonicClock() = default;
// Returns the monotonic time in microseconds.
virtual int64_t Now() = 0;
};
// Default implementation of MonotonicClock that uses MonotonicClockNow().
class DefaultMonotonicClock : public MonotonicClock {
public:
DefaultMonotonicClock();
~DefaultMonotonicClock() override;
// MonotonicClock implementation:
int64_t Now() override;
};
} // namespace media
} // namespace chromecast
#endif // CHROMECAST_MEDIA_BASE_MONOTONIC_CLOCK_H_
......@@ -297,6 +297,7 @@ cast_source_set("for_mixer_audio") {
"//chromecast/base:thread_health_checker",
"//chromecast/media/audio:libcast_external_audio_pipeline_1.0",
"//chromecast/media/base",
"//chromecast/media/base:monotonic_clock",
"//chromecast/media/cma/base",
"//chromecast/media/cma/decoder",
"//chromecast/public",
......
......@@ -5,25 +5,18 @@
#include "chromecast/media/cma/backend/media_pipeline_backend_for_mixer.h"
#include <time.h>
#include <limits>
#include "base/bind.h"
#include "base/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chromecast/base/task_runner_impl.h"
#include "chromecast/media/base/monotonic_clock.h"
#include "chromecast/media/cma/backend/audio_decoder_for_mixer.h"
#include "chromecast/media/cma/backend/av_sync.h"
#include "chromecast/media/cma/backend/video_decoder_for_mixer.h"
#if defined(OS_LINUX)
#include "chromecast/media/cma/backend/audio_buildflags.h"
#endif // defined(OS_LINUX)
#if defined(OS_FUCHSIA)
#include <zircon/syscalls.h>
#endif // defined(OS_FUCHSIA)
namespace {
// Delay video playback to achieve AV sync when video starts.
......@@ -239,21 +232,9 @@ MediaPipelineBackendForMixer::GetTaskRunner() const {
return static_cast<TaskRunnerImpl*>(params_.task_runner)->runner();
}
#if defined(OS_LINUX)
int64_t MediaPipelineBackendForMixer::MonotonicClockNow() const {
timespec now = {0, 0};
#if BUILDFLAG(MEDIA_CLOCK_MONOTONIC_RAW)
clock_gettime(CLOCK_MONOTONIC_RAW, &now);
#else
clock_gettime(CLOCK_MONOTONIC, &now);
#endif // MEDIA_CLOCK_MONOTONIC_RAW
return base::TimeDelta::FromTimeSpec(now).InMicroseconds();
}
#elif defined(OS_FUCHSIA)
int64_t MediaPipelineBackendForMixer::MonotonicClockNow() const {
return zx_clock_get_monotonic() / 1000;
return media::MonotonicClockNow();
}
#endif
bool MediaPipelineBackendForMixer::IsIgnorePtsMode() const {
return params_.sync_type ==
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment