Could not get EGL display connection issue

I add a systemd service for tegra_multimedia_api/sample/10_camera_recording.

[Unit]
Description=my test daemon
After=nvargus-daemon.service
[Service]
ExecStart=/home/nvidia/work/
WorkingDirectory=/home/nvidia/work/mytest
Restart=always
Type=simple
User=nvidia
[Install]
WantedBy=multi-user.target

mytest source code is simple, call camera_recording and save the log.

void dump_system_cmd(char *cmd, char *type, char *folder) {
char buf[256] = {0};
time_t timep;
struct tm *p;

time(&timep);
p = localtime(&timep);
sprintf(buf, "%s >> %s/%04d%02d%02d%02d%02d.%s", cmd, folder,
1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min,
type);
printf("buf = [%s]\n", buf);
system(buf);
}
int main(int argc, char **argv) {
dump_system_cmd("./camera_recording", "log", "argus_log");
sleep(10);
system("sync");
while (1) sleep(100);
}

I do power down and power up test for 58 times, then I find an issue.
abnormal case (3 times):

nvbuf_utils: Could not get EGL display connection
nvbuf_utils: ERROR getting proc addr of eglCreateImageKHR
nvbuf_utils: ERROR getting proc addr of eglDestroyImageKHR
Cannot get EGL display.
PRODUCER: Creating output stream
PRODUCER: Launching consumer thread
Opening in BLOCKING MODE 
875967048
842091865
create video encoder return true
PRODUCER: Starting repeat capture requests.
CONSUMER: Got EOS, exiting...
CONSUMER: Done.
PRODUCER: Done -- exiting.
************************************

normal case (55 times):

PRODUCER: Creating output stream
PRODUCER: Launching consumer thread
Opening in BLOCKING MODE 
875967048
842091865
create video encoder return true
PRODUCER: Starting repeat capture requests.
CONSUMER: Got EOS, exiting...
CONSUMER: Done.
PRODUCER: Done -- exiting.
************************************
Total Profiling Time = 0 sec
************************************

I do not know why, Could you help me? thank you very much!

Board:TX2
system version:# R32 (release), REVISION: 2.1, GCID: 16294929, BOARD: t186ref, EABI: aarch64, DATE: Tue Aug 13 04:45:36 UTC 2019

Looks like this depends on a GUI running. Just to verify, if you are in a text only console, e.g., after CTRL-ALT-F3, or using serial console, are you able to run this command without error? If not, then this script may need to change multi-user.target to:

...
[Install]
WantedBy=<b>graphical</b>.target

Even this may not be enough since someone may need to be logged in to the GUI to use the program.

hi,linuxdev,thank you very much.
I do power down and power up test for 58 times, then I find an issue.
abnormal case (3 times)(Could not get EGL display connection)
normal case (55 times)(no error)
It means I can run this command without error most of time.
My TX2 product is unmanned drone, So I need systemd to run argus app to get the camera data.
But I checked all argus samples code(such as camera_recording) are based on EGL.
I do not know how to remove EGL.
I am very confused…

I have no experience with argus, but since this works most of the time, and not always, this really sounds like a case of your program and/or service is at times starting before some requirement is in place. If your program really does not need any kind of X11 server on the Jetson (and often GLES is related to a running X11 server), then “graphical.target” would not be a requirement. In some cases people install a virtual X11 server even though the Jetson is running headless and only accessed remotely, and this is a case where graphical.target would be mandatory.

Startup does have some perhaps unexpected timing differences (e.g., a DHCP query might delay timing in one case but not the other), and so it is difficult to give an exact answer. There are times when something being started as a background thread in multi-user.target may not actually get going before graphical.target runs, but it wouldn’t be predictable.

Do you have any kind of virtual X11 server installed? Is the Jetson running headless at all times? If you use a local console via something like CTRL-ALT-F3, and then manually start the program with no monitor attached, does it run correctly? How do you run remote access in a normal case, e.g., via ssh, or via a virtual GUI app?

Hi,
We have r32.2.3 released. Would suggest you give it a try.