diff -r 000000000000 -r bd0ad44171e7 gmyth-stream/gmemcoder/src/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth-stream/gmemcoder/src/main.c Mon Apr 23 18:50:32 2007 +0100 @@ -0,0 +1,105 @@ +#include +#include +#include +#include + +#include +#include + +#include "gmemcoder.h" + +//#define FILE_OUT 1 + +static GMainLoop *mainloop = NULL; + +static void +_mencoder_ready_cb (GMencoder *mencoder, gpointer data) +{ + g_mencoder_play_stream (mencoder); +} + +static void +_mencoder_eos_cb (GMencoder *mencoder, gpointer data) +{ + g_print ("EOS\n"); + g_main_loop_quit ((GMainLoop *) data); +} + +static void +_mencoder_error_cb (GMencoder *mencoder, const gchar* msg, gpointer data) +{ + g_print ("Error: %s\n", msg); + g_main_loop_quit ((GMainLoop *) data); +} + +static gboolean +_io_channel_cb (GIOChannel *ch, + GIOCondition condition, + gpointer data) +{ + GString *cmd = g_string_new (""); + g_io_channel_read_line_string (ch, cmd, NULL, NULL); + + if (strcmp (cmd->str, "PLAY\n") == 0) { + g_mencoder_play_stream (G_MENCODER (data)); + } else if (strcmp (cmd->str, "PAUSE\n") == 0) { + g_mencoder_pause_stream (G_MENCODER (data)); + } else if (strcmp (cmd->str, "STOP\n") == 0) { + g_mencoder_close_stream (G_MENCODER (data)); + } else if (strcmp (cmd->str, "QUIT\n") == 0) { + g_mencoder_close_stream (G_MENCODER (data)); + g_main_loop_quit (mainloop); + } + g_string_free (cmd, TRUE); + return TRUE; +} + +int +main (int argc, char** argv) +{ + GMencoder *coder; + GIOChannel *ch; + + g_type_init (); + gst_init (&argc, &argv); + + g_set_prgname ("gmemcoder"); + + coder = g_mencoder_new (); + ch = g_io_channel_unix_new (0); + +#ifdef FILE_OUT + int fd = open (argv[2], O_WRONLY | O_CREAT | O_TRUNC); + g_debug ("FD %d", fd); + g_mencoder_setup_stream (coder, argv[1], 320, 288, fd); +#else + g_mencoder_setup_stream (coder, argv[1], 320, 288, atoi (argv[2])); +#endif + + mainloop = g_main_loop_new (NULL, FALSE); + g_io_add_watch (ch, G_IO_IN, _io_channel_cb, coder); + + + g_signal_connect (G_OBJECT (coder), + "ready", + G_CALLBACK (_mencoder_ready_cb), + NULL); + + g_signal_connect (G_OBJECT (coder), + "eos", + G_CALLBACK (_mencoder_eos_cb), + mainloop); + + g_signal_connect (G_OBJECT (coder), + "error", + G_CALLBACK (_mencoder_error_cb), + mainloop); + + g_main_loop_run (mainloop); + +#if FILE_OUT + close (fd); +#endif + + return 0; +}