Skip to content

Commit

Permalink
RTSP threads must not be too preemptive to delay other modules and in…
Browse files Browse the repository at this point in the history
…duce stuttering on IDR generation
  • Loading branch information
wberube committed Oct 25, 2024
1 parent affcbfe commit d326690
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) {
start_server();

if (app_config.rtsp_enable) {
rtspHandle = rtsp_create(RTSP_MAXIMUM_CONNECTIONS, 2);
rtspHandle = rtsp_create(RTSP_MAXIMUM_CONNECTIONS, 1);
HAL_INFO("rtsp", "Started listening for clients...\n");
}

Expand Down
57 changes: 32 additions & 25 deletions src/media.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,31 +356,38 @@ int enable_audio(void) {
pcmSamp = shine_samples_per_pass(mp3Enc);
}

pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
size_t stacksize;
pthread_attr_getstacksize(&thread_attr, &stacksize);
size_t new_stacksize = 16384;
if (pthread_attr_setstacksize(&thread_attr, new_stacksize))
HAL_DANGER("media", "Can't set stack size %zu\n", new_stacksize);
if (pthread_create(
&audPid, &thread_attr, (void *(*)(void *))aud_thread, NULL)) {
HAL_ERROR("media", "Starting the audio capture thread failed!\n");
}
if (pthread_attr_setstacksize(&thread_attr, stacksize))
HAL_DANGER("media", "Can't set stack size %zu\n", stacksize);
pthread_attr_destroy(&thread_attr);

pthread_attr_init(&thread_attr);
pthread_attr_getstacksize(&thread_attr, &stacksize);
if (pthread_attr_setstacksize(&thread_attr, new_stacksize))
HAL_DANGER("media", "Can't set stack size %zu\n", new_stacksize);
if (pthread_create(
&aencPid, &thread_attr, (void *(*)(void *))aenc_thread, NULL))
HAL_ERROR("media", "Starting the audio encoding thread failed!\n");
if (pthread_attr_setstacksize(&thread_attr, stacksize))
HAL_DANGER("media", "Can't set stack size %zu\n", stacksize);
pthread_attr_destroy(&thread_attr);
{
pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
size_t stacksize;
pthread_attr_getstacksize(&thread_attr, &stacksize);
size_t new_stacksize = 16384;
if (pthread_attr_setstacksize(&thread_attr, new_stacksize))
HAL_DANGER("media", "Can't set stack size %zu\n", new_stacksize);
if (pthread_create(
&audPid, &thread_attr, (void *(*)(void *))aud_thread, NULL)) {
HAL_ERROR("media", "Starting the audio capture thread failed!\n");
}
if (pthread_attr_setstacksize(&thread_attr, stacksize))
HAL_DANGER("media", "Can't set stack size %zu\n", stacksize);
pthread_attr_destroy(&thread_attr);
}

{
pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
size_t stacksize;
pthread_attr_getstacksize(&thread_attr, &stacksize);
size_t new_stacksize = 16384;
if (pthread_attr_setstacksize(&thread_attr, new_stacksize))
HAL_DANGER("media", "Can't set stack size %zu\n", new_stacksize);
if (pthread_create(
&aencPid, &thread_attr, (void *(*)(void *))aenc_thread, NULL))
HAL_ERROR("media", "Starting the audio encoding thread failed!\n");
if (pthread_attr_setstacksize(&thread_attr, stacksize))
HAL_DANGER("media", "Can't set stack size %zu\n", stacksize);
pthread_attr_destroy(&thread_attr);
}

return ret;
}
Expand Down

0 comments on commit d326690

Please sign in to comment.