gst/synaesthesia/: More source cleanups and add FIXME comments.

Original commit message from CVS:
* gst/synaesthesia/gstsynaesthesia.c: (gst_synaesthesia_init),
(gst_synaesthesia_sink_setcaps), (gst_synaesthesia_src_getcaps),
(gst_synaesthesia_src_setcaps), (gst_synaesthesia_chain),
(plugin_init):
* gst/synaesthesia/synaescope.c: (synaescope_coreGo),
(synaescope8):
More source cleanups and add FIXME comments.
This commit is contained in:
Stefan Kost 2007-02-12 12:46:20 +00:00
parent d094953671
commit 45542b7376
3 changed files with 121 additions and 69 deletions

View file

@ -1,3 +1,13 @@
2007-02-12 Stefan Kost <ensonic@users.sf.net>
* gst/synaesthesia/gstsynaesthesia.c: (gst_synaesthesia_init),
(gst_synaesthesia_sink_setcaps), (gst_synaesthesia_src_getcaps),
(gst_synaesthesia_src_setcaps), (gst_synaesthesia_chain),
(plugin_init):
* gst/synaesthesia/synaescope.c: (synaescope_coreGo),
(synaescope8):
More source cleanups and add FIXME comments.
2007-02-11 Sébastien Moutte <sebastien@moutte.net> 2007-02-11 Sébastien Moutte <sebastien@moutte.net>
* gst/realmedia/rmdemux.c:(gst_rmdemux_parse_indx_data): * gst/realmedia/rmdemux.c:(gst_rmdemux_parse_indx_data):

View file

@ -69,19 +69,23 @@ struct _GstSynaesthesia
GstPad *sinkpad, *srcpad; GstPad *sinkpad, *srcpad;
GstAdapter *adapter; GstAdapter *adapter;
/* the timestamp of the next frame */ guint64 audio_basetime; /* the timestamp of the next frame */
guint64 audio_basetime; guint64 frame_duration;
guint bps; /* bytes per sample */
guint spf; /* samples per video frame */
guint64 samples_consumed; guint64 samples_consumed;
gint16 datain[2][SYNAES_SAMPLES]; gint16 datain[2][SYNAES_SAMPLES];
/* video state */ /* video state */
gdouble fps; gint fps_n, fps_d;
gint width; gint width;
gint height; gint height;
gint channels; gint channels;
/* Audio state */ /* Audio state */
gint sample_rate; gint rate;
}; };
struct _GstSynaesthesiaClass struct _GstSynaesthesiaClass
@ -200,17 +204,18 @@ gst_synaesthesia_init (GstSynaesthesia * synaesthesia)
synaesthesia->sinkpad = synaesthesia->sinkpad =
gst_pad_new_from_static_template (&gst_synaesthesia_sink_template, gst_pad_new_from_static_template (&gst_synaesthesia_sink_template,
"sink"); "sink");
gst_pad_set_chain_function (synaesthesia->sinkpad, gst_synaesthesia_chain); gst_pad_set_chain_function (synaesthesia->sinkpad,
GST_DEBUG_FUNCPTR (gst_synaesthesia_chain));
gst_pad_set_setcaps_function (synaesthesia->sinkpad, gst_pad_set_setcaps_function (synaesthesia->sinkpad,
gst_synaesthesia_sink_setcaps); GST_DEBUG_FUNCPTR (gst_synaesthesia_sink_setcaps));
gst_element_add_pad (GST_ELEMENT (synaesthesia), synaesthesia->sinkpad); gst_element_add_pad (GST_ELEMENT (synaesthesia), synaesthesia->sinkpad);
synaesthesia->srcpad = synaesthesia->srcpad =
gst_pad_new_from_static_template (&gst_synaesthesia_src_template, "src"); gst_pad_new_from_static_template (&gst_synaesthesia_src_template, "src");
gst_pad_set_getcaps_function (synaesthesia->srcpad, gst_pad_set_getcaps_function (synaesthesia->srcpad,
gst_synaesthesia_src_getcaps); GST_DEBUG_FUNCPTR (gst_synaesthesia_src_getcaps));
gst_pad_set_setcaps_function (synaesthesia->srcpad, gst_pad_set_setcaps_function (synaesthesia->srcpad,
gst_synaesthesia_src_setcaps); GST_DEBUG_FUNCPTR (gst_synaesthesia_src_setcaps));
gst_element_add_pad (GST_ELEMENT (synaesthesia), synaesthesia->srcpad); gst_element_add_pad (GST_ELEMENT (synaesthesia), synaesthesia->srcpad);
synaesthesia->adapter = gst_adapter_new (); synaesthesia->adapter = gst_adapter_new ();
@ -218,14 +223,21 @@ gst_synaesthesia_init (GstSynaesthesia * synaesthesia)
/* reset the initial video state */ /* reset the initial video state */
synaesthesia->width = SYNAES_WIDTH; synaesthesia->width = SYNAES_WIDTH;
synaesthesia->height = SYNAES_HEIGHT; synaesthesia->height = SYNAES_HEIGHT;
synaesthesia->fps = 25.0; /* desired frame rate */ synaesthesia->fps_n = 25; /* desired frame rate */
synaesthesia->fps_d = 1;
synaesthesia->frame_duration = -1;
synaesthesia->sample_rate = 0; /* reset the initial audio state */
synaesthesia->rate = GST_AUDIO_DEF_RATE;
synaesthesia->channels = 2; synaesthesia->channels = 2;
synaesthesia->audio_basetime = GST_CLOCK_TIME_NONE; synaesthesia->audio_basetime = GST_CLOCK_TIME_NONE;
synaesthesia->samples_consumed = 0; synaesthesia->samples_consumed = 0;
/* FIXME: this isn't used by the engine, the size is hardcoded there again
* we also need to initialize once we negotiated
* the we can also supply spf (samples_per_frame)
*/
synaesthesia_init (synaesthesia->width, synaesthesia->height); synaesthesia_init (synaesthesia->width, synaesthesia->height);
} }
@ -272,10 +284,15 @@ gst_synaesthesia_sink_setcaps (GstPad * pad, GstCaps * caps)
!gst_structure_get_int (structure, "rate", &rate)) !gst_structure_get_int (structure, "rate", &rate))
goto missing_caps_details; goto missing_caps_details;
if (synaesthesia->channels != 2) if (channels != 2)
goto wrong_channels; goto wrong_channels;
synaesthesia->sample_rate = rate; if (rate <= 0)
goto wrong_rate;
synaesthesia->channels = channels;
synaesthesia->rate = rate;
done: done:
gst_object_unref (synaesthesia); gst_object_unref (synaesthesia);
@ -287,7 +304,11 @@ missing_caps_details:
res = FALSE; res = FALSE;
goto done; goto done;
wrong_channels: wrong_channels:
GST_WARNING ("channesl must be 2, but are %d", channels); GST_WARNING ("number of channels must be 2, but is %d", channels);
res = FALSE;
goto done;
wrong_rate:
GST_WARNING ("sample rate must be >0, but is %d", rate);
res = FALSE; res = FALSE;
goto done; goto done;
} }
@ -310,7 +331,8 @@ gst_synaesthesia_src_getcaps (GstPad * pad)
gst_structure_set (structure, gst_structure_set (structure,
"width", G_TYPE_INT, synaesthesia->width, "width", G_TYPE_INT, synaesthesia->width,
"height", G_TYPE_INT, synaesthesia->height, "height", G_TYPE_INT, synaesthesia->height,
"framerate", GST_TYPE_FRACTION, (gint) synaesthesia->fps, 1, NULL); "framerate", GST_TYPE_FRACTION, synaesthesia->fps_n,
synaesthesia->fps_d, NULL);
} }
gst_object_unref (synaesthesia); gst_object_unref (synaesthesia);
@ -326,29 +348,47 @@ gst_synaesthesia_src_setcaps (GstPad * pad, GstCaps * caps)
GstSynaesthesia *synaesthesia; GstSynaesthesia *synaesthesia;
GstStructure *structure; GstStructure *structure;
gint w, h; gint w, h;
gdouble fps; gint num, denom;
gboolean res = TRUE;
synaesthesia = GST_SYNAESTHESIA (gst_pad_get_parent (pad)); synaesthesia = GST_SYNAESTHESIA (gst_pad_get_parent (pad));
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
if (!gst_structure_get_int (structure, "width", &w) || if (!gst_structure_get_int (structure, "width", &w) ||
!gst_structure_get_int (structure, "height", &h) || !gst_structure_get_int (structure, "height", &h) ||
!gst_structure_get_double (structure, "framerate", &fps)) { !gst_structure_get_fraction (structure, "framerate", &num, &denom)) {
return GST_PAD_LINK_REFUSED; goto missing_caps_details;
} }
if ((w != SYNAES_WIDTH) || (h != SYNAES_HEIGHT)) if ((w != SYNAES_WIDTH) || (h != SYNAES_HEIGHT))
return GST_PAD_LINK_REFUSED; goto wrong_resolution;
synaesthesia->width = w; synaesthesia->width = w;
synaesthesia->height = h; synaesthesia->height = h;
synaesthesia->fps = fps; synaesthesia->fps_n = num;
synaesthesia->fps_d = denom;
synaesthesia->frame_duration = gst_util_uint64_scale_int (GST_SECOND,
synaesthesia->fps_d, synaesthesia->fps_n);
synaesthesia->spf = gst_util_uint64_scale_int (synaesthesia->rate,
synaesthesia->fps_d, synaesthesia->fps_n);
synaesthesia_init (synaesthesia->width, synaesthesia->height); synaesthesia_init (synaesthesia->width, synaesthesia->height);
done:
gst_object_unref (synaesthesia); gst_object_unref (synaesthesia);
return res;
return TRUE; /* Errors */
missing_caps_details:
GST_WARNING ("missing channels or rate in the caps");
res = FALSE;
goto done;
wrong_resolution:
GST_WARNING ("unsupported resolution: %d x %d (wanted %d x %d)",
w, h, SYNAES_WIDTH, SYNAES_HEIGHT);
res = FALSE;
goto done;
} }
static GstFlowReturn static GstFlowReturn
@ -356,8 +396,7 @@ gst_synaesthesia_chain (GstPad * pad, GstBuffer * buffer)
{ {
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GstSynaesthesia *synaesthesia; GstSynaesthesia *synaesthesia;
guint32 bytesperread; guint32 avail, bytesperread;
gint samples_per_frame;
synaesthesia = GST_SYNAESTHESIA (gst_pad_get_parent (pad)); synaesthesia = GST_SYNAESTHESIA (gst_pad_get_parent (pad));
@ -389,22 +428,26 @@ gst_synaesthesia_chain (GstPad * pad, GstBuffer * buffer)
if (synaesthesia->audio_basetime == GST_CLOCK_TIME_NONE) if (synaesthesia->audio_basetime == GST_CLOCK_TIME_NONE)
synaesthesia->audio_basetime = 0; synaesthesia->audio_basetime = 0;
bytesperread = SYNAES_SAMPLES * synaesthesia->channels * sizeof (gint16);
samples_per_frame = synaesthesia->sample_rate / synaesthesia->fps;
gst_adapter_push (synaesthesia->adapter, buffer); gst_adapter_push (synaesthesia->adapter, buffer);
while (gst_adapter_available (synaesthesia->adapter) > /* this is what we want */
bytesperread = SYNAES_SAMPLES * synaesthesia->channels * sizeof (gint16);
/* FIXME: what about:
bytesperread = MAX (SYNAES_SAMPLES, synaesthesia->spf) * synaesthesia->channels * sizeof (gint16);
*/
/* this is what we have */
avail = gst_adapter_available (synaesthesia->adapter);
while (avail >
MAX (bytesperread, MAX (bytesperread,
samples_per_frame * synaesthesia->channels * sizeof (gint16))) { synaesthesia->spf * synaesthesia->channels * sizeof (gint16))) {
const guint16 *data = const guint16 *data =
(const guint16 *) gst_adapter_peek (synaesthesia->adapter, (const guint16 *) gst_adapter_peek (synaesthesia->adapter,
bytesperread); bytesperread);
GstBuffer *outbuf; GstBuffer *outbuf;
guchar *out_frame; guchar *out_frame;
GstClockTimeDiff frame_duration = GST_SECOND / synaesthesia->fps; guint i;
gint i;
/* deinterleave */
for (i = 0; i < SYNAES_SAMPLES; i++) { for (i = 0; i < SYNAES_SAMPLES; i++) {
synaesthesia->datain[0][i] = *data++; synaesthesia->datain[0][i] = *data++;
synaesthesia->datain[1][i] = *data++; synaesthesia->datain[1][i] = *data++;
@ -422,9 +465,8 @@ gst_synaesthesia_chain (GstPad * pad, GstBuffer * buffer)
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (outbuf) =
synaesthesia->audio_basetime + synaesthesia->audio_basetime +
(GST_SECOND * synaesthesia->samples_consumed / (GST_SECOND * synaesthesia->samples_consumed / synaesthesia->rate);
synaesthesia->sample_rate); GST_BUFFER_DURATION (outbuf) = synaesthesia->frame_duration;
GST_BUFFER_DURATION (outbuf) = frame_duration;
out_frame = (guchar *) synaesthesia_update (synaesthesia->datain); out_frame = (guchar *) synaesthesia_update (synaesthesia->datain);
memcpy (GST_BUFFER_DATA (outbuf), out_frame, GST_BUFFER_SIZE (outbuf)); memcpy (GST_BUFFER_DATA (outbuf), out_frame, GST_BUFFER_SIZE (outbuf));
@ -435,9 +477,12 @@ gst_synaesthesia_chain (GstPad * pad, GstBuffer * buffer)
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
break; break;
synaesthesia->samples_consumed += samples_per_frame; /* FIXME: flush what we actually read */
gst_adapter_flush (synaesthesia->adapter, samples_per_frame * synaesthesia->samples_consumed += synaesthesia->spf;
gst_adapter_flush (synaesthesia->adapter, synaesthesia->spf *
synaesthesia->channels * sizeof (gint16)); synaesthesia->channels * sizeof (gint16));
avail = gst_adapter_available (synaesthesia->adapter);
} }
gst_object_unref (synaesthesia); gst_object_unref (synaesthesia);

View file

@ -25,15 +25,6 @@
#include "synaescope.h" #include "synaescope.h"
#ifndef G_OS_WIN32
#include <pthread.h>
#include <sys/time.h>
#else
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#endif
#include <dirent.h> #include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <time.h> #include <time.h>
@ -44,6 +35,12 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#ifdef G_OS_WIN32
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#endif
#define SCOPE_BG_RED 0 #define SCOPE_BG_RED 0
#define SCOPE_BG_GREEN 0 #define SCOPE_BG_GREEN 0
#define SCOPE_BG_BLUE 0 #define SCOPE_BG_BLUE 0
@ -82,29 +79,6 @@ static int scaleDown[256];
static void synaes_fft (double *x, double *y); static void synaes_fft (double *x, double *y);
static void synaescope_coreGo (void); static void synaescope_coreGo (void);
#define SYNAESCOPE_DOLOOP() \
while (running) { \
gint bar; \
guint val; \
gint val2; \
unsigned char *outptr = output; \
int w; \
\
synaescope_coreGo(); \
\
outptr = output; \
for (w=0; w < syn_width * syn_height; w++) { \
bits[w] = colEq[(outptr[0] >> 4) + (outptr[1] & 0xf0)]; \
outptr += 2; \
} \
\
GDK_THREADS_ENTER(); \
gdk_draw_image(win,gc,image,0,0,0,0,-1,-1); \
gdk_flush(); \
GDK_THREADS_LEAVE(); \
dosleep(SCOPE_SLEEP); \
}
static inline void static inline void
addPixel (unsigned char *output, int x, int y, int br1, int br2) addPixel (unsigned char *output, int x, int y, int br1, int br2)
{ {
@ -209,7 +183,7 @@ synaescope_coreGo (void)
if (corr_l[i] > 0 || corr_r[i] > 0) { if (corr_l[i] > 0 || corr_r[i] > 0) {
int h = (int) (corr_r[i] * syn_width / (corr_l[i] + corr_r[i])); int h = (int) (corr_r[i] * syn_width / (corr_l[i] + corr_r[i]));
/* int h = (int)( syn_width - 1 ); */ /* int h = (int)( syn_width - 1 ); */
int br1, br2, br = (int) ((corr_l[i] + corr_r[i]) * i * brightFactor2); int br1, br2, br = (int) ((corr_l[i] + corr_r[i]) * i * brightFactor2);
int px = h, py = heightAdd - i / heightFactor; int px = h, py = heightAdd - i / heightFactor;
@ -307,6 +281,30 @@ synaescope32 ()
#if 0 #if 0
#define SYNAESCOPE_DOLOOP() \
while (running) { \
gint bar; \
guint val; \
gint val2; \
unsigned char *outptr = output; \
int w; \
\
synaescope_coreGo(); \
\
outptr = output; \
for (w=0; w < syn_width * syn_height; w++) { \
bits[w] = colEq[(outptr[0] >> 4) + (outptr[1] & 0xf0)]; \
outptr += 2; \
} \
\
GDK_THREADS_ENTER(); \
gdk_draw_image(win,gc,image,0,0,0,0,-1,-1); \
gdk_flush(); \
GDK_THREADS_LEAVE(); \
dosleep(SCOPE_SLEEP); \
}
static void static void
synaescope16 (void *data) synaescope16 (void *data)
{ {
@ -411,9 +409,8 @@ synaescope8 (void *data)
SYNAESCOPE_DOLOOP (); SYNAESCOPE_DOLOOP ();
} }
#endif
#if 0
static void static void
run_synaescope (void *data) run_synaescope (void *data)
{ {