/*
 * This file was generated automatically by ExtUtils::ParseXS version 3.22 from the
 * contents of GstClock.xs. Do not edit this file, edit GstClock.xs instead.
 *
 *    ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "xs/GstClock.xs"
/*
 * Copyright (C) 2005 by the gtk2-perl team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * $Id$
 */

#include "gst2perl.h"

/* ------------------------------------------------------------------------- */

SV *
newSVGstClockTime (GstClockTime time)
{
	return newSVGUInt64 (time);
}

GstClockTime
SvGstClockTime (SV *time)
{
	return SvGUInt64 (time);
}

/* ------------------------------------------------------------------------- */

SV *
newSVGstClockTimeDiff (GstClockTimeDiff diff)
{
	return newSVGInt64 (diff);
}

GstClockTimeDiff
SvGstClockTimeDiff (SV *diff)
{
	return SvGInt64 (diff);
}

/* ------------------------------------------------------------------------- */

SV *
newSVGstClockID (GstClockID id)
{
        SV *sv;

	if (id == NULL)
		return &PL_sv_undef;

	sv = newSV (0);

        return sv_setref_pv (sv, "GStreamer::ClockID", id);
}

GstClockID
SvGstClockID (SV *sv)
{
        return INT2PTR (GstClockID, SvIV (SvRV (sv)));

}

/* ------------------------------------------------------------------------- */

#include <gperl_marshal.h>

static GPerlCallback *
gst2perl_clock_callback_create (SV *func, SV *data)
{
	return gperl_callback_new (func, data, 0, NULL, 0);
}

static gboolean
gst2perl_clock_callback (GstClock *clock,
                         GstClockTime time,
                         GstClockID id,
                         gpointer user_data)
{
	gboolean retval;
	GPerlCallback *callback;
	dGPERL_CALLBACK_MARSHAL_SP;

	callback = user_data;
	GPERL_CALLBACK_MARSHAL_INIT (callback);

	ENTER;
	SAVETMPS;

	PUSHMARK (SP);

	EXTEND (SP, 3);
	PUSHs (sv_2mortal (newSVGstClock (clock)));
	PUSHs (sv_2mortal (newSVGstClockTime (time)));
	/* We need to keep the clock id alive so we ref it to counter DESTROY's
	 * unref */
	PUSHs (sv_2mortal (newSVGstClockID (gst_clock_id_ref (id))));
	if (callback->data)
		XPUSHs (sv_2mortal (newSVsv (callback->data)));

	PUTBACK;

	call_sv (callback->func, G_SCALAR);

	SPAGAIN;

	retval = POPi;

	PUTBACK;
	FREETMPS;
	LEAVE;

	return retval;
}

/* ------------------------------------------------------------------------- */

#line 138 "xs/GstClock.c"
#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(var) if (0) var = var
#endif

#ifndef dVAR
#  define dVAR		dNOOP
#endif


/* This stuff is not part of the API! You have been warned. */
#ifndef PERL_VERSION_DECIMAL
#  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
#endif
#ifndef PERL_DECIMAL_VERSION
#  define PERL_DECIMAL_VERSION \
	  PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
#endif
#ifndef PERL_VERSION_GE
#  define PERL_VERSION_GE(r,v,s) \
	  (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
#endif
#ifndef PERL_VERSION_LE
#  define PERL_VERSION_LE(r,v,s) \
	  (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
#endif

/* XS_INTERNAL is the explicit static-linkage variant of the default
 * XS macro.
 *
 * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
 * "STATIC", ie. it exports XSUB symbols. You probably don't want that
 * for anything but the BOOT XSUB.
 *
 * See XSUB.h in core!
 */


/* TODO: This might be compatible further back than 5.10.0. */
#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
#  undef XS_EXTERNAL
#  undef XS_INTERNAL
#  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
#    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
#    define XS_INTERNAL(name) STATIC XSPROTO(name)
#  endif
#  if defined(__SYMBIAN32__)
#    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
#    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
#  endif
#  ifndef XS_EXTERNAL
#    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
#      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
#      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
#    else
#      ifdef __cplusplus
#        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
#        define XS_INTERNAL(name) static XSPROTO(name)
#      else
#        define XS_EXTERNAL(name) XSPROTO(name)
#        define XS_INTERNAL(name) STATIC XSPROTO(name)
#      endif
#    endif
#  endif
#endif

/* perl >= 5.10.0 && perl <= 5.15.1 */


/* The XS_EXTERNAL macro is used for functions that must not be static
 * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
 * macro defined, the best we can do is assume XS is the same.
 * Dito for XS_INTERNAL.
 */
#ifndef XS_EXTERNAL
#  define XS_EXTERNAL(name) XS(name)
#endif
#ifndef XS_INTERNAL
#  define XS_INTERNAL(name) XS(name)
#endif

/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
 * internal macro that we're free to redefine for varying linkage due
 * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
 * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
 */

#undef XS_EUPXS
#if defined(PERL_EUPXS_ALWAYS_EXPORT)
#  define XS_EUPXS(name) XS_EXTERNAL(name)
#else
   /* default to internal */
#  define XS_EUPXS(name) XS_INTERNAL(name)
#endif

#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)

/* prototype to pass -Wmissing-prototypes */
STATIC void
S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params);

STATIC void
S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params)
{
    const GV *const gv = CvGV(cv);

    PERL_ARGS_ASSERT_CROAK_XS_USAGE;

    if (gv) {
        const char *const gvname = GvNAME(gv);
        const HV *const stash = GvSTASH(gv);
        const char *const hvname = stash ? HvNAME(stash) : NULL;

        if (hvname)
            Perl_croak(aTHX_ "Usage: %s::%s(%s)", hvname, gvname, params);
        else
            Perl_croak(aTHX_ "Usage: %s(%s)", gvname, params);
    } else {
        /* Pants. I don't think that it should be possible to get here. */
        Perl_croak(aTHX_ "Usage: CODE(0x%"UVxf")(%s)", PTR2UV(cv), params);
    }
}
#undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE

#ifdef PERL_IMPLICIT_CONTEXT
#define croak_xs_usage(a,b)    S_croak_xs_usage(aTHX_ a,b)
#else
#define croak_xs_usage        S_croak_xs_usage
#endif

#endif

/* NOTE: the prototype of newXSproto() is different in versions of perls,
 * so we define a portable version of newXSproto()
 */
#ifdef newXS_flags
#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
#else
#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
#endif /* !defined(newXS_flags) */

#line 280 "xs/GstClock.c"

XS_EUPXS(XS_GStreamer__Clock_set_resolution); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_set_resolution)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "clock, resolution");
    {
	guint64	RETVAL;
	GstClock *	clock = SvGstClock (ST(0))
;
	guint64	resolution = SvGUInt64 (ST(1))
;

	RETVAL = gst_clock_set_resolution(clock, resolution);
	ST(0) = newSVGUInt64 (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GStreamer__Clock_get_resolution); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_get_resolution)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "clock");
    {
	guint64	RETVAL;
	GstClock *	clock = SvGstClock (ST(0))
;

	RETVAL = gst_clock_get_resolution(clock);
	ST(0) = newSVGUInt64 (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GStreamer__Clock_get_time); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_get_time)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "clock");
    {
	GstClockTime	RETVAL;
	GstClock *	clock = SvGstClock (ST(0))
;

	RETVAL = gst_clock_get_time(clock);
	ST(0) = newSVGstClockTime (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GStreamer__Clock_set_calibration); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_set_calibration)
{
    dVAR; dXSARGS;
    if (items != 5)
       croak_xs_usage(cv,  "clock, internal, external, rate_num, rate_denom");
    {
	GstClock *	clock = SvGstClock (ST(0))
;
	GstClockTime	internal = SvGstClockTime (ST(1))
;
	GstClockTime	external = SvGstClockTime (ST(2))
;
	GstClockTime	rate_num = SvGstClockTime (ST(3))
;
	GstClockTime	rate_denom = SvGstClockTime (ST(4))
;

	gst_clock_set_calibration(clock, internal, external, rate_num, rate_denom);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_GStreamer__Clock_get_calibration); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_get_calibration)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "clock");
    {
	GstClock *	clock = SvGstClock (ST(0))
;
	GstClockTime	internal;
	GstClockTime	external;
	GstClockTime	rate_num;
	GstClockTime	rate_denom;

	gst_clock_get_calibration(clock, &internal, &external, &rate_num, &rate_denom);
	XSprePUSH;	EXTEND(SP,4);
	PUSHs(sv_newmortal());
	ST(0) = newSVGstClockTime (internal);
	PUSHs(sv_newmortal());
	ST(1) = newSVGstClockTime (external);
	PUSHs(sv_newmortal());
	ST(2) = newSVGstClockTime (rate_num);
	PUSHs(sv_newmortal());
	ST(3) = newSVGstClockTime (rate_denom);
    }
    XSRETURN(4);
}


XS_EUPXS(XS_GStreamer__Clock_set_master); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_set_master)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "clock, master");
    {
	gboolean	RETVAL;
	GstClock *	clock = SvGstClock (ST(0))
;
	GstClock *	master = SvGstClock (ST(1))
;

	RETVAL = gst_clock_set_master(/* We need to keep master alive. */
	clock, gst_object_ref (master));
	ST(0) = boolSV(RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GStreamer__Clock_get_master); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_get_master)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "clock");
    {
	GstClock_ornull *	RETVAL;
	GstClock *	clock = SvGstClock (ST(0))
;

	RETVAL = gst_clock_get_master(clock);
	ST(0) = newSVGstClock_ornull (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GStreamer__Clock_add_observation); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_add_observation)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "clock, slave, master");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
#line 155 "xs/GstClock.xs"
	gboolean retval;
	gdouble r_squared;
#line 446 "xs/GstClock.c"
	GstClock *	clock = SvGstClock (ST(0))
;
	GstClockTime	slave = SvGstClockTime (ST(1))
;
	GstClockTime	master = SvGstClockTime (ST(2))
;
#line 158 "xs/GstClock.xs"
	retval = gst_clock_add_observation (clock, slave, master, &r_squared);
	EXTEND (sp, 2);
	PUSHs (sv_2mortal (newSVuv (retval)));
	PUSHs (sv_2mortal (newSVnv (r_squared)));
#line 458 "xs/GstClock.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_GStreamer__Clock_get_internal_time); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_get_internal_time)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "clock");
    {
	GstClockTime	RETVAL;
	GstClock *	clock = SvGstClock (ST(0))
;

	RETVAL = gst_clock_get_internal_time(clock);
	ST(0) = newSVGstClockTime (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GStreamer__Clock_adjust_unlocked); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_adjust_unlocked)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "clock, internal");
    {
	GstClockTime	RETVAL;
	GstClock *	clock = SvGstClock (ST(0))
;
	GstClockTime	internal = SvGstClockTime (ST(1))
;

	RETVAL = gst_clock_adjust_unlocked(clock, internal);
	ST(0) = newSVGstClockTime (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GStreamer__Clock_new_single_shot_id); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_new_single_shot_id)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "clock, time");
    {
	GstClockID	RETVAL;
	GstClock *	clock = SvGstClock (ST(0))
;
	GstClockTime	time = SvGstClockTime (ST(1))
;

	RETVAL = gst_clock_new_single_shot_id(clock, time);
	ST(0) = newSVGstClockID (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GStreamer__Clock_new_periodic_id); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__Clock_new_periodic_id)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "clock, start_time, interval");
    {
	GstClockID	RETVAL;
	GstClock *	clock = SvGstClock (ST(0))
;
	GstClockTime	start_time = SvGstClockTime (ST(1))
;
	GstClockTime	interval = SvGstClockTime (ST(2))
;

	RETVAL = gst_clock_new_periodic_id(clock, start_time, interval);
	ST(0) = newSVGstClockID (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GStreamer__ClockID_DESTROY); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__ClockID_DESTROY)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "id");
    {
	GstClockID	id = SvGstClockID (ST(0))
;
#line 179 "xs/GstClock.xs"
	gst_clock_id_unref (id);
#line 560 "xs/GstClock.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_GStreamer__ClockID_get_time); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__ClockID_get_time)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "id");
    {
	GstClockTime	RETVAL;
	GstClockID	id = SvGstClockID (ST(0))
;

	RETVAL = gst_clock_id_get_time(id);
	ST(0) = newSVGstClockTime (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GStreamer__ClockID_wait); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__ClockID_wait)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "id");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	GstClockID	id = SvGstClockID (ST(0))
;
#line 192 "xs/GstClock.xs"
	GstClockReturn retval = 0;
	GstClockTimeDiff jitter = 0;
#line 599 "xs/GstClock.c"
#line 195 "xs/GstClock.xs"
	retval = gst_clock_id_wait (id, &jitter);
	EXTEND (sp, 2);
	PUSHs (sv_2mortal (newSVGstClockReturn (retval)));
	PUSHs (sv_2mortal (newSVGstClockTime (jitter)));
#line 605 "xs/GstClock.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_GStreamer__ClockID_wait_async); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__ClockID_wait_async)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "id, func, data=NULL");
    {
	GstClockID	id = SvGstClockID (ST(0))
;
	SV *	func = ST(1)
;
	SV *	data;
#line 207 "xs/GstClock.xs"
	GPerlCallback *callback;
#line 626 "xs/GstClock.c"
	GstClockReturn	RETVAL;

	if (items < 3)
	    data = NULL;
	else {
	    data = ST(2)
;
	}
#line 209 "xs/GstClock.xs"
	callback = gst2perl_clock_callback_create (func, data);
	RETVAL = gst_clock_id_wait_async (id,
	                                  gst2perl_clock_callback,
	                                  callback);
	/* FIXME: When to free the callback? */
#line 641 "xs/GstClock.c"
	ST(0) = newSVGstClockReturn (RETVAL);
	sv_2mortal(ST(0));
    }
    XSRETURN(1);
}


XS_EUPXS(XS_GStreamer__ClockID_unschedule); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_GStreamer__ClockID_unschedule)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "id");
    {
	GstClockID	id = SvGstClockID (ST(0))
;

	gst_clock_id_unschedule(id);
    }
    XSRETURN_EMPTY;
}

#ifdef __cplusplus
extern "C"
#endif
XS_EXTERNAL(boot_GStreamer__Clock); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_GStreamer__Clock)
{
    dVAR; dXSARGS;
#if (PERL_REVISION == 5 && PERL_VERSION < 9)
    char* file = __FILE__;
#else
    const char* file = __FILE__;
#endif

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
#ifdef XS_APIVERSION_BOOTCHECK
    XS_APIVERSION_BOOTCHECK;
#endif
    XS_VERSION_BOOTCHECK;

        newXS("GStreamer::Clock::set_resolution", XS_GStreamer__Clock_set_resolution, file);
        newXS("GStreamer::Clock::get_resolution", XS_GStreamer__Clock_get_resolution, file);
        newXS("GStreamer::Clock::get_time", XS_GStreamer__Clock_get_time, file);
        newXS("GStreamer::Clock::set_calibration", XS_GStreamer__Clock_set_calibration, file);
        newXS("GStreamer::Clock::get_calibration", XS_GStreamer__Clock_get_calibration, file);
        newXS("GStreamer::Clock::set_master", XS_GStreamer__Clock_set_master, file);
        newXS("GStreamer::Clock::get_master", XS_GStreamer__Clock_get_master, file);
        newXS("GStreamer::Clock::add_observation", XS_GStreamer__Clock_add_observation, file);
        newXS("GStreamer::Clock::get_internal_time", XS_GStreamer__Clock_get_internal_time, file);
        newXS("GStreamer::Clock::adjust_unlocked", XS_GStreamer__Clock_adjust_unlocked, file);
        newXS("GStreamer::Clock::new_single_shot_id", XS_GStreamer__Clock_new_single_shot_id, file);
        newXS("GStreamer::Clock::new_periodic_id", XS_GStreamer__Clock_new_periodic_id, file);
        newXS("GStreamer::ClockID::DESTROY", XS_GStreamer__ClockID_DESTROY, file);
        newXS("GStreamer::ClockID::get_time", XS_GStreamer__ClockID_get_time, file);
        newXS("GStreamer::ClockID::wait", XS_GStreamer__ClockID_wait, file);
        newXS("GStreamer::ClockID::wait_async", XS_GStreamer__ClockID_wait_async, file);
        newXS("GStreamer::ClockID::unschedule", XS_GStreamer__ClockID_unschedule, file);

    /* Initialisation Section */

#line 131 "xs/GstClock.xs"
	gperl_object_set_no_warn_unreg_subclass (GST_TYPE_CLOCK, TRUE);

#line 707 "xs/GstClock.c"

    /* End of Initialisation Section */

#if (PERL_REVISION == 5 && PERL_VERSION >= 9)
  if (PL_unitcheckav)
       call_list(PL_scopestack_ix, PL_unitcheckav);
#endif
    XSRETURN_YES;
}

