Project

General

Profile

Bug #5722 » rstlog_patch.txt

Laurent H., 2019-12-08 14:09

 
1
diff --git a/src/parsers/message.c b/src/parsers/message.c
2
index 74c92401d..a7f860309 100644
3
--- a/src/parsers/message.c
4
+++ b/src/parsers/message.c
5
@@ -236,6 +236,8 @@ static void parser_init_es(parser_es_t *pes, parser_t *prs)
6
   pes->es_last_pcr = PTS_UNSET;
7
   pes->es_last_pcr_dts = PTS_UNSET;
8
   TAILQ_INIT(&pes->es_backlog);
9
+  tvhtrace(LS_PARSER, "tailq_init rstlog");
10
+  TAILQ_INIT(&pes->es_rstlog);
11
   if (pes->es_type == SCT_HBBTV && pes->es_psi.mt_name == NULL)
12
     dvb_table_parse_init(&pes->es_psi, "hbbtv", LS_TS, pes->es_pid,
13
                          DVB_HBBTV_BASE, DVB_HBBTV_MASK, pes);
14
@@ -250,6 +252,7 @@ static void parser_clean_es(parser_es_t *pes)
15
   pes->es_priv = NULL;
16
 
17
   streaming_queue_clear(&pes->es_backlog);
18
+  streaming_queue_clear(&pes->es_rstlog);
19
 
20
   if (pes->es_psi.mt_name)
21
     dvb_table_reset(&pes->es_psi);
22
diff --git a/src/parsers/parsers.c b/src/parsers/parsers.c
23
index 7524f715f..c570fedaa 100644
24
--- a/src/parsers/parsers.c
25
+++ b/src/parsers/parsers.c
26
@@ -92,6 +92,43 @@ parser_deliver_error(parser_t *t, parser_es_t *st)
27
   st->es_buf.sb_err = 0;
28
 }
29
 
30
+
31
+
32
+/**
33
+ * Do rstlog
34
+ */
35
+static void
36
+parser_rstlog(parser_t *t, parser_es_t *st, th_pkt_t *pkt)
37
+{
38
+  streaming_message_t *sm = streaming_msg_create_pkt(pkt);
39
+  TAILQ_INSERT_TAIL (&st->es_rstlog, sm, sm_link);
40
+  pkt_ref_dec(pkt); /* streaming_msg_create_pkt increses ref counter */
41
+}
42
+
43
+static void
44
+parser_do_rstlog(parser_t *t, parser_es_t *st)
45
+{
46
+  streaming_message_t *sm;
47
+  th_pkt_t *pkt;
48
+  tvhtrace(LS_PARSER,
49
+           "pkt rstlog %2d %-12s - rstlog flush start",
50
+           st->es_index,
51
+           streaming_component_type2txt(st->es_type));
52
+  while ((sm = TAILQ_FIRST(&st->es_rstlog)) != NULL) {
53
+    pkt = sm->sm_data;
54
+    TAILQ_REMOVE(&st->es_rstlog, sm, sm_link);
55
+    pkt_trace(LS_PARSER, pkt, "deliver from rstlog");
56
+    streaming_target_deliver2(t->prs_output, streaming_msg_create_pkt(pkt));
57
+    sm->sm_data = NULL;
58
+    streaming_msg_free(sm);
59
+  }
60
+  tvhtrace(LS_PARSER,
61
+           "pkt rstlog %2d %-12s - rstlog flush end -",
62
+           st->es_index,
63
+           streaming_component_type2txt(st->es_type));
64
+}
65
+
66
+
67
 /**
68
  *
69
  */
70
@@ -127,15 +164,24 @@ parser_deliver(parser_t *t, parser_es_t *st, th_pkt_t *pkt)
71
 deliver:
72
   pkt->pkt_componentindex = st->es_index;
73
 
74
-  pkt_trace(LS_PARSER, pkt, "deliver");
75
-
76
   if (SCT_ISVIDEO(pkt->pkt_type)) {
77
     pkt->v.pkt_aspect_num = st->es_aspect_num;
78
     pkt->v.pkt_aspect_den = st->es_aspect_den;
79
   }
80
 
81
   /* Forward packet */
82
-  streaming_target_deliver2(t->prs_output, streaming_msg_create_pkt(pkt));
83
+  if(atomic_get(&st->es_service->s_pending_restart) == 1) {
84
+    /* Queue pkt to es_rstlog if pending restart */
85
+    pkt_trace(LS_PARSER, pkt, "deliver to rstlog");
86
+    parser_rstlog(t, st, pkt);
87
+  } else {
88
+    /* empty es_restart queue */
89
+    if (!TAILQ_EMPTY(&st->es_rstlog)) {
90
+      parser_do_rstlog(t, st);
91
+    }
92
+    pkt_trace(LS_PARSER, pkt, "deliver");
93
+    streaming_target_deliver2(t->prs_output, streaming_msg_create_pkt(pkt));
94
+  }
95
 
96
   /* Decrease our own reference to the packet */
97
   pkt_ref_dec(pkt);
98
diff --git a/src/parsers/parsers.h b/src/parsers/parsers.h
99
index f37a56c57..c7ae69bed 100644
100
--- a/src/parsers/parsers.h
101
+++ b/src/parsers/parsers.h
102
@@ -56,6 +56,7 @@ struct parser_es {
103
   int       es_global_data_len;
104
   struct th_pkt *es_curpkt;
105
   struct streaming_message_queue es_backlog;
106
+  struct streaming_message_queue es_rstlog;
107
   tvhlog_limit_t es_pes_log;
108
   mpegts_psi_table_t es_psi;
109
   /* Clocks */
110
diff --git a/src/plumbing/tsfix.c b/src/plumbing/tsfix.c
111
index 4b4843e5d..6584597f5 100644
112
--- a/src/plumbing/tsfix.c
113
+++ b/src/plumbing/tsfix.c
114
@@ -552,6 +552,8 @@ tsfix_input_packet(tsfix_t *tf, streaming_message_t *sm)
115
   tfs = tfs_find(tf, pkt);
116
   streaming_msg_free(sm);
117
 
118
+  pkt_trace(LS_TSFIX, pkt, "*input*");
119
+
120
   if (tfs == NULL || mclk() < tf->tf_start_time) {
121
     tsfix_packet_drop(tfs, pkt, "start time");
122
     return;
(4-4/5)