/*
 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __CAMERA_RECORDER_SETTINGS_H__
#define __CAMERA_RECORDER_SETTINGS_H__

#include <camera.h>
#include <recorder.h>

typedef bool (*supported_cb)(int supported_type, void *user_data);
typedef int (*register_supported_func)(void *media_device, supported_cb callback, void *user_data);

typedef struct
{
    const char *label;
    const int mode;
} settings_data;

typedef struct
{
    const settings_data *data;
    int max_data_type;
    bool  *supported;
}settings_supported_data;

typedef struct
{
    int width;
    int height;
} resolution_item;

// Focus Mode Settings
static const settings_data focus_mode[] = // Synchronized with current capi-media-camera Focus Mode states.
{
    {"None", CAMERA_ATTR_AF_NONE},
    {"Normal", CAMERA_ATTR_AF_NORMAL},
    {"Macro", CAMERA_ATTR_AF_MACRO},
    {"Full", CAMERA_ATTR_AF_FULL}
};

// Flash Mode Settings
static const settings_data flash_mode[] = // Synchronized with current capi-media-camera Flash Mode states.
{
    {"Off", CAMERA_ATTR_FLASH_MODE_OFF},
    {"On", CAMERA_ATTR_FLASH_MODE_ON},
    {"Auto", CAMERA_ATTR_FLASH_MODE_AUTO},
    {"Red eye", CAMERA_ATTR_FLASH_MODE_REDEYE_REDUCTION},
    {"Slow sunc", CAMERA_ATTR_FLASH_MODE_SLOW_SYNC},
    {"Front curtain", CAMERA_ATTR_FLASH_MODE_FRONT_CURTAIN},
    {"Rear curtain", CAMERA_ATTR_FLASH_MODE_REAR_CURTAIN},
    {"Permanent", CAMERA_ATTR_FLASH_MODE_PERMANENT}
};

// Iso Level Settings
static const settings_data iso_level[] =     // Synchronized with current capi-media-camera Iso Level states.
{
    {"Auto", CAMERA_ATTR_ISO_AUTO},
    {"50", CAMERA_ATTR_ISO_100},
    {"100", CAMERA_ATTR_ISO_100},
    {"200", CAMERA_ATTR_ISO_200},
    {"400", CAMERA_ATTR_ISO_400},
    {"800", CAMERA_ATTR_ISO_800},
    {"1600", CAMERA_ATTR_ISO_1600},
    {"3200", CAMERA_ATTR_ISO_3200}
};

// White Balance Settings
static const settings_data white_balance[] =     // Synchronized with current capi-media-camera White Balance states.
{
    {"None", CAMERA_ATTR_WHITE_BALANCE_NONE},
    {"Automatic", CAMERA_ATTR_WHITE_BALANCE_AUTOMATIC},
    {"Day light", CAMERA_ATTR_WHITE_BALANCE_DAYLIGHT},
    {"Cloudy", CAMERA_ATTR_WHITE_BALANCE_CLOUDY},
    {"Fluorescent", CAMERA_ATTR_WHITE_BALANCE_FLUORESCENT},
    {"Incandescent", CAMERA_ATTR_WHITE_BALANCE_INCANDESCENT},
    {"Shade", CAMERA_ATTR_WHITE_BALANCE_SHADE},
    {"Horizon", CAMERA_ATTR_WHITE_BALANCE_HORIZON},
    {"Flash", CAMERA_ATTR_WHITE_BALANCE_FLASH},
    {"Custom", CAMERA_ATTR_WHITE_BALANCE_CUSTOM}
};

// Scene Mode Settings
static const settings_data scene_mode[] =     // Synchronized with current capi-media-camera Scene Mode states.
{
    {"Normal", CAMERA_ATTR_SCENE_MODE_NORMAL},
    {"Portrait", CAMERA_ATTR_SCENE_MODE_PORTRAIT},
    {"Landscape", CAMERA_ATTR_SCENE_MODE_LANDSCAPE},
    {"Sports", CAMERA_ATTR_SCENE_MODE_SPORTS},
    {"Party &amp; indoor", CAMERA_ATTR_SCENE_MODE_PARTY_N_INDOOR},
    {"Beach &amp; indoor", CAMERA_ATTR_SCENE_MODE_BEACH_N_INDOOR},
    {"Sunset", CAMERA_ATTR_SCENE_MODE_SUNSET},
    {"Dusk &amp; dawn", CAMERA_ATTR_SCENE_MODE_DUSK_N_DAWN},
    {"Fall", CAMERA_ATTR_SCENE_MODE_FALL_COLOR},
    {"Night scene", CAMERA_ATTR_SCENE_MODE_NIGHT_SCENE},
    {"Firework", CAMERA_ATTR_SCENE_MODE_FIREWORK},
    {"Text", CAMERA_ATTR_SCENE_MODE_TEXT},
    {"Show window", CAMERA_ATTR_SCENE_MODE_SHOW_WINDOW},
    {"Candle light", CAMERA_ATTR_SCENE_MODE_CANDLE_LIGHT},
    {"Backlight", CAMERA_ATTR_SCENE_MODE_BACKLIGHT},
    {"Aqua", CAMERA_ATTR_SCENE_MODE_AQUA}
};

// Effect Settings
static const settings_data effect[] =     // Synchronized with current capi-media-camera Effect states.
{
    {"None", CAMERA_ATTR_EFFECT_NONE},
    {"Mono", CAMERA_ATTR_EFFECT_MONO},
    {"Sepia", CAMERA_ATTR_EFFECT_SEPIA},
    {"Negative", CAMERA_ATTR_EFFECT_NEGATIVE},
    {"Blue", CAMERA_ATTR_EFFECT_BLUE},
    {"Green", CAMERA_ATTR_EFFECT_GREEN},
    {"Aqua", CAMERA_ATTR_EFFECT_AQUA},
    {"Violet", CAMERA_ATTR_EFFECT_VIOLET},
    {"Orange", CAMERA_ATTR_EFFECT_ORANGE},
    {"Gray", CAMERA_ATTR_EFFECT_GRAY},
    {"Red", CAMERA_ATTR_EFFECT_RED},
    {"Antique", CAMERA_ATTR_EFFECT_ANTIQUE},
    {"Warm", CAMERA_ATTR_EFFECT_WARM},
    {"Pink", CAMERA_ATTR_EFFECT_PINK},
    {"Yellow", CAMERA_ATTR_EFFECT_YELLOW},
    {"Purple", CAMERA_ATTR_EFFECT_PURPLE},
    {"Emboss", CAMERA_ATTR_EFFECT_EMBOSS},
    {"Outline", CAMERA_ATTR_EFFECT_OUTLINE},
    {"Solarization", CAMERA_ATTR_EFFECT_SOLARIZATION},
    {"Sketch", CAMERA_ATTR_EFFECT_SKETCH},
    {"Washed", CAMERA_ATTR_EFFECT_WASHED},
    {"Vintage warm ", CAMERA_ATTR_EFFECT_VINTAGE_WARM},
    {"Vintage cold", CAMERA_ATTR_EFFECT_VINTAGE_COLD},
    {"Posterization", CAMERA_ATTR_EFFECT_POSTERIZATION},
    {"Cartoon", CAMERA_ATTR_EFFECT_CARTOON},
    {"Selective color - Red", CAMERA_ATTR_EFFECT_SELECTIVE_RED},
    {"Selective color - Green", CAMERA_ATTR_EFFECT_SELECTIVE_GREEN},
    {"Selective color - Blue", CAMERA_ATTR_EFFECT_SELECTIVE_BLUE},
    {"Selective color - Yellow", CAMERA_ATTR_EFFECT_SELECTIVE_YELLOW},
    {"Selective color - Red and Yellow", CAMERA_ATTR_EFFECT_SELECTIVE_RED_YELLOW},
    {"Other Graphics effect", CAMERA_ATTR_EFFECT_OTHER_GRAPHICS}
};

// FPS Settings
static const settings_data fps[] =     // Synchronized with current capi-media-camera FPS  states.
{
    {"Auto", CAMERA_ATTR_FPS_AUTO},
    {"7", CAMERA_ATTR_FPS_7},
    {"8", CAMERA_ATTR_FPS_8},
    {"15", CAMERA_ATTR_FPS_15},
    {"20", CAMERA_ATTR_FPS_20},
    {"24", CAMERA_ATTR_FPS_24},
    {"25", CAMERA_ATTR_FPS_25},
    {"30", CAMERA_ATTR_FPS_30},
    {"60", CAMERA_ATTR_FPS_60},
    {"90", CAMERA_ATTR_FPS_90},
    {"120", CAMERA_ATTR_FPS_120}
};

//Flip Settings
static const settings_data rotation[] =     // Synchronized with current capi-media-camera Flip states.
{
    {"0", CAMERA_ROTATION_NONE},
    {"90", CAMERA_ROTATION_90},
    {"180", CAMERA_ROTATION_180},
    {"270", CAMERA_ROTATION_270}
};

//Quality Settings
typedef enum
{
    RECORD_QUALITY_LOW,
    RECORD_QUALITY_MEDIUM,
    RECORD_QUALITY_HIGH
}recording_quality;

typedef struct
{
    int bitrate;
    int width;
    int height;
    recording_quality quality;
}quality_components;

static const quality_components quality_table[] =
{
    {48000, 128, 96, RECORD_QUALITY_LOW},
    {64000, 128, 96, RECORD_QUALITY_MEDIUM},
    {80000, 128, 96, RECORD_QUALITY_HIGH},

    {72000, 162, 120, RECORD_QUALITY_LOW},
    {97000, 160, 120, RECORD_QUALITY_MEDIUM},
    {120000, 160, 120, RECORD_QUALITY_HIGH},

    {96000, 800, 600, RECORD_QUALITY_LOW},
    {128000, 800, 600, RECORD_QUALITY_MEDIUM},
    {160000, 800, 600, RECORD_QUALITY_HIGH},

    {96000, 0xfffe, 0xfffe, RECORD_QUALITY_LOW},
    {160000, 0xfffe, 0xfffe, RECORD_QUALITY_MEDIUM},
    {4000000, 0xfffe, 0xfffe, RECORD_QUALITY_HIGH}
};

static const settings_data quality[] =
{
    {"Low", RECORD_QUALITY_LOW},
    {"Medium", RECORD_QUALITY_MEDIUM},
    {"High", RECORD_QUALITY_HIGH}
};

//Video Codec Settings
static const settings_data video_codec[] =     // Synchronized with current capi-media-recorder Video Codec states.
{
    {"H263", RECORDER_VIDEO_CODEC_H263},
    {"H264", RECORDER_VIDEO_CODEC_H264},
    {"MPEG4", RECORDER_VIDEO_CODEC_MPEG4},
    {"Theora", RECORDER_VIDEO_CODEC_THEORA}
};

//Audio Codec Settings
static const settings_data audio_codec[] =     // Synchronized with current capi-media-recorder Audio Codec states.
{
    {"Disable", RECORDER_AUDIO_CODEC_DISABLE},
    {"AMR", RECORDER_AUDIO_CODEC_AMR},
    {"AAC", RECORDER_AUDIO_CODEC_AAC},
    {"Vorbis", RECORDER_AUDIO_CODEC_VORBIS},
    {"PCM", RECORDER_AUDIO_CODEC_PCM}
};

//File Format Settings
static const settings_data file_format[] =     // Synchronized with current capi-media-recorder File Format states.
{
    {"3GP", RECORDER_FILE_FORMAT_3GP},
    {"MP4", RECORDER_FILE_FORMAT_MP4}
};

//Preview Format Settings
static const settings_data preview_format[] =     // Synchronized with current capi-media-camera Pixel Preview Format states.
{
    {"Invalid", CAMERA_PIXEL_FORMAT_INVALID},
    {"NV12", CAMERA_PIXEL_FORMAT_NV12},
    {"NV12 Tiled", CAMERA_PIXEL_FORMAT_NV12T},
    {"NV16", CAMERA_PIXEL_FORMAT_NV16},
    {"NV21", CAMERA_PIXEL_FORMAT_NV21},
    {"YUYV(YUY2)", CAMERA_PIXEL_FORMAT_YUYV},
    {"UYVY", RECORDER_VIDEO_CODEC_H263},
    {"YUV422(Y:U:V) planar", CAMERA_PIXEL_FORMAT_422P},
    {"I420", CAMERA_PIXEL_FORMAT_I420},
    {"YV12", CAMERA_PIXEL_FORMAT_YV12},
    {"RGB565", CAMERA_PIXEL_FORMAT_RGB565},
    {"RGB888", CAMERA_PIXEL_FORMAT_RGB888},
    {"RGBA", CAMERA_PIXEL_FORMAT_RGBA},
    {"ARGB", CAMERA_PIXEL_FORMAT_ARGB},
    {"JPEG Encoded", CAMERA_PIXEL_FORMAT_JPEG}
};

//Exposure Mode Settings
static const settings_data exposure_mode[] =     // Synchronized with current capi-media-camera Exposure Mode states.
{
    {"Off", CAMERA_ATTR_EXPOSURE_MODE_OFF},
    {"All", CAMERA_ATTR_EXPOSURE_MODE_ALL},
    {"Center Tiled", CAMERA_ATTR_EXPOSURE_MODE_CENTER},
    {"Spot", CAMERA_ATTR_EXPOSURE_MODE_SPOT},
    {"Custom", CAMERA_ATTR_EXPOSURE_MODE_CUSTOM}
};

//PreProcessing Mode Settings
typedef enum
{
    PREPROCESSING_ON,
    PREPROCESSING_OFF,
}preprocessing_state;

static const settings_data preprocessing_mode[] =
{
    {"Enable", PREPROCESSING_ON},
    {"Disable", PREPROCESSING_OFF}
};

static const int quality_max_type =        sizeof(quality)/sizeof(settings_data);
static const int rotation_max_type =       sizeof(rotation)/sizeof(const settings_data);
static const int fps_max_type =            sizeof(fps)/sizeof(const settings_data);
static const int effect_max_type =         sizeof(effect)/sizeof(const settings_data);
static const int scene_mode_max_type =     sizeof(scene_mode)/sizeof(const settings_data);
static const int white_balance_max_type =  sizeof(white_balance)/sizeof(const settings_data);
static const int focus_mode_max =          sizeof(focus_mode)/sizeof(const settings_data);
static const int flash_mode_max =          sizeof(flash_mode)/sizeof(const settings_data);
static const int iso_level_max_type =      sizeof(iso_level)/sizeof(const settings_data);
static const int video_codec_max_type =    sizeof(video_codec)/sizeof(const settings_data);
static const int audio_codec_max_type =    sizeof(audio_codec)/sizeof(const settings_data);
static const int file_format_max_type =    sizeof(file_format)/sizeof(const settings_data);
static const int preview_format_max_type = sizeof(preview_format)/sizeof(const settings_data);
static const int exposure_mode_max_type =  sizeof(exposure_mode)/sizeof(const settings_data);
static const int preprocessing_max_type =  sizeof(preprocessing_mode)/sizeof(const settings_data);

int camera_settings_quality_bitrate_get(int width, int height, recording_quality quality);
int camera_settings_item_number_get(settings_supported_data *supported_data, int supported_type);

#endif // __CAMERA_RECORDER_SETTINGS_H__
