1 /* GStreamer Cpu Report Element
2 * Copyright (C) <2010> Zaheer Abbas Merali <zaheerabbas merali org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
29 #include "cpureport.h"
37 GstStaticPadTemplate cpu_report_src_template = GST_STATIC_PAD_TEMPLATE ("src",
42 GstStaticPadTemplate cpu_report_sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
47 static GstFlowReturn gst_cpu_report_transform_ip (GstBaseTransform * trans,
50 static gboolean gst_cpu_report_start (GstBaseTransform * trans);
51 static gboolean gst_cpu_report_stop (GstBaseTransform * trans);
53 GST_BOILERPLATE (GstCpuReport, gst_cpu_report, GstBaseTransform,
54 GST_TYPE_BASE_TRANSFORM);
57 gst_cpu_report_base_init (gpointer g_class)
59 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
61 gst_element_class_add_static_pad_template (element_class,
62 &cpu_report_sink_template);
63 gst_element_class_add_static_pad_template (element_class,
64 &cpu_report_src_template);
66 gst_element_class_set_details_simple (element_class, "CPU report",
68 "Post cpu usage information every buffer",
69 "Zaheer Abbas Merali <zaheerabbas at merali dot org>");
73 gst_cpu_report_finalize (GObject * obj)
75 G_OBJECT_CLASS (parent_class)->finalize (obj);
79 gst_cpu_report_class_init (GstCpuReportClass * g_class)
81 GstBaseTransformClass *gstbasetrans_class;
82 GObjectClass *gobject_class;
84 gobject_class = G_OBJECT_CLASS (g_class);
85 gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (g_class);
87 gobject_class->finalize = gst_cpu_report_finalize;
89 gstbasetrans_class->transform_ip =
90 GST_DEBUG_FUNCPTR (gst_cpu_report_transform_ip);
91 gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_cpu_report_start);
92 gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_cpu_report_stop);
96 gst_cpu_report_init (GstCpuReport * report, GstCpuReportClass * g_class)
98 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (report), TRUE);
103 gst_cpu_report_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
105 GstCpuReport *filter;
107 clock_t cur_cpu_time;
113 g_get_current_time (&cur_time);
114 cur_cpu_time = clock ();
116 filter = GST_CPU_REPORT (trans);
119 time_taken = GST_TIMEVAL_TO_TIME (cur_time) -
120 GST_TIMEVAL_TO_TIME (filter->last_time);
122 s = gst_structure_new ("cpu-report", "cpu-time", G_TYPE_DOUBLE,
123 ((gdouble) (cur_cpu_time - filter->last_cpu_time)),
124 "actual-time", G_TYPE_INT64, time_taken, "buffer-time", G_TYPE_INT64,
125 GST_BUFFER_TIMESTAMP (buf), NULL);
126 msg = gst_message_new_element (GST_OBJECT_CAST (filter), s);
127 gst_element_post_message (GST_ELEMENT_CAST (filter), msg);
128 filter->last_time = cur_time;
129 filter->last_cpu_time = cur_cpu_time;
136 gst_cpu_report_start (GstBaseTransform * trans)
138 GstCpuReport *filter;
140 filter = GST_CPU_REPORT (trans);
142 g_get_current_time (&filter->last_time);
143 filter->start_time = filter->last_time;
144 filter->last_cpu_time = clock ();
149 gst_cpu_report_stop (GstBaseTransform * trans)
151 /* anything we should be doing here? */