summaryrefslogtreecommitdiff
path: root/src/include/mm_radio_priv.h
blob: f45faac6f7561b9f2b4c96a273a30b7c4f88096c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
 * mm_radio_priv.h
 *
 * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef __MM_Radio_INTERNAL_H__
#define	__MM_Radio_INTERNAL_H__

/*===========================================================================================
  INCLUDE FILES
========================================================================================== */
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <malloc.h>
#include <pthread.h>
#include <signal.h>

#include <mm_types.h>
#include <mm_message.h>

#ifdef TIZEN_FEATURE_SOUND_FOCUS
#include "mm_radio_sound_focus.h"
#endif

#include "mm_radio.h"
#include "mm_radio_utils.h"
#include "mm_radio_resource.h"
#include <linux/videodev2.h>

#include <gst/gst.h>
#include <gst/gstbuffer.h>

#ifdef __cplusplus
	extern "C" {
#endif

/*===========================================================================================
  GLOBAL DEFINITIONS AND DECLARATIONS FOR MODULE
========================================================================================== */

/*---------------------------------------------------------------------------
    GLOBAL #defines:
---------------------------------------------------------------------------*/
#define SAMPLEDELAY					15000

/* si470x dependent define */
#define SYSCONFIG1					4		/* System Configuration 1 */
#define SYSCONFIG1_RDS				0x1000	/* bits 12..12: RDS Enable */
#define SYSCONFIG1_RDS_OFFSET		12		/* bits 12..12: RDS Enable Offset */

#define SYSCONFIG2					5		/* System Configuration 2 */
#define SYSCONFIG2_SEEKTH			0xff00	/* bits 15..08: RSSI Seek Threshold */
#define SYSCONFIG2_SEEKTH_OFFSET	8		/* bits 15..08: RSSI Seek Threshold Offset */

#define SYSCONFIG3					6		/* System Configuration 3 */
#define SYSCONFIG3_SKSNR			0x00f0	/* bits 07..04: Seek SNR Threshold */
#define SYSCONFIG3_SKCNT			0x000f	/* bits 03..00: Seek FM Impulse Detection Threshold */
#define SYSCONFIG3_SKSNR_OFFSET	4		/* bits 07..04: Seek SNR Threshold Offset */
#define SYSCONFIG3_SKCNT_OFFSET	0		/* bits 03..00: Seek FM Impulse Detection Threshold Offset */

#define DEFAULT_CHIP_MODEL			"radio-si470x"

/*---------------------------------------------------------------------------
    GLOBAL CONSTANT DEFINITIONS:
---------------------------------------------------------------------------*/
typedef enum {
	MMRADIO_COMMAND_CREATE = 0,
	MMRADIO_COMMAND_DESTROY,
	MMRADIO_COMMAND_REALIZE,
	MMRADIO_COMMAND_UNREALIZE,
	MMRADIO_COMMAND_START,
	MMRADIO_COMMAND_STOP,
	MMRADIO_COMMAND_START_SCAN,
	MMRADIO_COMMAND_STOP_SCAN,
	MMRADIO_COMMAND_SET_FREQ,
	MMRADIO_COMMAND_GET_FREQ,
	MMRADIO_COMMAND_MUTE,
	MMRADIO_COMMAND_UNMUTE,
	MMRADIO_COMMAND_SEEK,
	MMRADIO_COMMAND_SET_REGION,
	MMRADIO_COMMAND_GET_REGION,
	MMRADIO_COMMAND_SET_VOLUME,
	MMRADIO_COMMAND_GET_VOLUME,
	MMRADIO_COMMAND_NUM
} MMRadioCommand;

/* max and mix frequency types, KHz */
typedef enum {
	MM_RADIO_FREQ_NONE				= 0,
	/* min band types */
	MM_RADIO_FREQ_MIN_76100_KHZ		= 76100,
	MM_RADIO_FREQ_MIN_87500_KHZ		= 87500,
	MM_RADIO_FREQ_MIN_88100_KHZ		= 88100,
	/* max band types */
	MM_RADIO_FREQ_MAX_89900_KHZ		= 89900,
	MM_RADIO_FREQ_MAX_108000_KHZ	= 108000,
} MMRadioFreqTypes;

/* de-emphasis types  */
typedef enum {
	MM_RADIO_DEEMPHASIS_NONE = 0,
	MM_RADIO_DEEMPHASIS_50_US,
	MM_RADIO_DEEMPHASIS_75_US,
} MMRadioDeemphasis;

/* radio region settings */
typedef struct {
	MMRadioRegionType country;
	MMRadioDeemphasis deemphasis;	// unit :  us
	MMRadioFreqTypes band_min;		// <- freq. range, unit : KHz
	MMRadioFreqTypes band_max;		// ->
	int channel_spacing;				// TBD
} MMRadioRegion_t;

/*---------------------------------------------------------------------------
    GLOBAL DATA TYPE DEFINITIONS:
---------------------------------------------------------------------------*/
#define USE_GST_PIPELINE

#ifdef USE_GST_PIPELINE
typedef struct _mm_radio_gstreamer_s {
	GMainLoop *loop;
	GstElement *pipeline;
	GstElement *audiosrc;
	GstElement *queue2;
	GstElement *volume;
	GstElement *audiosink;
	GstBuffer *output_buffer;
} mm_radio_gstreamer_s;
#endif

typedef struct {
	/* radio state */
	int current_state;
	int old_state;
	int pending_state;

	int cmd;

	/* command lock */
	pthread_mutex_t cmd_lock;

	/* radio attributes */
	MMHandleType* attrs;

	/* message callback */
	MMMessageCallback msg_cb;
	void* msg_cb_param;

	/* radio device fd */
	int radio_fd;

	/* device control */
	struct v4l2_capability vc;
	struct v4l2_tuner vt;
	struct v4l2_control vctrl;
	struct v4l2_frequency vf;

	/* hw debug */
	struct v4l2_dbg_register reg;

	/* scan */
	pthread_t	scan_thread;
	bool	stop_scan;

	/* seek */
	pthread_t seek_thread;
	int prev_seek_freq;
	MMRadioSeekDirectionType seek_direction;

#ifdef TIZEN_FEATURE_SOUND_FOCUS
	mm_radio_sound_focus sound_focus;
#endif

	int freq;
#ifdef USE_GST_PIPELINE
	mm_radio_gstreamer_s* pGstreamer_s;
#endif
	mm_radio_resource_manager resource_manager;
	unsigned int subs_id;
	float local_volume;

	/* region settings */
	MMRadioRegion_t	region_setting;
} mm_radio_t;

/*===========================================================================================
  GLOBAL FUNCTION PROTOTYPES
========================================================================================== */
int _mmradio_create_radio(mm_radio_t *radio);
int _mmradio_destroy(mm_radio_t *radio);
int _mmradio_realize(mm_radio_t *radio);
int _mmradio_unrealize(mm_radio_t *radio);
int _mmradio_set_message_callback(mm_radio_t *radio, MMMessageCallback callback, void *user_param);
int _mmradio_get_state(mm_radio_t *radio, int *pState);
int _mmradio_set_frequency(mm_radio_t *radio, int freq);
int _mmradio_get_frequency(mm_radio_t *radio, int *pFreq);
int _mmradio_mute(mm_radio_t *radio);
int _mmradio_unmute(mm_radio_t *radio);
int _mmradio_start(mm_radio_t *radio);
int _mmradio_stop(mm_radio_t *radio);
int _mmradio_seek(mm_radio_t *radio, MMRadioSeekDirectionType direction);
int _mmradio_start_scan(mm_radio_t *radio);
int _mmradio_stop_scan(mm_radio_t *radio);
int _mm_radio_get_signal_strength(mm_radio_t *radio, int *strength);
#ifdef USE_GST_PIPELINE
int _mmradio_realize_pipeline(mm_radio_t *radio);
int _mmradio_start_pipeline(mm_radio_t *radio);
int _mmradio_stop_pipeline(mm_radio_t *radio);
int _mmradio_destroy_pipeline(mm_radio_t *radio);
#endif
int _mmradio_apply_region(mm_radio_t *radio, MMRadioRegionType region, bool update);
int _mmradio_get_region_type(mm_radio_t *radio, MMRadioRegionType *type);
int _mmradio_get_region_frequency_range(mm_radio_t *radio, unsigned int *min_freq, unsigned int *max_freq);
int _mmradio_get_channel_spacing(mm_radio_t *radio, unsigned int *ch_spacing);
int _mmradio_set_volume(mm_radio_t *radio, float volume);
int _mmradio_get_volume(mm_radio_t *radio, float *pVolume);

#ifdef __cplusplus
	}
#endif

#endif	/* __MM_Radio_INTERNAL_H__ */