Handle non-protobuf Takion Data

This commit is contained in:
Florian Märkl 2019-06-13 13:59:40 +02:00
commit cb5bc75d2e
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
5 changed files with 50 additions and 37 deletions

View file

@ -32,10 +32,34 @@
extern "C" {
#endif
struct chiaki_takion_av_packet_t;
typedef enum chiaki_takion_message_data_type_t {
CHIAKI_TAKION_MESSAGE_DATA_TYPE_PROTOBUF = 0,
CHIAKI_TAKION_MESSAGE_DATA_TYPE_9 = 9
} ChiakiTakionMessageDataType;
typedef void (*ChiakiTakionDataCallback)(uint8_t *buf, size_t buf_size, void *user);
typedef void (*ChiakiTakionAVCallback)(struct chiaki_takion_av_packet_t *packet, void *user);
typedef struct chiaki_takion_av_packet_t
{
ChiakiSeqNum16 packet_index;
ChiakiSeqNum16 frame_index;
bool uses_nalu_info_structs;
bool is_video;
ChiakiSeqNum16 unit_index;
uint16_t units_in_frame_total; // regular + units_in_frame_additional
uint16_t units_in_frame_additional;
uint32_t codec;
uint16_t word_at_0x18;
uint8_t adaptive_stream_index;
uint8_t byte_at_0x2c;
uint32_t key_pos;
uint8_t *data; // not owned
size_t data_size;
} ChiakiTakionAVPacket;
typedef void (*ChiakiTakionDataCallback)(ChiakiTakionMessageDataType, uint8_t *buf, size_t buf_size, void *user);
typedef void (*ChiakiTakionAVCallback)(ChiakiTakionAVPacket *packet, void *user);
typedef struct chiaki_takion_connect_info_t
@ -70,25 +94,6 @@ 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
{
ChiakiSeqNum16 packet_index;
ChiakiSeqNum16 frame_index;
bool uses_nalu_info_structs;
bool is_video;
ChiakiSeqNum16 unit_index;
uint16_t units_in_frame_total; // regular + units_in_frame_additional
uint16_t units_in_frame_additional;
uint32_t codec;
uint16_t word_at_0x18;
uint8_t adaptive_stream_index;
uint8_t byte_at_0x2c;
uint32_t key_pos;
uint8_t *data; // not owned
size_t data_size;
} ChiakiTakionAVPacket;
CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, ChiakiTakionConnectInfo *info);
CHIAKI_EXPORT void chiaki_takion_close(ChiakiTakion *takion);

View file

@ -53,7 +53,7 @@ typedef enum {
static void nagare_takion_data(uint8_t *buf, size_t buf_size, void *user);
static void nagare_takion_data(ChiakiTakionMessageDataType data_type, uint8_t *buf, size_t buf_size, void *user);
static ChiakiErrorCode nagare_send_big(ChiakiNagare *nagare);
static ChiakiErrorCode nagare_send_disconnect(ChiakiNagare *nagare);
static void nagare_takion_data_expect_bang(ChiakiNagare *nagare, uint8_t *buf, size_t buf_size);
@ -196,8 +196,11 @@ error_mirai:
static void nagare_takion_data(uint8_t *buf, size_t buf_size, void *user)
static void nagare_takion_data(ChiakiTakionMessageDataType data_type, uint8_t *buf, size_t buf_size, void *user)
{
if(data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_PROTOBUF)
return;
ChiakiNagare *nagare = user;
switch(nagare->mirai.request)

View file

@ -45,7 +45,7 @@ typedef struct senkusha_t
} Senkusha;
static void senkusha_takion_data(uint8_t *buf, size_t buf_size, void *user);
static void senkusha_takion_data(ChiakiTakionMessageDataType data_type, uint8_t *buf, size_t buf_size, void *user);
static ChiakiErrorCode senkusha_send_big(Senkusha *senkusha);
static ChiakiErrorCode senkusha_send_disconnect(Senkusha *senkusha);
@ -121,8 +121,11 @@ error_bang_mirai:
return err;
}
static void senkusha_takion_data(uint8_t *buf, size_t buf_size, void *user)
static void senkusha_takion_data(ChiakiTakionMessageDataType data_type, uint8_t *buf, size_t buf_size, void *user)
{
if(data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_PROTOBUF)
return;
Senkusha *senkusha = user;
tkproto_TakionMessage msg;

View file

@ -49,6 +49,7 @@ typedef enum takion_message_type_a_t {
TAKION_MESSAGE_TYPE_A_COOKIE_ACK = 0xb,
} TakionMessageTypeA;
typedef struct takion_message_t
{
uint32_t tag;
@ -468,7 +469,7 @@ static void takion_handle_packet_message(ChiakiTakion *takion, uint8_t *buf, siz
return;
//CHIAKI_LOGD(takion->log, "Takion received message with tag %#x, key pos %#x, type (%#x, %#x), payload size %#x, payload:\n", msg.tag, msg.key_pos, msg.type_a, msg.type_b, msg.payload_size);
//chiaki_log_hexdump(takion->log, CHIAKI_LOG_DEBUG, msg.payload, msg.payload_size);
//chiaki_log_hexdump(takion->log, CHIAKI_LOG_DEBUG, buf, buf_size);
switch(msg.type_a)
{
@ -498,18 +499,19 @@ static void takion_handle_packet_message_data(ChiakiTakion *takion, uint8_t type
uint32_t seq_num = ntohl(*((uint32_t *)(buf + 0)));
uint16_t channel = ntohs(*((uint16_t *)(buf + 4)));
uint16_t zero_a = *((uint16_t *)(buf + 6));
uint16_t zero_b = buf[8];
uint8_t data_type = buf[8]; // & 0xf
if(zero_a != 0)
CHIAKI_LOGW(takion->log, "Takion received data with unexpected nonzero %#x at buf+6\n", zero_a);
if(zero_b != 0)
CHIAKI_LOGW(takion->log, "Takion received data with unexpected nonzero %#x at buf+8\n", zero_b);
uint8_t *data = buf + 9;
size_t data_size = buf_size - 9;
if(takion->data_cb)
takion->data_cb(data, data_size, takion->data_cb_user);
if(data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_PROTOBUF && data_type != CHIAKI_TAKION_MESSAGE_DATA_TYPE_9)
CHIAKI_LOGW(takion->log, "Takion received data with unexpected data type %#x\n", data_type);
else if(takion->data_cb)
{
uint8_t *data = buf + 9;
size_t data_size = buf_size - 9;
takion->data_cb((ChiakiTakionMessageDataType)data_type, data, data_size, takion->data_cb_user);
}
chiaki_takion_send_message_data_ack(takion, 0, 0, channel, seq_num);
}

View file

@ -97,7 +97,7 @@ CHIAKI_EXPORT void chiaki_video_receiver_av_packet(ChiakiVideoReceiver *video_re
size_t frame_size;
if(chiaki_frame_processor_flush(&video_receiver->frame_processor, &frame, &frame_size) == CHIAKI_FRAME_PROCESSOR_FLUSH_RESULT_SUCCESS)
{
CHIAKI_LOGD(video_receiver->log, "Decoded frame %d\n", (int)video_receiver->frame_index_cur);
//CHIAKI_LOGD(video_receiver->log, "Decoded frame %d\n", (int)video_receiver->frame_index_cur);
if(video_receiver->session->video_sample_cb)
video_receiver->session->video_sample_cb(frame, frame_size, video_receiver->session->video_sample_cb_user);
free(frame);
@ -119,7 +119,7 @@ CHIAKI_EXPORT void chiaki_video_receiver_av_packet(ChiakiVideoReceiver *video_re
}
video_receiver->frame_index_cur = frame_index;
CHIAKI_LOGD(video_receiver->log, "Preparing slots for frame %d\n", (int)video_receiver->frame_index_cur);
//CHIAKI_LOGD(video_receiver->log, "Preparing slots for frame %d\n", (int)video_receiver->frame_index_cur);
chiaki_frame_processor_alloc_frame(&video_receiver->frame_processor, packet);
}