build: Separate common header file lib.hh from context class

With this separation, the user has the option of not including all
the classes with lib.hh, where as previously it was mandatory because
context is always needed.
This commit is contained in:
Joni Räsänen 2022-02-28 10:30:13 +02:00
parent 3b163e1027
commit f4352358bb
4 changed files with 100 additions and 87 deletions

View File

@ -31,7 +31,7 @@ target_sources(${PROJECT_NAME} PRIVATE
src/dispatch.cc
src/frame.cc
src/hostname.cc
src/lib.cc
src/context.cc
src/media_stream.cc
src/mingw_inet.cc
src/multicast.cc
@ -112,6 +112,7 @@ target_sources(${PROJECT_NAME} PRIVATE
include/uvgrtp/util.hh
include/uvgrtp/clock.hh
include/uvgrtp/context.hh
include/uvgrtp/crypto.hh
include/uvgrtp/debug.hh
include/uvgrtp/frame.hh

90
include/uvgrtp/context.hh Normal file
View File

@ -0,0 +1,90 @@
#pragma once
#include "util.hh"
#include <map>
#include <string>
namespace uvgrtp {
class session;
class context {
public:
/**
* \brief RTP context constructor
*
* \details Most of the time one RTP context per application is enough.
* If CNAME namespace isolation is required, multiple context objects can be created.
*/
context();
/**
* \brief RTP context destructor
*
* \details This does not destroy active sessions. They must be destroyed manually
* by calling uvgrtp::context::destroy_session()
*/
~context();
/**
* \brief Create a new RTP session
*
* \param addr IPv4 address of the remote participant
*
* \return RTP session object
*
* \retval uvgrtp::session On success
* \retval nullptr If "remote_addr" is empty
* \retval nullptr If memory allocation failed
*/
uvgrtp::session *create_session(std::string remote_addr);
/**
* \brief Create a new RTP session
*
* \details If UDP holepunching should be utilized, in addition to remote IP
* address, the caller must also provide local IP address where uvgRTP
* should bind itself to. If you are using uvgRTP for unidirectional streaming,
* please take a look at @ref RCE_HOLEPUNCH_KEEPALIVE
*
* \param remote_addr IPv4 address of the remote participant
* \param local_addr IPv4 address of a local interface
*
* \return RTP session object
*
* \retval uvgrtp::session On success
* \retval nullptr If remote_addr or local_addr is empty
* \retval nullptr If memory allocation failed
*/
uvgrtp::session *create_session(std::string remote_addr, std::string local_addr);
/**
* \brief Destroy RTP session and all of its media streams
*
* \param session Pointer to the session object that should be destroyed
*
* \return RTP error code
*
* \retval RTP_OK On success
* \retval RTP_INVALID_VALUE If session is nullptr
*/
rtp_error_t destroy_session(uvgrtp::session *session);
/// \cond DO_NOT_DOCUMENT
std::string& get_cname();
/// \endcond
bool crypto_enabled() const;
private:
/* Generate CNAME for participant using host and login names */
std::string generate_cname();
/* CNAME is the same for all connections */
std::string cname_;
};
}
namespace uvg_rtp = uvgrtp;

View File

@ -1,96 +1,17 @@
#pragma once
// these includes are here for easier usage of this library
/* Including this header will include all the necessary headers for using uvgRTP, but
* you can also include the headers individually instead of this header. */
#include "media_stream.hh" // media streamer class
#include "session.hh" // session class
#include "context.hh" // context class
#include "rtcp.hh" // RTCP
#include "clock.hh" // time related functions
#include "crypto.hh" // check if crypto is enabled
#include "debug.hh" // debug prints
#include "frame.hh" // frame related functions
#include "util.hh" // types
#include "version.hh" // version
#include <map>
#include <string>
namespace uvgrtp {
class context {
public:
/**
* \brief RTP context constructor
*
* \details Most of the time one RTP context per application is enough.
* If CNAME namespace isolation is required, multiple context objects can be created.
*/
context();
/**
* \brief RTP context destructor
*
* \details This does not destroy active sessions. They must be destroyed manually
* by calling uvgrtp::context::destroy_session()
*/
~context();
/**
* \brief Create a new RTP session
*
* \param addr IPv4 address of the remote participant
*
* \return RTP session object
*
* \retval uvgrtp::session On success
* \retval nullptr If "remote_addr" is empty
* \retval nullptr If memory allocation failed
*/
uvgrtp::session *create_session(std::string remote_addr);
/**
* \brief Create a new RTP session
*
* \details If UDP holepunching should be utilized, in addition to remote IP
* address, the caller must also provide local IP address where uvgRTP
* should bind itself to. If you are using uvgRTP for unidirectional streaming,
* please take a look at @ref RCE_HOLEPUNCH_KEEPALIVE
*
* \param remote_addr IPv4 address of the remote participant
* \param local_addr IPv4 address of a local interface
*
* \return RTP session object
*
* \retval uvgrtp::session On success
* \retval nullptr If remote_addr or local_addr is empty
* \retval nullptr If memory allocation failed
*/
uvgrtp::session *create_session(std::string remote_addr, std::string local_addr);
/**
* \brief Destroy RTP session and all of its media streams
*
* \param session Pointer to the session object that should be destroyed
*
* \return RTP error code
*
* \retval RTP_OK On success
* \retval RTP_INVALID_VALUE If session is nullptr
*/
rtp_error_t destroy_session(uvgrtp::session *session);
/// \cond DO_NOT_DOCUMENT
std::string& get_cname();
/// \endcond
bool crypto_enabled() const;
private:
/* Generate CNAME for participant using host and login names */
std::string generate_cname();
/* CNAME is the same for all connections */
std::string cname_;
};
}
namespace uvg_rtp = uvgrtp;

View File

@ -1,8 +1,9 @@
#include "uvgrtp/lib.hh"
#include "uvgrtp/context.hh"
#include "uvgrtp/version.hh"
#include "uvgrtp/session.hh"
#include "uvgrtp/debug.hh"
#include "uvgrtp/crypto.hh"
#include "hostname.hh"
#include "random.hh"