Commit 0a8d5813 authored by hark's avatar hark
Browse files

main in seperate file

parent f899ed1d
......@@ -27,20 +27,20 @@ all : c-player c-player-0.10 c-player-debug snowControl
c-player-0.10 : c-player.c
$(CC) -DTESTING -DGTK -g c-player.c wraps.c playlist.c snowbin.c teebin.c -o c-player-0.10 `pkg-config --cflags --libs gstreamer-interfaces-0.10 gstreamer-pbutils-0.10 gtk+-2.0 gstreamer-0.10` $(CFLAGS)
c-player-0.10 : c-player.c main.c
$(CC) -DSNOWBIN -DFP -DPL -DGTK -g main.c c-player.c wraps.c playlist.c snowbin.c teebin.c -o c-player-0.10 `pkg-config --cflags --libs gstreamer-interfaces-0.10 gstreamer-pbutils-0.10 gtk+-2.0 gstreamer-0.10` $(CFLAGS)
c-player-debug : c-player.c
$(CC) -DTT -DTESTING -DGTK -DGST1 -g c-player.c wraps.c playlist.c snowbin.c teebin.c -o c-player-debug `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
c-player-debug : main.c c-player.c
$(CC) -DTT -DTESTING -DGTK -DGST1 -g main.c c-player.c wraps.c playlist.c snowbin.c teebin.c -o c-player-debug `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
c-player-np : c-player.c snowbin.c teebin.c wraps.c common.h
$(CC) -DFP -DGTK -DGST1 -g c-player.c wraps.c snowbin.c teebin.c -o c-player-np `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
c-player-np : main.c c-player.c snowbin.c teebin.c wraps.c common.h
$(CC) -DGTK -DGST1 -g main.c c-player.c wraps.c snowbin.c teebin.c -o c-player-np `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
c-player : c-player.c snowbin.c playlist.c teebin.c wraps.c common.h playlist.h teebin.h
$(CC) -DSNOWBIN -DFP -DPL -DGTK -DGST1 -g c-player.c wraps.c playlist.c snowbin.c teebin.c -o c-player `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
c-player : main.c c-player.c snowbin.c playlist.c teebin.c wraps.c common.h playlist.h teebin.h
$(CC) -DSNOWBIN -DFP -DPL -DGTK -DGST1 -g main.c c-player.c wraps.c playlist.c snowbin.c teebin.c -o c-player `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
c-player-cli : c-player.c snowbin.c teebin.c wraps.c common.h
$(CC) -DGST1 -g c-player.c wraps.c snowbin.c teebin.c -o c-player-cli `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
c-player-cli : main.c c-player.c snowbin.c teebin.c wraps.c common.h
$(CC) -DGST1 -g main.c c-player.c wraps.c snowbin.c teebin.c -o c-player-cli `pkg-config --cflags --libs gtk+-2.0 gstreamer-1.0 gstreamer-pbutils-1.0 gstreamer-video-1.0` $(CFLAGS)
......
......@@ -62,7 +62,7 @@ GError *error = NULL;
#endif
static void cleanup( PlayerData * data) {
extern void player_cleanup( PlayerData * data) {
// this needs to be called from the main thread!
//global pData
......@@ -180,7 +180,7 @@ stop_cb (GtkButton * button, PlayerData * data)
#endif
static void
load_uri (const gchar * uri, PlayerData * data)
player_load_uri (const gchar * uri, PlayerData * data)
{
// this would stop playback, so don't do that
//gst_element_set_state (playerData.playbin2, GST_STATE_READY);
......@@ -225,7 +225,7 @@ preview_cb (GtkCheckButton * preview_check, PlayerData * data)
delete_event_cb (GtkWidget * widget, GdkEvent * event, PlayerData * data)
{
stop_cb (NULL, data);
cleanup (data);
player_cleanup (data);
}
/* This function is called everytime the video window needs to be redrawn (due to damage/exposure,
......@@ -272,8 +272,8 @@ slider_cb (GtkRange * range, PlayerData * data)
#ifdef GTK
/* This creates all the GTK+ widgets that compose our application, and registers the callbacks */
static void
create_ui (PlayerData * data)
extern void
player_create_ui (PlayerData * data)
{
char *markup;
PlayerGui *gui;
......@@ -407,7 +407,7 @@ thread_time = g_thread_create( thread_time_func, (gpointer)label_time, FALSE, &e
// pack the playlist
gtk_box_pack_start (GTK_BOX (gui->main_box), playlist_box, TRUE, TRUE, 0);
load_uri (playlist_get_current (), data);
player_load_uri (playlist_get_current (), data);
#endif
gtk_container_add (GTK_CONTAINER (main_window), gui->main_box);
gtk_window_set_default_size (GTK_WINDOW (main_window), 640, 480);
......@@ -419,8 +419,8 @@ thread_time = g_thread_create( thread_time_func, (gpointer)label_time, FALSE, &e
#ifdef GTK
/* This function is called periodically to refresh the GUI */
static int
refresh_ui (PlayerData * data)
extern int
player_refresh_ui (PlayerData * data)
{
auto GstFormat fmt = GST_FORMAT_TIME;
auto gint64 current = -1;
......@@ -497,7 +497,7 @@ player_reset_and_play (PlayerData *data)
#ifdef PL
// printf("current uri: %s", playlist_get_current());
load_uri(playlist_get_current(), pData);
player_load_uri(playlist_get_current(), pData);
#endif
int ret = 0;
/* Start playing */
......@@ -604,7 +604,7 @@ state_changed_cb (GstBus * bus, GstMessage * msg, PlayerData * data)
gst_message_parse_state_changed (msg, &old_state, &new_state,
&pending_state);
#ifdef GTK
refresh_ui(data);
player_refresh_ui(data);
#endif
if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data->playbin2))
{
......@@ -696,13 +696,13 @@ state_changed_cb (GstBus * bus, GstMessage * msg, PlayerData * data)
/* refresh ui to see if that makes position bar work ??? */
#ifdef GTK
refresh_ui (data);
player_refresh_ui (data);
#endif
if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED)
{
/* For extra responsiveness, we refresh the GUI as soon as we reach the PAUSED state */
#ifdef GTK
refresh_ui (data);
player_refresh_ui (data);
#endif
/* autoplay on loading new file? */
gst_element_set_state (data->playbin2, GST_STATE_PLAYING);
......@@ -863,7 +863,7 @@ application_cb (GstBus * bus, GstMessage * msg, PlayerData * data)
#endif
}
static void init_media(PlayerData *data)
extern void player_init_media(PlayerData *data)
{
GstBus *bus;
pData->duration = GST_CLOCK_TIME_NONE;
......@@ -943,171 +943,6 @@ static void init_media(PlayerData *data)
(GCallback) application_cb, pData);
gst_object_unref (bus);
}
static int signal_handler(PlayerData * data) {
printf(" \n Signal caught: %u \n ", 10);
cleanup(data);
}
int
main (int argc, char *argv[])
{
/* deal with command line arguments */
// feed, filename,
auto int opt = 0;
// auto int feedid = 1;
auto int audiosink = 23;
g_unix_signal_add(SIGUSR1, (GSourceFunc)signal_handler, pData);
g_unix_signal_add(SIGTERM, (GSourceFunc)signal_handler, pData);
g_unix_signal_add(SIGINT, (GSourceFunc)signal_handler, pData);
//test for valgrind
malloc(10);
// signal(15, signal_handler);
// signal(9, signal_handler);
// signal(15, signal_handler);
/*
if (signal(SIGTERM, signal_handler)) {
fputs("An error occurred while setting a signal handler.\n", stderr);
return EXIT_FAILURE;
}
*/
/* Initialize our global data structures */
pData = (PlayerData*)malloc(sizeof(struct PlayerData));
#ifdef SNOWBIN
snowbin_init_snowData(pData);
#endif
while ((opt = getopt (argc, argv, "i:f:a:s:")) != -1)
{
switch (opt)
{
// this only gets loaded without playlist
#ifndef PL
case 'i':
pData->playuri = optarg;
break;
#endif
case 'f':
pData->feedid = atoi(optarg);
break;
case 's':
if (strcmp(optarg,"snowmix") == 0)
{
pData->sink = SNOWMIX;
} else if (strcmp(optarg,"rtmp") == 0)
{
pData->sink = RTMP;
} else if (strcmp(optarg,"fake") == 0)
{
pData->sink = FAKE;
}
break;
#ifdef SNOWBIN
case 'a':
if (strcmp(optarg,"snowmix") == 0)
{
pData->snow->audiosink = SNOWMIX;
} else if (strcmp(optarg,"jack") == 0)
{
pData->snow->audiosink = JACK;
} else if (strcmp(optarg,"auto") == 0)
{
pData->snow->audiosink = AUTO;
} else if (strcmp(optarg,"fake") == 0)
{
pData->snow->audiosink = FAKE;
}
break;
#endif
case '?':
/* Case when user enters the command as
* $ ./cmd_exe -i
*/
if (optopt == 'u')
{
printf ("\nMissing mandatory input option \n");
exit(1);
}
else
{
printf
("\nInvalid option received possible options: \n -a audiosink [snowmix|jack|auto|fake] \n -i playuri \n -f feedid \n -s sink (not working) \n");
exit(1);
}
break;
} //switch
} //while
#ifdef GTK
#ifdef TT
if( ! g_thread_supported() )
g_thread_init( NULL );
gdk_threads_init();
gdk_threads_enter();
#endif
/* Initialize GTK */
gtk_init (&argc, &argv);
#endif
/* initialize gstreamer */
init_media(pData);
/* Create the GUI */
#ifdef GTK
create_ui (pData);
#endif
#ifndef PL
//load url
load_uri(pData->playuri, pData);
gst_element_set_state (pData->playbin2, GST_STATE_PLAYING);
#endif
/* Register a function that GLib will call every second */
#ifdef GTK
g_timeout_add_seconds (1, (GSourceFunc)refresh_ui, pData);
/* register a function that will check all items in the playlist for availablitity */
#ifdef PL
g_timeout_add_seconds (15, (GSourceFunc) playlist_refresh, pData);
#endif
#endif
gst_element_set_state (pData->playbin2, GST_STATE_PLAYING);
/* Start the GTK main loop. We will not regain control until gtk_main_quit is called. */
#ifdef GTK
gtk_main ();
#ifdef TT
gdk_threads_leave();
#endif
#else
// printf("using this without gtk is on the todo list");
pData->loop = g_main_loop_new (NULL, FALSE);
g_print ("Running...\n");
g_main_loop_run (pData->loop);
#endif
// cleanup();
return 0;
}
extern int
player_reset_and_play ();
extern void player_init_media(PlayerData *);
extern void player_create_gui(PlayerData *);
extern int player_refresh_ui(PlayerData *);
extern void player_cleanup(PlayerData *);
extern void player_load_uri(char *, PlayerData *);
#include "common.h"
#include "c-player.h"
#include "playlist.h"
static int signal_handler(PlayerData * data) {
printf(" \n Signal caught: %u \n ", 10);
player_cleanup(data);
}
int
main (int argc, char *argv[])
{
/* deal with command line arguments */
// feed, filename,
auto int opt = 0;
// auto int feedid = 1;
auto int audiosink = 23;
g_unix_signal_add(SIGUSR1, (GSourceFunc)signal_handler, pData);
g_unix_signal_add(SIGTERM, (GSourceFunc)signal_handler, pData);
g_unix_signal_add(SIGINT, (GSourceFunc)signal_handler, pData);
/* Initialize our global data structures */
pData = (PlayerData*)malloc(sizeof(struct PlayerData));
#ifdef SNOWBIN
snowbin_init_snowData(pData);
#endif
while ((opt = getopt (argc, argv, "i:f:a:s:")) != -1)
{
switch (opt)
{
// this only gets loaded without playlist
#ifndef PL
case 'i':
pData->playuri = optarg;
break;
#endif
case 'f':
pData->feedid = atoi(optarg);
break;
case 's':
if (strcmp(optarg,"snowmix") == 0)
{
pData->sink = SNOWMIX;
} else if (strcmp(optarg,"rtmp") == 0)
{
pData->sink = RTMP;
} else if (strcmp(optarg,"fake") == 0)
{
pData->sink = FAKE;
}
break;
#ifdef SNOWBIN
case 'a':
if (strcmp(optarg,"snowmix") == 0)
{
pData->snow->audiosink = SNOWMIX;
} else if (strcmp(optarg,"jack") == 0)
{
pData->snow->audiosink = JACK;
} else if (strcmp(optarg,"auto") == 0)
{
pData->snow->audiosink = AUTO;
} else if (strcmp(optarg,"fake") == 0)
{
pData->snow->audiosink = FAKE;
}
break;
#endif
case '?':
/* Case when user enters the command as
* $ ./cmd_exe -i
*/
if (optopt == 'u')
{
printf ("\nMissing mandatory input option \n");
exit(1);
}
else
{
printf
("\nInvalid option received possible options: \n -a audiosink [snowmix|jack|auto|fake] \n -i playuri \n -f feedid \n -s sink (not working) \n");
exit(1);
}
break;
} //switch
} //while
#ifdef GTK
#ifdef TT
if( ! g_thread_supported() )
g_thread_init( NULL );
gdk_threads_init();
gdk_threads_enter();
#endif
/* Initialize GTK */
gtk_init (&argc, &argv);
#endif
/* initialize player */
player_init_media(pData);
/* Create the GUI */
#ifdef GTK
player_create_ui (pData);
#endif
#ifndef PL
//load url
player_load_uri(pData->playuri, pData);
gst_element_set_state (pData->playbin2, GST_STATE_PLAYING);
#endif
/* Register a function that GLib will call every second */
#ifdef GTK
g_timeout_add_seconds (1, (GSourceFunc)player_refresh_ui, pData);
/* register a function that will check all items in the playlist for availablitity */
#ifdef PL
g_timeout_add_seconds (15, (GSourceFunc) playlist_refresh, pData);
#endif
#endif
gst_element_set_state (pData->playbin2, GST_STATE_PLAYING);
/* Start the GTK main loop. We will not regain control until gtk_main_quit is called. */
#ifdef GTK
gtk_main ();
#ifdef TT
gdk_threads_leave();
#endif
#else
// printf("using this without gtk is on the todo list");
pData->loop = g_main_loop_new (NULL, FALSE);
g_print ("Running...\n");
g_main_loop_run (pData->loop);
#endif
// cleanup();
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment