annotate stream/stream_radio.c @ 23559:294cbf94b48a

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