浏览代码

obs-output: Add ability to get congestion to rtmp output

jp9000 8 年之前
父节点
当前提交
5c27ab8d87
共有 1 个文件被更改,包括 17 次插入1 次删除
  1. 17 1
      plugins/obs-outputs/rtmp-stream.c

+ 17 - 1
plugins/obs-outputs/rtmp-stream.c

@@ -91,6 +91,7 @@ struct rtmp_stream {
 	int64_t          pframe_drop_threshold_usec;
 	int64_t          pframe_min_drop_dts_usec;
 	int              min_priority;
+	float            congestion;
 
 	int64_t          last_dts_usec;
 
@@ -883,8 +884,11 @@ static void check_to_drop_frames(struct rtmp_stream *stream, bool pframes)
 		stream->pframe_drop_threshold_usec :
 		stream->drop_threshold_usec;
 
-	if (num_packets < 5)
+	if (num_packets < 5) {
+		if (!pframes)
+			stream->congestion = 0.0f;
 		return;
+	}
 
 	circlebuf_peek_front(&stream->packets, &first, sizeof(first));
 
@@ -896,6 +900,11 @@ static void check_to_drop_frames(struct rtmp_stream *stream, bool pframes)
 	 * sent is higher than threshold, drop frames */
 	buffer_duration_usec = stream->last_dts_usec - first.dts_usec;
 
+	if (!pframes) {
+		stream->congestion = (float)buffer_duration_usec /
+			(float)drop_threshold;
+	}
+
 	if (buffer_duration_usec > drop_threshold) {
 		debug("buffer_duration_usec: %" PRId64, buffer_duration_usec);
 		drop_frames(stream, name, priority, p_min_dts_usec);
@@ -998,6 +1007,12 @@ static int rtmp_stream_dropped_frames(void *data)
 	return stream->dropped_frames;
 }
 
+static float rtmp_stream_congestion(void *data)
+{
+	struct rtmp_stream *stream = data;
+	return stream->min_priority > 0 ? 1.0f : stream->congestion;
+}
+
 struct obs_output_info rtmp_output_info = {
 	.id                 = "rtmp_output",
 	.flags              = OBS_OUTPUT_AV |
@@ -1013,5 +1028,6 @@ struct obs_output_info rtmp_output_info = {
 	.get_defaults       = rtmp_stream_defaults,
 	.get_properties     = rtmp_stream_properties,
 	.get_total_bytes    = rtmp_stream_total_bytes_sent,
+	.get_congestion     = rtmp_stream_congestion,
 	.get_dropped_frames = rtmp_stream_dropped_frames
 };