-
Notifications
You must be signed in to change notification settings - Fork 14
/
bmd-streamer.c
1478 lines (1307 loc) · 45.6 KB
/
bmd-streamer.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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* BlackMagic Design tools - h264 stream over USB extractor
* - ATEM TV Studio
* - H264 Pro Encoder
*
* These devices seem to use Fujitsu MB86H56 for encoding HD H264 video.
* Getting technical datasheet to that chip would make things a lot clearer.
*/
#define _GNU_SOURCE
#include <math.h>
#include <errno.h>
#include <spawn.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <signal.h>
#include <string.h>
#include <syslog.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <libusb.h>
#include "blackmagic.h"
#define VERSION "1.0.2"
/*
* TODO and ideas:
* - Get VR_SET_AUDIO_DELAY for remaining modes from USB traces
* - Selecting capture target format - now it's "Native (Progressive)"
* - Make the capture thread cancellable
*/
#define array_size(x) (sizeof(x) / sizeof(x[0]))
struct encoding_parameters {
uint16_t video_kbps, video_max_kbps, audio_kbps, audio_khz;
uint8_t h264_profile, h264_level, h264_bframes, h264_cabac, fps_divider;
int8_t input_source;
char * exec_program;
int respawn : 1;
int pipe_sz;
int src_x, src_y, src_width, src_height, dst_width, dst_height;
};
static int do_syslog = 0;
static int loglevel = LOG_NOTICE;
static int firmware_fd = AT_FDCWD;
static int running = 1;
static volatile int num_workers = 0;
static struct encoding_parameters ep = {
.video_kbps = 3000,
.video_max_kbps = 3500,
.h264_profile = FX2_H264_HIGH,
.h264_level = 42,
.h264_cabac = 1,
.h264_bframes = 1,
.audio_kbps = 256,
.audio_khz = 48000,
.fps_divider = 1,
.input_source = -1,
};
static const char *input_source_names[5] = {
[INPUT_COMPONENT] = "component",
[INPUT_HDMI] = "hdmi",
[INPUT_SDI] = "sdi",
[INPUT_COMPOSITE] = "composite",
[INPUT_SVIDEO] = "s-video",
};
enum DISPLAY_MODE {
DMODE_720x480i_29_97 = 0,
DMODE_720x576i_25,
DMODE_invalid,
DMODE_720x480p_59_94,
DMODE_720x576p_50,
DMODE_1920x1080p_23_976,
DMODE_1920x1080p_24,
DMODE_1920x1080p_25,
DMODE_1920x1080p_29_97, /* 0x08 */
DMODE_1920x1080p_30,
DMODE_1920x1080i_25,
DMODE_1920x1080i_29_97,
DMODE_1920x1080i_30,
DMODE_1920x1080p_50,
DMODE_1920x1080p_59_94,
DMODE_1920x1080p_60,
DMODE_1280x720p_50, /* 0x10 */
DMODE_1280x720p_59_94,
DMODE_1280x720p_60,
DMODE_MAX
};
struct display_mode {
const char * description;
int width, height;
int fps_numerator, fps_denominator;
uint8_t interlaced : 1;
uint8_t program_fpga : 1;
uint8_t convert_to_1088 : 1;
uint8_t fx2_fps;
uint8_t audio_delay;
uint16_t ain_offset;
uint16_t r1000, r1404, r140a, r1430_l;
uint16_t r147x[4];
uint16_t r154x[11];
};
static struct display_mode *display_modes[DMODE_MAX] = {
[DMODE_720x480i_29_97] = &(struct display_mode){
.description = "480i 29.97",
.width = 720, .height = 486, .interlaced = 1, .program_fpga = 1,
.fps_numerator = 30000, .fps_denominator = 1001, .fx2_fps = 0x4,
.audio_delay = 0x27, .ain_offset = 0x0000,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x10, 0x70, 0x70, 0x10 },
.r154x = { 0x1050, 0x0002, 0x07ff, 0x035a, 0x020d, 0x008a, 0x002c, 0x07ff, 0x02d0, 0x01e8, 0x001e },
},
[DMODE_720x576i_25] = &(struct display_mode){
.description = "576i 25",
.width = 720, .height = 576, .interlaced = 1, .program_fpga = 1,
.fps_numerator = 25, .fps_denominator = 1, .fx2_fps = 0x3,
.audio_delay = 0x30, .ain_offset = 0x0000,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x10, 0x70, 0x70, 0x10 },
.r154x = { 0x1050, 0x0000, 0x07ff, 0x0360, 0x0271, 0x0090, 0x002e, 0x07ff, 0x02d0, 0x0240, 0x0019 },
},
/* DMODE_720x480p_59_94 */
[DMODE_720x576p_50] = &(struct display_mode){
.description = "576p 50",
.width = 720, .height = 576,
.fps_numerator = 50, .fps_denominator = 1, .fx2_fps = 0x6,
.ain_offset = 0x0000,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x10, 0x70, 0x70, 0x10 },
.r154x = { 0x1050, 0x0000, 0x07ff, 0x0360, 0x0271, 0x0090, 0x002e, 0x07ff, 0x02d0, 0x0240, 0x0032 },
},
[DMODE_1920x1080p_23_976] = &(struct display_mode){
.description = "1080p 23.97",
.width = 1920, .height = 1080,
.fps_numerator = 24000, .fps_denominator = 1001, .fx2_fps = 0x1,
.ain_offset = 0x0177,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x10, 0x70, 0x70, 0x10 },
.r154x = { 0x0000, 0x0001, 0x07ff, 0x0abe, 0x0465, 0x033e, 0x0015, 0x07ff, 0x0780, 0x0438, 0x0018 },
},
[DMODE_1920x1080p_24] = &(struct display_mode){
.description = "1080p 24",
.width = 1920, .height = 1080,
.fps_numerator = 24, .fps_denominator = 1, .fx2_fps = 0x2,
.ain_offset = 0x0000,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x10, 0x70, 0x70, 0x10 },
.r154x = { 0x0000, 0x0001, 0x07ff, 0x0abe, 0x0465, 0x033e, 0x0015, 0x07ff, 0x0780, 0x0438, 0x0018 },
},
[DMODE_1920x1080p_25] = &(struct display_mode){
.description = "1080p 25",
.width = 1920, .height = 1080,
.fps_numerator = 25, .fps_denominator = 1, .fx2_fps = 0x3,
.ain_offset = 0x0708,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x26, 0x7d, 0x56, 0x07 },
.r154x = { 0x0000, 0x0001, 0x07ff, 0x0abd, 0x0465, 0x00c3, 0x0015, 0x07ff, 0x0780, 0x0438, 0x0019 },
},
/* DMODE_1920x1080p_29_97 */
[DMODE_1920x1080p_30] = &(struct display_mode){
.description = "1080p 30",
.width = 1920, .height = 1080,
.fps_numerator = 30, .fps_denominator = 1, .fx2_fps = 0x5,
.ain_offset = 0x0a8c,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x26, 0x7d, 0x56, 0x07 },
.r154x = { 0x0000, 0x0001, 0x07ff, 0x0897, 0x0465, 0x00c5, 0x0015, 0x07ff, 0x0780, 0x0438, 0x001e },
},
[DMODE_1920x1080i_25] = &(struct display_mode){
.description = "1080i 50",
.width = 1920, .height = 1080, .interlaced = 1, .convert_to_1088 = 1,
.fps_numerator = 25, .fps_denominator = 1, .fx2_fps = 0x3,
.ain_offset = 0x0000,
.r1000 = 0x0200, .r1404 = 0x0041, .r140a = 0x1701, .r1430_l = 0xff,
.r147x = { 0x26, 0x7d, 0x56, 0x07 },
.r154x = { 0x0000, 0x0034, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000e, 0x0780, 0x0438, 0x0000 },
},
[DMODE_1920x1080i_29_97] = &(struct display_mode){
.description = "1080i 29.97",
.width = 1920, .height = 1080, .interlaced = 1, .convert_to_1088 = 1,
.fps_numerator = 30000, .fps_denominator = 1001, .fx2_fps = 0x4,
.ain_offset = 0x0000,
.r1000 = 0x0200, .r1404 = 0x0071, .r140a = 0x1700, .r1430_l = 0xff,
.r147x = { 0x26, 0x7d, 0x56, 0x07 },
.r154x = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x000e, 0x0000, 0x0400, 0x0000 },
},
[DMODE_1920x1080i_30] = &(struct display_mode){
.description = "1080i 30",
.width = 1920, .height = 1080, .interlaced = 1, .convert_to_1088 = 1, .program_fpga = 1,
.fps_numerator = 30, .fps_denominator = 1, .fx2_fps = 0x5,
.ain_offset = 0x0000,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x10, 0x70, 0x70, 0x10 },
.r154x = { 0x0000, 0x0001, 0x07ff, 0x0898, 0x0465, 0x0118, 0x0015, 0x07ff, 0x0780, 0x0438, 0x001e },
},
[DMODE_1920x1080p_50] = &(struct display_mode){
.description = "1080p 50",
.width = 1920, .height = 1080, .interlaced = 0,
.fps_numerator = 50, .fps_denominator = 1, .fx2_fps = 0x6,
.ain_offset = 0x05a0,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x10, 0x70, 0x70, 0x10 },
.r154x = { 0x0000, 0x0001, 0x07ff, 0x0a50, 0x0465, 0x02d0, 0x0015, 0x07ff, 0x0780, 0x0438, 0x0032 },
},
[DMODE_1920x1080p_59_94] = &(struct display_mode){
.description = "1080p 59.94",
.width = 1920, .height = 1080, .interlaced = 0,
.fps_numerator = 60000, .fps_denominator = 1001, .fx2_fps = 0x7,
.ain_offset = 0x0000,
.r1000 = 0x0200, .r1404 = 0x0071, .r140a = 0x151e, .r1430_l = 0x02,
.r147x = { 0x10, 0x70, 0x70, 0x10 },
.r154x = { 0x0000, 0x0001, 0x07ff, 0x0898, 0x0465, 0x0118, 0x0015, 0x07ff, 0x0780, 0x0438, 0x0000 },
},
[DMODE_1920x1080p_60] = &(struct display_mode){
.description = "1080p 60",
.width = 1920, .height = 1080, .interlaced = 0,
.fps_numerator = 60, .fps_denominator = 1, .fx2_fps = 8,
.ain_offset = 0x079e,
.r1000 = 0x0200, .r1404 = 0x0071, .r140a = 0x151e, .r1430_l = 0x02,
.r147x = { 0x26, 0x7d, 0x56, 0x07 },
.r154x = { 0x0000, 0x0001, 0x07ff, 0x0897, 0x0465, 0x00c5, 0x0015, 0x07ff, 0x0780, 0x0438, 0x0000 },
},
[DMODE_1280x720p_50] = &(struct display_mode){
.description = "720p 50",
.width = 1280, .height = 720, .interlaced = 0,
.fps_numerator = 50, .fps_denominator = 1, .fx2_fps = 0x6,
.audio_delay = 0x05, .ain_offset = 0x0000,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x10, 0x70, 0x70, 0x10 },
.r154x = { 0x0000, 0x0001, 0x07ff, 0x07bb, 0x02ee, 0x0107, 0x001a, 0x07ff, 0x0500, 0x02d0, 0x0032 },
},
[DMODE_1280x720p_59_94] = &(struct display_mode){
.description = "720p 59.94",
.width = 1280, .height = 720, .interlaced = 0,
.fps_numerator = 60000, .fps_denominator = 1001, .fx2_fps = 0x7,
.audio_delay = 0x07, .ain_offset = 0x0384,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x10, 0x70, 0x70, 0x10 },
.r154x = { 0x0000, 0x0001, 0x07ff, 0x07bb, 0x02ee, 0x0107, 0x001a, 0x07ff, 0x0500, 0x02d0, 0x003c },
},
[DMODE_1280x720p_60] = &(struct display_mode){
.description = "720p 60",
.width = 1280, .height = 720,
.fps_numerator = 60, .fps_denominator = 1, .fx2_fps = 0x8,
.audio_delay = 0x06, .ain_offset = 0x02ee,
.r1000 = 0x0500, .r1404 = 0x0071, .r140a = 0x17ff, .r1430_l = 0xff,
.r147x = { 0x10, 0x70, 0x70, 0x10 },
.r154x = { 0x0000, 0x0001, 0x07ff, 0x0671, 0x02ee, 0x010b, 0x001a, 0x07ff, 0x0500, 0x02d0, 0x003c },
},
};
enum {
FX2Status_Unknown = 0,
FX2Status_NotPowered,
FX2Status_UpdatingFirmware,
FX2Status_Programming,
FX2Status_Booting,
FX2Status_Idle,
FX2Status_PreparingEncode,
FX2Status_Encoding,
FX2Status_PreparingNullOutput,
FX2Status_NullOutput,
FX2Status_PreparingStop,
FX2Status_Stopped,
FX2Status_InvalidFPGA
};
static const char* FX2Status_to_String(int s)
{
switch (s) {
case FX2Status_Unknown: return "Unknown";
case FX2Status_NotPowered: return "Not powered";
case FX2Status_UpdatingFirmware: return "Updating firmware";
case FX2Status_Programming: return "Programming H56";
case FX2Status_Booting: return "Booting H56";
case FX2Status_Idle: return "Idle";
case FX2Status_PreparingEncode: return "Preparing for Encode";
case FX2Status_Encoding: return "Encoding";
case FX2Status_PreparingNullOutput: return "Preparing for Null output";
case FX2Status_NullOutput: return "Null output";
case FX2Status_PreparingStop: return "Preparing for Stop";
case FX2Status_Stopped: return "Stopped";
case FX2Status_InvalidFPGA: return "FPGA Firmware Invalid";
default: return "Bad Status";
}
}
static int input_mode_to_display_mode(uint8_t mode)
{
if (mode & 0x80)
mode &= 0x9f;
else
mode &= 0x60;
switch (mode) {
case 0x00: return DMODE_720x480i_29_97;
case 0x20: return DMODE_720x576i_25;
case 0x40: return DMODE_720x480p_59_94;
case 0x60: return DMODE_720x576p_50;
case 0x80: return DMODE_1920x1080i_30;
case 0x81: return DMODE_1920x1080i_29_97;
case 0x82: return DMODE_1920x1080i_25;
case 0x83: return DMODE_1920x1080p_25;
case 0x84: case 0x86: return DMODE_1920x1080p_24;
case 0x85: case 0x87: return DMODE_1920x1080p_23_976;
case 0x88: return DMODE_1280x720p_60;
case 0x89: return DMODE_1280x720p_59_94;
case 0x8a: return DMODE_1280x720p_50;
case 0x8e: return DMODE_1920x1080p_30;
case 0x8f: return DMODE_1920x1080p_29_97;
case 0x90: return DMODE_1920x1080p_60;
case 0x91: return DMODE_1920x1080p_59_94;
case 0x92: return DMODE_1920x1080p_50;
default: return DMODE_invalid;
}
}
static void hexdump(char *buf, size_t buflen, const char *ptr, size_t ptrlen)
{
int i;
for (i = 0; i < ptrlen && (i+1)*2+1 <= buflen; i++)
snprintf(&buf[i*2], 3, "%02x", (unsigned char) ptr[i]);
}
static void dlog(int prio, const char *format, ...)
{
va_list va;
if (prio > loglevel) return;
va_start(va, format);
if (do_syslog)
vsyslog(prio, format, va);
else {
flockfile(stderr);
vfprintf(stderr, format, va);
fputc('\n', stderr);
funlockfile(stderr);
}
va_end(va);
}
struct firmware {
uint32_t size;
uint16_t device_id;
uint8_t data[];
};
static struct firmware *firmwares[2];
static struct firmware *load_firmware(const char *filename, uint16_t device_id)
{
struct firmware *fw;
struct stat st;
int r, fd;
r = fstatat(firmware_fd, filename, &st, 0);
if (r != 0) {
dlog(LOG_ERR, "%s: failed to load firmware to memory", filename);
return NULL;
}
fw = malloc(sizeof(struct firmware) + st.st_size);
if (fw == NULL)
return NULL;
fw->size = st.st_size;
fw->device_id = device_id;
fd = openat(firmware_fd, filename, O_RDONLY);
if (fd < 0)
goto error;
if (read(fd, fw->data, fw->size) != fw->size)
goto error;
close(fd);
return fw;
error:
close(fd);
free(fw);
return NULL;
}
struct mpeg_parser_buffer {
int output_fd;
int oldlen;
unsigned char olddata[0xbc];
unsigned char data[16*1024];
};
static int mpegparser_parse(struct mpeg_parser_buffer *pb, int newlen)
{
struct iovec iov[64];
unsigned char *buf = &pb->data[-pb->oldlen];
int i = 0, len = newlen + pb->oldlen, r = 0, ioc = 0, nomerge = 1;
while (i + 0xbc <= len) {
if (memcmp(&buf[i], "\x00\x00\x00\x00", 4) == 0) goto skip_block;
if (buf[i] != 0x47) {
while (buf[i] != 0x47 && i < len)
i++;
goto skip;
}
if (buf[i+1] == 0x1f && buf[i+2] == 0xff) goto skip_block;
if (pb->output_fd < 0 || r) {
skip_block:
i += 0xbc;
skip:
nomerge = 1;
continue;
}
if (nomerge) {
nomerge = 0;
iov[ioc].iov_base = &buf[i];
iov[ioc].iov_len = 0xbc;
if (++ioc >= array_size(iov)) {
if (writev(pb->output_fd, iov, ioc) < 0) {
dlog(LOG_NOTICE, "error writing MPEG TS: %s",
strerror(errno));
if (errno == EPIPE) r = -1;
}
ioc = 0;
nomerge = 1;
}
} else {
iov[ioc-1].iov_len += 0xbc;
}
i += 0xbc;
}
if (ioc && writev(pb->output_fd, iov, ioc) < 0) {
dlog(LOG_NOTICE, "error writing MPEG TS: %s",
strerror(errno));
if (errno == EPIPE) r = -1;
}
pb->oldlen = len - i;
memcpy(&pb->data[-pb->oldlen], &buf[i], pb->oldlen);
return r;
}
struct blackmagic_device {
char name[64];
pthread_t device_thread, mpegts_thread;
volatile int running;
int status;
int fxstatus;
int recognized : 1;
int encode_sent : 1;
int display_mode_changed : 1;
int current_display_mode;
struct display_mode *current_mode;
struct libusb_device_descriptor desc;
libusb_device *usbdev;
libusb_device_handle *usbdev_handle;
uint8_t mac[6];
uint8_t message_buffer[1024];
struct mpeg_parser_buffer mpegparser;
};
static void reapchildren(int sig)
{
int status;
while (waitpid(-1, &status, WNOHANG) == 0 || errno == EINTR);
}
static void dostop(int sig)
{
running = 0;
}
static void bmd_set_input_source(struct blackmagic_device *bmd, uint8_t mode)
{
int r;
if (bmd->status != LIBUSB_SUCCESS)
return;
dlog(LOG_NOTICE, "%s: switching input source to %s (%d)",
bmd->name, input_source_names[mode], mode);
r = libusb_control_transfer(
bmd->usbdev_handle, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR,
VR_SET_INPUT_SOURCE, 0x0000, 0, &mode, 1, 1000);
if (r < 0)
bmd->status = r;
}
static void bmd_read_register(struct blackmagic_device *bmd, uint8_t reg, uint8_t *value)
{
int r;
if (bmd->status != LIBUSB_SUCCESS)
return;
r = libusb_control_transfer(
bmd->usbdev_handle, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR,
VR_READ_REGISTER, 0x0000, reg << 8, value, 1, 1000);
if (r < 0)
bmd->status = r;
}
static void bmd_load_firmware(struct blackmagic_device *bmd, uint16_t address, uint8_t *data, size_t len)
{
int r;
if (bmd->status != LIBUSB_SUCCESS)
return;
r = libusb_control_transfer(
bmd->usbdev_handle, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR,
CYPRESS_VR_FIRMWARE_LOAD, address, 0, data, len, 1000);
if (r < 0)
bmd->status = r;
}
static uint16_t bmd_fujitsu_read(struct blackmagic_device *bmd, uint32_t reg)
{
uint8_t value[2];
int r;
if (bmd->status != LIBUSB_SUCCESS)
return 0;
r = libusb_control_transfer(
bmd->usbdev_handle, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR,
VR_FUJITSU_READ, reg & 0xffff, (reg >> 16) & 0xff,
value, sizeof(value), 1000);
if (r != 2)
return 0;
return (value[0] << 8) | value[1];
}
static void bmd_fujitsu_write(struct blackmagic_device *bmd, uint32_t reg, uint16_t value)
{
uint8_t msg[5];
int r;
if (bmd->status != LIBUSB_SUCCESS)
return;
msg[0] = reg >> 16;
msg[1] = reg >> 8;
msg[2] = reg;
msg[3] = value >> 8;
msg[4] = value;
if (loglevel >= LOG_DEBUG) {
uint16_t oldvalue = bmd_fujitsu_read(bmd, reg);
if (value != oldvalue)
dlog(LOG_DEBUG, "%s: fujitsu_write @%06x %04x != %04x",
bmd->name, reg, value, oldvalue);
}
r = libusb_control_transfer(
bmd->usbdev_handle, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR,
VR_FUJITSU_WRITE, 0, 0, msg, 5, 1000);
if (r < 0)
bmd->status = r;
}
static int bmd_upload_firmware(struct blackmagic_device *bmd, struct firmware *fw)
{
struct _fwhdr { uint8_t len, addr_high, addr_low, marker, data[]; };
struct _fwhdr *fwhdr;
uint16_t addr;
int i, pos = 0;
bmd_load_firmware(bmd, 0xe600, "\x01", 1);
while (pos < fw->size && bmd->status == LIBUSB_SUCCESS) {
fwhdr = (struct _fwhdr *) &fw->data[pos];
if (fwhdr->marker != 0)
break;
addr = (fwhdr->addr_high << 8) + fwhdr->addr_low;
bmd_load_firmware(bmd, addr, fwhdr->data, fwhdr->len);
pos += fwhdr->len + 5;
}
bmd_load_firmware(bmd, 0xe600, "\x00", 1);
return bmd->status == LIBUSB_SUCCESS;
}
static const char *format_usb_ports(const uint8_t *ports, size_t n, char *fmt)
{
int i = 0, p = 0;
if (n == 0) {
fmt[0] = 0;
return fmt;
}
p += sprintf(fmt, "%u", ports[0]);
for (i = 1; i < n; i++)
p += sprintf(&fmt[p], ".%u", ports[i]);
return fmt;
}
#ifdef __APPLE__
static int pipe2(int pipefd[2], int flags)
{
if (flags & ~O_CLOEXEC) { /* not implemented in this simple wrapper */
errno = EINVAL;
return -1;
}
if (pipe(pipefd) < 0)
return -1;
if (flags & O_CLOEXEC)
{
if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) < 0 ||
fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) < 0) {
close(pipefd[0]);
close(pipefd[1]);
return -1;
}
}
return 0;
}
#endif
static int bmd_start_exec_program(struct blackmagic_device *bmd, int pipe_sz, char *exec_program)
{
uint8_t ports[8];
char fmt[array_size(ports)*4];
char tmp[1024];
char *envp[16];
char *argv[] = { exec_program, 0 };
int r, i, p, pipefd[2];
posix_spawn_file_actions_t fa;
if (!exec_program) {
bmd->mpegparser.output_fd = STDOUT_FILENO;
return 1;
}
dlog(LOG_DEBUG, "%s: launching exec program: %s", bmd->name, ep.exec_program);
if (pipe2(pipefd, O_CLOEXEC) < 0)
return 0;
if (pipe_sz) {
if (fcntl(pipefd[0], F_SETPIPE_SZ, pipe_sz * 1024) < 0)
dlog(LOG_ERR, "%s: unable to set pipe size",
bmd->name, ep.exec_program);
}
i = p = 0;
if (bmd->desc.idProduct != USB_PID_BMD_H264_PRO_RECORDER) {
envp[i++] = &tmp[p];
p += snprintf(&tmp[p], sizeof(tmp)-p, "BMD_MAC=%02x%02x%02x%02x%02x%02x",
bmd->mac[0], bmd->mac[1], bmd->mac[2], bmd->mac[3], bmd->mac[4], bmd->mac[5]) + 1;
}
envp[i++] = &tmp[p];
p += snprintf(&tmp[p], sizeof(tmp)-p, "BMD_STREAM_WIDTH=%d", bmd->current_mode->width) + 1;
envp[i++] = &tmp[p];
p += snprintf(&tmp[p], sizeof(tmp)-p, "BMD_STREAM_HEIGHT=%d", bmd->current_mode->height) + 1;
envp[i++] = &tmp[p];
r = libusb_get_port_numbers(bmd->usbdev, ports, array_size(ports));
p += snprintf(&tmp[p], sizeof(tmp)-p, "BMD_USB_PORTS=%s", format_usb_ports(ports, r, fmt)) + 1;
envp[i] = 0;
posix_spawn_file_actions_init(&fa);
posix_spawn_file_actions_adddup2(&fa, pipefd[0], STDIN_FILENO);
posix_spawn_file_actions_addclose(&fa, pipefd[1]);
r = posix_spawnp(NULL, argv[0], &fa, NULL, argv, envp);
posix_spawn_file_actions_destroy(&fa);
close(pipefd[0]);
if (r != 0) {
close(pipefd[1]);
return 0;
}
bmd->mpegparser.output_fd = pipefd[1];
fcntl(pipefd[1], F_SETFL, O_NONBLOCK);
return 1;
}
static void bmd_kill_exec_program(struct blackmagic_device *bmd)
{
if (ep.exec_program && bmd->mpegparser.output_fd >= 0) {
dlog(LOG_DEBUG, "%s: closing output stream", bmd->name);
close(bmd->mpegparser.output_fd);
}
bmd->mpegparser.output_fd = -1;
}
static void *bmd_pump_mpegts(void *ctx)
{
struct blackmagic_device *bmd = ctx;
int actual_length, r;
do {
r = libusb_bulk_transfer(
bmd->usbdev_handle, 0x86,
bmd->mpegparser.data, sizeof(bmd->mpegparser.data),
&actual_length, 5000);
if (r != LIBUSB_SUCCESS && r != LIBUSB_ERROR_TIMEOUT)
break;
if (r == LIBUSB_ERROR_TIMEOUT)
dlog(LOG_INFO, "%s: mpeg-ts pump: timeout reading data, retrying!", bmd->name);
if (mpegparser_parse(&bmd->mpegparser, actual_length) < 0) {
if (ep.exec_program) {
if (ep.respawn) {
bmd_kill_exec_program(bmd);
bmd_start_exec_program(bmd, ep.pipe_sz, ep.exec_program);
} else {
bmd->running = 0;
}
} else
running = 0;
}
} while (running && bmd->running);
dlog(LOG_DEBUG, "%s: mpeg-ts pump exiting: %s", bmd->name, libusb_error_name(r));
return NULL;
}
static int bmd_recognize_device(struct blackmagic_device *bmd)
{
int i;
bmd->recognized = 1;
/* Pro Recorder does not have a NIC */
if (bmd->desc.idProduct == USB_PID_BMD_H264_PRO_RECORDER)
return 1;
/* ATEM TV Studio register layout:
* 0x84..0x87 firmware version, timestamp or checksum
* 4.1.2 -> 71 70 86 c6
* 4.2.1 -> 7a 01 f1 34
* 0x88..0x8d mac address
* 0xa0..0xa3 ipv4 address
* 0xa4..0xa7 ipv4 netmask
* 0xa8..0xab ipv4 gateway
*/
for (i = 0; i < 6; i++)
bmd_read_register(bmd, 0x88 + i, &bmd->mac[i]);
dlog(LOG_NOTICE, "%s: MAC address %02x:%02x:%02x:%02x:%02x:%02x",
bmd->name,
bmd->mac[0], bmd->mac[1], bmd->mac[2],
bmd->mac[3], bmd->mac[4], bmd->mac[5]);
return bmd->status == LIBUSB_SUCCESS;
}
static int bmd_configure_encoder(struct blackmagic_device *bmd, struct encoding_parameters *ep)
{
uint8_t fpga_command_1[1] = { 0x20 };
uint8_t fpga_command_2[1] = { 0x40 };
struct display_mode *current_mode = bmd->current_mode;
uint32_t total_bandwidth;
float fps;
int r;
fps = (float)current_mode->fps_numerator / current_mode->fps_denominator;
/* apparently approximate of total bandwidth required */
total_bandwidth = 85226;
total_bandwidth += (ep->audio_kbps * 1000.0 * 1024 / (8 * ep->audio_khz) + 14) / 148 * 1504.0 * ep->audio_khz / 1024;
total_bandwidth += 48128.0 * fps / ((fps == 25 || fps == 50) ? 12 : 15);
total_bandwidth += 1.021739130434783 * (ceil(1464*fps) + ceil(152*fps) + (ep->video_max_kbps + 1000) * 1000);
r = libusb_control_transfer(
bmd->usbdev_handle, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR,
current_mode->program_fpga ? VR_SEND_FPGA_COMMAND : VR_CLEAR_FPGA_COMMAND, 0, 0,
fpga_command_1, sizeof(fpga_command_1), 1000);
if (r < 0) {
bmd->status = r;
return 0;
}
r = libusb_control_transfer(
bmd->usbdev_handle, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR,
VR_CLEAR_FPGA_COMMAND, 0, 0,
fpga_command_2, sizeof(fpga_command_2), 1000);
if (r < 0) {
bmd->status = r;
return 0;
}
r = libusb_control_transfer(
bmd->usbdev_handle, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR,
VR_SET_AUDIO_DELAY, 0, 0, ¤t_mode->audio_delay, 1, 5000);
if (r < 0) {
bmd->status = r;
return 0;
}
/* Group 1 - likely muxing related */
bmd_fujitsu_write(bmd, 0x0800ea, 0x0a0c);
bmd_fujitsu_write(bmd, 0x0800ec, 0x000d);
bmd_fujitsu_write(bmd, 0x0800ee, 0x0000);
bmd_fujitsu_write(bmd, 0x0800f0, 0x0504);
bmd_fujitsu_write(bmd, 0x0800f2, 0x4844);
bmd_fujitsu_write(bmd, 0x0800f4, 0x4d56);
bmd_fujitsu_write(bmd, 0x0800f6, 0x8804);
bmd_fujitsu_write(bmd, 0x0800f8, 0x0fff);
bmd_fujitsu_write(bmd, 0x0800fa, 0xfcfc);
bmd_fujitsu_write(bmd, 0x080100, 0x6308);
bmd_fujitsu_write(bmd, 0x080102, 0xc000 | ((total_bandwidth/400) >> 8));
bmd_fujitsu_write(bmd, 0x080104, 0x00ff | ((total_bandwidth/400) << 8));
bmd_fujitsu_write(bmd, 0x080106, 0xffff);
bmd_fujitsu_write(bmd, 0x080108, 0xffff);
bmd_fujitsu_write(bmd, 0x080110, 0x1bf0);
bmd_fujitsu_write(bmd, 0x080112, 0x11f0);
bmd_fujitsu_write(bmd, 0x080114, 0x0302);
bmd_fujitsu_write(bmd, 0x080116, 0x0102 | (current_mode->fx2_fps << 3));
bmd_fujitsu_write(bmd, 0x080118, 0x0ff1); //(audiomode_related_fixed_var << 8) | 0xf1
bmd_fujitsu_write(bmd, 0x08011a, 0x00f0);
bmd_fujitsu_write(bmd, 0x08011c, 0x0000);
/* Group 2 - MPEG TS muxer */
bmd_fujitsu_write(bmd, 0x001000, current_mode->r1000);
bmd_fujitsu_write(bmd, 0x001002, 0x8480);
bmd_fujitsu_write(bmd, 0x001004, 0x0002);
bmd_fujitsu_write(bmd, 0x001006, total_bandwidth / 1000);
bmd_fujitsu_write(bmd, 0x001008, 0x0000);
bmd_fujitsu_write(bmd, 0x00100c, 0x0000);
bmd_fujitsu_write(bmd, 0x00100e, 0x0000);
bmd_fujitsu_write(bmd, 0x001010, 0x0000);
bmd_fujitsu_write(bmd, 0x001012, 0x0000);
bmd_fujitsu_write(bmd, 0x001014, 0x0000);
bmd_fujitsu_write(bmd, 0x001016, 0x1011); // Video PID
bmd_fujitsu_write(bmd, 0x001018, 0x1100); // Audio PID
bmd_fujitsu_write(bmd, 0x00101a, 0x0100); // Program Map Table PID
bmd_fujitsu_write(bmd, 0x00101c, 0x001f); // DVB SIT PID
bmd_fujitsu_write(bmd, 0x00101e, 0x1001); // Program clock PID
bmd_fujitsu_write(bmd, 0x001020, 0x00e0); // Video PES stream ID
bmd_fujitsu_write(bmd, 0x001022, 0x00c0); // Audio PES stream ID
bmd_fujitsu_write(bmd, 0x001146, 0x0101);
bmd_fujitsu_write(bmd, 0x001148, 0x0100);
/* Group 3 - H264 encoder, video source tuning */
bmd_fujitsu_write(bmd, 0x001404, current_mode->r1404);
bmd_fujitsu_write(bmd, 0x001406, ep->video_max_kbps + 1000);
bmd_fujitsu_write(bmd, 0x001408, ep->video_kbps);
bmd_fujitsu_write(bmd, 0x00140a, current_mode->r140a);
bmd_fujitsu_write(bmd, 0x00140c, ep->h264_cabac ? 0x0000 : 0x0100);
bmd_fujitsu_write(bmd, 0x00140e, 0xd400 | ((current_mode->fps_denominator == 1) ? 0x0001 : 0x0000));
bmd_fujitsu_write(bmd, 0x001418, 0x0001);
bmd_fujitsu_write(bmd, 0x001420, 0x0000);
bmd_fujitsu_write(bmd, 0x001422, ep->video_max_kbps);
/* Register 0x1430 lower byte is related to INPUT MODE/TARGET MODE specific.
* affects directly the output stream resolution, possibly TS mode bits. */
bmd_fujitsu_write(bmd, 0x001430, current_mode->r1430_l | (ep->h264_bframes ? 0x0000 : 0x0100));
bmd_fujitsu_write(bmd, 0x001470, current_mode->r147x[0]);
bmd_fujitsu_write(bmd, 0x001472, current_mode->r147x[1]);
bmd_fujitsu_write(bmd, 0x001474, current_mode->r147x[2]);
bmd_fujitsu_write(bmd, 0x001476, current_mode->r147x[3]);
bmd_fujitsu_write(bmd, 0x001478, 0x0000);
bmd_fujitsu_write(bmd, 0x00147a, 0x0000);
bmd_fujitsu_write(bmd, 0x00147c, 0x0000);
bmd_fujitsu_write(bmd, 0x00147e, 0x0000);
/* INPUT MODE based constants likely tuning for sync or similar,
* some of these seem to get ignored (and initialized to random
* value by the BMD drivers). */
bmd_fujitsu_write(bmd, 0x001540, current_mode->r154x[0]);
bmd_fujitsu_write(bmd, 0x001542, current_mode->r154x[1]);
bmd_fujitsu_write(bmd, 0x001544, current_mode->r154x[2]);
bmd_fujitsu_write(bmd, 0x001546, current_mode->r154x[3]);
bmd_fujitsu_write(bmd, 0x001548, current_mode->r154x[4]);
bmd_fujitsu_write(bmd, 0x00154a, current_mode->r154x[5]);
bmd_fujitsu_write(bmd, 0x00154c, current_mode->r154x[6]);
bmd_fujitsu_write(bmd, 0x00154e, current_mode->r154x[7]);
bmd_fujitsu_write(bmd, 0x001550, current_mode->r154x[8]);
bmd_fujitsu_write(bmd, 0x001552, current_mode->r154x[9]);
bmd_fujitsu_write(bmd, 0x001554, current_mode->r154x[10]);
/* Group 4 - Audio encoder */
switch (ep->audio_khz) {
case 32000:
bmd_fujitsu_write(bmd, 0x001802, 2);
break;
case 44100:
bmd_fujitsu_write(bmd, 0x001802, 1);
break;
case 48000:
default:
bmd_fujitsu_write(bmd, 0x001802, 0);
break;
}
bmd_fujitsu_write(bmd, 0x001804, ep->audio_kbps);
bmd_fujitsu_write(bmd, 0x001806, 0x02c0);
bmd_fujitsu_write(bmd, 0x001810, 0x0000);
bmd_fujitsu_write(bmd, 0x001812, current_mode->ain_offset);
if (0 /*audio_format == 5*/) {
bmd_fujitsu_write(bmd, 0x001830, 0x0000);
} else if (1 /*audio_format == 4 - AAC */) {
bmd_fujitsu_write(bmd, 0x001850, 0x0033);
bmd_fujitsu_write(bmd, 0x001852, 0x0200);
}
/* Group 5 - Scaler / H.264 encoder */
if (ep->src_x || ep->src_y || ep->src_width || ep->src_height || ep->dst_width || ep->dst_height) {
// bit 0x8000 resolution converter enabled
// bit 0x00ff conversion target, 0=no conversion, 4=NTSC, 5=PAL, 0xff=progressive
bmd_fujitsu_write(bmd, 0x001520, 0x80ff);
bmd_fujitsu_write(bmd, 0x001522, ep->src_x); // src x offset
bmd_fujitsu_write(bmd, 0x001524, ep->src_y); // src y offset
bmd_fujitsu_write(bmd, 0x001526, ep->src_width?ep->src_width:current_mode->width); // src width
bmd_fujitsu_write(bmd, 0x001528, ep->src_height?ep->src_height:current_mode->height);// src height (1080)
bmd_fujitsu_write(bmd, 0x00152e, ep->dst_width?ep->dst_width:current_mode->width); // dst width
bmd_fujitsu_write(bmd, 0x001530, ep->dst_height?ep->dst_height:current_mode->height);// dst height (1088)
} else if (current_mode->convert_to_1088) {
/* Convert to height 1088 */
bmd_fujitsu_write(bmd, 0x001520, 0x80ff);
bmd_fujitsu_write(bmd, 0x001522, 0); // src x offset
bmd_fujitsu_write(bmd, 0x001524, 0); // src y offset
bmd_fujitsu_write(bmd, 0x001526, current_mode->width); // src width
bmd_fujitsu_write(bmd, 0x001528, current_mode->height); // src height (1080)
bmd_fujitsu_write(bmd, 0x00152e, current_mode->width); // dst width
bmd_fujitsu_write(bmd, 0x001530, 1088); // dst height (1088)
} else {
bmd_fujitsu_write(bmd, 0x001520, 0); // 0=conversion
bmd_fujitsu_write(bmd, 0x001522, 0); // src x offset
bmd_fujitsu_write(bmd, 0x001524, 0); // src y offset
bmd_fujitsu_write(bmd, 0x001526, 0); // src width
bmd_fujitsu_write(bmd, 0x001528, 0); // src height
bmd_fujitsu_write(bmd, 0x00152e, 0); // dst width
bmd_fujitsu_write(bmd, 0x001530, 0); // dst height
}
bmd_fujitsu_write(bmd, 0x0015a0, (ep->h264_profile << 14) | ep->h264_level);
bmd_fujitsu_write(bmd, 0x0015a2, ((ep->dst_width?ep->dst_width:current_mode->width) + 15) >> 4);
bmd_fujitsu_write(bmd, 0x0015a4, ((ep->dst_height?ep->dst_height:current_mode->height) + 15) >> 4);
bmd_fujitsu_write(bmd, 0x0015a6, current_mode->fps_denominator); // divider
bmd_fujitsu_write(bmd, 0x0015a8, 2*current_mode->fps_numerator/ep->fps_divider >> 16);
bmd_fujitsu_write(bmd, 0x0015aa, 2*current_mode->fps_numerator/ep->fps_divider & 0xffff);
bmd_fujitsu_write(bmd, 0x0015ac, 0x0001); // {1=HD,2=PAL,3=NTSC} depends on target resolution
if (ep->fps_divider != 1) {
/* Possibly input-output frame ratio */
bmd_fujitsu_write(bmd, 0x0015b2, 0x8000 | ep->fps_divider);
bmd_fujitsu_write(bmd, 0x0015b4, 1);
} else {
bmd_fujitsu_write(bmd, 0x0015b2, 0);
}
/* Group 6 - Enable */
bmd_fujitsu_write(bmd, 0x001144, 0x3333);
return bmd->status == LIBUSB_SUCCESS;
}
static void bmd_encoder_dump(struct blackmagic_device *bmd)
{
uint32_t fps_numerator;
fps_numerator = bmd_fujitsu_read(bmd, 0x0015a8);
fps_numerator <<= 16;
fps_numerator += bmd_fujitsu_read(bmd, 0x0015aa);
fps_numerator /= 2;
fprintf(stderr,
"-------------------------------------------------------\n"
"Detected mode: %02x\n"
".fps_numerator = %d, .fps_denominator = %d, .fx2_fps = 0x%x,\n"
".ain_offset = 0x%04x,\n"
".r1000 = 0x%04x, .r1404 = 0x%04x, .r140a = 0x%04x, .r1430_l = 0x%02x,\n"
".r147x = { 0x%02x, 0x%02x, 0x%02x, 0x%02x },\n"
".r154x = { 0x%04x, 0x%04x, 0x%04x, 0x%04x, 0x%04x, 0x%04x, 0x%04x, 0x%04x, 0x%04x, 0x%04x, 0x%04x },\n"
"-------------------------------------------------------\n",
bmd->current_display_mode,
fps_numerator,
bmd_fujitsu_read(bmd, 0x0015a6),
(bmd_fujitsu_read(bmd, 0x080116) >> 3) & 0xf,
bmd_fujitsu_read(bmd, 0x001812),
bmd_fujitsu_read(bmd, 0x001000),
bmd_fujitsu_read(bmd, 0x001404),
bmd_fujitsu_read(bmd, 0x00140a),
bmd_fujitsu_read(bmd, 0x001430) & 0xff,
bmd_fujitsu_read(bmd, 0x001470),
bmd_fujitsu_read(bmd, 0x001472),
bmd_fujitsu_read(bmd, 0x001474),