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