Commit 3d6ef15b authored by hark's avatar hark
Browse files

some stuff

parent 97bea5d9
......@@ -11,3 +11,7 @@ c-player-debug
rot13
switchs
tcpclient
c-player-np
midicontrol
valgrind.sh
......@@ -31,13 +31,16 @@ c-player-0.10 : c-player.c
gcc -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-debug : c-player.c
gcc -D TT -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)
gcc -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 : c-player.c snowbin.c playlist.c teebin.c wraps.c
gcc -DFP -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-np : c-player.c snowbin.c teebin.c wraps.c common.h
gcc -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-cli : c-player.c
gcc -DGST1 -g c-player.c wraps.c playlist.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 : c-player.c snowbin.c playlist.c teebin.c wraps.c common.h playlist.h teebin.h
gcc -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-cli : c-player.c snowbin.c teebin.c wraps.c common.h
gcc -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)
......
......@@ -19,14 +19,20 @@
#include <string.h>
#include "common.h"
#ifdef PL
#include "playlist.h"
#include "teebin.h"
#endif
#include "rtmpbin.h"
//#ifndef GST1
#ifdef SNOWBIN
#include "teebin.h"
#include "snowbin.h"
//#endif
#endif
// player things
/*
static const char *playuri = NULL;
static char *feedname = NULL;
static int preview = 0;
......@@ -34,7 +40,7 @@ static GstStateChangeReturn ret;
static GstBus *bus;
// snowbin or auto
static gchar *sink = "snowbin";
*/
//Gtk things
#ifdef GTK
......@@ -52,25 +58,32 @@ GError *error = NULL;
#endif
#ifdef TT
static GSourceFunc set_time (char * markup_time)
{
gtk_label_set_text(GTK_LABEL(label_time), markup_time );
printf("test: %s", markup_time);
}
static gpointer thread_time_func( gpointer data )
{
int i;
gchar * markup_time;
auto int i;
auto gchar * markup_time;
while(1)
{
sleep(0.2);
sleep(1);
i = i + 1;
gchar *markup_time = g_markup_printf_escaped ("Time fucktime, i:%u", i);
gdk_threads_enter();
gtk_label_set_text(GTK_LABEL(data), markup_time );
gdk_threads_leave();
markup_time = g_markup_printf_escaped ("i:%u", i);
// > that is depreciated gdk_threads_enter();
gdk_threads_add_idle ((GSourceFunc)set_time,markup_time);
// > that is depreciated gdk_threads_leave();
g_free(markup_time);
}
g_free(i);
}
#endif
......@@ -83,7 +96,7 @@ static gpointer thread_time_func( gpointer data )
static void
realize_cb (GtkWidget * widget, PlayerData * data)
{
GdkWindow *window = gtk_widget_get_window (widget);
auto GdkWindow *window = gtk_widget_get_window (widget);
static guintptr window_handle;
if (!gdk_window_ensure_native (window))
......@@ -148,7 +161,7 @@ load_uri (const gchar * uri)
#ifdef GTK
markup =
g_markup_printf_escaped
("<span foreground=\"red\" size=\"x-large\">%s</span>", uri);
("<span foreground=\"red\" size=\"x-small\">%s</span>", uri);
gtk_label_set_markup (GTK_LABEL (loaded_label), markup);
#endif
// gst_element_set_state (pData->playbin2, GST_STATE_PLAYING);
......@@ -158,23 +171,20 @@ load_uri (const gchar * uri)
static void
preview_cb (GtkCheckButton * preview_check, PlayerData * data)
{
while (TRUE)
{
if (preview == 0)
if (data->preview == 0)
{
g_print ("turning on preview checkcb \n");
// g_print ("turning on preview checkcb \n");
teebin_preview_on(data);
preview = 1;
break;
data->preview = 1;
return;
}
if (preview == 1)
if (data->preview == 1)
{
g_print ("turning off preview checkcb \n");
// g_print ("turning off preview checkcb \n");
teebin_preview_off(data);
preview = 0;
break;
data->preview = 0;
return;
}
}
}
#endif
......@@ -222,7 +232,7 @@ expose_cb (GtkWidget * widget, GdkEventExpose * event, PlayerData * data)
static void
slider_cb (GtkRange * range, PlayerData * data)
{
gdouble value = gtk_range_get_value (GTK_RANGE (data->slider));
auto gdouble value = gtk_range_get_value (GTK_RANGE (data->slider));
gst_element_seek_simple (data->playbin2, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT,
(gint64) (value * GST_SECOND));
......@@ -243,7 +253,7 @@ create_ui (PlayerData * data)
static GtkWidget *options; /* HBox to hold the options and current uri */
static GtkWidget *play_button, *pause_button, *stop_button, *open_button, *add_button; /* Buttons */
static GtkWidget *test_button, *previous_button, *next_button;
static GtkWidget *preview_check; /* Checkbuttons */
// static GtkWidget *preview_check; /* Checkbuttons */
// this should be done by playlist
// GtkWidget *loop_check; /* Checkbuttons */
......@@ -261,18 +271,19 @@ create_ui (PlayerData * data)
data);
/* make the feed label that will change color based on playing state */
feed_label = gtk_label_new(NULL);
markup =
g_markup_printf_escaped
("<span foreground=\"red\" size=\"x-large\">%s</span>", feedname);
feed_label = gtk_label_new (feedname);
gtk_label_set_markup (GTK_LABEL (feed_label), markup);
("<span foreground=\"red\" size=\"x-large\">F: %u --</span>", data->feedid);
gtk_label_set_markup (GTK_LABEL(feed_label), markup);
g_free (markup);
loaded_label = gtk_label_new(NULL);
markup =
g_markup_printf_escaped
("<span foreground=\"red\" size=\"x-large\">currently loaded uri</span>");
loaded_label = gtk_label_new (feedname);
gtk_label_set_markup (GTK_LABEL (loaded_label), markup);
("<span foreground=\"red\" size=\"x-small\">currently loaded uri</span>");
gtk_label_set_markup (GTK_LABEL(loaded_label), markup);
g_free (markup);
markup =
......@@ -296,11 +307,11 @@ create_ui (PlayerData * data)
g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb),
data);
preview_check = gtk_check_button_new_with_label ("preview current video");
g_signal_connect (G_OBJECT (preview_check), "toggled",
data->preview_check = gtk_check_button_new_with_label ("preview current video");
g_signal_connect (G_OBJECT (data->preview_check), "toggled",
G_CALLBACK (preview_cb), data);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(preview_check), TRUE);
// gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(preview_check), TRUE);
// uri_entrybox = gtk_entry_new ();
......@@ -326,10 +337,7 @@ thread_time = g_thread_create( thread_time_func, (gpointer)label_time, FALSE, &e
gtk_box_pack_start (GTK_BOX (controls), play_button, FALSE, FALSE, 2);
gtk_box_pack_start (GTK_BOX (controls), pause_button, FALSE, FALSE, 2);
gtk_box_pack_start (GTK_BOX (controls), stop_button, FALSE, FALSE, 2);
gtk_box_pack_start (GTK_BOX (controls), preview_check, FALSE, FALSE, 2);
gtk_box_pack_start (GTK_BOX (controls), data->preview_check, FALSE, FALSE, 2);
/* options */
options = gtk_vbox_new (FALSE, 0);
......@@ -356,13 +364,15 @@ thread_time = g_thread_create( thread_time_func, (gpointer)label_time, FALSE, &e
gtk_box_pack_start (GTK_BOX (main_box), options, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (main_box), controls, FALSE, FALSE, 0);
#ifdef PL
/* init playlist */
playlist_box = playlist_init_gtk ();
// pack the playlist
gtk_box_pack_start (GTK_BOX (main_box), playlist_box, TRUE, TRUE, 0);
load_uri (playlist_get_current ());
#endif
gtk_container_add (GTK_CONTAINER (main_window), main_box);
gtk_window_set_default_size (GTK_WINDOW (main_window), 640, 480);
......@@ -376,9 +386,11 @@ thread_time = g_thread_create( thread_time_func, (gpointer)label_time, FALSE, &e
static int
refresh_ui (PlayerData * data)
{
GstFormat fmt = GST_FORMAT_TIME;
gint64 current = -1;
// printf("refresh_ui state: %u paused=%u \n", data->state, GST_STATE_PAUSED);
auto GstFormat fmt = GST_FORMAT_TIME;
auto gint64 current = -1;
auto char *nicetime;
auto int sec, min, hour, time;
// printf("refresh_ui state: %u paused=%u \n", data->state, GST_STATE_PAUSED);
/* We do not want to update anything unless we are in the PAUSED or PLAYING states */
if (data->state < GST_STATE_PAUSED)
return TRUE;
......@@ -422,9 +434,7 @@ refresh_ui (PlayerData * data)
/* Re-enable the signal */
g_signal_handler_unblock (data->slider, data->slider_update_signal_id);
//char *nicetime = "00:00:00";
char *nicetime;
int sec, min, hour, time;
time = current / GST_SECOND;
time = current / GST_SECOND;
hour = time / 3600;
min = time % 3600 / 60;
sec = time % 60;
......@@ -447,10 +457,11 @@ player_reset_and_play ()
/* stop playing */
gst_element_set_state (pData->playbin2, GST_STATE_READY);
#ifdef PL
printf("current uri: %s", playlist_get_current());
load_uri(playlist_get_current());
// static int ret;
#endif
int ret = 0;
/* Start playing */
ret = gst_element_set_state (pData->playbin2, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE)
......@@ -486,8 +497,8 @@ tags_cb (GstElement * playbin2, gint stream, PlayerData * data)
static void
error_cb (GstBus * bus, GstMessage * msg, PlayerData * data)
{
GError *err;
gchar *debug_info;
auto GError *err;
auto gchar *debug_info;
/* Print error details on the screen */
gst_message_parse_error (msg, &err, &debug_info);
......@@ -547,10 +558,13 @@ eos_cb (GstBus * bus, GstMessage * msg, PlayerData * data)
static void
state_changed_cb (GstBus * bus, GstMessage * msg, PlayerData * data)
{
GstState old_state, new_state, pending_state;
auto GstState old_state, new_state, pending_state;
auto GstFormat fmt = GST_FORMAT_TIME;
char feedname[10] = "F:00";
snprintf(&feedname, sizeof(feedname), "F:%u", data->feedid);
gst_message_parse_state_changed (msg, &old_state, &new_state,
&pending_state);
GstFormat fmt = GST_FORMAT_TIME;
#ifdef GTK
refresh_ui(data);
#endif
......@@ -664,13 +678,14 @@ state_changed_cb (GstBus * bus, GstMessage * msg, PlayerData * data)
static void
analyze_streams (PlayerData * data)
{
gint i;
GstTagList *tags;
gchar *str, *total_str;
guint rate;
gint n_video, n_audio, n_text;
GtkTextBuffer *text;
auto gint i;
auto GstTagList *tags;
auto gchar *str, *total_str;
auto guint rate;
auto gint n_video, n_audio, n_text;
#ifdef GTK
auto GtkTextBuffer *text;
/* Clean current contents of the widget */
text = gtk_text_view_get_buffer (GTK_TEXT_VIEW (data->streams_list));
gtk_text_buffer_set_text (text, "", -1);
......@@ -724,7 +739,9 @@ analyze_streams (PlayerData * data)
if (gst_tag_list_get_string (tags, GST_TAG_AUDIO_CODEC, &str))
{
total_str = g_strdup_printf (" codec: %s\n", str);
#ifdef GTK
gtk_text_buffer_insert_at_cursor (text, total_str, -1);
#endif
g_free (total_str);
g_free (str);
}
......@@ -808,47 +825,48 @@ application_cb (GstBus * bus, GstMessage * msg, PlayerData * data)
#endif
}
static void init_media()
static void init_media(PlayerData *data)
{
GstBus *bus;
pData->duration = GST_CLOCK_TIME_NONE;
pData->state = GST_STATE_NULL;
/* Initialize GStreamer */
gst_init (NULL, NULL);
pData->duration = GST_CLOCK_TIME_NONE;
/* Create the elements */
/* Create the elements */
#ifdef GST1
pData->playbin2 = gst_element_factory_make ("playbin", "playbin2");
#else
pData->playbin2 = gst_element_factory_make ("playbin2", "playbin2");
#endif
// g_print ("sink: %s \n", sink);
GstElement *videosink, *audiosink;
videosink = gst_element_factory_make("xvimagesink", "xvimagesink");
// videosink = gst_element_factory_make("fakesink", "fakesink");
g_print ("sink: %s \n", sink);
#define SNOWBIN
#ifdef SNOWBIN
GstElement *audiosink, *xvimagesink;
xvimagesink = gst_element_factory_make("xvimagesink", "xvimagesink");
gst_element_factory_make("xvimagesink", "xvimagesink");
#ifdef SNOWBIN
/*set snowvideobin as sink */
g_object_set (pData->playbin2, "video-sink",
create_teebin(xvimagesink, get_snowvideobin(pData->snow)), NULL);
g_object_set (pData->playbin2, "video-sink",
create_teebin(videosink, get_snowvideobin(pData->snow)), NULL);
/*set snowaudiobin as sink */
audiosink = get_snowaudiobin(pData->snow);
g_object_set (pData->playbin2, "audio-sink",audiosink, NULL);
g_object_set (pData->playbin2, "audio-sink",audiosink, NULL);
#else
/*
g_print ("autosink \n");
GstElement *videosink, *audiosink;
videosink = gst_element_factory_make ("xvimagesink", "xvimagesink");
audiosink = gst_element_factory_make ("autoaudiosink", "autoaudiosink");
// audiosink = gst_element_factory_make ("fakesink", "fakesink");
g_object_set (pData->playbin2, "video-sink", videosink, NULL);
g_object_set (pData->playbin2, "audio-sink", audiosink, NULL);
g_print (" SNOWBIN is not defined (port it to gst1.0)");
*/
g_print (" SNOWBIN is not defined, so we are not using it! \n ");
#endif
if (!pData->playbin2)
......@@ -889,34 +907,95 @@ static void init_media()
}
static void cleanup() {
// this needs to be called from the main thread!
//global pData
g_print ("Cleaning up\n");
g_print ("Deleting pipeline\n");
gst_element_set_state (pData->playbin2, GST_STATE_NULL);
gst_object_unref (GST_OBJECT (pData->playbin2));
// g_source_remove (bus_watch_id);
#ifdef GTK
gtk_main_quit();
#else
g_main_loop_unref (pData->loop);
#endif
free(pData);
exit(0);
}
static int signal_handler(PlayerData * data) {
printf(" \n Signal caught: %u \n ", 10);
cleanup();
}
int
main (int argc, char *argv[])
{
/* deal with command line arguments */
// feed, filename,
int opt = 0;
int feedid = 1;
int audiosink = 23;
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));
snowbin_init_snowData(pData);
#ifdef SNOWBIN
snowbin_init_snowData(pData);
#endif
while ((opt = getopt (argc, argv, "i:f:a:s:")) != -1)
{
switch (opt)
{
// this is something for the playlist
//case 'i':
// playuri = optarg;
// break;
// this only gets loaded without playlist
#ifndef PL
case 'i':
pData->playuri = optarg;
break;
#endif
case 'f':
feedid = atoi(optarg);
pData->feedid = atoi(optarg);
break;
case 's':
sink = optarg;
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)
{
......@@ -933,6 +1012,7 @@ main (int argc, char *argv[])
pData->snow->audiosink = FAKE;
}
break;
#endif
case '?':
/* Case when user enters the command as
* $ ./cmd_exe -i
......@@ -968,20 +1048,32 @@ main (int argc, char *argv[])
#endif
/* initialize gstreamer */
init_media();
init_media(pData);
/* Create the GUI */
#ifdef GTK
create_ui (pData);
#endif
#ifndef PL
//load url
load_uri(pData->playuri);
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);
#endif
/* register a function that will check all items in the playlist for availablitity */
// g_timeout_add_seconds (15, (GsourceFunc)playlist_refresh, &pData);
#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
......@@ -991,10 +1083,14 @@ init_media();
gdk_threads_leave();
#endif
#else
printf("using this without gtk is on the todo list");
// 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
/* Free resources */
gst_element_set_state (pData->playbin2, GST_STATE_NULL);
gst_object_unref (pData->playbin2);
// cleanup();
return 0;
}
......@@ -48,8 +48,10 @@
//glib stuff
//#include <glib.h>
//#include <glib-2.0/glib/gprintf.h>
#include <glib.h>
#include <glib-2.0/glib/gprintf.h>
#include <glib-unix.h>
//gtk stuff
#ifdef GTK
......@@ -88,20 +90,18 @@
#define gst_element_factory_make(element, name) gst_element_factory_make_debug (element, name);
enum {
STOMDING,
ANDERDING,
WTF,
AUTO,
JACK,
SNOWMIX,
FAKE
FAKE,
RTMP
};
typedef struct snowMixer snowMixer;
struct snowMixer {
//general
char *host; //host
int port; //port
char *port; //port
char *control_socket; //ctrsocket
char *state; //snowmix
//video
......@@ -138,20 +138,28 @@ struct snowData {
/* Structure to contain all our information, so we can pass it around */
typedef struct PlayerData PlayerData;
struct PlayerData{
// things that used to be global vars
char *playuri;
int feedid;
int sink;
int preview;
//mainloop
GMainLoop *loop;
//gstreamer
GstElement *playbin2; /* Our one and only pipeline */
GstDiscoverer *discoverer;
GstState state; /* Current state of the pipeline */
gint64 duration; /* Duration of the clip, in nanoseconds */
GstElement *valve;
//gtk
#ifdef GTK
GtkWidget *slider; /* Slider widget to keep track of current position */
GtkWidget *streams_list; /* Text widget to display info about the streams */
gulong slider_update_signal_id; /* Signal ID for the slider update signal */
GtkWidget *preview_check;
#endif
snowData *snow;
snowData *snow;
};
//CustomData globalData;
......
......@@ -544,8 +544,8 @@ playlist_selection_changed_cb (GtkTreeSelection * selection, gpointer data)
}
static void
refresh_ui (PlayerData * data)
extern void
playlist_refresh (PlayerData * data)