Merge "Remove obsolete media_{codec,profiles}*.xml files" into cuttlefish-testing
diff --git a/common/libs/utils/Android.bp b/common/libs/utils/Android.bp
index 11c54aa..1551515 100644
--- a/common/libs/utils/Android.bp
+++ b/common/libs/utils/Android.bp
@@ -33,3 +33,11 @@
],
defaults: ["cuttlefish_host_and_guest"],
}
+
+cc_test {
+ name: "cuttlefish_simulated_buffer_test",
+ srcs: ["simulated_buffer_test.cpp"],
+ shared_libs: ["libcuttlefish_utils"],
+ gtest: true,
+ defaults: ["cuttlefish_host_only"],
+}
diff --git a/guest/hals/audio/simulated_buffer.h b/common/libs/utils/simulated_buffer.h
similarity index 100%
rename from guest/hals/audio/simulated_buffer.h
rename to common/libs/utils/simulated_buffer.h
diff --git a/common/libs/utils/simulated_buffer_test.cpp b/common/libs/utils/simulated_buffer_test.cpp
new file mode 100644
index 0000000..c3fbe49
--- /dev/null
+++ b/common/libs/utils/simulated_buffer_test.cpp
@@ -0,0 +1,442 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "common/libs/utils/simulated_buffer.h"
+#include <gtest/gtest.h>
+
+using cvd::time::MonotonicTimePoint;
+using cvd::time::MonotonicTimePointFactory;
+using cvd::time::Seconds;
+using cvd::time::Milliseconds;
+using cvd::time::Nanoseconds;
+using cvd::time::kNanosecondsPerSecond;
+
+class MockTimepointFactory : public MonotonicTimePointFactory {
+ public:
+ virtual void FetchCurrentTime(MonotonicTimePoint* dest) const override {
+ *dest = system_time_;
+ }
+
+ void SetTime(const MonotonicTimePoint& in) {
+ system_time_ = in;
+ }
+
+ protected:
+ MonotonicTimePoint system_time_;
+};
+
+template <typename T> class MockSimulatedBuffer : public T {
+ public:
+ MockSimulatedBuffer(
+ int64_t sample_rate,
+ int64_t capacity,
+ MockTimepointFactory* factory) :
+ T(sample_rate, capacity, factory),
+ factory_(factory) { }
+
+ void FetchCurrentTime(MonotonicTimePoint* dest) const {
+ return factory_->FetchCurrentTime(dest);
+ }
+
+ void SleepUntilTime(const MonotonicTimePoint& tick) {
+ factory_->SetTime(tick);
+ }
+
+ protected:
+ // Save a redundant pointer to avoid downcasting
+ MockTimepointFactory* factory_;
+};
+
+static const int64_t kItemRate = 48000;
+static const int64_t kBufferCapacity = 4800;
+
+class SimulatedBufferTest : public ::testing::Test {
+ public:
+ MockTimepointFactory clock;
+ MockSimulatedBuffer<SimulatedBufferBase> buffer;
+
+ SimulatedBufferTest() : buffer(kItemRate, kBufferCapacity, &clock) { }
+};
+
+TEST_F(SimulatedBufferTest, TimeMocking) {
+ // Ensure that the mocked clock starts at the epoch.
+ MonotonicTimePoint epoch_time;
+ MonotonicTimePoint actual_time;
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(epoch_time, actual_time);
+
+ // Ensure that sleeping works
+ MonotonicTimePoint test_time = actual_time + Seconds(10);
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+
+ // Try one more sleep to make sure that time moves forward
+ test_time += Seconds(5);
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+}
+
+TEST_F(SimulatedBufferTest, ItemScaling) {
+ // Make certain that we start at item 0
+ EXPECT_EQ(0, buffer.GetCurrentItemNum());
+
+ // Make certain that the expected number of items appear in 1 second
+ MonotonicTimePoint actual_time;
+ buffer.FetchCurrentTime(&actual_time);
+ MonotonicTimePoint test_time = actual_time + Seconds(1);
+ buffer.SleepUntilTime(test_time);
+ EXPECT_EQ(kItemRate, buffer.GetCurrentItemNum());
+
+ // Sleep an additional 10 seconds to make certain that the item numbers
+ // increment
+ test_time += Seconds(10);
+ buffer.SleepUntilTime(test_time);
+ EXPECT_EQ(11 * kItemRate, buffer.GetCurrentItemNum());
+
+ // Make certain that partial seconds work
+ test_time += Milliseconds(1500);
+ buffer.SleepUntilTime(test_time);
+ EXPECT_EQ(12.5 * kItemRate, buffer.GetCurrentItemNum());
+
+ // Make certain that we don't get new items when paused
+ buffer.SetPaused(true);
+ test_time += Seconds(10);
+ buffer.SleepUntilTime(test_time);
+ EXPECT_EQ(12.5 * kItemRate, buffer.GetCurrentItemNum());
+
+ // Make certain that we start getting items when pausing stops
+ buffer.SetPaused(false);
+ test_time += Milliseconds(500);
+ buffer.SleepUntilTime(test_time);
+ EXPECT_EQ(13 * kItemRate, buffer.GetCurrentItemNum());
+}
+
+TEST_F(SimulatedBufferTest, ItemSleeping) {
+ // See if sleeping on an time causes the right amount of time to pass
+ EXPECT_EQ(0, buffer.GetCurrentItemNum());
+ MonotonicTimePoint base_time;
+ buffer.FetchCurrentTime(&base_time);
+
+ // Wait for 1500ms worth of samples
+ buffer.SleepUntilItem(kItemRate * 1500 / 1000);
+ EXPECT_EQ(kItemRate * 1500 / 1000, buffer.GetCurrentItemNum());
+ MonotonicTimePoint actual_time;
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(1500, Milliseconds(actual_time - base_time).count());
+
+ // Now wait again for more samples
+ buffer.SleepUntilItem(kItemRate * 2500 / 1000);
+ EXPECT_EQ(kItemRate * 2500 / 1000, buffer.GetCurrentItemNum());
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(2500, Milliseconds(actual_time - base_time).count());
+}
+
+class OutputBufferTest : public ::testing::Test {
+ public:
+ MockTimepointFactory clock;
+ MockSimulatedBuffer<SimulatedOutputBuffer> buffer;
+
+ OutputBufferTest() : buffer(kItemRate, kBufferCapacity, &clock) { }
+};
+
+TEST_F(OutputBufferTest, NonBlockingQueueing) {
+ int64_t half_buffer = kBufferCapacity / 2;
+ EXPECT_EQ(0, buffer.GetCurrentItemNum());
+
+ // Filling half of the buffer should not block
+ MonotonicTimePoint test_time;
+ buffer.FetchCurrentTime(&test_time);
+ EXPECT_EQ(half_buffer, buffer.AddToOutputBuffer(half_buffer, false));
+ MonotonicTimePoint actual_time;
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(half_buffer, buffer.GetOutputBufferSize());
+
+ // Filling all but one entry of the buffer should not block
+ EXPECT_EQ(half_buffer - 1,
+ buffer.AddToOutputBuffer(half_buffer - 1, false));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity - 1, buffer.GetOutputBufferSize());
+
+ // Filling the entire buffer should not block
+ EXPECT_EQ(1, buffer.AddToOutputBuffer(half_buffer, false));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(actual_time, test_time);
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+
+ // The buffer should reject additional data but not block
+ EXPECT_EQ(0, buffer.AddToOutputBuffer(half_buffer, false));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+
+ // One quarter of the buffer should drain in the expected time
+ Nanoseconds quarter_drain_time(
+ kBufferCapacity / 4 * kNanosecondsPerSecond / kItemRate);
+ test_time += quarter_drain_time;
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(actual_time, test_time);
+ EXPECT_EQ(kBufferCapacity * 3 / 4, buffer.GetOutputBufferSize());
+
+ // The buffer should now accept new data without blocking
+ EXPECT_EQ(kBufferCapacity / 4,
+ buffer.AddToOutputBuffer(half_buffer, false));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+
+ // Now that the buffer is full it should reject additional data but
+ // not block
+ EXPECT_EQ(0, buffer.AddToOutputBuffer(half_buffer, false));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+
+ // Wait for 3/4 of the buffer to drain
+ test_time += Nanoseconds(3 * quarter_drain_time.count());
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity / 4, buffer.GetOutputBufferSize());
+
+ // The entire buffer should drain on schedule
+ test_time += Nanoseconds(quarter_drain_time.count() - 1);
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(1, buffer.GetOutputBufferSize());
+ test_time += Nanoseconds(1);
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(0, buffer.GetOutputBufferSize());
+
+ // It should be possible to fill the buffer in a single shot
+ EXPECT_EQ(kBufferCapacity,
+ buffer.AddToOutputBuffer(kBufferCapacity, false));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+
+ // The buffer shouldn't accept additional data but shouldn't block
+ EXPECT_EQ(0, buffer.AddToOutputBuffer(1, false));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+
+ // The buffer should underflow sanely
+ test_time += Nanoseconds(6 * quarter_drain_time.count());
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(0, buffer.GetOutputBufferSize());
+
+ // The underflow shouldn't increase the buffer's capacity
+ EXPECT_EQ(kBufferCapacity,
+ buffer.AddToOutputBuffer(kBufferCapacity + 1, false));
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+}
+
+TEST_F(OutputBufferTest, BlockingQueueing) {
+ int64_t half_buffer = kBufferCapacity / 2;
+
+ // Check the initial setup
+ EXPECT_EQ(0, buffer.GetCurrentItemNum());
+ MonotonicTimePoint test_time;
+ buffer.FetchCurrentTime(&test_time);
+
+ // Filling half the buffer works without blocking
+ EXPECT_EQ(half_buffer, buffer.AddToOutputBuffer(half_buffer, true));
+ MonotonicTimePoint actual_time;
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(half_buffer, buffer.GetOutputBufferSize());
+
+ // Filling all but one entry of the buffer also works without blocking
+ EXPECT_EQ(half_buffer - 1,
+ buffer.AddToOutputBuffer(half_buffer - 1, true));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity - 1, buffer.GetOutputBufferSize());
+
+ // Putting the last sample into the buffer doesn't block
+ EXPECT_EQ(1, buffer.AddToOutputBuffer(1, true));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+
+ // Putting more data into the buffer causes blocking
+ EXPECT_EQ(half_buffer, buffer.AddToOutputBuffer(half_buffer, true));
+ Nanoseconds half_drain_time(
+ ((kBufferCapacity / 2) * kNanosecondsPerSecond + kItemRate - 1) /
+ kItemRate);
+ Nanoseconds quarter_drain_time(half_drain_time.count() / 2);
+ test_time += half_drain_time;
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+
+ // The buffer drains as expected
+ test_time += quarter_drain_time;
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity * 3 / 4, buffer.GetOutputBufferSize());
+
+ // Overfilling the drained buffer also causes blocking
+ EXPECT_EQ(half_buffer, buffer.AddToOutputBuffer(half_buffer, true));
+ test_time += quarter_drain_time;
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+
+ // The buffer drains on schedule
+ test_time += Nanoseconds(half_drain_time.count() * 2 - 1);
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(1, buffer.GetOutputBufferSize());
+ test_time += Nanoseconds(1);
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(0, buffer.GetOutputBufferSize());
+
+ // It's possible to fill the entire output buffer in 1 shot without blocking
+ EXPECT_EQ(kBufferCapacity,
+ buffer.AddToOutputBuffer(kBufferCapacity, true));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+
+ // Adding a single extra sample causes some blocking
+ EXPECT_EQ(1, buffer.AddToOutputBuffer(1, true));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_LT(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity, buffer.GetOutputBufferSize());
+}
+
+class InputBufferTest : public ::testing::Test {
+ public:
+ MockTimepointFactory clock;
+ MockSimulatedBuffer<SimulatedInputBuffer> buffer;
+
+ InputBufferTest() : buffer(kItemRate, kBufferCapacity, &clock) { }
+};
+
+TEST_F(InputBufferTest, NonBlockingInput) {
+ Nanoseconds quarter_fill_time(kBufferCapacity / 4 * kNanosecondsPerSecond /
+ kItemRate);
+ // Verify that the buffer starts empty
+ EXPECT_EQ(0, buffer.GetCurrentItemNum());
+ MonotonicTimePoint actual_time;
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(0, buffer.RemoveFromInputBuffer(kBufferCapacity, false));
+ EXPECT_EQ(0, buffer.GetLostInputItems());
+
+ // Wait for 1/4 of the buffer to fill
+ MonotonicTimePoint test_time = actual_time + quarter_fill_time;
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(0, buffer.GetLostInputItems());
+
+ // Verify that we can read the samples in two groups
+ EXPECT_EQ(kBufferCapacity / 8,
+ buffer.RemoveFromInputBuffer(kBufferCapacity / 8, false));
+ EXPECT_EQ(kBufferCapacity / 8,
+ buffer.RemoveFromInputBuffer(kBufferCapacity, false));
+
+ // Verify that there are no samples left and that we did not block
+ EXPECT_EQ(0, buffer.RemoveFromInputBuffer(kBufferCapacity, false));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+
+ // Verify that the buffer fills on schedule
+ test_time += Nanoseconds(4 * quarter_fill_time.count() - 1);
+ buffer.SleepUntilTime(test_time);
+ EXPECT_EQ(kBufferCapacity - 1,
+ buffer.RemoveFromInputBuffer(kBufferCapacity, false));
+ test_time += Nanoseconds(1);
+ buffer.SleepUntilTime(test_time);
+ EXPECT_EQ(1, buffer.RemoveFromInputBuffer(kBufferCapacity, false));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(0, buffer.GetLostInputItems());
+
+ // Verify that the buffer overflows as expected
+ test_time += Nanoseconds(5 * quarter_fill_time.count());
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity / 4, buffer.GetLostInputItems());
+ EXPECT_EQ(0, buffer.GetLostInputItems());
+
+ EXPECT_EQ(kBufferCapacity,
+ buffer.RemoveFromInputBuffer(2 * kBufferCapacity, false));
+ EXPECT_EQ(0, buffer.RemoveFromInputBuffer(kBufferCapacity, false));
+}
+
+TEST_F(InputBufferTest, BlockingInput) {
+ Nanoseconds quarter_fill_time(kBufferCapacity / 4 * kNanosecondsPerSecond /
+ kItemRate);
+ // Verify that the buffer starts empty
+ EXPECT_EQ(0, buffer.GetCurrentItemNum());
+ MonotonicTimePoint actual_time;
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(0, buffer.GetLostInputItems());
+
+ // Wait for 1/4 of the buffer to fill
+ MonotonicTimePoint test_time = actual_time + quarter_fill_time;
+ EXPECT_EQ(kBufferCapacity / 4,
+ buffer.RemoveFromInputBuffer(kBufferCapacity / 4, true));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(0, buffer.GetLostInputItems());
+
+ // Verify that the buffer fills on schedule
+ test_time += Nanoseconds(4 * quarter_fill_time.count());
+ EXPECT_EQ(kBufferCapacity,
+ buffer.RemoveFromInputBuffer(kBufferCapacity, true));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(0, buffer.GetLostInputItems());
+
+ // Verify that the buffer overflows as expected
+ test_time += Nanoseconds(5 * quarter_fill_time.count());
+ buffer.SleepUntilTime(test_time);
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+ EXPECT_EQ(kBufferCapacity / 4, buffer.GetLostInputItems());
+ EXPECT_EQ(0, buffer.GetLostInputItems());
+ EXPECT_EQ(kBufferCapacity,
+ buffer.RemoveFromInputBuffer(kBufferCapacity, true));
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+
+ // Verify that reads bigger than the buffer work as expected
+ test_time += Nanoseconds(8 * quarter_fill_time.count());
+ EXPECT_EQ(kBufferCapacity * 2,
+ buffer.RemoveFromInputBuffer(kBufferCapacity * 2, true));
+ EXPECT_EQ(0, buffer.GetLostInputItems());
+ buffer.FetchCurrentTime(&actual_time);
+ EXPECT_EQ(test_time, actual_time);
+}
diff --git a/guest/hals/audio/vsoc_audio_input_stream.h b/guest/hals/audio/vsoc_audio_input_stream.h
index 40d6b19..5673676 100644
--- a/guest/hals/audio/vsoc_audio_input_stream.h
+++ b/guest/hals/audio/vsoc_audio_input_stream.h
@@ -17,9 +17,9 @@
#include <memory>
+#include "common/libs/utils/simulated_buffer.h"
#include "common/vsoc/lib/vsoc_audio_message.h"
#include "guest/hals/audio/audio_hal.h"
-#include "guest/hals/audio/simulated_buffer.h"
namespace cvd {
diff --git a/guest/hals/audio/vsoc_audio_output_stream.h b/guest/hals/audio/vsoc_audio_output_stream.h
index 14ea2f4..6b8a1e6 100644
--- a/guest/hals/audio/vsoc_audio_output_stream.h
+++ b/guest/hals/audio/vsoc_audio_output_stream.h
@@ -17,9 +17,9 @@
#include <memory>
+#include "common/libs/utils/simulated_buffer.h"
#include "common/vsoc/lib/vsoc_audio_message.h"
#include "guest/hals/audio/audio_hal.h"
-#include "guest/hals/audio/simulated_buffer.h"
namespace cvd {
diff --git a/guest/hals/hwcomposer/Android.mk b/guest/hals/hwcomposer/vsoc-future/Android.mk
similarity index 100%
rename from guest/hals/hwcomposer/Android.mk
rename to guest/hals/hwcomposer/vsoc-future/Android.mk
diff --git a/guest/hals/hwcomposer/hwcomposer.cpp b/guest/hals/hwcomposer/vsoc-future/hwcomposer.cpp
similarity index 100%
rename from guest/hals/hwcomposer/hwcomposer.cpp
rename to guest/hals/hwcomposer/vsoc-future/hwcomposer.cpp
diff --git a/guest/hals/hwcomposer/legacy/Android.mk b/guest/hals/hwcomposer/vsoc/Android.mk
similarity index 100%
rename from guest/hals/hwcomposer/legacy/Android.mk
rename to guest/hals/hwcomposer/vsoc/Android.mk
diff --git a/guest/hals/hwcomposer/legacy/base_composer.cpp b/guest/hals/hwcomposer/vsoc/base_composer.cpp
similarity index 100%
rename from guest/hals/hwcomposer/legacy/base_composer.cpp
rename to guest/hals/hwcomposer/vsoc/base_composer.cpp
diff --git a/guest/hals/hwcomposer/legacy/base_composer.h b/guest/hals/hwcomposer/vsoc/base_composer.h
similarity index 98%
rename from guest/hals/hwcomposer/legacy/base_composer.h
rename to guest/hals/hwcomposer/vsoc/base_composer.h
index 9e8d10c..f3467ef 100644
--- a/guest/hals/hwcomposer/legacy/base_composer.h
+++ b/guest/hals/hwcomposer/vsoc/base_composer.h
@@ -18,7 +18,7 @@
#include <functional>
#include <hardware/gralloc.h>
-#include "hwcomposer_common.h"
+#include "hwcomposer.h"
namespace cvd {
diff --git a/guest/hals/hwcomposer/legacy/geometry_utils.cpp b/guest/hals/hwcomposer/vsoc/geometry_utils.cpp
similarity index 100%
rename from guest/hals/hwcomposer/legacy/geometry_utils.cpp
rename to guest/hals/hwcomposer/vsoc/geometry_utils.cpp
diff --git a/guest/hals/hwcomposer/legacy/geometry_utils.h b/guest/hals/hwcomposer/vsoc/geometry_utils.h
similarity index 95%
rename from guest/hals/hwcomposer/legacy/geometry_utils.h
rename to guest/hals/hwcomposer/vsoc/geometry_utils.h
index b6a037b..937283f 100644
--- a/guest/hals/hwcomposer/legacy/geometry_utils.h
+++ b/guest/hals/hwcomposer/vsoc/geometry_utils.h
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-#include "hwcomposer_common.h"
+#include "hwcomposer.h"
namespace cvd {
diff --git a/guest/hals/hwcomposer/legacy/hwcomposer.cpp b/guest/hals/hwcomposer/vsoc/hwcomposer.cpp
similarity index 98%
rename from guest/hals/hwcomposer/legacy/hwcomposer.cpp
rename to guest/hals/hwcomposer/vsoc/hwcomposer.cpp
index 9711656..1c33d3a 100644
--- a/guest/hals/hwcomposer/legacy/hwcomposer.cpp
+++ b/guest/hals/hwcomposer/vsoc/hwcomposer.cpp
@@ -59,7 +59,7 @@
#include "base_composer.h"
#include "geometry_utils.h"
-#include "hwcomposer_common.h"
+#include "hwcomposer.h"
#include "stats_keeper.h"
#include "vsoc_composer.h"
@@ -350,8 +350,10 @@
(struct vsoc_hwc_composer_device_1_t*)data;
setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
+ int64_t nanoseconds = static_cast<int64_t>(1e9);
+
int64_t base_timestamp = pdev->vsync_base_timestamp;
- int64_t last_logged = base_timestamp / 1e9;
+ int64_t last_logged = base_timestamp / nanoseconds;
int sent = 0;
int last_sent = 0;
static const int log_interval = 60;
@@ -363,13 +365,13 @@
ALOGE("%s:%d error in vsync thread clock_gettime: %s", __FILE__, __LINE__,
strerror(errno));
}
- int64_t timestamp = int64_t(rt.tv_sec) * 1e9 + rt.tv_nsec;
+ int64_t timestamp = int64_t(rt.tv_sec) * nanoseconds + rt.tv_nsec;
// Given now's timestamp calculate the time of the next timestamp.
timestamp += pdev->vsync_period_ns -
(timestamp - base_timestamp) % pdev->vsync_period_ns;
- rt.tv_sec = timestamp / 1e9;
- rt.tv_nsec = timestamp % static_cast<int32_t>(1e9);
+ rt.tv_sec = timestamp / nanoseconds;
+ rt.tv_nsec = timestamp % static_cast<int32_t>(nanoseconds);
int err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &rt, NULL);
if (err == -1) {
ALOGE("error in vsync thread: %s", strerror(errno));
diff --git a/guest/hals/hwcomposer/legacy/hwcomposer_common.h b/guest/hals/hwcomposer/vsoc/hwcomposer.h
similarity index 100%
rename from guest/hals/hwcomposer/legacy/hwcomposer_common.h
rename to guest/hals/hwcomposer/vsoc/hwcomposer.h
diff --git a/guest/hals/hwcomposer/legacy/hwcomposer.mk b/guest/hals/hwcomposer/vsoc/hwcomposer.mk
similarity index 100%
rename from guest/hals/hwcomposer/legacy/hwcomposer.mk
rename to guest/hals/hwcomposer/vsoc/hwcomposer.mk
diff --git a/guest/hals/hwcomposer/legacy/stats_keeper.cpp b/guest/hals/hwcomposer/vsoc/stats_keeper.cpp
similarity index 100%
rename from guest/hals/hwcomposer/legacy/stats_keeper.cpp
rename to guest/hals/hwcomposer/vsoc/stats_keeper.cpp
diff --git a/guest/hals/hwcomposer/legacy/stats_keeper.h b/guest/hals/hwcomposer/vsoc/stats_keeper.h
similarity index 99%
rename from guest/hals/hwcomposer/legacy/stats_keeper.h
rename to guest/hals/hwcomposer/vsoc/stats_keeper.h
index c813920..e1dd330 100644
--- a/guest/hals/hwcomposer/legacy/stats_keeper.h
+++ b/guest/hals/hwcomposer/vsoc/stats_keeper.h
@@ -24,7 +24,7 @@
#include "common/libs/time/monotonic_time.h"
#include "common/vsoc/lib/screen_region_view.h"
-#include "hwcomposer_common.h"
+#include "hwcomposer.h"
namespace cvd {
diff --git a/guest/hals/hwcomposer/legacy/vsoc_composer.cpp b/guest/hals/hwcomposer/vsoc/vsoc_composer.cpp
similarity index 99%
rename from guest/hals/hwcomposer/legacy/vsoc_composer.cpp
rename to guest/hals/hwcomposer/vsoc/vsoc_composer.cpp
index 179e930..33b08e1 100644
--- a/guest/hals/hwcomposer/legacy/vsoc_composer.cpp
+++ b/guest/hals/hwcomposer/vsoc/vsoc_composer.cpp
@@ -30,7 +30,6 @@
#include "common/vsoc/lib/screen_region_view.h"
#include "geometry_utils.h"
-#include "hwcomposer_common.h"
using vsoc::screen::ScreenRegionView;
diff --git a/guest/hals/hwcomposer/legacy/vsoc_composer.h b/guest/hals/hwcomposer/vsoc/vsoc_composer.h
similarity index 97%
rename from guest/hals/hwcomposer/legacy/vsoc_composer.h
rename to guest/hals/hwcomposer/vsoc/vsoc_composer.h
index 48f290f..0e8e2c2 100644
--- a/guest/hals/hwcomposer/legacy/vsoc_composer.h
+++ b/guest/hals/hwcomposer/vsoc/vsoc_composer.h
@@ -22,7 +22,7 @@
#include "guest/hals/gralloc/legacy/gralloc_vsoc_priv.h"
#include "base_composer.h"
-#include "hwcomposer_common.h"
+#include "hwcomposer.h"
namespace cvd {