Skip to content

Commit

Permalink
RTMP: Do not response publish start message if hooks fail.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 23, 2024
1 parent 5eb802d commit 319ace2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 42 deletions.
5 changes: 5 additions & 0 deletions trunk/src/app/srs_app_rtmp_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,11 @@ srs_error_t SrsRtmpConn::do_publishing(SrsLiveSource* source, SrsPublishRecvThre
->attr("timeout", srs_fmt("%d", srsu2msi(publish_normal_timeout)))->end();
SrsAutoFree(ISrsApmSpan, span);
#endif

// Response the start publishing message, let client start to publish messages.
if ((err = rtmp->start_publishing(info->res->stream_id)) != srs_success) {
return srs_error_wrap(err, "start publishing");
}

int64_t nb_msgs = 0;
uint64_t nb_frames = 0;
Expand Down
63 changes: 21 additions & 42 deletions trunk/src/protocol/srs_protocol_rtmp_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,7 @@ srs_error_t SrsRtmpServer::on_play_client_pause(int stream_id, bool is_pause)
srs_error_t SrsRtmpServer::start_fmle_publish(int stream_id)
{
srs_error_t err = srs_success;

// FCPublish
double fc_publish_tid = 0;
if (true) {
Expand All @@ -2651,10 +2651,10 @@ srs_error_t SrsRtmpServer::start_fmle_publish(int stream_id)
if ((err = expect_message<SrsFMLEStartPacket>(&msg, &pkt)) != srs_success) {
return srs_error_wrap(err, "recv FCPublish");
}

SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsFMLEStartPacket, pkt);

fc_publish_tid = pkt->transaction_id;
}
// FCPublish response
Expand All @@ -2664,7 +2664,7 @@ srs_error_t SrsRtmpServer::start_fmle_publish(int stream_id)
return srs_error_wrap(err, "send FCPublish response");
}
}

// createStream
double create_stream_tid = 0;
if (true) {
Expand All @@ -2673,10 +2673,10 @@ srs_error_t SrsRtmpServer::start_fmle_publish(int stream_id)
if ((err = expect_message<SrsCreateStreamPacket>(&msg, &pkt)) != srs_success) {
return srs_error_wrap(err, "recv createStream");
}

SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsCreateStreamPacket, pkt);

create_stream_tid = pkt->transaction_id;
}
// createStream response
Expand All @@ -2686,44 +2686,31 @@ srs_error_t SrsRtmpServer::start_fmle_publish(int stream_id)
return srs_error_wrap(err, "send createStream response");
}
}

// publish
if (true) {
SrsCommonMessage* msg = NULL;
SrsPublishPacket* pkt = NULL;
if ((err = expect_message<SrsPublishPacket>(&msg, &pkt)) != srs_success) {
return srs_error_wrap(err, "recv publish");
}

SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsPublishPacket, pkt);
}
// publish response onFCPublish(NetStream.Publish.Start)
if (true) {
SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket();

pkt->command_name = RTMP_AMF0_COMMAND_ON_FC_PUBLISH;
pkt->data->set(StatusCode, SrsAmf0Any::str(StatusCodePublishStart));
pkt->data->set(StatusDescription, SrsAmf0Any::str("Started publishing stream."));

if ((err = protocol->send_and_free_packet(pkt, stream_id)) != srs_success) {
return srs_error_wrap(err, "send NetStream.Publish.Start");
}
}
// publish response onStatus(NetStream.Publish.Start)
if (true) {
SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket();

pkt->data->set(StatusLevel, SrsAmf0Any::str(StatusLevelStatus));
pkt->data->set(StatusCode, SrsAmf0Any::str(StatusCodePublishStart));
pkt->data->set(StatusDescription, SrsAmf0Any::str("Started publishing stream."));
pkt->data->set(StatusClientId, SrsAmf0Any::str(RTMP_SIG_CLIENT_ID));


if ((err = protocol->send_and_free_packet(pkt, stream_id)) != srs_success) {
return srs_error_wrap(err, "send NetStream.Publish.Start");
}
}

return err;
}

Expand Down Expand Up @@ -2756,20 +2743,6 @@ srs_error_t SrsRtmpServer::start_haivision_publish(int stream_id)
}
}

// publish response onStatus(NetStream.Publish.Start)
if (true) {
SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket();

pkt->data->set(StatusLevel, SrsAmf0Any::str(StatusLevelStatus));
pkt->data->set(StatusCode, SrsAmf0Any::str(StatusCodePublishStart));
pkt->data->set(StatusDescription, SrsAmf0Any::str("Started publishing stream."));
pkt->data->set(StatusClientId, SrsAmf0Any::str(RTMP_SIG_CLIENT_ID));

if ((err = protocol->send_and_free_packet(pkt, stream_id)) != srs_success) {
return srs_error_wrap(err, "send NetStream.Publish.Start");
}
}

return err;
}

Expand Down Expand Up @@ -2816,21 +2789,27 @@ srs_error_t SrsRtmpServer::fmle_unpublish(int stream_id, double unpublish_tid)
srs_error_t SrsRtmpServer::start_flash_publish(int stream_id)
{
srs_error_t err = srs_success;

return err;
}

srs_error_t SrsRtmpServer::start_publishing(int stream_id)
{
srs_error_t err = srs_success;

// publish response onStatus(NetStream.Publish.Start)
if (true) {
SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket();

pkt->data->set(StatusLevel, SrsAmf0Any::str(StatusLevelStatus));
pkt->data->set(StatusCode, SrsAmf0Any::str(StatusCodePublishStart));
pkt->data->set(StatusDescription, SrsAmf0Any::str("Started publishing stream."));
pkt->data->set(StatusClientId, SrsAmf0Any::str(RTMP_SIG_CLIENT_ID));

if ((err = protocol->send_and_free_packet(pkt, stream_id)) != srs_success) {
return srs_error_wrap(err, "send NetStream.Publish.Start");
}
}

return err;
}

Expand Down
4 changes: 4 additions & 0 deletions trunk/src/protocol/srs_protocol_rtmp_stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ class SrsRtmpServer
// When client type is publish, response with packets:
// onStatus(NetStream.Publish.Start)
virtual srs_error_t start_flash_publish(int stream_id);
// Response the start publishing message after hooks verified. To stop reconnecting of
// OBS when publish failed, we should never send the onStatus(NetStream.Publish.Start)
// message before failure caused by hooks. See https://github.com/ossrs/srs/issues/4037
virtual srs_error_t start_publishing(int stream_id);
public:
// Expect a specified message, drop others util got specified one.
// @pmsg, user must free it. NULL if not success.
Expand Down

0 comments on commit 319ace2

Please sign in to comment.