tizen beta release
[profile/ivi/gst-openmax0.10.git] / omx / gstomx_mpeg4enc.c
1 /*
2  * Copyright (C) 2007-2009 Nokia Corporation.
3  *
4  * Author: Felipe Contreras <felipe.contreras@nokia.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation
9  * version 2.1 of the License.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #include "gstomx_mpeg4enc.h"
23 #include "gstomx.h"
24
25 GSTOMX_BOILERPLATE (GstOmxMpeg4Enc, gst_omx_mpeg4enc, GstOmxBaseVideoEnc,
26     GST_OMX_BASE_VIDEOENC_TYPE);
27
28 static void
29 type_base_init (gpointer g_class)
30 {
31   GstElementClass *element_class;
32
33   element_class = GST_ELEMENT_CLASS (g_class);
34
35   gst_element_class_set_details_simple (element_class,
36       "OpenMAX IL MPEG-4 video encoder",
37       "Codec/Encoder/Video",
38       "Encodes video in MPEG-4 format with OpenMAX IL", "Felipe Contreras");
39
40   gst_element_class_add_pad_template (element_class,
41       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
42           gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
43
44   gst_element_class_add_pad_template (element_class,
45       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
46           gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
47 }
48
49 static void
50 type_class_init (gpointer g_class, gpointer class_data)
51 {
52 }
53
54 static void
55 settings_changed_cb (GOmxCore * core)
56 {
57   GstOmxBaseVideoEnc *omx_base;
58   GstOmxBaseFilter *omx_base_filter;
59   guint width;
60   guint height;
61
62   omx_base_filter = core->object;
63   omx_base = GST_OMX_BASE_VIDEOENC (omx_base_filter);
64
65   GST_DEBUG_OBJECT (omx_base, "settings changed");
66
67   {
68     OMX_PARAM_PORTDEFINITIONTYPE param;
69
70     G_OMX_INIT_PARAM (param);
71
72     param.nPortIndex = omx_base_filter->out_port->port_index;
73     OMX_GetParameter (core->omx_handle, OMX_IndexParamPortDefinition, &param);
74
75     width = param.format.video.nFrameWidth;
76     height = param.format.video.nFrameHeight;
77   }
78
79   {
80     GstCaps *new_caps;
81
82     new_caps = gst_caps_new_simple ("video/mpeg",
83         "mpegversion", G_TYPE_INT, 4,
84         "width", G_TYPE_INT, width,
85         "height", G_TYPE_INT, height,
86         "framerate", GST_TYPE_FRACTION,
87         omx_base->framerate_num, omx_base->framerate_denom,
88         "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
89
90     GST_INFO_OBJECT (omx_base, "caps are: %" GST_PTR_FORMAT, new_caps);
91     gst_pad_set_caps (omx_base_filter->srcpad, new_caps);
92   }
93 }
94
95 static void
96 type_instance_init (GTypeInstance * instance, gpointer g_class)
97 {
98   GstOmxBaseFilter *omx_base_filter;
99   GstOmxBaseVideoEnc *omx_base;
100
101   omx_base_filter = GST_OMX_BASE_FILTER (instance);
102   omx_base = GST_OMX_BASE_VIDEOENC (instance);
103
104   omx_base->compression_format = OMX_VIDEO_CodingMPEG4;
105
106   omx_base_filter->gomx->settings_changed_cb = settings_changed_cb;
107 }