Skip to content

Commit

Permalink
reformat to 120 char per line
Browse files Browse the repository at this point in the history
  • Loading branch information
MaZderMind committed Oct 25, 2020
1 parent 5a28e1d commit 23dd9b6
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 471 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ColumnLimit: 120
259 changes: 102 additions & 157 deletions src/gstebur128element.c

Large diffs are not rendered by default.

304 changes: 102 additions & 202 deletions src/gstebur128graphelement.c

Large diffs are not rendered by default.

23 changes: 6 additions & 17 deletions src/gstebur128graphelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,19 @@
G_BEGIN_DECLS

#define GST_TYPE_EBUR128GRAPH (gst_ebur128graph_get_type())
#define GST_EBUR128GRAPH(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_EBUR128GRAPH, GstEbur128Graph))
#define GST_EBUR128GRAPH_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_EBUR128GRAPH, \
GstEbur128GraphClass))
#define GST_IS_EBUR128GRAPH(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_EBUR128GRAPH))
#define GST_IS_EBUR128GRAPH_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_EBUR128GRAPH))
#define GST_EBUR128GRAPH(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_EBUR128GRAPH, GstEbur128Graph))
#define GST_EBUR128GRAPH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_EBUR128GRAPH, GstEbur128GraphClass))
#define GST_IS_EBUR128GRAPH(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_EBUR128GRAPH))
#define GST_IS_EBUR128GRAPH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_EBUR128GRAPH))

typedef struct _GstEbur128Position GstEbur128Position;
struct _GstEbur128Position {
gint x, y, w, h;
};

typedef enum {
GST_EBUR128_SCALE_MODE_RELATIVE,
GST_EBUR128_SCALE_MODE_ABSOLUTE
} GstEbur128ScaleMode;
typedef enum { GST_EBUR128_SCALE_MODE_RELATIVE, GST_EBUR128_SCALE_MODE_ABSOLUTE } GstEbur128ScaleMode;

typedef enum {
GST_EBUR128_MEASUREMENT_MOMENTARY,
GST_EBUR128_MEASUREMENT_SHORT_TERM
} GstEbur128Measurement;
typedef enum { GST_EBUR128_MEASUREMENT_MOMENTARY, GST_EBUR128_MEASUREMENT_SHORT_TERM } GstEbur128Measurement;

typedef struct _GstEbur128Positions GstEbur128Positions;
struct _GstEbur128Positions {
Expand Down
18 changes: 7 additions & 11 deletions src/gstebur128plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
*/
static gboolean ebur128_plugin_init(GstPlugin *ebur128) {
gboolean success = TRUE;
success &=
gst_element_register(ebur128, "ebur128", GST_RANK_NONE, GST_TYPE_EBUR128);
success &= gst_element_register(ebur128, "ebur128graph", GST_RANK_NONE,
GST_TYPE_EBUR128GRAPH);
success &= gst_element_register(ebur128, "ebur128", GST_RANK_NONE, GST_TYPE_EBUR128);
success &= gst_element_register(ebur128, "ebur128graph", GST_RANK_NONE, GST_TYPE_EBUR128GRAPH);
return success;
}

Expand All @@ -29,10 +27,8 @@ static gboolean ebur128_plugin_init(GstPlugin *ebur128) {

/* gstreamer looks for this structure to register ebur128s
*/
GST_PLUGIN_DEFINE(
GST_VERSION_MAJOR, GST_VERSION_MINOR, ebur128,
"The EBU-R 128 Plugin ('ebur128') provides Elements for calculating the "
"EBU-R 128 Loudness of an Audio-Stream and "
"to generate a Video-Stream visualizing the Loudness over Time",
ebur128_plugin_init, PACKAGE_VERSION, GST_LICENSE, GST_PACKAGE_NAME,
GST_PACKAGE_ORIGIN)
GST_PLUGIN_DEFINE(GST_VERSION_MAJOR, GST_VERSION_MINOR, ebur128,
"The EBU-R 128 Plugin ('ebur128') provides Elements for calculating the "
"EBU-R 128 Loudness of an Audio-Stream and "
"to generate a Video-Stream visualizing the Loudness over Time",
ebur128_plugin_init, PACKAGE_VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
12 changes: 4 additions & 8 deletions src/gstebur128shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
#include "gstebur128shared.h"
#include <ebur128.h>

gboolean gst_ebur128_validate_lib_return(const char *invocation,
const int return_value) {
gboolean gst_ebur128_validate_lib_return(const char *invocation, const int return_value) {
if (return_value != EBUR128_SUCCESS) {
GST_ERROR("Error-Code %d from libebur128 call to %s", return_value,
invocation);
GST_ERROR("Error-Code %d from libebur128 call to %s", return_value, invocation);
return FALSE;
}

return TRUE;
}

gboolean gst_ebur128_add_frames(ebur128_state *state, GstAudioFormat format,
guint8 *data, gint num_frames) {
gboolean gst_ebur128_add_frames(ebur128_state *state, GstAudioFormat format, guint8 *data, gint num_frames) {
gboolean success = TRUE;
int ret;

Expand All @@ -43,8 +40,7 @@ gboolean gst_ebur128_add_frames(ebur128_state *state, GstAudioFormat format,
case GST_AUDIO_FORMAT_F64LE:
case GST_AUDIO_FORMAT_F64BE:
ret = ebur128_add_frames_double(state, (const double *)data, num_frames);
success &=
gst_ebur128_validate_lib_return("ebur128_add_frames_double", ret);
success &= gst_ebur128_validate_lib_return("ebur128_add_frames_double", ret);
break;
default:
GST_ERROR("Unhandled Audio-Format: %s", gst_audio_format_to_string(format));
Expand Down
6 changes: 2 additions & 4 deletions src/gstebur128shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#include <gst/audio/audio.h>
#include <gst/gst.h>

gboolean gst_ebur128_validate_lib_return(const char *invocation,
const int return_value);
gboolean gst_ebur128_validate_lib_return(const char *invocation, const int return_value);

gboolean gst_ebur128_add_frames(ebur128_state *state, GstAudioFormat format,
guint8 *data, gint num_frames);
gboolean gst_ebur128_add_frames(ebur128_state *state, GstAudioFormat format, guint8 *data, gint num_frames);

#endif // __GST_EBUR128SHARED_H__
126 changes: 54 additions & 72 deletions tests/elements/ebur128.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,48 @@
#include <gst/audio/audio.h>
#include <gst/check/gstcheck.h>

#define SUPPORTED_AUDIO_FORMATS \
"{ " GST_AUDIO_NE(S16) ", " GST_AUDIO_NE(S32) "," GST_AUDIO_NE( \
F32) ", " GST_AUDIO_NE(F64) " }"
#define SUPPORTED_AUDIO_FORMATS \
"{ " GST_AUDIO_NE(S16) ", " GST_AUDIO_NE(S32) "," GST_AUDIO_NE(F32) ", " GST_AUDIO_NE(F64) " }"

#define SUPPORTED_AUDIO_CHANNELS "(int) {1, 2, 5 }"

#define SUPPORTED_CAPS_STRING \
"audio/x-raw, " \
"format = (string) " SUPPORTED_AUDIO_FORMATS ", " \
"rate = " GST_AUDIO_RATE_RANGE ", " \
"channels = " SUPPORTED_AUDIO_CHANNELS ", " \
#define SUPPORTED_CAPS_STRING \
"audio/x-raw, " \
"format = (string) " SUPPORTED_AUDIO_FORMATS ", " \
"rate = " GST_AUDIO_RATE_RANGE ", " \
"channels = " SUPPORTED_AUDIO_CHANNELS ", " \
"layout = (string) interleaved "

#define S16_CAPS_STRING \
"audio/x-raw, " \
"format = (string) " GST_AUDIO_NE(S16) ", " \
"layout = (string) interleaved, " \
"rate = (int) 48000, " \
#define S16_CAPS_STRING \
"audio/x-raw, " \
"format = (string) " GST_AUDIO_NE(S16) ", " \
"layout = (string) interleaved, " \
"rate = (int) 48000, " \
"channels = (int) 2"

#define S32_CAPS_STRING \
"audio/x-raw, " \
"format = (string) " GST_AUDIO_NE(S32) ", " \
"layout = (string) interleaved, " \
"rate = (int) 48000, " \
#define S32_CAPS_STRING \
"audio/x-raw, " \
"format = (string) " GST_AUDIO_NE(S32) ", " \
"layout = (string) interleaved, " \
"rate = (int) 48000, " \
"channels = (int) 2"
#define F32_CAPS_STRING \
"audio/x-raw, " \
"format = (string) " GST_AUDIO_NE(F32) ", " \
"layout = (string) interleaved, " \
"rate = (int) 48000, " \
#define F32_CAPS_STRING \
"audio/x-raw, " \
"format = (string) " GST_AUDIO_NE(F32) ", " \
"layout = (string) interleaved, " \
"rate = (int) 48000, " \
"channels = (int) 2"
#define F64_CAPS_STRING \
"audio/x-raw, " \
"format = (string) " GST_AUDIO_NE(F64) ", " \
"layout = (string) interleaved, " \
"rate = (int) 48000, " \
#define F64_CAPS_STRING \
"audio/x-raw, " \
"format = (string) " GST_AUDIO_NE(F64) ", " \
"layout = (string) interleaved, " \
"rate = (int) 48000, " \
"channels = (int) 2"

static GstStaticPadTemplate sinktemplate =
GST_STATIC_PAD_TEMPLATE("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
GST_STATIC_CAPS(SUPPORTED_CAPS_STRING));
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE(
"src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS(SUPPORTED_CAPS_STRING));
GST_STATIC_PAD_TEMPLATE("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS(SUPPORTED_CAPS_STRING));
static GstStaticPadTemplate srctemplate =
GST_STATIC_PAD_TEMPLATE("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS(SUPPORTED_CAPS_STRING));

/* For ease of programming we use globals to keep refs for our floating
* src and sink pads we create; otherwise we always have to do get_pad,
Expand All @@ -76,8 +74,7 @@ static void setup_element(const gchar *caps_str) {
gst_caps_unref(caps);

/* set to playing */
fail_unless(gst_element_set_state(element, GST_STATE_PLAYING) ==
GST_STATE_CHANGE_SUCCESS,
fail_unless(gst_element_set_state(element, GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
"could not set to playing");

/* create a bus to get the element message on */
Expand All @@ -97,9 +94,7 @@ static void cleanup_element() {
gst_element_set_bus(element, NULL);
ASSERT_OBJECT_REFCOUNT(bus, "bus", 1);
gst_object_unref(bus);
fail_unless(gst_element_set_state(element, GST_STATE_NULL) ==
GST_STATE_CHANGE_SUCCESS,
"could not set to null");
fail_unless(gst_element_set_state(element, GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
ASSERT_OBJECT_REFCOUNT(element, "element", 1);

gst_check_drop_buffers();
Expand All @@ -110,56 +105,48 @@ static void cleanup_element() {
gst_check_teardown_element(element);
}

static void caps_to_audio_info(const char *caps_string,
GstAudioInfo *audio_info) {
static void caps_to_audio_info(const char *caps_string, GstAudioInfo *audio_info) {
GstCaps *caps = gst_caps_from_string(caps_string);
gst_audio_info_from_caps(audio_info, caps);
gst_caps_unref(caps);
}

static GstBuffer *create_buffer(const char *caps_string,
const guint num_msecs) {
static GstBuffer *create_buffer(const char *caps_string, const guint num_msecs) {
GstAudioInfo audio_info;
caps_to_audio_info(caps_string, &audio_info);

guint num_frames = audio_info.rate * num_msecs / 1000;
gsize num_bytes = audio_info.bpf * num_frames;
GST_INFO("create buffer of %ld bytes for %d frames of %d bpf (%d bps * %d "
"channels) in %d msecs",
num_bytes, num_frames, audio_info.bpf,
audio_info.bpf / audio_info.channels, audio_info.channels,
num_msecs);
num_bytes, num_frames, audio_info.bpf, audio_info.bpf / audio_info.channels, audio_info.channels, num_msecs);
GstBuffer *buf = gst_buffer_new_and_alloc(num_bytes);
GST_BUFFER_TIMESTAMP(buf) = G_GUINT64_CONSTANT(0);

return buf;
}

#define DEFINE_TRIANGLE_BUFFER(NAME, T, MIN, MAX) \
static void fill_triangle_buffer_##NAME( \
guint8 *buffer_data, guint num_samples_per_wave, guint num_frames, \
const guint channels) { \
T *ptr = (T *)buffer_data; \
\
for (guint frame_idx = 0; frame_idx < num_frames; frame_idx++) { \
\
T sample = (frame_idx % num_samples_per_wave) * \
(MAX / num_samples_per_wave * 2) - \
MIN; \
\
for (gint channel_idx = 0; channel_idx < channels; channel_idx++) { \
ptr[frame_idx * channels + channel_idx] = sample / 8; \
} \
} \
#define DEFINE_TRIANGLE_BUFFER(NAME, T, MIN, MAX) \
static void fill_triangle_buffer_##NAME(guint8 *buffer_data, guint num_samples_per_wave, guint num_frames, \
const guint channels) { \
T *ptr = (T *)buffer_data; \
\
for (guint frame_idx = 0; frame_idx < num_frames; frame_idx++) { \
\
T sample = (frame_idx % num_samples_per_wave) * (MAX / num_samples_per_wave * 2) - MIN; \
\
for (gint channel_idx = 0; channel_idx < channels; channel_idx++) { \
ptr[frame_idx * channels + channel_idx] = sample / 8; \
} \
} \
};

DEFINE_TRIANGLE_BUFFER(s16, gshort, G_MINSHORT, G_MAXSHORT)
DEFINE_TRIANGLE_BUFFER(s32, gint, G_MININT, G_MAXINT)
DEFINE_TRIANGLE_BUFFER(f32, gfloat, -1.0, 1.0)
DEFINE_TRIANGLE_BUFFER(f64, gdouble, -1.0, 1.0)

static GstBuffer *create_triangle_buffer(const char *caps_string,
const guint num_msecs) {
static GstBuffer *create_triangle_buffer(const char *caps_string, const guint num_msecs) {
GstBuffer *buf = create_buffer(caps_string, num_msecs);

GstAudioInfo audio_info;
Expand All @@ -174,17 +161,13 @@ static GstBuffer *create_triangle_buffer(const char *caps_string,

GST_INFO("num_samples_per_wave=%d", num_samples_per_wave);
if (audio_info.finfo->format == GST_AUDIO_FORMAT_S16LE) {
fill_triangle_buffer_s16(map.data, num_samples_per_wave, num_frames,
audio_info.channels);
fill_triangle_buffer_s16(map.data, num_samples_per_wave, num_frames, audio_info.channels);
} else if (audio_info.finfo->format == GST_AUDIO_FORMAT_S32LE) {
fill_triangle_buffer_s32(map.data, num_samples_per_wave, num_frames,
audio_info.channels);
fill_triangle_buffer_s32(map.data, num_samples_per_wave, num_frames, audio_info.channels);
} else if (audio_info.finfo->format == GST_AUDIO_FORMAT_F32LE) {
fill_triangle_buffer_f32(map.data, num_samples_per_wave, num_frames,
audio_info.channels);
fill_triangle_buffer_f32(map.data, num_samples_per_wave, num_frames, audio_info.channels);
} else if (audio_info.finfo->format == GST_AUDIO_FORMAT_F64LE) {
fill_triangle_buffer_f64(map.data, num_samples_per_wave, num_frames,
audio_info.channels);
fill_triangle_buffer_f64(map.data, num_samples_per_wave, num_frames, audio_info.channels);
} else {
fail("Unhandled Format");
}
Expand Down Expand Up @@ -424,8 +407,7 @@ GST_START_TEST(test_prop_post_messages) {
GstBuffer *inbuffer = create_buffer(S16_CAPS_STRING, 100);
gst_pad_push(mysrcpad, inbuffer);

GstMessage *message =
gst_bus_poll(bus, GST_MESSAGE_ELEMENT, 50 * GST_MSECOND);
GstMessage *message = gst_bus_poll(bus, GST_MESSAGE_ELEMENT, 50 * GST_MSECOND);
fail_unless(message == NULL);

cleanup_element();
Expand Down

0 comments on commit 23dd9b6

Please sign in to comment.