Add ability to return an RTP frame from packet handler
When a complete RTP frame has been received, the packet handler must return the frame to RTP packet dispatcher which then returns the frame to user either through frame queue or receive hook
This commit is contained in:
parent
2bbe34924f
commit
3eb02207d9
|
@ -33,7 +33,7 @@ namespace uvg_rtp {
|
|||
* Return RTP_PKT_NOT_HANDLED if the packet is not handled by this handler
|
||||
* Return RTP_PKT_MODIFIED if the packet was modified but should be forwarded to other handlers
|
||||
* Return RTP_GENERIC_ERROR if the packet was corrupted in some way */
|
||||
static rtp_error_t packet_handler(ssize_t size, void *packet);
|
||||
static rtp_error_t packet_handler(ssize_t size, void *packet, uvg_rtp::frame::rtp_frame **out);
|
||||
|
||||
protected:
|
||||
virtual rtp_error_t __push_frame(uint8_t *data, size_t data_len, int flags);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace uvg_rtp {
|
||||
|
||||
typedef rtp_error_t (*packet_handler)(ssize_t, void *);
|
||||
typedef rtp_error_t (*packet_handler)(ssize_t, void *, uvg_rtp::frame::rtp_frame **);
|
||||
|
||||
class pkt_dispatcher : public runner {
|
||||
public:
|
||||
|
|
|
@ -36,6 +36,7 @@ const int MAX_PACKET = 65536;
|
|||
const int MAX_PAYLOAD = 1443;
|
||||
|
||||
typedef enum RTP_ERROR {
|
||||
RTP_PKT_READY = 5, /* packet can be returned to user */
|
||||
RTP_PKT_MODIFIED = 4, /* packet was modified by the layer (see src/pkt_dispatch.cc) */
|
||||
RTP_PKT_NOT_HANDLED = 3, /* packet does not belong to this layer */
|
||||
RTP_INTERRUPTED = 2,
|
||||
|
|
|
@ -35,7 +35,7 @@ rtp_error_t uvg_rtp::formats::media::__push_frame(uint8_t *data, size_t data_len
|
|||
return RTP_GENERIC_ERROR;
|
||||
}
|
||||
|
||||
static rtp_error_t packet_handler(ssize_t size, void *packet)
|
||||
static rtp_error_t packet_handler(ssize_t size, void *packet, uvg_rtp::frame::rtp_frame **out)
|
||||
{
|
||||
(void)size, (void)packet;
|
||||
return RTP_OK;
|
||||
|
|
|
@ -105,13 +105,21 @@ std::vector<uvg_rtp::packet_handler>& uvg_rtp::pkt_dispatcher::get_handlers()
|
|||
* This requirement gives packet handler a clean and generic interface while giving a possibility to modify
|
||||
* the packet in each of the called handlers if needed. For example SRTP handler verifies RTP authentication
|
||||
* tag and decrypts the packet and RTP handler verifies the fields of the RTP packet and processes it into
|
||||
* a more easily modifiable format for the media handler. */
|
||||
* a more easily modifiable format for the media handler.
|
||||
*
|
||||
* If packet is modified by the handler but the frame is not ready to be returned to user,
|
||||
* handler returns RTP_PKT_MODIFIED to indicate that it has modified the input buffer and that
|
||||
* the packet should be passed onto other handlers.
|
||||
*
|
||||
* When packet is ready to be returned to user, "out" parameter of packet handler is set to point to
|
||||
* the allocated frame that can be returned and return value of the packet handler is RTP_PKT_READY. */
|
||||
static void runner(uvg_rtp::pkt_dispatcher *dispatcher, uvg_rtp::socket& socket)
|
||||
{
|
||||
int nread;
|
||||
fd_set read_fds;
|
||||
rtp_error_t ret;
|
||||
struct timeval t_val;
|
||||
uvg_rtp::frame::rtp_frame *frame;
|
||||
|
||||
FD_ZERO(&read_fds);
|
||||
|
||||
|
@ -140,11 +148,15 @@ static void runner(uvg_rtp::pkt_dispatcher *dispatcher, uvg_rtp::socket& socket)
|
|||
}
|
||||
|
||||
for (auto& handler : dispatcher->get_handlers()) {
|
||||
switch ((ret = (*handler)(nread, recv_buffer))) {
|
||||
/* packet was handled successfully or the packet was in some way corrupted */
|
||||
switch ((ret = (*handler)(nread, recv_buffer, &frame))) {
|
||||
/* packet was handled successfully */
|
||||
case RTP_OK:
|
||||
break;
|
||||
|
||||
/* "out" contains an RTP packet that can be returned to the user */
|
||||
case RTP_PKT_READY:
|
||||
break;
|
||||
|
||||
/* the received packet is not handled at all or only partially by the called handler
|
||||
* proceed to the next handler */
|
||||
case RTP_PKT_NOT_HANDLED:
|
||||
|
@ -152,7 +164,7 @@ static void runner(uvg_rtp::pkt_dispatcher *dispatcher, uvg_rtp::socket& socket)
|
|||
continue;
|
||||
|
||||
case RTP_GENERIC_ERROR:
|
||||
LOG_DEBUG("Received a corrputed packet!");
|
||||
LOG_DEBUG("Received a corrupted packet!");
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue