gmyth-stream/gmemcoder/src/main.c
branchtrunk
changeset 586 bd0ad44171e7
child 588 3219eb5401c0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gmyth-stream/gmemcoder/src/main.c	Mon Apr 23 18:50:32 2007 +0100
     1.3 @@ -0,0 +1,105 @@
     1.4 +#include <sys/stat.h>
     1.5 +#include <fcntl.h>
     1.6 +#include <unistd.h>
     1.7 +#include <string.h>
     1.8 +
     1.9 +#include <gst/gst.h>
    1.10 +#include <glib.h> 
    1.11 +
    1.12 +#include "gmemcoder.h"
    1.13 +
    1.14 +//#define FILE_OUT  1
    1.15 +
    1.16 +static GMainLoop *mainloop = NULL;
    1.17 +
    1.18 +static void
    1.19 +_mencoder_ready_cb (GMencoder *mencoder, gpointer data)
    1.20 +{
    1.21 +    g_mencoder_play_stream (mencoder);
    1.22 +}
    1.23 +
    1.24 +static void
    1.25 +_mencoder_eos_cb (GMencoder *mencoder, gpointer data)
    1.26 +{
    1.27 +    g_print ("EOS\n");
    1.28 +    g_main_loop_quit ((GMainLoop *) data);
    1.29 +}
    1.30 +
    1.31 +static void
    1.32 +_mencoder_error_cb (GMencoder *mencoder, const gchar* msg, gpointer data)
    1.33 +{
    1.34 +    g_print ("Error: %s\n", msg);
    1.35 +    g_main_loop_quit ((GMainLoop *) data);
    1.36 +}
    1.37 +
    1.38 +static gboolean
    1.39 +_io_channel_cb (GIOChannel *ch,
    1.40 +                GIOCondition condition,
    1.41 +                gpointer data)
    1.42 +{
    1.43 +    GString *cmd = g_string_new ("");
    1.44 +    g_io_channel_read_line_string (ch, cmd, NULL, NULL);
    1.45 +
    1.46 +    if (strcmp (cmd->str, "PLAY\n") == 0) {
    1.47 +        g_mencoder_play_stream (G_MENCODER (data));
    1.48 +    } else if (strcmp (cmd->str, "PAUSE\n") == 0) {
    1.49 +        g_mencoder_pause_stream (G_MENCODER (data));
    1.50 +    } else if (strcmp (cmd->str, "STOP\n") == 0) {
    1.51 +        g_mencoder_close_stream (G_MENCODER (data));
    1.52 +    } else if (strcmp (cmd->str, "QUIT\n") == 0) {
    1.53 +        g_mencoder_close_stream (G_MENCODER (data));
    1.54 +        g_main_loop_quit (mainloop);
    1.55 +    }
    1.56 +    g_string_free (cmd, TRUE);
    1.57 +    return TRUE;
    1.58 +}
    1.59 +
    1.60 +int 
    1.61 +main (int argc, char** argv)
    1.62 +{
    1.63 +    GMencoder *coder;
    1.64 +    GIOChannel *ch;
    1.65 +
    1.66 +	g_type_init ();
    1.67 +	gst_init (&argc, &argv);
    1.68 +
    1.69 +	g_set_prgname ("gmemcoder");
    1.70 +
    1.71 +    coder = g_mencoder_new ();
    1.72 +    ch = g_io_channel_unix_new (0);
    1.73 +
    1.74 +#ifdef FILE_OUT
    1.75 +    int fd = open (argv[2], O_WRONLY | O_CREAT | O_TRUNC);
    1.76 +    g_debug ("FD %d", fd);
    1.77 +    g_mencoder_setup_stream (coder, argv[1], 320, 288, fd);
    1.78 +#else
    1.79 +    g_mencoder_setup_stream (coder, argv[1], 320, 288, atoi (argv[2]));
    1.80 +#endif
    1.81 +
    1.82 +	mainloop = g_main_loop_new (NULL, FALSE);
    1.83 +    g_io_add_watch (ch, G_IO_IN, _io_channel_cb, coder);    
    1.84 +
    1.85 +
    1.86 +    g_signal_connect (G_OBJECT (coder),
    1.87 +                        "ready",
    1.88 +                        G_CALLBACK (_mencoder_ready_cb),
    1.89 +                        NULL);
    1.90 +
    1.91 +    g_signal_connect (G_OBJECT (coder),
    1.92 +                        "eos",
    1.93 +                        G_CALLBACK (_mencoder_eos_cb),
    1.94 +                        mainloop);
    1.95 +
    1.96 +    g_signal_connect (G_OBJECT (coder),
    1.97 +                        "error",
    1.98 +                        G_CALLBACK (_mencoder_error_cb),
    1.99 +                        mainloop);
   1.100 +
   1.101 +	g_main_loop_run (mainloop);
   1.102 +
   1.103 +#if FILE_OUT
   1.104 +    close (fd);
   1.105 +#endif
   1.106 +	
   1.107 +	return 0;
   1.108 +}