Skip to content

Commit 6e63d77

Browse files
committed
Protect title_list access with mutex
It doesn't make much sense to call hese functions in paraller, but doing so might cause some harm ...
1 parent 1f268d0 commit 6e63d77

File tree

1 file changed

+48
-20
lines changed

1 file changed

+48
-20
lines changed

src/libbluray/bluray.c

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,10 +2543,9 @@ int bd_play_playlist_at(BLURAY *bd, int playlist, int playitem, int playmark, in
25432543
// Select a title for playback
25442544
// The title index is an index into the list
25452545
// established by bd_get_titles()
2546-
int bd_select_title(BLURAY *bd, uint32_t title_idx)
2546+
static int _select_title(BLURAY *bd, uint32_t title_idx)
25472547
{
25482548
const char *f_name;
2549-
int result;
25502549

25512550
// Open the playlist
25522551
if (bd->title_list == NULL) {
@@ -2558,13 +2557,18 @@ int bd_select_title(BLURAY *bd, uint32_t title_idx)
25582557
return 0;
25592558
}
25602559

2561-
bd_mutex_lock(&bd->mutex);
2562-
25632560
bd->title_idx = title_idx;
25642561
f_name = bd->title_list->title_info[title_idx].name;
25652562

2566-
result = _open_playlist(bd, f_name, 0);
2563+
return _open_playlist(bd, f_name, 0);
2564+
}
2565+
2566+
int bd_select_title(BLURAY *bd, uint32_t title_idx)
2567+
{
2568+
int result;
25672569

2570+
bd_mutex_lock(&bd->mutex);
2571+
result = _select_title(bd, title_idx);
25682572
bd_mutex_unlock(&bd->mutex);
25692573

25702574
return result;
@@ -2646,38 +2650,55 @@ void bd_seamless_angle_change(BLURAY *bd, unsigned angle)
26462650

26472651
uint32_t bd_get_titles(BLURAY *bd, uint8_t flags, uint32_t min_title_length)
26482652
{
2653+
NAV_TITLE_LIST *title_list;
2654+
uint32_t count;
2655+
26492656
if (!bd) {
26502657
return 0;
26512658
}
26522659

2653-
nav_free_title_list(&bd->title_list);
2654-
bd->title_list = nav_get_title_list(bd->disc, flags, min_title_length);
2655-
2656-
if (!bd->title_list) {
2660+
title_list = nav_get_title_list(bd->disc, flags, min_title_length);
2661+
if (!title_list) {
26572662
BD_DEBUG(DBG_BLURAY | DBG_CRIT, "nav_get_title_list(%s) failed\n", disc_root(bd->disc));
26582663
return 0;
26592664
}
26602665

2666+
bd_mutex_lock(&bd->mutex);
2667+
2668+
nav_free_title_list(&bd->title_list);
2669+
bd->title_list = title_list;
2670+
26612671
disc_event(bd->disc, DISC_EVENT_START, bd->disc_info.num_titles);
2672+
count = bd->title_list->count;
2673+
2674+
bd_mutex_unlock(&bd->mutex);
26622675

2663-
return bd->title_list->count;
2676+
return count;
26642677
}
26652678

26662679
int bd_get_main_title(BLURAY *bd)
26672680
{
2681+
int main_title_idx = -1;
2682+
26682683
if (!bd) {
26692684
return -1;
26702685
}
2686+
2687+
bd_mutex_lock(&bd->mutex);
2688+
26712689
if (bd->title_type != title_undef) {
26722690
BD_DEBUG(DBG_CRIT | DBG_BLURAY, "bd_get_main_title() can't be used with BluRay menus\n");
26732691
}
26742692

26752693
if (bd->title_list == NULL) {
26762694
BD_DEBUG(DBG_BLURAY | DBG_CRIT, "Title list not yet read!\n");
2677-
return -1;
2695+
} else {
2696+
main_title_idx = bd->title_list->main_title_idx;
26782697
}
26792698

2680-
return bd->title_list->main_title_idx;
2699+
bd_mutex_unlock(&bd->mutex);
2700+
2701+
return main_title_idx;
26812702
}
26822703

26832704
static int _copy_streams(const NAV_CLIP *clip, BLURAY_STREAM_INFO **pstreams,
@@ -2828,19 +2849,26 @@ static BLURAY_TITLE_INFO *_get_title_info(BLURAY *bd, uint32_t title_idx, uint32
28282849

28292850
BLURAY_TITLE_INFO* bd_get_title_info(BLURAY *bd, uint32_t title_idx, unsigned angle)
28302851
{
2852+
char mpls_name[11] = "";
2853+
int mpls_id = -1;
2854+
2855+
bd_mutex_lock(&bd->mutex);
2856+
28312857
if (bd->title_list == NULL) {
28322858
BD_DEBUG(DBG_BLURAY | DBG_CRIT, "Title list not yet read!\n");
2833-
return NULL;
2834-
}
2835-
if (bd->title_list->count <= title_idx) {
2859+
} else if (bd->title_list->count <= title_idx) {
28362860
BD_DEBUG(DBG_BLURAY | DBG_CRIT, "Invalid title index %d!\n", title_idx);
2837-
return NULL;
2861+
} else {
2862+
mpls_id = bd->title_list->title_info[title_idx].mpls_id;
2863+
memcpy(mpls_name, bd->title_list->title_info[title_idx].name, 11);
28382864
}
28392865

2840-
return _get_title_info(bd,
2841-
title_idx, bd->title_list->title_info[title_idx].mpls_id,
2842-
bd->title_list->title_info[title_idx].name,
2843-
angle);
2866+
bd_mutex_unlock(&bd->mutex);
2867+
2868+
if (mpls_id < 0)
2869+
return NULL;
2870+
2871+
return _get_title_info(bd, title_idx, mpls_id, mpls_name, angle);
28442872
}
28452873

28462874
BLURAY_TITLE_INFO* bd_get_playlist_info(BLURAY *bd, uint32_t playlist, unsigned angle)

0 commit comments

Comments
 (0)