From 4b087df3abb37500712e34a9106054355c57a172 Mon Sep 17 00:00:00 2001 From: Moritz Grimm Date: Mon, 15 Jun 2015 08:04:57 +0200 Subject: [PATCH] Add plumbing for future encapsulation of libshout usage --- src/Makefile.am | 2 ++ src/ezstream.c | 9 ++++--- src/stream.c | 37 +++++++++++++++++++++++++++ src/stream.h | 23 +++++++++++++++++ tests/Makefile.am | 6 +++++ tests/check_stream.c | 60 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 src/stream.c create mode 100644 src/stream.h create mode 100644 tests/check_stream.c diff --git a/src/Makefile.am b/src/Makefile.am index dcb9568..f9aa525 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,7 @@ noinst_HEADERS = \ log.h \ metadata.h \ playlist.h \ + stream.h \ util.h \ xalloc.h libezstream_la_SOURCES = \ @@ -24,6 +25,7 @@ libezstream_la_SOURCES = \ log.c \ metadata.c \ playlist.c \ + stream.c \ util.c \ xalloc.c libezstream_la_DEPENDENCIES = \ diff --git a/src/ezstream.c b/src/ezstream.c index 1c5e47a..37cb715 100644 --- a/src/ezstream.c +++ b/src/ezstream.c @@ -32,6 +32,7 @@ #include "log.h" #include "metadata.h" #include "playlist.h" +#include "stream.h" #include "util.h" #include "xalloc.h" @@ -994,8 +995,7 @@ streamPlaylist(shout_t *shout) int ez_shutdown(int exitval) { - shout_shutdown(); - + stream_exit(); playlist_exit(); cfg_encoder_exit(); cfg_decoder_exit(); @@ -1017,6 +1017,7 @@ main(int argc, char *argv[]) struct sigaction act; unsigned int i; #endif + ret = 1; if (0 > cfg_init() || 0 > cmdline_parse(argc, argv, &ret) || @@ -1024,9 +1025,9 @@ main(int argc, char *argv[]) 0 > cfg_decoder_init() || 0 > cfg_encoder_init() || 0 > playlist_init() || - 0 > cfg_reload()) + 0 > cfg_reload() || + 0 > stream_init()) return (ez_shutdown(ret)); - shout_init(); if (0 > cfg_check(&errstr)) { log_error("%s: %s", cfg_get_program_config_file(), errstr); diff --git a/src/stream.c b/src/stream.c new file mode 100644 index 0000000..ff56d6b --- /dev/null +++ b/src/stream.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 Moritz Grimm + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include + +#include "cfg.h" +#include "stream.h" + +int +stream_init(void) +{ + shout_init(); + return (0); +} + +void +stream_exit(void) +{ + shout_shutdown(); +} diff --git a/src/stream.h b/src/stream.h new file mode 100644 index 0000000..2cc1676 --- /dev/null +++ b/src/stream.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2015 Moritz Grimm + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __STREAM_H__ +#define __STREAM_H__ + +int stream_init(void); +void stream_exit(void); + +#endif /* __STREAM_H__ */ diff --git a/tests/Makefile.am b/tests/Makefile.am index ffc2c15..3f04b4f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,6 +6,7 @@ TESTS = \ check_cmdline \ check_log \ check_playlist \ + check_stream \ check_xalloc check_PROGRAMS = $(TESTS) @@ -34,6 +35,11 @@ check_playlist_SOURCES = \ check_playlist_DEPENDENCIES = $(top_builddir)/src/libezstream.la check_playlist_LDADD = $(check_playlist_DEPENDENCIES) @CHECK_LIBS@ +check_stream_SOURCES = \ + check_stream.c +check_stream_DEPENDENCIES = $(top_builddir)/src/libezstream.la +check_stream_LDADD = $(check_stream_DEPENDENCIES) @CHECK_LIBS@ + check_xalloc_SOURCES = \ check_xalloc.c check_xalloc_DEPENDENCIES = $(top_builddir)/src/libezstream.la diff --git a/tests/check_stream.c b/tests/check_stream.c new file mode 100644 index 0000000..1e6000e --- /dev/null +++ b/tests/check_stream.c @@ -0,0 +1,60 @@ +#include + +#include "stream.h" + +Suite * stream_suite(void); +void setup_checked(void); +void teardown_checked(void); + +START_TEST(test_stream) +{ +} +END_TEST + +Suite * +stream_suite(void) +{ + Suite *s; + TCase *tc_stream; + + s = suite_create("Stream"); + + tc_stream = tcase_create("Stream"); + tcase_add_checked_fixture(tc_stream, setup_checked, teardown_checked); + tcase_add_test(tc_stream, test_stream); + suite_add_tcase(s, tc_stream); + + return (s); +} + +void +setup_checked(void) +{ + if (0 < stream_init()) + ck_abort_msg("setup_checked failed"); +} + +void +teardown_checked(void) +{ + stream_exit(); +} + +int +main(void) +{ + unsigned int num_failed; + Suite *s; + SRunner *sr; + + s = stream_suite(); + sr = srunner_create(s); + + srunner_run_all(sr, CK_NORMAL); + num_failed = srunner_ntests_failed(sr); + srunner_free(sr); + + if (num_failed) + return (1); + return (0); +}