/* Process keyboard input */ static gboolean handle_keyboard (GIOChannel *source, GIOCondition cond, CustomData *data) { gchar *str = NULL; if (g_io_channel_read_line (source, &str, NULL, NULL, NULL) != G_IO_STATUS_NORMAL) { return TRUE; } switch (g_ascii_tolower (str[0])) { case 'c': update_color_channel ("CONTRAST", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline)); break; case 'b': update_color_channel ("BRIGHTNESS", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline)); break; case 'h': update_color_channel ("HUE", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline)); break; case 's': update_color_channel ("SATURATION", g_ascii_isupper (str[0]), GST_COLOR_BALANCE (data->pipeline)); break; case 'q': g_main_loop_quit (data->loop); break; default: break; } g_free (str); print_current_values (data->pipeline); return TRUE; }
static void gst_video_balance_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstVideoBalance *balance = GST_VIDEO_BALANCE (object); gdouble d; const gchar *label = NULL; GST_BASE_TRANSFORM_LOCK (balance); GST_OBJECT_LOCK (balance); switch (prop_id) { case PROP_CONTRAST: d = g_value_get_double (value); GST_DEBUG_OBJECT (balance, "Changing contrast from %lf to %lf", balance->contrast, d); if (d != balance->contrast) label = "CONTRAST"; balance->contrast = d; break; case PROP_BRIGHTNESS: d = g_value_get_double (value); GST_DEBUG_OBJECT (balance, "Changing brightness from %lf to %lf", balance->brightness, d); if (d != balance->brightness) label = "BRIGHTNESS"; balance->brightness = d; break; case PROP_HUE: d = g_value_get_double (value); GST_DEBUG_OBJECT (balance, "Changing hue from %lf to %lf", balance->hue, d); if (d != balance->hue) label = "HUE"; balance->hue = d; break; case PROP_SATURATION: d = g_value_get_double (value); GST_DEBUG_OBJECT (balance, "Changing saturation from %lf to %lf", balance->saturation, d); if (d != balance->saturation) label = "SATURATION"; balance->saturation = d; break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } gst_video_balance_update_properties (balance); GST_OBJECT_UNLOCK (balance); GST_BASE_TRANSFORM_UNLOCK (balance); if (label) { GstColorBalanceChannel *channel = gst_video_balance_find_channel (balance, label); gst_color_balance_value_changed (GST_COLOR_BALANCE (balance), channel, gst_color_balance_get_value (GST_COLOR_BALANCE (balance), channel)); } }
int gstreamer_prepare_color_balance() { if (color_balance_element) gst_object_unref(color_balance_element); color_balance_element = find_color_balance_element(); if (color_balance_element == NULL) return 0; if (!GST_IS_COLOR_BALANCE(color_balance_element)) return 0; GList *channel_list = gst_color_balance_list_channels( GST_COLOR_BALANCE(color_balance_element)); if (channel_list == NULL) return 0; for (int i = 0; i < 4; i++) color_balance_channel[i] = NULL; channel_list = g_list_first(channel_list); while (channel_list) { GstColorBalanceChannel *channel = channel_list->data; if (strcasestr(channel->label, "BRIGHTNESS") != NULL) color_balance_channel[CHANNEL_BRIGHTNESS] = channel; else if (strcasestr(channel->label, "CONTRAST") != NULL) color_balance_channel[CHANNEL_CONTRAST] = channel; else if (strcasestr(channel->label, "HUE") != NULL) color_balance_channel[CHANNEL_HUE] = channel; else if (strcasestr(channel->label, "SATURATION") != NULL) color_balance_channel[CHANNEL_SATURATION] = channel; else printf("gstplay: Unknown color balance channel %s detected.\n", channel->label); channel_list = g_list_next(channel_list); } int r = 0; for (int i = 0; i < 4; i++) { if (color_balance_channel[i] != NULL) { // printf("gstplay: Color balance channel %s found.\n", // color_balance_channel[i]->label); if (find_xvimagesink() && strncmp(color_balance_channel[i]->label, "XV_", 3) != 0) { char *s = g_malloc(strlen(color_balance_channel[i]->label) + 4); sprintf(s, "XV_%s", color_balance_channel[i]->label); g_free(color_balance_channel[i]->label); color_balance_channel[i]->label = s; printf("gstplay: Fixing mismatched xvimagesink color balance channel name to %s.\n", s); } gint v = gst_color_balance_get_value( GST_COLOR_BALANCE(color_balance_element), color_balance_channel[i]); r |= 1 << i; last_value_set[i] = v; } } return r; }
/* Output the current values of all Color Balance channels */ static void print_current_values (GstElement *pipeline) { const GList *channels, *l; /* Output Color Balance values */ channels = gst_color_balance_list_channels (GST_COLOR_BALANCE (pipeline)); for (l = channels; l != NULL; l = l->next) { GstColorBalanceChannel *channel = (GstColorBalanceChannel *)l->data; gint value = gst_color_balance_get_value (GST_COLOR_BALANCE (pipeline), channel); g_print ("%s: %3d%% ", channel->label, 100 * (value - channel->min_value) / (channel->max_value - channel->min_value)); } g_print ("\n"); }
bool CameraBinImageProcessing::setColorBalanceValue(const QString& channel, int value) { if (!GST_IS_COLOR_BALANCE(m_session->cameraBin())) { // Camerabin doesn't implement gstcolorbalance interface return false; } GstColorBalance *balance = GST_COLOR_BALANCE(m_session->cameraBin()); const GList *controls = gst_color_balance_list_channels(balance); const GList *item; GstColorBalanceChannel *colorBalanceChannel; for (item = controls; item; item = g_list_next (item)) { colorBalanceChannel = (GstColorBalanceChannel *)item->data; if (!g_ascii_strcasecmp (colorBalanceChannel->label, channel.toAscii())) { gst_color_balance_set_value (balance, colorBalanceChannel, value); return true; } } return false; }
bool CameraBinImageProcessing::setColorBalanceValue(const QString& channel, qreal value) { if (!GST_IS_COLOR_BALANCE(m_session->cameraBin())) { // Camerabin doesn't implement gstcolorbalance interface return false; } GstColorBalance *balance = GST_COLOR_BALANCE(m_session->cameraBin()); const GList *controls = gst_color_balance_list_channels(balance); const GList *item; GstColorBalanceChannel *colorBalanceChannel; for (item = controls; item; item = g_list_next (item)) { colorBalanceChannel = (GstColorBalanceChannel *)item->data; if (!g_ascii_strcasecmp (colorBalanceChannel->label, channel.toLatin1())) { //map the [-1.0 .. 1.0] range to [min_value..max_value] gint scaledValue = colorBalanceChannel->min_value + qRound( (value+1.0)/2.0 * (colorBalanceChannel->max_value - colorBalanceChannel->min_value)); gst_color_balance_set_value (balance, colorBalanceChannel, scaledValue); return true; } } return false; }
void CameraBinImageProcessing::updateColorBalanceValues() { if (!GST_IS_COLOR_BALANCE(m_session->cameraBin())) { // Camerabin doesn't implement gstcolorbalance interface return; } GstColorBalance *balance = GST_COLOR_BALANCE(m_session->cameraBin()); const GList *controls = gst_color_balance_list_channels(balance); const GList *item; GstColorBalanceChannel *channel; gint cur_value; qreal scaledValue = 0; for (item = controls; item; item = g_list_next (item)) { channel = (GstColorBalanceChannel *)item->data; cur_value = gst_color_balance_get_value (balance, channel); //map the [min_value..max_value] range to [-1.0 .. 1.0] if (channel->min_value != channel->max_value) { scaledValue = qreal(cur_value - channel->min_value) / (channel->max_value - channel->min_value) * 2 - 1; } if (!g_ascii_strcasecmp (channel->label, "brightness")) { m_values[QCameraImageProcessingControl::BrightnessAdjustment] = scaledValue; } else if (!g_ascii_strcasecmp (channel->label, "contrast")) { m_values[QCameraImageProcessingControl::ContrastAdjustment] = scaledValue; } else if (!g_ascii_strcasecmp (channel->label, "saturation")) { m_values[QCameraImageProcessingControl::SaturationAdjustment] = scaledValue; } } }
void CameraBinImageProcessing::updateColorBalanceValues() { if (!GST_IS_COLOR_BALANCE(m_session->cameraBin())) { // Camerabin doesn't implement gstcolorbalance interface return; } GstColorBalance *balance = GST_COLOR_BALANCE(m_session->cameraBin()); const GList *controls = gst_color_balance_list_channels(balance); const GList *item; GstColorBalanceChannel *channel; gint cur_value; for (item = controls; item; item = g_list_next (item)) { channel = (GstColorBalanceChannel *)item->data; cur_value = gst_color_balance_get_value (balance, channel); if (!g_ascii_strcasecmp (channel->label, "brightness")) { m_values[QCameraImageProcessingControl::Brightness] = cur_value; } else if (!g_ascii_strcasecmp (channel->label, "contrast")) { m_values[QCameraImageProcessingControl::Contrast] = cur_value; } else if (!g_ascii_strcasecmp (channel->label, "saturation")) { m_values[QCameraImageProcessingControl::Saturation] = cur_value; } } }
void empathy_video_src_set_channel (GstElement *src, EmpathyGstVideoSrcChannel channel, guint percent) { GstElement *color; GstColorBalance *balance; const GList *channels; GList *l; /* Find something supporting GstColorBalance */ color = gst_bin_get_by_interface (GST_BIN (src), GST_TYPE_COLOR_BALANCE); if (color == NULL) return; balance = GST_COLOR_BALANCE (color); channels = gst_color_balance_list_channels (balance); for (l = (GList *) channels; l != NULL; l = g_list_next (l)) { GstColorBalanceChannel *c = GST_COLOR_BALANCE_CHANNEL (l->data); if (g_ascii_strcasecmp (c->label, channel_names[channel]) == 0) { gst_color_balance_set_value (balance, c, ((c->max_value - c->min_value) * percent)/100 + c->min_value); break; } } g_object_unref (color); }
void gstreamer_set_color_balance(int channel, gdouble value) { if (color_balance_channel[channel] == NULL) return; gint v = color_balance_channel[channel]->min_value + value * 0.01 * (color_balance_channel[channel]->max_value - color_balance_channel[channel]->min_value); if (v != last_value_set[channel]) { gst_color_balance_set_value(GST_COLOR_BALANCE(color_balance_element), color_balance_channel[channel], v); last_value_set[channel] = v; } }
gdouble gstreamer_get_color_balance(int channel) { if (color_balance_channel[channel] == NULL) { printf("gstplay: Could not read color balance channel.\n"); return - 1.0; } gdouble v = gst_color_balance_get_value(GST_COLOR_BALANCE(color_balance_element), color_balance_channel[channel]); // Normalize to [0, 100]. return (v - color_balance_channel[channel]->min_value) * 100.0 / (color_balance_channel[channel]->max_value - color_balance_channel[channel]->min_value); }
static void gst_gl_sink_bin_color_balance_set_value (GstColorBalance * balance, GstColorBalanceChannel * channel, gint value) { GstGLSinkBin *self = GST_GL_SINK_BIN (balance); GstColorBalance *balance_element = NULL; balance_element = GST_COLOR_BALANCE (gst_bin_get_by_interface (GST_BIN (self), GST_TYPE_COLOR_BALANCE)); if (balance_element) { gst_color_balance_set_value (balance_element, channel, value); gst_object_unref (balance_element); } }
/** * gst_base_camera_src_get_colorbalance: * @self: the camerasrc bin * * Get object implementing colorbalance interface, if there is one. Otherwise * returns NULL. */ GstColorBalance * gst_base_camera_src_get_color_balance (GstBaseCameraSrc * self) { GstElement *elem; if (GST_IS_COLOR_BALANCE (self)) { elem = GST_ELEMENT (self); } else { elem = gst_bin_get_by_interface (GST_BIN (self), GST_TYPE_COLOR_BALANCE); } if (elem) { return GST_COLOR_BALANCE (self); } return NULL; }
Balance::Balance(GstElement *pipeline, QObject *parent) : QObject(parent), balance(GST_COLOR_BALANCE(pipeline)) { const GList *controls = gst_color_balance_list_channels(balance); const GList *item; GstColorBalanceChannel *channel; gint index; if (controls) { for (item = controls, index = 0; item != nullptr; item = item->next, ++index) { channel = (GstColorBalanceChannel *)item->data; channels[QString(channel->label).toLower()] = channel; } } }
static GstColorBalanceType gst_gl_sink_bin_color_balance_get_balance_type (GstColorBalance * balance) { GstGLSinkBin *self = GST_GL_SINK_BIN (balance); GstColorBalance *balance_element = NULL; GstColorBalanceType type = 0; balance_element = GST_COLOR_BALANCE (gst_bin_get_by_interface (GST_BIN (self), GST_TYPE_COLOR_BALANCE)); if (balance_element) { type = gst_color_balance_get_balance_type (balance_element); gst_object_unref (balance_element); } return type; }
static const GList * gst_gl_sink_bin_color_balance_list_channels (GstColorBalance * balance) { GstGLSinkBin *self = GST_GL_SINK_BIN (balance); GstColorBalance *balance_element = NULL; const GList *list = NULL; balance_element = GST_COLOR_BALANCE (gst_bin_get_by_interface (GST_BIN (self), GST_TYPE_COLOR_BALANCE)); if (balance_element) { list = gst_color_balance_list_channels (balance_element); gst_object_unref (balance_element); } return list; }
guint empathy_video_src_get_supported_channels (GstElement *src) { GstElement *color; GstColorBalance *balance; const GList *channels; GList *l; guint result = 0; /* Find something supporting GstColorBalance */ color = gst_bin_get_by_interface (GST_BIN (src), GST_TYPE_COLOR_BALANCE); if (color == NULL) goto out; balance = GST_COLOR_BALANCE (color); channels = gst_color_balance_list_channels (balance); for (l = (GList *) channels; l != NULL; l = g_list_next (l)) { GstColorBalanceChannel *channel = GST_COLOR_BALANCE_CHANNEL (l->data); int i; for (i = 0; i < NR_EMPATHY_GST_VIDEO_SRC_CHANNELS; i++) { if (g_ascii_strcasecmp (channel->label, channel_names[i]) == 0) { result |= (1 << i); break; } } } g_object_unref (color); out: return result; }
static GstColorBalance * dup_color_balance (GstElement *src) { GstElement *color; /* Find something supporting GstColorBalance */ color = gst_bin_get_by_interface (GST_BIN (src), GST_TYPE_COLOR_BALANCE); if (color == NULL) return NULL; /* colorbalance is wrapped by GstImplementsInterface, we * need to check if it is actually supported for this instance * in its current state before trying to use it */ if (!GST_IS_COLOR_BALANCE (color)) { g_object_unref (color); return NULL; } return GST_COLOR_BALANCE (color); }
static GstElement *find_color_balance_element() { GstIterator *iterator = gst_bin_iterate_all_by_interface( GST_BIN(pipeline), GST_TYPE_COLOR_BALANCE); GstElement *color_balance_element = NULL; gboolean done = FALSE, hardware = FALSE; #if GST_CHECK_VERSION(1, 0, 0) GValue item = G_VALUE_INIT; #else gpointer item; #endif while (!done) { switch (gst_iterator_next(iterator, &item)) { case GST_ITERATOR_OK : { #if GST_CHECK_VERSION(1, 0, 0) GstElement *element = g_value_get_object(&item); #else GstElement *element = GST_ELEMENT(item); #endif if (is_valid_color_balance_element(element)) { if (!color_balance_element) { color_balance_element = GST_ELEMENT_CAST( gst_object_ref(element)); hardware = (gst_color_balance_get_balance_type(GST_COLOR_BALANCE (element)) == GST_COLOR_BALANCE_HARDWARE); } else if (!hardware) { gboolean tmp = (gst_color_balance_get_balance_type(GST_COLOR_BALANCE (element)) == GST_COLOR_BALANCE_HARDWARE); if (tmp) { if (color_balance_element) gst_object_unref(color_balance_element); color_balance_element = GST_ELEMENT_CAST(gst_object_ref(element)); hardware = TRUE; } } } #if GST_CHECK_VERSION(1, 0, 0) g_value_reset(&item); #endif if (hardware && color_balance_element) done = TRUE; break; } case GST_ITERATOR_RESYNC : gst_iterator_resync(iterator); done = FALSE; hardware = FALSE; if (color_balance_element) gst_object_unref(color_balance_element); color_balance_element = NULL; break; case GST_ITERATOR_DONE: case GST_ITERATOR_ERROR: default: done = TRUE; } } #if GST_CHECK_VERSION(1, 0, 0) g_value_unset(&item); #endif gst_iterator_free(iterator); return color_balance_element; }
static void run_options (char opt) { int res; switch (opt) { case 'f': { GstTuner *tuner = GST_TUNER (source); GstTunerChannel *channel; guint freq; channel = gst_tuner_get_channel (tuner); freq = gst_tuner_get_frequency (tuner, channel); printf ("\ntype the new frequency (current = %u) (-1 to cancel): ", freq); res = scanf ("%u", &freq); if (res != 1 || freq != -1) gst_tuner_set_frequency (tuner, channel, freq); } break; case 'n': { GstTuner *tuner = GST_TUNER (source); const GList *item, *list; const GstTunerNorm *current_norm; GstTunerNorm *norm = NULL; gint index, next_norm; list = gst_tuner_list_norms (tuner); current_norm = gst_tuner_get_norm (tuner); printf ("\nlist of norms:\n"); for (item = list, index = 0; item != NULL; item = item->next, ++index) { norm = item->data; if (current_norm == norm) { printf (" * %u - %s\n", index, norm->label); } else { printf (" %u - %s\n", index, norm->label); } } printf ("\ntype the number of norm you want (-1 to cancel): "); res = scanf ("%d", &next_norm); if (res != 1 || next_norm < 0) { break; } if (index <= next_norm) { printf ("Norm %d not available\n", next_norm); break; } for (item = list, index = 0; item != NULL && index <= next_norm; item = item->next, ++index) { norm = item->data; } if (norm) gst_tuner_set_norm (tuner, norm); } break; case 'i': { GstTuner *tuner = GST_TUNER (source); const GList *item, *list; const GstTunerChannel *current_channel; GstTunerChannel *channel = NULL; gint index, next_channel; list = gst_tuner_list_channels (tuner); current_channel = gst_tuner_get_channel (tuner); printf ("\nlist of inputs:\n"); for (item = list, index = 0; item != NULL; item = item->next, ++index) { channel = item->data; if (current_channel == channel) { printf (" * %u - %s\n", index, channel->label); } else { printf (" %u - %s\n", index, channel->label); } } printf ("\ntype the number of input you want (-1 to cancel): "); res = scanf ("%d", &next_channel); if (res != 1 || next_channel < 0) { break; } if (index <= next_channel) { printf ("Input %d not available\n", next_channel); break; } for (item = list, index = 0; item != NULL && index <= next_channel; item = item->next, ++index) { channel = item->data; } if (channel) gst_tuner_set_channel (tuner, channel); } break; case 'e': gst_element_set_state (pipeline, GST_STATE_NULL); g_main_loop_quit (loop); printf ("Bye\n"); g_thread_exit (0); break; case 'c': { GstColorBalance *balance = GST_COLOR_BALANCE (source); const GList *controls; GstColorBalanceChannel *channel; const GList *item; gint index, new_value; controls = gst_color_balance_list_channels (balance); printf ("\n"); if (controls == NULL) { printf ("There is no list of colorbalance controls\n"); goto done; } if (controls) { printf ("list of controls:\n"); for (item = controls, index = 0; item != NULL; item = item->next, ++index) { channel = item->data; printf (" %u - %s (%d - %d) = %d\n", index, channel->label, channel->min_value, channel->max_value, gst_color_balance_get_value (balance, channel)); } printf ("\ntype the number of color control you want (-1 to cancel): "); res = scanf ("%d", &new_value); if (res != 1 || new_value == -1) break; for (item = controls, index = 0; item != NULL && index <= new_value; item = item->next, ++index) { channel = item->data; } printf (" %u - %s (%d - %d) = %d, type the new value: ", index - 1, channel->label, channel->min_value, channel->max_value, gst_color_balance_get_value (balance, channel)); res = scanf ("%d", &new_value); if (res != 1 || new_value == -1) break; gst_color_balance_set_value (balance, channel, new_value); } } case 'v': { GstVideoOrientation *vidorient = GST_VIDEO_ORIENTATION (source); gboolean flip = FALSE; gint center = 0; printf ("\n"); if (gst_video_orientation_get_hflip (vidorient, &flip)) { gint new_value; printf ("Horizontal flip is %s\n", flip ? "on" : "off"); printf ("\ntype 1 to toggle (-1 to cancel): "); res = scanf ("%d", &new_value); if (res != 1 || new_value == 1) { flip = !flip; if (gst_video_orientation_set_hflip (vidorient, flip)) { gst_video_orientation_get_hflip (vidorient, &flip); printf ("Now horizontal flip is %s\n", flip ? "on" : "off"); } else { printf ("Error toggling horizontal flip\n"); } } else { } } else { printf ("Horizontal flip control not available\n"); } if (gst_video_orientation_get_vflip (vidorient, &flip)) { gint new_value; printf ("\nVertical flip is %s\n", flip ? "on" : "off"); printf ("\ntype 1 to toggle (-1 to cancel): "); res = scanf ("%d", &new_value); if (res != 1 || new_value == 1) { flip = !flip; if (gst_video_orientation_set_vflip (vidorient, flip)) { gst_video_orientation_get_vflip (vidorient, &flip); printf ("Now vertical flip is %s\n", flip ? "on" : "off"); } else { printf ("Error toggling vertical flip\n"); } } else { } } else { printf ("Vertical flip control not available\n"); } if (gst_video_orientation_get_hcenter (vidorient, ¢er)) { printf ("Horizontal center is %d\n", center); printf ("\ntype the new horizontal center value (-1 to cancel): "); res = scanf ("%d", ¢er); if (res != 1 || center != -1) { if (gst_video_orientation_set_hcenter (vidorient, center)) { gst_video_orientation_get_hcenter (vidorient, ¢er); printf ("Now horizontal center is %d\n", center); } else { printf ("Error setting horizontal center\n"); } } else { } } else { printf ("Horizontal center control not available\n"); } if (gst_video_orientation_get_vcenter (vidorient, ¢er)) { printf ("Vertical center is %d\n", center); printf ("\ntype the new vertical center value (-1 to cancel): "); res = scanf ("%d", ¢er); if (res != 1 || center != -1) { if (gst_video_orientation_set_vcenter (vidorient, center)) { gst_video_orientation_get_vcenter (vidorient, ¢er); printf ("Now vertical center is %d\n", center); } else { printf ("Error setting vertical center\n"); } } else { } } else { printf ("Vertical center control not available\n"); } } break; break; default: if (opt != 10) printf ("error: invalid option %c", opt); break; } done: return; }