|
|
@@ -3,12 +3,12 @@
|
|
|
#include "videocommon.h"
|
|
|
#include "bs.h"
|
|
|
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
+#ifdef _WIN32
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
#include <windows.h>
|
|
|
#else
|
|
|
#include <semaphore.h>
|
|
|
-#endif // RVC_OS_WIN
|
|
|
+#endif // _WIN32
|
|
|
|
|
|
#include <assert.h>
|
|
|
#include <malloc.h>
|
|
|
@@ -178,9 +178,6 @@ static void rtpLogevent(videortp_t* rtp, int itype, const char* strmessage)
|
|
|
}
|
|
|
|
|
|
|
|
|
-//#define Dbg(__fmt__, ...) __Dbg(vrtp, __fmt__, __VA_ARGS__)
|
|
|
-
|
|
|
-
|
|
|
static void get_start_config_bitrate(videortp_config_t *config, int *max_bitrate, int *target_bitrate, int *min_bitrate){
|
|
|
*max_bitrate = config->bit_rate; //bps
|
|
|
*min_bitrate = 50*1000 > config->bit_rate ? config->bit_rate : 50*1000; //bps
|
|
|
@@ -307,7 +304,7 @@ static __inline void receiver_notify_peer_fast_update(videortp_t *vrtp)
|
|
|
DWORD dwNow = GetTickCount();
|
|
|
if (dwNow - vrtp->last_peer_update_tick >= PEER_UPDATE_INTERVAL) {
|
|
|
|
|
|
- rtpDbg(vrtp,"%I64d receiver_notify_peer_fast_update!", TimeInMilliseconds());
|
|
|
+ //rtpDbg(vrtp,"%I64d receiver_notify_peer_fast_update!", TimeInMilliseconds());
|
|
|
rtp_session_send_rtcp_h261_fir(vrtp->rtp_sess);
|
|
|
vrtp->last_peer_update_tick = dwNow;
|
|
|
}
|
|
|
@@ -450,15 +447,15 @@ void decoder_create(videortp_t *vrtp, const videortp_config_t *config){
|
|
|
log_func.userdata = vrtp;
|
|
|
vrtp->decoder = video_decoder_open(&decoder_config, &log_func);
|
|
|
|
|
|
- rtpDbg(vrtp,"decoder_create color_space: %d decode_id: %d width: %d height: %d.",
|
|
|
- decoder_config.color_space, decoder_config.decode_id, decoder_config.width, decoder_config.height);
|
|
|
+ //rtpDbg(vrtp,"decoder_create color_space: %d decode_id: %d width: %d height: %d.",
|
|
|
+ // decoder_config.color_space, decoder_config.decode_id, decoder_config.width, decoder_config.height);
|
|
|
}
|
|
|
|
|
|
void decoder_destroy(videortp_t *vrtp){
|
|
|
if (vrtp->decoder != NULL) {
|
|
|
video_decoder_close(vrtp->decoder);
|
|
|
}
|
|
|
- rtpDbg(vrtp,"decoder_destroy.");
|
|
|
+ //rtpDbg(vrtp,"decoder_destroy.");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -565,7 +562,7 @@ static int receiver_standard_h264_add_encoded_buffer_startcode(videortp_t *vrtp,
|
|
|
uint8_t *output_buf)
|
|
|
{
|
|
|
uint8_t *dst = NULL;
|
|
|
- bool_t start_picture=TRUE;
|
|
|
+ bool_t start_picture=true;
|
|
|
int output_len = 0;
|
|
|
int i = 0;
|
|
|
|
|
|
@@ -579,7 +576,7 @@ static int receiver_standard_h264_add_encoded_buffer_startcode(videortp_t *vrtp,
|
|
|
|
|
|
if (start_picture || nalu_type==NAL_SPS || nalu_type==NAL_PPS){
|
|
|
*dst++=0;
|
|
|
- start_picture=FALSE;
|
|
|
+ start_picture=false;
|
|
|
}
|
|
|
*dst++ = 0;
|
|
|
*dst++ = 0;
|
|
|
@@ -795,7 +792,7 @@ rtpframe_t *receiver_standard_h264_assemble(videortp_t *vrtp,
|
|
|
|
|
|
int ret = -1;
|
|
|
int iret = -1;
|
|
|
- rtpframe_t *frame = NULL;
|
|
|
+ //rtpframe_t *frame = NULL;
|
|
|
int key = 0;
|
|
|
|
|
|
x264_hdr *hdr = (x264_hdr*)&part_data->buf[0];
|
|
|
@@ -874,7 +871,7 @@ static int receiver_process_standard_h264_packet(
|
|
|
|
|
|
decoded = receiver_standard_h264_decode(vrtp, frame);
|
|
|
if (decoded) {
|
|
|
- //Dbg("decode_frame ok!");
|
|
|
+ //rtpDbg(vrtp,"decode_frame ok!");
|
|
|
if (vrtp->frame_duration==0 && vrtp->prev_dec_seq+1 == rtpframe_get_first_seq(frame)) {
|
|
|
vrtp->frame_duration = frame->ts - vrtp->prev_dec_ts;
|
|
|
rtpDbg(vrtp,"decode frame duration: %d", vrtp->frame_duration);
|
|
|
@@ -989,7 +986,7 @@ static int receiver_custom_h264_decode(videortp_t *vrtp, rtpframe_t *frame)
|
|
|
{
|
|
|
if (frame->used) {
|
|
|
rtpframe_part_t *pos = NULL;
|
|
|
- int got_picture = 0;
|
|
|
+ //int got_picture = 0;
|
|
|
uint8_t *input_buf = NULL;
|
|
|
int input_len = 0;
|
|
|
|
|
|
@@ -1151,17 +1148,15 @@ void* recv_proc(void* arg)
|
|
|
#endif
|
|
|
{
|
|
|
videortp_t *vrtp = (videortp_t*)arg;
|
|
|
- int ifresh_time = vrtp->config.fresh_time;
|
|
|
int rtp_timeout_cnt = 0;
|
|
|
int64_t pre_500_ms = TimeInMilliseconds();
|
|
|
- rtpDbg(vrtp,"enter recv_proc,and ifresh time is %dms.", ifresh_time);
|
|
|
#ifdef _WIN32
|
|
|
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
|
|
|
#else
|
|
|
struct sched_param param;
|
|
|
int policy;
|
|
|
pthread_getschedparam(pthread_self(), &policy, ¶m);
|
|
|
- rtpDbg(vrtp,"%s:%d current thread policy is %d, priority is %d.", __FUNCTION__, __LINE__, policy, param.sched_priority);
|
|
|
+ rtpDbg(vrtp,"current thread policy is %d, priority is %d.", policy, param.sched_priority);
|
|
|
#endif
|
|
|
receiver_notify_peer_fast_update_now(vrtp);
|
|
|
|
|
|
@@ -1173,7 +1168,7 @@ void* recv_proc(void* arg)
|
|
|
struct timespec ts;
|
|
|
//int ivalue = -1;
|
|
|
clock_gettime(CLOCK_REALTIME, &ts);
|
|
|
- long unsec = ts.tv_nsec + (1000 * 1000 * ifresh_time);
|
|
|
+ long unsec = ts.tv_nsec + (1000 * 1000 * 10);
|
|
|
ts.tv_sec += (unsec / 1000000000);
|
|
|
ts.tv_nsec = (unsec % 1000000000);
|
|
|
if (0 != sem_timedwait(&vrtp->sem_evt, &ts) && (ETIMEDOUT == errno))
|
|
|
@@ -1286,7 +1281,7 @@ void* recv_proc(void* arg)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- rtpDbg(vrtp, "exit recv_proc.");
|
|
|
+ //rtpDbg(vrtp, "exit recv_proc.");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -1948,12 +1943,12 @@ void ffmpeg_encoder_create(videortp_t *vrtp, const videortp_config_t *config){
|
|
|
encoder_config.min_qp = 10;
|
|
|
video_encoder_api_configure_encoder(vrtp->encoder, &encoder_config, get_mtu(config->mtu) - 5/*padding*/ - ((sizeof(h26x_hdr)-2 + 32/*rtp_header_extension_length*/)));
|
|
|
|
|
|
- rtpDbg(vrtp,"ffmpeg_encoder_create color_space: %d encode_id: %d width: %d height: %d.",
|
|
|
- encoder_config.color_space, encoder_config.encode_id, encoder_config.width, encoder_config.height);
|
|
|
- rtpDbg(vrtp,"ffmpeg_encoder_create max_bitrate: %d min_bitrate: %d target_bitrate: %d.",
|
|
|
- max_bitrate, min_bitrate, target_bitrate);
|
|
|
- rtpDbg(vrtp,"ffmpeg_encoder_create min_framerate: %d key_frame_interval: %d target_qp: %d.",
|
|
|
- encoder_config.min_framerate, encoder_config.key_frame_interval, encoder_config.target_qp);
|
|
|
+ //rtpDbg(vrtp,"ffmpeg_encoder_create color_space: %d encode_id: %d width: %d height: %d.",
|
|
|
+ // encoder_config.color_space, encoder_config.encode_id, encoder_config.width, encoder_config.height);
|
|
|
+ //rtpDbg(vrtp,"ffmpeg_encoder_create max_bitrate: %d min_bitrate: %d target_bitrate: %d.",
|
|
|
+ // max_bitrate, min_bitrate, target_bitrate);
|
|
|
+ //rtpDbg(vrtp,"ffmpeg_encoder_create min_framerate: %d key_frame_interval: %d target_qp: %d.",
|
|
|
+ // encoder_config.min_framerate, encoder_config.key_frame_interval, encoder_config.target_qp);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -1963,7 +1958,7 @@ void ffmpeg_encoder_destory(videortp_t *vrtp){
|
|
|
video_encoder_api_stop(vrtp->encoder);
|
|
|
video_encoder_api_destroy(vrtp->encoder);
|
|
|
}
|
|
|
- rtpDbg(vrtp,"ffmpeg_encoder_destory.");
|
|
|
+ //rtpDbg(vrtp,"ffmpeg_encoder_destory.");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2000,7 +1995,7 @@ void jitter_buffer_create(videortp_t *vrtp, const videortp_config_t *config){
|
|
|
log_func.userdata = vrtp;
|
|
|
vrtp->jbuffer = video_jbuffer_api_new(&video_jbuffer_observer, &log_func);
|
|
|
|
|
|
- rtpDbg(vrtp,"jitter_buffer_create.");
|
|
|
+ //rtpDbg(vrtp,"jitter_buffer_create.");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2008,7 +2003,7 @@ void jitter_buffer_destory(videortp_t *vrtp){
|
|
|
if (vrtp->jbuffer != NULL) {
|
|
|
video_jbuffer_api_destroy(vrtp->jbuffer);
|
|
|
}
|
|
|
- rtpDbg(vrtp,"jitter_buffer_destory.");
|
|
|
+ //rtpDbg(vrtp,"jitter_buffer_destory.");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2071,12 +2066,12 @@ int videortp_create(const videortp_config_t *config, videortp_t **p_rtp)
|
|
|
vrtp->remote_support_cc = 0;
|
|
|
memcpy((void *)(&vrtp->config), (const void *)config, sizeof(videortp_config_t));
|
|
|
|
|
|
- rtpDbg(vrtp,"videortp_create local_pt: %d local_ip: %d local_rtp_port: %d.", config->local_pt, config->local_ip, config->local_rtp_port);
|
|
|
- rtpDbg(vrtp,"videortp_create remote_pt: %d remote_ip: %d remote_rtp_port: %d.", config->remote_pt, config->remote_ip, config->remote_rtp_port);
|
|
|
- rtpDbg(vrtp,"videortp_create tx_width: %d tx_height: %d.", config->tx_width, config->tx_height);
|
|
|
- rtpDbg(vrtp,"videortp_create rx_width: %d rx_height: %d.", config->rx_width, config->rx_height);
|
|
|
- rtpDbg(vrtp,"videortp_create capture_width: %d capture_height: %d.", config->capture_width, config->capture_height);
|
|
|
- rtpDbg(vrtp,"videortp_create fps_num: %d bit_rate: %d dir: %d.", config->fps_num, config->bit_rate, config->dir);
|
|
|
+ //rtpDbg(vrtp,"videortp_create local_pt: %d local_ip: %d local_rtp_port: %d.", config->local_pt, config->local_ip, config->local_rtp_port);
|
|
|
+ //rtpDbg(vrtp,"videortp_create remote_pt: %d remote_ip: %d remote_rtp_port: %d.", config->remote_pt, config->remote_ip, config->remote_rtp_port);
|
|
|
+ //rtpDbg(vrtp,"videortp_create tx_width: %d tx_height: %d.", config->tx_width, config->tx_height);
|
|
|
+ //rtpDbg(vrtp,"videortp_create rx_width: %d rx_height: %d.", config->rx_width, config->rx_height);
|
|
|
+ //rtpDbg(vrtp,"videortp_create capture_width: %d capture_height: %d.", config->capture_width, config->capture_height);
|
|
|
+ //rtpDbg(vrtp,"videortp_create fps_num: %d bit_rate: %d dir: %d.", config->fps_num, config->bit_rate, config->dir);
|
|
|
|
|
|
INIT_LIST_HEAD(&vrtp->free_part_list);
|
|
|
for (i = 0; i < FRAME_WIN_SIZE; ++i) {
|
|
|
@@ -2092,11 +2087,11 @@ int videortp_create(const videortp_config_t *config, videortp_t **p_rtp)
|
|
|
rtpLogevent(vrtp, 0, strMessage);
|
|
|
goto on_error;
|
|
|
}
|
|
|
- else {
|
|
|
- char strInfo[MAX_PATH] = { 0 };
|
|
|
- snprintf(strInfo, MAX_PATH, "video rtp create success and local port is %d.", config->local_rtp_port);
|
|
|
- rtpLogevent(vrtp, 0, strInfo);
|
|
|
- }
|
|
|
+ //else {
|
|
|
+ // char strmsg[MAX_PATH] = { 0 };
|
|
|
+ // _snprintf(strmsg, MAX_PATH, "video rtp create success and local port is %d.", config->local_rtp_port);
|
|
|
+ // rtpLogevent(vrtp, 0, strmsg);
|
|
|
+ //}
|
|
|
|
|
|
{
|
|
|
VideoStatsLogCallBack log_func;
|
|
|
@@ -2146,7 +2141,7 @@ void videortp_destroy(videortp_t *vrtp)
|
|
|
}
|
|
|
config = &vrtp->config;
|
|
|
|
|
|
- rtpDbg(vrtp,"videortp_destroy.");
|
|
|
+ //rtpDbg(vrtp,"videortp_destroy.");
|
|
|
|
|
|
receiver_clear_window(vrtp);
|
|
|
while (!list_empty(&vrtp->free_part_list)) {
|
|
|
@@ -2166,11 +2161,11 @@ void videortp_destroy(videortp_t *vrtp)
|
|
|
rtp_session_get_local_rtp_port(vrtp->rtp_sess, &ilocal_port);
|
|
|
|
|
|
rtp_session_destroy(vrtp->rtp_sess);
|
|
|
- {
|
|
|
- char strInfo[MAX_PATH] = { 0 };
|
|
|
- snprintf(strInfo, MAX_PATH, "video rtp destroy and local port is %u.", ilocal_port);
|
|
|
- rtpLogevent(vrtp, 1, strInfo);
|
|
|
- }
|
|
|
+ //{
|
|
|
+ // char strmsg[MAX_PATH] = { 0 };
|
|
|
+ // _snprintf(strmsg, MAX_PATH, "video rtp destroy and local port is %u.", ilocal_port);
|
|
|
+ // rtpLogevent(vrtp, 1, strmsg);
|
|
|
+ //}
|
|
|
vrtp->rtp_sess = NULL;
|
|
|
|
|
|
if (config->dir & DIR_RX) {
|
|
|
@@ -2210,15 +2205,11 @@ int videortp_start(videortp_t *vrtp)
|
|
|
pthread_attr_setschedparam(&attr, ¶m);
|
|
|
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
|
|
|
int err = pthread_create(&vrtp->recv_threadid, NULL, recv_proc, vrtp);
|
|
|
- if (0 == err) {
|
|
|
- rtpDbg(vrtp,"create vrtp recv thread success, and thread id is %u.", vrtp->recv_threadid);
|
|
|
- }
|
|
|
- else {
|
|
|
+ if (0 != err) {
|
|
|
rtpDbg(vrtp,"create vrtp recv thread failed for %s.", strerror(errno));
|
|
|
}
|
|
|
#endif
|
|
|
}
|
|
|
- rtpDbg(vrtp,"videortp_start.");
|
|
|
|
|
|
receiver_config_stats.remote_pt = vrtp->config.remote_pt;
|
|
|
receiver_config_stats.local_ip = vrtp->config.local_ip;
|
|
|
@@ -2247,7 +2238,7 @@ int videortp_start(videortp_t *vrtp)
|
|
|
void videortp_stop(videortp_t* vrtp)
|
|
|
{
|
|
|
int64_t now = TimeInMilliseconds();
|
|
|
- rtpDbg(vrtp,"%s:%d start call videortp_stop.", __FUNCTION__, __LINE__);
|
|
|
+ //rtpDbg(vrtp,"start call videortp_stop.");
|
|
|
#ifdef _WIN32
|
|
|
if (vrtp->evt) {
|
|
|
SetEvent(vrtp->evt);
|
|
|
@@ -2264,7 +2255,6 @@ void videortp_stop(videortp_t* vrtp)
|
|
|
sem_post(&vrtp->sem_evt);
|
|
|
if (0 != vrtp->recv_threadid) {
|
|
|
if (0 == pthread_join(vrtp->recv_threadid, NULL)){
|
|
|
- rtpDbg(vrtp, "%s:%d vrtp receive thread %u thread join success.", __FUNCTION__, __LINE__, vrtp->recv_threadid);
|
|
|
vrtp->recv_threadid = 0;
|
|
|
}
|
|
|
else {
|
|
|
@@ -2275,13 +2265,10 @@ void videortp_stop(videortp_t* vrtp)
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
- rtpDbg(vrtp,"%s:%d stop rtp recv thread.", __FUNCTION__, __LINE__);
|
|
|
-
|
|
|
video_stats_receiver_on_stopped(now);
|
|
|
video_stats_sender_on_stopped(now);
|
|
|
+
|
|
|
video_jbuffer_api_stop(vrtp->jbuffer);
|
|
|
-
|
|
|
- rtpDbg(vrtp,"%s:%d videortp_stop func end.", __FUNCTION__, __LINE__);
|
|
|
}
|
|
|
|
|
|
int videortp_send_frame(videortp_t *vrtp, const video_frame *frame)
|
|
|
@@ -2290,7 +2277,7 @@ int videortp_send_frame(videortp_t *vrtp, const video_frame *frame)
|
|
|
int64_t now;
|
|
|
|
|
|
if(DEBUG_TX){
|
|
|
- rtpDbg(vrtp,"%s:%d: videortp_send_frame width: %d height: %d format: %d.", __FILE__, __LINE__, frame->width, frame->height, frame->format);
|
|
|
+ rtpDbg(vrtp,"%s:%d: videortp_send_frame width: %d height: %d format: %d.", __FILE__, __LINE__, frame->width, frame->height, frame->format);
|
|
|
}
|
|
|
|
|
|
if (VIDEO_FORMAT_RGB24 != frame->format)
|
|
|
@@ -2308,8 +2295,7 @@ int videortp_send_frame(videortp_t *vrtp, const video_frame *frame)
|
|
|
vrtp->force_key_frames = 0;
|
|
|
|
|
|
if(DEBUG_TX){
|
|
|
- rtpDbg(vrtp,"%s:%d: videortp_send_frame force_key_frames.", __FILE__, __LINE__);
|
|
|
-
|
|
|
+ rtpDbg(vrtp,"%s:%d: videortp_send_frame force_key_frames.", __FILE__, __LINE__);
|
|
|
}
|
|
|
}
|
|
|
//在编码器中固定i帧间隔为2s,不再需要自己主动设置了
|
|
|
@@ -2322,7 +2308,7 @@ int videortp_send_frame(videortp_t *vrtp, const video_frame *frame)
|
|
|
if (vrtp->framenum % start_key_interval == 0) {
|
|
|
video_encoder_api_send_key_frame(vrtp->encoder);
|
|
|
if(DEBUG_TX){
|
|
|
- rtpDbg(vrtp,"%s:%d: videortp_send_frame framenum: %d force_key_frames.", __FILE__, __LINE__, vrtp->framenum);
|
|
|
+ rtpDbg(vrtp,"%s:%d: videortp_send_frame framenum: %d force_key_frames.", __FILE__, __LINE__, vrtp->framenum);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -2363,9 +2349,9 @@ int videortp_send_yuvframe(videortp_t *vrtp, const video_frame *vframe)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int videortp_reconfig_local_pt(videortp_t *vrtp, unsigned int local_pt){
|
|
|
- rtpDbg(vrtp,"videortp_reconfig_local_pt:%u .", local_pt);
|
|
|
-
|
|
|
+int videortp_reconfig_local_pt(videortp_t *vrtp, unsigned int local_pt)
|
|
|
+{
|
|
|
+ //rtpDbg(vrtp,"videortp_reconfig_local_pt:%u .", local_pt);
|
|
|
vrtp->config.local_pt = local_pt;
|
|
|
}
|
|
|
|