<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 Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, 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;
  gchar *iso_key;
  GList *flicker;
};

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

struct DataEntry FlashValues[] = {
  {GST_PHOTOGRAPHY_FLASH_MODE_AUTO, "auto"},
  {GST_PHOTOGRAPHY_FLASH_MODE_OFF, "off"},
  {GST_PHOTOGRAPHY_FLASH_MODE_ON, "on"},
  {GST_PHOTOGRAPHY_FLASH_MODE_RED_EYE, "red-eye"}
};

struct DataEntry FocusValues[] = {
  {GST_PHOTOGRAPHY_FOCUS_MODE_AUTO, "auto"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_MACRO, "macro"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_INFINITY, "infinity"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_HYPERFOCAL, "fixed"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_EXTENDED, "edof"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_NORMAL, "continuous"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_EXTENDED, "continuous"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_MANUAL, "manual"}
};

struct DataEntry ISOValues[] = {
  {0, "auto"},
  {0, "iso-auto"},
  {1, "ISO_HJR"},
  {100, "ISO100"},
  {100, "iso-100"},
  {100, "100"},
  {200, "ISO200"},
  {200, "iso-200"},
  {200, "200"},
  {400, "ISO400"},
  {400, "iso-400"},
  {400, "400"},
  {800, "ISO800"},
  {800, "iso-800"},
  {800, "800"},
  {1600, "ISO1600"},
  {1600, "1600"},
  {3200, "ISO3200"},
  {3200, "3200"},
  {6400, "ISO6400"},
  {6400, "6400"},
  {12800, "ISO12800"},
  {12800, "12800"}
};

struct DataEntry WhiteBalanceValues[] = {
  {GST_PHOTOGRAPHY_WB_MODE_AUTO, "auto"},
  {GST_PHOTOGRAPHY_WB_MODE_DAYLIGHT, "daylight"},
  {GST_PHOTOGRAPHY_WB_MODE_CLOUDY, "cloudy-daylight"},
  {GST_PHOTOGRAPHY_WB_MODE_SUNSET, "twilight"},
  {GST_PHOTOGRAPHY_WB_MODE_TUNGSTEN, "incandescent"},
  {GST_PHOTOGRAPHY_WB_MODE_FLUORESCENT, "fluorescent"},
  {GST_PHOTOGRAPHY_WB_MODE_MANUAL, "manual"},
  {GST_PHOTOGRAPHY_WB_MODE_WARM_FLUORESCENT, "warm-fluorescent"},
  {GST_PHOTOGRAPHY_WB_MODE_SHADE, "shade"}
};

struct DataEntry SceneValues[] = {
  {GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT, "portrait"},
  {GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE, "landscape"},
  {GST_PHOTOGRAPHY_SCENE_MODE_SPORT, "sports"},
  {GST_PHOTOGRAPHY_SCENE_MODE_NIGHT, "night"},
  {GST_PHOTOGRAPHY_SCENE_MODE_AUTO, "auto"},
  {GST_PHOTOGRAPHY_SCENE_MODE_ACTION, "action"},
  {GST_PHOTOGRAPHY_SCENE_MODE_NIGHT_PORTRAIT, "night-portrait"},
  {GST_PHOTOGRAPHY_SCENE_MODE_THEATRE, "theatre"},
  {GST_PHOTOGRAPHY_SCENE_MODE_BEACH, "beach"},
  {GST_PHOTOGRAPHY_SCENE_MODE_SNOW, "snow"},
  {GST_PHOTOGRAPHY_SCENE_MODE_SUNSET, "sunset"},
  {GST_PHOTOGRAPHY_SCENE_MODE_STEADY_PHOTO, "steadyphoto"},
  {GST_PHOTOGRAPHY_SCENE_MODE_FIREWORKS, "fireworks"},
  {GST_PHOTOGRAPHY_SCENE_MODE_PARTY, "party"},
  {GST_PHOTOGRAPHY_SCENE_MODE_CANDLELIGHT, "candlelight"},
  {GST_PHOTOGRAPHY_SCENE_MODE_BARCODE, "barcode"}
};

struct DataEntry ColourToneValues[] = {
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_NORMAL, "none"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_SEPIA, "sepia"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_NEGATIVE, "negative"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_GRAYSCALE, "mono"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_VIVID, "vivid"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_SOLARIZE, "solarize"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_SKY_BLUE, "still-sky-blue"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_GRASS_GREEN, "still-grass-green"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_SKIN_WHITEN, "still-skin-whiten-medium"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_POSTERIZE, "posterize"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_WHITEBOARD, "whiteboard"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_BLACKBOARD, "blackboard"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_AQUA, "aqua"},
};

struct DataEntry FlickerValues[] = {
  {GST_PHOTOGRAPHY_FLICKER_REDUCTION_OFF, "off"},
  {GST_PHOTOGRAPHY_FLICKER_REDUCTION_50HZ, "50hz"},
  {GST_PHOTOGRAPHY_FLICKER_REDUCTION_60HZ, "60hz"},
  {GST_PHOTOGRAPHY_FLICKER_REDUCTION_AUTO, "auto"}
};

static GList *gst_droidcamsrc_photography_append_list (GList * list,
    const int key, const gchar * value);
static GList *gst_droidcamsrc_photography_create_list (const gchar * params,
    struct DataEntry entries[], gsize len);

#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);	\<commit_msg>[gst modes] Add additioanl modes from GST for android<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 Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, 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;
  gchar *iso_key;
  GList *flicker;
};

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

struct DataEntry FlashValues[] = {
  {GST_PHOTOGRAPHY_FLASH_MODE_AUTO, "auto"},
  {GST_PHOTOGRAPHY_FLASH_MODE_OFF, "off"},
  {GST_PHOTOGRAPHY_FLASH_MODE_ON, "on"},
  {GST_PHOTOGRAPHY_FLASH_MODE_RED_EYE, "red-eye"}
};

struct DataEntry FocusValues[] = {
  {GST_PHOTOGRAPHY_FOCUS_MODE_AUTO, "auto"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_MACRO, "macro"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_INFINITY, "infinity"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_HYPERFOCAL, "fixed"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_EXTENDED, "edof"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_NORMAL, "continuous"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_EXTENDED, "continuous"},
  {GST_PHOTOGRAPHY_FOCUS_MODE_MANUAL, "manual"}
};

struct DataEntry ISOValues[] = {
  {0, "auto"},
  {0, "iso-auto"},
  {1, "ISO_HJR"},
  {100, "ISO100"},
  {100, "iso-100"},
  {100, "100"},
  {200, "ISO200"},
  {200, "iso-200"},
  {200, "200"},
  {400, "ISO400"},
  {400, "iso-400"},
  {400, "400"},
  {800, "ISO800"},
  {800, "iso-800"},
  {800, "800"},
  {1600, "ISO1600"},
  {1600, "1600"},
  {3200, "ISO3200"},
  {3200, "3200"},
  {6400, "ISO6400"},
  {6400, "6400"},
  {12800, "ISO12800"},
  {12800, "12800"}
};

struct DataEntry WhiteBalanceValues[] = {
  {GST_PHOTOGRAPHY_WB_MODE_AUTO, "auto"},
  {GST_PHOTOGRAPHY_WB_MODE_DAYLIGHT, "daylight"},
  {GST_PHOTOGRAPHY_WB_MODE_CLOUDY, "cloudy-daylight"},
  {GST_PHOTOGRAPHY_WB_MODE_SUNSET, "twilight"},
  {GST_PHOTOGRAPHY_WB_MODE_TUNGSTEN, "incandescent"},
  {GST_PHOTOGRAPHY_WB_MODE_FLUORESCENT, "fluorescent"},
  {GST_PHOTOGRAPHY_WB_MODE_MANUAL, "manual"},
  {GST_PHOTOGRAPHY_WB_MODE_WARM_FLUORESCENT, "warm-fluorescent"},
  {GST_PHOTOGRAPHY_WB_MODE_SHADE, "shade"}
};

struct DataEntry SceneValues[] = {
  {GST_PHOTOGRAPHY_SCENE_MODE_PORTRAIT, "portrait"},
  {GST_PHOTOGRAPHY_SCENE_MODE_LANDSCAPE, "landscape"},
  {GST_PHOTOGRAPHY_SCENE_MODE_SPORT, "sports"},
  {GST_PHOTOGRAPHY_SCENE_MODE_NIGHT, "night"},
  {GST_PHOTOGRAPHY_SCENE_MODE_AUTO, "auto"},
  {GST_PHOTOGRAPHY_SCENE_MODE_ACTION, "action"},
  {GST_PHOTOGRAPHY_SCENE_MODE_NIGHT_PORTRAIT, "night-portrait"},
  {GST_PHOTOGRAPHY_SCENE_MODE_THEATRE, "theatre"},
  {GST_PHOTOGRAPHY_SCENE_MODE_BEACH, "beach"},
  {GST_PHOTOGRAPHY_SCENE_MODE_SNOW, "snow"},
  {GST_PHOTOGRAPHY_SCENE_MODE_SUNSET, "sunset"},
  {GST_PHOTOGRAPHY_SCENE_MODE_STEADY_PHOTO, "steadyphoto"},
  {GST_PHOTOGRAPHY_SCENE_MODE_FIREWORKS, "fireworks"},
  {GST_PHOTOGRAPHY_SCENE_MODE_PARTY, "party"},
  {GST_PHOTOGRAPHY_SCENE_MODE_CANDLELIGHT, "candlelight"},
  {GST_PHOTOGRAPHY_SCENE_MODE_BARCODE, "barcode"},
  {GST_PHOTOGRAPHY_SCENE_MODE_ASD, "asd"},
  {GST_PHOTOGRAPHY_SCENE_MODE_BACKLIGHT, "backlight"},
  {GST_PHOTOGRAPHY_SCENE_MODE_FLOWERS, "flowers"},
  {GST_PHOTOGRAPHY_SCENE_MODE_AR, "AR"},
  {GST_PHOTOGRAPHY_SCENE_MODE_HDR, "hdr"}
};

struct DataEntry ColourToneValues[] = {
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_NORMAL, "none"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_SEPIA, "sepia"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_NEGATIVE, "negative"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_GRAYSCALE, "mono"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_VIVID, "vivid"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_SOLARIZE, "solarize"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_SKY_BLUE, "still-sky-blue"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_GRASS_GREEN, "still-grass-green"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_SKIN_WHITEN, "still-skin-whiten-medium"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_POSTERIZE, "posterize"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_WHITEBOARD, "whiteboard"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_BLACKBOARD, "blackboard"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_AQUA, "aqua"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_EMBOSS, "emboss"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_SKETCH, "sketch"},
  {GST_PHOTOGRAPHY_COLOR_TONE_MODE_NEON, "neon"}
};

struct DataEntry FlickerValues[] = {
  {GST_PHOTOGRAPHY_FLICKER_REDUCTION_OFF, "off"},
  {GST_PHOTOGRAPHY_FLICKER_REDUCTION_50HZ, "50hz"},
  {GST_PHOTOGRAPHY_FLICKER_REDUCTION_60HZ, "60hz"},
  {GST_PHOTOGRAPHY_FLICKER_REDUCTION_AUTO, "auto"}
};

static GList *gst_droidcamsrc_photography_append_list (GList * list,
    const int key, const gchar * value);
static GList *gst_droidcamsrc_photography_create_list (const gchar * params,
    struct DataEntry entries[], gsize len);

#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);	\
{'fraction_non_alphanumeric': 0.11247958628198149, 'fraction_numerical': 0.02286336418072945, 'mean_word_length': 7.070840197693575, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5926030', 'n_tokens_mistral': 6945, 'n_tokens_neox': 6384, 'n_words': 940}