mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-05-26 15:26:12 +00:00
Merge pull request #332 from intelfx/work/fix-janus-rtpv
janus: fix rtpv chunking
This commit is contained in:
@@ -47,9 +47,9 @@ void us_rtp_assign(us_rtp_s *rtp, uint payload, bool video) {
|
|||||||
rtp->ssrc = us_triple_u32(us_get_now_monotonic_u64());
|
rtp->ssrc = us_triple_u32(us_get_now_monotonic_u64());
|
||||||
}
|
}
|
||||||
|
|
||||||
void us_rtp_write_header(us_rtp_s *rtp, u32 pts, bool marked) {
|
void us_rtp_write_header(us_rtp_s *rtp, u32 pts, bool last_header) {
|
||||||
u32 word0 = 0x80000000;
|
u32 word0 = 0x80000000;
|
||||||
if (marked) {
|
if (last_header) {
|
||||||
word0 |= 1 << 23;
|
word0 |= 1 << 23;
|
||||||
}
|
}
|
||||||
word0 |= (rtp->payload & 0x7F) << 16;
|
word0 |= (rtp->payload & 0x7F) << 16;
|
||||||
|
|||||||
@@ -66,4 +66,4 @@ us_rtp_s *us_rtp_init(void);
|
|||||||
void us_rtp_destroy(us_rtp_s *rtp);
|
void us_rtp_destroy(us_rtp_s *rtp);
|
||||||
|
|
||||||
void us_rtp_assign(us_rtp_s *rtp, uint payload, bool video);
|
void us_rtp_assign(us_rtp_s *rtp, uint payload, bool video);
|
||||||
void us_rtp_write_header(us_rtp_s *rtp, u32 pts, bool marked);
|
void us_rtp_write_header(us_rtp_s *rtp, u32 pts, bool last_header);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
#include "rtp.h"
|
#include "rtp.h"
|
||||||
|
|
||||||
|
|
||||||
void _rtpv_process_nalu(us_rtpv_s *rtpv, const u8 *data, uz size, u32 pts, bool marked);
|
void _rtpv_process_nalu(us_rtpv_s *rtpv, const u8 *data, uz size, u32 pts, bool first_nalu, bool last_nalu);
|
||||||
|
|
||||||
static sz _find_annexb(const u8 *data, uz size);
|
static sz _find_annexb(const u8 *data, uz size);
|
||||||
|
|
||||||
@@ -80,6 +80,7 @@ void us_rtpv_wrap(us_rtpv_s *rtpv, const us_frame_s *frame, bool zero_playout_de
|
|||||||
}
|
}
|
||||||
uz begin = offset_to_first + _PRE;
|
uz begin = offset_to_first + _PRE;
|
||||||
|
|
||||||
|
bool first_nalu = true;
|
||||||
while (begin < frame->used) { // Find and iterate by NALUs
|
while (begin < frame->used) { // Find and iterate by NALUs
|
||||||
const u8 *const data = frame->data + begin;
|
const u8 *const data = frame->data + begin;
|
||||||
const sz offset_to_next = _find_annexb(data, frame->used - begin);
|
const sz offset_to_next = _find_annexb(data, frame->used - begin);
|
||||||
@@ -90,21 +91,23 @@ void us_rtpv_wrap(us_rtpv_s *rtpv, const us_frame_s *frame, bool zero_playout_de
|
|||||||
--size;
|
--size;
|
||||||
}
|
}
|
||||||
if (size > 1) { // Skip too short NALUs
|
if (size > 1) { // Skip too short NALUs
|
||||||
_rtpv_process_nalu(rtpv, data, size, pts, false);
|
_rtpv_process_nalu(rtpv, data, size, pts, first_nalu, false);
|
||||||
|
first_nalu = false;
|
||||||
}
|
}
|
||||||
begin += offset_to_next + _PRE;
|
begin += offset_to_next + _PRE;
|
||||||
|
|
||||||
} else { // Process the tail
|
} else { // Process the tail
|
||||||
const uz size = frame->used - begin;
|
const uz size = frame->used - begin;
|
||||||
if (size > 1) {
|
if (size > 1) {
|
||||||
_rtpv_process_nalu(rtpv, data, size, pts, true);
|
_rtpv_process_nalu(rtpv, data, size, pts, first_nalu, true);
|
||||||
|
first_nalu = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _rtpv_process_nalu(us_rtpv_s *rtpv, const u8 *data, uz size, u32 pts, bool marked) {
|
void _rtpv_process_nalu(us_rtpv_s *rtpv, const u8 *data, uz size, u32 pts, bool first_nalu, bool last_nalu) {
|
||||||
US_A(size > 1);
|
US_A(size > 1);
|
||||||
|
|
||||||
const uint ref_idc = (data[0] >> 5) & 3;
|
const uint ref_idc = (data[0] >> 5) & 3;
|
||||||
@@ -113,12 +116,11 @@ void _rtpv_process_nalu(us_rtpv_s *rtpv, const u8 *data, uz size, u32 pts, bool
|
|||||||
u8 *dg = rtp->datagram;
|
u8 *dg = rtp->datagram;
|
||||||
|
|
||||||
if (size + US_RTP_HEADER_SIZE <= US_RTP_TOTAL_SIZE) {
|
if (size + US_RTP_HEADER_SIZE <= US_RTP_TOTAL_SIZE) {
|
||||||
us_rtp_write_header(rtp, pts, marked);
|
us_rtp_write_header(rtp, pts, last_nalu);
|
||||||
memcpy(dg + US_RTP_HEADER_SIZE, data, size);
|
memcpy(dg + US_RTP_HEADER_SIZE, data, size);
|
||||||
rtp->used = size + US_RTP_HEADER_SIZE;
|
rtp->used = size + US_RTP_HEADER_SIZE;
|
||||||
const bool sps_or_pps = (type == 7 || type == 8);
|
rtp->first_of_frame = first_nalu;
|
||||||
rtp->first_of_frame = !sps_or_pps;
|
rtp->last_of_frame = last_nalu;
|
||||||
rtp->last_of_frame = !sps_or_pps;
|
|
||||||
rtpv->callback(rtp);
|
rtpv->callback(rtp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -136,7 +138,7 @@ void _rtpv_process_nalu(us_rtpv_s *rtpv, const u8 *data, uz size, u32 pts, bool
|
|||||||
frag_size = remaining;
|
frag_size = remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
us_rtp_write_header(rtp, pts, (marked && last));
|
us_rtp_write_header(rtp, pts, (last_nalu && last));
|
||||||
|
|
||||||
dg[US_RTP_HEADER_SIZE] = 28 | (ref_idc << 5);
|
dg[US_RTP_HEADER_SIZE] = 28 | (ref_idc << 5);
|
||||||
|
|
||||||
@@ -151,8 +153,8 @@ void _rtpv_process_nalu(us_rtpv_s *rtpv, const u8 *data, uz size, u32 pts, bool
|
|||||||
|
|
||||||
memcpy(dg + fu_overhead, src, frag_size);
|
memcpy(dg + fu_overhead, src, frag_size);
|
||||||
rtp->used = fu_overhead + frag_size;
|
rtp->used = fu_overhead + frag_size;
|
||||||
rtp->first_of_frame = first;
|
rtp->first_of_frame = first_nalu && first;
|
||||||
rtp->last_of_frame = last;
|
rtp->last_of_frame = last_nalu && last;
|
||||||
rtpv->callback(rtp);
|
rtpv->callback(rtp);
|
||||||
|
|
||||||
src += frag_size;
|
src += frag_size;
|
||||||
|
|||||||
Reference in New Issue
Block a user