Logo Search packages:      
Sourcecode: betaradio version File versions  Download package

gst_player.c

/* gst_player.c generated by valac 0.12.0, the Vala compiler
 * generated from gst_player.vala, do not modify */

/* -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- */
/* vim:set fileencodings=utf-8 tabstop=4 expandtab shiftwidth=4 softtabstop=4: */

#include <glib.h>
#include <glib-object.h>
#include <gst/gst.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>


#define TYPE_GST_PLAYER (gst_player_get_type ())
#define GST_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GST_PLAYER, GstPlayer))
#define GST_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GST_PLAYER, GstPlayerClass))
#define IS_GST_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GST_PLAYER))
#define IS_GST_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GST_PLAYER))
#define GST_PLAYER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GST_PLAYER, GstPlayerClass))

typedef struct _GstPlayer GstPlayer;
typedef struct _GstPlayerClass GstPlayerClass;
typedef struct _GstPlayerPrivate GstPlayerPrivate;
#define _gst_object_unref0(var) ((var == NULL) ? NULL : (var = (gst_object_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

00030 struct _GstPlayer {
      GObject parent_instance;
      GstPlayerPrivate * priv;
};

00035 struct _GstPlayerClass {
      GObjectClass parent_class;
};

00039 struct _GstPlayerPrivate {
      GstElement* player;
};


static gpointer gst_player_parent_class = NULL;
static GstPlayer* gst_player_instance;
static GstPlayer* gst_player_instance = NULL;

GType gst_player_get_type (void) G_GNUC_CONST;
#define GST_PLAYER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_GST_PLAYER, GstPlayerPrivate))
enum  {
      GST_PLAYER_DUMMY_PROPERTY
};
static GstPlayer* gst_player_new (const gchar* name);
static GstPlayer* gst_player_construct (GType object_type, const gchar* name);
static gboolean gst_player_bus_callback (GstPlayer* self, GstBus* bus, GstMessage* msg);
static gboolean _gst_player_bus_callback_gst_bus_func (GstBus* bus, GstMessage* message, gpointer self);
GstPlayer* gst_player_get_instance (void);
void gst_player_play (GstPlayer* self, const gchar* url);
static inline void _dynamic_set_uri0 (GstElement* obj, const gchar* value);
void gst_player_stop (GstPlayer* self);
static void gst_player_finalize (GObject* obj);


static gboolean _gst_player_bus_callback_gst_bus_func (GstBus* bus, GstMessage* message, gpointer self) {
      gboolean result;
      result = gst_player_bus_callback (self, bus, message);
      return result;
}


static GstPlayer* gst_player_construct (GType object_type, const gchar* name) {
      GstPlayer * self = NULL;
      GstElement* _tmp0_ = NULL;
      GstBus* _tmp1_ = NULL;
      GstBus* _tmp2_;
      g_return_val_if_fail (name != NULL, NULL);
      self = (GstPlayer*) g_object_new (object_type, NULL);
      _tmp0_ = gst_element_factory_make ("playbin2", name);
      _gst_object_unref0 (self->priv->player);
      self->priv->player = _tmp0_;
      _tmp1_ = gst_element_get_bus (self->priv->player);
      _tmp2_ = _tmp1_;
      gst_bus_add_watch_full (_tmp2_, G_PRIORITY_DEFAULT, _gst_player_bus_callback_gst_bus_func, g_object_ref (self), g_object_unref);
      _gst_object_unref0 (_tmp2_);
      return self;
}


static GstPlayer* gst_player_new (const gchar* name) {
      return gst_player_construct (TYPE_GST_PLAYER, name);
}


static gpointer _g_object_ref0 (gpointer self) {
      return self ? g_object_ref (self) : NULL;
}


GstPlayer* gst_player_get_instance (void) {
      GstPlayer* result = NULL;
      GstPlayer* _tmp1_;
      if (gst_player_instance == NULL) {
            GstPlayer* _tmp0_ = NULL;
            _tmp0_ = gst_player_new ("BetaRadio");
            _g_object_unref0 (gst_player_instance);
            gst_player_instance = _tmp0_;
      }
      _tmp1_ = _g_object_ref0 (gst_player_instance);
      result = _tmp1_;
      return result;
}


static inline void _dynamic_set_uri0 (GstElement* obj, const gchar* value) {
      g_object_set (obj, "uri", value, NULL);
}


void gst_player_play (GstPlayer* self, const gchar* url) {
      GstState state = 0;
      GstState pending = 0;
      g_return_if_fail (self != NULL);
      g_return_if_fail (url != NULL);
      while (TRUE) {
            GstState _tmp0_;
            GstState _tmp1_;
            GstStateChangeReturn _tmp2_;
            const gchar* _tmp3_ = NULL;
            const gchar* _tmp4_ = NULL;
            _tmp2_ = gst_element_get_state (self->priv->player, &_tmp0_, &_tmp1_, (GstClockTime) 2000);
            state = _tmp0_;
            pending = _tmp1_;
            if (!(_tmp2_ != GST_STATE_CHANGE_SUCCESS)) {
                  break;
            }
            _tmp3_ = gst_element_state_get_name (state);
            _tmp4_ = gst_element_state_get_name (pending);
            g_message ("gst_player.vala:48: state: %s, pending: %s", _tmp3_, _tmp4_);
      }
      if (state != GST_STATE_READY) {
            gst_element_set_state (self->priv->player, GST_STATE_READY);
      }
      _dynamic_set_uri0 (self->priv->player, url);
      while (TRUE) {
            GstState _tmp5_;
            GstState _tmp6_;
            GstStateChangeReturn _tmp7_;
            const gchar* _tmp8_ = NULL;
            const gchar* _tmp9_ = NULL;
            _tmp7_ = gst_element_get_state (self->priv->player, &_tmp5_, &_tmp6_, (GstClockTime) 2000);
            state = _tmp5_;
            pending = _tmp6_;
            if (!(_tmp7_ != GST_STATE_CHANGE_SUCCESS)) {
                  break;
            }
            _tmp8_ = gst_element_state_get_name (state);
            _tmp9_ = gst_element_state_get_name (pending);
            g_message ("gst_player.vala:58: state: %s, pending: %s", _tmp8_, _tmp9_);
      }
      gst_element_set_state (self->priv->player, GST_STATE_PLAYING);
}


void gst_player_stop (GstPlayer* self) {
      GstState state = 0;
      GstState pending = 0;
      g_return_if_fail (self != NULL);
      while (TRUE) {
            GstState _tmp0_;
            GstState _tmp1_;
            GstStateChangeReturn _tmp2_;
            const gchar* _tmp3_ = NULL;
            const gchar* _tmp4_ = NULL;
            _tmp2_ = gst_element_get_state (self->priv->player, &_tmp0_, &_tmp1_, (GstClockTime) 2000);
            state = _tmp0_;
            pending = _tmp1_;
            if (!(_tmp2_ != GST_STATE_CHANGE_SUCCESS)) {
                  break;
            }
            _tmp3_ = gst_element_state_get_name (state);
            _tmp4_ = gst_element_state_get_name (pending);
            g_message ("gst_player.vala:69: state: %s, pending: %s", _tmp3_, _tmp4_);
      }
      if (state != GST_STATE_READY) {
            gst_element_set_state (self->priv->player, GST_STATE_READY);
      }
}


static gboolean gst_player_bus_callback (GstPlayer* self, GstBus* bus, GstMessage* msg) {
      gboolean result = FALSE;
      g_return_val_if_fail (self != NULL, FALSE);
      g_return_val_if_fail (bus != NULL, FALSE);
      g_return_val_if_fail (msg != NULL, FALSE);
      switch (msg->type) {
            case GST_MESSAGE_ERROR:
            {
                  GError* err = NULL;
                  gchar* debug = NULL;
                  GError* _tmp0_ = NULL;
                  gchar* _tmp1_ = NULL;
                  gst_message_parse_error (msg, &_tmp0_, &_tmp1_);
                  _g_error_free0 (err);
                  err = _tmp0_;
                  _g_free0 (debug);
                  debug = _tmp1_;
                  g_warning ("gst_player.vala:83: Error: %s\n", err->message);
                  gst_element_set_state (self->priv->player, GST_STATE_NULL);
                  _g_free0 (debug);
                  _g_error_free0 (err);
                  break;
            }
            case GST_MESSAGE_EOS:
            {
                  g_warning ("gst_player.vala:87: end of stream\n");
                  break;
            }
            case GST_MESSAGE_STATE_CHANGED:
            {
                  GstState oldstate = 0;
                  GstState newstate = 0;
                  GstState pending = 0;
                  GstState _tmp2_;
                  GstState _tmp3_;
                  GstState _tmp4_;
                  const gchar* _tmp5_ = NULL;
                  const gchar* _tmp6_ = NULL;
                  const gchar* _tmp7_ = NULL;
                  gst_message_parse_state_changed (msg, &_tmp2_, &_tmp3_, &_tmp4_);
                  oldstate = _tmp2_;
                  newstate = _tmp3_;
                  pending = _tmp4_;
                  _tmp5_ = gst_element_state_get_name (oldstate);
                  _tmp6_ = gst_element_state_get_name (newstate);
                  _tmp7_ = gst_element_state_get_name (pending);
                  fprintf (stdout, "state changed: %s->%s:%s\n", _tmp5_, _tmp6_, _tmp7_);
                  break;
            }
            case GST_MESSAGE_BUFFERING:
            {
                  break;
            }
            default:
            {
                  const gchar* _tmp8_ = NULL;
                  _tmp8_ = gst_message_type_get_name (msg->type);
                  g_message ("gst_player.vala:103: message type: %s", _tmp8_);
                  break;
            }
      }
      result = TRUE;
      return result;
}


static void gst_player_class_init (GstPlayerClass * klass) {
      gst_player_parent_class = g_type_class_peek_parent (klass);
      g_type_class_add_private (klass, sizeof (GstPlayerPrivate));
      G_OBJECT_CLASS (klass)->finalize = gst_player_finalize;
}


static void gst_player_instance_init (GstPlayer * self) {
      self->priv = GST_PLAYER_GET_PRIVATE (self);
      self->priv->player = NULL;
}


static void gst_player_finalize (GObject* obj) {
      GstPlayer * self;
      self = GST_PLAYER (obj);
      _gst_object_unref0 (self->priv->player);
      self->priv->player = NULL;
      _gst_object_unref0 (self->priv->player);
      G_OBJECT_CLASS (gst_player_parent_class)->finalize (obj);
}


/**
 * Copyright (C) 2010 Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
GType gst_player_get_type (void) {
      static volatile gsize gst_player_type_id__volatile = 0;
      if (g_once_init_enter (&gst_player_type_id__volatile)) {
            static const GTypeInfo g_define_type_info = { sizeof (GstPlayerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gst_player_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GstPlayer), 0, (GInstanceInitFunc) gst_player_instance_init, NULL };
            GType gst_player_type_id;
            gst_player_type_id = g_type_register_static (G_TYPE_OBJECT, "GstPlayer", &g_define_type_info, 0);
            g_once_init_leave (&gst_player_type_id__volatile, gst_player_type_id);
      }
      return gst_player_type_id__volatile;
}




Generated by  Doxygen 1.6.0   Back to index