static void vaapi_encode_h264_write_sei(PutBitContext *pbc, VAAPIEncodeContext *ctx, VAAPIEncodePicture *pic) { VAAPIEncodeH264Context *priv = ctx->priv_data; PutBitContext payload_bits; char payload[256]; int payload_type, payload_size, i; void (*write_payload)(PutBitContext *pbc, VAAPIEncodeContext *ctx, VAAPIEncodePicture *pic) = NULL; vaapi_encode_h264_write_nal_header(pbc, NAL_SEI, 0); for (payload_type = 0; payload_type < 64; payload_type++) { switch (payload_type) { case SEI_TYPE_BUFFERING_PERIOD: if (!priv->send_timing_sei || pic->type != PICTURE_TYPE_IDR) continue; write_payload = &vaapi_encode_h264_write_buffering_period; break; case SEI_TYPE_PIC_TIMING: if (!priv->send_timing_sei) continue; write_payload = &vaapi_encode_h264_write_pic_timing; break; case SEI_TYPE_USER_DATA_UNREGISTERED: if (pic->encode_order != 0) continue; write_payload = &vaapi_encode_h264_write_identifier; break; default: continue; } init_put_bits(&payload_bits, payload, sizeof(payload)); write_payload(&payload_bits, ctx, pic); if (put_bits_count(&payload_bits) & 7) { write_u(&payload_bits, 1, 1, bit_equal_to_one); while (put_bits_count(&payload_bits) & 7) write_u(&payload_bits, 1, 0, bit_equal_to_zero); } payload_size = put_bits_count(&payload_bits) / 8; flush_put_bits(&payload_bits); u(8, payload_type, last_payload_type_byte); u(8, payload_size, last_payload_size_byte); for (i = 0; i < payload_size; i++) u(8, payload[i] & 0xff, sei_payload); } vaapi_encode_h264_write_trailing_rbsp(pbc); }
bool Message::send(Client& client) { uint32_t remaining_length = variable_header_length() + payload_length(); uint32_t packet_length = fixed_header_length(remaining_length) + remaining_length; uint8_t *packet = new uint8_t[packet_length]; uint32_t pos = 0; write_fixed_header(packet, pos, remaining_length); write_variable_header(packet, pos); write_payload(packet, pos); uint32_t sent = client.write(const_cast<const uint8_t*>(packet), packet_length); delete [] packet; return (sent == packet_length); }
bool Radio::writeFast(const void *buf, uint8_t len, const bool multicast) { // Let's block if FIFO is full or max number of retries is reached. Return 0 so the user can control the retries // manually. The radio will auto-clear everything in the FIFO as long as CE remains high. while (get_status() & _BV(TX_FULL)) { // Max number of retries is reached, let's clear the flag and return 0. if (get_status() & _BV(MAX_RT)) { write_register(STATUS, _BV(MAX_RT)); return 0; } } write_payload(buf, len, multicast ? W_TX_PAYLOAD_NO_ACK : W_TX_PAYLOAD); return 1; }
bool Radio::writeBlocking(const void *buf, uint8_t len, uint32_t timeout) { uint32_t elapsed = 0; while (get_status() & _BV(TX_FULL)) { if (get_status() & _BV(MAX_RT)) { // Set re-transmit and clear the MAX_RT interrupt flag. reUseTX(); // If this payload has exceeded the user-defined timeout, exit and return 0. if (elapsed > timeout) { return 0; } } _delay_ms(100); elapsed += 100; } write_payload(buf, len, W_TX_PAYLOAD); return 1; }