Disable sound focus feature
[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 #include <media/mm_resource_manager.h>
36
37 #include "mm_radio.h"
38 #include "mm_radio_utils.h"
39 #include <linux/videodev2.h>
40
41 #include <gst/gst.h>
42 #include <gst/gstbuffer.h>
43
44 #ifdef __cplusplus
45         extern "C" {
46 #endif
47
48 /*===========================================================================================
49   GLOBAL DEFINITIONS AND DECLARATIONS FOR MODULE
50 ========================================================================================== */
51
52 /*---------------------------------------------------------------------------
53     GLOBAL #defines:
54 ---------------------------------------------------------------------------*/
55 #define SAMPLEDELAY                                     15000
56
57 /* si470x dependent define */
58 #define SYSCONFIG1                                      4               /* System Configuration 1 */
59 #define SYSCONFIG1_RDS                          0x1000  /* bits 12..12: RDS Enable */
60 #define SYSCONFIG1_RDS_OFFSET           12              /* bits 12..12: RDS Enable Offset */
61
62 #define SYSCONFIG2                                      5               /* System Configuration 2 */
63 #define SYSCONFIG2_SEEKTH                       0xff00  /* bits 15..08: RSSI Seek Threshold */
64 #define SYSCONFIG2_SEEKTH_OFFSET        8               /* bits 15..08: RSSI Seek Threshold Offset */
65
66 #define SYSCONFIG3                                      6               /* System Configuration 3 */
67 #define SYSCONFIG3_SKSNR                        0x00f0  /* bits 07..04: Seek SNR Threshold */
68 #define SYSCONFIG3_SKCNT                        0x000f  /* bits 03..00: Seek FM Impulse Detection Threshold */
69 #define SYSCONFIG3_SKSNR_OFFSET 4               /* bits 07..04: Seek SNR Threshold Offset */
70 #define SYSCONFIG3_SKCNT_OFFSET 0               /* bits 03..00: Seek FM Impulse Detection Threshold Offset */
71
72 #define DEFAULT_CHIP_MODEL                      "radio-si470x"
73
74 /*---------------------------------------------------------------------------
75     GLOBAL CONSTANT DEFINITIONS:
76 ---------------------------------------------------------------------------*/
77 typedef enum {
78         MMRADIO_COMMAND_CREATE = 0,
79         MMRADIO_COMMAND_DESTROY,
80         MMRADIO_COMMAND_REALIZE,
81         MMRADIO_COMMAND_UNREALIZE,
82         MMRADIO_COMMAND_START,
83         MMRADIO_COMMAND_STOP,
84         MMRADIO_COMMAND_START_SCAN,
85         MMRADIO_COMMAND_STOP_SCAN,
86         MMRADIO_COMMAND_SET_FREQ,
87         MMRADIO_COMMAND_GET_FREQ,
88         MMRADIO_COMMAND_MUTE,
89         MMRADIO_COMMAND_UNMUTE,
90         MMRADIO_COMMAND_SEEK,
91         MMRADIO_COMMAND_SET_REGION,
92         MMRADIO_COMMAND_GET_REGION,
93         MMRADIO_COMMAND_SET_VOLUME,
94         MMRADIO_COMMAND_GET_VOLUME,
95         MMRADIO_COMMAND_NUM
96 } MMRadioCommand;
97
98 /* max and mix frequency types, KHz */
99 typedef enum {
100         MM_RADIO_FREQ_NONE                              = 0,
101         /* min band types */
102         MM_RADIO_FREQ_MIN_76100_KHZ             = 76100,
103         MM_RADIO_FREQ_MIN_87500_KHZ             = 87500,
104         MM_RADIO_FREQ_MIN_88100_KHZ             = 88100,
105         /* max band types */
106         MM_RADIO_FREQ_MAX_89900_KHZ             = 89900,
107         MM_RADIO_FREQ_MAX_108000_KHZ    = 108000,
108 } MMRadioFreqTypes;
109
110 /* de-emphasis types  */
111 typedef enum {
112         MM_RADIO_DEEMPHASIS_NONE = 0,
113         MM_RADIO_DEEMPHASIS_50_US,
114         MM_RADIO_DEEMPHASIS_75_US,
115 } MMRadioDeemphasis;
116
117 /* radio region settings */
118 typedef struct {
119         MMRadioRegionType country;
120         MMRadioDeemphasis deemphasis;   // unit :  us
121         MMRadioFreqTypes band_min;              // <- freq. range, unit : KHz
122         MMRadioFreqTypes band_max;              // ->
123         int channel_spacing;                            // TBD
124 } MMRadioRegion_t;
125
126 typedef struct {
127         pthread_t thread;
128         pthread_mutex_t mutex;
129         pthread_cond_t cond;
130         int thread_id;
131         bool is_running;
132         bool stop;
133         bool thread_exit;
134 } MMRadioThread_t;
135
136 /*---------------------------------------------------------------------------
137     GLOBAL DATA TYPE DEFINITIONS:
138 ---------------------------------------------------------------------------*/
139 #define USE_GST_PIPELINE
140
141 #ifdef USE_GST_PIPELINE
142 typedef struct _mm_radio_gstreamer_s {
143         GMainLoop *loop;
144         GstElement *pipeline;
145         GstElement *audiosrc;
146         GstElement *queue2;
147         GstElement *volume;
148         GstElement *audiosink;
149         GstBuffer *output_buffer;
150 } mm_radio_gstreamer_s;
151 #endif
152
153 typedef struct {
154         /* radio state */
155         int current_state;
156         int old_state;
157         int pending_state;
158
159         int cmd;
160
161         /* command lock */
162         pthread_mutex_t cmd_lock;
163
164         /* radio attributes */
165         MMHandleType* attrs;
166
167         /* message callback */
168         MMMessageCallback msg_cb;
169         void* msg_cb_param;
170
171         /* radio device fd */
172         int radio_fd;
173
174         /* device control */
175         struct v4l2_capability vc;
176         struct v4l2_tuner vt;
177         struct v4l2_control vctrl;
178         struct v4l2_frequency vf;
179
180         /* hw debug */
181         struct v4l2_dbg_register reg;
182
183         /* scan */
184         MMRadioThread_t scan;
185
186         /* seek */
187         MMRadioThread_t seek;
188         int prev_seek_freq;
189         MMRadioSeekDirectionType seek_direction;
190
191         int freq;
192 #ifdef USE_GST_PIPELINE
193         mm_radio_gstreamer_s* pGstreamer_s;
194 #endif
195         mm_resource_manager_h resource_manager;
196         mm_resource_manager_res_h radio_resource;
197         int interrupted_by_resource_conflict;
198
199         unsigned int subs_id;
200         float local_volume;
201
202         /* region settings */
203         MMRadioRegion_t region_setting;
204 } mm_radio_t;
205
206 /*===========================================================================================
207   GLOBAL FUNCTION PROTOTYPES
208 ========================================================================================== */
209 int _mmradio_create_radio(mm_radio_t *radio);
210 int _mmradio_destroy(mm_radio_t *radio);
211 int _mmradio_realize(mm_radio_t *radio);
212 int _mmradio_unrealize(mm_radio_t *radio);
213 int _mmradio_set_message_callback(mm_radio_t *radio, MMMessageCallback callback, void *user_param);
214 int _mmradio_get_state(mm_radio_t *radio, int *pState);
215 int _mmradio_set_frequency(mm_radio_t *radio, int freq);
216 int _mmradio_get_frequency(mm_radio_t *radio, int *pFreq);
217 int _mmradio_mute(mm_radio_t *radio);
218 int _mmradio_unmute(mm_radio_t *radio);
219 int _mmradio_start(mm_radio_t *radio);
220 int _mmradio_stop(mm_radio_t *radio);
221 int _mmradio_seek(mm_radio_t *radio, MMRadioSeekDirectionType direction);
222 int _mmradio_start_scan(mm_radio_t *radio);
223 int _mmradio_stop_scan(mm_radio_t *radio);
224 int _mm_radio_get_signal_strength(mm_radio_t *radio, int *strength);
225 #ifdef USE_GST_PIPELINE
226 int _mmradio_realize_pipeline(mm_radio_t *radio);
227 int _mmradio_start_pipeline(mm_radio_t *radio);
228 int _mmradio_stop_pipeline(mm_radio_t *radio);
229 int _mmradio_destroy_pipeline(mm_radio_t *radio);
230 #endif
231 int _mmradio_apply_region(mm_radio_t *radio, MMRadioRegionType region, bool update);
232 int _mmradio_get_region_type(mm_radio_t *radio, MMRadioRegionType *type);
233 int _mmradio_get_region_frequency_range(mm_radio_t *radio, unsigned int *min_freq, unsigned int *max_freq);
234 int _mmradio_get_channel_spacing(mm_radio_t *radio, unsigned int *ch_spacing);
235 int _mmradio_set_volume(mm_radio_t *radio, float volume);
236 int _mmradio_get_volume(mm_radio_t *radio, float *pVolume);
237
238 #ifdef __cplusplus
239         }
240 #endif
241
242 #endif  /* __MM_Radio_INTERNAL_H__ */