Skip to content

Commit

Permalink
Add --input-dump option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Chorbadzhiyski committed Jan 28, 2012
1 parent 83207bd commit 60e69f0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
next : Version next
* Add --output-tos (-g) option used to set output TOS value.
* Add --input-dump (-W) option used save input stream in file.

2011-12-23 : Version 5.0
* Add --bench (-b) option that benchmarks libdvbcsa decryption.
Expand Down
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Input options:
-R --input-rtp | Enable RTP input
-z --input-ignore-disc | Do not report discontinuty errors in input.
-M --input-service <srvid> | Choose service id when input is MPTS.
-W --input-dump <filename> | Save input stream in file.

Output options:
-O --output <dest> | Where to send output. File or multicast address.
Expand Down
3 changes: 3 additions & 0 deletions data.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ struct ts {
struct io input;
struct io output;

FILE *input_dump_file;
char *input_dump_filename;

int debug_level;
int ts_discont;

Expand Down
7 changes: 7 additions & 0 deletions tsdecrypt.1
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ in order to select the correct service (program). If the input is MPTS
and \fB\-\-input\-service\fR is not used, tsdecrypt chooses the last service
listed in PAT.
.TP
\fB\-W\fR, \fB\-\-input\-dump\fR <filename>
Save input stream in <filename>. If the input is RTP, the file will contain
the data without RTP headers (pure mpeg transport stream). Easiest way to
save the input is using command line like the following:

tsdecrypt -I 239.78.78.78:5000 -O /dev/null -s 0.0.0.0 -W file.ts
.TP
.SH OUTPUT OPTIONS
.PP
.TP
Expand Down
24 changes: 21 additions & 3 deletions tsdecrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void run_benchmark(void) {
puts("* Done *");
}

// Unused short options: FQTWYajkmnqruv0123456789
// Unused short options: FQTYajkmnqruv0123456789
static const struct option long_options[] = {
{ "ident", required_argument, NULL, 'i' },
{ "daemon", required_argument, NULL, 'd' },
Expand All @@ -116,6 +116,7 @@ static const struct option long_options[] = {
{ "input-rtp", no_argument, NULL, 'R' },
{ "input-ignore-disc", no_argument, NULL, 'z' },
{ "input-service", required_argument, NULL, 'M' },
{ "input-dump", required_argument, NULL, 'W' },

{ "output", required_argument, NULL, 'O' },
{ "output-intf", required_argument, NULL, 'o' },
Expand Down Expand Up @@ -178,6 +179,7 @@ static void show_help(struct ts *ts) {
printf(" -R --input-rtp | Enable RTP input\n");
printf(" -z --input-ignore-disc | Do not report discontinuty errors in input.\n");
printf(" -M --input-service <srvid> | Choose service id when input is MPTS.\n");
printf(" -W --input-dump <filename> | Save input stream in file.\n");
printf("\n");
printf("Output options:\n");
printf(" -O --output <dest> | Where to send output. File or multicast address.\n");
Expand Down Expand Up @@ -266,7 +268,7 @@ static int parse_io_param(struct io *io, char *opt, int open_flags, mode_t open_

static void parse_options(struct ts *ts, int argc, char **argv) {
int j, i, ca_err = 0, server_err = 1, input_addr_err = 0, output_addr_err = 0, output_intf_err = 0, ident_err = 0, port_set = 0;
while ( (j = getopt_long(argc, argv, "i:d:N:Sl:L:I:RzM:O:o:t:g:pwxyc:C:A:s:U:P:B:eZ:Ef:X:H:G:KJ:D:bhV", long_options, NULL)) != -1 ) {
while ( (j = getopt_long(argc, argv, "i:d:N:Sl:L:I:RzM:W:O:o:t:g:pwxyc:C:A:s:U:P:B:eZ:Ef:X:H:G:KJ:D:bhV", long_options, NULL)) != -1 ) {
char *p = NULL;
switch (j) {
case 'i':
Expand Down Expand Up @@ -309,6 +311,9 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
case 'M':
ts->forced_service_id = strtoul(optarg, NULL, 0) & 0xffff;
break;
case 'W':
ts->input_dump_filename = optarg;
break;

case 'O':
output_addr_err = parse_io_param(&ts->output, optarg,
Expand Down Expand Up @@ -512,6 +517,13 @@ static void parse_options(struct ts *ts, int argc, char **argv) {
} else if (ts->input.type == FILE_IO) {
ts_LOGf("Input file : %s\n", ts->input.fd == 0 ? "STDIN" : ts->input.fname);
}
if (ts->input_dump_filename) {
ts->input_dump_file = fopen(ts->input_dump_filename, "w");
if (ts->input_dump_file)
ts_LOGf("Input dump : %s\n", ts->input_dump_filename);
else
ts_LOGf("Input dump : %s | ERROR: %s\n", ts->input_dump_filename, strerror(errno));
}
if (ts->forced_service_id)
ts_LOGf("Service id : 0x%04x (%d)\n",
ts->forced_service_id, ts->forced_service_id);
Expand Down Expand Up @@ -759,8 +771,11 @@ int main(int argc, char **argv) {
readen = read(ts.input.fd, ts_packet, FRAME_SIZE);
have_data = !(readen <= 0);
}
if (readen > 0)
if (readen > 0) {
if (ts.input_dump_file)
fwrite(ts_packet, readen, 1, ts.input_dump_file);
process_packets(&ts, ts_packet, readen);
}
if (!keep_running)
break;
} while (have_data);
Expand All @@ -787,6 +802,9 @@ int main(int argc, char **argv) {
closelog();
}

if (ts.input_dump_file)
fclose(ts.input_dump_file);

if (ts.daemonize)
unlink(ts.pidfile);

Expand Down

0 comments on commit 60e69f0

Please sign in to comment.