-
Notifications
You must be signed in to change notification settings - Fork 0
/
libchiaki.pxd
1351 lines (1016 loc) · 41.2 KB
/
libchiaki.pxd
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
from libc.stdint cimport uint32_t, uint16_t, uint8_t, int8_t, int16_t, uint64_t, int32_t
cdef extern from "netinet/in.h":
struct addrinfo:
pass
cdef extern from "sys/socket.h":
ctypedef uint16_t sa_family_t
struct sockaddr:
sa_family_t sa_family
char sa_data[14]
cdef extern from "netdb.h":
int32_t getaddrinfo(const char *node,
const char *service,
const addrinfo *hints,
addrinfo **res)
cdef extern from "chiaki/common.h":
ctypedef uint32_t chiaki_unaligned_uint32_t
ctypedef uint16_t chiaki_unaligned_uint16_t
ctypedef enum ChiakiErrorCode:
CHIAKI_ERR_SUCCESS
CHIAKI_ERR_UNKNOWN
CHIAKI_ERR_PARSE_ADDR
CHIAKI_ERR_THREAD
CHIAKI_ERR_MEMORY
CHIAKI_ERR_OVERFLOW
CHIAKI_ERR_NETWORK
CHIAKI_ERR_CONNECTION_REFUSED
CHIAKI_ERR_HOST_DOWN
CHIAKI_ERR_HOST_UNREACH
CHIAKI_ERR_DISCONNECTED
CHIAKI_ERR_INVALID_DATA
CHIAKI_ERR_BUF_TOO_SMALL
CHIAKI_ERR_MUTEX_LOCKED
CHIAKI_ERR_CANCELED
CHIAKI_ERR_TIMEOUT
CHIAKI_ERR_INVALID_RESPONSE
CHIAKI_ERR_INVALID_MAC
CHIAKI_ERR_UNINITIALIZED
CHIAKI_ERR_FEC_FAILED
CHIAKI_ERR_VERSION_MISMATCH
CHIAKI_ERR_HTTP_NONOK
const char* chiaki_error_string(ChiakiErrorCode code)
void* chiaki_aligned_alloc(size_t alignment, size_t size)
void chiaki_aligned_free(void* ptr)
ctypedef enum ChiakiTarget:
CHIAKI_TARGET_PS4_UNKNOWN
CHIAKI_TARGET_PS4_8
CHIAKI_TARGET_PS4_9
CHIAKI_TARGET_PS4_10
CHIAKI_TARGET_PS5_UNKNOWN
CHIAKI_TARGET_PS5_1
bint chiaki_target_is_unknown(ChiakiTarget target)
bint chiaki_target_is_ps5(ChiakiTarget target)
ChiakiErrorCode chiaki_lib_init()
ctypedef enum ChiakiCodec:
CHIAKI_CODEC_H264
CHIAKI_CODEC_H265
CHIAKI_CODEC_H265_HDR
bint chiaki_codec_is_h265(ChiakiCodec codec)
bint chiaki_codec_is_hdr(ChiakiCodec codec)
const char* chiaki_codec_name(ChiakiCodec codec)
cdef extern from "chiaki/log.h":
ctypedef enum ChiakiLogLevel:
CHIAKI_LOG_DEBUG
CHIAKI_LOG_VERBOSE
CHIAKI_LOG_INFO
CHIAKI_LOG_WARNING
CHIAKI_LOG_ERROR
char chiaki_log_level_char(ChiakiLogLevel level)
ctypedef void (*ChiakiLogCb)(ChiakiLogLevel level, const char* msg, void* user)
cdef struct chiaki_log_t:
uint32_t level_mask
ChiakiLogCb cb
void* user
ctypedef chiaki_log_t ChiakiLog
void chiaki_log_init(ChiakiLog* log, uint32_t level_mask, ChiakiLogCb cb, void* user)
void chiaki_log_cb_print(ChiakiLogLevel level, const char* msg, void* user)
void chiaki_log(ChiakiLog* log, ChiakiLogLevel level, const char* fmt, ...)
void chiaki_log_hexdump(ChiakiLog* log, ChiakiLogLevel level, const uint8_t* buf, size_t buf_size)
void chiaki_log_hexdump_raw(ChiakiLog* log, ChiakiLogLevel level, const uint8_t* buf, size_t buf_size)
cdef struct chiaki_log_sniffer_t:
ChiakiLog* forward_log
ChiakiLog sniff_log
uint32_t sniff_level_mask
char* buf
size_t buf_len
ctypedef chiaki_log_sniffer_t ChiakiLogSniffer
void chiaki_log_sniffer_init(ChiakiLogSniffer* sniffer, uint32_t level_mask, ChiakiLog* forward_log)
void chiaki_log_sniffer_fini(ChiakiLogSniffer* sniffer)
ChiakiLog* chiaki_log_sniffer_get_log(ChiakiLogSniffer* sniffer)
const char* chiaki_log_sniffer_get_buffer(ChiakiLogSniffer* sniffer)
cdef extern from "chiaki/controller.h":
cpdef enum chiaki_controller_button_t:
CHIAKI_CONTROLLER_BUTTON_CROSS
CHIAKI_CONTROLLER_BUTTON_MOON
CHIAKI_CONTROLLER_BUTTON_BOX
CHIAKI_CONTROLLER_BUTTON_PYRAMID
CHIAKI_CONTROLLER_BUTTON_DPAD_LEFT
CHIAKI_CONTROLLER_BUTTON_DPAD_RIGHT
CHIAKI_CONTROLLER_BUTTON_DPAD_UP
CHIAKI_CONTROLLER_BUTTON_DPAD_DOWN
CHIAKI_CONTROLLER_BUTTON_L1
CHIAKI_CONTROLLER_BUTTON_R1
CHIAKI_CONTROLLER_BUTTON_L3
CHIAKI_CONTROLLER_BUTTON_R3
CHIAKI_CONTROLLER_BUTTON_OPTIONS
CHIAKI_CONTROLLER_BUTTON_SHARE
CHIAKI_CONTROLLER_BUTTON_TOUCHPAD
CHIAKI_CONTROLLER_BUTTON_PS
ctypedef chiaki_controller_button_t ChiakiControllerButton
cpdef enum chiaki_controller_analog_button_t:
CHIAKI_CONTROLLER_ANALOG_BUTTON_L2
CHIAKI_CONTROLLER_ANALOG_BUTTON_R2
ctypedef chiaki_controller_analog_button_t ChiakiControllerAnalogButton
cdef struct chiaki_controller_touch_t:
uint16_t x
uint16_t y
int8_t id
ctypedef chiaki_controller_touch_t ChiakiControllerTouch
cdef struct chiaki_controller_state_t:
uint32_t buttons
uint8_t l2_state
uint8_t r2_state
int16_t left_x
int16_t left_y
int16_t right_x
int16_t right_y
uint8_t touch_id_next
ChiakiControllerTouch touches[2]
float gyro_x
float gyro_y
float gyro_z
float accel_x
float accel_y
float accel_z
float orient_x
float orient_y
float orient_z
float orient_w
ctypedef chiaki_controller_state_t ChiakiControllerState
void chiaki_controller_state_set_idle(ChiakiControllerState* state)
int8_t chiaki_controller_state_start_touch(ChiakiControllerState* state, uint16_t x, uint16_t y)
void chiaki_controller_state_stop_touch(ChiakiControllerState* state, uint8_t id)
void chiaki_controller_state_set_touch_pos(ChiakiControllerState* state, uint8_t id, uint16_t x, uint16_t y)
bint chiaki_controller_state_equals(ChiakiControllerState* a, ChiakiControllerState* b)
void chiaki_controller_state_or(ChiakiControllerState* out, ChiakiControllerState* a, ChiakiControllerState* b)
cdef extern from "chiaki/orientation.h":
cdef struct chiaki_orientation_t:
float x
float y
float z
float w
ctypedef chiaki_orientation_t ChiakiOrientation
void chiaki_orientation_init(ChiakiOrientation* orient)
void chiaki_orientation_update(ChiakiOrientation* orient, float gx, float gy, float gz, float ax, float ay, float az, float beta, float time_step_sec)
cdef struct chiaki_orientation_tracker_t:
float gyro_x
float gyro_y
float gyro_z
float accel_x
float accel_y
float accel_z
ChiakiOrientation orient
uint32_t timestamp
uint64_t sample_index
ctypedef chiaki_orientation_tracker_t ChiakiOrientationTracker
void chiaki_orientation_tracker_init(ChiakiOrientationTracker* tracker)
void chiaki_orientation_tracker_update(ChiakiOrientationTracker* tracker, float gx, float gy, float gz, float ax, float ay, float az, uint32_t timestamp_us)
void chiaki_orientation_tracker_apply_to_controller_state(ChiakiOrientationTracker* tracker, ChiakiControllerState* state)
cdef extern from "chiaki/seqnum.h":
ctypedef uint16_t ChiakiSeqNum16
bint chiaki_seq_num_16_lt(ChiakiSeqNum16 a, ChiakiSeqNum16 b)
bint chiaki_seq_num_16_gt(ChiakiSeqNum16 a, ChiakiSeqNum16 b)
ctypedef uint32_t ChiakiSeqNum32
bint chiaki_seq_num_32_lt(ChiakiSeqNum32 a, ChiakiSeqNum32 b)
bint chiaki_seq_num_32_gt(ChiakiSeqNum32 a, ChiakiSeqNum32 b)
cdef extern from "chiaki/thread.h":
# https://groups.google.com/g/cython-users/c/kqUBhXwqHSY
cdef struct pthread_t:
pass
cdef struct pthread_mutex_t:
pass
cdef struct pthread_cond_t:
pass
cdef struct chiaki_thread_t:
pthread_t thread
ctypedef chiaki_thread_t ChiakiThread
cdef struct chiaki_mutex_t:
pthread_mutex_t mutex
ctypedef chiaki_mutex_t ChiakiMutex
cdef struct chiaki_cond_t:
pthread_cond_t cond
ctypedef chiaki_cond_t ChiakiCond
cdef struct chiaki_bool_pred_cond_t:
ChiakiCond cond
ChiakiMutex mutex
bint pred
ctypedef chiaki_bool_pred_cond_t ChiakiBoolPredCond
cdef extern from "chiaki/stoppipe.h":
cdef struct chiaki_stop_pipe_t:
int fds[2]
ctypedef chiaki_stop_pipe_t ChiakiStopPipe
cdef extern from "chiaki/sock.h":
ctypedef int chiaki_socket_t
cdef extern from "chiaki/discovery.h":
char* CHIAKI_DISCOVERY_PROTOCOL_VERSION_PS4
char* CHIAKI_DISCOVERY_PROTOCOL_VERSION_PS5
uint16_t CHIAKI_DISCOVERY_PORT_PS4
uint16_t CHIAKI_DISCOVERY_PORT_PS5
cpdef enum chiaki_discovery_cmd_t:
CHIAKI_DISCOVERY_CMD_SRCH
CHIAKI_DISCOVERY_CMD_WAKEUP
ctypedef chiaki_discovery_cmd_t ChiakiDiscoveryCmd
cdef struct chiaki_discovery_packet_t:
ChiakiDiscoveryCmd cmd
char* protocol_version
uint64_t user_credential
ctypedef chiaki_discovery_packet_t ChiakiDiscoveryPacket
cpdef enum chiaki_discovery_host_state_t:
CHIAKI_DISCOVERY_HOST_STATE_UNKNOWN
CHIAKI_DISCOVERY_HOST_STATE_READY
CHIAKI_DISCOVERY_HOST_STATE_STANDBY
ctypedef chiaki_discovery_host_state_t ChiakiDiscoveryHostState
cdef struct chiaki_discovery_host_t:
ChiakiDiscoveryHostState state
uint16_t host_request_port
const char* host_addr
const char* system_version
const char* device_discovery_protocol_version
const char* host_name
const char* host_type
const char* host_id
const char* running_app_titleid
const char* running_app_name
ctypedef chiaki_discovery_host_t ChiakiDiscoveryHost
cdef struct chiaki_discovery_t:
ChiakiLog* log
chiaki_socket_t socket
sockaddr local_addr
ctypedef chiaki_discovery_t ChiakiDiscovery
const char *chiaki_discovery_host_state_string(ChiakiDiscoveryHostState state)
ChiakiErrorCode chiaki_discovery_init(ChiakiDiscovery* discovery, ChiakiLog* log, sa_family_t family)
void chiaki_discovery_fini(ChiakiDiscovery* discovery)
ChiakiErrorCode chiaki_discovery_send(ChiakiDiscovery* discovery, ChiakiDiscoveryPacket* packet, sockaddr* addr, size_t addr_size)
ctypedef void (*ChiakiDiscoveryCb)(ChiakiDiscoveryHost* host, void* user)
cdef struct chiaki_discovery_thread_t:
ChiakiDiscovery* discovery
ChiakiThread thread
ChiakiStopPipe stop_pipe
ChiakiDiscoveryCb cb
void* cb_user
ctypedef chiaki_discovery_thread_t ChiakiDiscoveryThread
ChiakiErrorCode chiaki_discovery_thread_start(ChiakiDiscoveryThread* thread, ChiakiDiscovery* discovery, ChiakiDiscoveryCb cb, void* cb_user)
ChiakiErrorCode chiaki_discovery_thread_stop(ChiakiDiscoveryThread* thread)
ChiakiErrorCode chiaki_discovery_wakeup(ChiakiLog *log, ChiakiDiscovery *discovery, const char *host, uint64_t user_credential, bint ps5);
cdef extern from "chiaki/discoveryservice.h":
ctypedef void (*ChiakiDiscoveryServiceCb)(ChiakiDiscoveryHost* hosts, size_t hosts_count, void* user)
cdef struct chiaki_discovery_service_options_t:
size_t hosts_max
uint64_t host_drop_pings
uint64_t ping_ms
uint64_t ping_initial_ms
sockaddr* send_addr
size_t send_addr_size
char* send_host
ChiakiDiscoveryServiceCb cb
void* cb_user
ctypedef chiaki_discovery_service_options_t ChiakiDiscoveryServiceOptions
cdef struct chiaki_discovery_service_host_discovery_info_t:
uint64_t last_ping_index
ctypedef chiaki_discovery_service_host_discovery_info_t ChiakiDiscoveryServiceHostDiscoveryInfo
cdef struct chiaki_discovery_service_t:
ChiakiLog* log
ChiakiDiscoveryServiceOptions options
ChiakiDiscovery discovery
uint64_t ping_index
ChiakiDiscoveryHost* hosts
ChiakiDiscoveryServiceHostDiscoveryInfo* host_discovery_infos
size_t hosts_count
ChiakiMutex state_mutex
ChiakiThread thread
ChiakiBoolPredCond stop_cond
ctypedef chiaki_discovery_service_t ChiakiDiscoveryService
ChiakiErrorCode chiaki_discovery_service_init(ChiakiDiscoveryService* service, ChiakiDiscoveryServiceOptions* options, ChiakiLog* log)
void chiaki_discovery_service_fini(ChiakiDiscoveryService* service)
cdef extern from "chiaki/audio.h":
cdef struct chiaki_audio_header_t:
uint8_t channels
uint8_t bits
uint32_t rate
uint32_t frame_size
uint32_t unknown
ctypedef chiaki_audio_header_t ChiakiAudioHeader
cdef extern from "chiaki/packetstats.h":
cdef struct chiaki_packet_stats_t:
ChiakiMutex mutex
uint64_t gen_received
uint64_t gen_lost
ChiakiSeqNum16 seq_min
ChiakiSeqNum16 seq_max
uint64_t seq_received
ctypedef chiaki_packet_stats_t ChiakiPacketStats
cdef extern from "chiaki/audioreceiver.h":
ctypedef void (*ChiakiAudioSinkHeader)(ChiakiAudioHeader* header, void* user)
ctypedef void (*ChiakiAudioSinkFrame)(uint8_t* buf, size_t buf_size, void* user)
cdef struct chiaki_audio_sink_t:
void* user
ChiakiAudioSinkHeader header_cb
ChiakiAudioSinkFrame frame_cb
ctypedef chiaki_audio_sink_t ChiakiAudioSink
cdef struct chiaki_audio_receiver_t:
chiaki_session_t* session
ChiakiLog* log
ChiakiMutex mutex
ChiakiSeqNum16 frame_index_prev
bint frame_index_startup
ChiakiPacketStats* packet_stats
ctypedef chiaki_audio_receiver_t ChiakiAudioReceiver
cdef extern from "chiaki/rpcrypt.h":
cdef struct chiaki_rpcrypt_t:
ChiakiTarget target
uint8_t[0x10] bright
uint8_t[0x10] ambassador
ctypedef chiaki_rpcrypt_t ChiakiRPCrypt
cdef extern from "chiaki/ecdh.h":
cdef struct ec_group_st:
pass
cdef struct ec_key_st:
pass
cdef struct chiaki_ecdh_t:
ec_group_st* group
ec_key_st* key_local
ctypedef chiaki_ecdh_t ChiakiECDH
cdef extern from "chiaki/ctrl.h":
ctypedef void (*ChiakiCantDisplayCb)(void *user, bint cant_display)
cdef struct chiaki_ctrl_display_sink_t:
void *user
ChiakiCantDisplayCb cantdisplay_cb
ctypedef chiaki_ctrl_display_sink_t ChiakiCtrlDisplaySink
ctypedef chiaki_ctrl_message_queue_t ChiakiCtrlMessageQueue
cdef struct chiaki_ctrl_message_queue_t:
ChiakiCtrlMessageQueue* next
uint16_t type
uint8_t* payload
size_t payload_size
cdef struct chiaki_ctrl_t:
chiaki_session_t* session
ChiakiThread thread
bint should_stop
bint login_pin_entered
uint8_t* login_pin
size_t login_pin_size
ChiakiCtrlMessageQueue* msg_queue
ChiakiStopPipe notif_pipe
ChiakiMutex notif_mutex
bint login_pin_requested
bint cant_displaya
bint cant_displayb
chiaki_socket_t sock
uint8_t[512] recv_buf
uint8_t[520] rudp_recv_buf
size_t recv_buf_size
uint64_t crypt_counter_local
uint64_t crypt_counter_remote
uint32_t keyboard_text_counter
ctypedef chiaki_ctrl_t ChiakiCtrl
cdef extern from "chiaki/gkcrypt.h":
cdef struct chiaki_key_state_t:
uint64_t prev
ctypedef chiaki_key_state_t ChiakiKeyState
cdef struct chiaki_gkcrypt_t:
uint8_t index
uint8_t* key_buf
size_t key_buf_size
size_t key_buf_populated
uint64_t key_buf_key_pos_min
size_t key_buf_start_offset
uint64_t last_key_pos
bint key_buf_thread_stop
ChiakiMutex key_buf_mutex
ChiakiCond key_buf_cond
ChiakiThread key_buf_thread
uint8_t iv[0x10]
uint8_t key_base[0x10]
uint8_t key_gmac_base[0x10]
uint8_t key_gmac_current[0x10]
uint64_t key_gmac_index_current
ChiakiLog* log
ctypedef chiaki_gkcrypt_t ChiakiGKCrypt
cdef extern from "chiaki/reorderqueue.h":
cpdef enum chiaki_reorder_queue_drop_strategy_t:
CHIAKI_REORDER_QUEUE_DROP_STRATEGY_BEGIN
CHIAKI_REORDER_QUEUE_DROP_STRATEGY_END
ctypedef chiaki_reorder_queue_drop_strategy_t ChiakiReorderQueueDropStrategy
cdef struct chiaki_reorder_queue_entry_t:
void* user
bint set
ctypedef chiaki_reorder_queue_entry_t ChiakiReorderQueueEntry
ctypedef void (*ChiakiReorderQueueDropCb)(uint64_t seq_num, void* elem_user, void* cb_user)
ctypedef bint (*ChiakiReorderQueueSeqNumGt)(uint64_t a, uint64_t b)
ctypedef bint (*ChiakiReorderQueueSeqNumLt)(uint64_t a, uint64_t b)
ctypedef uint64_t (*ChiakiReorderQueueSeqNumAdd)(uint64_t a, uint64_t b)
ctypedef uint64_t (*ChiakiReorderQueueSeqNumSub)(uint64_t a, uint64_t b)
cdef struct chiaki_reorder_queue_t:
size_t size_exp
ChiakiReorderQueueEntry* queue
uint64_t begin
uint64_t count
ChiakiReorderQueueSeqNumGt seq_num_gt
ChiakiReorderQueueSeqNumLt seq_num_lt
ChiakiReorderQueueSeqNumAdd seq_num_add
ChiakiReorderQueueSeqNumSub seq_num_sub
ChiakiReorderQueueDropStrategy drop_strategy
ChiakiReorderQueueDropCb drop_cb
void* drop_cb_user
ctypedef chiaki_reorder_queue_t ChiakiReorderQueue
cdef extern from "chiaki/takionsendbuffer.h":
cdef struct chiaki_takion_send_buffer_packet_t:
ChiakiSeqNum32 seq_num
uint64_t tries
uint64_t last_send_ms
uint8_t* buf
size_t buf_size
ctypedef chiaki_takion_send_buffer_packet_t ChiakiTakionSendBufferPacket
ctypedef chiaki_takion_t ChiakiTakion
cdef struct chiaki_takion_send_buffer_t:
ChiakiLog* log
ChiakiTakion* takion
ChiakiTakionSendBufferPacket* packets
size_t packets_size
size_t packets_count
ChiakiMutex mutex
ChiakiCond cond
bint should_stop
ChiakiThread thread
ctypedef chiaki_takion_send_buffer_t ChiakiTakionSendBuffer
cdef extern from "chiaki/takion.h":
cpdef enum chiaki_takion_message_data_type_t:
CHIAKI_TAKION_MESSAGE_DATA_TYPE_PROTOBUF
CHIAKI_TAKION_MESSAGE_DATA_TYPE_RUMBLE
CHIAKI_TAKION_MESSAGE_DATA_TYPE_9
CHIAKI_TAKION_MESSAGE_DATA_TYPE_TRIGGER_EFFECTS
ctypedef chiaki_takion_message_data_type_t ChiakiTakionMessageDataType
cdef struct chiaki_takion_av_packet_t:
ChiakiSeqNum16 packet_index
ChiakiSeqNum16 frame_index
bint uses_nalu_info_structs
bint is_video
bint is_haptics
ChiakiSeqNum16 unit_index
uint16_t units_in_frame_total
uint16_t units_in_frame_fec
uint8_t codec
uint16_t word_at_0x18
uint8_t adaptive_stream_index
uint8_t byte_at_0x2c
uint64_t key_pos
uint8_t* data
size_t data_size
ctypedef chiaki_takion_av_packet_t ChiakiTakionAVPacket
uint8_t chiaki_takion_av_packet_audio_unit_size(ChiakiTakionAVPacket* packet)
uint8_t chiaki_takion_av_packet_audio_source_units_count(ChiakiTakionAVPacket* packet)
uint8_t chiaki_takion_av_packet_audio_fec_units_count(ChiakiTakionAVPacket* packet)
ctypedef ChiakiErrorCode (*ChiakiTakionAVPacketParse)(ChiakiTakionAVPacket* packet, ChiakiKeyState* key_state, uint8_t* buf, size_t buf_size)
cdef struct chiaki_takion_congestion_packet_t:
uint16_t word_0
uint16_t received
uint16_t lost
ctypedef chiaki_takion_congestion_packet_t ChiakiTakionCongestionPacket
ctypedef enum ChiakiTakionEventType:
CHIAKI_TAKION_EVENT_TYPE_CONNECTED
CHIAKI_TAKION_EVENT_TYPE_DISCONNECT
CHIAKI_TAKION_EVENT_TYPE_DATA
CHIAKI_TAKION_EVENT_TYPE_DATA_ACK
CHIAKI_TAKION_EVENT_TYPE_AV
cdef struct _ChiakiTakionEvent_ChiakiTakionEvent_chiaki_takion_event_t_data_s:
ChiakiTakionMessageDataType data_type
uint8_t* buf
size_t buf_size
cdef struct _ChiakiTakionEvent_ChiakiTakionEvent_chiaki_takion_event_t_data_ack_s:
ChiakiSeqNum32 seq_num
cdef struct chiaki_takion_event_t:
ChiakiTakionEventType type
_ChiakiTakionEvent_ChiakiTakionEvent_chiaki_takion_event_t_data_s data
_ChiakiTakionEvent_ChiakiTakionEvent_chiaki_takion_event_t_data_ack_s data_ack
ChiakiTakionAVPacket* av
ctypedef chiaki_takion_event_t ChiakiTakionEvent
ctypedef void (*ChiakiTakionCallback)(ChiakiTakionEvent* event, void* user)
cdef struct chiaki_takion_connect_info_t:
ChiakiLog* log
sockaddr* sa
size_t sa_len
bint ip_dontfrag
ChiakiTakionCallback cb
void* cb_user
bint enable_crypt
bint enable_dualsense
uint8_t protocol_version
bint close_socket
ctypedef chiaki_takion_connect_info_t ChiakiTakionConnectInfo
cdef struct chiaki_takion_postponed_packet_t:
uint8_t* buf
size_t buf_size
ctypedef chiaki_takion_postponed_packet_t ChiakiTakionPostponedPacket
cdef struct chiaki_takion_t:
ChiakiLog* log
uint8_t version
bint enable_crypt
chiaki_takion_postponed_packet_t* postponed_packets
size_t postponed_packets_size
size_t postponed_packets_count
ChiakiGKCrypt* gkcrypt_local
uint64_t key_pos_local
ChiakiMutex gkcrypt_local_mutex
ChiakiGKCrypt* gkcrypt_remote
ChiakiReorderQueue data_queue
ChiakiTakionSendBuffer send_buffer
ChiakiTakionCallback cb
void* cb_user
chiaki_socket_t sock
ChiakiThread thread
ChiakiStopPipe stop_pipe
uint32_t tag_local
uint32_t tag_remote
bint close_socket
ChiakiSeqNum32 seq_num_local
ChiakiMutex seq_num_local_mutex
uint32_t a_rwnd
ChiakiTakionAVPacketParse av_packet_parse
ChiakiKeyState key_state
bint enable_dualsense
cdef extern from "chiaki/video.h":
cdef struct chiaki_video_profile_t:
unsigned int width
unsigned int height
size_t header_sz
uint8_t* header
ctypedef chiaki_video_profile_t ChiakiVideoProfile
cdef extern from "chiaki/frameprocessor.h":
cdef struct chiaki_stream_stats_t:
uint64_t frames
uint64_t bytes
ctypedef chiaki_stream_stats_t ChiakiStreamStats
cdef struct chiaki_frame_unit_t:
pass
ctypedef chiaki_frame_unit_t ChiakiFrameUnit
cdef struct chiaki_frame_processor_t:
ChiakiLog* log
uint8_t* frame_buf
size_t frame_buf_size
size_t buf_size_per_unit
size_t buf_stride_per_unit
unsigned int units_source_expected
unsigned int units_fec_expected
unsigned int units_source_received
unsigned int units_fec_received
ChiakiFrameUnit* unit_slots
size_t unit_slots_size
bint flushed
ChiakiStreamStats stream_stats
ctypedef chiaki_frame_processor_t ChiakiFrameProcessor
cdef extern from "chiaki/bitstream.h":
cdef struct chiaki_bitstream_t:
ChiakiLog *log;
ChiakiCodec codec;
uint32_t placeholder_union #We'll never access this directly from cython so just put in a placeholder for these unions
ctypedef chiaki_bitstream_t ChiakiBitstream
cdef extern from "chiaki/videoreceiver.h":
cdef struct chiaki_video_receiver_t:
chiaki_session_t* session
ChiakiLog* log
ChiakiVideoProfile profiles[8]
size_t profiles_count
int profile_cur
int32_t frame_index_cur
int32_t frame_index_prev
int32_t frame_index_prev_complete
ChiakiFrameProcessor frame_processor
ChiakiPacketStats* packet_stats
int32_t frames_lost
int32_t[16] reference_frames
ChiakiBitstream bitstream
ctypedef chiaki_video_receiver_t ChiakiVideoReceiver
cdef extern from "chiaki/feedback.h":
cdef struct chiaki_feedback_state_t:
float gyro_x
float gyro_y
float gyro_z
float accel_x
float accel_y
float accel_z
float orient_x
float orient_y
float orient_z
float orient_w
int16_t left_x
int16_t left_y
int16_t right_x
int16_t right_y
ctypedef chiaki_feedback_state_t ChiakiFeedbackState
cdef struct chiaki_feedback_history_event_t:
uint8_t buf[0x5]
size_t len
ctypedef chiaki_feedback_history_event_t ChiakiFeedbackHistoryEvent
cdef struct chiaki_feedback_history_buffer_t:
ChiakiFeedbackHistoryEvent* events
size_t size
size_t begin
size_t len
ctypedef chiaki_feedback_history_buffer_t ChiakiFeedbackHistoryBuffer
cdef extern from "chiaki/feedbacksender.h":
cdef struct chiaki_feedback_sender_t:
ChiakiLog* log
ChiakiTakion* takion
ChiakiThread thread
ChiakiSeqNum16 state_seq_num
ChiakiSeqNum16 history_seq_num
ChiakiFeedbackHistoryBuffer history_buf
bint should_stop
ChiakiControllerState controller_state_prev
ChiakiControllerState controller_state
bint controller_state_changed
ChiakiMutex state_mutex
ChiakiCond state_cond
ctypedef chiaki_feedback_sender_t ChiakiFeedbackSender
cdef extern from "chiaki/congestioncontrol.h":
cdef struct chiaki_congestion_control_t:
ChiakiTakion *takion
ChiakiPacketStats *stats
ChiakiThread thread
ChiakiBoolPredCond stop_cond
double packet_loss
ctypedef chiaki_congestion_control_t ChiakiCongestionControl
cdef extern from "chiaki/streamconnection.h":
cdef struct chiaki_stream_connection_t:
chiaki_session_t* session
ChiakiLog* log
ChiakiTakion takion
uint8_t* ecdh_secret
ChiakiGKCrypt* gkcrypt_local
ChiakiGKCrypt* gkcrypt_remote
ChiakiPacketStats packet_stats
ChiakiAudioReceiver* audio_receiver
ChiakiVideoReceiver* video_receiver
ChiakiAudioReceiver* haptics_receiver
ChiakiFeedbackSender feedback_sender
ChiakiCongestionControl congestion_control
bint feedback_sender_active
ChiakiMutex feedback_sender_mutex
ChiakiCond state_cond
ChiakiMutex state_mutex
int state
bint state_finished
bint state_failed
bint should_stop
bint remote_disconnected
char* remote_disconnect_reason
double measured_bitrate
ctypedef chiaki_stream_connection_t ChiakiStreamConnection
cdef extern from "miniupnpc/miniupnpc.h":
cdef struct UPNPUrls:
char *controlURL
char *ipcondescURL
char *controlURL_CIF
char *controlURL_6FC
char *rootdescURL
cdef struct IGDdatas_service:
char[128] controlurl #FIXME: How to pull in MINIUPNPC_URL_MAXSIZE?
char[128] eventsuburl
char[128] scpdurl
char[128] servicetype
cdef struct IGDdatas:
char[128] cureltname
char[128] urlbase
char[128] presentationurl
int level
IGDdatas_service CIF
IGDdatas_service first
IGDdatas_service second
IGDdatas_service IPv6FC
IGDdatas_service tmp
cdef extern from "chiaki/remote/holepunch.h":
cdef struct holepunch_regist_info_t:
uint8_t[16] data1
uint8_t[16] data2
uint8_t[16] custom_data1;
char[46] regist_local_ip #INET6_ADDRSTRLEN is normally 46, how to handle this on systems that define it differently?
ctypedef holepunch_regist_info_t ChiakiHolepunchRegistInfo
cdef struct upnp_gateway_info_t:
char[46] lan_ip #Again, figure out how to pull in the system define for INET6_ADDRSTRLEN here
UPNPUrls *urls
IGDdatas *data
ctypedef upnp_gateway_info_t UPNPGatewayInfo
cdef enum chiaki_holepunch_console_type_t:
CHIAKI_HOLEPUNCH_CONSOLE_TYPE_PS4 = 0,
CHIAKI_HOLEPUNCH_CONSOLE_TYPE_PS5 = 1
ctypedef chiaki_holepunch_console_type_t ChiakiHolepunchConsoleType
ctypedef void CURLSH #Opaque pointer when you're not building libcurl
cdef enum session_state_t:
SESSION_STATE_INIT = 0,
SESSION_STATE_WS_OPEN = 1 << 0,
SESSION_STATE_CREATED = 1 << 1,
SESSION_STATE_STARTED = 1 << 2,
SESSION_STATE_CLIENT_JOINED = 1 << 3,
SESSION_STATE_DATA_SENT = 1 << 4,
SESSION_STATE_CONSOLE_JOINED = 1 << 5,
SESSION_STATE_CUSTOMDATA1_RECEIVED = 1 << 6,
SESSION_STATE_CTRL_OFFER_RECEIVED = 1 << 7,
SESSION_STATE_CTRL_OFFER_SENT = 1 << 8,
SESSION_STATE_CTRL_CONSOLE_ACCEPTED = 1 << 9,
SESSION_STATE_CTRL_CLIENT_ACCEPTED = 1 << 10,
SESSION_STATE_CTRL_ESTABLISHED = 1 << 11,
SESSION_STATE_DATA_OFFER_RECEIVED = 1 << 12,
SESSION_STATE_DATA_OFFER_SENT = 1 << 13,
SESSION_STATE_DATA_CONSOLE_ACCEPTED = 1 << 14,
SESSION_STATE_DATA_CLIENT_ACCEPTED = 1 << 15,
SESSION_STATE_DATA_ESTABLISHED = 1 << 16,
SESSION_STATE_DELETED = 1 << 17
ctypedef session_state_t SessionState #TODO: Can we do opaque enums in cython?
#pulled from stun.h
cdef struct stun_server_t:
char* host
uint16_t port
ctypedef stun_server_t StunServer
cdef struct session_t:
#TODO: Clean this up, how much of this stuff do we really need? (from original chiaki4deck, warning that this will probably change a lot...)
char* oauth_header
uint8_t[32] console_uid
ChiakiHolepunchConsoleType console_type
chiaki_socket_t sock
uint64_t account_id
char[37] session_id #FIXME: Pull UUIDV4_STR_LEN from the headers
char[37] pushctx_id
uint16_t sid_local
uint16_t sid_console;
uint8_t[20] hashed_id_local
uint8_t[20] hashed_id_console
size_t local_req_id
uint8_t[6] local_mac_addr
uint16_t local_port_ctrl
uint16_t local_port_data
int32_t stun_allocation_increment
StunServer[10] stun_server_list
size_t num_stun_servers
UPNPGatewayInfo gw
uint8_t[16] data1
uint8_t[16] data2
uint8_t[16] custom_data1
char[46] ps_ip #INET6_ADDRSTRLEN again
uint16_t ctrl_port
char[46] client_local_ip
CURLSH* curl_share
char* ws_fqdn
ChiakiThread ws_thread
void* ws_notification_queue #Opaque pointer from our perspective, normally is notification_queue_t
bint ws_thread_should_stop