提交 3412a0e1 编写于 作者: J jp9000

obs-outputs: Wait for packet before header output

Waiting for the first packet to arrive before sending the headers helps
prevent issues with certain types of encoders that may not get their
header/SEI until the first packet has been received.
上级 1a95004f
......@@ -36,6 +36,7 @@ struct flv_output {
struct dstr path;
FILE *file;
bool active;
bool sent_headers;
int64_t last_packet_ts;
};
......@@ -176,7 +177,6 @@ static bool flv_output_start(void *data)
/* write headers and start capture */
stream->active = true;
write_headers(stream);
obs_output_begin_data_capture(stream->output, 0);
info("Writing FLV file '%s'...", stream->path.array);
......@@ -188,6 +188,11 @@ static void flv_output_data(void *data, struct encoder_packet *packet)
struct flv_output *stream = data;
struct encoder_packet parsed_packet;
if (!stream->sent_headers) {
write_headers(stream);
stream->sent_headers = true;
}
if (packet->type == OBS_ENCODER_VIDEO) {
obs_parse_avc_packet(&parsed_packet, packet);
write_packet(stream, &parsed_packet, false);
......
......@@ -43,6 +43,7 @@ struct rtmp_stream {
pthread_mutex_t packets_mutex;
struct circlebuf packets;
bool sent_headers;
bool connecting;
pthread_t connect_thread;
......@@ -155,6 +156,8 @@ static void rtmp_stream_stop(void *data)
}
os_event_reset(stream->stop_event);
stream->sent_headers = false;
}
static inline void set_rtmp_str(AVal *val, const char *str)
......@@ -207,10 +210,15 @@ static int send_packet(struct rtmp_stream *stream,
return ret;
}
static inline void send_headers(struct rtmp_stream *stream);
static bool send_remaining_packets(struct rtmp_stream *stream)
{
struct encoder_packet packet;
if (!stream->sent_headers)
send_headers(stream);
while (get_next_packet(stream, &packet))
if (send_packet(stream, &packet, false) < 0)
return false;
......@@ -230,6 +238,10 @@ static void *send_thread(void *data)
break;
if (!get_next_packet(stream, &packet))
continue;
if (!stream->sent_headers)
send_headers(stream);
if (send_packet(stream, &packet, false) < 0) {
disconnected = true;
break;
......@@ -299,9 +311,9 @@ static void send_video_header(struct rtmp_stream *stream)
send_packet(stream, &packet, true);
}
static void send_headers(struct rtmp_stream *stream)
static inline void send_headers(struct rtmp_stream *stream)
{
send_meta_data(stream);
stream->sent_headers = true;
send_audio_header(stream);
send_video_header(stream);
}
......@@ -351,7 +363,7 @@ static int init_send(struct rtmp_stream *stream)
}
stream->active = true;
send_headers(stream);
send_meta_data(stream);
obs_output_begin_data_capture(stream->output, 0);
return OBS_OUTPUT_SUCCESS;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册