static void flv_video(struct serializer *s, struct encoder_packet *packet, bool is_header) { int64_t offset = packet->pts - packet->dts; int32_t time_ms = get_ms_time(packet, packet->dts); if (!packet->data || !packet->size) return; s_w8(s, RTMP_PACKET_TYPE_VIDEO); #ifdef DEBUG_TIMESTAMPS blog(LOG_DEBUG, "Video: %lu", time_ms); #endif s_wb24(s, (uint32_t)packet->size + 5); s_wb24(s, time_ms); s_w8(s, (time_ms >> 24) & 0x7F); s_wb24(s, 0); /* these are the 5 extra bytes mentioned above */ s_w8(s, packet->keyframe ? 0x17 : 0x27); s_w8(s, is_header ? 0 : 1); s_wb24(s, get_ms_time(packet, offset)); s_write(s, packet->data, packet->size); /* write tag size (starting byte doesnt count) */ s_wb32(s, (uint32_t)serializer_get_pos(s) + 4 - 1); }
static void flv_audio(struct serializer *s, struct encoder_packet *packet, bool is_header) { int32_t time_ms = get_ms_time(packet, packet->dts); if (!packet->data || !packet->size) return; s_w8(s, RTMP_PACKET_TYPE_AUDIO); #ifdef DEBUG_TIMESTAMPS blog(LOG_DEBUG, "Audio: %lu", time_ms); #endif s_wb24(s, (uint32_t)packet->size + 2); s_wb24(s, time_ms); s_w8(s, (time_ms >> 24) & 0x7F); s_wb24(s, 0); /* these are the two extra bytes mentioned above */ s_w8(s, 0xaf); s_w8(s, is_header ? 0 : 1); s_write(s, packet->data, packet->size); /* write tag size (starting byte doesnt count) */ s_wb32(s, (uint32_t)serializer_get_pos(s) + 4 - 1); }
bool flv_meta_data(obs_output_t *context, uint8_t **output, size_t *size, bool write_header, size_t audio_idx) { struct array_output_data data; struct serializer s; uint8_t *meta_data = NULL; size_t meta_data_size; uint32_t start_pos; array_output_serializer_init(&s, &data); if (!build_flv_meta_data(context, &meta_data, &meta_data_size, audio_idx)) { bfree(meta_data); return false; } if (write_header) { s_write(&s, "FLV", 3); s_w8(&s, 1); s_w8(&s, 5); s_wb32(&s, 9); s_wb32(&s, 0); } start_pos = serializer_get_pos(&s); s_w8(&s, RTMP_PACKET_TYPE_INFO); s_wb24(&s, (uint32_t)meta_data_size); s_wb32(&s, 0); s_wb24(&s, 0); s_write(&s, meta_data, meta_data_size); s_wb32(&s, (uint32_t)serializer_get_pos(&s) - start_pos - 1); *output = data.bytes.array; *size = data.bytes.num; bfree(meta_data); return true; }
void flv_meta_data(obs_output_t context, uint8_t **output, size_t *size) { struct array_output_data data; struct serializer s; uint8_t *meta_data; size_t meta_data_size; uint32_t start_pos; array_output_serializer_init(&s, &data); build_flv_meta_data(context, &meta_data, &meta_data_size); #ifdef WRITE_FLV_HEADER s_write(&s, "FLV", 3); s_w8(&s, 1); s_w8(&s, 5); s_wb32(&s, 9); s_wb32(&s, 0); #endif start_pos = serializer_get_pos(&s); s_w8(&s, RTMP_PACKET_TYPE_INFO); s_wb24(&s, (uint32_t)meta_data_size); s_wb32(&s, 0); s_wb24(&s, 0); s_write(&s, meta_data, meta_data_size); s_wb32(&s, (uint32_t)serializer_get_pos(&s) - start_pos + 4 - 1); *output = data.bytes.array; *size = data.bytes.num; bfree(meta_data); }