Mercurial > mplayer.hg
annotate stream/stream_radio.c @ 30503:53be04353b90
Explain WIN32_LOADER definition hack.
author | diego |
---|---|
date | Fri, 12 Feb 2010 14:25:25 +0000 |
parents | 0f1b5b68af32 |
children | 32725ca88fed |
rev | line source |
---|---|
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1 /* |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
2 * radio support |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
3 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
4 * Abilities: |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
5 * * Listening v4l compatible radio cards using line-in or |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
6 * similar cable |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
7 * * Grabbing audio data using -ao pcm or -dumpaudio |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
8 * (must be compiled with --enable-radio-capture). |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
9 * |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
10 * Initially written by Vladimir Voroshilov <voroshil@univer.omsk.su>. |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
11 * Based on tv.c and tvi_v4l2.c code. |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
12 * |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
13 * This file is part of MPlayer. |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
14 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
15 * MPlayer is free software; you can redistribute it and/or modify |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
16 * it under the terms of the GNU General Public License as published by |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
17 * the Free Software Foundation; either version 2 of the License, or |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
18 * (at your option) any later version. |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
19 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
20 * MPlayer is distributed in the hope that it will be useful, |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
23 * GNU General Public License for more details. |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
24 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
25 * You should have received a copy of the GNU General Public License along |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
26 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
25962
diff
changeset
|
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
28 */ |
19608
18a538908577
Check for requirements at configure-time, not at run-time.
diego
parents:
19606
diff
changeset
|
29 #include "config.h" |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
30 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
31 #include <stdlib.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
32 #include <stdio.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
33 #include <string.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
34 #include <sys/ioctl.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
35 #include <errno.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
36 #include <unistd.h> |
20985 | 37 |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
38 #ifdef CONFIG_RADIO_BSDBT848 |
20985 | 39 #include <sys/param.h> |
22948 | 40 #ifdef IOCTL_BT848_H_NAME |
41 #include IOCTL_BT848_H_NAME | |
42 #endif | |
20985 | 43 |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
44 #else /* CONFIG_RADIO_BSDBT848 */ |
20985 | 45 |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
46 #include <linux/types.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
47 |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
48 #ifdef CONFIG_RADIO_V4L2 |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
49 #include <linux/videodev2.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
50 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
51 |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
52 #ifdef CONFIG_RADIO_V4L |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
53 #include <linux/videodev.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
54 #warning "V4L is deprecated and will be removed in future" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
55 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
56 |
22948 | 57 #endif // !IOCTL_BT848_H_NAME |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
58 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
59 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
60 #include "stream.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
61 #include "libmpdemux/demuxer.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
62 #include "m_struct.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
63 #include "m_option.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
64 #include "mp_msg.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
65 #include "help_mp.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
66 #include "stream_radio.h" |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23485
diff
changeset
|
67 #include "libavutil/avstring.h" |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
68 |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
69 #ifdef CONFIG_RADIO_CAPTURE |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
70 #include "audio_in.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
71 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
72 #ifdef HAVE_SYS_SOUNDCARD_H |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
73 #include <sys/soundcard.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
74 #else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
75 #ifdef HAVE_SOUNDCARD_H |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
76 #include <soundcard.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
77 #else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
78 #include <linux/soundcard.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
79 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
80 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
81 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
82 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
83 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
84 typedef struct radio_channels_s { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
85 int index; ///< channel index in channels list |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
86 float freq; ///< frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
87 char name[20]; ///< channel name |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
88 struct radio_channels_s * next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
89 struct radio_channels_s * prev; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
90 } radio_channels_t; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
91 |
23890 | 92 /// default values for options |
93 radio_param_t stream_radio_defaults={ | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
94 #ifdef CONFIG_RADIO_BSDBT848 |
23890 | 95 "/dev/tuner0", //device |
96 87.50, //freq_min | |
97 108.00, //freq_max | |
20985 | 98 #else |
23890 | 99 "/dev/radio0", //device; |
20985 | 100 #endif |
23890 | 101 "default", //driver |
102 NULL, //channels | |
103 100, //volume | |
104 NULL, //adevice | |
105 44100, //arate | |
106 2, //achannels | |
107 0, //freq_channel | |
108 NULL, //capture | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
109 }; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
110 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
111 typedef struct radio_priv_s { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
112 int radio_fd; ///< radio device descriptor |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
113 int frac; ///< fraction value (see comment to init_frac) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
114 radio_channels_t* radio_channel_list; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
115 radio_channels_t* radio_channel_current; |
20758
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
116 float rangelow; ///< lowest tunable frequency in MHz |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
117 float rangehigh; ///< highest tunable frequency in MHz |
22754 | 118 const struct radio_driver_s* driver; |
20737 | 119 int old_snd_volume; |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
120 #ifdef CONFIG_RADIO_CAPTURE |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
121 volatile int do_capture; ///< is capture enabled |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
122 audio_in_t audio_in; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
123 unsigned char* audio_ringbuffer; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
124 int audio_head; ///< start of meanfull data in ringbuffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
125 int audio_tail; ///< end of meanfull data in ringbuffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
126 int audio_buffer_size; ///< size of ringbuffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
127 int audio_cnt; ///< size of meanfull data inringbuffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
128 int audio_drop; ///< number of dropped bytes |
25962 | 129 int audio_initialized; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
130 #endif |
23890 | 131 radio_param_t *radio_param; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
132 } radio_priv_t; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
133 |
22754 | 134 typedef struct radio_driver_s { |
135 char* name; | |
136 char* info; | |
137 int (*init_frac)(radio_priv_t* priv); | |
138 void (*set_volume)(radio_priv_t* priv,int volume); | |
139 int (*get_volume)(radio_priv_t* priv,int* volume); | |
140 int (*set_frequency)(radio_priv_t* priv,float frequency); | |
141 int (*get_frequency)(radio_priv_t* priv,float* frequency); | |
142 } radio_driver_t; | |
143 | |
23890 | 144 #define ST_OFF(f) M_ST_OFF(radio_param_t,f) |
25242 | 145 static const m_option_t stream_opts_fields[] = { |
23890 | 146 {"hostname", ST_OFF(freq_channel), CONF_TYPE_FLOAT, 0, 0 ,0, NULL}, |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
147 {"filename", ST_OFF(capture), CONF_TYPE_STRING, 0, 0 ,0, NULL}, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
148 { NULL, NULL, 0, 0, 0, 0, NULL } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
149 }; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
150 |
25691 | 151 static const struct m_struct_st stream_opts = { |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
152 "radio", |
23890 | 153 sizeof(radio_param_t), |
154 &stream_radio_defaults, | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
155 stream_opts_fields |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
156 }; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
157 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
158 static void close_s(struct stream_st * stream); |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
159 #ifdef CONFIG_RADIO_CAPTURE |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
160 static int clear_buffer(radio_priv_t* priv); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
161 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
162 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
163 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
164 /***************************************************************** |
23890 | 165 * \brief parse channels parameter and store result into list |
166 * \param freq_channel if channels!=NULL this mean channel number, otherwise - frequency | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
167 * \param pfreq selected frequency (from selected channel or from URL) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
168 * \result STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
169 * |
23890 | 170 * channels option must be in the following format |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
171 * <frequency>-<name>,<frequency>-<name>,... |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
172 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
173 * '_' will be replaced with spaces. |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
174 * |
23890 | 175 * If channels option is not null, number in movie URL will be treated as |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
176 * channel position in channel list. |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
177 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
178 static int parse_channels(radio_priv_t* priv,float freq_channel,float* pfreq){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
179 char** channels; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
180 int i; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
181 int channel = 0; |
23890 | 182 if (priv->radio_param->channels){ |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
183 /*parsing channels string*/ |
23890 | 184 channels=priv->radio_param->channels; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
185 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
186 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_ChannelNamesDetected); |
19606 | 187 priv->radio_channel_list = malloc(sizeof(radio_channels_t)); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
188 priv->radio_channel_list->index=1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
189 priv->radio_channel_list->next=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
190 priv->radio_channel_list->prev=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
191 priv->radio_channel_current = priv->radio_channel_list; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
192 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
193 while (*channels) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
194 char* tmp = *(channels++); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
195 char* sep = strchr(tmp,'-'); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
196 if (!sep) continue; // Wrong syntax, but mplayer should not crash |
23703
9fb716ab06a3
Avoid code duplication and ugly config.h hack by using av_strlcat/av_strlcpy
reimar
parents:
23485
diff
changeset
|
197 av_strlcpy(priv->radio_channel_current->name, sep + 1,sizeof(priv->radio_channel_current->name)-1); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
198 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
199 sep[0] = '\0'; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
200 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
201 priv->radio_channel_current->freq=atof(tmp); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
202 |
20758
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
203 if ((priv->radio_channel_current->freq>priv->rangehigh)||(priv->radio_channel_current->freq<priv->rangelow)) |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
204 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_WrongFreqForChannel, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
205 priv->radio_channel_current->name); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
206 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
207 while ((sep=strchr(priv->radio_channel_current->name, '_'))) sep[0] = ' '; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
208 |
19606 | 209 priv->radio_channel_current->next = malloc(sizeof(radio_channels_t)); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
210 priv->radio_channel_current->next->index = priv->radio_channel_current->index + 1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
211 priv->radio_channel_current->next->prev = priv->radio_channel_current; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
212 priv->radio_channel_current->next->next = NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
213 priv->radio_channel_current = priv->radio_channel_current->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
214 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
215 if (priv->radio_channel_current->prev) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
216 priv->radio_channel_current->prev->next = NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
217 free(priv->radio_channel_current); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
218 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
219 if (freq_channel) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
220 channel = freq_channel; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
221 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
222 channel = 1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
223 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
224 priv->radio_channel_current = priv->radio_channel_list; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
225 for (i = 1; i < channel; i++) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
226 if (priv->radio_channel_current->next) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
227 priv->radio_channel_current = priv->radio_channel_current->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
228 if (priv->radio_channel_current->index!=channel){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
229 if (((float)((int)freq_channel))!=freq_channel) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
230 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_WrongChannelNumberFloat,freq_channel); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
231 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
232 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_WrongChannelNumberInt,(int)freq_channel); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
233 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
234 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
235 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_SelectedChannel, priv->radio_channel_current->index, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
236 priv->radio_channel_current->name, priv->radio_channel_current->freq); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
237 *pfreq=priv->radio_channel_current->freq; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
238 }else{ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
239 if (freq_channel){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
240 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_FreqParameterDetected); |
19606 | 241 priv->radio_channel_list=malloc(sizeof(radio_channels_t)); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
242 priv->radio_channel_list->next=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
243 priv->radio_channel_list->prev=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
244 priv->radio_channel_list->index=1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
245 snprintf(priv->radio_channel_list->name,sizeof(priv->radio_channel_current->name)-1,"Freq: %.2f",freq_channel); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
246 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
247 priv->radio_channel_current=priv->radio_channel_list; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
248 *pfreq=freq_channel; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
249 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
250 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
251 mp_msg(MSGT_RADIO, MSGL_DBG2, MSGTR_RADIO_DoneParsingChannels); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
252 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
253 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
254 |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
255 #ifdef CONFIG_RADIO_V4L2 |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
256 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
257 * \brief get fraction value for using in set_frequency and get_frequency |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
258 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
259 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
260 * V4L2_TUNER_CAP_LOW: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
261 * unit=62.5Hz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
262 * frac= 1MHz/unit=1000000/62.5 =16000 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
263 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
264 * otherwise: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
265 * unit=62500Hz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
266 * frac= 1MHz/unit=1000000/62500 =16 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
267 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
268 static int init_frac_v4l2(radio_priv_t* priv){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
269 struct v4l2_tuner tuner; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
270 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
271 memset(&tuner,0,sizeof(tuner)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
272 tuner.index=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
273 if (ioctl(priv->radio_fd, VIDIOC_G_TUNER, &tuner)<0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
274 mp_msg(MSGT_RADIO,MSGL_WARN,MSGTR_RADIO_GetTunerFailed,strerror(errno),priv->frac); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
275 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
276 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
277 if(tuner.type!=V4L2_TUNER_RADIO){ |
23890 | 278 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_NotRadioDevice,priv->radio_param->device); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
279 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
280 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
281 if(tuner.capability & V4L2_TUNER_CAP_LOW){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
282 priv->frac=16000; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
283 mp_msg(MSGT_RADIO,MSGL_DBG2,MSGTR_RADIO_TunerCapLowYes,priv->frac); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
284 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
285 else{ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
286 priv->frac=16; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
287 mp_msg(MSGT_RADIO,MSGL_DBG2,MSGTR_RADIO_TunerCapLowNo,priv->frac); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
288 } |
20758
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
289 |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
290 priv->rangelow=((float)tuner.rangelow)/priv->frac; |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
291 priv->rangehigh=((float)tuner.rangehigh)/priv->frac; |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
292 mp_msg(MSGT_RADIO,MSGL_V,MSGTR_RADIO_FreqRange,priv->rangelow,priv->rangehigh); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
293 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
294 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
295 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
296 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
297 * \brief tune card to given frequency |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
298 * \param frequency frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
299 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
300 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
301 static int set_frequency_v4l2(radio_priv_t* priv,float frequency){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
302 struct v4l2_frequency freq; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
303 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
304 memset(&freq,0,sizeof(freq)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
305 freq.tuner=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
306 freq.type=V4L2_TUNER_RADIO; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
307 freq.frequency=frequency*priv->frac; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
308 if(ioctl(priv->radio_fd,VIDIOC_S_FREQUENCY,&freq)<0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
309 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_SetFreqFailed,freq.frequency, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
310 frequency,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
311 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
312 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
313 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
314 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
315 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
316 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
317 * \brief get current tuned frequency from card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
318 * \param frequency where to store frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
319 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
320 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
321 static int get_frequency_v4l2(radio_priv_t* priv,float* frequency){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
322 struct v4l2_frequency freq; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
323 memset(&freq,0,sizeof(freq)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
324 if (ioctl(priv->radio_fd, VIDIOC_G_FREQUENCY, &freq) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
325 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_GetFreqFailed,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
326 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
327 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
328 *frequency=((float)freq.frequency)/priv->frac; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
329 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
330 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
331 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
332 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
333 * \brief set volume on radio card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
334 * \param volume volume level (0..100) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
335 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
336 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
337 static void set_volume_v4l2(radio_priv_t* priv,int volume){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
338 struct v4l2_queryctrl qctrl; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
339 struct v4l2_control control; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
340 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
341 /*arg must be between 0 and 100*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
342 if (volume > 100) volume = 100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
343 if (volume < 0) volume = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
344 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
345 memset(&control,0,sizeof(control)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
346 control.id=V4L2_CID_AUDIO_MUTE; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
347 control.value = (volume==0?1:0); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
348 if (ioctl(priv->radio_fd, VIDIOC_S_CTRL, &control)<0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
349 mp_msg(MSGT_RADIO,MSGL_WARN,MSGTR_RADIO_SetMuteFailed,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
350 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
351 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
352 memset(&qctrl,0,sizeof(qctrl)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
353 qctrl.id = V4L2_CID_AUDIO_VOLUME; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
354 if (ioctl(priv->radio_fd, VIDIOC_QUERYCTRL, &qctrl) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
355 mp_msg(MSGT_RADIO, MSGL_WARN, MSGTR_RADIO_QueryControlFailed,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
356 return; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
357 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
358 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
359 memset(&control,0,sizeof(control)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
360 control.id=V4L2_CID_AUDIO_VOLUME; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
361 control.value=qctrl.minimum+volume*(qctrl.maximum-qctrl.minimum)/100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
362 if (ioctl(priv->radio_fd, VIDIOC_S_CTRL, &control) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
363 mp_msg(MSGT_RADIO, MSGL_WARN,MSGTR_RADIO_SetVolumeFailed,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
364 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
365 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
366 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
367 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
368 * \brief get current volume from radio card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
369 * \param volume where to store volume level (0..100) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
370 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
371 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
372 static int get_volume_v4l2(radio_priv_t* priv,int* volume){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
373 struct v4l2_queryctrl qctrl; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
374 struct v4l2_control control; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
375 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
376 memset(&qctrl,0,sizeof(qctrl)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
377 qctrl.id = V4L2_CID_AUDIO_VOLUME; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
378 if (ioctl(priv->radio_fd, VIDIOC_QUERYCTRL, &qctrl) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
379 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_QueryControlFailed,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
380 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
381 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
382 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
383 memset(&control,0,sizeof(control)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
384 control.id=V4L2_CID_AUDIO_VOLUME; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
385 if (ioctl(priv->radio_fd, VIDIOC_G_CTRL, &control) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
386 mp_msg(MSGT_RADIO, MSGL_ERR,MSGTR_RADIO_GetVolumeFailed,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
387 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
388 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
389 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
390 if (qctrl.maximum==qctrl.minimum) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
391 *volume=qctrl.minimum; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
392 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
393 *volume=100*(control.value-qctrl.minimum)/(qctrl.maximum-qctrl.minimum); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
394 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
395 /*arg must be between 0 and 100*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
396 if (*volume > 100) *volume = 100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
397 if (*volume < 0) *volume = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
398 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
399 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
400 } |
22754 | 401 |
402 /* v4l2 driver info structure */ | |
403 static const radio_driver_t radio_driver_v4l2={ | |
404 "v4l2", | |
405 MSGTR_RADIO_DriverV4L2, | |
406 init_frac_v4l2, | |
407 set_volume_v4l2, | |
408 get_volume_v4l2, | |
409 set_frequency_v4l2, | |
410 get_frequency_v4l2 | |
411 }; | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
412 #endif /* CONFIG_RADIO_V4L2 */ |
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
413 #ifdef CONFIG_RADIO_V4L |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
414 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
415 * \brief get fraction value for using in set_frequency and get_frequency |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
416 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
417 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
418 * V4L2_TUNER_CAP_LOW: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
419 * unit=62.5Hz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
420 * frac= 1MHz/unit=1000000/62.5 =16000 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
421 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
422 * otherwise: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
423 * unit=62500Hz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
424 * frac= 1MHz/unit=1000000/62500 =16 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
425 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
426 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
427 static int init_frac_v4l(radio_priv_t* priv){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
428 struct video_tuner tuner; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
429 memset(&tuner,0,sizeof(tuner)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
430 if (ioctl(priv->radio_fd, VIDIOCGTUNER, &tuner) <0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
431 mp_msg(MSGT_RADIO,MSGL_WARN,MSGTR_RADIO_GetTunerFailed,strerror(errno),priv->frac); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
432 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
433 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
434 if(tuner.flags & VIDEO_TUNER_LOW){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
435 priv->frac=16000; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
436 mp_msg(MSGT_RADIO,MSGL_DBG2,MSGTR_RADIO_TunerCapLowYes,priv->frac); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
437 }else{ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
438 priv->frac=16; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
439 mp_msg(MSGT_RADIO,MSGL_DBG2,MSGTR_RADIO_TunerCapLowNo,priv->frac); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
440 } |
20758
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
441 |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
442 priv->rangelow=((float)tuner.rangelow)/priv->frac; |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
443 priv->rangehigh=((float)tuner.rangehigh)/priv->frac; |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
444 mp_msg(MSGT_RADIO,MSGL_V,MSGTR_RADIO_FreqRange,priv->rangelow,priv->rangehigh); |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
445 |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
446 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
447 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
448 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
449 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
450 * \brief tune card to given frequency |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
451 * \param frequency frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
452 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
453 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
454 static int set_frequency_v4l(radio_priv_t* priv,float frequency){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
455 __u32 freq; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
456 freq=frequency*priv->frac; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
457 if (ioctl(priv->radio_fd, VIDIOCSFREQ, &freq) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
458 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_SetFreqFailed,freq,frequency,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
459 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
460 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
461 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
462 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
463 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
464 * \brief get current tuned frequency from card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
465 * \param frequency where to store frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
466 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
467 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
468 static int get_frequency_v4l(radio_priv_t* priv,float* frequency){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
469 __u32 freq; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
470 if (ioctl(priv->radio_fd, VIDIOCGFREQ, &freq) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
471 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_GetFreqFailed,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
472 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
473 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
474 *frequency=((float)freq)/priv->frac; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
475 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
476 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
477 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
478 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
479 * \brief set volume on radio card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
480 * \param volume volume level (0..100) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
481 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
482 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
483 static void set_volume_v4l(radio_priv_t* priv,int volume){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
484 struct video_audio audio; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
485 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
486 /*arg must be between 0 and 100*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
487 if (volume > 100) volume = 100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
488 if (volume < 0) volume = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
489 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
490 memset(&audio,0,sizeof(audio)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
491 audio.flags = (volume==0?VIDEO_AUDIO_MUTE:0); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
492 if (ioctl(priv->radio_fd, VIDIOCSAUDIO, &audio)<0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
493 mp_msg(MSGT_RADIO,MSGL_WARN,MSGTR_RADIO_SetMuteFailed,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
494 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
495 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
496 memset(&audio,0,sizeof(audio)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
497 audio.flags = VIDEO_AUDIO_VOLUME; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
498 audio.mode = VIDEO_SOUND_STEREO; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
499 audio.audio = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
500 audio.volume = volume* (65535 / 100); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
501 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
502 if (ioctl(priv->radio_fd, VIDIOCSAUDIO, &audio) < 0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
503 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_SetVolumeFailed,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
504 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
505 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
506 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
507 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
508 * \brief get current volume from radio card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
509 * \param volume where to store volume level (0..100) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
510 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
511 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
512 static int get_volume_v4l(radio_priv_t* priv,int* volume){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
513 struct video_audio audio; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
514 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
515 memset(&audio,0,sizeof(audio)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
516 audio.audio=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
517 if (ioctl(priv->radio_fd, VIDIOCGAUDIO, &audio) < 0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
518 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_GetVolumeFailed,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
519 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
520 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
521 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
522 if (audio.flags & VIDEO_AUDIO_VOLUME){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
523 *volume=100*audio.volume/65535; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
524 /*arg must be between 0 and 100*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
525 if (*volume > 100) *volume = 100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
526 if (*volume < 0) *volume = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
527 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
528 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
529 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
530 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
531 } |
22754 | 532 |
533 /* v4l driver info structure */ | |
534 static const radio_driver_t radio_driver_v4l={ | |
535 "v4l", | |
536 MSGTR_RADIO_DriverV4L, | |
537 init_frac_v4l, | |
538 set_volume_v4l, | |
539 get_volume_v4l, | |
540 set_frequency_v4l, | |
541 get_frequency_v4l | |
542 }; | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
543 #endif /* CONFIG_RADIO_V4L */ |
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
544 #ifdef CONFIG_RADIO_BSDBT848 |
22948 | 545 |
20985 | 546 /***************************************************************** |
547 * \brief get fraction value for using in set_frequency and get_frequency | |
548 * \return STREAM_OK if success, STREAM_ERROR otherwise | |
549 * | |
550 * For *BSD BT848 frac=100 | |
551 * | |
552 * Here is a coment from FreeBSD 5.2-RELEASE source code: | |
553 * | |
554 * * Tuner Notes: | |
555 * * Programming the tuner properly is quite complicated. | |
556 * * Here are some notes, based on a FM1246 data sheet for a PAL-I tuner. | |
557 * * The tuner (front end) covers 45.75 MHz - 855.25 MHz and an FM band of | |
558 * * 87.5 MHz to 108.0 MHz. | |
559 * | |
560 * Thus, frequency range is limited to 87.5-108.0, but you can change | |
561 * it, using freq_min and freq_max options | |
562 */ | |
563 static int init_frac_bsdbt848(radio_priv_t* priv){ | |
564 priv->frac=100; | |
23890 | 565 priv->rangelow=priv->radio_param->freq_min; |
566 priv->rangehigh=priv->radio_param->freq_max; | |
20985 | 567 return STREAM_OK; |
568 } | |
569 | |
570 /***************************************************************** | |
571 * \brief tune card to given frequency | |
572 * \param frequency frequency in MHz | |
573 * \return STREAM_OK if success, STREAM_ERROR otherwise | |
574 */ | |
575 static int set_frequency_bsdbt848(radio_priv_t* priv,float frequency){ | |
576 unsigned int freq; | |
577 freq=frequency*priv->frac; | |
578 if(ioctl(priv->radio_fd,RADIO_SETFREQ,&freq)<0){ | |
579 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_SetFreqFailed,freq, frequency, strerror(errno)); | |
580 return STREAM_ERROR; | |
581 } | |
582 return STREAM_OK; | |
583 } | |
584 | |
585 /***************************************************************** | |
586 * \brief get current tuned frequency from card | |
587 * \param frequency where to store frequency in MHz | |
588 * \return STREAM_OK if success, STREAM_ERROR otherwise | |
589 */ | |
590 static int get_frequency_bsdbt848(radio_priv_t* priv,float* frequency){ | |
591 unsigned int freq; | |
592 if (ioctl(priv->radio_fd, RADIO_GETFREQ, &freq) < 0) { | |
593 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_GetFreqFailed,strerror(errno)); | |
594 return STREAM_ERROR; | |
595 } | |
596 *frequency=((float)freq)/priv->frac; | |
597 return STREAM_OK; | |
598 } | |
599 | |
600 /***************************************************************** | |
601 * \brief set volume on radio card | |
602 * \param volume volume level (0..100) | |
603 * \return STREAM_OK if success, STREAM_ERROR otherwise | |
604 * | |
605 * *BSD BT848 does not have volume changing abilities, so | |
606 * we will just mute sound if volume=0 and unmute it otherwise. | |
607 */ | |
608 static void set_volume_bsdbt848(radio_priv_t* priv,int volume){ | |
609 int audio_flags; | |
610 | |
611 /*arg must be between 0 and 100*/ | |
612 if (volume > 100) volume = 100; | |
613 if (volume < 0) volume = 0; | |
614 | |
615 audio_flags = (volume==0?AUDIO_MUTE:AUDIO_UNMUTE); | |
616 if (ioctl(priv->radio_fd, BT848_SAUDIO, &audio_flags)<0){ | |
617 mp_msg(MSGT_RADIO,MSGL_WARN,MSGTR_RADIO_SetMuteFailed,strerror(errno)); | |
618 } | |
619 } | |
620 | |
621 /***************************************************************** | |
622 * \brief get current volume from radio card | |
623 * \param volume where to store volume level (0..100) | |
624 * \return previous STREAM_OK if success, STREAM_ERROR otherwise | |
625 * | |
626 * *BSD BT848 does not have volume changing abilities, so | |
627 * we will return 0 if sound is muted and 100 otherwise. | |
628 */ | |
629 static int get_volume_bsdbt848(radio_priv_t* priv,int* volume){ | |
630 int audio_flags; | |
631 | |
632 if (ioctl(priv->radio_fd, BT848_GAUDIO, &audio_flags)<0){ | |
633 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_GetVolumeFailed,strerror(errno)); | |
634 return STREAM_ERROR; | |
635 } | |
636 | |
637 if (audio_flags & AUDIO_MUTE) | |
638 *volume=0; | |
639 else | |
640 *volume=100; | |
641 | |
642 return STREAM_OK; | |
643 } | |
22754 | 644 |
645 /* bsdbt848 driver info structure */ | |
22928
09f2039f1113
Fix typo in r22772 which causes compilation error under *BSD.
voroshil
parents:
22754
diff
changeset
|
646 static const radio_driver_t radio_driver_bsdbt848={ |
22754 | 647 "bsdbt848", |
22928
09f2039f1113
Fix typo in r22772 which causes compilation error under *BSD.
voroshil
parents:
22754
diff
changeset
|
648 MSGTR_RADIO_DriverBSDBT848, |
09f2039f1113
Fix typo in r22772 which causes compilation error under *BSD.
voroshil
parents:
22754
diff
changeset
|
649 init_frac_bsdbt848, |
09f2039f1113
Fix typo in r22772 which causes compilation error under *BSD.
voroshil
parents:
22754
diff
changeset
|
650 set_volume_bsdbt848, |
09f2039f1113
Fix typo in r22772 which causes compilation error under *BSD.
voroshil
parents:
22754
diff
changeset
|
651 get_volume_bsdbt848, |
09f2039f1113
Fix typo in r22772 which causes compilation error under *BSD.
voroshil
parents:
22754
diff
changeset
|
652 set_frequency_bsdbt848, |
09f2039f1113
Fix typo in r22772 which causes compilation error under *BSD.
voroshil
parents:
22754
diff
changeset
|
653 get_frequency_bsdbt848 |
22754 | 654 }; |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
655 #endif /* CONFIG_RADIO_BSDBT848 */ |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
656 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
657 static inline int init_frac(radio_priv_t* priv){ |
22754 | 658 return priv->driver->init_frac(priv); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
659 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
660 static inline int set_frequency(radio_priv_t* priv,float frequency){ |
20758
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
661 if ((frequency<priv->rangelow)||(frequency>priv->rangehigh)){ |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
662 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_WrongFreq,frequency); |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
663 return STREAM_ERROR; |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
664 } |
22754 | 665 if(priv->driver->set_frequency(priv,frequency)!=STREAM_OK) |
666 return STREAM_ERROR; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
667 |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
668 #ifdef CONFIG_RADIO_CAPTURE |
20796
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
669 if(clear_buffer(priv)!=STREAM_OK){ |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
670 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_ClearBufferFailed,strerror(errno)); |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
671 return STREAM_ERROR; |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
672 } |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
673 #endif |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
674 return STREAM_OK; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
675 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
676 static inline int get_frequency(radio_priv_t* priv,float* frequency){ |
22754 | 677 return priv->driver->get_frequency(priv,frequency); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
678 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
679 static inline void set_volume(radio_priv_t* priv,int volume){ |
22754 | 680 priv->driver->set_volume(priv,volume); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
681 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
682 static inline int get_volume(radio_priv_t* priv,int* volume){ |
22754 | 683 return priv->driver->get_volume(priv,volume); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
684 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
685 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
686 |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
687 #ifndef CONFIG_RADIO_CAPTURE |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
688 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
689 * \brief stub, if capture disabled at compile-time |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
690 * \return STREAM_OK |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
691 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
692 static inline int init_audio(radio_priv_t *priv){ return STREAM_OK;} |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
693 #else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
694 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
695 * \brief making buffer empty |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
696 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
697 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
698 * when changing channel we must clear buffer to avoid large switching delay |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
699 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
700 static int clear_buffer(radio_priv_t* priv){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
701 if (!priv->do_capture) return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
702 priv->audio_tail = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
703 priv->audio_head = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
704 priv->audio_cnt=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
705 memset(priv->audio_ringbuffer,0,priv->audio_in.blocksize); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
706 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
707 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
708 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
709 * \brief read next part of data into buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
710 * \return -1 if error occured or no data available yet, otherwise - bytes read |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
711 * NOTE: audio device works in non-blocking mode |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
712 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
713 static int read_chunk(audio_in_t *ai, unsigned char *buffer) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
714 { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
715 int ret; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
716 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
717 switch (ai->type) { |
27390
9d95dc936e66
Introduce CONFIG_ALSA preprocessor directive for ALSA 0.9 and 1.x.
diego
parents:
27387
diff
changeset
|
718 #ifdef CONFIG_ALSA |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
719 case AUDIO_IN_ALSA: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
720 //device opened in non-blocking mode |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
721 ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
722 if (ret != ai->alsa.chunk_size) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
723 if (ret < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
724 if (ret==-EAGAIN) return -1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
725 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio, snd_strerror(ret)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
726 if (ret == -EPIPE) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
727 if (ai_alsa_xrun(ai) == 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
728 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_XRUNSomeFramesMayBeLeftOut); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
729 } else { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
730 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_ErrFatalCannotRecover); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
731 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
732 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
733 } else { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
734 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_NotEnoughSamples); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
735 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
736 return -1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
737 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
738 return ret; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
739 #endif |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
740 #ifdef CONFIG_OSS_AUDIO |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
741 case AUDIO_IN_OSS: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
742 { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
743 int bt=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
744 /* |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
745 we must return exactly blocksize bytes, so if we have got any bytes |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
746 at first call to read, we will loop untils get all blocksize bytes |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
747 otherwise we will return -1 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
748 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
749 while(bt<ai->blocksize){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
750 //device opened in non-blocking mode |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
751 ret = read(ai->oss.audio_fd, buffer+bt, ai->blocksize-bt); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
752 if (ret==ai->blocksize) return ret; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
753 if (ret<0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
754 if (errno==EAGAIN && bt==0) return -1; //no data avail yet |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
755 if (errno==EAGAIN) { usleep(1000); continue;} //nilling buffer to blocksize size |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
756 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio, strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
757 return -1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
758 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
759 bt+=ret; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
760 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
761 return bt; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
762 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
763 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
764 default: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
765 return -1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
766 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
767 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
768 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
769 * \brief grab next frame from audio device |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
770 * \parameter buffer - store buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
771 * \parameter len - store buffer size in bytes |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
772 * \return number of bytes written into buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
773 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
774 * grabs len (or less) bytes from ringbuffer into buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
775 * if ringbuffer is empty waits until len bytes of data will be available |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
776 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
777 * priv->audio_cnt - size (in bytes) of ringbuffer's filled part |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
778 * priv->audio_drop - size (in bytes) of dropped data (if no space in ringbuffer) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
779 * priv->audio_head - index of first byte in filled part |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
780 * priv->audio_tail - index of last byte in filled part |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
781 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
782 * NOTE: audio_tail always aligned by priv->audio_in.blocksize |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
783 * audio_head may NOT. |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
784 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
785 static int grab_audio_frame(radio_priv_t *priv, char *buffer, int len) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
786 { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
787 int i; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
788 mp_msg(MSGT_RADIO, MSGL_DBG3, MSGTR_RADIO_BufferString,"grab_audio_frame",priv->audio_cnt,priv->audio_drop); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
789 /* Cache buffer must be filled by some audio packets when playing starts. |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
790 Otherwise MPlayer will quit with EOF error. |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
791 Probably, there is need more carefull checking rather than simple 'for' loop |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
792 (something like timer or similar). |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
793 |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
794 1000ms delay will happen only at first buffer filling. At next call function |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
795 just fills buffer until either buffer full or no data from driver available. |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
796 */ |
24821
3b23a0e6fe7b
Don't wait for filling entire audio ringbuffer at each call to grab_audio_frame.
voroshil
parents:
24820
diff
changeset
|
797 for (i=0;i<1000 && !priv->audio_cnt; i++){ |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
798 //read_chunk fills exact priv->blocksize bytes |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
799 if(read_chunk(&priv->audio_in, priv->audio_ringbuffer+priv->audio_tail) < 0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
800 //sleppeing only when waiting first block to fill empty buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
801 if (!priv->audio_cnt){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
802 usleep(1000); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
803 continue; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
804 }else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
805 break; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
806 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
807 priv->audio_cnt+=priv->audio_in.blocksize; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
808 priv->audio_tail = (priv->audio_tail+priv->audio_in.blocksize) % priv->audio_buffer_size; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
809 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
810 if(priv->audio_cnt<len) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
811 len=priv->audio_cnt; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
812 memcpy(buffer, priv->audio_ringbuffer+priv->audio_head,len); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
813 priv->audio_head = (priv->audio_head+len) % priv->audio_buffer_size; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
814 priv->audio_cnt-=len; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
815 return len; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
816 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
817 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
818 * \brief init audio device |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
819 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
820 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
821 static int init_audio(radio_priv_t *priv) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
822 { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
823 int is_oss=1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
824 int seconds=2; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
825 char* tmp; |
25962 | 826 if (priv->audio_initialized) return 1; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
827 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
828 /* do_capture==0 mplayer was not started with capture keyword, so disabling capture*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
829 if(!priv->do_capture) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
830 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
831 |
23890 | 832 if (!priv->radio_param->adevice){ |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
833 priv->do_capture=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
834 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
835 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
836 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
837 priv->do_capture=1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
838 mp_msg(MSGT_RADIO,MSGL_V,MSGTR_RADIO_CaptureStarting); |
27390
9d95dc936e66
Introduce CONFIG_ALSA preprocessor directive for ALSA 0.9 and 1.x.
diego
parents:
27387
diff
changeset
|
839 #ifdef CONFIG_ALSA |
23890 | 840 while ((tmp = strrchr(priv->radio_param->adevice, '='))){ |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
841 tmp[0] = ':'; |
23890 | 842 //adevice option looks like ALSA device name. Switching to ALSA |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
843 is_oss=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
844 } |
23890 | 845 while ((tmp = strrchr(priv->radio_param->adevice, '.'))) |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
846 tmp[0] = ','; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
847 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
848 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
849 if(audio_in_init(&priv->audio_in, is_oss?AUDIO_IN_OSS:AUDIO_IN_ALSA)<0){ |
24019 | 850 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_AudioInInitFailed); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
851 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
852 |
23890 | 853 audio_in_set_device(&priv->audio_in, priv->radio_param->adevice); |
854 audio_in_set_channels(&priv->audio_in, priv->radio_param->achannels); | |
855 audio_in_set_samplerate(&priv->audio_in, priv->radio_param->arate); | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
856 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
857 if (audio_in_setup(&priv->audio_in) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
858 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_AudioInSetupFailed, strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
859 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
860 } |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
861 #ifdef CONFIG_OSS_AUDIO |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
862 if(is_oss) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
863 ioctl(priv->audio_in.oss.audio_fd, SNDCTL_DSP_NONBLOCK, 0); |
24583
af12ba770230
Fix compilation with enabled radio capture and disabled OSS audio.
voroshil
parents:
24257
diff
changeset
|
864 #endif |
27390
9d95dc936e66
Introduce CONFIG_ALSA preprocessor directive for ALSA 0.9 and 1.x.
diego
parents:
27387
diff
changeset
|
865 #ifdef CONFIG_ALSA |
24583
af12ba770230
Fix compilation with enabled radio capture and disabled OSS audio.
voroshil
parents:
24257
diff
changeset
|
866 if(!is_oss) |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
867 snd_pcm_nonblock(priv->audio_in.alsa.handle,1); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
868 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
869 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
870 priv->audio_buffer_size = seconds*priv->audio_in.samplerate*priv->audio_in.channels* |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
871 priv->audio_in.bytes_per_sample+priv->audio_in.blocksize; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
872 if (priv->audio_buffer_size < 256*priv->audio_in.blocksize) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
873 priv->audio_buffer_size = 256*priv->audio_in.blocksize; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
874 mp_msg(MSGT_RADIO, MSGL_V, MSGTR_RADIO_AudioBuffer, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
875 priv->audio_buffer_size,priv->audio_in.blocksize); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
876 /* start capture */ |
19606 | 877 priv->audio_ringbuffer = calloc(1, priv->audio_buffer_size); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
878 if (!priv->audio_ringbuffer) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
879 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_AllocateBufferFailed,priv->audio_in.blocksize, priv->audio_buffer_size, strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
880 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
881 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
882 priv->audio_head = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
883 priv->audio_tail = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
884 priv->audio_cnt = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
885 priv->audio_drop = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
886 |
24820 | 887 audio_in_start_capture(&priv->audio_in); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
888 |
25962 | 889 priv->audio_initialized = 1; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
890 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
891 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
892 } |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
893 #endif /* CONFIG_RADIO_CAPTURE */ |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
894 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
895 /*------------------------------------------------------------------------- |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
896 for call from mplayer.c |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
897 --------------------------------------------------------------------------*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
898 /***************************************************************** |
20968 | 899 * \brief public wrapper for get_frequency |
900 * \parameter frequency pointer to float, which will contain frequency in MHz | |
901 * \return 1 if success,0 - otherwise | |
902 */ | |
903 int radio_get_freq(struct stream_st *stream, float* frequency){ | |
904 radio_priv_t* priv=(radio_priv_t*)stream->priv; | |
905 | |
906 if (!frequency) | |
907 return 0; | |
908 if (get_frequency(priv,frequency)!=STREAM_OK){ | |
909 return 0; | |
910 } | |
911 return 1; | |
912 } | |
913 /***************************************************************** | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
914 * \brief public wrapper for set_frequency |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
915 * \parameter frequency frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
916 * \return 1 if success,0 - otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
917 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
918 int radio_set_freq(struct stream_st *stream, float frequency){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
919 radio_priv_t* priv=(radio_priv_t*)stream->priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
920 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
921 if (set_frequency(priv,frequency)!=STREAM_OK){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
922 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
923 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
924 if (get_frequency(priv,&frequency)!=STREAM_OK){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
925 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
926 } |
20967
460da4c85cb4
Change verbosity level from MSGL_V to MSGL_INFO for "Current frequency is"
voroshil
parents:
20806
diff
changeset
|
927 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_CurrentFreq,frequency); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
928 return 1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
929 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
930 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
931 /***************************************************************** |
21042 | 932 * \brief tune current frequency by step_interval value |
933 * \parameter step_interval increment value | |
934 * \return 1 if success,0 - otherwise | |
935 * | |
936 */ | |
937 int radio_step_freq(struct stream_st *stream, float step_interval){ | |
938 float frequency; | |
939 radio_priv_t* priv=(radio_priv_t*)stream->priv; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
940 |
21042 | 941 if (get_frequency(priv,&frequency)!=STREAM_OK) |
942 return 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
943 |
21042 | 944 frequency+=step_interval; |
945 if (frequency>priv->rangehigh) | |
946 frequency=priv->rangehigh; | |
947 if (frequency<priv->rangelow) | |
948 frequency=priv->rangelow; | |
949 | |
950 return radio_set_freq(stream,frequency); | |
951 } | |
952 /***************************************************************** | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
953 * \brief step channel up or down |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
954 * \parameter direction RADIO_CHANNEL_LOWER - go to prev channel,RADIO_CHANNEL_HIGHER - to next |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
955 * \return 1 if success,0 - otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
956 * |
23890 | 957 * if channel parameter is NULL function prints error message and does nothing, otherwise |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
958 * changes channel to prev or next in list |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
959 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
960 int radio_step_channel(struct stream_st *stream, int direction) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
961 radio_priv_t* priv=(radio_priv_t*)stream->priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
962 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
963 if (priv->radio_channel_list) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
964 switch (direction){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
965 case RADIO_CHANNEL_HIGHER: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
966 if (priv->radio_channel_current->next) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
967 priv->radio_channel_current = priv->radio_channel_current->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
968 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
969 priv->radio_channel_current = priv->radio_channel_list; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
970 if(!radio_set_freq(stream,priv->radio_channel_current->freq)) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
971 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
972 mp_msg(MSGT_RADIO, MSGL_V, MSGTR_RADIO_SelectedChannel, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
973 priv->radio_channel_current->index, priv->radio_channel_current->name, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
974 priv->radio_channel_current->freq); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
975 break; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
976 case RADIO_CHANNEL_LOWER: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
977 if (priv->radio_channel_current->prev) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
978 priv->radio_channel_current = priv->radio_channel_current->prev; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
979 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
980 while (priv->radio_channel_current->next) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
981 priv->radio_channel_current = priv->radio_channel_current->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
982 if(!radio_set_freq(stream,priv->radio_channel_current->freq)) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
983 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
984 mp_msg(MSGT_RADIO, MSGL_V, MSGTR_RADIO_SelectedChannel, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
985 priv->radio_channel_current->index, priv->radio_channel_current->name, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
986 priv->radio_channel_current->freq); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
987 break; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
988 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
989 }else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
990 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_ChangeChannelNoChannelList); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
991 return 1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
992 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
993 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
994 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
995 * \brief change channel to one with given index |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
996 * \parameter channel string, containing channel number |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
997 * \return 1 if success,0 - otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
998 * |
23890 | 999 * if channel parameter is NULL function prints error message and does nothing, otherwise |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1000 * changes channel to given |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1001 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1002 int radio_set_channel(struct stream_st *stream, char *channel) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1003 radio_priv_t* priv=(radio_priv_t*)stream->priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1004 int i, channel_int; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1005 radio_channels_t* tmp; |
19793
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1006 char* endptr; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1007 |
19793
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1008 if (*channel=='\0') |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1009 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_WrongChannelName,channel); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
1010 |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1011 if (priv->radio_channel_list) { |
19793
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1012 channel_int = strtol(channel,&endptr,10); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1013 tmp = priv->radio_channel_list; |
19793
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1014 if (*endptr!='\0'){ |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1015 //channel is not a number, so it contains channel name |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1016 for ( ; tmp; tmp=tmp->next) |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1017 if (!strncmp(channel,tmp->name,sizeof(tmp->name)-1)) |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1018 break; |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1019 if (!tmp){ |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1020 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_WrongChannelName,channel); |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1021 return 0; |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1022 } |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1023 }else{ |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1024 for (i = 1; i < channel_int; i++) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1025 if (tmp->next) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1026 tmp = tmp->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1027 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1028 break; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1029 if (tmp->index!=channel_int){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1030 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_WrongChannelNumberInt,channel_int); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1031 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1032 } |
19793
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1033 } |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1034 priv->radio_channel_current=tmp; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1035 mp_msg(MSGT_RADIO, MSGL_V, MSGTR_RADIO_SelectedChannel, priv->radio_channel_current->index, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1036 priv->radio_channel_current->name, priv->radio_channel_current->freq); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1037 if(!radio_set_freq(stream, priv->radio_channel_current->freq)) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1038 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1039 } else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1040 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_ChangeChannelNoChannelList); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1041 return 1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1042 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1043 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1044 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1045 * \brief get current channel's name |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1046 * \return pointer to string, containing current channel's name |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1047 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1048 * NOTE: return value may be NULL (e.g. when channel list not initialized) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1049 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1050 char* radio_get_channel_name(struct stream_st *stream){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1051 radio_priv_t* priv=(radio_priv_t*)stream->priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1052 if (priv->radio_channel_current) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1053 return priv->radio_channel_current->name; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1054 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1055 return NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1056 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1057 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1058 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1059 * \brief fills given buffer with audio data |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1060 * \return number of bytes, written into buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1061 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1062 static int fill_buffer_s(struct stream_st *s, char* buffer, int max_len){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1063 int len=max_len; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1064 |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
1065 #ifdef CONFIG_RADIO_CAPTURE |
23485 | 1066 radio_priv_t* priv=(radio_priv_t*)s->priv; |
1067 | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1068 if (priv->do_capture){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1069 len=grab_audio_frame(priv, buffer,max_len); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1070 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1071 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1072 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1073 memset(buffer,0,len); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1074 return len; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1075 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1076 |
22754 | 1077 |
1078 /* | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
1079 order if significant! |
22754 | 1080 when no driver explicitly specified first available will be used |
1081 */ | |
1082 static const radio_driver_t* radio_drivers[]={ | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
1083 #ifdef CONFIG_RADIO_BSDBT848 |
22928
09f2039f1113
Fix typo in r22772 which causes compilation error under *BSD.
voroshil
parents:
22754
diff
changeset
|
1084 &radio_driver_bsdbt848, |
22754 | 1085 #endif |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
1086 #ifdef CONFIG_RADIO_V4L2 |
22754 | 1087 &radio_driver_v4l2, |
1088 #endif | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
1089 #ifdef CONFIG_RADIO_V4L |
22754 | 1090 &radio_driver_v4l, |
1091 #endif | |
1092 0 | |
1093 }; | |
1094 | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1095 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1096 * Stream initialization |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1097 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1098 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1099 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1100 radio_priv_t* priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1101 float frequency=0; |
22754 | 1102 int i; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1103 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1104 if (strncmp("radio://",stream->url,8) != 0) |
24257 | 1105 return STREAM_UNSUPPORTED; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1106 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1107 if(mode != STREAM_READ) |
24257 | 1108 return STREAM_UNSUPPORTED; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1109 |
23890 | 1110 priv=calloc(1,sizeof(radio_priv_t)); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1111 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1112 if (!priv) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1113 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1114 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1115 |
23890 | 1116 priv->radio_param=opts; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1117 |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
1118 #ifdef CONFIG_RADIO_CAPTURE |
23890 | 1119 if (priv->radio_param->capture && strncmp("capture",priv->radio_param->capture,7)==0) |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1120 priv->do_capture=1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1121 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1122 priv->do_capture=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1123 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1124 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1125 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1126 |
23890 | 1127 if (strncmp(priv->radio_param->driver,"default",7)==0) |
22754 | 1128 priv->driver=radio_drivers[0]; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1129 else |
22754 | 1130 priv->driver=NULL; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1131 |
22754 | 1132 mp_msg(MSGT_RADIO,MSGL_V,MSGTR_RADIO_AvailableDrivers); |
1133 for(i=0;radio_drivers[i];i++){ | |
1134 mp_msg(MSGT_RADIO,MSGL_V,"%s, ",radio_drivers[i]->name); | |
23890 | 1135 if(strcmp(priv->radio_param->driver,radio_drivers[i]->name)==0) |
22754 | 1136 priv->driver=radio_drivers[i]; |
1137 } | |
1138 mp_msg(MSGT_RADIO,MSGL_V,"\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27390
diff
changeset
|
1139 |
22754 | 1140 if(priv->driver) |
1141 mp_msg(MSGT_RADIO, MSGL_INFO, priv->driver->info); | |
1142 else{ | |
23890 | 1143 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_DriverUnknownStr,priv->radio_param->driver); |
22754 | 1144 close_s(stream); |
1145 return STREAM_ERROR; | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1146 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1147 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1148 stream->type = STREAMTYPE_RADIO; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1149 /* using rawaudio demuxer */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1150 *file_format = DEMUXER_TYPE_RAWAUDIO; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1151 stream->flags = STREAM_READ; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1152 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1153 priv->radio_fd=-1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1154 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1155 stream->start_pos=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1156 stream->end_pos=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1157 stream->priv=priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1158 stream->close=close_s; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1159 stream->fill_buffer=fill_buffer_s; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1160 |
23890 | 1161 priv->radio_fd = open(priv->radio_param->device, O_RDONLY); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1162 if (priv->radio_fd < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1163 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_UnableOpenDevice, |
23890 | 1164 priv->radio_param->device, strerror(errno)); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1165 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1166 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1167 } |
23890 | 1168 mp_msg(MSGT_RADIO, MSGL_V, MSGTR_RADIO_RadioDevice, priv->radio_fd,priv->radio_param->device); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1169 fcntl(priv->radio_fd, F_SETFD, FD_CLOEXEC); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1170 |
20737 | 1171 get_volume(priv, &priv->old_snd_volume); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1172 set_volume(priv,0); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1173 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1174 if (init_frac(priv)!=STREAM_OK){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1175 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1176 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1177 }; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1178 |
23890 | 1179 if (parse_channels(priv,priv->radio_param->freq_channel,&frequency)!=STREAM_OK){ |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1180 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1181 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1182 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1183 |
20758
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
1184 if ((frequency<priv->rangelow)||(frequency>priv->rangehigh)){ |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1185 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_WrongFreq,frequency); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1186 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1187 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1188 }else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1189 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_UsingFreq,frequency); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1190 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1191 if(set_frequency(priv,frequency)!=STREAM_OK){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1192 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1193 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1194 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1195 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1196 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1197 if (init_audio(priv)!=STREAM_OK){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1198 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1199 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1200 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1201 |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
1202 #if defined(CONFIG_RADIO_CAPTURE) && defined(CONFIG_STREAM_CACHE) |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1203 if(priv->do_capture){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1204 //5 second cache |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1205 if(!stream_enable_cache(stream,5*priv->audio_in.samplerate*priv->audio_in.channels* |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1206 priv->audio_in.bytes_per_sample,2*priv->audio_in.samplerate*priv->audio_in.channels* |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1207 priv->audio_in.bytes_per_sample,priv->audio_in.blocksize)) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1208 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_StreamEnableCacheFailed,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1209 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1210 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1211 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1212 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1213 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1214 |
23890 | 1215 set_volume(priv,priv->radio_param->volume); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1216 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1217 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1218 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1219 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1220 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1221 * Close stream. Clear structures. |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1222 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1223 static void close_s(struct stream_st * stream){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1224 radio_priv_t* priv=(radio_priv_t*)stream->priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1225 radio_channels_t * tmp; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1226 if (!priv) return; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1227 |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26737
diff
changeset
|
1228 #ifdef CONFIG_RADIO_CAPTURE |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1229 if(priv->audio_ringbuffer){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1230 free(priv->audio_ringbuffer); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1231 priv->audio_ringbuffer=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1232 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1233 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1234 priv->do_capture=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1235 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1236 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1237 while (priv->radio_channel_list) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1238 tmp=priv->radio_channel_list; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1239 priv->radio_channel_list=priv->radio_channel_list->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1240 free(tmp); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1241 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1242 priv->radio_channel_current=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1243 priv->radio_channel_list=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1244 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1245 if (priv->radio_fd>0){ |
20796
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
1246 set_volume(priv, priv->old_snd_volume); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1247 close(priv->radio_fd); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1248 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1249 |
23890 | 1250 if(priv->radio_param) |
1251 m_struct_free(&stream_opts,priv->radio_param); | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1252 free(priv); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1253 stream->priv=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1254 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1255 |
25211 | 1256 const stream_info_t stream_info_radio = { |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1257 "Radio stream", |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1258 "Radio", |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1259 "Vladimir Voroshilov", |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1260 "In development", |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1261 open_s, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1262 { "radio", NULL }, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1263 &stream_opts, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1264 1 // Urls are an option string |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1265 }; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1266 |