blob: 0ca7edcf459c061c684bcb31bffcb0473f402139 [file] [log] [blame]
Alex Vakulenkoe4eec202017-01-27 14:41:04 -08001#include <sched.h>
Fan Xu74df4902018-09-20 16:40:51 -07002#include <sys/resource.h>
Alex Vakulenkoe4eec202017-01-27 14:41:04 -08003#include <unistd.h>
4
Alex Vakulenkoe4eec202017-01-27 14:41:04 -08005#include <dvr/performance_client_api.h>
Fan Xu74df4902018-09-20 16:40:51 -07006#include <log/log.h>
Alex Vakulenko5a244ed2017-06-09 16:29:04 -07007#include <pdx/service_dispatcher.h>
Fan Xu74df4902018-09-20 16:40:51 -07008#include <private/dvr/buffer_hub.h>
Fan Xucfd12742018-09-14 13:23:52 -07009#include <private/dvr/buffer_hub_binder.h>
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080010
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080011int main(int, char**) {
12 int ret = -1;
13 std::shared_ptr<android::pdx::Service> service;
14 std::unique_ptr<android::pdx::ServiceDispatcher> dispatcher;
15
16 // We need to be able to create endpoints with full perms.
17 umask(0000);
18
Corey Tabaka52ea25c2017-09-13 18:02:48 -070019 // Bump up the soft limit of open fd to the hard limit.
20 struct rlimit64 rlim;
21 ret = getrlimit64(RLIMIT_NOFILE, &rlim);
22 LOG_ALWAYS_FATAL_IF(ret != 0, "Failed to get nofile limit.");
23
24 ALOGI("Current nofile limit is %llu/%llu.", rlim.rlim_cur, rlim.rlim_max);
25 rlim.rlim_cur = rlim.rlim_max;
26 ret = setrlimit64(RLIMIT_NOFILE, &rlim);
27 ALOGE_IF(ret < 0, "Failed to set nofile limit, error=%s", strerror(errno));
28
29 rlim.rlim_cur = -1;
30 rlim.rlim_max = -1;
31 if (getrlimit64(RLIMIT_NOFILE, &rlim) < 0)
32 ALOGE("Failed to get nofile limit.");
33 else
34 ALOGI("New nofile limit is %llu/%llu.", rlim.rlim_cur, rlim.rlim_max);
35
Fan Xucfd12742018-09-14 13:23:52 -070036 CHECK_ERROR(android::dvr::BufferHubBinderService::start() != android::OK,
37 error, "Failed to create bufferhub binder service\n");
38
Alex Vakulenko5a244ed2017-06-09 16:29:04 -070039 dispatcher = android::pdx::ServiceDispatcher::Create();
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080040 CHECK_ERROR(!dispatcher, error, "Failed to create service dispatcher\n");
41
42 service = android::dvr::BufferHubService::Create();
Fan Xucfd12742018-09-14 13:23:52 -070043 CHECK_ERROR(!service, error, "Failed to create bufferhubd service\n");
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080044 dispatcher->AddService(service);
45
46 ret = dvrSetSchedulerClass(0, "graphics");
47 CHECK_ERROR(ret < 0, error, "Failed to set thread priority");
48
49 ALOGI("Entering message loop.");
50
51 ret = dispatcher->EnterDispatchLoop();
52 CHECK_ERROR(ret < 0, error, "Dispatch loop exited because: %s\n",
53 strerror(-ret));
54
55error:
56 return -ret;
57}