Refactor AV Receiving

This commit is contained in:
Florian Märkl 2019-05-18 13:28:10 +02:00
commit 2b2b4ae31d
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
3 changed files with 34 additions and 23 deletions

View file

@ -24,15 +24,17 @@
#include "gkcrypt.h"
#include <netinet/in.h>
#include <stdbool.h>
#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);

View file

@ -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);
}

View file

@ -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);
}