History

stream_blurary: consistently cleanup on error

Sometimes there was an immediate return on error and other times it destroyed things before returning the error. Make this consistent whenever something fails while we open. Also remove the destruct function since it is completely redundant with bluray_stream_close.

Dudemanguy committed 1 year ago

Commit affea091 parent e20e0001 file · +23 −15Browse files

Unified · Split

stream/stream_bluray.c+23−15
@@ -104,13 +104,6 @@ struct bluray_priv_s { · 103 unmodified lines
104 struct m_config_cache *opts_cache;104 struct m_config_cache *opts_cache;
105};105};
106 106
107static void destruct(struct bluray_priv_s *priv)
108{
109 if (priv->title_info)
110 bd_free_title_info(priv->title_info);
111 bd_close(priv->bd);
112}
113
114inline static int play_playlist(struct bluray_priv_s *priv, int playlist)107inline static int play_playlist(struct bluray_priv_s *priv, int playlist)
115{108{
116 return bd_select_playlist(priv->bd, playlist);109 return bd_select_playlist(priv->bd, playlist);
@@ -123,7 +116,14 @@ inline static int play_title(struct bluray_priv_s *priv, int title) · 6 unmodified lines
123 116
124static void bluray_stream_close(stream_t *s)117static void bluray_stream_close(stream_t *s)
125{118{
126 destruct(s->priv);119 struct bluray_priv_s *priv = s->priv;
120 if (!priv)
121 return;
122
123 if (priv->title_info)
124 bd_free_title_info(priv->title_info);
125 if (priv->bd)
126 bd_close(priv->bd);
127}127}
128 128
129static void handle_event(stream_t *s, const BD_EVENT *ev)129static void handle_event(stream_t *s, const BD_EVENT *ev)
@@ -408,6 +408,7 @@ static int bluray_stream_open_internal(stream_t *s) · 278 unmodified lines
408{408{
409 struct bluray_priv_s *b = s->priv;409 struct bluray_priv_s *b = s->priv;
410 410
411 int ret = 0;
411 char *device = NULL;412 char *device = NULL;
412 /* find the requested device */413 /* find the requested device */
413 if (b->cfg_device && b->cfg_device[0]) {414 if (b->cfg_device && b->cfg_device[0]) {
@@ -418,7 +419,8 @@ static int bluray_stream_open_internal(stream_t *s) · 4 unmodified lines
418 419
419 if (!device || !device[0]) {420 if (!device || !device[0]) {
420 MP_ERR(s, "No Blu-ray device/location was specified ...\n");421 MP_ERR(s, "No Blu-ray device/location was specified ...\n");
421 return STREAM_UNSUPPORTED;422 ret = STREAM_UNSUPPORTED;
423 goto err;
422 }424 }
423 425
424 if (!mp_msg_test(s->log, MSGL_DEBUG))426 if (!mp_msg_test(s->log, MSGL_DEBUG))
@@ -430,26 +432,28 @@ static int bluray_stream_open_internal(stream_t *s) · 5 unmodified lines
430 talloc_free(device_tmp);432 talloc_free(device_tmp);
431 if (!bd) {433 if (!bd) {
432 MP_ERR(s, "Couldn't open Blu-ray device: %s\n", device);434 MP_ERR(s, "Couldn't open Blu-ray device: %s\n", device);
433 return STREAM_UNSUPPORTED;435 ret = STREAM_UNSUPPORTED;
436 goto err;
434 }437 }
435 b->bd = bd;438 b->bd = bd;
436 439
437 if (!check_disc_info(s)) {440 if (!check_disc_info(s)) {
438 destruct(b);441 ret = STREAM_UNSUPPORTED;
439 return STREAM_UNSUPPORTED;442 goto err;
440 }443 }
441 444
442 int title_guess = BLURAY_DEFAULT_TITLE;445 int title_guess = BLURAY_DEFAULT_TITLE;
443 if (b->use_nav) {446 if (b->use_nav) {
444 MP_FATAL(s, "BluRay menu support has been removed.\n");447 MP_FATAL(s, "BluRay menu support has been removed.\n");
445 return STREAM_ERROR;448 ret = STREAM_ERROR;
449 goto err;
446 } else {450 } else {
447 /* check for available titles on disc */451 /* check for available titles on disc */
448 b->num_titles = bd_get_titles(bd, TITLES_RELEVANT, 0);452 b->num_titles = bd_get_titles(bd, TITLES_RELEVANT, 0);
449 if (!b->num_titles) {453 if (!b->num_titles) {
450 MP_ERR(s, "Can't find any Blu-ray-compatible title here.\n");454 MP_ERR(s, "Can't find any Blu-ray-compatible title here.\n");
451 destruct(b);455 ret = STREAM_UNSUPPORTED;
452 return STREAM_UNSUPPORTED;456 goto err;
453 }457 }
454 458
455 MP_INFO(s, "List of available titles:\n");459 MP_INFO(s, "List of available titles:\n");
@@ -494,6 +498,10 @@ static int bluray_stream_open_internal(stream_t *s) · 38 unmodified lines
494 MP_VERBOSE(s, "Blu-ray successfully opened.\n");498 MP_VERBOSE(s, "Blu-ray successfully opened.\n");
495 499
496 return STREAM_OK;500 return STREAM_OK;
501
502err:
503 bluray_stream_close(s);
504 return ret;
497}505}
498 506
499const stream_info_t stream_info_bdnav;507const stream_info_t stream_info_bdnav;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t