Mercurial > mplayer.hg
annotate stream/stream_radio.c @ 21966:d9494ca70ca7
Simplify by using av_codec_get_id and include riff.h only in demux_lavf.c
author | reimar |
---|---|
date | Sun, 21 Jan 2007 15:44:58 +0000 |
parents | c549c2de24ce |
children | 8d480f1b41df |
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 | 36 |
37 #ifdef RADIO_BSDBT848_HDR | |
38 #include <sys/param.h> | |
39 #include RADIO_BSDBT848_HDR | |
40 | |
41 #else // RADIO_BSDBT848_HDR | |
42 | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
43 #include <linux/types.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
44 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
45 #ifdef HAVE_RADIO_V4L2 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
46 #include <linux/videodev2.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
47 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
48 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
49 #ifdef HAVE_RADIO_V4L |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
50 #include <linux/videodev.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
51 #warning "V4L is deprecated and will be removed in future" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
52 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
53 |
20985 | 54 #endif // !RADIO_BSDBT848_HDR |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
55 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
56 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
57 #include "stream.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
58 #include "libmpdemux/demuxer.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
59 #include "m_struct.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
60 #include "m_option.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
61 #include "mp_msg.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
62 #include "help_mp.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
63 #include "stream_radio.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
64 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
65 #ifdef USE_RADIO_CAPTURE |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
66 #include "audio_in.h" |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
67 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
68 #ifdef HAVE_SYS_SOUNDCARD_H |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
69 #include <sys/soundcard.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
70 #else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
71 #ifdef HAVE_SOUNDCARD_H |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
72 #include <soundcard.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
73 #else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
74 #include <linux/soundcard.h> |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
75 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
76 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
77 |
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 #define RADIO_DRIVER_UNKNOWN 0 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
81 #define RADIO_DRIVER_V4L 1 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
82 #define RADIO_DRIVER_V4L2 2 |
20985 | 83 #define RADIO_DRIVER_BSDBT848 3 |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
84 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
85 typedef struct radio_channels_s { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
86 int index; ///< channel index in channels list |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
87 float freq; ///< frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
88 char name[20]; ///< channel name |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
89 struct radio_channels_s * next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
90 struct radio_channels_s * prev; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
91 } radio_channels_t; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
92 |
20985 | 93 #ifdef RADIO_BSDBT848_HDR |
94 /** (device,string, "/dev/tuner0") name of radio device file */ | |
95 char* radio_param_device="/dev/tuner0"; | |
96 /** radio_param_freq_min (freq_min,float,87.5) minimal allowed frequency */ | |
97 float radio_param_freq_min=87.50; | |
98 /** radio_param_freq_min (freq_min,float,108.0) maximal allowed frequency */ | |
99 float radio_param_freq_max=108.00; | |
100 #else | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
101 /** (device,string, "/dev/radio0") name of radio device file */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
102 char* radio_param_device="/dev/radio0"; |
20985 | 103 #endif |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
104 /** (driver,string, "v4l2") radio driver (v4l,v4l2) */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
105 char* radio_param_driver="default"; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
106 /** 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
|
107 char** radio_param_channels; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
108 /** 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
|
109 int radio_param_volume=100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
110 /** 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
|
111 char* radio_param_adevice; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
112 /** radio_param_arate (arate,number,44100) audio framerate |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
113 (please also set -rawaudio rate parameter to the same value) */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
114 int radio_param_arate=44100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
115 /** radio_param_achannels (achannels,number,2) number of audio channels */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
116 int radio_param_achannels=2; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
117 extern int demux_rawaudio_packs_per_sec; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
118 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
119 static struct stream_priv_s { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
120 /* 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
|
121 float radio_param_freq_channel; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
122 char* capture; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
123 } stream_priv_dflts = { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
124 0, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
125 NULL |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
126 }; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
127 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
128 typedef struct radio_priv_s { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
129 int radio_fd; ///< radio device descriptor |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
130 int frac; ///< fraction value (see comment to init_frac) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
131 radio_channels_t* radio_channel_list; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
132 radio_channels_t* radio_channel_current; |
20758
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
133 float rangelow; ///< lowest tunable frequency in MHz |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
134 float rangehigh; ///< highest tunable frequency in MHz |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
135 int driver; |
20737 | 136 int old_snd_volume; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
137 #ifdef USE_RADIO_CAPTURE |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
138 volatile int do_capture; ///< is capture enabled |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
139 audio_in_t audio_in; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
140 unsigned char* audio_ringbuffer; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
141 int audio_head; ///< start of meanfull data in ringbuffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
142 int audio_tail; ///< end of meanfull data in ringbuffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
143 int audio_buffer_size; ///< size of ringbuffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
144 int audio_cnt; ///< size of meanfull data inringbuffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
145 int audio_drop; ///< number of dropped bytes |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
146 int audio_inited; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
147 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
148 } radio_priv_t; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
149 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
150 #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
|
151 static m_option_t stream_opts_fields[] = { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
152 {"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
|
153 {"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
|
154 { NULL, NULL, 0, 0, 0, 0, NULL } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
155 }; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
156 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
157 static struct m_struct_st stream_opts = { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
158 "radio", |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
159 sizeof(struct stream_priv_s), |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
160 &stream_priv_dflts, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
161 stream_opts_fields |
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 void close_s(struct stream_st * stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
165 #ifdef USE_RADIO_CAPTURE |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
166 static int clear_buffer(radio_priv_t* priv); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
167 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
168 |
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 * \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
|
172 * \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
|
173 * \param pfreq selected frequency (from selected channel or from URL) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
174 * \result STREAM_OK if success, STREAM_ERROR otherwise |
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 * 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
|
177 * <frequency>-<name>,<frequency>-<name>,... |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
178 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
179 * '_' will be replaced with spaces. |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
180 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
181 * 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
|
182 * channel position in channel list. |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
183 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
184 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
|
185 char** channels; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
186 int i; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
187 int channel = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
188 if (radio_param_channels){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
189 /*parsing channels string*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
190 channels =radio_param_channels; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
191 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
192 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_ChannelNamesDetected); |
19606 | 193 priv->radio_channel_list = malloc(sizeof(radio_channels_t)); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
194 priv->radio_channel_list->index=1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
195 priv->radio_channel_list->next=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
196 priv->radio_channel_list->prev=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
197 priv->radio_channel_current = priv->radio_channel_list; |
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 while (*channels) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
200 char* tmp = *(channels++); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
201 char* sep = strchr(tmp,'-'); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
202 if (!sep) continue; // Wrong syntax, but mplayer should not crash |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
203 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
|
204 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
205 sep[0] = '\0'; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
206 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
207 priv->radio_channel_current->freq=atof(tmp); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
208 |
20758
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
209 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
|
210 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_WrongFreqForChannel, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
211 priv->radio_channel_current->name); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
212 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
213 while ((sep=strchr(priv->radio_channel_current->name, '_'))) sep[0] = ' '; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
214 |
19606 | 215 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
|
216 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
|
217 priv->radio_channel_current->next->prev = priv->radio_channel_current; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
218 priv->radio_channel_current->next->next = NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
219 priv->radio_channel_current = priv->radio_channel_current->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
220 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
221 if (priv->radio_channel_current->prev) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
222 priv->radio_channel_current->prev->next = NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
223 free(priv->radio_channel_current); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
224 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
225 if (freq_channel) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
226 channel = freq_channel; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
227 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
228 channel = 1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
229 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
230 priv->radio_channel_current = priv->radio_channel_list; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
231 for (i = 1; i < channel; i++) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
232 if (priv->radio_channel_current->next) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
233 priv->radio_channel_current = priv->radio_channel_current->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
234 if (priv->radio_channel_current->index!=channel){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
235 if (((float)((int)freq_channel))!=freq_channel) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
236 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
|
237 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
238 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
|
239 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
240 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
241 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
|
242 priv->radio_channel_current->name, priv->radio_channel_current->freq); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
243 *pfreq=priv->radio_channel_current->freq; |
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 if (freq_channel){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
246 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_FreqParameterDetected); |
19606 | 247 priv->radio_channel_list=malloc(sizeof(radio_channels_t)); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
248 priv->radio_channel_list->next=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
249 priv->radio_channel_list->prev=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
250 priv->radio_channel_list->index=1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
251 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
|
252 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
253 priv->radio_channel_current=priv->radio_channel_list; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
254 *pfreq=freq_channel; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
255 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
256 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
257 mp_msg(MSGT_RADIO, MSGL_DBG2, MSGTR_RADIO_DoneParsingChannels); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
258 return STREAM_OK; |
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 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
261 #ifdef HAVE_RADIO_V4L2 |
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 * \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
|
264 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
265 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
266 * V4L2_TUNER_CAP_LOW: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
267 * unit=62.5Hz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
268 * frac= 1MHz/unit=1000000/62.5 =16000 |
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 * otherwise: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
271 * unit=62500Hz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
272 * frac= 1MHz/unit=1000000/62500 =16 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
273 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
274 static int init_frac_v4l2(radio_priv_t* priv){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
275 struct v4l2_tuner tuner; |
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 memset(&tuner,0,sizeof(tuner)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
278 tuner.index=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
279 if (ioctl(priv->radio_fd, VIDIOC_G_TUNER, &tuner)<0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
280 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
|
281 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
282 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
283 if(tuner.type!=V4L2_TUNER_RADIO){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
284 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
|
285 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
286 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
287 if(tuner.capability & V4L2_TUNER_CAP_LOW){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
288 priv->frac=16000; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
289 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
|
290 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
291 else{ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
292 priv->frac=16; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
293 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
|
294 } |
20758
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
295 |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
296 priv->rangelow=((float)tuner.rangelow)/priv->frac; |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
297 priv->rangehigh=((float)tuner.rangehigh)/priv->frac; |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
298 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
|
299 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
300 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
301 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
302 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
303 * \brief tune card to given frequency |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
304 * \param frequency frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
305 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
306 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
307 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
|
308 struct v4l2_frequency freq; |
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 memset(&freq,0,sizeof(freq)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
311 freq.tuner=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
312 freq.type=V4L2_TUNER_RADIO; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
313 freq.frequency=frequency*priv->frac; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
314 if(ioctl(priv->radio_fd,VIDIOC_S_FREQUENCY,&freq)<0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
315 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
|
316 frequency,strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
317 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
318 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
319 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
320 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
321 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
322 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
323 * \brief get current tuned frequency from card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
324 * \param frequency where to store frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
325 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
326 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
327 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
|
328 struct v4l2_frequency freq; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
329 memset(&freq,0,sizeof(freq)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
330 if (ioctl(priv->radio_fd, VIDIOC_G_FREQUENCY, &freq) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
331 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
|
332 return STREAM_ERROR; |
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 *frequency=((float)freq.frequency)/priv->frac; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
335 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
336 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
337 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
338 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
339 * \brief set volume on radio card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
340 * \param volume volume level (0..100) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
341 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
342 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
343 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
|
344 struct v4l2_queryctrl qctrl; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
345 struct v4l2_control control; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
346 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
347 /*arg must be between 0 and 100*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
348 if (volume > 100) volume = 100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
349 if (volume < 0) volume = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
350 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
351 memset(&control,0,sizeof(control)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
352 control.id=V4L2_CID_AUDIO_MUTE; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
353 control.value = (volume==0?1:0); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
354 if (ioctl(priv->radio_fd, VIDIOC_S_CTRL, &control)<0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
355 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
|
356 } |
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(&qctrl,0,sizeof(qctrl)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
359 qctrl.id = V4L2_CID_AUDIO_VOLUME; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
360 if (ioctl(priv->radio_fd, VIDIOC_QUERYCTRL, &qctrl) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
361 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
|
362 return; |
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(&control,0,sizeof(control)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
366 control.id=V4L2_CID_AUDIO_VOLUME; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
367 control.value=qctrl.minimum+volume*(qctrl.maximum-qctrl.minimum)/100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
368 if (ioctl(priv->radio_fd, VIDIOC_S_CTRL, &control) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
369 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
|
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 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
373 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
374 * \brief get current volume from radio card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
375 * \param volume where to store volume level (0..100) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
376 * \return STREAM_OK if success, STREAM_ERROR otherwise |
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 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
|
379 struct v4l2_queryctrl qctrl; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
380 struct v4l2_control control; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
381 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
382 memset(&qctrl,0,sizeof(qctrl)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
383 qctrl.id = V4L2_CID_AUDIO_VOLUME; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
384 if (ioctl(priv->radio_fd, VIDIOC_QUERYCTRL, &qctrl) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
385 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
|
386 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
387 } |
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(&control,0,sizeof(control)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
390 control.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_G_CTRL, &control) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
392 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
|
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 if (qctrl.maximum==qctrl.minimum) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
397 *volume=qctrl.minimum; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
398 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
399 *volume=100*(control.value-qctrl.minimum)/(qctrl.maximum-qctrl.minimum); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
400 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
401 /*arg must be between 0 and 100*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
402 if (*volume > 100) *volume = 100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
403 if (*volume < 0) *volume = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
404 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
405 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
406 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
407 #endif //HAVE_RADIO_V4L2 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
408 #ifdef HAVE_RADIO_V4L |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
409 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
410 * \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
|
411 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
412 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
413 * V4L2_TUNER_CAP_LOW: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
414 * unit=62.5Hz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
415 * frac= 1MHz/unit=1000000/62.5 =16000 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
416 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
417 * otherwise: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
418 * unit=62500Hz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
419 * frac= 1MHz/unit=1000000/62500 =16 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
420 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
421 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
422 static int init_frac_v4l(radio_priv_t* priv){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
423 struct video_tuner tuner; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
424 memset(&tuner,0,sizeof(tuner)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
425 if (ioctl(priv->radio_fd, VIDIOCGTUNER, &tuner) <0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
426 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
|
427 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
428 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
429 if(tuner.flags & VIDEO_TUNER_LOW){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
430 priv->frac=16000; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
431 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
|
432 }else{ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
433 priv->frac=16; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
434 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
|
435 } |
20758
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
436 |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
437 priv->rangelow=((float)tuner.rangelow)/priv->frac; |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
438 priv->rangehigh=((float)tuner.rangehigh)/priv->frac; |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
439 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
|
440 |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
441 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
442 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
443 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
444 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
445 * \brief tune card to given frequency |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
446 * \param frequency frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
447 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
448 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
449 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
|
450 __u32 freq; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
451 freq=frequency*priv->frac; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
452 if (ioctl(priv->radio_fd, VIDIOCSFREQ, &freq) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
453 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
|
454 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
455 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
456 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
457 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
458 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
459 * \brief get current tuned frequency from card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
460 * \param frequency where to store frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
461 * \return STREAM_OK if success, STREAM_ERROR otherwise |
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 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
|
464 __u32 freq; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
465 if (ioctl(priv->radio_fd, VIDIOCGFREQ, &freq) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
466 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
|
467 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
468 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
469 *frequency=((float)freq)/priv->frac; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
470 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
471 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
472 |
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 * \brief set volume on radio card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
475 * \param volume volume level (0..100) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
476 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
477 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
478 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
|
479 struct video_audio audio; |
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 /*arg must be between 0 and 100*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
482 if (volume > 100) volume = 100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
483 if (volume < 0) volume = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
484 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
485 memset(&audio,0,sizeof(audio)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
486 audio.flags = (volume==0?VIDEO_AUDIO_MUTE:0); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
487 if (ioctl(priv->radio_fd, VIDIOCSAUDIO, &audio)<0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
488 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
|
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 memset(&audio,0,sizeof(audio)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
492 audio.flags = VIDEO_AUDIO_VOLUME; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
493 audio.mode = VIDEO_SOUND_STEREO; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
494 audio.audio = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
495 audio.volume = volume* (65535 / 100); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
496 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
497 if (ioctl(priv->radio_fd, VIDIOCSAUDIO, &audio) < 0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
498 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
|
499 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
500 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
501 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
502 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
503 * \brief get current volume from radio card |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
504 * \param volume where to store volume level (0..100) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
505 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
506 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
507 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
|
508 struct video_audio audio; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
509 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
510 memset(&audio,0,sizeof(audio)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
511 audio.audio=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
512 if (ioctl(priv->radio_fd, VIDIOCGAUDIO, &audio) < 0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
513 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
|
514 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
515 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
516 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
517 if (audio.flags & VIDEO_AUDIO_VOLUME){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
518 *volume=100*audio.volume/65535; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
519 /*arg must be between 0 and 100*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
520 if (*volume > 100) *volume = 100; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
521 if (*volume < 0) *volume = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
522 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
523 } |
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 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
526 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
527 #endif //HAVE_RADIO_V4L |
20985 | 528 #ifdef RADIO_BSDBT848_HDR |
529 /***************************************************************** | |
530 * \brief get fraction value for using in set_frequency and get_frequency | |
531 * \return STREAM_OK if success, STREAM_ERROR otherwise | |
532 * | |
533 * For *BSD BT848 frac=100 | |
534 * | |
535 * Here is a coment from FreeBSD 5.2-RELEASE source code: | |
536 * | |
537 * * Tuner Notes: | |
538 * * Programming the tuner properly is quite complicated. | |
539 * * Here are some notes, based on a FM1246 data sheet for a PAL-I tuner. | |
540 * * The tuner (front end) covers 45.75 MHz - 855.25 MHz and an FM band of | |
541 * * 87.5 MHz to 108.0 MHz. | |
542 * | |
543 * Thus, frequency range is limited to 87.5-108.0, but you can change | |
544 * it, using freq_min and freq_max options | |
545 */ | |
546 static int init_frac_bsdbt848(radio_priv_t* priv){ | |
547 priv->frac=100; | |
548 priv->rangelow=radio_param_freq_min; | |
549 priv->rangehigh=radio_param_freq_max; | |
550 return STREAM_OK; | |
551 } | |
552 | |
553 /***************************************************************** | |
554 * \brief tune card to given frequency | |
555 * \param frequency frequency in MHz | |
556 * \return STREAM_OK if success, STREAM_ERROR otherwise | |
557 */ | |
558 static int set_frequency_bsdbt848(radio_priv_t* priv,float frequency){ | |
559 unsigned int freq; | |
560 freq=frequency*priv->frac; | |
561 if(ioctl(priv->radio_fd,RADIO_SETFREQ,&freq)<0){ | |
562 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_SetFreqFailed,freq, frequency, strerror(errno)); | |
563 return STREAM_ERROR; | |
564 } | |
565 return STREAM_OK; | |
566 } | |
567 | |
568 /***************************************************************** | |
569 * \brief get current tuned frequency from card | |
570 * \param frequency where to store frequency in MHz | |
571 * \return STREAM_OK if success, STREAM_ERROR otherwise | |
572 */ | |
573 static int get_frequency_bsdbt848(radio_priv_t* priv,float* frequency){ | |
574 unsigned int freq; | |
575 if (ioctl(priv->radio_fd, RADIO_GETFREQ, &freq) < 0) { | |
576 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_GetFreqFailed,strerror(errno)); | |
577 return STREAM_ERROR; | |
578 } | |
579 *frequency=((float)freq)/priv->frac; | |
580 return STREAM_OK; | |
581 } | |
582 | |
583 /***************************************************************** | |
584 * \brief set volume on radio card | |
585 * \param volume volume level (0..100) | |
586 * \return STREAM_OK if success, STREAM_ERROR otherwise | |
587 * | |
588 * *BSD BT848 does not have volume changing abilities, so | |
589 * we will just mute sound if volume=0 and unmute it otherwise. | |
590 */ | |
591 static void set_volume_bsdbt848(radio_priv_t* priv,int volume){ | |
592 int audio_flags; | |
593 | |
594 /*arg must be between 0 and 100*/ | |
595 if (volume > 100) volume = 100; | |
596 if (volume < 0) volume = 0; | |
597 | |
598 audio_flags = (volume==0?AUDIO_MUTE:AUDIO_UNMUTE); | |
599 if (ioctl(priv->radio_fd, BT848_SAUDIO, &audio_flags)<0){ | |
600 mp_msg(MSGT_RADIO,MSGL_WARN,MSGTR_RADIO_SetMuteFailed,strerror(errno)); | |
601 } | |
602 } | |
603 | |
604 /***************************************************************** | |
605 * \brief get current volume from radio card | |
606 * \param volume where to store volume level (0..100) | |
607 * \return previous STREAM_OK if success, STREAM_ERROR otherwise | |
608 * | |
609 * *BSD BT848 does not have volume changing abilities, so | |
610 * we will return 0 if sound is muted and 100 otherwise. | |
611 */ | |
612 static int get_volume_bsdbt848(radio_priv_t* priv,int* volume){ | |
613 int audio_flags; | |
614 | |
615 if (ioctl(priv->radio_fd, BT848_GAUDIO, &audio_flags)<0){ | |
616 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_GetVolumeFailed,strerror(errno)); | |
617 return STREAM_ERROR; | |
618 } | |
619 | |
620 if (audio_flags & AUDIO_MUTE) | |
621 *volume=0; | |
622 else | |
623 *volume=100; | |
624 | |
625 return STREAM_OK; | |
626 } | |
627 #endif //RADIO_BSDBT848_HDR | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
628 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
629 static inline int init_frac(radio_priv_t* priv){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
630 switch(priv->driver){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
631 #ifdef HAVE_RADIO_V4L |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
632 case RADIO_DRIVER_V4L: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
633 return init_frac_v4l(priv); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
634 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
635 #ifdef HAVE_RADIO_V4L2 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
636 case RADIO_DRIVER_V4L2: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
637 return init_frac_v4l2(priv); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
638 #endif |
20985 | 639 #ifdef RADIO_BSDBT848_HDR |
640 case RADIO_DRIVER_BSDBT848: | |
641 return init_frac_bsdbt848(priv); | |
642 #endif | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
643 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
644 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
645 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
646 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
647 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
|
648 if ((frequency<priv->rangelow)||(frequency>priv->rangehigh)){ |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
649 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_WrongFreq,frequency); |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
650 return STREAM_ERROR; |
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
651 } |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
652 switch(priv->driver){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
653 #ifdef HAVE_RADIO_V4L |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
654 case RADIO_DRIVER_V4L: |
20796
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
655 if(set_frequency_v4l(priv,frequency)!=STREAM_OK) |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
656 return STREAM_ERROR; |
20806 | 657 break; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
658 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
659 #ifdef HAVE_RADIO_V4L2 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
660 case RADIO_DRIVER_V4L2: |
20796
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
661 if(set_frequency_v4l2(priv,frequency)!=STREAM_OK) |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
662 return STREAM_ERROR; |
20806 | 663 break; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
664 #endif |
20985 | 665 #ifdef RADIO_BSDBT848_HDR |
666 case RADIO_DRIVER_BSDBT848: | |
667 if(set_frequency_bsdbt848(priv,frequency)!=STREAM_OK) | |
668 return STREAM_ERROR; | |
669 break; | |
670 #endif | |
20796
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
671 default: |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
672 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver); |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
673 return STREAM_ERROR; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
674 } |
20796
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
675 #ifdef USE_RADIO_CAPTURE |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
676 if(clear_buffer(priv)!=STREAM_OK){ |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
677 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
|
678 return STREAM_ERROR; |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
679 } |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
680 #endif |
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
681 return STREAM_OK; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
682 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
683 static inline int get_frequency(radio_priv_t* priv,float* frequency){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
684 switch(priv->driver){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
685 #ifdef HAVE_RADIO_V4L |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
686 case RADIO_DRIVER_V4L: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
687 return get_frequency_v4l(priv,frequency); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
688 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
689 #ifdef HAVE_RADIO_V4L2 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
690 case RADIO_DRIVER_V4L2: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
691 return get_frequency_v4l2(priv,frequency); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
692 #endif |
20985 | 693 #ifdef RADIO_BSDBT848_HDR |
694 case RADIO_DRIVER_BSDBT848: | |
695 return get_frequency_bsdbt848(priv,frequency); | |
696 #endif | |
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 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
699 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
700 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
701 static inline void set_volume(radio_priv_t* priv,int volume){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
702 switch(priv->driver){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
703 #ifdef HAVE_RADIO_V4L |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
704 case RADIO_DRIVER_V4L: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
705 set_volume_v4l(priv,volume); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
706 return; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
707 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
708 #ifdef HAVE_RADIO_V4L2 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
709 case RADIO_DRIVER_V4L2: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
710 set_volume_v4l2(priv,volume); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
711 return; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
712 #endif |
20985 | 713 #ifdef RADIO_BSDBT848_HDR |
714 case RADIO_DRIVER_BSDBT848: | |
715 set_volume_bsdbt848(priv,volume); | |
716 return; | |
717 #endif | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
718 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
719 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver); |
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 static inline int get_volume(radio_priv_t* priv,int* volume){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
722 switch(priv->driver){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
723 #ifdef HAVE_RADIO_V4L |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
724 case RADIO_DRIVER_V4L: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
725 return get_volume_v4l(priv,volume); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
726 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
727 #ifdef HAVE_RADIO_V4L2 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
728 case RADIO_DRIVER_V4L2: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
729 return get_volume_v4l2(priv,volume); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
730 #endif |
20985 | 731 #ifdef RADIO_BSDBT848_HDR |
732 case RADIO_DRIVER_BSDBT848: | |
733 return get_volume_bsdbt848(priv,volume); | |
734 #endif | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
735 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
736 mp_msg(MSGT_RADIO,MSGL_ERR,MSGTR_RADIO_DriverUnknownId,priv->driver); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
737 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
738 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
739 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
740 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
741 #ifndef USE_RADIO_CAPTURE |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
742 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
743 * \brief stub, if capture disabled at compile-time |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
744 * \return STREAM_OK |
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 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
|
747 #else |
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 * \brief making buffer empty |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
750 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
751 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
752 * 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
|
753 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
754 static int clear_buffer(radio_priv_t* priv){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
755 if (!priv->do_capture) return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
756 priv->audio_tail = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
757 priv->audio_head = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
758 priv->audio_cnt=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
759 memset(priv->audio_ringbuffer,0,priv->audio_in.blocksize); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
760 return STREAM_OK; |
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 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
763 * \brief read next part of data into buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
764 * \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
|
765 * NOTE: audio device works in non-blocking mode |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
766 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
767 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
|
768 { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
769 int ret; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
770 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
771 switch (ai->type) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
772 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
773 case AUDIO_IN_ALSA: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
774 //device opened in non-blocking mode |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
775 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
|
776 if (ret != ai->alsa.chunk_size) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
777 if (ret < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
778 if (ret==-EAGAIN) return -1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
779 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
|
780 if (ret == -EPIPE) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
781 if (ai_alsa_xrun(ai) == 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
782 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_XRUNSomeFramesMayBeLeftOut); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
783 } else { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
784 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_ErrFatalCannotRecover); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
785 } |
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 } else { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
788 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_MPDEMUX_AUDIOIN_NotEnoughSamples); |
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 return -1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
791 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
792 return ret; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
793 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
794 #ifdef USE_OSS_AUDIO |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
795 case AUDIO_IN_OSS: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
796 { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
797 int bt=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
798 /* |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
799 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
|
800 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
|
801 otherwise we will return -1 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
802 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
803 while(bt<ai->blocksize){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
804 //device opened in non-blocking mode |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
805 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
|
806 if (ret==ai->blocksize) return ret; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
807 if (ret<0){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
808 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
|
809 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
|
810 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
|
811 return -1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
812 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
813 bt+=ret; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
814 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
815 return bt; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
816 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
817 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
818 default: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
819 return -1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
820 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
821 } |
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 * \brief grab next frame from audio device |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
824 * \parameter buffer - store buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
825 * \parameter len - store buffer size in bytes |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
826 * \return number of bytes written into buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
827 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
828 * grabs len (or less) bytes from ringbuffer into buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
829 * 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
|
830 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
831 * 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
|
832 * 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
|
833 * priv->audio_head - index of first byte in filled part |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
834 * priv->audio_tail - index of last byte in filled part |
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 * NOTE: audio_tail always aligned by priv->audio_in.blocksize |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
837 * audio_head may NOT. |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
838 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
839 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
|
840 { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
841 int i; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
842 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
|
843 /* 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
|
844 Otherwise MPlayer will quit with EOF error. |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
845 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
|
846 (something like timer or similar). |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
847 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
848 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
|
849 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
|
850 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
851 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
|
852 //read_chunk fills exact priv->blocksize bytes |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
853 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
|
854 //sleppeing only when waiting first block to fill empty buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
855 if (!priv->audio_cnt){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
856 usleep(1000); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
857 continue; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
858 }else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
859 break; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
860 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
861 priv->audio_cnt+=priv->audio_in.blocksize; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
862 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
|
863 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
864 if(priv->audio_cnt<len) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
865 len=priv->audio_cnt; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
866 memcpy(buffer, priv->audio_ringbuffer+priv->audio_head,len); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
867 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
|
868 priv->audio_cnt-=len; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
869 return len; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
870 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
871 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
872 * \brief init audio device |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
873 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
874 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
875 static int init_audio(radio_priv_t *priv) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
876 { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
877 int is_oss=1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
878 int seconds=2; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
879 char* tmp; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
880 if (priv->audio_inited) return 1; |
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 /* 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
|
883 if(!priv->do_capture) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
884 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
885 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
886 if (!radio_param_adevice){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
887 priv->do_capture=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
888 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
889 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
890 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
891 priv->do_capture=1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
892 mp_msg(MSGT_RADIO,MSGL_V,MSGTR_RADIO_CaptureStarting); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
893 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
894 while ((tmp = strrchr(radio_param_adevice, '='))){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
895 tmp[0] = ':'; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
896 //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
|
897 is_oss=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 while ((tmp = strrchr(radio_param_adevice, '.'))) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
900 tmp[0] = ','; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
901 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
902 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
903 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
|
904 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
|
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 audio_in_set_device(&priv->audio_in, radio_param_adevice); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
908 audio_in_set_channels(&priv->audio_in, radio_param_achannels); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
909 audio_in_set_samplerate(&priv->audio_in, radio_param_arate); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
910 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
911 if (audio_in_setup(&priv->audio_in) < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
912 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
|
913 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
914 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
915 if(is_oss) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
916 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
|
917 #if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
918 else{ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
919 snd_pcm_nonblock(priv->audio_in.alsa.handle,1); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
920 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
921 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
922 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
923 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
|
924 priv->audio_in.bytes_per_sample+priv->audio_in.blocksize; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
925 if (priv->audio_buffer_size < 256*priv->audio_in.blocksize) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
926 priv->audio_buffer_size = 256*priv->audio_in.blocksize; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
927 mp_msg(MSGT_RADIO, MSGL_V, MSGTR_RADIO_AudioBuffer, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
928 priv->audio_buffer_size,priv->audio_in.blocksize); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
929 /* start capture */ |
19606 | 930 priv->audio_ringbuffer = calloc(1, priv->audio_buffer_size); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
931 if (!priv->audio_ringbuffer) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
932 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
|
933 return STREAM_ERROR; |
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 priv->audio_head = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
936 priv->audio_tail = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
937 priv->audio_cnt = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
938 priv->audio_drop = 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
939 |
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 priv->audio_inited = 1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
942 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
943 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
944 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
945 #endif //USE_RADIO_CAPTURE |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
946 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
947 /*------------------------------------------------------------------------- |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
948 for call from mplayer.c |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
949 --------------------------------------------------------------------------*/ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
950 /***************************************************************** |
20968 | 951 * \brief public wrapper for get_frequency |
952 * \parameter frequency pointer to float, which will contain frequency in MHz | |
953 * \return 1 if success,0 - otherwise | |
954 */ | |
955 int radio_get_freq(struct stream_st *stream, float* frequency){ | |
956 radio_priv_t* priv=(radio_priv_t*)stream->priv; | |
957 | |
958 if (!frequency) | |
959 return 0; | |
960 if (get_frequency(priv,frequency)!=STREAM_OK){ | |
961 return 0; | |
962 } | |
963 return 1; | |
964 } | |
965 /***************************************************************** | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
966 * \brief public wrapper for set_frequency |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
967 * \parameter frequency frequency in MHz |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
968 * \return 1 if success,0 - otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
969 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
970 int radio_set_freq(struct stream_st *stream, float frequency){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
971 radio_priv_t* priv=(radio_priv_t*)stream->priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
972 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
973 if (set_frequency(priv,frequency)!=STREAM_OK){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
974 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
975 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
976 if (get_frequency(priv,&frequency)!=STREAM_OK){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
977 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
978 } |
20967
460da4c85cb4
Change verbosity level from MSGL_V to MSGL_INFO for "Current frequency is"
voroshil
parents:
20806
diff
changeset
|
979 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
|
980 return 1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
981 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
982 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
983 /***************************************************************** |
21042 | 984 * \brief tune current frequency by step_interval value |
985 * \parameter step_interval increment value | |
986 * \return 1 if success,0 - otherwise | |
987 * | |
988 */ | |
989 int radio_step_freq(struct stream_st *stream, float step_interval){ | |
990 float frequency; | |
991 radio_priv_t* priv=(radio_priv_t*)stream->priv; | |
992 | |
993 if (get_frequency(priv,&frequency)!=STREAM_OK) | |
994 return 0; | |
995 | |
996 frequency+=step_interval; | |
997 if (frequency>priv->rangehigh) | |
998 frequency=priv->rangehigh; | |
999 if (frequency<priv->rangelow) | |
1000 frequency=priv->rangelow; | |
1001 | |
1002 return radio_set_freq(stream,frequency); | |
1003 } | |
1004 /***************************************************************** | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1005 * \brief step channel up or down |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1006 * \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
|
1007 * \return 1 if success,0 - otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1008 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1009 * 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
|
1010 * changes channel to prev or next in list |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1011 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1012 int radio_step_channel(struct stream_st *stream, int direction) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1013 radio_priv_t* priv=(radio_priv_t*)stream->priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1014 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1015 if (priv->radio_channel_list) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1016 switch (direction){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1017 case RADIO_CHANNEL_HIGHER: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1018 if (priv->radio_channel_current->next) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1019 priv->radio_channel_current = priv->radio_channel_current->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1020 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1021 priv->radio_channel_current = priv->radio_channel_list; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1022 if(!radio_set_freq(stream,priv->radio_channel_current->freq)) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1023 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1024 mp_msg(MSGT_RADIO, MSGL_V, MSGTR_RADIO_SelectedChannel, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1025 priv->radio_channel_current->index, priv->radio_channel_current->name, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1026 priv->radio_channel_current->freq); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1027 break; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1028 case RADIO_CHANNEL_LOWER: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1029 if (priv->radio_channel_current->prev) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1030 priv->radio_channel_current = priv->radio_channel_current->prev; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1031 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1032 while (priv->radio_channel_current->next) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1033 priv->radio_channel_current = priv->radio_channel_current->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1034 if(!radio_set_freq(stream,priv->radio_channel_current->freq)) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1035 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1036 mp_msg(MSGT_RADIO, MSGL_V, MSGTR_RADIO_SelectedChannel, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1037 priv->radio_channel_current->index, priv->radio_channel_current->name, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1038 priv->radio_channel_current->freq); |
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 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1041 }else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1042 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_ChangeChannelNoChannelList); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1043 return 1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1044 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1045 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1046 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1047 * \brief change channel to one with given index |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1048 * \parameter channel string, containing channel number |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1049 * \return 1 if success,0 - otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1050 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1051 * 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
|
1052 * changes channel to given |
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 int radio_set_channel(struct stream_st *stream, char *channel) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1055 radio_priv_t* priv=(radio_priv_t*)stream->priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1056 int i, channel_int; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1057 radio_channels_t* tmp; |
19793
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1058 char* endptr; |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1059 |
19793
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1060 if (*channel=='\0') |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1061 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
|
1062 |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1063 if (priv->radio_channel_list) { |
19793
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1064 channel_int = strtol(channel,&endptr,10); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1065 tmp = priv->radio_channel_list; |
19793
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1066 if (*endptr!='\0'){ |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1067 //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
|
1068 for ( ; tmp; tmp=tmp->next) |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1069 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
|
1070 break; |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1071 if (!tmp){ |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1072 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
|
1073 return 0; |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1074 } |
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1075 }else{ |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1076 for (i = 1; i < channel_int; i++) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1077 if (tmp->next) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1078 tmp = tmp->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1079 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1080 break; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1081 if (tmp->index!=channel_int){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1082 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
|
1083 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1084 } |
19793
6c98f3566af1
ability to pass channel name (not only number) to radio_set_channel
voroshil
parents:
19618
diff
changeset
|
1085 } |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1086 priv->radio_channel_current=tmp; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1087 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
|
1088 priv->radio_channel_current->name, priv->radio_channel_current->freq); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1089 if(!radio_set_freq(stream, priv->radio_channel_current->freq)) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1090 return 0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1091 } else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1092 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_ChangeChannelNoChannelList); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1093 return 1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1094 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1095 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1096 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1097 * \brief get current channel's name |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1098 * \return pointer to string, containing current channel's name |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1099 * |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1100 * 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
|
1101 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1102 char* radio_get_channel_name(struct stream_st *stream){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1103 radio_priv_t* priv=(radio_priv_t*)stream->priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1104 if (priv->radio_channel_current) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1105 return priv->radio_channel_current->name; |
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 return NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1108 } |
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 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1111 * \brief fills given buffer with audio data |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1112 * \return number of bytes, written into buffer |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1113 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1114 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
|
1115 radio_priv_t* priv=(radio_priv_t*)s->priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1116 int len=max_len; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1117 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1118 #ifdef USE_RADIO_CAPTURE |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1119 if (priv->do_capture){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1120 len=grab_audio_frame(priv, buffer,max_len); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1121 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1122 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1123 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1124 memset(buffer,0,len); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1125 return len; |
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 /***************************************************************** |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1129 * Stream initialization |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1130 * \return STREAM_OK if success, STREAM_ERROR otherwise |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1131 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1132 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
|
1133 struct stream_priv_s* p=(struct stream_priv_s*)opts; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1134 radio_priv_t* priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1135 float frequency=0; |
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 if (strncmp("radio://",stream->url,8) != 0) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1138 return STREAM_UNSUPORTED; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1139 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1140 if(mode != STREAM_READ) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1141 return STREAM_UNSUPORTED; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1142 |
19606 | 1143 priv=malloc(sizeof(radio_priv_t)); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1144 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1145 if (!priv) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1146 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1147 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1148 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1149 memset(priv,0,sizeof(radio_priv_t)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1150 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1151 #ifdef USE_RADIO_CAPTURE |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1152 if (p->capture && strncmp("capture",p->capture,7)==0) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1153 priv->do_capture=1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1154 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1155 priv->do_capture=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1156 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1157 |
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 if (strncmp(radio_param_driver,"default",7)==0) |
20985 | 1161 #if defined(HAVE_RADIO_V4L2) |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1162 priv->driver=RADIO_DRIVER_V4L2; |
20985 | 1163 #elif defined(RADIO_BSDBT848_HDR) |
1164 priv->driver=RADIO_DRIVER_BSDBT848; | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1165 #else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1166 priv->driver=RADIO_DRIVER_V4L; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1167 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1168 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1169 #ifdef HAVE_RADIO_V4L2 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1170 if (strncmp(radio_param_driver,"v4l2",4)==0) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1171 priv->driver=RADIO_DRIVER_V4L2; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1172 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1173 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1174 #ifdef HAVE_RADIO_V4L |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1175 if (strncmp(radio_param_driver,"v4l",3)==0) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1176 priv->driver=RADIO_DRIVER_V4L; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1177 else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1178 #endif |
20985 | 1179 #ifdef RADIO_BSDBT848_HDR |
1180 if (strncmp(radio_param_driver,"bsdbt848",8)==0) | |
1181 priv->driver=RADIO_DRIVER_BSDBT848; | |
1182 else | |
1183 #endif | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1184 priv->driver=RADIO_DRIVER_UNKNOWN; |
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 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1187 switch(priv->driver){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1188 case RADIO_DRIVER_V4L: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1189 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_DriverV4L); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1190 break; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1191 case RADIO_DRIVER_V4L2: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1192 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_DriverV4L2); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1193 break; |
20985 | 1194 case RADIO_DRIVER_BSDBT848: |
1195 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_DriverBSDBT848); | |
1196 break; | |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1197 default: |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1198 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_DriverUnknownStr,radio_param_driver); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1199 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1200 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1201 } |
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 stream->type = STREAMTYPE_RADIO; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1204 /* using rawaudio demuxer */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1205 *file_format = DEMUXER_TYPE_RAWAUDIO; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1206 stream->flags = STREAM_READ; |
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 priv->radio_fd=-1; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1209 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1210 stream->start_pos=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1211 stream->end_pos=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1212 stream->priv=priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1213 stream->close=close_s; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1214 stream->fill_buffer=fill_buffer_s; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1215 |
20738 | 1216 priv->radio_fd = open(radio_param_device, O_RDONLY); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1217 if (priv->radio_fd < 0) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1218 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_UnableOpenDevice, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1219 radio_param_device, strerror(errno)); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1220 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1221 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1222 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1223 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
|
1224 fcntl(priv->radio_fd, F_SETFD, FD_CLOEXEC); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1225 |
20737 | 1226 get_volume(priv, &priv->old_snd_volume); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1227 set_volume(priv,0); |
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 if (init_frac(priv)!=STREAM_OK){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1230 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1231 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1232 }; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1233 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1234 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
|
1235 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1236 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1237 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1238 |
20758
e0f3254f3b76
Adding ability to check allowed frequency range.
voroshil
parents:
20738
diff
changeset
|
1239 if ((frequency<priv->rangelow)||(frequency>priv->rangehigh)){ |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1240 mp_msg(MSGT_RADIO, MSGL_ERR, MSGTR_RADIO_WrongFreq,frequency); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1241 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1242 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1243 }else |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1244 mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_UsingFreq,frequency); |
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 if(set_frequency(priv,frequency)!=STREAM_OK){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1247 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1248 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1249 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1250 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1251 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1252 if (init_audio(priv)!=STREAM_OK){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1253 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1254 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1255 } |
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 defined(USE_RADIO_CAPTURE) && defined(USE_STREAM_CACHE) |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1258 if(priv->do_capture){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1259 //5 second cache |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1260 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
|
1261 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
|
1262 priv->audio_in.bytes_per_sample,priv->audio_in.blocksize)) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1263 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
|
1264 close_s(stream); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1265 return STREAM_ERROR; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1266 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1267 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1268 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1269 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1270 set_volume(priv,radio_param_volume); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1271 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1272 return STREAM_OK; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1273 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1274 |
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 * Close stream. Clear structures. |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1277 */ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1278 static void close_s(struct stream_st * stream){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1279 radio_priv_t* priv=(radio_priv_t*)stream->priv; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1280 radio_channels_t * tmp; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1281 if (!priv) return; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1282 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1283 #ifdef USE_RADIO_CAPTURE |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1284 if(priv->audio_ringbuffer){ |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1285 free(priv->audio_ringbuffer); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1286 priv->audio_ringbuffer=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1287 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1288 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1289 priv->do_capture=0; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1290 #endif |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1291 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1292 while (priv->radio_channel_list) { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1293 tmp=priv->radio_channel_list; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1294 priv->radio_channel_list=priv->radio_channel_list->next; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1295 free(tmp); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1296 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1297 priv->radio_channel_current=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1298 priv->radio_channel_list=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1299 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1300 if (priv->radio_fd>0){ |
20796
dee98cb0b090
Move non driver-specific block to non-driver specific procedure, to avoid
voroshil
parents:
20758
diff
changeset
|
1301 set_volume(priv, priv->old_snd_volume); |
19568
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1302 close(priv->radio_fd); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1303 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1304 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1305 free(priv); |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1306 stream->priv=NULL; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1307 } |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1308 |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1309 stream_info_t stream_info_radio = { |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1310 "Radio stream", |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1311 "Radio", |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1312 "Vladimir Voroshilov", |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1313 "In development", |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1314 open_s, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1315 { "radio", NULL }, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1316 &stream_opts, |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1317 1 // Urls are an option string |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1318 }; |
bd821fd3e244
Radio support, patch by Vladimir Voroshilov (voroshil gmail com)
reimar
parents:
diff
changeset
|
1319 |