2000-06-25 21:38:00 +00:00
|
|
|
/*
|
|
|
|
* Initial main.c file generated by Glade. Edit as required.
|
|
|
|
* Glade will not overwrite this file.
|
|
|
|
*/
|
|
|
|
|
2000-08-18 20:35:48 +00:00
|
|
|
#include <config.h>
|
2000-06-25 21:38:00 +00:00
|
|
|
|
2000-07-12 22:52:42 +00:00
|
|
|
//#define DEBUG_ENABLED
|
|
|
|
|
2000-08-14 10:16:23 +00:00
|
|
|
#include <glade/glade.h>
|
2000-07-12 22:52:42 +00:00
|
|
|
#include <gst/gstclock.h>
|
|
|
|
|
2000-07-05 10:21:08 +00:00
|
|
|
#include "gstplay.h"
|
2000-06-25 21:38:00 +00:00
|
|
|
|
2000-08-14 10:16:23 +00:00
|
|
|
#include "callbacks.h"
|
2000-06-25 21:38:00 +00:00
|
|
|
#include "interface.h"
|
|
|
|
|
2000-07-12 22:52:42 +00:00
|
|
|
#define MUTEX_STATUS() (g_mutex_trylock(gdk_threads_mutex)? g_mutex_unlock(gdk_threads_mutex), "was not locked" : "was locked")
|
|
|
|
|
2000-08-14 10:16:23 +00:00
|
|
|
#define BUFFER 20
|
2000-07-12 22:52:42 +00:00
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
static gboolean idle_func(gpointer data);
|
|
|
|
static gint start_from_file(guchar *filename);
|
|
|
|
|
|
|
|
GstElement *show;
|
|
|
|
GstElement *audio_play;
|
2000-06-25 21:38:00 +00:00
|
|
|
GstElement *src;
|
2000-10-12 19:41:30 +00:00
|
|
|
GstElement *parse;
|
2000-09-22 23:35:14 +00:00
|
|
|
GstElement *pipeline;
|
2000-07-05 10:21:08 +00:00
|
|
|
GstPlayState state;
|
|
|
|
gboolean picture_shown = FALSE;
|
|
|
|
guchar statusline[200];
|
|
|
|
guchar *statustext = "stopped";
|
2000-08-14 10:16:23 +00:00
|
|
|
GtkWidget *status_area;
|
2000-10-12 19:41:30 +00:00
|
|
|
GtkWidget *video;
|
2000-08-14 10:16:23 +00:00
|
|
|
GtkAdjustment *adjustment;
|
|
|
|
GtkWidget *play_button;
|
|
|
|
GtkWidget *pause_button;
|
|
|
|
GtkWidget *stop_button;
|
|
|
|
GtkFileSelection *open_file_selection;
|
|
|
|
|
2000-07-05 10:21:08 +00:00
|
|
|
static void frame_displayed(GstSrc *asrc)
|
|
|
|
{
|
|
|
|
int size, time, frame_time = 0, src_pos;
|
|
|
|
guint mux_rate;
|
|
|
|
static int prev_time = -1;
|
|
|
|
|
2000-07-15 12:06:18 +00:00
|
|
|
if (!parse) return;
|
2000-07-12 22:52:42 +00:00
|
|
|
DEBUG("gstplay: frame displayed %s\n", MUTEX_STATUS());
|
|
|
|
|
2000-07-05 10:21:08 +00:00
|
|
|
mux_rate = gst_util_get_int_arg(GTK_OBJECT(parse),"mux_rate");
|
|
|
|
size = gst_util_get_int_arg(GTK_OBJECT(src),"size");
|
|
|
|
time = (size*8)/mux_rate;
|
|
|
|
frame_time = gst_util_get_int_arg(GTK_OBJECT(show),"frame_time");
|
|
|
|
src_pos = gst_util_get_int_arg(GTK_OBJECT(src),"offset");
|
|
|
|
frame_time = (src_pos*8)/mux_rate;
|
|
|
|
|
|
|
|
if (frame_time >= prev_time) {
|
|
|
|
|
|
|
|
g_snprintf(statusline, 200, "%02d:%02d / %02d:%02d\n",
|
|
|
|
frame_time/60, frame_time%60,
|
|
|
|
time/60, time%60);
|
|
|
|
|
|
|
|
//printf("%d %d %g\n", frame_time, size, frame_time*100.0/size);
|
|
|
|
|
2000-08-14 10:16:23 +00:00
|
|
|
update_status_area(status_area);
|
2000-07-05 10:21:08 +00:00
|
|
|
if (state == GSTPLAY_PLAYING)
|
2000-08-14 10:16:23 +00:00
|
|
|
update_slider(adjustment, src_pos*100.0/size);
|
2000-07-05 10:21:08 +00:00
|
|
|
}
|
|
|
|
picture_shown = TRUE;
|
|
|
|
|
|
|
|
prev_time = frame_time;
|
2000-07-12 22:52:42 +00:00
|
|
|
DEBUG("gstplay: frame displayed end %s\n", MUTEX_STATUS());
|
2000-07-05 10:21:08 +00:00
|
|
|
}
|
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
static gboolean idle_func(gpointer data) {
|
2000-07-12 22:52:42 +00:00
|
|
|
DEBUG("idle start %s\n",MUTEX_STATUS());
|
2000-08-18 20:35:48 +00:00
|
|
|
gst_bin_iterate(GST_BIN(data));
|
2000-07-12 22:52:42 +00:00
|
|
|
DEBUG("idle stop %s\n",MUTEX_STATUS());
|
2000-07-05 10:21:08 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void eof(GstSrc *src) {
|
|
|
|
change_state(GSTPLAY_PAUSE);
|
|
|
|
picture_shown = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_next_picture() {
|
|
|
|
picture_shown = FALSE;
|
2000-07-12 22:52:42 +00:00
|
|
|
DEBUG("gstplay: next picture %s\n", MUTEX_STATUS());
|
2000-07-05 10:21:08 +00:00
|
|
|
while (!picture_shown) {
|
2000-07-12 22:52:42 +00:00
|
|
|
gdk_threads_leave();
|
2000-07-05 10:21:08 +00:00
|
|
|
gst_src_push(GST_SRC(src));
|
2000-07-12 22:52:42 +00:00
|
|
|
gdk_threads_enter();
|
2000-07-05 10:21:08 +00:00
|
|
|
}
|
2000-07-12 22:52:42 +00:00
|
|
|
DEBUG("gstplay: next found %s\n", MUTEX_STATUS());
|
2000-06-25 21:38:00 +00:00
|
|
|
}
|
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
static void mute_audio(gboolean mute) {
|
2000-07-05 10:21:08 +00:00
|
|
|
gtk_object_set(GTK_OBJECT(audio_play),"mute",mute,NULL);
|
|
|
|
}
|
|
|
|
|
2000-08-14 10:16:23 +00:00
|
|
|
static void gstplay_tear_down()
|
|
|
|
{
|
|
|
|
g_print("setting to NULL state\n");
|
|
|
|
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
target_drag_data_received (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GtkSelectionData *data,
|
|
|
|
guint info,
|
|
|
|
guint time)
|
|
|
|
{
|
|
|
|
if (strstr(data->data, "file:")) {
|
|
|
|
g_print("Got: %s\n",data->data);
|
|
|
|
start_from_file(g_strchomp(&data->data[5]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
on_exit_menu_activate (GtkMenuItem *menuitem,
|
|
|
|
gpointer user_data)
|
2000-07-13 19:49:50 +00:00
|
|
|
{
|
|
|
|
gdk_threads_leave();
|
2000-08-14 10:16:23 +00:00
|
|
|
gstplay_tear_down();
|
2000-07-13 19:49:50 +00:00
|
|
|
gdk_threads_enter();
|
2000-10-12 19:41:30 +00:00
|
|
|
gst_main_quit();
|
2000-07-13 19:49:50 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 10:16:23 +00:00
|
|
|
void on_ok_button1_clicked (GtkButton *button,
|
|
|
|
GtkFileSelection *sel)
|
2000-07-13 19:49:50 +00:00
|
|
|
{
|
2000-08-14 10:16:23 +00:00
|
|
|
gchar *selected_filename;
|
2000-07-13 19:49:50 +00:00
|
|
|
|
2000-08-14 10:16:23 +00:00
|
|
|
selected_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION(open_file_selection));
|
|
|
|
start_from_file(selected_filename);
|
2000-07-13 19:49:50 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 10:16:23 +00:00
|
|
|
gint on_gstplay_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
|
2000-07-12 22:52:42 +00:00
|
|
|
{
|
2000-08-14 10:16:23 +00:00
|
|
|
gdk_threads_leave();
|
|
|
|
gstplay_tear_down();
|
|
|
|
gdk_threads_enter();
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-07-12 22:52:42 +00:00
|
|
|
|
2000-07-05 10:21:08 +00:00
|
|
|
void change_state(GstPlayState new_state) {
|
|
|
|
|
|
|
|
if (new_state == state) return;
|
|
|
|
switch (new_state) {
|
|
|
|
case GSTPLAY_PLAYING:
|
|
|
|
mute_audio(FALSE);
|
|
|
|
statustext = "playing";
|
2000-08-14 10:16:23 +00:00
|
|
|
update_status_area(status_area);
|
2000-10-12 19:41:30 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_READY);
|
2000-08-18 20:35:48 +00:00
|
|
|
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PLAYING);
|
|
|
|
gtk_idle_add(idle_func, pipeline);
|
2000-07-05 10:21:08 +00:00
|
|
|
state = GSTPLAY_PLAYING;
|
|
|
|
update_buttons(0);
|
|
|
|
break;
|
|
|
|
case GSTPLAY_PAUSE:
|
|
|
|
statustext = "paused";
|
2000-08-14 10:16:23 +00:00
|
|
|
update_status_area(status_area);
|
2000-08-18 20:35:48 +00:00
|
|
|
if (state != GSTPLAY_STOPPED) gtk_idle_remove_by_data(pipeline);
|
2000-10-12 19:41:30 +00:00
|
|
|
//gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_PAUSED);
|
2000-07-05 10:21:08 +00:00
|
|
|
mute_audio(TRUE);
|
|
|
|
state = GSTPLAY_PAUSE;
|
|
|
|
update_buttons(1);
|
|
|
|
break;
|
|
|
|
case GSTPLAY_STOPPED:
|
2000-08-18 20:35:48 +00:00
|
|
|
if (state != GSTPLAY_PAUSE) gtk_idle_remove_by_data(pipeline);
|
2000-10-12 19:41:30 +00:00
|
|
|
//gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_NULL);
|
2000-07-05 10:21:08 +00:00
|
|
|
statustext = "stopped";
|
2000-08-14 10:16:23 +00:00
|
|
|
update_status_area(status_area);
|
2000-07-05 10:21:08 +00:00
|
|
|
mute_audio(TRUE);
|
|
|
|
state = GSTPLAY_STOPPED;
|
|
|
|
gtk_object_set(GTK_OBJECT(src),"offset",0,NULL);
|
|
|
|
update_buttons(2);
|
2000-08-14 10:16:23 +00:00
|
|
|
update_slider(adjustment, 0.0);
|
2000-10-12 19:41:30 +00:00
|
|
|
//show_next_picture();
|
2000-07-05 10:21:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
static gint start_from_file(guchar *filename)
|
2000-08-14 10:16:23 +00:00
|
|
|
{
|
2000-10-12 19:41:30 +00:00
|
|
|
src = gst_elementfactory_make("disksrc", "disk_src");
|
2000-08-14 10:16:23 +00:00
|
|
|
g_return_val_if_fail(src != NULL, -1);
|
|
|
|
g_print("should be using file '%s'\n",filename);
|
|
|
|
gtk_object_set(GTK_OBJECT(src),"location",filename,NULL);
|
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
gst_pipeline_add_src(GST_PIPELINE(pipeline),GST_ELEMENT(src));
|
2000-08-14 10:16:23 +00:00
|
|
|
gtk_signal_connect(GTK_OBJECT(src),"eos",
|
|
|
|
GTK_SIGNAL_FUNC(eof),NULL);
|
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
if (!gst_pipeline_autoplug(GST_PIPELINE(pipeline))) {
|
|
|
|
g_print("unable to handle stream\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2000-08-14 10:16:23 +00:00
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
if (GST_PAD_CONNECTED(gst_element_get_pad(show, "sink"))) {
|
|
|
|
gtk_widget_show(video);
|
|
|
|
}
|
2000-08-14 10:16:23 +00:00
|
|
|
g_print("setting to READY state\n");
|
|
|
|
gst_element_set_state(GST_ELEMENT(pipeline),GST_STATE_READY);
|
|
|
|
|
|
|
|
state = GSTPLAY_STOPPED;
|
|
|
|
|
|
|
|
change_state(GSTPLAY_PLAYING);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTargetEntry target_table[] = {
|
|
|
|
{ "text/plain", 0, 0 }
|
|
|
|
};
|
|
|
|
|
2000-06-25 21:38:00 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2000-08-14 10:16:23 +00:00
|
|
|
GladeXML *xml;
|
|
|
|
GtkWidget *slider, *gstplay;
|
2000-06-25 21:38:00 +00:00
|
|
|
|
|
|
|
bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
|
|
|
|
textdomain (PACKAGE);
|
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
gst_init(&argc,&argv);
|
2000-06-25 21:38:00 +00:00
|
|
|
gnome_init ("gstreamer", VERSION, argc, argv);
|
2000-08-14 10:16:23 +00:00
|
|
|
glade_init();
|
|
|
|
glade_gnome_init();
|
|
|
|
|
2000-08-18 20:35:48 +00:00
|
|
|
g_print("using %s\n", DATADIR"gstplay.glade");
|
2000-08-14 10:16:23 +00:00
|
|
|
/* load the interface */
|
2000-08-18 20:35:48 +00:00
|
|
|
xml = glade_xml_new(DATADIR "gstplay.glade", "gstplay");
|
2000-08-14 10:16:23 +00:00
|
|
|
|
|
|
|
status_area = glade_xml_get_widget(xml, "status_area");
|
|
|
|
slider = glade_xml_get_widget(xml, "slider");
|
|
|
|
{
|
|
|
|
GtkArg arg;
|
|
|
|
GtkRange *range;
|
|
|
|
arg.name = "adjustment";
|
|
|
|
gtk_object_getv(GTK_OBJECT(slider),1,&arg);
|
|
|
|
range = GTK_RANGE(GTK_VALUE_POINTER(arg));
|
|
|
|
adjustment = gtk_range_get_adjustment(range);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(adjustment),"value_changed",
|
|
|
|
GTK_SIGNAL_FUNC(on_hscale1_value_changed),NULL);
|
|
|
|
}
|
|
|
|
play_button = glade_xml_get_widget(xml, "toggle_play");
|
|
|
|
pause_button = glade_xml_get_widget(xml, "toggle_pause");
|
|
|
|
stop_button = glade_xml_get_widget(xml, "toggle_stop");
|
|
|
|
|
|
|
|
gstplay = glade_xml_get_widget(xml, "gstplay");
|
|
|
|
gtk_drag_dest_set (gstplay,
|
|
|
|
GTK_DEST_DEFAULT_ALL,
|
|
|
|
target_table, 1,
|
|
|
|
GDK_ACTION_COPY);
|
|
|
|
gtk_signal_connect (GTK_OBJECT (gstplay), "drag_data_received",
|
|
|
|
GTK_SIGNAL_FUNC (target_drag_data_received),
|
|
|
|
NULL);
|
|
|
|
|
2000-07-05 10:21:08 +00:00
|
|
|
g_snprintf(statusline, 200, "seeking");
|
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
/* create a new bin to hold the elements */
|
|
|
|
pipeline = gst_pipeline_new("pipeline");
|
|
|
|
g_assert(pipeline != NULL);
|
2000-07-12 22:52:42 +00:00
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
/* and an audio sink */
|
|
|
|
audio_play = gst_elementfactory_make("audiosink","play_audio");
|
|
|
|
g_return_val_if_fail(audio_play != NULL, -1);
|
|
|
|
|
|
|
|
/* and a video sink */
|
2000-06-25 21:38:00 +00:00
|
|
|
show = gst_elementfactory_make("videosink","show");
|
|
|
|
g_return_val_if_fail(show != NULL, -1);
|
2000-07-15 12:06:18 +00:00
|
|
|
gtk_object_set(GTK_OBJECT(show),"xv_enabled",FALSE,NULL);
|
2000-10-12 19:41:30 +00:00
|
|
|
gtk_signal_connect(GTK_OBJECT(show),"frame_displayed",
|
|
|
|
GTK_SIGNAL_FUNC(frame_displayed),NULL);
|
2000-08-14 10:16:23 +00:00
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
video = gst_util_get_widget_arg(GTK_OBJECT(show),"widget");
|
2000-08-14 10:16:23 +00:00
|
|
|
gnome_dock_set_client_area(GNOME_DOCK(glade_xml_get_widget(xml, "dock1")),
|
2000-10-12 19:41:30 +00:00
|
|
|
video);
|
2000-07-12 22:52:42 +00:00
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
gst_pipeline_add_sink(GST_PIPELINE(pipeline), audio_play);
|
|
|
|
gst_pipeline_add_sink(GST_PIPELINE(pipeline), show);
|
2000-07-05 10:21:08 +00:00
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
/* connect the signals in the interface */
|
|
|
|
glade_xml_signal_autoconnect(xml);
|
2000-06-25 21:38:00 +00:00
|
|
|
|
2000-08-14 10:16:23 +00:00
|
|
|
if (argc > 1) {
|
|
|
|
gint ret;
|
|
|
|
|
|
|
|
ret = start_from_file(argv[1]);
|
|
|
|
if (ret < 0) exit(ret);
|
|
|
|
}
|
2000-06-25 21:38:00 +00:00
|
|
|
|
2000-10-12 19:41:30 +00:00
|
|
|
gst_main();
|
2000-06-25 21:38:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|