Apply tizen coding rule
[platform/core/multimedia/libmm-radio.git] / src / include / mm_radio_priv.h
1 /*
2  * mm_radio_priv.h
3  *
4  * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef __MM_Radio_INTERNAL_H__
21 #define __MM_Radio_INTERNAL_H__
22
23 /*===========================================================================================
24   INCLUDE FILES
25 ========================================================================================== */
26 #include <stdio.h>
27 #include <stdbool.h>
28 #include <unistd.h>
29 #include <malloc.h>
30 #include <pthread.h>
31 #include <signal.h>
32
33 #include <mm_types.h>
34 #include <mm_message.h>
35
36 #ifdef TIZEN_FEATURE_SOUND_FOCUS
37 #include "mm_radio_sound_focus.h"
38 #endif
39
40 #include "mm_radio.h"
41 #include "mm_radio_utils.h"
42 #include <linux/videodev2.h>
43
44 #include <gst/gst.h>
45 #include <gst/gstbuffer.h>
46
47 #ifdef __cplusplus
48         extern "C" {
49 #endif
50
51 /*===========================================================================================
52   GLOBAL DEFINITIONS AND DECLARATIONS FOR MODULE
53 ========================================================================================== */
54
55 /*---------------------------------------------------------------------------
56     GLOBAL #defines:
57 ---------------------------------------------------------------------------*/
58 #define SAMPLEDELAY                                     15000
59
60 /* si470x dependent define */
61 #define SYSCONFIG1                                      4               /* System Configuration 1 */
62 #define SYSCONFIG1_RDS                          0x1000  /* bits 12..12: RDS Enable */
63 #define SYSCONFIG1_RDS_OFFSET           12              /* bits 12..12: RDS Enable Offset */
64
65 #define SYSCONFIG2                                      5               /* System Configuration 2 */
66 #define SYSCONFIG2_SEEKTH                       0xff00  /* bits 15..08: RSSI Seek Threshold */
67 #define SYSCONFIG2_SEEKTH_OFFSET        8               /* bits 15..08: RSSI Seek Threshold Offset */
68
69 #define SYSCONFIG3                                      6               /* System Configuration 3 */
70 #define SYSCONFIG3_SKSNR                        0x00f0  /* bits 07..04: Seek SNR Threshold */
71 #define SYSCONFIG3_SKCNT                        0x000f  /* bits 03..00: Seek FM Impulse Detection Threshold */
72 #define SYSCONFIG3_SKSNR_OFFSET 4               /* bits 07..04: Seek SNR Threshold Offset */
73 #define SYSCONFIG3_SKCNT_OFFSET 0               /* bits 03..00: Seek FM Impulse Detection Threshold Offset */
74
75 #define DEFAULT_CHIP_MODEL                      "radio-si470x"
76
77 /*---------------------------------------------------------------------------
78     GLOBAL CONSTANT DEFINITIONS:
79 ---------------------------------------------------------------------------*/
80 typedef enum {
81         MMRADIO_COMMAND_CREATE = 0,
82         MMRADIO_COMMAND_DESTROY,
83         MMRADIO_COMMAND_REALIZE,
84         MMRADIO_COMMAND_UNREALIZE,
85         MMRADIO_COMMAND_START,
86         MMRADIO_COMMAND_STOP,
87         MMRADIO_COMMAND_START_SCAN,
88         MMRADIO_COMMAND_STOP_SCAN,
89         MMRADIO_COMMAND_SET_FREQ,
90         MMRADIO_COMMAND_GET_FREQ,
91         MMRADIO_COMMAND_MUTE,
92         MMRADIO_COMMAND_UNMUTE,
93         MMRADIO_COMMAND_SEEK,
94         MMRADIO_COMMAND_SET_REGION,
95         MMRADIO_COMMAND_GET_REGION,
96         MMRADIO_COMMAND_SET_VOLUME,
97         MMRADIO_COMMAND_GET_VOLUME,
98         MMRADIO_COMMAND_NUM
99 } MMRadioCommand;
100
101 /* max and mix frequency types, KHz */
102 typedef enum {
103         MM_RADIO_FREQ_NONE                              = 0,
104         /* min band types */
105         MM_RADIO_FREQ_MIN_76100_KHZ             = 76100,
106         MM_RADIO_FREQ_MIN_87500_KHZ             = 87500,
107         MM_RADIO_FREQ_MIN_88100_KHZ             = 88100,
108         /* max band types */
109         MM_RADIO_FREQ_MAX_89900_KHZ             = 89900,
110         MM_RADIO_FREQ_MAX_108000_KHZ    = 108000,
111 } MMRadioFreqTypes;
112
113 /* de-emphasis types  */
114 typedef enum {
115         MM_RADIO_DEEMPHASIS_NONE = 0,
116         MM_RADIO_DEEMPHASIS_50_US,
117         MM_RADIO_DEEMPHASIS_75_US,
118 } MMRadioDeemphasis;
119
120 /* radio region settings */
121 typedef struct {
122         MMRadioRegionType country;
123         MMRadioDeemphasis deemphasis;   // unit :  us
124         MMRadioFreqTypes band_min;              // <- freq. range, unit : KHz
125         MMRadioFreqTypes band_max;              // ->
126         int channel_spacing;                            // TBD
127 } MMRadioRegion_t;
128
129 /*---------------------------------------------------------------------------
130     GLOBAL DATA TYPE DEFINITIONS:
131 ---------------------------------------------------------------------------*/
132 #define USE_GST_PIPELINE
133
134 #ifdef USE_GST_PIPELINE
135 typedef struct _mm_radio_gstreamer_s {
136         GMainLoop *loop;
137         GstElement *pipeline;
138         GstElement *audiosrc;
139         GstElement *queue2;
140         GstElement *volume;
141         GstElement *audiosink;
142         GstBuffer *output_buffer;
143 } mm_radio_gstreamer_s;
144 #endif
145
146 typedef struct {
147         /* radio state */
148         int current_state;
149         int old_state;
150         int pending_state;
151
152         int cmd;
153
154         /* command lock */
155         pthread_mutex_t cmd_lock;
156
157         /* radio attributes */
158         MMHandleType* attrs;
159
160         /* message callback */
161         MMMessageCallback msg_cb;
162         void* msg_cb_param;
163
164         /* radio device fd */
165         int radio_fd;
166
167         /* device control */
168         struct v4l2_capability vc;
169         struct v4l2_tuner vt;
170         struct v4l2_control vctrl;
171         struct v4l2_frequency vf;
172
173         /* hw debug */
174         struct v4l2_dbg_register reg;
175
176         /* scan */
177         pthread_t       scan_thread;
178         bool    stop_scan;
179
180         /* seek */
181         pthread_t seek_thread;
182         int prev_seek_freq;
183         MMRadioSeekDirectionType seek_direction;
184
185 #ifdef TIZEN_FEATURE_SOUND_FOCUS
186         mm_radio_sound_focus sound_focus;
187 #endif
188
189         int freq;
190 #ifdef USE_GST_PIPELINE
191         mm_radio_gstreamer_s* pGstreamer_s;
192 #endif
193         unsigned int subs_id;
194         float local_volume;
195
196         /* region settings */
197         MMRadioRegion_t region_setting;
198 } mm_radio_t;
199
200 /*===========================================================================================
201   GLOBAL FUNCTION PROTOTYPES
202 ========================================================================================== */
203 int _mmradio_create_radio(mm_radio_t *radio);
204 int _mmradio_destroy(mm_radio_t *radio);
205 int _mmradio_realize(mm_radio_t *radio);
206 int _mmradio_unrealize(mm_radio_t *radio);
207 int _mmradio_set_message_callback(mm_radio_t *radio, MMMessageCallback callback, void *user_param);
208 int _mmradio_get_state(mm_radio_t *radio, int *pState);
209 int _mmradio_set_frequency(mm_radio_t *radio, int freq);
210 int _mmradio_get_frequency(mm_radio_t *radio, int *pFreq);
211 int _mmradio_mute(mm_radio_t *radio);
212 int _mmradio_unmute(mm_radio_t *radio);
213 int _mmradio_start(mm_radio_t *radio);
214 int _mmradio_stop(mm_radio_t *radio);
215 int _mmradio_seek(mm_radio_t *radio, MMRadioSeekDirectionType direction);
216 int _mmradio_start_scan(mm_radio_t *radio);
217 int _mmradio_stop_scan(mm_radio_t *radio);
218 int _mm_radio_get_signal_strength(mm_radio_t *radio, int *strength);
219 #ifdef USE_GST_PIPELINE
220 int _mmradio_realize_pipeline(mm_radio_t *radio);
221 int _mmradio_start_pipeline(mm_radio_t *radio);
222 int _mmradio_stop_pipeline(mm_radio_t *radio);
223 int _mmradio_destroy_pipeline(mm_radio_t *radio);
224 #endif
225 int _mmradio_apply_region(mm_radio_t *radio, MMRadioRegionType region, bool update);
226 int _mmradio_get_region_type(mm_radio_t *radio, MMRadioRegionType *type);
227 int _mmradio_get_region_frequency_range(mm_radio_t *radio, unsigned int *min_freq, unsigned int *max_freq);
228 int _mmradio_get_channel_spacing(mm_radio_t *radio, unsigned int *ch_spacing);
229 int _mmradio_set_volume(mm_radio_t *radio, float volume);
230 int _mmradio_get_volume(mm_radio_t *radio, float *pVolume);
231
232 #ifdef __cplusplus
233         }
234 #endif
235
236 #endif  /* __MM_Radio_INTERNAL_H__ */