Browse Source

Replace hardcoded usleep with packet_delay option (-y default unset)

Georgi Chorbadzhiyski 12 years ago
parent
commit
2309ce8db3
4 changed files with 17 additions and 3 deletions
  1. 4
    2
      camd.c
  2. 2
    0
      data.c
  3. 2
    0
      data.h
  4. 9
    1
      tsdecrypt.c

+ 4
- 2
camd.c View File

@@ -198,7 +198,8 @@ static int camd35_send_ecm(struct ts *ts, uint16_t ca_id, uint16_t service_id, u
198 198
 	// OSCAM do not like it if ECM's are comming too fast
199 199
 	// It thinks they are part of a single packet and ignores
200 200
 	// the data at the end. The usleep() is a hack but works
201
-	usleep(10000);
201
+	if (ts->packet_delay)
202
+		usleep(ts->packet_delay);
202 203
 
203 204
 	int ret = camd35_send_buf(ts, to_send);
204 205
 	if (ret <= 0) {
@@ -233,7 +234,8 @@ static int camd35_send_emm(struct ts *ts, uint16_t ca_id, uint8_t *data, uint8_t
233 234
 	// OSCAM do not like it if EMM's are comming too fast
234 235
 	// It thinks they are part of a single packet and ignores
235 236
 	// the data at the end. The usleep() is a hack but works
236
-	usleep(10000);
237
+	if (ts->packet_delay)
238
+		usleep(ts->packet_delay);
237 239
 
238 240
 	int ret = camd35_send_buf(ts, to_send);
239 241
 	if (ret <= 0) {

+ 2
- 0
data.c View File

@@ -54,6 +54,8 @@ void data_init(struct ts *ts) {
54 54
 	ts->emm_send    = 0;
55 55
 	ts->pid_filter  = 1;
56 56
 
57
+	ts->packet_delay = 0;
58
+
57 59
 	ts->input.fd    = 0; // STDIN
58 60
 	ts->input.type  = FILE_IO;
59 61
 

+ 2
- 0
data.h View File

@@ -117,6 +117,8 @@ struct ts {
117 117
 
118 118
 	int					threaded;
119 119
 
120
+	int					packet_delay;
121
+
120 122
 	int					decode_stop;
121 123
 	pthread_t			decode_thread;
122 124
 	CBUF				*decode_buf;

+ 9
- 1
tsdecrypt.c View File

@@ -61,6 +61,7 @@ static void show_help(struct ts *ts) {
61 61
 	printf("    -s server_addr | default: disabled (format 1.2.3.4:2233)\n");
62 62
 	printf("    -U server_user | default: %s\n", ts->camd35.user);
63 63
 	printf("    -P server_pass | default: %s\n", ts->camd35.pass);
64
+	printf("    -y usec_delay  | Sleep X usec between sending ECM/EMM packets to OSCAM. default: %d\n", ts->packet_delay);
64 65
 	printf("\n");
65 66
 	printf("  Filtering options:\n");
66 67
 	printf("    -e             | EMM send (default: %s).\n", ts->emm_send ? "enabled" : "disabled");
@@ -104,7 +105,7 @@ static int parse_io_param(struct io *io, char *opt, int open_flags, mode_t open_
104 105
 
105 106
 static void parse_options(struct ts *ts, int argc, char **argv) {
106 107
 	int j, i, ca_err = 0, server_err = 1, input_addr_err = 0, output_addr_err = 0, output_intf_err = 0, ident_err = 0;
107
-	while ((j = getopt(argc, argv, "i:d:l:L:c:s:I:O:o:t:U:P:ezpD:h")) != -1) {
108
+	while ((j = getopt(argc, argv, "i:d:l:L:c:s:I:O:o:t:U:P:y:ezpD:h")) != -1) {
108 109
 		char *p = NULL;
109 110
 		switch (j) {
110 111
 			case 'i':
@@ -173,6 +174,11 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
173 174
 				strncpy(ts->camd35.pass, optarg, sizeof(ts->camd35.pass) - 1);
174 175
 				ts->camd35.pass[sizeof(ts->camd35.pass) - 1] = 0;
175 176
 				break;
177
+			case 'y':
178
+				ts->packet_delay = atoi(optarg);
179
+				if (ts->packet_delay < 0 || ts->packet_delay > 1000000)
180
+					ts->packet_delay = 0;
181
+				break;
176 182
 
177 183
 			case 'z':
178 184
 				ts->ts_discont = !ts->ts_discont;
@@ -239,6 +245,8 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
239 245
 	ts_LOGf("Server addr: tcp://%s:%u/\n", inet_ntoa(ts->camd35.server_addr), ts->camd35.server_port);
240 246
 	ts_LOGf("Server user: %s\n", ts->camd35.user);
241 247
 	ts_LOGf("Server pass: %s\n", ts->camd35.pass);
248
+	if (ts->packet_delay)
249
+		ts_LOGf("Pkt sleep  : %d us (%d ms)\n", ts->packet_delay, ts->packet_delay / 1000);
242 250
 	ts_LOGf("EMM send   : %s\n", ts->emm_send   ? "enabled" : "disabled");
243 251
 	ts_LOGf("PID filter : %s\n", ts->pid_filter ? "enabled" : "disabled");
244 252
 	ts_LOGf("TS discont : %s\n", ts->ts_discont ? "report" : "ignore");

Loading…
Cancel
Save