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