Skip to content

Commit

Permalink
improve video fec
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Jan 7, 2024
1 parent 35a199a commit f66357f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 29 deletions.
45 changes: 22 additions & 23 deletions src/WBVideoStreamTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ WBVideoStreamTx::~WBVideoStreamTx() {
}
}

void WBVideoStreamTx::set_config_data(
uint8_t codec_type, std::shared_ptr<std::vector<uint8_t>> config_buff) {
auto config=std::make_shared<CodecConfigData>();
config->codec_type=codec_type;
config->config_buff=config_buff;
std::lock_guard<std::mutex> guard(m_codec_config_mutex);
m_codec_config=config;
}

bool WBVideoStreamTx::enqueue_frame(
std::shared_ptr<std::vector<uint8_t>> frame, int max_block_size,
int fec_overhead_perc,
std::chrono::steady_clock::time_point creation_time) {
auto item=std::make_shared<EnqueuedFrame>();
item->frame=frame;
item->max_block_size=max_block_size;
item->fec_overhead_perc=fec_overhead_perc;
item->creation_time=creation_time;
const bool res= m_block_queue->try_enqueue(item);
return res;
}

void WBVideoStreamTx::loop_process_data() {
if(options.dequeue_thread_max_realtime){
SchedulingHelper::setThreadParamsMaxRealtime();
Expand Down Expand Up @@ -71,28 +93,6 @@ void WBVideoStreamTx::process_enqueued_frame(const EnqueuedFrame & enq_frame) {
n_secondary_fragments);
}

void WBVideoStreamTx::set_config_data(
uint8_t codec_type, std::shared_ptr<std::vector<uint8_t>> config_buff) {
auto config=std::make_shared<CodecConfigData>();
config->codec_type=codec_type;
config->config_buff=config_buff;
std::lock_guard<std::mutex> guard(m_codec_config_mutex);
m_codec_config=config;
}

bool WBVideoStreamTx::enqueue_frame(
std::shared_ptr<std::vector<uint8_t>> frame, int max_block_size,
int fec_overhead_perc,
std::chrono::steady_clock::time_point creation_time) {
auto item=std::make_shared<EnqueuedFrame>();
item->frame=frame;
item->max_block_size=max_block_size;
item->fec_overhead_perc=fec_overhead_perc;
item->creation_time=creation_time;
const bool res= m_block_queue->try_enqueue(item);
return res;
}

void WBVideoStreamTx::send_packet(const uint8_t *packet, int packet_len) {
const auto radiotap_header=m_radiotap_header_holder->thread_safe_get();
const bool encrypt=m_enable_encryption.load();
Expand All @@ -102,7 +102,6 @@ void WBVideoStreamTx::send_packet(const uint8_t *packet, int packet_len) {
bool WBVideoStreamTx::send_video_config() {
std::lock_guard<std::mutex> guard(m_codec_config_mutex);
if(m_codec_config== nullptr)return false;
auto& codec_config=*m_codec_config;
auto& config_buff=*m_codec_config->config_buff;
assert(!config_buff.empty() && config_buff.size()<MAX_PAYLOAD_BEFORE_FEC);
m_fec_encoder->fragment_and_encode(config_buff.data(),config_buff.size(),1,0);
Expand Down
13 changes: 7 additions & 6 deletions src/WBVideoStreamTx.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class WBVideoStreamTx {
WBVideoStreamTx(const WBVideoStreamTx&) = delete;
WBVideoStreamTx&operator=(const WBVideoStreamTx&) = delete;
~WBVideoStreamTx();
void set_config_data(uint8_t codec_type,std::shared_ptr<std::vector<uint8_t>> config_buff);
bool enqueue_frame(std::shared_ptr<std::vector<uint8_t>> frame,int max_block_size,int fec_overhead_perc,
std::chrono::steady_clock::time_point creation_time=std::chrono::steady_clock::now());
std::atomic_int32_t in_fps=0;
std::atomic_int32_t in_bps=0;
std::atomic_int32_t out_pps=0;
private:
struct EnqueuedFrame {
std::chrono::steady_clock::time_point enqueue_time_point=std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point creation_time=std::chrono::steady_clock::now();
Expand All @@ -43,12 +50,6 @@ class WBVideoStreamTx {
uint8_t codec_type;
std::shared_ptr<std::vector<uint8_t>> config_buff=nullptr;
};
void set_config_data(uint8_t codec_type,std::shared_ptr<std::vector<uint8_t>> config_buff);
bool enqueue_frame(std::shared_ptr<std::vector<uint8_t>> frame,int max_block_size,int fec_overhead_perc,
std::chrono::steady_clock::time_point creation_time=std::chrono::steady_clock::now());
std::atomic_int32_t in_fps=0;
std::atomic_int32_t in_bps=0;
std::atomic_int32_t out_pps=0;
private:
const Options options;
std::shared_ptr<WBTxRx> m_txrx;
Expand Down
31 changes: 31 additions & 0 deletions src/dummy_link/DummyLink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Created by consti10 on 07.01.24.
//

#include "DummyLink.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>

void* create_shared_memory(size_t size) {
// Our memory buffer will be readable and writable:
int protection = PROT_READ | PROT_WRITE;

// The buffer will be shared (meaning other processes can access it), but
// anonymous (meaning third-party processes cannot obtain an address for it),
// so only this process and its children will be able to use it:
int visibility = MAP_SHARED | MAP_ANONYMOUS;

// The remaining parameters to `mmap()` are not important for this use case,
// but the manpage for `mmap` explains their purpose.
return mmap(NULL, size, protection, visibility, -1, 0);
}


void DummyLink::tx_radiotap(const uint8_t *packet_buff, int packet_size) {

}

void DummyLink::rx_radiotap() {

}
19 changes: 19 additions & 0 deletions src/dummy_link/DummyLink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Created by consti10 on 07.01.24.
//

#ifndef OPENHD_DUMMYLINK_H
#define OPENHD_DUMMYLINK_H

#include <cstdint>

class DummyLink {
public:
void tx_radiotap(const uint8_t* packet_buff, int packet_size);
void rx_radiotap();
private:
bool m_is_air;
};


#endif //OPENHD_DUMMYLINK_H

0 comments on commit f66357f

Please sign in to comment.