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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, 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 #define gst_cpu_report_parent_class parent_class
54 G_DEFINE_TYPE (GstCpuReport, gst_cpu_report, GST_TYPE_BASE_TRANSFORM);
57 gst_cpu_report_finalize (GObject * obj)
59 G_OBJECT_CLASS (parent_class)->finalize (obj);
63 gst_cpu_report_class_init (GstCpuReportClass * g_class)
65 GstBaseTransformClass *gstbasetrans_class;
66 GstElementClass *element_class;
67 GObjectClass *gobject_class;
69 gobject_class = G_OBJECT_CLASS (g_class);
70 element_class = GST_ELEMENT_CLASS (g_class);
71 gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (g_class);
73 gobject_class->finalize = gst_cpu_report_finalize;
75 gst_element_class_add_static_pad_template (element_class,
76 &cpu_report_sink_template);
77 gst_element_class_add_static_pad_template (element_class,
78 &cpu_report_src_template);
80 gst_element_class_set_static_metadata (element_class, "CPU report",
82 "Post cpu usage information every buffer",
83 "Zaheer Abbas Merali <zaheerabbas at merali dot org>");
85 gstbasetrans_class->transform_ip =
86 GST_DEBUG_FUNCPTR (gst_cpu_report_transform_ip);
87 gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_cpu_report_start);
88 gstbasetrans_class->stop = GST_DEBUG_FUNCPTR (gst_cpu_report_stop);
92 gst_cpu_report_init (GstCpuReport * report)
94 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (report), TRUE);
99 gst_cpu_report_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
101 GstCpuReport *filter;
103 clock_t cur_cpu_time;
109 g_get_current_time (&cur_time);
110 cur_cpu_time = clock ();
112 filter = GST_CPU_REPORT (trans);
115 time_taken = GST_TIMEVAL_TO_TIME (cur_time) -
116 GST_TIMEVAL_TO_TIME (filter->last_time);
118 s = gst_structure_new ("cpu-report", "cpu-time", G_TYPE_DOUBLE,
119 ((gdouble) (cur_cpu_time - filter->last_cpu_time)),
120 "actual-time", G_TYPE_INT64, time_taken, "buffer-time", G_TYPE_INT64,
121 GST_BUFFER_TIMESTAMP (buf), NULL);
122 msg = gst_message_new_element (GST_OBJECT_CAST (filter), s);
123 gst_element_post_message (GST_ELEMENT_CAST (filter), msg);
124 filter->last_time = cur_time;
125 filter->last_cpu_time = cur_cpu_time;
132 gst_cpu_report_start (GstBaseTransform * trans)
134 GstCpuReport *filter;
136 filter = GST_CPU_REPORT (trans);
138 g_get_current_time (&filter->last_time);
139 filter->start_time = filter->last_time;
140 filter->last_cpu_time = clock ();
145 gst_cpu_report_stop (GstBaseTransform * trans)
147 /* anything we should be doing here? */