| 1753 | } |
| 1754 | |
| 1755 | int start_broadcast(broadcast_ctx_t &ctx) { |
| 1756 | auto address_family = net::af_from_enum_string(config::sunshine.address_family); |
| 1757 | auto protocol = address_family == net::IPV4 ? udp::v4() : udp::v6(); |
| 1758 | auto control_port = net::map_port(CONTROL_PORT); |
| 1759 | auto video_port = net::map_port(VIDEO_STREAM_PORT); |
| 1760 | auto audio_port = net::map_port(AUDIO_STREAM_PORT); |
| 1761 | |
| 1762 | if (ctx.control_server.bind(address_family, control_port)) { |
| 1763 | BOOST_LOG(error) << "Couldn't bind Control server to port ["sv << control_port << "], likely another process already bound to the port"sv; |
| 1764 | |
| 1765 | return -1; |
| 1766 | } |
| 1767 | |
| 1768 | boost::system::error_code ec; |
| 1769 | ctx.video_sock.open(protocol, ec); |
| 1770 | if (ec) { |
| 1771 | BOOST_LOG(fatal) << "Couldn't open socket for Video server: "sv << ec.message(); |
| 1772 | |
| 1773 | return -1; |
| 1774 | } |
| 1775 | |
| 1776 | // Set video socket send buffer size (SO_SENDBUF) to 1MB |
| 1777 | try { |
| 1778 | ctx.video_sock.set_option(boost::asio::socket_base::send_buffer_size(1024 * 1024)); |
| 1779 | } catch (...) { |
| 1780 | BOOST_LOG(error) << "Failed to set video socket send buffer size (SO_SENDBUF)"; |
| 1781 | } |
| 1782 | |
| 1783 | ctx.video_sock.bind(udp::endpoint(protocol, video_port), ec); |
| 1784 | if (ec) { |
| 1785 | BOOST_LOG(fatal) << "Couldn't bind Video server to port ["sv << video_port << "]: "sv << ec.message(); |
| 1786 | |
| 1787 | return -1; |
| 1788 | } |
| 1789 | |
| 1790 | ctx.audio_sock.open(protocol, ec); |
| 1791 | if (ec) { |
| 1792 | BOOST_LOG(fatal) << "Couldn't open socket for Audio server: "sv << ec.message(); |
| 1793 | |
| 1794 | return -1; |
| 1795 | } |
| 1796 | |
| 1797 | ctx.audio_sock.bind(udp::endpoint(protocol, audio_port), ec); |
| 1798 | if (ec) { |
| 1799 | BOOST_LOG(fatal) << "Couldn't bind Audio server to port ["sv << audio_port << "]: "sv << ec.message(); |
| 1800 | |
| 1801 | return -1; |
| 1802 | } |
| 1803 | |
| 1804 | ctx.message_queue_queue = std::make_shared<message_queue_queue_t::element_type>(30); |
| 1805 | |
| 1806 | ctx.video_thread = std::thread {videoBroadcastThread, std::ref(ctx.video_sock)}; |
| 1807 | ctx.audio_thread = std::thread {audioBroadcastThread, std::ref(ctx.audio_sock)}; |
| 1808 | ctx.control_thread = std::thread {controlBroadcastThread, &ctx.control_server}; |
| 1809 | |
| 1810 | ctx.recv_thread = std::thread {recvThread, std::ref(ctx)}; |
| 1811 | |
| 1812 | return 0; |
nothing calls this directly
no test coverage detected