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