mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 14:03:11 -07:00
Make Stream Connection better stoppable
This commit is contained in:
parent
99fb690ad7
commit
5d9f114e01
2 changed files with 20 additions and 16 deletions
|
@ -142,6 +142,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_session_stop(ChiakiSession *session)
|
||||||
chiaki_stop_pipe_stop(&session->stop_pipe);
|
chiaki_stop_pipe_stop(&session->stop_pipe);
|
||||||
chiaki_cond_signal(&session->state_cond);
|
chiaki_cond_signal(&session->state_cond);
|
||||||
|
|
||||||
|
chiaki_stream_connection_stop(&session->stream_connection);
|
||||||
|
|
||||||
chiaki_mutex_unlock(&session->state_mutex);
|
chiaki_mutex_unlock(&session->state_mutex);
|
||||||
return CHIAKI_ERR_SUCCESS;
|
return CHIAKI_ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -285,19 +287,14 @@ static void *session_thread_func(void *arg)
|
||||||
QUIT(quit_audio_receiver);
|
QUIT(quit_audio_receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chiaki_mutex_unlock(&session->state_mutex);
|
||||||
err = chiaki_stream_connection_run(&session->stream_connection);
|
err = chiaki_stream_connection_run(&session->stream_connection);
|
||||||
if(err != CHIAKI_ERR_SUCCESS)
|
chiaki_mutex_lock(&session->state_mutex);
|
||||||
{
|
if(err != CHIAKI_ERR_SUCCESS && err != CHIAKI_ERR_CANCELED)
|
||||||
CHIAKI_LOGE(&session->log, "StreamConnection run failed");
|
CHIAKI_LOGE(&session->log, "StreamConnection run failed");
|
||||||
QUIT(quit_stream_connection);
|
else
|
||||||
}
|
CHIAKI_LOGI(&session->log, "StreamConnection completed successfully");
|
||||||
|
|
||||||
CHIAKI_LOGI(&session->log, "StreamConnection completed successfully");
|
|
||||||
|
|
||||||
quit_stream_connection:
|
|
||||||
chiaki_stream_connection_fini(&session->stream_connection);
|
|
||||||
|
|
||||||
quit_video_receiver:
|
|
||||||
chiaki_video_receiver_free(session->video_receiver);
|
chiaki_video_receiver_free(session->video_receiver);
|
||||||
session->video_receiver = NULL;
|
session->video_receiver = NULL;
|
||||||
|
|
||||||
|
@ -318,6 +315,7 @@ quit:
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
#undef CHECK_STOP
|
#undef CHECK_STOP
|
||||||
|
#undef QUIT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,13 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
|
||||||
err = chiaki_mutex_lock(&stream_connection->state_mutex);
|
err = chiaki_mutex_lock(&stream_connection->state_mutex);
|
||||||
assert(err == CHIAKI_ERR_SUCCESS);
|
assert(err == CHIAKI_ERR_SUCCESS);
|
||||||
|
|
||||||
|
#define CHECK_STOP(quit_label) do { \
|
||||||
|
if(stream_connection->should_stop) \
|
||||||
|
{ \
|
||||||
|
session->quit_reason = CHIAKI_QUIT_REASON_STOPPED; \
|
||||||
|
goto quit_label; \
|
||||||
|
} } while(0)
|
||||||
|
|
||||||
stream_connection->state = STATE_TAKION_CONNECT;
|
stream_connection->state = STATE_TAKION_CONNECT;
|
||||||
stream_connection->state_finished = false;
|
stream_connection->state_finished = false;
|
||||||
stream_connection->state_failed = false;
|
stream_connection->state_failed = false;
|
||||||
|
@ -154,10 +161,9 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: timeout?
|
err = chiaki_cond_timedwait_pred(&stream_connection->state_cond, &stream_connection->state_mutex, EXPECT_TIMEOUT_MS, state_finished_cond_check, stream_connection);
|
||||||
err = chiaki_cond_wait_pred(&stream_connection->state_cond, &stream_connection->state_mutex, state_finished_cond_check, stream_connection);
|
|
||||||
assert(err == CHIAKI_ERR_SUCCESS || err == CHIAKI_ERR_TIMEOUT);
|
assert(err == CHIAKI_ERR_SUCCESS || err == CHIAKI_ERR_TIMEOUT);
|
||||||
// TODO: check stop
|
CHECK_STOP(close_takion);
|
||||||
if(err != CHIAKI_ERR_SUCCESS)
|
if(err != CHIAKI_ERR_SUCCESS)
|
||||||
{
|
{
|
||||||
CHIAKI_LOGE(&session->log, "StreamConnection Takion connect failed");
|
CHIAKI_LOGE(&session->log, "StreamConnection Takion connect failed");
|
||||||
|
@ -178,14 +184,13 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
|
||||||
|
|
||||||
err = chiaki_cond_timedwait_pred(&stream_connection->state_cond, &stream_connection->state_mutex, EXPECT_TIMEOUT_MS, state_finished_cond_check, stream_connection);
|
err = chiaki_cond_timedwait_pred(&stream_connection->state_cond, &stream_connection->state_mutex, EXPECT_TIMEOUT_MS, state_finished_cond_check, stream_connection);
|
||||||
assert(err == CHIAKI_ERR_SUCCESS || err == CHIAKI_ERR_TIMEOUT);
|
assert(err == CHIAKI_ERR_SUCCESS || err == CHIAKI_ERR_TIMEOUT);
|
||||||
|
CHECK_STOP(disconnect);
|
||||||
|
|
||||||
if(!stream_connection->state_finished)
|
if(!stream_connection->state_finished)
|
||||||
{
|
{
|
||||||
if(err == CHIAKI_ERR_TIMEOUT)
|
if(err == CHIAKI_ERR_TIMEOUT)
|
||||||
CHIAKI_LOGE(&session->log, "StreamConnection bang receive timeout");
|
CHIAKI_LOGE(&session->log, "StreamConnection bang receive timeout");
|
||||||
|
|
||||||
// TODO: check canceled and don't report error
|
|
||||||
|
|
||||||
CHIAKI_LOGE(&session->log, "StreamConnection didn't receive bang or failed to handle it");
|
CHIAKI_LOGE(&session->log, "StreamConnection didn't receive bang or failed to handle it");
|
||||||
err = CHIAKI_ERR_UNKNOWN;
|
err = CHIAKI_ERR_UNKNOWN;
|
||||||
goto disconnect;
|
goto disconnect;
|
||||||
|
@ -198,6 +203,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
|
||||||
stream_connection->state_failed = false;
|
stream_connection->state_failed = false;
|
||||||
err = chiaki_cond_timedwait_pred(&stream_connection->state_cond, &stream_connection->state_mutex, EXPECT_TIMEOUT_MS, state_finished_cond_check, stream_connection);
|
err = chiaki_cond_timedwait_pred(&stream_connection->state_cond, &stream_connection->state_mutex, EXPECT_TIMEOUT_MS, state_finished_cond_check, stream_connection);
|
||||||
assert(err == CHIAKI_ERR_SUCCESS || err == CHIAKI_ERR_TIMEOUT);
|
assert(err == CHIAKI_ERR_SUCCESS || err == CHIAKI_ERR_TIMEOUT);
|
||||||
|
CHECK_STOP(disconnect);
|
||||||
|
|
||||||
if(!stream_connection->state_finished)
|
if(!stream_connection->state_finished)
|
||||||
{
|
{
|
||||||
|
@ -255,9 +261,9 @@ disconnect:
|
||||||
if(stream_connection->should_stop)
|
if(stream_connection->should_stop)
|
||||||
CHIAKI_LOGI(stream_connection->log, "StreamConnection was requested to stop");
|
CHIAKI_LOGI(stream_connection->log, "StreamConnection was requested to stop");
|
||||||
|
|
||||||
|
close_takion:
|
||||||
chiaki_mutex_unlock(&stream_connection->state_mutex);
|
chiaki_mutex_unlock(&stream_connection->state_mutex);
|
||||||
|
|
||||||
close_takion:
|
|
||||||
chiaki_takion_close(&stream_connection->takion);
|
chiaki_takion_close(&stream_connection->takion);
|
||||||
CHIAKI_LOGI(&session->log, "StreamConnection closed takion");
|
CHIAKI_LOGI(&session->log, "StreamConnection closed takion");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue