ClpeStream.cpp
Go to the documentation of this file.
1 #include "ClpeStream.h"
2 
4 void intecept_frame(int camera_id, unsigned int cur_frame_seq, unsigned char* p_buffer, unsigned int size, struct timeval *pt_camera_timeStamp);
5 
8 unsigned int g_stop_signal = 0;
9 
10 // related to clpe_getFrameCb()
11 #define MAX_SEQ_OFFSET 110000 // 3600 * 30 = 108000
13 struct timeval frame_pre[AVAILALE_PORT] = {{0,},};
14 struct timeval prePcTime[AVAILALE_PORT] = {{0,},}; /* added by dwsun */
15 unsigned int seq_base[AVAILALE_PORT] = {0, };
16 int g_lock = 0;
17 #define SIMPLE_LOCK while(g_lock) { usleep(10); } g_lock = 1;
18 #define SIMPLE_UNLOCK g_lock = 0;
19 
20 typedef struct function_arg{
23  char use_cam[AVAILALE_PORT]; // master & slave
25 
26 typedef struct frame_info{
27  int camera_id;
28  unsigned char *p_buffer;
29  unsigned int size;
30  unsigned int last_frame_seq;
31  unsigned int current_frame_seq;
32  struct timeval pt_camera_timeStamp;
34 
35 unsigned int g_last_cam_id = 0;
36 unsigned int g_cur_cam_id = 0;
37 unsigned int g_last_frame_seq = 0;
38 unsigned int g_cur_frame_seq = 0;
39 
40 t_frame_info gt_frame_info[AVAILALE_PORT] = {0,}; // master & slave
41 
42 
43 pthread_t g_pthread;
44 
45 GstBus* appSinkBus;
46 GstElement* gAppSink;
47 
48 void increase_seq(PortData* data, xu32 now_seq)
49 {
50  xu32 idx;
51 
52  if(! now_seq) {
53  now_seq = data->frame_now_seq;
54  }
55  for(idx = 0; idx < MAX_FRAME; idx ++) {
56  if((data->frameX[idx].seq != 0) && (data->frameX[idx].seq <= now_seq)) { // Remove also NOW
57  memset(&data->frameX[idx], 0x00, sizeof(PortDataFrameX) - sizeof(T_UDP_BLOCK));
58  }
59  }
60 
61  data->frame_now_seq = now_seq + 1;
62  data->frame_max_seq = data->frame_now_seq + MAX_FRAME - 1;
63 }
64 
66 {
67  PortDataFrameX* frame = &data->frameX[data->frame_now_seq % MAX_FRAME];
68  xu32 now_seq = frame->seq;
69  xu32 ui32_udpFrameSize = 0;
70  xu32 ui32_udpMaxBlockNum = 0;
71 
72  if(data->idx == UDP_PORT_IDX_IMX490) // in case of IMX490
73  {
74  ui32_udpFrameSize = UDP_FRAME_SIZE_IMX490;
75  ui32_udpMaxBlockNum = UDP_MAX_BLOCK_NUM_IMX490;
76  }
77  else
78  {
79  ui32_udpFrameSize = UDP_FRAME_SIZE;
80  ui32_udpMaxBlockNum = UDP_MAX_BLOCK_NUM;
81  }
82 
83  //if(IS_BLOCK_DONE(frame))
84  if(frame->block_set_num == ui32_udpMaxBlockNum + 1)
85  {
86  // For STAT, Call Callback
87  data->up_count++;
88  data->parent->up_count++;
89  if(data->idx != UDP_PORT_IDX_IMX490)
90  {
92  }
93 #ifdef CANLAB_LOGGING_ENABLE
94  if(data->cb_app(data->idx, frame->seq, frame->block.block[0], ui32_udpFrameSize, &frame->tv_frame
95  , data->dropped) < 0) {
96 
97  g_main_loop_quit (data->parent->loop);
98  return -1;
99  }
100 #else // #ifdef CANLAB_LOGGING_ENABLE
101 #if 0
102  if(data->cb_app(data->idx, frame->block.block[0], UDP_FRAME_SIZE, &frame->tv_frame) < 0) {
103 
104  g_main_loop_quit (data->parent->loop);
105  return -1;
106  }
107 #else
108  if(g_stop_signal == 1)
109  {
110  //g_main_loop_quit(data->parent->loop);
111  g_stop_signal = 0;
112  return -1;
113  }
114  else
115  {
116  xu16 ui16_tmp_cam_id;
117 
118  ui16_tmp_cam_id = (data->idx & 0x6) | ((data->idx & 0x1) ^ 1);
119 
120  data->cb_app(ui16_tmp_cam_id, frame->block.block[0], ui32_udpFrameSize, &frame->tv_frame);
121  intecept_frame(data->idx, frame->seq, frame->block.block[0], ui32_udpFrameSize, &frame->tv_frame);
122 
123  }
124 
125 #endif
126 #endif // #ifdef CANLAB_LOGGING_ENABLE
127 
128  // Send To SRC
129  if(data->play) {
130  GstBuffer* buffer;
131  GstMapInfo map;
132 
133  buffer = gst_buffer_new_and_alloc (ui32_udpFrameSize);
134  gst_buffer_map (buffer, &map, GST_MAP_WRITE);
135  memcpy(map.data, &frame->block, ui32_udpFrameSize);
136  gst_buffer_unmap (buffer, &map);
137 
138  struct timeval tv_frame_pts;
139  timersub(&frame->tv_frame, &data->frame_base_tv, &tv_frame_pts);
140 
141  GST_BUFFER_PTS(buffer) = GST_TIMEVAL_TO_TIME(tv_frame_pts);
142  gst_app_src_push_buffer (GST_APP_SRC (data->up_appsrc), buffer);
143  }
144  } else {
145  // Old Discard : Not Completed
146  data->dropped ++;
147  data->parent->dropped ++;
148  }
149 
150  increase_seq(data, now_seq);
151 
152  return 0;
153 }
154 
155 static GstFlowReturn
156 on_new_sample_from_sink (GstElement* elt, PortData* data)
157 {
158  GstSample *sample;
159  GstBuffer *buffer;
160  GstFlowReturn ret = GST_FLOW_OK;
161  gsize recv_len;
162  PortDataFrameX* frame;
163  xu16 ui16_udpMaxBlockNum = 0;
164  xu32 ui32_udpLastBlockSize = 0;
165  xu32 fps = 0;
166 
167  if(data->idx == UDP_PORT_IDX_IMX490) // in case of IMX490
168  {
169  ui16_udpMaxBlockNum = UDP_MAX_BLOCK_NUM_IMX490;
170  ui32_udpLastBlockSize = UDP_LAST_BLOCK_SIZE_IMX490;
171  fps = 25;
172  }
173  else
174  {
175  ui16_udpMaxBlockNum = UDP_MAX_BLOCK_NUM;
176  ui32_udpLastBlockSize = UDP_LAST_BLOCK_SIZE;
177  fps = 30;
178  }
179 
180  sample = gst_app_sink_pull_sample (GST_APP_SINK (elt));
181 
182 
183  if(data->skip_count < ((ui16_udpMaxBlockNum+1) * fps * 1)) // skip 1 sec
184  {
185  data->skip_count++;
186  gst_sample_unref (sample);
187  return ret;
188  }
189 
190  buffer = gst_sample_get_buffer (sample);
191  recv_len = gst_buffer_extract(buffer, 0, data->recv, sizeof(*data->recv));
192 
193  T_MSG_BLOCK_INFO* info = (T_MSG_BLOCK_INFO*) &data->recv->info;
194 
195  DATA_LOCK(data);
196 
197  if(data->do_check) {
198  if((
199  info->seq > data->frame_max_seq + 1
200  || info->seq < data->frame_now_seq
201  )) {
202  data->discard_low_seq++;
203 
204  DATA_UNLOCK(data);
205 
206  gst_sample_unref (sample);
207  return ret;
208  }
209 
210 #if 0
211  if((
212 
213  info->seq == data->frame_max_seq + 1
214  )) {
215  DATA_UNLOCK(data);
216  gst_sample_unref (sample);
217  return ret;
218  }
219 #endif
220  }
221 
222  xu32 now = info->seq % MAX_FRAME;
223  frame = &data->frameX[now];
224 
225  // Valid Check
226  if((
227  info->block_id > ui16_udpMaxBlockNum
228  || frame->block_set[info->block_id] // Already Exist ; Pre seq -> Drop, Future Seq -> ToDO
229  || recv_len < (ui32_udpLastBlockSize + sizeof(T_MSG_BLOCK_INFO))
230  )) {
231  DATA_UNLOCK(data);
232  gst_sample_unref (sample);
233  return ret;
234  }
235 
236  // Block processing
237  if(info->block_id == ui16_udpMaxBlockNum) { // Last
238  memcpy(frame->block.last.block, data->recv->block, ui32_udpLastBlockSize);
239  } else {
240  memcpy(frame->block.block[info->block_id],data->recv->block, UDP_BLOCK_SIZE);
241  }
242 
243  frame->block_set[info->block_id] = TRUE;
244  frame->block_set_num ++;
245 
246  if(frame->block_set_num == 1) { // First
247  frame->seq = info->seq;
248  frame->tv_frame = info->frame;
249  }
250  // moved above
251  //else if(IS_BLOCK_DONE(frame))
252  else if(frame->block_set_num == (xu32)(ui16_udpMaxBlockNum + 1))
253  {
254  if(! data->do_check ) {
255  data->do_check = 1;
256 
257  // Totally Init
258  data->frame_now_seq = info->seq; // Error ???? frame->seq
259  data->frame_max_seq = data->frame_now_seq + MAX_FRAME - 1;
260 
261  // Totally 1st
262  data->frame_base_tv = info->frame;
263 
264 #ifndef FIX_NOW_FRAME /* root.2021.0515 */
265  xu32 idx;
266  for(idx = 0; idx < MAX_FRAME; idx ++) {
267  if(data->frameX[idx].seq < info->seq) {
268  memset(&data->frameX[idx], 0x00, sizeof(PortDataFrameX) - sizeof(T_UDP_BLOCK));
269  }
270  }
271 #endif /* FIX_NOW_FRAME root.2021.0515 */
272  }
273  else
274  {
275  data->frame_now_seq = info->seq;
276  data->frame_max_seq = data->frame_now_seq + MAX_FRAME - 1;
277  }
278 
279  process_block_done(data);
280  }
281 
282  DATA_UNLOCK(data);
283  gst_sample_unref (sample);
284 
285  return ret;
286 }
287 
288 gboolean on_sink_message_appsink (GstBus * bus, GstMessage * message, PortData* data)
289 {
290  xc8 name_app[32];
291 
292  snprintf(name_app, sizeof(name_app), "app_%u", data->idx);
293 
294  switch (GST_MESSAGE_TYPE (message)) {
295  case GST_MESSAGE_EOS:
296  g_print ("The appsink[%s] Finished playback\n", name_app);
297  g_main_loop_quit (data->parent->loop);
298  break;
299  case GST_MESSAGE_ERROR:
300  g_print ("The appsink[%s] received error\n", name_app);
301  g_main_loop_quit (data->parent->loop);
302  break;
303  default:
304  break;
305  }
306  return TRUE;
307 }
308 
309 gboolean on_source_message (GstBus * bus, GstMessage * message, PortData * data)
310 {
311  GstElement *appsrc;
312  xc8 name_app[32];
313 
314  snprintf(name_app, sizeof(name_app), "app_%u", data->idx);
315 
316  switch (GST_MESSAGE_TYPE (message)) {
317  case GST_MESSAGE_EOS:
318  g_print ("The appsrc[%s] got dry\n", name_app);
319  appsrc = gst_bin_get_by_name (GST_BIN (data->appsrc), name_app);
320  gst_app_src_end_of_stream (GST_APP_SRC (appsrc));
321  gst_object_unref (appsrc);
322  break;
323  case GST_MESSAGE_ERROR:
324  g_print ("The appsrc[%s] received error\n", name_app);
325  g_main_loop_quit (data->parent->loop);
326  break;
327  default:
328  break;
329  }
330  return TRUE;
331 }
332 
334 {
335  xc8 buff[4096];
336  xc8 name_app[32];
337  xc8 name_appsrc[32];
338  //xu16 port = START_PORT + data->idx;
339  xu16 port = 0;
340 
341  xu32 image_width = 0;
342  xu32 image_height = 0;
343  xc8 ip_address[32];
344 
345  if(data->idx == UDP_PORT_IDX_IMX490) // in case of IMX490
346  {
347  image_width = IMG_WIDTH_IMX490;
348  image_height = IMG_HEIGHT_IMX490;
349  }
350  else
351  {
352  image_width = IMG_WIDTH_IMX390;
353  image_height = IMG_HEIGHT_IMX390;
354  }
355 
356  if(data->idx < MAX_PORT)
357  {
358  snprintf(ip_address, sizeof(ip_address), "192.168.7.8");
359  port = START_PORT + data->idx;
360  }
361  else
362  {
363  snprintf(ip_address, sizeof(ip_address), "192.168.8.8");
364  port = START_PORT + data->idx - MAX_PORT;
365  }
366 
367  /* ========================================= SINK ========================================= */
368  snprintf(name_app, sizeof(name_app), "app_%u", data->idx);
369  snprintf(buff, sizeof(buff),
370  "udpsrc address=%s port=%u retrieve-sender-address=false buffer-size=%u "
371  " ! queue max-size-time=2000000000 max-size-buffers=2000000000 max-size-bytes=2000000000 "
372  " ! appsink name=%s",
373  ip_address, port,
375  name_app
376  );
377 
378  data->appsink = gst_parse_launch (buff, NULL);
379  if (data->appsink == NULL) {
380  g_print ("Launch fail for port[%u]\n", port);
381  return FALSE;
382  }
383 
384 
385  appSinkBus = gst_element_get_bus (data->appsink);
386  data->appSinkBusWatchId[data->idx] = gst_bus_add_watch (appSinkBus, (GstBusFunc) on_sink_message_appsink, data);
387  gst_object_unref (appSinkBus);
388 
389  //GstElement* appsink;
390  gAppSink = gst_bin_get_by_name (GST_BIN(data->appsink), name_app);
391  g_object_set (G_OBJECT (gAppSink), "emit-signals", TRUE, "sync", FALSE, NULL);
392  g_signal_connect (gAppSink, "new-sample", G_CALLBACK (on_new_sample_from_sink), data);
393  gst_object_unref (gAppSink);
394 
395  /* ========================================= SOURCE ========================================= */
396  snprintf(name_appsrc, sizeof(name_appsrc), "appsrc_%u", data->idx);
397 
398  if(data->play) { // play = ON
400  {
401  snprintf(buff, sizeof(buff), "appsrc name=%s stream-type=\"stream\" is-live=1 do-timestamp=0 format=time "
402  " caps=\"video/x-raw,format=UYVY,width=%d,height=%d,pixel-aspect-ratio=1/1,interlace-mode=progressive,framerate=30/1\" "
403  " ! queue max-size-time=2000000000 max-size-buffers=2000000000 max-size-bytes=2000000000 "
404  "! videoscale method=0 n-thread=9 ! video/x-raw, width=480, height=270 "
405  "! videoconvert ! ximagesink sync=false async=false",
406  name_appsrc,
407  image_width,
408  image_height
409  );
410  }
411  else
412  {
413  snprintf(buff, sizeof(buff), "appsrc name=%s stream-type=\"stream\" is-live=1 do-timestamp=0 format=time "
414  " caps=\"video/x-raw,format=UYVY,width=%d,height=%d,pixel-aspect-ratio=1/1,interlace-mode=progressive,framerate=30/1\" "
415  " ! queue max-size-time=2000000000 max-size-buffers=2000000000 max-size-bytes=2000000000 "
416  " ! videoconvert ! ximagesink sync=false async=false",
417  name_appsrc,
418  image_width,
419  image_height
420  );
421  }
422  }
423 
424  if(data->play) { // play = ON
425  GstBus* appSrcBus;
426  data->appsrc = gst_parse_launch (buff, NULL);
427  if (data->appsrc == NULL) {
428  g_print ("Launch fail for port[%u]\n", port);
429  return FALSE;
430  }
431 
432  appSrcBus = gst_element_get_bus (data->appsrc);
433  data->appSrcBusWatchId[data->idx] = gst_bus_add_watch (appSrcBus, (GstBusFunc) on_source_message, data);
434  gst_object_unref (appSrcBus);
435 
436  data->up_appsrc = gst_bin_get_by_name (GST_BIN(data->appsrc), name_appsrc);
437  g_object_set (data->up_appsrc, "format", GST_FORMAT_TIME, NULL);
438 
439  }
440 
441  return TRUE;
442 }
443 
444 
445 void *clpe_runStream(void *pArg)
446 {
447  t_function_arg *pt_func_arg;
448  T_CB_APP cb_app;
449  int play;
450  GstMessage *msg = NULL;
451  //int result = 0;
452 
453  pt_func_arg = (t_function_arg *)pArg;
454 
455  cb_app = pt_func_arg->callback_func;
456  play = pt_func_arg->display_on;
457 
458  if(! cb_app) {
459  fprintf(stderr, "T_CB_APP is NULL.\n");
460  //result = -1;
461  free(pt_func_arg);
462  //return (void *)&result;
463  return NULL;
464  }
465 
466 #if 0
467  char renice_cmd[ 128 ];
468  int pid = getpid();
469  sprintf (renice_cmd, "renice -20 %d > /dev/null" , pid);
470  if(0 > system (renice_cmd)) {
471  result = -1;
472  return (void *)&result;
473  }
474 #endif
475 
476  gst_init (NULL,NULL);
477  memset(&g_MainData, 0x00, sizeof(g_MainData));
478  g_MainData.loop = g_main_loop_new (NULL, FALSE);
479 
481  for(xu16 idx = 0; idx < AVAILALE_PORT; idx++) {
482  if(pt_func_arg->use_cam[idx] == 1)
483  {
485  }
486  }
487 
488  for(xu16 idx = 0; idx < AVAILALE_PORT; idx++) {
489  if(pt_func_arg->use_cam[idx] == 1)
490  {
491 
493  g_MainData.port[idx].cb_app = cb_app;
494 #if 0
495  if(idx < 4)
496  g_MainData.port[idx].play = play;
497  else
498  g_MainData.port[idx].play = 0;
499 #else
500  g_MainData.port[idx].play = play;
501 #endif
502  g_MainData.port[idx].idx = idx;
503  g_MainData.port[idx].seq = 0;
504  g_MainData.port[idx].recv = &g_recv[idx];
505 
506  g_MainData.port[idx].frame_now_seq = 0;
508  if(! launch_port(&g_MainData.port[idx]) ) {
509  g_main_loop_unref (g_MainData.loop);
510  //result = -2;
511  free(pt_func_arg);
512  return NULL;
513  }
514  }
515  }
516 
517  for(xu16 idx = 0; idx < AVAILALE_PORT; idx++) {
518  if(pt_func_arg->use_cam[idx] == 1)
519  {
520  PortData* data = &g_MainData.port[idx];
521 
522  if(data->appsrc) {
523  gst_element_set_state (data->appsrc, GST_STATE_PLAYING);
524  }
525  gst_element_set_state (data->appsink, GST_STATE_PLAYING);
526  //gLastAppsink = data->appsrc;
527  }
528  }
529 
530  //g_main_loop_run (g_MainData.loop);
531  msg = gst_bus_timed_pop_filtered(appSinkBus, GST_CLOCK_TIME_NONE, GstMessageType(GST_MESSAGE_EOS));
532  if(msg != NULL)
533  {
534  gst_message_unref(msg);
535  }
536 
537  for(xu16 idx = 0; idx < AVAILALE_PORT; idx++) {
538  if(pt_func_arg->use_cam[idx] == 1)
539  {
540  PortData* data = &g_MainData.port[idx];
541 
542  gst_element_set_state (g_MainData.port[idx].appsink, GST_STATE_NULL);
543  if(data->appsrc) {
544  gst_element_set_state (g_MainData.port[idx].appsrc, GST_STATE_NULL);
545  }
546  g_source_remove(data->appSinkBusWatchId[idx]);
547  gst_object_unref (g_MainData.port[idx].appsink);
548  if(data->appsrc) {
549  g_source_remove(data->appSrcBusWatchId[idx]);
550  gst_object_unref (g_MainData.port[idx].appsrc);
551  }
552  }
553  }
554 
555  g_main_loop_unref (g_MainData.loop);
556 
557  free(pt_func_arg);
558  //return (void *)&result;
559  return NULL;
560 }
561 
562 void intecept_frame(int camera_id, unsigned int cur_frame_seq, unsigned char* p_buffer, unsigned int size, struct timeval *pt_camera_timeStamp)
563 {
564  gt_frame_info[camera_id].camera_id = camera_id;
565  gt_frame_info[camera_id].p_buffer = p_buffer;
566  gt_frame_info[camera_id].size = size;
567  gt_frame_info[camera_id].pt_camera_timeStamp = *pt_camera_timeStamp;
568  gt_frame_info[camera_id].current_frame_seq = cur_frame_seq;
569 
570  g_cur_cam_id = camera_id;
571  g_cur_frame_seq = cur_frame_seq;
572 }
573 
574 int clpe_startStream(T_CB_APP cb_app, char use_cam_0, char use_cam_1, char use_cam_2, char use_cam_3, int display_on)
575 {
576 // pthread_t p_thread;
577  int thread_id;
578  t_function_arg *pt_func_arg;
579  int result = ERROR_NONE;
580 
581  pt_func_arg = (t_function_arg *)malloc(sizeof(t_function_arg));
582  pt_func_arg->callback_func = cb_app;
583  pt_func_arg->display_on = display_on;
584  pt_func_arg->use_cam[0] = use_cam_0;
585  pt_func_arg->use_cam[1] = use_cam_1;
586  pt_func_arg->use_cam[2] = use_cam_2;
587  pt_func_arg->use_cam[3] = use_cam_3;
588 
589  thread_id = pthread_create(&g_pthread, NULL, clpe_runStream, (void *)(pt_func_arg));
590 
591  if (thread_id < 0)
592  {
593  printf("Fail to create thread !!! \n");
594  result = ERROR_CREATE_TASK;
595  }
596  return result;
597 }
598 
600 {
601  int result = ERROR_NONE;
602 
603  g_stop_signal = 1;
604 
605  //g_main_loop_quit(g_MainData.loop);
606  gst_element_post_message(gAppSink, gst_message_new_eos(GST_OBJECT(gAppSink)));
607 
608  pthread_join(g_pthread, NULL);
609 
610  memset(gt_frame_info, 0x00, sizeof(gt_frame_info));
611  g_cur_cam_id = 0;
612  g_last_cam_id = 0;
613  g_cur_frame_seq = 0;
614  g_last_frame_seq = 0;
615 
616  return result;
617 }
618 
619 int clpe_getFrameAnyCam(int *p_camera_id, unsigned char **p_buffer, unsigned int *p_size, struct timeval *pt_camera_timeStamp)
620 {
621  int timeout = 3000;
622 
623  do{
625  {
626  *p_camera_id = g_cur_cam_id;
627  *p_buffer = gt_frame_info[g_cur_cam_id].p_buffer;
628  *p_size = gt_frame_info[g_cur_cam_id].size;
629  *pt_camera_timeStamp = gt_frame_info[g_cur_cam_id].pt_camera_timeStamp;
630 
633  break;
634  }
635  usleep(1000);
636  }while(--timeout);
637  if(timeout == 0)
638  {
639  return ERROR_NO_FRAME;
640  }
641 
642  return ERROR_NONE;
643 }
644 
645 int clpe_getFrameWithCamId(int camera_id, unsigned char **p_buffer, unsigned int *p_size, struct timeval *pt_camera_timeStamp)
646 {
647  int timeout = 3000;
648  if(camera_id > AVAILALE_PORT) // master & slave
649  {
651  }
652  do{
653  if(gt_frame_info[camera_id].last_frame_seq != gt_frame_info[camera_id].current_frame_seq)
654  {
655  *p_buffer = gt_frame_info[camera_id].p_buffer;
656  *p_size = gt_frame_info[camera_id].size;
657  *pt_camera_timeStamp = gt_frame_info[camera_id].pt_camera_timeStamp;
659  break;
660  }
661  usleep(1000);
662  }while(--timeout);
663  if(timeout == 0)
664  {
665  return ERROR_NO_FRAME;
666  }
667  return ERROR_NONE;
668 }
669 
670 
671 #ifdef CANLAB_LOGGING_ENABLE
672 int clpe_getFrameCb(unsigned int inst, unsigned int seq, unsigned char* buffer, unsigned int size, struct timeval* frame_us, unsigned int dropped)
673 {
674  struct timeval tv_sub;
675  struct timeval cur_sub;
676  struct tm ltm_frame;
677  struct tm ltm_curPc;
678  struct timeval curPcTime; // added by dwsun
679 
680  gettimeofday(&curPcTime, NULL); // added by dwsun
681  if(! seq_base[inst]) seq_base[inst] = seq;
682 
683  if(frame_pre[inst].tv_sec) {
684  // 1st skip :
685  localtime_r(&frame_us->tv_sec, &ltm_frame);
686  timersub(frame_us, &frame_pre[inst], &tv_sub);
687 
688  localtime_r(&curPcTime.tv_sec, &ltm_curPc);
689  timersub(&curPcTime, &prePcTime[inst], &cur_sub);
690 
691  SIMPLE_LOCK;
692  printf("%u | %4u | " FORM_LTM " | %6lu |",
693  50000 + inst,
694  // seq,
695  seq - seq_base[inst],
696  ARGS_LTM(ltm_frame, *frame_us),
697  tv_sub.tv_usec
698  );
699 
700  /* added by dwsun */
701  printf(" " FORM_LTM " | %6lu | %u\n",
702  //50000 + inst,
703  //seq,
704  ARGS_LTM(ltm_curPc, curPcTime),
705  cur_sub.tv_usec,
706  dropped
707  );
709  }
710 
711  prePcTime[inst] = curPcTime; // added by dwsun
712  memcpy(&frame_pre[inst], frame_us, sizeof(frame_pre[inst]));
713 
714  // Must Do Return as fast as posible (Recommend in 5ms).
715  if(seq - seq_base[inst] > g_max_seq_offset) {
716  return -1; // -1 : STOP
717  }
718  return 0; // -1 : STOP
719 
720 }
721 #endif //#ifdef CANLAB_LOGGING_ENABLE
PortData::appSinkBusWatchId
x32 appSinkBusWatchId[AVAILALE_PORT]
Definition: ClpeStream.h:145
SIMPLE_UNLOCK
#define SIMPLE_UNLOCK
Definition: ClpeStream.cpp:18
MAX_SEQ_OFFSET
#define MAX_SEQ_OFFSET
Definition: ClpeStream.cpp:11
PortData::frame_now_seq
xu32 frame_now_seq
Definition: ClpeStream.h:136
t_frame_info
struct frame_info t_frame_info
t_function_arg
struct function_arg t_function_arg
T_CB_APP
int(* T_CB_APP)(unsigned int inst, unsigned char *buffer, unsigned int size, struct timeval *frame_us)
Definition: ClpeStreamApi.h:10
frame_pre
struct timeval frame_pre[AVAILALE_PORT]
Definition: ClpeStream.cpp:13
g_lock
int g_lock
Definition: ClpeStream.cpp:16
SIMPLE_LOCK
#define SIMPLE_LOCK
Definition: ClpeStream.cpp:17
clpe_startStream
int clpe_startStream(T_CB_APP cb_app, char use_cam_0, char use_cam_1, char use_cam_2, char use_cam_3, int display_on)
Definition: ClpeStream.cpp:574
PortData::frameX
PortDataFrameX frameX[MAX_FRAME]
Definition: ClpeStream.h:135
ERROR_NONE
#define ERROR_NONE
Definition: ClpeStreamApi.h:14
increase_seq
void increase_seq(PortData *data, xu32 now_seq)
Definition: ClpeStream.cpp:48
PortDataFrameX
Definition: ClpeStream.h:92
frame_info::size
unsigned int size
Definition: ClpeStream.cpp:29
UDP_MAX_BLOCK_NUM
#define UDP_MAX_BLOCK_NUM
Definition: ClpeStream.h:48
ClpeStream.h
clpe_runStream
void * clpe_runStream(void *pArg)
Definition: ClpeStream.cpp:445
UDP_MAX_BLOCK_NUM_IMX490
#define UDP_MAX_BLOCK_NUM_IMX490
Definition: ClpeStream.h:56
appSinkBus
GstBus * appSinkBus
Definition: ClpeStream.cpp:45
PortData::up_appsrc
GstElement * up_appsrc
Definition: ClpeStream.h:144
launch_port
int launch_port(PortData *data)
Definition: ClpeStream.cpp:333
_ProgramMain::loop
GMainLoop * loop
Definition: ClpeStream.h:153
PortData
Definition: ClpeStream.h:116
MAX_PORT
#define MAX_PORT
Definition: ClpeStream.h:26
IMG_HEIGHT_IMX490
#define IMG_HEIGHT_IMX490
Definition: ClpeStream.h:39
AVAILALE_PORT
#define AVAILALE_PORT
Definition: ClpeStream.h:28
T_UDP_BLOCK_CONTENT::info
T_MSG_BLOCK_INFO info
Definition: ClpeStream.h:77
PortDataFrameX::seq
xu32 seq
Definition: ClpeStream.h:94
PortDataFrameX::block_set_num
xu32 block_set_num
Definition: ClpeStream.h:96
UDP_BLOCK_SIZE
#define UDP_BLOCK_SIZE
Definition: ClpeStream.h:47
PortData::parent
struct _ProgramMain * parent
Definition: ClpeStream.h:148
g_max_seq_offset
unsigned int g_max_seq_offset
Definition: ClpeStream.cpp:12
frame_info::camera_id
int camera_id
Definition: ClpeStream.cpp:27
g_stop_signal
unsigned int g_stop_signal
Definition: ClpeStream.cpp:8
PortData::appsink
GstElement * appsink
Definition: ClpeStream.h:142
PortDataFrameX::tv_frame
struct timeval tv_frame
Definition: ClpeStream.h:98
frame_info::current_frame_seq
unsigned int current_frame_seq
Definition: ClpeStream.cpp:31
clpe_getFrameAnyCam
int clpe_getFrameAnyCam(int *p_camera_id, unsigned char **p_buffer, unsigned int *p_size, struct timeval *pt_camera_timeStamp)
Definition: ClpeStream.cpp:619
clpe_stopStream
int clpe_stopStream(void)
Definition: ClpeStream.cpp:599
IMG_WIDTH_IMX390
#define IMG_WIDTH_IMX390
Definition: ClpeStream.h:36
PortData::frame_base_tv
struct timeval frame_base_tv
Definition: ClpeStream.h:121
g_MainData
ProgramMain g_MainData
Definition: ClpeStream.cpp:6
MAX_FRAME
#define MAX_FRAME
Definition: ClpeStream.h:134
intecept_frame
void intecept_frame(int camera_id, unsigned int cur_frame_seq, unsigned char *p_buffer, unsigned int size, struct timeval *pt_camera_timeStamp)
Definition: ClpeStream.cpp:562
PortData::discard_low_seq
xu64 discard_low_seq
Definition: ClpeStream.h:128
_ProgramMain::ui32_use_camera_cnt
xu32 ui32_use_camera_cnt
Definition: ClpeStream.h:160
gt_frame_info
t_frame_info gt_frame_info[AVAILALE_PORT]
Definition: ClpeStream.cpp:40
function_arg::use_cam
char use_cam[AVAILALE_PORT]
Definition: ClpeStream.cpp:23
UDP_FRAME_SIZE
#define UDP_FRAME_SIZE
Definition: ClpeStream.h:46
xu16
unsigned short xu16
Definition: ClpeStream.h:64
UDP_LAST_BLOCK_SIZE_IMX490
#define UDP_LAST_BLOCK_SIZE_IMX490
Definition: ClpeStream.h:57
on_source_message
gboolean on_source_message(GstBus *bus, GstMessage *message, PortData *data)
Definition: ClpeStream.cpp:309
g_cur_frame_seq
unsigned int g_cur_frame_seq
Definition: ClpeStream.cpp:38
T_UDP_BLOCK_LAST::block
xu8 block[UDP_LAST_BLOCK_SIZE]
Definition: ClpeStream.h:83
prePcTime
struct timeval prePcTime[AVAILALE_PORT]
Definition: ClpeStream.cpp:14
frame_info
Definition: ClpeStream.cpp:26
ERROR_NOT_AVALIABLE_CAM_ID
#define ERROR_NOT_AVALIABLE_CAM_ID
Definition: ClpeStreamApi.h:17
on_sink_message_appsink
gboolean on_sink_message_appsink(GstBus *bus, GstMessage *message, PortData *data)
Definition: ClpeStream.cpp:288
process_block_done
int process_block_done(PortData *data)
Definition: ClpeStream.cpp:65
clpe_getFrameWithCamId
int clpe_getFrameWithCamId(int camera_id, unsigned char **p_buffer, unsigned int *p_size, struct timeval *pt_camera_timeStamp)
Definition: ClpeStream.cpp:645
PortData::do_check
xu32 do_check
Definition: ClpeStream.h:125
PortData::dropped
xu32 dropped
Definition: ClpeStream.h:126
PortData::appSrcBusWatchId
x32 appSrcBusWatchId[AVAILALE_PORT]
Definition: ClpeStream.h:146
function_arg
Definition: ClpeStream.cpp:20
g_cur_cam_id
unsigned int g_cur_cam_id
Definition: ClpeStream.cpp:36
T_UDP_BLOCK_CONTENT
Definition: ClpeStream.h:76
ERROR_CREATE_TASK
#define ERROR_CREATE_TASK
Definition: ClpeStreamApi.h:15
DATA_UNLOCK
#define DATA_UNLOCK(_data)
Definition: ClpeStream.h:131
function_arg::callback_func
T_CB_APP callback_func
Definition: ClpeStream.cpp:21
IMG_HEIGHT_IMX390
#define IMG_HEIGHT_IMX390
Definition: ClpeStream.h:37
DATA_LOCK
#define DATA_LOCK(_data)
Definition: ClpeStream.h:130
ARGS_LTM
#define ARGS_LTM(_ltm, _tv)
Definition: ClpeStream.h:34
PortData::up_count
xu32 up_count
Definition: ClpeStream.h:127
PortData::idx
xu16 idx
Definition: ClpeStream.h:118
_ProgramMain::port
PortData port[AVAILALE_PORT]
Definition: ClpeStream.h:155
g_recv
T_UDP_BLOCK_CONTENT g_recv[AVAILALE_PORT]
Definition: ClpeStream.cpp:7
PortData::seq
xu32 seq
Definition: ClpeStream.h:119
PortDataFrameX::block_set
xu8 block_set[UDP_MAX_BLOCK_NUM_IMX490+1]
Definition: ClpeStream.h:97
T_MSG_BLOCK_INFO::seq
xu32 seq
Definition: ClpeStream.h:71
PortDataFrameX::block
T_UDP_BLOCK block
Definition: ClpeStream.h:100
on_new_sample_from_sink
static GstFlowReturn on_new_sample_from_sink(GstElement *elt, PortData *data)
Definition: ClpeStream.cpp:156
_ProgramMain::dropped
xu32 dropped
Definition: ClpeStream.h:157
xu32
unsigned int xu32
Definition: ClpeStream.h:66
FORM_LTM
#define FORM_LTM
Definition: ClpeStream.h:33
T_UDP_BLOCK_CONTENT::block
xu8 block[UDP_BLOCK_SIZE]
Definition: ClpeStream.h:78
g_pthread
pthread_t g_pthread
Definition: ClpeStream.cpp:43
frame_info::pt_camera_timeStamp
struct timeval pt_camera_timeStamp
Definition: ClpeStream.cpp:32
ERROR_NO_FRAME
#define ERROR_NO_FRAME
Definition: ClpeStreamApi.h:16
PortData::frame_max_seq
xu32 frame_max_seq
Definition: ClpeStream.h:137
T_UDP_BLOCK
Definition: ClpeStream.h:86
PortData::recv
T_UDP_BLOCK_CONTENT * recv
Definition: ClpeStream.h:147
UDP_PORT_IDX_IMX490
#define UDP_PORT_IDX_IMX490
Definition: ClpeStream.h:54
PortData::appsrc
GstElement * appsrc
Definition: ClpeStream.h:143
T_MSG_BLOCK_INFO::block_id
xu16 block_id
Definition: ClpeStream.h:72
PortData::skip_count
xu16 skip_count
Definition: ClpeStream.h:123
frame_info::last_frame_seq
unsigned int last_frame_seq
Definition: ClpeStream.cpp:30
g_last_frame_seq
unsigned int g_last_frame_seq
Definition: ClpeStream.cpp:37
_ProgramMain::up_count
xu32 up_count
Definition: ClpeStream.h:158
xc8
char xc8
Definition: ClpeStream.h:62
seq_base
unsigned int seq_base[AVAILALE_PORT]
Definition: ClpeStream.cpp:15
_ProgramMain
Definition: ClpeStream.h:151
T_MSG_BLOCK_INFO
Definition: ClpeStream.h:70
T_MSG_BLOCK_INFO::frame
struct timeval frame
Definition: ClpeStream.h:73
IMG_WIDTH_IMX490
#define IMG_WIDTH_IMX490
Definition: ClpeStream.h:38
T_UDP_BLOCK::last
T_UDP_BLOCK_LAST last
Definition: ClpeStream.h:88
g_last_cam_id
unsigned int g_last_cam_id
Definition: ClpeStream.cpp:35
UDP_FRAME_SIZE_IMX490
#define UDP_FRAME_SIZE_IMX490
Definition: ClpeStream.h:55
START_PORT
#define START_PORT
Definition: ClpeStream.h:24
gAppSink
GstElement * gAppSink
Definition: ClpeStream.cpp:46
UDP_GST_MAX_BUFFER_SIZE
#define UDP_GST_MAX_BUFFER_SIZE
Definition: ClpeStream.h:44
UDP_LAST_BLOCK_SIZE
#define UDP_LAST_BLOCK_SIZE
Definition: ClpeStream.h:51
PortData::play
x32 play
Definition: ClpeStream.h:140
T_UDP_BLOCK::block
xu8 block[UDP_MAX_BLOCK_NUM_IMX490][UDP_BLOCK_SIZE]
Definition: ClpeStream.h:87
function_arg::display_on
int display_on
Definition: ClpeStream.cpp:22
frame_info::p_buffer
unsigned char * p_buffer
Definition: ClpeStream.cpp:28
PortData::cb_app
T_CB_APP cb_app
Definition: ClpeStream.h:139


clpe_sdk
Author(s): Can-lab Corporation
autogenerated on Wed Oct 12 2022 02:17:28