Skip to content

Commit 66fa881

Browse files
committed
main: remove try-catch block
remove the try-block This should be a pure refactor, assuming that no-one throws. This should be true since @^{/noexcept} (last throws were directly in the try-block - replaced by exit_uv+goto).
1 parent 4a92c72 commit 66fa881

1 file changed

Lines changed: 59 additions & 73 deletions

File tree

src/main.cpp

Lines changed: 59 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,90 +1469,76 @@ int main(int argc, char *argv[])
14691469
#endif /* HAVE_SCHED_SETSCHEDULER */
14701470
#endif /* USE_RT */
14711471

1472-
try {
1473-
opt.video.capture_device = uv.capture_device; // iHDTV
1474-
opt.video.start_time = start_time; // RTP protocols
1475-
opt.video.display_device = uv.display_device; // UltraGrid RTP, iHDTV
1476-
// RTSP + SDP
1477-
opt.video.send_audio = strcmp("none", opt.audio.send_cfg) != 0;
1478-
opt.video.send_video =
1479-
strcmp("none", vidcap_params_get_driver(
1480-
opt.vidcap_params_head)) != 0;
1481-
1482-
uv.state_video_rxtx = video_rxtx::create(opt.video_protocol, &opt.video, &opt.common);
1483-
if (!uv.state_video_rxtx) {
1484-
if (strcmp(opt.video_protocol, "help") != 0) {
1485-
throw string("Requested RX/TX cannot be created (missing library?)");
1486-
} else {
1487-
throw 0;
1488-
}
1472+
opt.video.capture_device = uv.capture_device; // iHDTV
1473+
opt.video.start_time = start_time; // RTP protocols
1474+
opt.video.display_device = uv.display_device; // UltraGrid RTP, iHDTV
1475+
// RTSP + SDP
1476+
opt.video.send_audio = strcmp("none", opt.audio.send_cfg) != 0;
1477+
opt.video.send_video =
1478+
strcmp("none", vidcap_params_get_driver(opt.vidcap_params_head)) !=
1479+
0;
1480+
1481+
uv.state_video_rxtx =
1482+
video_rxtx::create(opt.video_protocol, &opt.video, &opt.common);
1483+
if (!uv.state_video_rxtx) {
1484+
int rc = EXIT_SUCCESS;
1485+
if (strcmp(opt.video_protocol, "help") != 0) {
1486+
error_msg("Requested RX/TX cannot be created "
1487+
"(missing library?)\n");
1488+
rc = EXIT_FAILURE;
14891489
}
1490+
exit_uv(rc);
1491+
goto cleanup;
1492+
}
14901493

1491-
opt.audio.vrxtx = uv.state_video_rxtx;
1492-
opt.audio.display = uv.display_device;
1493-
ret = audio_init(&uv.audio, &opt.audio, &opt.common);
1494-
if (ret != 0) {
1495-
exit_uv(ret < 0 ? EXIT_FAIL_AUDIO : 0);
1496-
goto cleanup;
1497-
}
1494+
opt.audio.vrxtx = uv.state_video_rxtx;
1495+
opt.audio.display = uv.display_device;
1496+
ret = audio_init(&uv.audio, &opt.audio, &opt.common);
1497+
if (ret != 0) {
1498+
exit_uv(ret < 0 ? EXIT_FAIL_AUDIO : 0);
1499+
goto cleanup;
1500+
}
14981501

1499-
if ((opt.video.rxtx_mode & MODE_RECEIVER) != 0U) {
1500-
if (!uv.state_video_rxtx->supports_receiving()) {
1501-
fprintf(stderr, "Selected RX/TX mode doesn't support receiving.\n");
1502-
exit_uv(EXIT_FAILURE);
1503-
goto cleanup;
1504-
}
1505-
// init module here so as it is capable of receiving messages
1506-
if (pthread_create
1507-
(&receiver_thread_id, NULL, video_rxtx::receiver_thread,
1508-
(void *) uv.state_video_rxtx) != 0) {
1509-
perror("Unable to create display thread!\n");
1510-
exit_uv(EXIT_FAILURE);
1511-
goto cleanup;
1512-
}
1502+
if ((opt.video.rxtx_mode & MODE_RECEIVER) != 0U) {
1503+
if (!uv.state_video_rxtx->supports_receiving()) {
1504+
fprintf(
1505+
stderr,
1506+
"Selected RX/TX mode doesn't support receiving.\n");
1507+
exit_uv(EXIT_FAILURE);
1508+
goto cleanup;
15131509
}
1514-
1515-
if ((opt.video.rxtx_mode & MODE_SENDER) != 0U) {
1516-
if (pthread_create
1517-
(&capture_thread_id, NULL, capture_thread,
1518-
(void *) &uv) != 0) {
1519-
perror("Unable to create capture thread!\n");
1520-
exit_uv(EXIT_FAILURE);
1521-
goto cleanup;
1522-
}
1510+
// init module here so as it is capable of receiving messages
1511+
if (pthread_create(&receiver_thread_id, NULL,
1512+
video_rxtx::receiver_thread,
1513+
(void *) uv.state_video_rxtx) != 0) {
1514+
perror("Unable to create display thread!\n");
1515+
exit_uv(EXIT_FAILURE);
1516+
goto cleanup;
15231517
}
1518+
}
15241519

1525-
if (opt.requested_capabilities != nullptr) {
1526-
print_capabilities(opt.requested_capabilities);
1527-
exit_uv(EXIT_SUCCESS);
1520+
if ((opt.video.rxtx_mode & MODE_SENDER) != 0U) {
1521+
if (pthread_create(&capture_thread_id, NULL, capture_thread,
1522+
(void *) &uv) != 0) {
1523+
perror("Unable to create capture thread!\n");
1524+
exit_uv(EXIT_FAILURE);
15281525
goto cleanup;
15291526
}
1527+
}
15301528

1531-
audio_start(uv.audio);
1532-
1533-
control_start(control);
1534-
kc.start();
1535-
1536-
display_run_mainloop(uv.display_device);
1537-
1538-
} catch (ug_no_error const &e) {
1539-
exit_uv(0);
1540-
} catch (ug_runtime_error const &e) {
1541-
LOG(LOG_LEVEL_ERROR) << e.what() << "\n";
1542-
exit_uv(e.get_code());
1543-
} catch (runtime_error const &e) {
1544-
LOG(LOG_LEVEL_ERROR) << e.what() << "\n";
1545-
exit_uv(EXIT_FAILURE);
1546-
} catch (exception const &e) {
1547-
LOG(LOG_LEVEL_ERROR) << e.what() << "\n";
1548-
exit_uv(EXIT_FAILURE);
1549-
} catch (string const &str) {
1550-
LOG(LOG_LEVEL_ERROR) << str << "\n";
1551-
exit_uv(EXIT_FAILURE);
1552-
} catch (int i) {
1553-
exit_uv(i);
1529+
if (opt.requested_capabilities != nullptr) {
1530+
print_capabilities(opt.requested_capabilities);
1531+
exit_uv(EXIT_SUCCESS);
1532+
goto cleanup;
15541533
}
15551534

1535+
audio_start(uv.audio);
1536+
1537+
control_start(control);
1538+
kc.start();
1539+
1540+
display_run_mainloop(uv.display_device);
1541+
15561542
cleanup:
15571543
if (!pthread_equal(receiver_thread_id, PTHREAD_NULL)) {
15581544
pthread_join(receiver_thread_id, NULL);

0 commit comments

Comments
 (0)