Minor changes to code indentation
This commit is contained in:
parent
7f2bd7f4f0
commit
e7cfaa1d99
27
daemon/rtsp_client.cpp
Executable file → Normal file
27
daemon/rtsp_client.cpp
Executable file → Normal file
@ -21,13 +21,13 @@
|
|||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/asio/ip/tcp.hpp>
|
#include <boost/asio/ip/tcp.hpp>
|
||||||
|
#include <chrono>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <istream>
|
#include <istream>
|
||||||
|
#include <map>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
@ -37,7 +37,6 @@ using namespace boost::asio;
|
|||||||
using namespace boost::asio::ip;
|
using namespace boost::asio::ip;
|
||||||
using namespace boost::algorithm;
|
using namespace boost::algorithm;
|
||||||
|
|
||||||
|
|
||||||
struct RtspResponse {
|
struct RtspResponse {
|
||||||
int32_t cseq{-1};
|
int32_t cseq{-1};
|
||||||
std::string content_type;
|
std::string content_type;
|
||||||
@ -101,8 +100,7 @@ RtspResponse read_response(tcp::iostream& s, uint16_t max_length) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<bool, RtspSource> RtspClient::process(
|
std::pair<bool, RtspSource> RtspClient::process(RtspClient::Observer callback,
|
||||||
RtspClient::Observer callback,
|
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const std::string& domain,
|
const std::string& domain,
|
||||||
const std::string& path,
|
const std::string& path,
|
||||||
@ -178,7 +176,8 @@ std::pair<bool, RtspSource> RtspClient::process(
|
|||||||
ss << "rtsp:" << std::hex
|
ss << "rtsp:" << std::hex
|
||||||
<< crc16(reinterpret_cast<const uint8_t*>(res.body.c_str()),
|
<< crc16(reinterpret_cast<const uint8_t*>(res.body.c_str()),
|
||||||
res.body.length());
|
res.body.length());
|
||||||
/*<< std::hex << ip::address_v4::from_string(address.c_str()).to_ulong();*/
|
/*<< std::hex <<
|
||||||
|
* ip::address_v4::from_string(address.c_str()).to_ulong();*/
|
||||||
rtsp_source.id = ss.str();
|
rtsp_source.id = ss.str();
|
||||||
rtsp_source.source = "mDNS";
|
rtsp_source.source = "mDNS";
|
||||||
rtsp_source.address = address;
|
rtsp_source.address = address;
|
||||||
@ -216,8 +215,8 @@ std::pair<bool, RtspSource> RtspClient::process(
|
|||||||
std::getline(s, request);
|
std::getline(s, request);
|
||||||
} while (request.empty() && !s.error());
|
} while (request.empty() && !s.error());
|
||||||
if (s.error()) {
|
if (s.error()) {
|
||||||
BOOST_LOG_TRIVIAL(info) << "rtsp_client:: end: "
|
BOOST_LOG_TRIVIAL(info)
|
||||||
<< s.error().message();
|
<< "rtsp_client:: end: " << s.error().message();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
BOOST_LOG_TRIVIAL(info) << "rtsp_client:: received " << request;
|
BOOST_LOG_TRIVIAL(info) << "rtsp_client:: received " << request;
|
||||||
@ -234,8 +233,8 @@ std::pair<bool, RtspSource> RtspClient::process(
|
|||||||
auto path = std::get<4>(res);
|
auto path = std::get<4>(res);
|
||||||
if (path.rfind("/by-name/") != std::string::npos) {
|
if (path.rfind("/by-name/") != std::string::npos) {
|
||||||
announced_name = path.substr(9);
|
announced_name = path.substr(9);
|
||||||
BOOST_LOG_TRIVIAL(debug) << "rtsp_client:: found announced name "
|
BOOST_LOG_TRIVIAL(debug)
|
||||||
<< announced_name;
|
<< "rtsp_client:: found announced name " << announced_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is_announce = true;
|
is_announce = true;
|
||||||
@ -259,7 +258,6 @@ std::pair<bool, RtspSource> RtspClient::process(
|
|||||||
return {true, rtsp_source};
|
return {true, rtsp_source};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RtspClient::stop(const std::string& name, const std::string& domain) {
|
void RtspClient::stop(const std::string& name, const std::string& domain) {
|
||||||
std::lock_guard<std::mutex> lock(g_mutex);
|
std::lock_guard<std::mutex> lock(g_mutex);
|
||||||
auto it = g_active_clients.find({name, domain});
|
auto it = g_active_clients.find({name, domain});
|
||||||
@ -279,8 +277,7 @@ void RtspClient::stop_all() {
|
|||||||
std::lock_guard<std::mutex> lock(g_mutex);
|
std::lock_guard<std::mutex> lock(g_mutex);
|
||||||
auto it = g_active_clients.begin();
|
auto it = g_active_clients.begin();
|
||||||
while (it != g_active_clients.end()) {
|
while (it != g_active_clients.end()) {
|
||||||
BOOST_LOG_TRIVIAL(info)
|
BOOST_LOG_TRIVIAL(info) << "rtsp_client:: stopping client "
|
||||||
<< "rtsp_client:: stopping client "
|
|
||||||
<< it->first.first << " " << it->first.second;
|
<< it->first.first << " " << it->first.second;
|
||||||
#if BOOST_VERSION < 106600
|
#if BOOST_VERSION < 106600
|
||||||
it->second->close();
|
it->second->close();
|
||||||
@ -291,10 +288,8 @@ void RtspClient::stop_all() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<bool, RtspSource> RtspClient::describe(
|
std::pair<bool, RtspSource> RtspClient::describe(const std::string& path,
|
||||||
const std::string& path,
|
|
||||||
const std::string& address,
|
const std::string& address,
|
||||||
const std::string& port) {
|
const std::string& port) {
|
||||||
return RtspClient::process({}, {}, {}, path, address, port, false);
|
return RtspClient::process({}, {}, {}, path, address, port, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
#ifndef _RTSP_CLIENT_HPP_
|
#ifndef _RTSP_CLIENT_HPP_
|
||||||
#define _RTSP_CLIENT_HPP_
|
#define _RTSP_CLIENT_HPP_
|
||||||
|
|
||||||
#include <mutex>
|
|
||||||
#include <boost/asio/ip/tcp.hpp>
|
#include <boost/asio/ip/tcp.hpp>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
struct RtspSource {
|
struct RtspSource {
|
||||||
std::string id;
|
std::string id;
|
||||||
@ -36,13 +36,11 @@ class RtspClient {
|
|||||||
constexpr static uint16_t client_timeout = 10; // sec
|
constexpr static uint16_t client_timeout = 10; // sec
|
||||||
constexpr static const char dft_port[] = "554";
|
constexpr static const char dft_port[] = "554";
|
||||||
|
|
||||||
using Observer = std::function<void(
|
using Observer = std::function<void(const std::string& name,
|
||||||
const std::string& name,
|
|
||||||
const std::string& domain,
|
const std::string& domain,
|
||||||
const RtspSource& source)>;
|
const RtspSource& source)>;
|
||||||
|
|
||||||
static std::pair<bool, RtspSource> process(
|
static std::pair<bool, RtspSource> process(Observer callback,
|
||||||
Observer callback,
|
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
const std::string& domain,
|
const std::string& domain,
|
||||||
const std::string& path,
|
const std::string& path,
|
||||||
@ -59,10 +57,11 @@ class RtspClient {
|
|||||||
const std::string& port = dft_port);
|
const std::string& port = dft_port);
|
||||||
|
|
||||||
inline static std::atomic<uint16_t> g_seq_number{0};
|
inline static std::atomic<uint16_t> g_seq_number{0};
|
||||||
inline static std::map<std::pair<std::string /*name*/, std::string /*domain*/>,
|
inline static std::map<
|
||||||
boost::asio::ip::tcp::iostream* /*stream*/> g_active_clients;
|
std::pair<std::string /*name*/, std::string /*domain*/>,
|
||||||
|
boost::asio::ip::tcp::iostream* /*stream*/>
|
||||||
|
g_active_clients;
|
||||||
inline static std::mutex g_mutex;
|
inline static std::mutex g_mutex;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user