| 29 | #include "openhd_util.h" |
| 30 | |
| 31 | OHDVideoGround::OHDVideoGround(std::shared_ptr<OHDLink> link_handle) |
| 32 | : m_link_handle(std::move(link_handle)) { |
| 33 | m_console = openhd::log::create_or_get("v_gnd"); |
| 34 | m_primary_video_forwarder = std::make_unique<openhd::UDPMultiForwarder>(); |
| 35 | m_secondary_video_forwarder = std::make_unique<openhd::UDPMultiForwarder>(); |
| 36 | m_audio_forwarder = std::make_unique<openhd::UDPMultiForwarder>(); |
| 37 | // We always forward video to localhost::5600 (primary) and 5601 (secondary) |
| 38 | // for the default Ground control application (e.g. QOpenHD) to pick up |
| 39 | addForwarder("127.0.0.1"); |
| 40 | // See the description in the .config file for more info |
| 41 | if (openhd::load_config().NW_FORWARD_TO_LOCALHOST_58XX || true) { |
| 42 | m_console->debug("Forwarding video to 5800/5801 localhost is enabled"); |
| 43 | // Adding forwarder for WebRTC |
| 44 | m_primary_video_forwarder->addForwarder("127.0.0.1", 5800); |
| 45 | m_secondary_video_forwarder->addForwarder("127.0.0.1", 5801); |
| 46 | } |
| 47 | if (m_link_handle) { |
| 48 | m_link_handle->register_on_receive_video_data_cb( |
| 49 | [this](int stream_index, const uint8_t* data, int data_len) { |
| 50 | on_video_data(stream_index, data, data_len); |
| 51 | }); |
| 52 | m_link_handle->m_audio_data_rx_cb = [this](const uint8_t* data, |
| 53 | int data_len) { |
| 54 | on_audio_data(data, data_len); |
| 55 | }; |
| 56 | } else { |
| 57 | m_console->warn("No link handle, no video forwarding"); |
| 58 | } |
| 59 | // On the ground, forward video to all connected external devices via UDP |
| 60 | // (In addition to localhost) |
| 61 | // However, if a tcp client on localhost connects, we forward to the udp ports |
| 62 | // higher than 5600 on localhost - see the method below |
| 63 | openhd::ExternalDeviceManager::instance().register_listener( |
| 64 | [this](openhd::ExternalDevice external_device, bool connected) { |
| 65 | start_stop_forwarding_external_device(external_device, connected); |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | OHDVideoGround::~OHDVideoGround() { |
| 70 | if (m_link_handle) { |
nothing calls this directly
no test coverage detected