1#include "include/private/dvr/vsync_client.h"
2
3#include <log/log.h>
4
5#include <pdx/default_transport/client_channel_factory.h>
6#include <private/dvr/display_protocol.h>
7
8using android::dvr::display::VSyncProtocol;
9using android::pdx::Transaction;
10
11namespace android {
12namespace dvr {
13
14VSyncClient::VSyncClient(long timeout_ms)
15    : BASE(pdx::default_transport::ClientChannelFactory::Create(
16               VSyncProtocol::kClientPath),
17           timeout_ms) {}
18
19VSyncClient::VSyncClient()
20    : BASE(pdx::default_transport::ClientChannelFactory::Create(
21          VSyncProtocol::kClientPath)) {}
22
23int VSyncClient::Wait(int64_t* timestamp_ns) {
24  auto status = InvokeRemoteMethod<VSyncProtocol::Wait>();
25  if (!status) {
26    ALOGE("VSyncClient::Wait: Failed to wait for vsync: %s",
27          status.GetErrorMessage().c_str());
28    return -status.error();
29  }
30
31  if (timestamp_ns != nullptr) {
32    *timestamp_ns = status.get();
33  }
34  return 0;
35}
36
37int VSyncClient::GetFd() { return event_fd(); }
38
39int VSyncClient::GetLastTimestamp(int64_t* timestamp_ns) {
40  auto status = InvokeRemoteMethod<VSyncProtocol::GetLastTimestamp>();
41  if (!status) {
42    ALOGE("VSyncClient::GetLastTimestamp: Failed to get vsync timestamp: %s",
43          status.GetErrorMessage().c_str());
44    return -status.error();
45  }
46  *timestamp_ns = status.get();
47  return 0;
48}
49
50int VSyncClient::GetSchedInfo(int64_t* vsync_period_ns, int64_t* timestamp_ns,
51                              uint32_t* next_vsync_count) {
52  if (!vsync_period_ns || !timestamp_ns || !next_vsync_count)
53    return -EINVAL;
54
55  auto status = InvokeRemoteMethod<VSyncProtocol::GetSchedInfo>();
56  if (!status) {
57    ALOGE("VSyncClient::GetSchedInfo:: Failed to get warp timestamp: %s",
58          status.GetErrorMessage().c_str());
59    return -status.error();
60  }
61
62  *vsync_period_ns = status.get().vsync_period_ns;
63  *timestamp_ns = status.get().timestamp_ns;
64  *next_vsync_count = status.get().next_vsync_count;
65  return 0;
66}
67
68int VSyncClient::Acknowledge() {
69  auto status = InvokeRemoteMethod<VSyncProtocol::Acknowledge>();
70  ALOGE_IF(!status, "VSuncClient::Acknowledge: Failed to ack vsync because: %s",
71           status.GetErrorMessage().c_str());
72  return ReturnStatusOrError(status);
73}
74
75}  // namespace dvr
76}  // namespace android
77