diff --git a/lib/include/chiaki/takion.h b/lib/include/chiaki/takion.h index ee3e63a..b0db46e 100644 --- a/lib/include/chiaki/takion.h +++ b/lib/include/chiaki/takion.h @@ -24,15 +24,17 @@ #include "gkcrypt.h" #include +#include #ifdef __cplusplus extern "C" { #endif +struct chiaki_takion_av_packet_t; typedef void (*ChiakiTakionDataCallback)(uint8_t *buf, size_t buf_size, void *user); -typedef void (*ChiakiTakionAVCallback)(uint8_t *buf, size_t buf_size, uint8_t base_type, uint32_t key_pos, void *user); +typedef void (*ChiakiTakionAVCallback)(struct chiaki_takion_av_packet_t *header, uint8_t *buf, size_t buf_size, uint8_t base_type, uint32_t key_pos, void *user); typedef struct chiaki_takion_connect_info_t @@ -67,6 +69,20 @@ typedef struct chiaki_takion_t uint32_t something; // 0x19000, TODO: is this some kind of remaining buffer size? } ChiakiTakion; +typedef struct chiaki_takion_av_packet_t +{ + uint16_t packet_index; + uint16_t frame_index; + bool byte_at_0x1a; + bool is_2; + uint16_t word_at_0xa; + uint16_t word_at_0xc; + uint16_t word_at_0xe; + uint32_t codec; + uint16_t word_at_0x18; + uint8_t adaptive_stream_index; + uint8_t byte_at_0x2c; +} ChiakiTakionAVPacket; CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, ChiakiTakionConnectInfo *info); CHIAKI_EXPORT void chiaki_takion_close(ChiakiTakion *takion); diff --git a/lib/src/nagare.c b/lib/src/nagare.c index 48957b6..5d46cfa 100644 --- a/lib/src/nagare.c +++ b/lib/src/nagare.c @@ -58,7 +58,7 @@ static ChiakiErrorCode nagare_send_disconnect(ChiakiNagare *nagare); static void nagare_takion_data_expect_bang(ChiakiNagare *nagare, uint8_t *buf, size_t buf_size); static void nagare_takion_data_expect_streaminfo(ChiakiNagare *nagare, uint8_t *buf, size_t buf_size); static ChiakiErrorCode nagare_send_streaminfo_ack(ChiakiNagare *nagare); -static void nagare_takion_av(uint8_t *buf, size_t buf_size, uint8_t base_type, uint32_t key_pos, void *user); +static void nagare_takion_av(ChiakiTakionAVPacket *header, uint8_t *buf, size_t buf_size, uint8_t base_type, uint32_t key_pos, void *user); static ChiakiErrorCode nagare_takion_mac(uint8_t *buf, size_t buf_size, size_t key_pos, uint8_t *mac_out, void *user); @@ -502,21 +502,31 @@ static ChiakiErrorCode nagare_send_disconnect(ChiakiNagare *nagare) } -static void nagare_takion_av(uint8_t *buf, size_t buf_size, uint8_t base_type, uint32_t key_pos, void *user) +static void nagare_takion_av(ChiakiTakionAVPacket *header, uint8_t *buf, size_t buf_size, uint8_t base_type, uint32_t key_pos, void *user) { ChiakiNagare *nagare = user; chiaki_gkcrypt_decrypt(nagare->gkcrypt_remote, key_pos + CHIAKI_GKCRYPT_BLOCK_SIZE, buf, buf_size); - if(buf[0] == 0xf4 && buf_size >= 0x50) + //CHIAKI_LOGD(nagare->log, "AV: index: %u,%u; b@0x1a: %d; is_2: %d; 0xa: %u; 0xc: %u; 0xe: %u; codec: %u; 0x18: %u; adaptive_stream: %u, 0x2c: %u\n", + // header->packet_index, header->frame_index, header->byte_at_0x1a, header->is_2 ? 1 : 0, header->word_at_0xa, header->word_at_0xc, header->word_at_0xe, header->codec, + // header->word_at_0x18, header->adaptive_stream_index, header->byte_at_0x2c); + + if(header->codec == 5/*buf[0] == 0xf4 && buf_size >= 0x50*/) { + //CHIAKI_LOGD(nagare->log, "audio!\n"); chiaki_audio_receiver_frame_packet(nagare->session->audio_receiver, buf, 0x50); } - else if(base_type == 2 && buf[0] != 0xf4) + else { - //CHIAKI_LOGD(nagare->log, "av frame 2, which is not audio\n"); + //CHIAKI_LOGD(nagare->log, "NON-audio\n"); } + /*else if(base_type == 2 && buf[0] != 0xf4) + { + CHIAKI_LOGD(nagare->log, "av frame 2, which is not audio\n"); + }*/ + //CHIAKI_LOGD(nagare->log, "Nagare AV %lu\n", buf_size); //chiaki_log_hexdump(nagare->log, CHIAKI_LOG_DEBUG, buf, buf_size); } diff --git a/lib/src/takion.c b/lib/src/takion.c index 2b5ead6..008253f 100644 --- a/lib/src/takion.c +++ b/lib/src/takion.c @@ -716,21 +716,6 @@ static ChiakiErrorCode takion_recv_message_cookie_ack(ChiakiTakion *takion) #define AV_HEADER_SIZE_2 0x17 #define AV_HEADER_SIZE_3 0x12 -typedef struct takion_av_packet_t -{ - uint16_t packet_index; - uint16_t frame_index; - bool byte_at_0x1a; - bool is_2; - uint16_t word_at_0xa; - uint16_t word_at_0xc; - uint16_t word_at_0xe; - uint32_t codec; - uint16_t word_at_0x18; - uint8_t adaptive_stream_index; - uint8_t byte_at_0x2c; -} TakionAVPacket; - static void takion_handle_packet_av(ChiakiTakion *takion, uint8_t base_type, uint8_t *buf, size_t buf_size) { // HHIxIIx @@ -739,7 +724,7 @@ static void takion_handle_packet_av(ChiakiTakion *takion, uint8_t base_type, uin size_t av_size = buf_size-1; - TakionAVPacket packet = {0}; + ChiakiTakionAVPacket packet = {0}; packet.is_2 = base_type == 2; packet.byte_at_0x1a = ((buf[0] >> 4) & 1) != 0; @@ -802,5 +787,5 @@ static void takion_handle_packet_av(ChiakiTakion *takion, uint8_t base_type, uin size_t data_size = av_size; if(takion->av_cb) - takion->av_cb(data, data_size, base_type, key_pos, takion->av_cb_user); + takion->av_cb(&packet, data, data_size, base_type, key_pos, takion->av_cb_user); } \ No newline at end of file