adder: add a tests for the aggregation of durations
[platform/upstream/gstreamer.git] / ext / libvisual / gstaudiobasevisualizer.h
1 /* GStreamer
2  * Copyright (C) <2011> Stefan Kost <ensonic@users.sf.net>
3  *
4  * gstaudiobasevisualizer.c: base class for audio visualisation elements
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __GST_AUDIO_BASE_VISUALIZER_H__
22 #define __GST_AUDIO_BASE_VISUALIZER_H__
23
24 #include <gst/gst.h>
25 #include <gst/base/gstbasetransform.h>
26
27 #include <gst/video/video.h>
28 #include <gst/audio/audio.h>
29 #include <gst/base/gstadapter.h>
30
31 G_BEGIN_DECLS
32 #define GST_TYPE_AUDIO_BASE_VISUALIZER            (gst_audio_base_visualizer_get_type())
33 #define GST_AUDIO_BASE_VISUALIZER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_BASE_VISUALIZER,GstAudioBaseVisualizer))
34 #define GST_AUDIO_BASE_VISUALIZER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_BASE_VISUALIZER,GstAudioBaseVisualizerClass))
35 #define GST_IS_SYNAESTHESIA(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_BASE_VISUALIZER))
36 #define GST_IS_SYNAESTHESIA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_BASE_VISUALIZER))
37 typedef struct _GstAudioBaseVisualizer GstAudioBaseVisualizer;
38 typedef struct _GstAudioBaseVisualizerClass GstAudioBaseVisualizerClass;
39
40 typedef void (*GstAudioBaseVisualizerShaderFunc)(GstAudioBaseVisualizer *scope, const guint8 *s, guint8 *d);
41
42 /**
43  * GstAudioBaseVisualizerShader:
44  * @GST_AUDIO_BASE_VISUALIZER_SHADER_NONE: no shading
45  * @GST_AUDIO_BASE_VISUALIZER_SHADER_FADE: plain fading
46  * @GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_UP: fade and move up
47  * @GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_DOWN: fade and move down
48  * @GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_LEFT: fade and move left
49  * @GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_RIGHT: fade and move right
50  * @GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_OUT: fade and move horizontally out
51  * @GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_IN: fade and move horizontally in
52  * @GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_OUT: fade and move vertically out
53  * @GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_IN: fade and move vertically in
54  *
55  * Different types of supported background shading functions.
56  */
57 typedef enum {
58   GST_AUDIO_BASE_VISUALIZER_SHADER_NONE,
59   GST_AUDIO_BASE_VISUALIZER_SHADER_FADE,
60   GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_UP,
61   GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_DOWN,
62   GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_LEFT,
63   GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_RIGHT,
64   GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_OUT,
65   GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_HORIZ_IN,
66   GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_OUT,
67   GST_AUDIO_BASE_VISUALIZER_SHADER_FADE_AND_MOVE_VERT_IN
68 } GstAudioBaseVisualizerShader;
69
70 struct _GstAudioBaseVisualizer
71 {
72   GstElement parent;
73
74   /* pads */
75   GstPad *srcpad, *sinkpad;
76
77   GstBufferPool *pool;
78   GstAdapter *adapter;
79   GstBuffer *inbuf;
80   guint8 *pixelbuf;
81
82   GstAudioBaseVisualizerShader shader_type;
83   GstAudioBaseVisualizerShaderFunc shader;
84   guint32 shade_amount;
85
86   guint spf;                    /* samples per video frame */
87   guint req_spf;                /* min samples per frame wanted by the subclass */
88
89   /* video state */
90   GstVideoInfo vinfo;
91   GstVideoFormat video_format;
92   gint fps_n, fps_d;
93   gint width;
94   gint height;
95   guint64 frame_duration;
96   guint bpf;                    /* bytes per frame */
97
98   /* audio state */
99   GstAudioInfo ainfo;
100
101   /* configuration mutex */
102   GMutex config_lock;
103   
104   /* QoS stuff *//* with LOCK */
105   gdouble proportion;
106   GstClockTime earliest_time;
107   
108   GstSegment segment;
109 };
110
111 struct _GstAudioBaseVisualizerClass
112 {
113   GstElementClass parent_class;
114
115   /* virtual function, called whenever the format changes */
116   gboolean (*setup) (GstAudioBaseVisualizer * scope);
117
118   /* virtual function for rendering a frame */
119   gboolean (*render) (GstAudioBaseVisualizer * scope, GstBuffer * audio, GstBuffer * video);
120 };
121
122 GType gst_audio_base_visualizer_get_type (void);
123
124 G_END_DECLS
125 #endif /* __GST_AUDIO_BASE_VISUALIZER_H__ */