<commit_before>/*
 * gst-droid
 *
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "gstdroidcamsrcphotography.h"
#include "gstdroidcamsrc.h"
#include <stdlib.h>             /* atoi() */
#include <string.h>             /* memcpy() */
#ifndef GST_USE_UNSTABLE_API
#define GST_USE_UNSTABLE_API
#endif /* GST_USE_UNSTABLE_API */
#include <gst/interfaces/photography.h>

GST_DEBUG_CATEGORY_EXTERN (gst_droid_camsrc_debug);
#define GST_CAT_DEFAULT gst_droid_camsrc_debug

struct Entry
{
  int prop;
  const gchar *photo_prop;
};

struct Entry Entries[] = {
  {PROP_WB_MODE, GST_PHOTOGRAPHY_PROP_WB_MODE},
  {PROP_COLOR_TONE, GST_PHOTOGRAPHY_PROP_COLOR_TONE},
  {PROP_SCENE_MODE, GST_PHOTOGRAPHY_PROP_SCENE_MODE},
  {PROP_FLASH_MODE, GST_PHOTOGRAPHY_PROP_FLASH_MODE},
  {PROP_FLICKER_MODE, GST_PHOTOGRAPHY_PROP_FLICKER_MODE},
  {PROP_FOCUS_MODE, GST_PHOTOGRAPHY_PROP_FOCUS_MODE},
  {PROP_EXPOSURE_MODE, GST_PHOTOGRAPHY_PROP_EXPOSURE_MODE},
  {PROP_NOISE_REDUCTION, GST_PHOTOGRAPHY_PROP_NOISE_REDUCTION},
  {PROP_ZOOM, GST_PHOTOGRAPHY_PROP_ZOOM},
  {PROP_EV_COMP, GST_PHOTOGRAPHY_PROP_EV_COMP},
  {PROP_ANALOG_GAIN, GST_PHOTOGRAPHY_PROP_ANALOG_GAIN},
  {PROP_LENS_FOCUS, GST_PHOTOGRAPHY_PROP_LENS_FOCUS},
  {PROP_APERTURE, GST_PHOTOGRAPHY_PROP_APERTURE},
  {PROP_ISO_SPEED, GST_PHOTOGRAPHY_PROP_ISO_SPEED},
  {PROP_COLOR_TEMPERATURE, GST_PHOTOGRAPHY_PROP_COLOR_TEMPERATURE},
  {PROP_MIN_EXPOSURE_TIME, GST_PHOTOGRAPHY_PROP_MIN_EXPOSURE_TIME},
  {PROP_MAX_EXPOSURE_TIME, GST_PHOTOGRAPHY_PROP_MAX_EXPOSURE_TIME},
  {PROP_EXPOSURE_TIME, GST_PHOTOGRAPHY_PROP_EXPOSURE_TIME},
  {PROP_CAPABILITIES, GST_PHOTOGRAPHY_PROP_CAPABILITIES},
  {PROP_IMAGE_CAPTURE_SUPPORTED_CAPS,
      GST_PHOTOGRAPHY_PROP_IMAGE_CAPTURE_SUPPORTED_CAPS},
  {PROP_IMAGE_PREVIEW_SUPPORTED_CAPS,
      GST_PHOTOGRAPHY_PROP_IMAGE_PREVIEW_SUPPORTED_CAPS},
  {PROP_WHITE_POINT, GST_PHOTOGRAPHY_PROP_WHITE_POINT},
};

struct _GstDroidCamSrcPhotography
{
  GstPhotographySettings settings;
  GList *flash;
  GList *color_tone;
  GList *focus;
  GList *scene;
  GList *wb;
  GList *iso;
  GList *flicker;
};

struct DataEntry
{
  int key;
  gchar *value;
};

static GList *gst_droidcamsrc_photography_load (GKeyFile * file,
    const gchar * property);

#define PHOTO_IFACE_FUNC(name, tset, tget)					\
  static gboolean gst_droidcamsrc_get_##name (GstDroidCamSrc * src, tget val); \
  static gboolean gst_droidcamsrc_set_##name (GstDroidCamSrc * src, tset val); \
  static gboolean gst_droidcamsrc_photography_get_##name (GstPhotography *photo, tget val) \
  { \
    return gst_droidcamsrc_get_##name (GST_DROIDCAMSRC (photo), val);	\
  }                                                                                             \
  static gboolean gst_droidcamsrc_photography_set_##name (GstPhotography *photo, tset val) \
  { \
    return gst_droidcamsrc_set_##name (GST_DROIDCAMSRC (photo), val);	\
  }

#define APPLY_SETTING(table, val, droid)				\
  {									\
    int x;								\
    int len = g_list_length (table);					\
    gchar *value = NULL;						\
    for (x = 0; x < len; x++) {						\
      struct DataEntry *entry = (struct DataEntry *) g_list_nth_data (table, x); \
      if (val == entry->key) {						\
	value = entry->value;						\
	break;								\
      }									\
    }									\
									\
    if (value) {							\
      GST_INFO_OBJECT (src, "setting %s to %s", droid, value);		\
      gst_droidcamsrc_params_set_string (src->dev->params, droid, value); \
    } else {								\
      GST_WARNING_OBJECT (src, "setting %s to %d is not supported", droid, val); \
    }									\
  }

#define SET_ENUM(table,val,droid,memb)					\
  int x;								\
  int len = g_list_length (table);					\
  const gchar *value = NULL;						\
  for (x = 0; x < len; x++) {						\
    struct DataEntry *entry = (struct DataEntry *) g_list_nth_data (table, x); \
    if (val == entry->key) {						\
      value = entry->value;						\
      break;								\
    }									\
  }									\
									\
  if (!value) {								\
    GST_WARNING_OBJECT (src, "setting %s to %d is not supported", droid, val); \
    return FALSE;							\
  }									\
									\
  GST_OBJECT_LOCK (src);						\
  src->photo->settings.memb = val;					\<commit_msg>droidcamsrc: add more debugging to SET_ENUM photography macro<commit_after>/*
 * gst-droid
 *
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "gstdroidcamsrcphotography.h"
#include "gstdroidcamsrc.h"
#include <stdlib.h>             /* atoi() */
#include <string.h>             /* memcpy() */
#ifndef GST_USE_UNSTABLE_API
#define GST_USE_UNSTABLE_API
#endif /* GST_USE_UNSTABLE_API */
#include <gst/interfaces/photography.h>

GST_DEBUG_CATEGORY_EXTERN (gst_droid_camsrc_debug);
#define GST_CAT_DEFAULT gst_droid_camsrc_debug

struct Entry
{
  int prop;
  const gchar *photo_prop;
};

struct Entry Entries[] = {
  {PROP_WB_MODE, GST_PHOTOGRAPHY_PROP_WB_MODE},
  {PROP_COLOR_TONE, GST_PHOTOGRAPHY_PROP_COLOR_TONE},
  {PROP_SCENE_MODE, GST_PHOTOGRAPHY_PROP_SCENE_MODE},
  {PROP_FLASH_MODE, GST_PHOTOGRAPHY_PROP_FLASH_MODE},
  {PROP_FLICKER_MODE, GST_PHOTOGRAPHY_PROP_FLICKER_MODE},
  {PROP_FOCUS_MODE, GST_PHOTOGRAPHY_PROP_FOCUS_MODE},
  {PROP_EXPOSURE_MODE, GST_PHOTOGRAPHY_PROP_EXPOSURE_MODE},
  {PROP_NOISE_REDUCTION, GST_PHOTOGRAPHY_PROP_NOISE_REDUCTION},
  {PROP_ZOOM, GST_PHOTOGRAPHY_PROP_ZOOM},
  {PROP_EV_COMP, GST_PHOTOGRAPHY_PROP_EV_COMP},
  {PROP_ANALOG_GAIN, GST_PHOTOGRAPHY_PROP_ANALOG_GAIN},
  {PROP_LENS_FOCUS, GST_PHOTOGRAPHY_PROP_LENS_FOCUS},
  {PROP_APERTURE, GST_PHOTOGRAPHY_PROP_APERTURE},
  {PROP_ISO_SPEED, GST_PHOTOGRAPHY_PROP_ISO_SPEED},
  {PROP_COLOR_TEMPERATURE, GST_PHOTOGRAPHY_PROP_COLOR_TEMPERATURE},
  {PROP_MIN_EXPOSURE_TIME, GST_PHOTOGRAPHY_PROP_MIN_EXPOSURE_TIME},
  {PROP_MAX_EXPOSURE_TIME, GST_PHOTOGRAPHY_PROP_MAX_EXPOSURE_TIME},
  {PROP_EXPOSURE_TIME, GST_PHOTOGRAPHY_PROP_EXPOSURE_TIME},
  {PROP_CAPABILITIES, GST_PHOTOGRAPHY_PROP_CAPABILITIES},
  {PROP_IMAGE_CAPTURE_SUPPORTED_CAPS,
      GST_PHOTOGRAPHY_PROP_IMAGE_CAPTURE_SUPPORTED_CAPS},
  {PROP_IMAGE_PREVIEW_SUPPORTED_CAPS,
      GST_PHOTOGRAPHY_PROP_IMAGE_PREVIEW_SUPPORTED_CAPS},
  {PROP_WHITE_POINT, GST_PHOTOGRAPHY_PROP_WHITE_POINT},
};

struct _GstDroidCamSrcPhotography
{
  GstPhotographySettings settings;
  GList *flash;
  GList *color_tone;
  GList *focus;
  GList *scene;
  GList *wb;
  GList *iso;
  GList *flicker;
};

struct DataEntry
{
  int key;
  gchar *value;
};

static GList *gst_droidcamsrc_photography_load (GKeyFile * file,
    const gchar * property);

#define PHOTO_IFACE_FUNC(name, tset, tget)					\
  static gboolean gst_droidcamsrc_get_##name (GstDroidCamSrc * src, tget val); \
  static gboolean gst_droidcamsrc_set_##name (GstDroidCamSrc * src, tset val); \
  static gboolean gst_droidcamsrc_photography_get_##name (GstPhotography *photo, tget val) \
  { \
    return gst_droidcamsrc_get_##name (GST_DROIDCAMSRC (photo), val);	\
  }                                                                                             \
  static gboolean gst_droidcamsrc_photography_set_##name (GstPhotography *photo, tset val) \
  { \
    return gst_droidcamsrc_set_##name (GST_DROIDCAMSRC (photo), val);	\
  }

#define APPLY_SETTING(table, val, droid)				\
  {									\
    int x;								\
    int len = g_list_length (table);					\
    gchar *value = NULL;						\
    for (x = 0; x < len; x++) {						\
      struct DataEntry *entry = (struct DataEntry *) g_list_nth_data (table, x); \
      if (val == entry->key) {						\
	value = entry->value;						\
	break;								\
      }									\
    }									\
									\
    if (value) {							\
      GST_INFO_OBJECT (src, "setting %s to %s", droid, value);		\
      gst_droidcamsrc_params_set_string (src->dev->params, droid, value); \
    } else {								\
      GST_WARNING_OBJECT (src, "setting %s to %d is not supported", droid, val); \
    }									\
  }

#define SET_ENUM(table,val,droid,memb)					\
  int x;								\
  int len = g_list_length (table);					\
  const gchar *value = NULL;						\
  for (x = 0; x < len; x++) {						\
    struct DataEntry *entry = (struct DataEntry *) g_list_nth_data (table, x); \
    if (val == entry->key) {						\
      value = entry->value;						\
      break;								\
    }									\
  }									\
									\
  if (!value) {								\
    GST_WARNING_OBJECT (src, "setting %s to %d is not supported", droid, val); \
    return FALSE;							\
  }									\
									\
  GST_DEBUG_OBJECT (src, "setting %s to %s (%d)", droid, value, val);	\
									\
  GST_OBJECT_LOCK (src);						\
  src->photo->settings.memb = val;					\
{'fraction_non_alphanumeric': 0.09874468716022536, 'fraction_numerical': 0.003558367104872986, 'mean_word_length': 3.238793464599916, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3389729', 'n_tokens_mistral': 4332, 'n_tokens_neox': 3839, 'n_words': 795}