forked from fsphil/hacktv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hacktv.c
796 lines (706 loc) · 21.2 KB
/
hacktv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/* hacktv - Analogue video transmitter for the HackRF */
/*=======================================================================*/
/* Copyright 2017 Philip Heron <[email protected]> */
/* */
/* This program is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <signal.h>
#include "hacktv.h"
#include "test.h"
#include "ffmpeg.h"
#include "file.h"
#include "hackrf.h"
#ifdef HAVE_SOAPYSDR
#include "soapysdr.h"
#endif
#ifdef HAVE_FL2K
#include "fl2k.h"
#endif
volatile int _abort = 0;
static void _sigint_callback_handler(int signum)
{
fprintf(stderr, "Caught signal %d\n", signum);
if(_abort > 0)
{
exit(-1);
}
_abort++;
}
/* RF sink callback handlers */
static int _hacktv_rf_write(hacktv_t *s, int16_t *iq_data, size_t samples)
{
if(s->rf_write)
{
return(s->rf_write(s->rf_private, iq_data, samples));
}
return(HACKTV_ERROR);
}
static int _hacktv_rf_close(hacktv_t *s)
{
if(s->rf_close)
{
return(s->rf_close(s->rf_private));
}
return(HACKTV_OK);
}
static void print_usage(void)
{
printf(
"\n"
"Usage: hacktv [options] input [input...]\n"
"\n"
" -o, --output <target> Set the output device or file, Default: hackrf\n"
" -m, --mode <name> Set the television mode. Default: i\n"
" -s, --samplerate <value> Set the sample rate in Hz. Default: 16MHz\n"
" -l, --level <value> Set the output level. Default: 1.0\n"
" -D, --deviation <value> Override the mode's FM deviation. (Hz)\n"
" -G, --gamma <value> Override the mode's gamma correction value.\n"
" -r, --repeat Repeat the inputs forever.\n"
" -v, --verbose Enable verbose output.\n"
" --teletext <path> Enable teletext output. (625 line modes only)\n"
" --wss <mode> Enable WSS output. (625 line modes only)\n"
" --videocrypt <mode> Enable Videocrypt I scrambling. (PAL only)\n"
" --videocrypt2 <mode> Enable Videocrypt II scrambling. (PAL only)\n"
" --videocrypts <mode> Enable Videocrypt S scrambling. (PAL only)\n"
" --syster Enable Nagravision Syster scambling. (PAL only)\n"
" --acp Enable Analogue Copy Protection signal.\n"
" --filter Enable experimental VSB modulation filter.\n"
" --noaudio Suppress all audio subcarriers.\n"
"\n"
"Input options\n"
"\n"
" test:colourbars Generate and transmit a test pattern.\n"
" ffmpeg:<file|url> Decode and transmit a video file with ffmpeg.\n"
"\n"
" If no valid input prefix is provided, ffmpeg: is assumed.\n"
"\n"
"HackRF output options\n"
"\n"
" -o, --output hackrf[:<serial>] Open a HackRF for output.\n"
" -f, --frequency <value> Set the RF frequency in Hz, 0MHz to 7250MHz.\n"
" -a, --amp Enable the TX RF amplifier.\n"
" -g, --gain <value> Set the TX VGA (IF) gain, 0-47dB. Default: 0dB\n"
"\n"
" Only modes with a complex output are supported by the HackRF.\n"
"\n"
#ifdef HAVE_SOAPYSDR
"SoapySDR output options\n"
"\n"
" -o, --output soapysdr[:<opts>] Open a SoapySDR device for output.\n"
" -f, --frequency <value> Set the RF frequency in Hz.\n"
" -g, --gain <value> Set the TX level. Default: 0dB\n"
" -A, --antenna <name> Set the antenna.\n"
"\n"
#endif
#ifdef HAVE_FL2K
"fl2k output options\n"
"\n"
" -o, --output fl2k[:<dev>] Open an fl2k device for output.\n"
"\n"
" Real signals are output on the Red channel. Complex signals are output\n"
" on the Red (I) and Green (Q) channels.\n"
"\n"
" The 0.7v p-p voltage level of the FL2K is too low to create a correct\n"
" composite video signal, it will appear too dark without amplification.\n"
"\n"
#endif
"File output options\n"
"\n"
" -o, --output file:<filename> Open a file for output. Use - for stdout.\n"
" -t, --type <type> Set the file data type.\n"
"\n"
"Supported file types:\n"
"\n"
" uint8\n"
" int8\n"
" uint16\n"
" int16\n"
" int32\n"
" float\n"
"\n"
" The default output is int16. The TV mode will determine if the output\n"
" is real or complex.\n"
"\n"
" If no valid output prefix is provided, file: is assumed.\n"
"\n"
"Supported television modes:\n"
"\n"
" i = PAL colour, 25 fps, 625 lines, AM (complex), 6.0 MHz FM audio\n"
" b, g = PAL colour, 25 fps, 625 lines, AM (complex), 5.5 MHz FM audio\n"
" pal-fm = PAL colour, 25 fps, 625 lines, FM (complex), 6.5 MHz FM audio\n"
" pal = PAL colour, 25 fps, 625 lines, unmodulated (real)\n"
" m = NTSC colour, 30/1.001 fps, 525 lines, AM (complex)\n"
" ntsc = NTSC colour, 30/1.001 fps, 525 lines, unmodulated (real)\n"
" l = SECAM colour, 25 fps, 625 lines, AM (complex), 6.5 MHz AM\n"
" audio\n"
" secam = SECAM colour, 25 fps, 625 lines, unmodulated (real)\n"
" e = No colour, 25 fps, 819 lines, AM (complex)\n"
" 819 = No colour, 25 fps, 819 lines, unmodulated (real)\n"
" a = No colour, 25 fps, 405 lines, AM (complex)\n"
" 405 = No colour, 25 fps, 405 lines, unmodulated (real)\n"
" 240-am = No colour, 25 fps, 240 lines, AM (complex)\n"
" 240 = No colour, 25 fps, 240 lines, unmodulated (real)\n"
" 30-am = No colour, 12.5 fps, 30 lines, AM (complex)\n"
" 30 = No colour, 12.5 fps, 30 lines, unmodulated (real)\n"
" apollo-fsc-fm = Field sequential colour, 30/1.001 fps, 525 lines, FM (complex)\n"
" 1.25 MHz FM audio\n"
" apollo-fsc = Field sequential colour, 30/1.001 fps, 525 lines, unmodulated\n"
" (real)\n"
" apollo-fm = No colour, 10 fps, 320 lines, FM (complex), 1.25 MHz FM audio\n"
" apollo = No colour, 10 fps, 320 lines, unmodulated (real)\n"
"\n"
"NOTE: The number of samples per line is rounded to the nearest integer,\n"
"which may result in a slight frame rate error.\n"
"\n"
"For modes which include audio you also need to ensure the sample rate\n"
"is adequate to contain both the video signal and audio subcarriers.\n"
"\n"
"16MHz works well with PAL modes, and 13.5MHz for NTSC modes.\n"
"\n"
"Teletext\n"
"\n"
"Teletext is a digital information service transmitted within the VBI lines of\n"
"the video signal. Developed in the UK in the 1970s, it was used throughout\n"
"much of Europe until the end of analogue TV in the 2010s.\n"
"\n"
"hacktv supports TTI files. The path can be either a single file or a\n"
"directory. All files in the directory will be loaded.\n"
"\n"
"Raw packet sources are also supported with the raw:<source> path name.\n"
"The input is expected to be 42 byte teletext packets. Use - for stdin.\n"
"\n"
"Lines 7-22 and 320-335 are used, 16 lines per field.\n"
"\n"
"Teletext support in hacktv is only compatible with 625 line PAL modes.\n"
"NTSC and SECAM variations exist and may be supported in the future.\n"
"\n"
"WSS (Widescreen Signaling)\n"
"\n"
"WSS provides a method to signal to a TV the intended aspect ratio of\n"
"the video. The following modes are supported:\n"
"\n"
" 4:3 = Video is 4:3.\n"
" 16:9 = Video is 16:9 (Anamorphic).\n"
" 14:9-letterbox = Crop a 4:3 video to 14:9.\n"
" 16:9-letterbox = Crop a 4:3 video to 16:9.\n"
" auto = Automatically switch between 4:3 and 16:9.\n"
"\n"
"Currently only supported in 625 line modes. A 525 line variant exists and\n"
"may be supported in future.\n"
"\n"
"Videocrypt I\n"
"\n"
"A video scrambling system used by the Sky TV analogue satellite service in\n"
"the UK in the 1990s. Each line of the image is cut at a point determined by\n"
"a pseudorandom number generator, then the two parts are swapped.\n"
"\n"
"hacktv supports the following modes:\n"
"\n"
" free = Free-access, no subscription card is required to decode.\n"
" conditional = A valid Sky card is required to decode. Sample data from MTV.\n"
"\n"
"Videocrypt is only compatiable with 625 line PAL modes. This version\n"
"works best when used with samples rates at multiples of 14MHz.\n"
"\n"
"Videocrypt II\n"
"\n"
"A variation of Videocrypt I used throughout Europe. The scrambling method is\n"
"identical to VC1, but has a higher VBI data rate.\n"
"\n"
"hacktv supports the following modes:\n"
"\n"
" free = Free-access, no subscription card is required to decode.\n"
"\n"
"Both VC1 and VC2 cannot be used together except if both are in free-access mode.\n"
"\n"
"Videocrypt S (Simulation)\n"
"\n"
"A variation of Videocrypt II used on the short lived BBC Select service. This\n"
"mode uses line-shuffling rather than line cut-and-rotate.\n"
"\n"
"hacktv supports the following modes:\n"
"\n"
" free = Free-access, no subscription card is required to decode.\n"
"\n"
"This is a simulation and will not work with real hardware.\n"
"Audio inversion is not yet supported.\n"
"\n"
"Nagravision Syster\n"
"\n"
"Another video scrambling system used in the 1990s in Europe. The video lines\n"
"are vertically shuffled within a field.\n"
"\n"
"Syster is only compatible with 625 line PAL modes and does not currently work\n"
"with most hardware.\n"
"\n"
"Audio inversion is not yet supported.\n"
"\n"
);
}
#define _OPT_TELETEXT 1000
#define _OPT_WSS 1001
#define _OPT_VIDEOCRYPT 1002
#define _OPT_VIDEOCRYPT2 1003
#define _OPT_VIDEOCRYPTS 1004
#define _OPT_SYSTER 1005
#define _OPT_ACP 1006
#define _OPT_FILTER 1007
#define _OPT_NOAUDIO 1008
int main(int argc, char *argv[])
{
int c;
int option_index;
static struct option long_options[] = {
{ "output", required_argument, 0, '0' },
{ "mode", required_argument, 0, 'm' },
{ "samplerate", required_argument, 0, 's' },
{ "level", required_argument, 0, 'l' },
{ "deviation", required_argument, 0, 'D' },
{ "gamma", required_argument, 0, 'G' },
{ "repeat", no_argument, 0, 'r' },
{ "verbose", no_argument, 0, 'v' },
{ "teletext", required_argument, 0, _OPT_TELETEXT },
{ "wss", required_argument, 0, _OPT_WSS },
{ "videocrypt", required_argument, 0, _OPT_VIDEOCRYPT },
{ "videocrypt2", required_argument, 0, _OPT_VIDEOCRYPT2 },
{ "videocrypts", required_argument, 0, _OPT_VIDEOCRYPTS },
{ "syster", no_argument, 0, _OPT_SYSTER },
{ "acp", no_argument, 0, _OPT_ACP },
{ "filter", no_argument, 0, _OPT_FILTER },
{ "noaudio", no_argument, 0, _OPT_NOAUDIO },
{ "frequency", required_argument, 0, 'f' },
{ "amp", no_argument, 0, 'a' },
{ "gain", required_argument, 0, 'x' },
{ "antenna", required_argument, 0, 'A' },
{ "type", required_argument, 0, 't' },
{ 0, 0, 0, 0 }
};
static hacktv_t s;
const vid_configs_t *vid_confs;
vid_config_t vid_conf;
char *pre, *sub;
int l;
int r;
/* Initialise the state */
memset(&s, 0, sizeof(hacktv_t));
/* Default configuration */
s.output_type = "hackrf";
s.output = NULL;
s.mode = "i";
s.samplerate = 16000000;
s.level = 1.0;
s.deviation = -1;
s.gamma = -1;
s.repeat = 0;
s.verbose = 0;
s.teletext = NULL;
s.wss = NULL;
s.videocrypt = NULL;
s.videocrypt2 = NULL;
s.videocrypts = NULL;
s.syster = 0;
s.acp = 0;
s.filter = 0;
s.noaudio = 0;
s.frequency = 0;
s.amp = 0;
s.gain = 0;
s.antenna = NULL;
s.file_type = HACKTV_INT16;
opterr = 0;
while((c = getopt_long(argc, argv, "o:m:s:D:G:rvf:al:g:A:t:", long_options, &option_index)) != -1)
{
switch(c)
{
case 'o': /* -o, --output <[type:]target> */
/* Get a pointer to the output prefix and target */
pre = optarg;
sub = strchr(pre, ':');
if(sub != NULL)
{
/* Split the optarg into two */
*sub = '\0';
sub++;
}
/* Try to match the prefix with a known type */
if(strcmp(pre, "file") == 0)
{
s.output_type = "file";
s.output = sub;
}
else if(strcmp(pre, "hackrf") == 0)
{
s.output_type = "hackrf";
s.output = sub;
}
#ifdef HAVE_SOAPYSDR
else if(strcmp(pre, "soapysdr") == 0)
{
s.output_type = "soapysdr";
s.output = sub;
}
#endif
#ifdef HAVE_FL2K
else if(strcmp(pre, "fl2k") == 0)
{
s.output_type = "fl2k";
s.output = sub;
}
#endif
else
{
/* Unrecognised output type, default to file */
if(sub != NULL)
{
/* Recolonise */
sub--;
*sub = ':';
}
s.output_type = "file";
s.output = pre;
}
break;
case 'm': /* -m, --mode <name> */
s.mode = optarg;
break;
case 's': /* -s, --samplerate <value> */
s.samplerate = atoi(optarg);
break;
case 'l': /* -l, --level <value> */
s.level = atof(optarg);
break;
case 'D': /* -D, --deviation <value> */
s.deviation = atof(optarg);
break;
case 'G': /* -G, --gamma <value> */
s.gamma = atof(optarg);
break;
case 'r': /* -r, --repeat */
s.repeat = 1;
break;
case 'v': /* -v, --verbose */
s.verbose = 1;
break;
case _OPT_TELETEXT: /* --teletext <path> */
free(s.teletext);
s.teletext = strdup(optarg);
break;
case _OPT_WSS: /* --wss <mode> */
free(s.wss);
s.wss = strdup(optarg);
break;
case _OPT_VIDEOCRYPT: /* --videocrypt */
free(s.videocrypt);
s.videocrypt = strdup(optarg);
break;
case _OPT_VIDEOCRYPT2: /* --videocrypt2 */
free(s.videocrypt2);
s.videocrypt2 = strdup(optarg);
break;
case _OPT_VIDEOCRYPTS: /* --videocrypts */
free(s.videocrypts);
s.videocrypts = strdup(optarg);
break;
case _OPT_SYSTER: /* --syster */
s.syster = 1;
break;
case _OPT_ACP: /* --acp */
s.acp = 1;
break;
case _OPT_FILTER: /* --filter */
s.filter = 1;
break;
case _OPT_NOAUDIO: /* --noaudio */
s.noaudio = 1;
break;
case 'f': /* -f, --frequency <value> */
s.frequency = atol(optarg);
break;
case 'a': /* -a, --amp */
s.amp = 1;
break;
case 'g': /* -g, --gain <value> */
s.gain = atoi(optarg);
break;
case 'A': /* -A, --antenna <name> */
free(s.antenna);
s.antenna = strdup(optarg);
break;
case 't': /* -t, --type <type> */
if(strcmp(optarg, "uint8") == 0)
{
s.file_type = HACKTV_UINT8;
}
else if(strcmp(optarg, "int8") == 0)
{
s.file_type = HACKTV_INT8;
}
else if(strcmp(optarg, "uint16") == 0)
{
s.file_type = HACKTV_UINT16;
}
else if(strcmp(optarg, "int16") == 0)
{
s.file_type = HACKTV_INT16;
}
else if(strcmp(optarg, "int32") == 0)
{
s.file_type = HACKTV_INT32;
}
else if(strcmp(optarg, "float") == 0)
{
s.file_type = HACKTV_FLOAT;
}
else
{
fprintf(stderr, "Unrecognised file data type.\n");
return(-1);
}
break;
case '?':
print_usage();
return(0);
}
}
if(optind >= argc)
{
printf("No input specified.\n");
return(-1);
}
/* Load the mode configuration */
for(vid_confs = vid_configs; vid_confs->id != NULL; vid_confs++)
{
if(strcmp(s.mode, vid_confs->id) == 0) break;
}
if(vid_confs->id == NULL)
{
fprintf(stderr, "Unrecognised TV mode.\n");
return(-1);
}
/* Catch all the signals */
signal(SIGINT, &_sigint_callback_handler);
signal(SIGILL, &_sigint_callback_handler);
signal(SIGFPE, &_sigint_callback_handler);
signal(SIGSEGV, &_sigint_callback_handler);
signal(SIGTERM, &_sigint_callback_handler);
signal(SIGABRT, &_sigint_callback_handler);
memcpy(&vid_conf, vid_confs->conf, sizeof(vid_config_t));
if(s.deviation > 0)
{
/* Override the FM deviation value */
vid_conf.fm_deviation = s.deviation;
}
if(s.gamma > 0)
{
/* Override the gamma value */
vid_conf.gamma = s.gamma;
}
if(s.noaudio > 0)
{
/* Disable all audio sub-carriers */
vid_conf.fm_audio_level = 0;
vid_conf.am_audio_level = 0;
vid_conf.nicam_level = 0;
vid_conf.fm_mono_carrier = 0;
vid_conf.fm_left_carrier = 0;
vid_conf.fm_right_carrier = 0;
vid_conf.nicam_carrier = 0;
vid_conf.am_mono_carrier = 0;
}
vid_conf.level *= s.level;
if(s.teletext)
{
if(vid_conf.lines != 625)
{
fprintf(stderr, "Teletext is only available with 625 line modes.\n");
return(-1);
}
vid_conf.teletext = s.teletext;
}
if(s.wss)
{
if(vid_conf.lines != 625)
{
fprintf(stderr, "WSS is only available with 625 line modes.\n");
return(-1);
}
vid_conf.wss = s.wss;
}
if(s.videocrypt)
{
if(vid_conf.lines != 625 && vid_conf.colour_mode != VID_PAL)
{
fprintf(stderr, "Videocrypt I is only compatible with 625 line PAL modes.\n");
return(-1);
}
vid_conf.videocrypt = s.videocrypt;
}
if(s.videocrypt2)
{
if(vid_conf.lines != 625 && vid_conf.colour_mode != VID_PAL)
{
fprintf(stderr, "Videocrypt II is only compatible with 625 line PAL modes.\n");
return(-1);
}
/* Only allow both VC1 and VC2 if both are in free-access mode */
if(s.videocrypt && !(strcmp(s.videocrypt, "free") == 0 && strcmp(s.videocrypt2, "free") == 0))
{
fprintf(stderr, "Videocrypt I and II cannot be used together except in free-access mode.\n");
return(-1);
}
vid_conf.videocrypt2 = s.videocrypt2;
}
if(s.videocrypts)
{
if(vid_conf.lines != 625 && vid_conf.colour_mode != VID_PAL)
{
fprintf(stderr, "Videocrypt S is only compatible with 625 line PAL modes.\n");
return(-1);
}
if(s.videocrypt || s.videocrypt2)
{
fprintf(stderr, "Using multiple scrambling modes is not supported.\n");
return(-1);
}
vid_conf.videocrypts = s.videocrypts;
}
if(s.syster)
{
if(vid_conf.lines != 625 && vid_conf.colour_mode != VID_PAL)
{
fprintf(stderr, "Nagravision Syster is only compatible with 625 line PAL modes.\n");
return(-1);
}
if(vid_conf.videocrypt || vid_conf.videocrypt2 || vid_conf.videocrypts)
{
fprintf(stderr, "Using multiple scrambling modes is not supported.\n");
return(-1);
}
vid_conf.syster = 1;
}
if(s.acp)
{
if(vid_conf.lines != 625 && vid_conf.lines != 525)
{
fprintf(stderr, "Analogue Copy Protection is only compatible with 525 and 625 line modes.\n");
return(-1);
}
if(vid_conf.videocrypt || vid_conf.videocrypt2 || vid_conf.videocrypts || vid_conf.syster)
{
fprintf(stderr, "Analogue Copy Protection cannot be used with video scrambling enabled.\n");
return(-1);
}
vid_conf.acp = 1;
}
/* Setup video encoder */
r = vid_init(&s.vid, s.samplerate, &vid_conf);
if(r != VID_OK)
{
fprintf(stderr, "Unable to initialise video encoder.\n");
return(-1);
}
vid_info(&s.vid);
if(s.filter)
{
vid_init_filter(&s.vid);
}
if(strcmp(s.output_type, "hackrf") == 0)
{
if(rf_hackrf_open(&s, s.output, s.frequency, s.gain, s.amp) != HACKTV_OK)
{
vid_free(&s.vid);
return(-1);
}
}
#ifdef HAVE_SOAPYSDR
else if(strcmp(s.output_type, "soapysdr") == 0)
{
if(rf_soapysdr_open(&s, s.output, s.frequency, s.gain, s.antenna) != HACKTV_OK)
{
vid_free(&s.vid);
return(-1);
}
}
#endif
#ifdef HAVE_FL2K
else if(strcmp(s.output_type, "fl2k") == 0)
{
if(rf_fl2k_open(&s, s.output) != HACKTV_OK)
{
vid_free(&s.vid);
return(-1);
}
}
#endif
else if(strcmp(s.output_type, "file") == 0)
{
if(rf_file_open(&s, s.output, s.file_type) != HACKTV_OK)
{
vid_free(&s.vid);
return(-1);
}
}
av_ffmpeg_init();
do
{
for(c = optind; c < argc && !_abort; c++)
{
/* Get a pointer to the output prefix and target */
pre = argv[c];
sub = strchr(pre, ':');
if(sub != NULL)
{
l = sub - pre;
sub++;
}
else
{
l = strlen(pre);
}
if(strncmp(pre, "test", l) == 0)
{
r = av_test_open(&s.vid);
}
else if(strncmp(pre, "ffmpeg", l) == 0)
{
r = av_ffmpeg_open(&s.vid, sub);
}
else
{
r = av_ffmpeg_open(&s.vid, pre);
}
if(r != HACKTV_OK)
{
vid_free(&s.vid);
return(-1);
}
while(!_abort)
{
size_t samples;
int16_t *data = vid_next_line(&s.vid, &samples);
if(data == NULL) break;
if(_hacktv_rf_write(&s, data, samples) != HACKTV_OK) break;
}
vid_av_close(&s.vid);
}
}
while(s.repeat && !_abort);
_hacktv_rf_close(&s);
vid_free(&s.vid);
av_ffmpeg_deinit();
return(0);
}