libobs/media-io: Fix leaks and error handling
This commit is contained in:
parent
8075e8bb65
commit
0c208f1e62
@ -354,7 +354,6 @@ static inline bool valid_audio_params(const struct audio_output_info *info)
|
|||||||
int audio_output_open(audio_t **audio, struct audio_output_info *info)
|
int audio_output_open(audio_t **audio, struct audio_output_info *info)
|
||||||
{
|
{
|
||||||
struct audio_output *out;
|
struct audio_output *out;
|
||||||
pthread_mutexattr_t attr;
|
|
||||||
bool planar = is_audio_planar(info->format);
|
bool planar = is_audio_planar(info->format);
|
||||||
|
|
||||||
if (!valid_audio_params(info))
|
if (!valid_audio_params(info))
|
||||||
@ -362,7 +361,7 @@ int audio_output_open(audio_t **audio, struct audio_output_info *info)
|
|||||||
|
|
||||||
out = bzalloc(sizeof(struct audio_output));
|
out = bzalloc(sizeof(struct audio_output));
|
||||||
if (!out)
|
if (!out)
|
||||||
goto fail;
|
goto fail0;
|
||||||
|
|
||||||
memcpy(&out->info, info, sizeof(struct audio_output_info));
|
memcpy(&out->info, info, sizeof(struct audio_output_info));
|
||||||
out->channels = get_audio_channels(info->speakers);
|
out->channels = get_audio_channels(info->speakers);
|
||||||
@ -372,22 +371,22 @@ int audio_output_open(audio_t **audio, struct audio_output_info *info)
|
|||||||
out->block_size = (planar ? 1 : out->channels) *
|
out->block_size = (planar ? 1 : out->channels) *
|
||||||
get_audio_bytes_per_channel(info->format);
|
get_audio_bytes_per_channel(info->format);
|
||||||
|
|
||||||
if (pthread_mutexattr_init(&attr) != 0)
|
if (pthread_mutex_init_recursive(&out->input_mutex) != 0)
|
||||||
goto fail;
|
goto fail0;
|
||||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
|
||||||
goto fail;
|
|
||||||
if (pthread_mutex_init(&out->input_mutex, &attr) != 0)
|
|
||||||
goto fail;
|
|
||||||
if (os_event_init(&out->stop_event, OS_EVENT_TYPE_MANUAL) != 0)
|
if (os_event_init(&out->stop_event, OS_EVENT_TYPE_MANUAL) != 0)
|
||||||
goto fail;
|
goto fail1;
|
||||||
if (pthread_create(&out->thread, NULL, audio_thread, out) != 0)
|
if (pthread_create(&out->thread, NULL, audio_thread, out) != 0)
|
||||||
goto fail;
|
goto fail2;
|
||||||
|
|
||||||
out->initialized = true;
|
out->initialized = true;
|
||||||
*audio = out;
|
*audio = out;
|
||||||
return AUDIO_OUTPUT_SUCCESS;
|
return AUDIO_OUTPUT_SUCCESS;
|
||||||
|
|
||||||
fail:
|
fail2:
|
||||||
|
os_event_destroy(out->stop_event);
|
||||||
|
fail1:
|
||||||
|
pthread_mutex_destroy(&out->input_mutex);
|
||||||
|
fail0:
|
||||||
audio_output_close(out);
|
audio_output_close(out);
|
||||||
return AUDIO_OUTPUT_FAIL;
|
return AUDIO_OUTPUT_FAIL;
|
||||||
}
|
}
|
||||||
@ -402,6 +401,8 @@ void audio_output_close(audio_t *audio)
|
|||||||
if (audio->initialized) {
|
if (audio->initialized) {
|
||||||
os_event_signal(audio->stop_event);
|
os_event_signal(audio->stop_event);
|
||||||
pthread_join(audio->thread, &thread_ret);
|
pthread_join(audio->thread, &thread_ret);
|
||||||
|
os_event_destroy(audio->stop_event);
|
||||||
|
pthread_mutex_destroy(&audio->input_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t mix_idx = 0; mix_idx < MAX_AUDIO_MIXES; mix_idx++) {
|
for (size_t mix_idx = 0; mix_idx < MAX_AUDIO_MIXES; mix_idx++) {
|
||||||
@ -412,8 +413,6 @@ void audio_output_close(audio_t *audio)
|
|||||||
|
|
||||||
da_free(mix->inputs);
|
da_free(mix->inputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
os_event_destroy(audio->stop_event);
|
|
||||||
bfree(audio);
|
bfree(audio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,32 +225,27 @@ static inline void init_cache(struct video_output *video)
|
|||||||
int video_output_open(video_t **video, struct video_output_info *info)
|
int video_output_open(video_t **video, struct video_output_info *info)
|
||||||
{
|
{
|
||||||
struct video_output *out;
|
struct video_output *out;
|
||||||
pthread_mutexattr_t attr;
|
|
||||||
|
|
||||||
if (!valid_video_params(info))
|
if (!valid_video_params(info))
|
||||||
return VIDEO_OUTPUT_INVALIDPARAM;
|
return VIDEO_OUTPUT_INVALIDPARAM;
|
||||||
|
|
||||||
out = bzalloc(sizeof(struct video_output));
|
out = bzalloc(sizeof(struct video_output));
|
||||||
if (!out)
|
if (!out)
|
||||||
goto fail;
|
goto fail0;
|
||||||
|
|
||||||
memcpy(&out->info, info, sizeof(struct video_output_info));
|
memcpy(&out->info, info, sizeof(struct video_output_info));
|
||||||
out->frame_time =
|
out->frame_time =
|
||||||
util_mul_div64(1000000000ULL, info->fps_den, info->fps_num);
|
util_mul_div64(1000000000ULL, info->fps_den, info->fps_num);
|
||||||
out->initialized = false;
|
out->initialized = false;
|
||||||
|
|
||||||
if (pthread_mutexattr_init(&attr) != 0)
|
if (pthread_mutex_init_recursive(&out->data_mutex) != 0)
|
||||||
goto fail;
|
goto fail0;
|
||||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0)
|
if (pthread_mutex_init_recursive(&out->input_mutex) != 0)
|
||||||
goto fail;
|
goto fail1;
|
||||||
if (pthread_mutex_init(&out->data_mutex, &attr) != 0)
|
|
||||||
goto fail;
|
|
||||||
if (pthread_mutex_init(&out->input_mutex, &attr) != 0)
|
|
||||||
goto fail;
|
|
||||||
if (os_sem_init(&out->update_semaphore, 0) != 0)
|
if (os_sem_init(&out->update_semaphore, 0) != 0)
|
||||||
goto fail;
|
goto fail2;
|
||||||
if (pthread_create(&out->thread, NULL, video_thread, out) != 0)
|
if (pthread_create(&out->thread, NULL, video_thread, out) != 0)
|
||||||
goto fail;
|
goto fail3;
|
||||||
|
|
||||||
init_cache(out);
|
init_cache(out);
|
||||||
|
|
||||||
@ -258,7 +253,13 @@ int video_output_open(video_t **video, struct video_output_info *info)
|
|||||||
*video = out;
|
*video = out;
|
||||||
return VIDEO_OUTPUT_SUCCESS;
|
return VIDEO_OUTPUT_SUCCESS;
|
||||||
|
|
||||||
fail:
|
fail3:
|
||||||
|
os_sem_destroy(out->update_semaphore);
|
||||||
|
fail2:
|
||||||
|
pthread_mutex_destroy(&out->input_mutex);
|
||||||
|
fail1:
|
||||||
|
pthread_mutex_destroy(&out->data_mutex);
|
||||||
|
fail0:
|
||||||
video_output_close(out);
|
video_output_close(out);
|
||||||
return VIDEO_OUTPUT_FAIL;
|
return VIDEO_OUTPUT_FAIL;
|
||||||
}
|
}
|
||||||
@ -277,9 +278,6 @@ void video_output_close(video_t *video)
|
|||||||
for (size_t i = 0; i < video->info.cache_size; i++)
|
for (size_t i = 0; i < video->info.cache_size; i++)
|
||||||
video_frame_free((struct video_frame *)&video->cache[i]);
|
video_frame_free((struct video_frame *)&video->cache[i]);
|
||||||
|
|
||||||
os_sem_destroy(video->update_semaphore);
|
|
||||||
pthread_mutex_destroy(&video->data_mutex);
|
|
||||||
pthread_mutex_destroy(&video->input_mutex);
|
|
||||||
bfree(video);
|
bfree(video);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,6 +508,9 @@ void video_output_stop(video_t *video)
|
|||||||
video->stop = true;
|
video->stop = true;
|
||||||
os_sem_post(video->update_semaphore);
|
os_sem_post(video->update_semaphore);
|
||||||
pthread_join(video->thread, &thread_ret);
|
pthread_join(video->thread, &thread_ret);
|
||||||
|
os_sem_destroy(video->update_semaphore);
|
||||||
|
pthread_mutex_destroy(&video->data_mutex);
|
||||||
|
pthread_mutex_destroy(&video->input_mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user