27 #include <linux/input.h>
30 #include "glib_tools.h"
31 #include <glib-unix.h>
36 #include <glib/gstdio.h>
37 #include "mediasourcepipeline.h"
39 #include "wayland-client.h"
42 #define UNUSED( x ) ((void)(x))
44 std::string files_path_;
47 bool ParseCommandLine(
int argc,
char** argv) {
50 "Please specify a directory containing raw frame files for media "
51 "source playback!\n");
53 }
else if (argc == 2) {
54 files_path_ = argv[1];
60 static void keyPressed(
void* data,
unsigned int key )
63 pi->HandleKeyboardInput(key);
66 static void keyReleased(
void *,
unsigned int )
70 static EssKeyListener keyListener=
75 void rtMainLoopCb(
void*)
79 err = rtRemoteProcessSingleItem();
80 if (err == RT_ERROR_QUEUE_EMPTY) {
83 else if (err != RT_OK) {
84 fprintf(stderr,
"rtRemoteProcessSingleItem() returned %d\n", err);
88 void rtRemoteCallback(
void*)
92 int ret = HANDLE_EINTR_EAGAIN(write(gPipefd[PIPE_WRITE], temp, 1));
94 fprintf(stderr,
"can't write to pipe");
97 bool initRt(GMainLoop* main_loop, GSource* source, rtObjectRef pipeline)
102 g_source_attach(source, g_main_loop_get_context(main_loop));
104 rtRemoteRegisterQueueReadyHandler( rtEnvironmentGetGlobal(), rtRemoteCallback,
nullptr );
107 if(rc != RT_OK)
return false;
109 const char* objectName = getenv(
"PX_WAYLAND_CLIENT_REMOTE_OBJECT_NAME");
110 if (!objectName) objectName =
"MEDIASOURCE_PIPELINE_RT";
111 printf(
"Register RT object: %s\n", objectName);
113 rc = rtRemoteRegisterObject(objectName, pipeline);
115 return (rc == RT_OK);
118 std::string getExePath()
121 ssize_t count = readlink(
"/proc/self/exe", result, 255);
122 std::string full_path = std::string( result, (count > 0) ? count : 0 );
123 return dirname((
char*) full_path.c_str());
126 gboolean essosIteration(gint fd,GIOCondition condition,gpointer user_data)
129 EssCtx* ctx = (EssCtx*) user_data;
130 EssContextRunEventLoopOnce( ctx );
135 gboolean runEssosEventLoop(EssCtx* ctx)
137 EssContextRunEventLoopOnce( ctx );
141 int main(
int argc,
char** argv) {
144 EssCtx* ctx = EssContextCreate();
145 GMainLoop* g_main_loop = NULL;
146 GSource* source = NULL;
148 if (!ParseCommandLine(argc, argv)) {
149 fprintf(stderr,
"Failed to parse command line\n");
153 gst_init(&argc, &argv);
156 if ( !EssContextSetUseWayland( ctx,
true ) )
158 printf(
"Failed to connect to wayland display, exiting...\n");
162 bool have_folder =
false;
164 lstat(files_path_.c_str(), &st);
165 if (S_ISDIR(st.st_mode))
169 files_path_ = getExePath() +
"/mse_frames";
170 printf(
"No directory passed or directory invalid, using default path:%s\n",files_path_.c_str());
172 lstat(files_path_.c_str(), &st);
173 if (!S_ISDIR(st.st_mode))
175 printf(
"Default path:%s not found, exiting...\n",files_path_.c_str());
180 printf(
"Using path:%s\n",files_path_.c_str());
187 fprintf(stderr,
"Failed to start pipeline!\n");
191 if ( !EssContextSetKeyListener( ctx, pi, &keyListener ) )
193 printf(
"Failed to connect to essos key listener\n");
196 if ( !EssContextStart( ctx ) )
198 printf(
"Failed to start essos context\n");
203 g_main_loop = g_main_loop_new(NULL, FALSE);
205 if(!initRt(g_main_loop,source,pi))
207 fprintf(stderr,
"Failed to init rt!\n");
220 g_idle_add ((GSourceFunc) runEssosEventLoop, ctx);
222 g_main_loop_run(g_main_loop);
225 g_main_loop_unref(g_main_loop);
229 g_source_unref(source);
231 EssContextDestroy( ctx );