Sync with latest src tizen2.4
[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_asm.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 #ifdef __cplusplus
47         extern "C" {
48 #endif
49
50 /*===========================================================================================
51   GLOBAL DEFINITIONS AND DECLARATIONS FOR MODULE
52 ========================================================================================== */
53
54 /*---------------------------------------------------------------------------
55     GLOBAL #defines:
56 ---------------------------------------------------------------------------*/
57 #define SAMPLEDELAY             15000
58
59 /* si470x dependent define */
60 #define SYSCONFIG1                                      4               /* System Configuration 1 */
61 #define SYSCONFIG1_RDS                          0x1000  /* bits 12..12: RDS Enable */
62 #define SYSCONFIG1_RDS_OFFSET           12              /* bits 12..12: RDS Enable Offset */
63
64 #define SYSCONFIG2                                      5               /* System Configuration 2 */
65 #define SYSCONFIG2_SEEKTH                       0xff00  /* bits 15..08: RSSI Seek Threshold */
66 #define SYSCONFIG2_SEEKTH_OFFSET        8               /* bits 15..08: RSSI Seek Threshold Offset */
67
68 #define SYSCONFIG3                                      6               /* System Configuration 3 */
69 #define SYSCONFIG3_SKSNR                        0x00f0  /* bits 07..04: Seek SNR Threshold */
70 #define SYSCONFIG3_SKCNT                        0x000f  /* bits 03..00: Seek FM Impulse Detection Threshold */
71 #define SYSCONFIG3_SKSNR_OFFSET 4               /* bits 07..04: Seek SNR Threshold Offset */
72 #define SYSCONFIG3_SKCNT_OFFSET 0               /* bits 03..00: Seek FM Impulse Detection Threshold Offset */
73
74 #define DEFAULT_CHIP_MODEL                      "radio-si470x"
75
76 /*---------------------------------------------------------------------------
77     GLOBAL CONSTANT DEFINITIONS:
78 ---------------------------------------------------------------------------*/
79 typedef enum
80 {
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_NUM
97 } MMRadioCommand;
98
99 /* max and mix frequency types, KHz */
100 typedef enum
101 {
102         MM_RADIO_FREQ_NONE                              = 0,
103         /* min band types */
104         MM_RADIO_FREQ_MIN_76100_KHZ             = 76100,
105         MM_RADIO_FREQ_MIN_87500_KHZ             = 87500,
106         MM_RADIO_FREQ_MIN_88100_KHZ             = 88100,
107         /* max band types */
108         MM_RADIO_FREQ_MAX_89900_KHZ             = 89900,
109         MM_RADIO_FREQ_MAX_108000_KHZ    = 108000,
110 }MMRadioFreqTypes;
111
112 /* de-emphasis types  */
113 typedef enum
114 {
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 {
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 {
138         GMainLoop *loop;
139         GstElement *pipeline;
140         GstElement *audiosrc;
141         GstElement *queue2;
142         GstElement *volume;
143         GstElement *audiosink;
144         GstBuffer *output_buffer;
145 } mm_radio_gstreamer_s;
146 #endif
147
148 typedef struct {
149         /* radio state */
150         int current_state;
151         int old_state;
152         int pending_state;
153
154         int cmd;
155
156         /* command lock */
157         pthread_mutex_t cmd_lock;
158
159         /* radio attributes */
160         MMHandleType* attrs;
161
162         /* message callback */
163         MMMessageCallback msg_cb;
164         void* msg_cb_param;
165
166         /* radio device fd */
167         int radio_fd;
168
169         /* device control */
170         struct v4l2_capability vc;
171         struct v4l2_tuner vt;
172         struct v4l2_control vctrl;
173         struct v4l2_frequency vf;
174
175         /* hw debug */
176         struct v4l2_dbg_register reg;
177
178         /* scan */
179         pthread_t       scan_thread;
180         bool    stop_scan;
181
182         /* seek */
183         pthread_t seek_thread;
184         int prev_seek_freq;
185         MMRadioSeekDirectionType seek_direction;
186
187         /* ASM */
188         MMRadioASM sm;
189
190         int freq;
191 #ifdef USE_GST_PIPELINE
192         mm_radio_gstreamer_s* pGstreamer_s;
193 #endif
194
195         /* region settings */
196         MMRadioRegion_t region_setting;
197 } mm_radio_t;
198
199 /*===========================================================================================
200   GLOBAL FUNCTION PROTOTYPES
201 ========================================================================================== */
202 int _mmradio_create_radio(mm_radio_t* radio);
203 int _mmradio_destroy(mm_radio_t* radio);
204 int _mmradio_realize(mm_radio_t* radio);
205 int _mmradio_unrealize(mm_radio_t* radio);
206 int _mmradio_set_message_callback(mm_radio_t* radio, MMMessageCallback callback, void *user_param);
207 int _mmradio_get_state(mm_radio_t* radio, int* pState);
208 int _mmradio_set_frequency(mm_radio_t* radio, int freq);
209 int _mmradio_get_frequency(mm_radio_t* radio, int* pFreq);
210 int _mmradio_mute(mm_radio_t* radio);
211 int _mmradio_unmute(mm_radio_t* radio);
212 int _mmradio_start(mm_radio_t* radio);
213 int _mmradio_stop(mm_radio_t* radio);
214 int _mmradio_seek(mm_radio_t* radio, MMRadioSeekDirectionType direction);
215 int _mmradio_start_scan(mm_radio_t* radio);
216 int _mmradio_stop_scan(mm_radio_t* radio);
217 int _mm_radio_get_signal_strength(mm_radio_t* radio, int *value);
218 #ifdef USE_GST_PIPELINE
219 int _mmradio_realize_pipeline( mm_radio_t* radio);
220 int _mmradio_start_pipeline(mm_radio_t* radio);
221 int _mmradio_stop_pipeline( mm_radio_t* radio);
222 int _mmradio_destroy_pipeline(mm_radio_t* radio);
223 #endif
224 int _mmradio_apply_region(mm_radio_t*radio, MMRadioRegionType region, bool update);
225 int _mmradio_get_region_type(mm_radio_t*radio, MMRadioRegionType *type);
226 int _mmradio_get_region_frequency_range(mm_radio_t* radio, unsigned int *min_freq, unsigned int *max_freq);
227 #if 0
228 int mmradio_set_attrs(mm_radio_t*  radio, MMRadioAttrsType type, MMHandleType attrs);
229 MMHandleType mmradio_get_attrs(mm_radio_t*  radio, MMRadioAttrsType type);
230 #endif
231
232 #ifdef __cplusplus
233         }
234 #endif
235
236 #endif  /* __MM_Radio_INTERNAL_H__ */