/* rygel-avc-transcoder.c generated by valac 0.56.1, the Vala compiler
 * generated from rygel-avc-transcoder.vala, do not modify */

/*
 * Copyright (C) 2011 Nokia Corporation.
 * Copyright (C) 2013 Cable Television Laboratories, Inc.
 *
 * Author: Luis de Bethencourt <luis.debethencourt@collabora.com>
 *         Prasanna Modem <prasanna@ecaspia.com>
 *
 * This file is part of Rygel.
 *
 * Rygel 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.
 *
 * Rygel 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
 */

#include <glib-object.h>
#include "rygel-server.h"
#include <glib.h>
#include <gst/pbutils/pbutils.h>
#include <gst/gst.h>
#include <stdlib.h>
#include <string.h>
#include "rygel-media-engine-gst.h"

#define RYGEL_AVC_TRANSCODER_VIDEO_BITRATE 1200
#define RYGEL_AVC_TRANSCODER_AUDIO_BITRATE 64
#define RYGEL_AVC_TRANSCODER_CONTAINER "video/quicktime,variant=iso"
#define RYGEL_AVC_TRANSCODER_AUDIO_CAPS "audio/mpeg,mpegversion=4"
#define RYGEL_AVC_TRANSCODER_VIDEO_CAPS "video/x-h264,stream-format=avc"
#define RYGEL_AVC_TRANSCODER_RESTRICTIONS "video/x-raw,framerate=(fraction)15/1,width=352,height=288"
#define RYGEL_AVC_TRANSCODER_NAME "AVC_MP4_BL_CIF15_AAC_520"

#define RYGEL_TYPE_GST_TRANSCODER (rygel_gst_transcoder_get_type ())
#define RYGEL_GST_TRANSCODER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_GST_TRANSCODER, RygelGstTranscoder))
#define RYGEL_GST_TRANSCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_GST_TRANSCODER, RygelGstTranscoderClass))
#define RYGEL_IS_GST_TRANSCODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_GST_TRANSCODER))
#define RYGEL_IS_GST_TRANSCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_GST_TRANSCODER))
#define RYGEL_GST_TRANSCODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_GST_TRANSCODER, RygelGstTranscoderClass))

typedef struct _RygelGstTranscoder RygelGstTranscoder;
typedef struct _RygelGstTranscoderClass RygelGstTranscoderClass;
typedef struct _RygelGstTranscoderPrivate RygelGstTranscoderPrivate;

#define RYGEL_TYPE_AUDIO_TRANSCODER (rygel_audio_transcoder_get_type ())
#define RYGEL_AUDIO_TRANSCODER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_AUDIO_TRANSCODER, RygelAudioTranscoder))
#define RYGEL_AUDIO_TRANSCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_AUDIO_TRANSCODER, RygelAudioTranscoderClass))
#define RYGEL_IS_AUDIO_TRANSCODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_AUDIO_TRANSCODER))
#define RYGEL_IS_AUDIO_TRANSCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_AUDIO_TRANSCODER))
#define RYGEL_AUDIO_TRANSCODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_AUDIO_TRANSCODER, RygelAudioTranscoderClass))

typedef struct _RygelAudioTranscoder RygelAudioTranscoder;
typedef struct _RygelAudioTranscoderClass RygelAudioTranscoderClass;
typedef struct _RygelAudioTranscoderPrivate RygelAudioTranscoderPrivate;

#define RYGEL_TYPE_VIDEO_TRANSCODER (rygel_video_transcoder_get_type ())
#define RYGEL_VIDEO_TRANSCODER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_VIDEO_TRANSCODER, RygelVideoTranscoder))
#define RYGEL_VIDEO_TRANSCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_VIDEO_TRANSCODER, RygelVideoTranscoderClass))
#define RYGEL_IS_VIDEO_TRANSCODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_VIDEO_TRANSCODER))
#define RYGEL_IS_VIDEO_TRANSCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_VIDEO_TRANSCODER))
#define RYGEL_VIDEO_TRANSCODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_VIDEO_TRANSCODER, RygelVideoTranscoderClass))

typedef struct _RygelVideoTranscoder RygelVideoTranscoder;
typedef struct _RygelVideoTranscoderClass RygelVideoTranscoderClass;
typedef struct _RygelVideoTranscoderPrivate RygelVideoTranscoderPrivate;

#define RYGEL_TYPE_AVC_TRANSCODER (rygel_avc_transcoder_get_type ())
#define RYGEL_AVC_TRANSCODER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_AVC_TRANSCODER, RygelAVCTranscoder))
#define RYGEL_AVC_TRANSCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_AVC_TRANSCODER, RygelAVCTranscoderClass))
#define RYGEL_IS_AVC_TRANSCODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_AVC_TRANSCODER))
#define RYGEL_IS_AVC_TRANSCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_AVC_TRANSCODER))
#define RYGEL_AVC_TRANSCODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_AVC_TRANSCODER, RygelAVCTranscoderClass))

typedef struct _RygelAVCTranscoder RygelAVCTranscoder;
typedef struct _RygelAVCTranscoderClass RygelAVCTranscoderClass;
typedef struct _RygelAVCTranscoderPrivate RygelAVCTranscoderPrivate;
enum  {
	RYGEL_AVC_TRANSCODER_0_PROPERTY,
	RYGEL_AVC_TRANSCODER_NUM_PROPERTIES
};
static GParamSpec* rygel_avc_transcoder_properties[RYGEL_AVC_TRANSCODER_NUM_PROPERTIES];

struct _RygelGstTranscoder {
	GObject parent_instance;
	RygelGstTranscoderPrivate * priv;
};

struct _RygelGstTranscoderClass {
	GObjectClass parent_class;
	RygelMediaResource* (*get_resource_for_item) (RygelGstTranscoder* self, RygelMediaFileItem* item);
	guint (*get_distance) (RygelGstTranscoder* self, RygelMediaFileItem* item);
	GstEncodingProfile* (*get_encoding_profile) (RygelGstTranscoder* self, RygelMediaFileItem* item);
};

struct _RygelAudioTranscoder {
	RygelGstTranscoder parent_instance;
	RygelAudioTranscoderPrivate * priv;
	gint audio_bitrate;
	GstCaps* container_format;
	GstCaps* audio_codec_format;
};

struct _RygelAudioTranscoderClass {
	RygelGstTranscoderClass parent_class;
};

struct _RygelVideoTranscoder {
	RygelAudioTranscoder parent_instance;
	RygelVideoTranscoderPrivate * priv;
};

struct _RygelVideoTranscoderClass {
	RygelAudioTranscoderClass parent_class;
};

struct _RygelAVCTranscoder {
	RygelVideoTranscoder parent_instance;
	RygelAVCTranscoderPrivate * priv;
};

struct _RygelAVCTranscoderClass {
	RygelVideoTranscoderClass parent_class;
};

static gpointer rygel_avc_transcoder_parent_class = NULL;

VALA_EXTERN GType rygel_gst_transcoder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType rygel_audio_transcoder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType rygel_video_transcoder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType rygel_avc_transcoder_get_type (void) G_GNUC_CONST ;
VALA_EXTERN RygelAVCTranscoder* rygel_avc_transcoder_new (void);
VALA_EXTERN RygelAVCTranscoder* rygel_avc_transcoder_construct (GType object_type);
VALA_EXTERN RygelVideoTranscoder* rygel_video_transcoder_construct (GType object_type,
                                                        const gchar* name,
                                                        const gchar* content_type,
                                                        const gchar* dlna_profile,
                                                        gint audio_bitrate,
                                                        gint video_bitrate,
                                                        const gchar* container_caps,
                                                        const gchar* audio_codec_caps,
                                                        const gchar* video_codec_caps,
                                                        const gchar* extension,
                                                        const gchar* restrictions);
VALA_EXTERN void rygel_gst_transcoder_set_preset (RygelGstTranscoder* self,
                                      const gchar* value);
static GType rygel_avc_transcoder_get_type_once (void);

RygelAVCTranscoder*
rygel_avc_transcoder_construct (GType object_type)
{
	RygelAVCTranscoder * self = NULL;
	self = (RygelAVCTranscoder*) rygel_video_transcoder_construct (object_type, RYGEL_AVC_TRANSCODER_NAME, "video/mp4", RYGEL_AVC_TRANSCODER_NAME, RYGEL_AVC_TRANSCODER_AUDIO_BITRATE, RYGEL_AVC_TRANSCODER_VIDEO_BITRATE, RYGEL_AVC_TRANSCODER_CONTAINER, RYGEL_AVC_TRANSCODER_AUDIO_CAPS, RYGEL_AVC_TRANSCODER_VIDEO_CAPS, "mp4", RYGEL_AVC_TRANSCODER_RESTRICTIONS);
	rygel_gst_transcoder_set_preset ((RygelGstTranscoder*) self, "Rygel AVC_MP4_BL_CIF15_AAC_520 preset");
	return self;
}

RygelAVCTranscoder*
rygel_avc_transcoder_new (void)
{
	return rygel_avc_transcoder_construct (RYGEL_TYPE_AVC_TRANSCODER);
}

static void
rygel_avc_transcoder_class_init (RygelAVCTranscoderClass * klass,
                                 gpointer klass_data)
{
	rygel_avc_transcoder_parent_class = g_type_class_peek_parent (klass);
}

static void
rygel_avc_transcoder_instance_init (RygelAVCTranscoder * self,
                                    gpointer klass)
{
}

/**
 * Transcoder for H.264 in MP4 conforming to DLNA profile
 * AVC_MP4_BL_CIF15_AAC_520 (15 fps, CIF resolution)
 */
static GType
rygel_avc_transcoder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelAVCTranscoderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_avc_transcoder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelAVCTranscoder), 0, (GInstanceInitFunc) rygel_avc_transcoder_instance_init, NULL };
	GType rygel_avc_transcoder_type_id;
	rygel_avc_transcoder_type_id = g_type_register_static (RYGEL_TYPE_VIDEO_TRANSCODER, "RygelAVCTranscoder", &g_define_type_info, 0);
	return rygel_avc_transcoder_type_id;
}

GType
rygel_avc_transcoder_get_type (void)
{
	static volatile gsize rygel_avc_transcoder_type_id__once = 0;
	if (g_once_init_enter (&rygel_avc_transcoder_type_id__once)) {
		GType rygel_avc_transcoder_type_id;
		rygel_avc_transcoder_type_id = rygel_avc_transcoder_get_type_once ();
		g_once_init_leave (&rygel_avc_transcoder_type_id__once, rygel_avc_transcoder_type_id);
	}
	return rygel_avc_transcoder_type_id__once;
}

