1 /* GStreamer DVB source
2 * Copyright (C) 2006 Zaheer Abbas Merali <zaheerabbas at merali
4 * Copyright (C) 2014 Samsung Electronics. All rights reserved.
5 * @Author: Reynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 * SECTION:element-dvbsrc
26 * dvbsrc can be used to capture media from DVB cards. Supported DTV
27 * broadcasting standards include DVB-T/C/S, ATSC, ISDB-T and DTMB.
29 * ## Example launch line
31 * gst-launch-1.0 dvbsrc modulation="QAM 64" trans-mode=8k bandwidth=8 frequency=514000000 code-rate-lp=AUTO code-rate-hp=2/3 guard=4 hierarchy=0 ! mpegtsdemux name=demux ! queue max-size-buffers=0 max-size-time=0 ! mpegvideoparse ! mpegvideoparse ! mpeg2dec ! xvimagesink demux. ! queue max-size-buffers=0 max-size-time=0 ! mpegaudioparse ! mpg123audiodec ! audioconvert ! pulsesink
32 * ]| Captures a full transport stream from DVB card 0 that is a DVB-T card at tuned frequency 514000000 Hz with other parameters as seen in the pipeline and renders the first TV program on the transport stream.
34 * gst-launch-1.0 dvbsrc modulation="QAM 64" trans-mode=8k bandwidth=8 frequency=514000000 code-rate-lp=AUTO code-rate-hp=2/3 guard=4 hierarchy=0 pids=100:256:257 ! mpegtsdemux name=demux ! queue max-size-buffers=0 max-size-time=0 ! mpegvideoparse ! mpeg2dec ! xvimagesink demux. ! queue max-size-buffers=0 max-size-time=0 ! mpegaudioparse ! mpg123audiodec ! audioconvert ! pulsesink
35 * ]| Captures and renders a transport stream from DVB card 0 that is a DVB-T card for a program at tuned frequency 514000000 Hz with PMT PID 100 and elementary stream PIDs of 256, 257 with other parameters as seen in the pipeline.
37 * gst-launch-1.0 dvbsrc polarity="h" frequency=11302000 symbol-rate=27500 diseqc-source=0 pids=50:102:103 ! mpegtsdemux name=demux ! queue max-size-buffers=0 max-size-time=0 ! mpegvideoparse ! mpeg2dec ! xvimagesink demux. ! queue max-size-buffers=0 max-size-time=0 ! mpegaudioparse ! mpg123audiodec ! audioconvert ! pulsesink
38 * ]| Captures and renders a transport stream from DVB card 0 that is a DVB-S card for a program at tuned frequency 11302000 kHz, symbol rate of 27500 kBd (kilo bauds) with PMT PID of 50 and elementary stream PIDs of 102 and 103.
40 * gst-launch-1.0 dvbsrc frequency=515142857 guard=16 trans-mode="8k" isdbt-layer-enabled=7 isdbt-partial-reception=1 isdbt-layera-fec="2/3" isdbt-layera-modulation="QPSK" isdbt-layera-segment-count=1 isdbt-layera-time-interleaving=4 isdbt-layerb-fec="3/4" isdbt-layerb-modulation="qam-64" isdbt-layerb-segment-count=12 isdbt-layerb-time-interleaving=2 isdbt-layerc-fec="1/2" isdbt-layerc-modulation="qam-64" isdbt-layerc-segment-count=0 isdbt-layerc-time-interleaving=0 delsys="isdb-t" ! tsdemux ! "video/x-h264" ! h264parse ! queue ! avdec_h264 ! videoconvert ! queue ! autovideosink
41 * ]| Captures and renders the video track of TV ParaĆba HD (Globo affiliate) in Campina Grande, Brazil. This is an ISDB-T (Brazilian ISDB-Tb variant) broadcast.
43 * gst-launch-1.0 dvbsrc frequency=503000000 delsys="atsc" modulation="8vsb" pids=48:49:52 ! decodebin name=dec dec. ! videoconvert ! autovideosink dec. ! audioconvert ! autoaudiosink
44 * ]| Captures and renders KOFY-HD in San Jose, California. This is an ATSC broadcast, PMT ID 48, Audio/Video elementary stream PIDs 49 and 52 respectively.
49 * History of DVB_API_VERSION 5 minor changes
51 * API Addition/changes in reverse order (most recent first)
53 * Minor 10 (statistics properties)
63 * DTV_ISDBS_TS_ID_LEGACY (was DVB_ISDBS_TS_ID)
64 * DTV_DVBT2_PLP_ID_LEGACY (was DVB_DVBT2_PLP_ID)
69 * Minor 7 (DTMB Support)
72 * TRANSMISSION_MODE_C1 / _C3780
73 * GUARD_INTERVAL_PN420 / _PN595 / _PN945
74 * INTERLEAVING_NONE / _240 / _720
76 * SYS_DTMB (Renamed from SYS_DMBTH but has safety #define)
79 * DTV_ATSCMH_* (for those not defined in later versions)
81 * Somewhere in between 5 and 6:
82 * SYS_DVBC_ANNEX_A / _C (Safety #define for _AC => A)
84 * Minor 5 (Note : minimum version we support according to configure.ac)
88 /* We know we have at least DVB_API_VERSION >= 5 (minor 5) */
89 #define HAVE_V5_MINOR(minor) ((DVB_API_VERSION > 5) || \
90 (DVB_API_VERSION_MINOR >= (minor)))
96 #include "gstdvbsrc.h"
98 #include <gst/glib-compat-private.h>
99 #include <sys/ioctl.h>
100 #include <sys/poll.h>
109 #include <linux/dvb/version.h>
110 #include <linux/dvb/frontend.h>
111 #include <linux/dvb/dmx.h>
113 #include <gst/gst-i18n-plugin.h>
115 /* Before 5.6 we map A to AC */
116 #if !HAVE_V5_MINOR(6)
117 #define SYS_DVBC_ANNEX_A SYS_DVBC_ANNEX_AC
120 /* NO_STREAM_ID_FILTER & DTV_STREAMID introduced in minor 8 */
121 #ifndef NO_STREAM_ID_FILTER
122 #define NO_STREAM_ID_FILTER (~0U)
124 #ifndef DTV_STREAM_ID
125 #define DTV_STREAM_ID DTV_ISDBS_TS_ID
128 GST_DEBUG_CATEGORY_STATIC (gstdvbsrc_debug);
129 #define GST_CAT_DEFAULT (gstdvbsrc_debug)
134 * Can't be greater than DTV_IOCTL_MAX_MSGS but we are
135 * not using more than 25 for the largest use case (ISDB-T).
139 #define NUM_DTV_PROPS 25
157 ARG_DVBSRC_DISEQC_SRC,
158 ARG_DVBSRC_FREQUENCY,
162 ARG_DVBSRC_BANDWIDTH,
163 ARG_DVBSRC_CODE_RATE_HP,
164 ARG_DVBSRC_CODE_RATE_LP,
166 ARG_DVBSRC_MODULATION,
167 ARG_DVBSRC_TRANSMISSION_MODE,
168 ARG_DVBSRC_HIERARCHY_INF,
170 ARG_DVBSRC_INVERSION,
171 ARG_DVBSRC_STATS_REPORTING_INTERVAL,
173 ARG_DVBSRC_TUNING_TIMEOUT,
174 ARG_DVBSRC_DVB_BUFFER_SIZE,
178 ARG_DVBSRC_STREAM_ID,
179 ARG_DVBSRC_BANDWIDTH_HZ,
180 ARG_DVBSRC_ISDBT_LAYER_ENABLED,
181 ARG_DVBSRC_ISDBT_PARTIAL_RECEPTION,
182 ARG_DVBSRC_ISDBT_SOUND_BROADCASTING,
183 ARG_DVBSRC_ISDBT_SB_SUBCHANNEL_ID,
184 ARG_DVBSRC_ISDBT_SB_SEGMENT_IDX,
185 ARG_DVBSRC_ISDBT_SB_SEGMENT_COUNT,
186 ARG_DVBSRC_ISDBT_LAYERA_FEC,
187 ARG_DVBSRC_ISDBT_LAYERA_MODULATION,
188 ARG_DVBSRC_ISDBT_LAYERA_SEGMENT_COUNT,
189 ARG_DVBSRC_ISDBT_LAYERA_TIME_INTERLEAVING,
190 ARG_DVBSRC_ISDBT_LAYERB_FEC,
191 ARG_DVBSRC_ISDBT_LAYERB_MODULATION,
192 ARG_DVBSRC_ISDBT_LAYERB_SEGMENT_COUNT,
193 ARG_DVBSRC_ISDBT_LAYERB_TIME_INTERLEAVING,
194 ARG_DVBSRC_ISDBT_LAYERC_FEC,
195 ARG_DVBSRC_ISDBT_LAYERC_MODULATION,
196 ARG_DVBSRC_ISDBT_LAYERC_SEGMENT_COUNT,
197 ARG_DVBSRC_ISDBT_LAYERC_TIME_INTERLEAVING,
201 ARG_DVBSRC_INTERLEAVING
204 #define DEFAULT_ADAPTER 0
205 #define DEFAULT_FRONTEND 0
206 #define DEFAULT_DISEQC_SRC -1 /* disabled */
207 #define DEFAULT_FREQUENCY 0
208 #define DEFAULT_POLARITY "H"
209 #define DEFAULT_PIDS "8192" /* Special value meaning 'all' PIDs */
210 #define DEFAULT_SYMBOL_RATE 0
211 #define DEFAULT_BANDWIDTH_HZ 8000000
212 #define DEFAULT_BANDWIDTH BANDWIDTH_8_MHZ
213 #define DEFAULT_CODE_RATE_HP FEC_AUTO
214 #define DEFAULT_CODE_RATE_LP FEC_1_2
215 #define DEFAULT_GUARD GUARD_INTERVAL_1_16
216 #define DEFAULT_MODULATION QAM_16
217 #define DEFAULT_TRANSMISSION_MODE TRANSMISSION_MODE_8K
218 #define DEFAULT_HIERARCHY HIERARCHY_1
219 #define DEFAULT_INVERSION INVERSION_ON
220 #define DEFAULT_STATS_REPORTING_INTERVAL 100
221 #define DEFAULT_TIMEOUT 1000000 /* 1 second */
222 #define DEFAULT_TUNING_TIMEOUT 10 * GST_SECOND /* 10 seconds */
223 #define DEFAULT_DVB_BUFFER_SIZE (10*188*1024) /* kernel default is 8192 */
224 #define DEFAULT_BUFFER_SIZE 8192 /* not a property */
225 #define DEFAULT_DELSYS SYS_UNDEFINED
226 #define DEFAULT_PILOT PILOT_AUTO
227 #define DEFAULT_ROLLOFF ROLLOFF_AUTO
228 #define DEFAULT_STREAM_ID NO_STREAM_ID_FILTER
229 #define DEFAULT_ISDBT_LAYER_ENABLED 7
230 #define DEFAULT_ISDBT_PARTIAL_RECEPTION 1
231 #define DEFAULT_ISDBT_SOUND_BROADCASTING 0
232 #define DEFAULT_ISDBT_SB_SUBCHANNEL_ID -1
233 #define DEFAULT_ISDBT_SB_SEGMENT_IDX 0
234 #define DEFAULT_ISDBT_SB_SEGMENT_COUNT 1
235 #define DEFAULT_ISDBT_LAYERA_FEC FEC_AUTO
236 #define DEFAULT_ISDBT_LAYERA_MODULATION QAM_AUTO
237 #define DEFAULT_ISDBT_LAYERA_SEGMENT_COUNT -1
238 #define DEFAULT_ISDBT_LAYERA_TIME_INTERLEAVING -1
239 #define DEFAULT_ISDBT_LAYERB_FEC FEC_AUTO
240 #define DEFAULT_ISDBT_LAYERB_MODULATION QAM_AUTO
241 #define DEFAULT_ISDBT_LAYERB_SEGMENT_COUNT -1
242 #define DEFAULT_ISDBT_LAYERB_TIME_INTERLEAVING -1
243 #define DEFAULT_ISDBT_LAYERC_FEC FEC_AUTO
244 #define DEFAULT_ISDBT_LAYERC_MODULATION QAM_AUTO
245 #define DEFAULT_ISDBT_LAYERC_SEGMENT_COUNT -1
246 #define DEFAULT_ISDBT_LAYERC_TIME_INTERLEAVING -1
247 #define DEFAULT_LNB_SLOF (11700*1000UL)
248 #define DEFAULT_LNB_LOF1 (9750*1000UL)
249 #define DEFAULT_LNB_LOF2 (10600*1000UL)
251 #define DEFAULT_INTERLEAVING INTERLEAVING_AUTO
253 #define DEFAULT_INTERLEAVING 0
256 static void gst_dvbsrc_output_frontend_stats (GstDvbSrc * src);
258 #define GST_TYPE_DVBSRC_CODE_RATE (gst_dvbsrc_code_rate_get_type ())
260 gst_dvbsrc_code_rate_get_type (void)
262 static GType dvbsrc_code_rate_type = 0;
263 static const GEnumValue code_rate_types[] = {
264 {FEC_NONE, "NONE", "none"},
265 {FEC_1_2, "1/2", "1/2"},
266 {FEC_2_3, "2/3", "2/3"},
267 {FEC_3_4, "3/4", "3/4"},
268 {FEC_4_5, "4/5", "4/5"},
269 {FEC_5_6, "5/6", "5/6"},
270 {FEC_6_7, "6/7", "6/7"},
271 {FEC_7_8, "7/8", "7/8"},
272 {FEC_8_9, "8/9", "8/9"},
273 {FEC_AUTO, "AUTO", "auto"},
274 {FEC_3_5, "3/5", "3/5"},
275 {FEC_9_10, "9/10", "9/10"},
277 {FEC_2_5, "2/5", "2/5"},
282 if (!dvbsrc_code_rate_type) {
283 dvbsrc_code_rate_type =
284 g_enum_register_static ("GstDvbSrcCode_Rate", code_rate_types);
286 return dvbsrc_code_rate_type;
289 #define GST_TYPE_DVBSRC_MODULATION (gst_dvbsrc_modulation_get_type ())
291 gst_dvbsrc_modulation_get_type (void)
293 static GType dvbsrc_modulation_type = 0;
294 static const GEnumValue modulation_types[] = {
295 {QPSK, "QPSK", "qpsk"},
296 {QAM_16, "QAM 16", "qam-16"},
297 {QAM_32, "QAM 32", "qam-32"},
298 {QAM_64, "QAM 64", "qam-64"},
299 {QAM_128, "QAM 128", "qam-128"},
300 {QAM_256, "QAM 256", "qam-256"},
301 {QAM_AUTO, "AUTO", "auto"},
302 {VSB_8, "8VSB", "8vsb"},
303 {VSB_16, "16VSB", "16vsb"},
304 {PSK_8, "8PSK", "8psk"},
305 {APSK_16, "16APSK", "16apsk"},
306 {APSK_32, "32APSK", "32apsk"},
307 {DQPSK, "DQPSK", "dqpsk"},
308 {QAM_4_NR, "QAM 4 NR", "qam-4-nr"},
312 if (!dvbsrc_modulation_type) {
313 dvbsrc_modulation_type =
314 g_enum_register_static ("GstDvbSrcModulation", modulation_types);
316 return dvbsrc_modulation_type;
319 #define GST_TYPE_DVBSRC_TRANSMISSION_MODE (gst_dvbsrc_transmission_mode_get_type ())
321 gst_dvbsrc_transmission_mode_get_type (void)
323 static GType dvbsrc_transmission_mode_type = 0;
324 static const GEnumValue transmission_mode_types[] = {
325 {TRANSMISSION_MODE_2K, "2K", "2k"},
326 {TRANSMISSION_MODE_8K, "8K", "8k"},
327 {TRANSMISSION_MODE_AUTO, "AUTO", "auto"},
328 {TRANSMISSION_MODE_4K, "4K", "4k"},
329 {TRANSMISSION_MODE_1K, "1K", "1k"},
330 {TRANSMISSION_MODE_16K, "16K", "16k"},
331 {TRANSMISSION_MODE_32K, "32K", "32k"},
333 {TRANSMISSION_MODE_C1, "C1", "c1"},
334 {TRANSMISSION_MODE_C3780, "C3780", "c3780"},
339 if (!dvbsrc_transmission_mode_type) {
340 dvbsrc_transmission_mode_type =
341 g_enum_register_static ("GstDvbSrcTransmission_Mode",
342 transmission_mode_types);
344 return dvbsrc_transmission_mode_type;
347 #define GST_TYPE_DVBSRC_BANDWIDTH (gst_dvbsrc_bandwidth_get_type ())
349 gst_dvbsrc_bandwidth_get_type (void)
351 static GType dvbsrc_bandwidth_type = 0;
352 static const GEnumValue bandwidth_types[] = {
353 {BANDWIDTH_8_MHZ, "8", "8"},
354 {BANDWIDTH_7_MHZ, "7", "7"},
355 {BANDWIDTH_6_MHZ, "6", "6"},
356 {BANDWIDTH_AUTO, "AUTO", "AUTO"},
357 {BANDWIDTH_5_MHZ, "5", "5"},
358 {BANDWIDTH_10_MHZ, "10", "10"},
359 {BANDWIDTH_1_712_MHZ, "1.712", "1.712"},
363 if (!dvbsrc_bandwidth_type) {
364 dvbsrc_bandwidth_type =
365 g_enum_register_static ("GstDvbSrcBandwidth", bandwidth_types);
367 return dvbsrc_bandwidth_type;
370 #define GST_TYPE_DVBSRC_GUARD (gst_dvbsrc_guard_get_type ())
372 gst_dvbsrc_guard_get_type (void)
374 static GType dvbsrc_guard_type = 0;
375 static const GEnumValue guard_types[] = {
376 {GUARD_INTERVAL_1_32, "32", "32"},
377 {GUARD_INTERVAL_1_16, "16", "16"},
378 {GUARD_INTERVAL_1_8, "8", "8"},
379 {GUARD_INTERVAL_1_4, "4", "4"},
380 {GUARD_INTERVAL_AUTO, "AUTO", "auto"},
381 {GUARD_INTERVAL_1_128, "128", "128"},
382 {GUARD_INTERVAL_19_128, "19/128", "19/128"},
383 {GUARD_INTERVAL_19_256, "19/256", "19/256"},
385 {GUARD_INTERVAL_PN420, "PN420", "pn420"},
386 {GUARD_INTERVAL_PN595, "PN595", "pn595"},
387 {GUARD_INTERVAL_PN945, "PN945", "pn945"},
392 if (!dvbsrc_guard_type) {
393 dvbsrc_guard_type = g_enum_register_static ("GstDvbSrcGuard", guard_types);
395 return dvbsrc_guard_type;
398 #define GST_TYPE_DVBSRC_HIERARCHY (gst_dvbsrc_hierarchy_get_type ())
400 gst_dvbsrc_hierarchy_get_type (void)
402 static GType dvbsrc_hierarchy_type = 0;
403 static const GEnumValue hierarchy_types[] = {
404 {HIERARCHY_NONE, "NONE", "none"},
405 {HIERARCHY_1, "1", "1"},
406 {HIERARCHY_2, "2", "2"},
407 {HIERARCHY_4, "4", "4"},
408 {HIERARCHY_AUTO, "AUTO", "auto"},
412 if (!dvbsrc_hierarchy_type) {
413 dvbsrc_hierarchy_type =
414 g_enum_register_static ("GstDvbSrcHierarchy", hierarchy_types);
416 return dvbsrc_hierarchy_type;
419 #define GST_TYPE_DVBSRC_INVERSION (gst_dvbsrc_inversion_get_type ())
421 gst_dvbsrc_inversion_get_type (void)
423 static GType dvbsrc_inversion_type = 0;
424 static const GEnumValue inversion_types[] = {
425 {INVERSION_OFF, "OFF", "off"},
426 {INVERSION_ON, "ON", "on"},
427 {INVERSION_AUTO, "AUTO", "auto"},
431 if (!dvbsrc_inversion_type) {
432 dvbsrc_inversion_type =
433 g_enum_register_static ("GstDvbSrcInversion", inversion_types);
435 return dvbsrc_inversion_type;
438 #define GST_TYPE_DVBSRC_DELSYS (gst_dvbsrc_delsys_get_type ())
440 gst_dvbsrc_delsys_get_type (void)
442 static GType dvbsrc_delsys_type = 0;
443 static const GEnumValue delsys_types[] = {
444 {SYS_UNDEFINED, "UNDEFINED", "undefined"},
445 {SYS_DVBC_ANNEX_A, "DVB-C-A", "dvb-c-a"},
446 {SYS_DVBC_ANNEX_B, "DVB-C-B", "dvb-c-b"},
447 {SYS_DVBT, "DVB-T", "dvb-t"},
448 {SYS_DSS, "DSS", "dss"},
449 {SYS_DVBS, "DVB-S", "dvb-s"},
450 {SYS_DVBS2, "DVB-S2", "dvb-s2"},
451 {SYS_DVBH, "DVB-H", "dvb-h"},
452 {SYS_ISDBT, "ISDB-T", "isdb-t"},
453 {SYS_ISDBS, "ISDB-S", "isdb-s"},
454 {SYS_ISDBC, "ISDB-C", "isdb-c"},
455 {SYS_ATSC, "ATSC", "atsc"},
456 {SYS_ATSCMH, "ATSC-MH", "atsc-mh"},
458 {SYS_DTMB, "DTMB", "dtmb"},
460 {SYS_CMMB, "CMMB", "cmmb"},
461 {SYS_DAB, "DAB", "dab"},
462 {SYS_DVBT2, "DVB-T2", "dvb-t2"},
463 {SYS_TURBO, "TURBO", "turbo"},
465 {SYS_DVBC_ANNEX_C, "DVB-C-C", "dvb-c-c"},
470 if (!dvbsrc_delsys_type) {
472 g_enum_register_static ("GstDvbSrcDelsys", delsys_types);
474 return dvbsrc_delsys_type;
477 #define GST_TYPE_DVBSRC_PILOT (gst_dvbsrc_pilot_get_type ())
479 gst_dvbsrc_pilot_get_type (void)
481 static GType dvbsrc_pilot_type = 0;
482 static const GEnumValue pilot_types[] = {
483 {PILOT_ON, "ON", "on"},
484 {PILOT_OFF, "OFF", "off"},
485 {PILOT_AUTO, "AUTO", "auto"},
489 if (!dvbsrc_pilot_type) {
490 dvbsrc_pilot_type = g_enum_register_static ("GstDvbSrcPilot", pilot_types);
492 return dvbsrc_pilot_type;
495 #define GST_TYPE_DVBSRC_ROLLOFF (gst_dvbsrc_rolloff_get_type ())
497 gst_dvbsrc_rolloff_get_type (void)
499 static GType dvbsrc_rolloff_type = 0;
500 static const GEnumValue rolloff_types[] = {
501 {ROLLOFF_35, "35", "35"},
502 {ROLLOFF_20, "20", "20"},
503 {ROLLOFF_25, "25", "25"},
504 {ROLLOFF_AUTO, "auto", "auto"},
508 if (!dvbsrc_rolloff_type) {
509 dvbsrc_rolloff_type =
510 g_enum_register_static ("GstDvbSrcRolloff", rolloff_types);
512 return dvbsrc_rolloff_type;
515 #define GST_TYPE_INTERLEAVING (gst_dvbsrc_interleaving_get_type ())
517 gst_dvbsrc_interleaving_get_type (void)
519 static GType dvbsrc_interleaving_type = 0;
520 static const GEnumValue interleaving_types[] = {
522 {INTERLEAVING_NONE, "NONE", "none"},
523 {INTERLEAVING_AUTO, "AUTO", "auto"},
524 {INTERLEAVING_240, "240", "240"},
525 {INTERLEAVING_720, "720", "720"},
530 if (!dvbsrc_interleaving_type) {
531 dvbsrc_interleaving_type =
532 g_enum_register_static ("GstDvbSrcInterleaving", interleaving_types);
534 return dvbsrc_interleaving_type;
537 static void gst_dvbsrc_finalize (GObject * object);
538 static void gst_dvbsrc_set_property (GObject * object, guint prop_id,
539 const GValue * value, GParamSpec * pspec);
540 static void gst_dvbsrc_get_property (GObject * object, guint prop_id,
541 GValue * value, GParamSpec * pspec);
543 static GstFlowReturn gst_dvbsrc_create (GstPushSrc * element,
544 GstBuffer ** buffer);
546 static gboolean gst_dvbsrc_start (GstBaseSrc * bsrc);
547 static gboolean gst_dvbsrc_stop (GstBaseSrc * bsrc);
548 static GstStateChangeReturn gst_dvbsrc_change_state (GstElement * element,
549 GstStateChange transition);
551 static gboolean gst_dvbsrc_unlock (GstBaseSrc * bsrc);
552 static gboolean gst_dvbsrc_unlock_stop (GstBaseSrc * bsrc);
553 static gboolean gst_dvbsrc_is_seekable (GstBaseSrc * bsrc);
554 static gboolean gst_dvbsrc_get_size (GstBaseSrc * src, guint64 * size);
556 static void gst_dvbsrc_do_tune (GstDvbSrc * src);
557 static gboolean gst_dvbsrc_tune (GstDvbSrc * object);
558 static gboolean gst_dvbsrc_set_fe_params (GstDvbSrc * object,
559 struct dtv_properties *props);
560 static void gst_dvbsrc_guess_delsys (GstDvbSrc * object);
561 static gboolean gst_dvbsrc_tune_fe (GstDvbSrc * object);
563 static void gst_dvbsrc_set_pes_filters (GstDvbSrc * object);
564 static void gst_dvbsrc_unset_pes_filters (GstDvbSrc * object);
565 static gboolean gst_dvbsrc_is_valid_modulation (guint delsys, guint mod);
566 static gboolean gst_dvbsrc_is_valid_trans_mode (guint delsys, guint mode);
567 static gboolean gst_dvbsrc_is_valid_bandwidth (guint delsys, guint bw);
572 * This loop should be safe enough considering:
574 * 1.- EINTR suggest the next ioctl might succeed
575 * 2.- It's highly unlikely you will end up spining
576 * before your entire system goes nuts due to
577 * the massive number of interrupts.
579 * We don't check for EAGAIN here cause we are opening
580 * the frontend in blocking mode.
582 #define LOOP_WHILE_EINTR(v,func) do { (v) = (func); } \
583 while ((v) == -1 && errno == EINTR);
585 static GstStaticPadTemplate ts_src_factory = GST_STATIC_PAD_TEMPLATE ("src",
590 "mpegversion = (int) 2," "systemstream = (boolean) TRUE"));
593 ******************************
598 ******************************
601 #define gst_dvbsrc_parent_class parent_class
602 G_DEFINE_TYPE (GstDvbSrc, gst_dvbsrc, GST_TYPE_PUSH_SRC);
604 static guint gst_dvbsrc_signals[LAST_SIGNAL] = { 0 };
606 /* initialize the plugin's class */
608 gst_dvbsrc_class_init (GstDvbSrcClass * klass)
610 GObjectClass *gobject_class;
611 GstElementClass *gstelement_class;
612 GstBaseSrcClass *gstbasesrc_class;
613 GstPushSrcClass *gstpushsrc_class;
614 GstDvbSrcClass *gstdvbsrc_class;
616 gobject_class = (GObjectClass *) klass;
617 gstelement_class = (GstElementClass *) klass;
618 gstbasesrc_class = (GstBaseSrcClass *) klass;
619 gstpushsrc_class = (GstPushSrcClass *) klass;
620 gstdvbsrc_class = (GstDvbSrcClass *) klass;
622 gobject_class->set_property = gst_dvbsrc_set_property;
623 gobject_class->get_property = gst_dvbsrc_get_property;
624 gobject_class->finalize = gst_dvbsrc_finalize;
626 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_dvbsrc_change_state);
628 gst_element_class_add_static_pad_template (gstelement_class, &ts_src_factory);
630 gst_element_class_set_static_metadata (gstelement_class, "DVB Source",
632 "Digital Video Broadcast Source",
633 "P2P-VCR, C-Lab, University of Paderborn, "
634 "Zaheer Abbas Merali <zaheerabbas at merali dot org>\n"
635 "Reynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>");
637 gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_dvbsrc_start);
638 gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_dvbsrc_stop);
639 gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_dvbsrc_unlock);
640 gstbasesrc_class->unlock_stop = GST_DEBUG_FUNCPTR (gst_dvbsrc_unlock_stop);
641 gstbasesrc_class->is_seekable = GST_DEBUG_FUNCPTR (gst_dvbsrc_is_seekable);
642 gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_dvbsrc_get_size);
644 gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_dvbsrc_create);
646 gstdvbsrc_class->do_tune = GST_DEBUG_FUNCPTR (gst_dvbsrc_do_tune);
648 g_object_class_install_property (gobject_class, ARG_DVBSRC_ADAPTER,
649 g_param_spec_int ("adapter", "The adapter device number",
650 "The DVB adapter device number (eg. 0 for adapter0)",
651 0, 16, DEFAULT_ADAPTER, G_PARAM_READWRITE));
653 g_object_class_install_property (gobject_class, ARG_DVBSRC_FRONTEND,
654 g_param_spec_int ("frontend", "The frontend device number",
655 "The frontend device number (eg. 0 for frontend0)",
656 0, 16, DEFAULT_FRONTEND, G_PARAM_READWRITE));
658 g_object_class_install_property (gobject_class, ARG_DVBSRC_FREQUENCY,
659 g_param_spec_uint ("frequency", "Center frequency",
660 "Center frequency to tune into. Measured in kHz for the satellite "
661 "distribution standars and Hz for all the rest",
662 0, G_MAXUINT, DEFAULT_FREQUENCY,
663 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
665 g_object_class_install_property (gobject_class, ARG_DVBSRC_POLARITY,
666 g_param_spec_string ("polarity", "polarity",
667 "(DVB-S/S2) Polarity [vhHV] (eg. V for Vertical)",
669 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
671 g_object_class_install_property (gobject_class, ARG_DVBSRC_PIDS,
672 g_param_spec_string ("pids", "pids",
673 "Colon-separated list of PIDs (eg. 110:120) to capture. ACT and CAT "
674 "are automatically included but PMT should be added explicitly. "
675 "Special value 8192 gets full MPEG-TS",
676 DEFAULT_PIDS, GST_PARAM_MUTABLE_PLAYING | G_PARAM_WRITABLE));
678 g_object_class_install_property (gobject_class, ARG_DVBSRC_SYM_RATE,
679 g_param_spec_uint ("symbol-rate",
681 "(DVB-S/S2, DVB-C) Symbol rate in kBd (kilo bauds)",
682 0, G_MAXUINT, DEFAULT_SYMBOL_RATE,
683 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
685 g_object_class_install_property (gobject_class, ARG_DVBSRC_TUNE,
686 g_param_spec_pointer ("tune",
687 "tune", "Atomically tune to channel. (For Apps)", G_PARAM_WRITABLE));
689 g_object_class_install_property (gobject_class, ARG_DVBSRC_DISEQC_SRC,
690 g_param_spec_int ("diseqc-source",
692 "(DVB-S/S2) Selected DiSEqC source. Only needed if you have a "
693 "DiSEqC switch. Otherwise leave at -1 (disabled)", -1, 7,
694 DEFAULT_DISEQC_SRC, GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
696 g_object_class_install_property (gobject_class, ARG_DVBSRC_BANDWIDTH_HZ,
697 g_param_spec_uint ("bandwidth-hz", "bandwidth-hz",
698 "Channel bandwidth in Hz", 0, G_MAXUINT, DEFAULT_BANDWIDTH_HZ,
699 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
701 #ifndef GST_REMOVE_DEPRECATED
702 g_object_class_install_property (gobject_class, ARG_DVBSRC_BANDWIDTH,
703 g_param_spec_enum ("bandwidth", "bandwidth",
704 "(DVB-T) Bandwidth. Deprecated", GST_TYPE_DVBSRC_BANDWIDTH,
706 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE | G_PARAM_DEPRECATED));
709 /* FIXME: DVB-C, DVB-S, DVB-S2 named it as innerFEC */
710 g_object_class_install_property (gobject_class, ARG_DVBSRC_CODE_RATE_HP,
711 g_param_spec_enum ("code-rate-hp",
713 "(DVB-T, DVB-S/S2 and DVB-C) High priority code rate",
714 GST_TYPE_DVBSRC_CODE_RATE, DEFAULT_CODE_RATE_HP,
715 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
717 g_object_class_install_property (gobject_class, ARG_DVBSRC_CODE_RATE_LP,
718 g_param_spec_enum ("code-rate-lp",
720 "(DVB-T) Low priority code rate",
721 GST_TYPE_DVBSRC_CODE_RATE, DEFAULT_CODE_RATE_LP,
722 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
724 /* FIXME: should the property be called 'guard-interval' then? */
725 g_object_class_install_property (gobject_class, ARG_DVBSRC_GUARD,
726 g_param_spec_enum ("guard",
728 "(DVB-T) Guard Interval",
729 GST_TYPE_DVBSRC_GUARD, DEFAULT_GUARD,
730 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
732 g_object_class_install_property (gobject_class, ARG_DVBSRC_MODULATION,
733 g_param_spec_enum ("modulation", "modulation",
734 "(DVB-T/T2/C/S2, TURBO and ATSC) Modulation type",
735 GST_TYPE_DVBSRC_MODULATION, DEFAULT_MODULATION,
736 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
738 /* FIXME: property should be named 'transmission-mode' */
739 g_object_class_install_property (gobject_class,
740 ARG_DVBSRC_TRANSMISSION_MODE,
741 g_param_spec_enum ("trans-mode", "trans-mode",
742 "(DVB-T) Transmission mode",
743 GST_TYPE_DVBSRC_TRANSMISSION_MODE, DEFAULT_TRANSMISSION_MODE,
744 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
746 g_object_class_install_property (gobject_class, ARG_DVBSRC_HIERARCHY_INF,
747 g_param_spec_enum ("hierarchy", "hierarchy",
748 "(DVB-T) Hierarchy information",
749 GST_TYPE_DVBSRC_HIERARCHY, DEFAULT_HIERARCHY,
750 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
752 g_object_class_install_property (gobject_class, ARG_DVBSRC_INVERSION,
753 g_param_spec_enum ("inversion", "inversion",
754 "(DVB-T and DVB-C) Inversion information",
755 GST_TYPE_DVBSRC_INVERSION, DEFAULT_INVERSION,
756 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
758 g_object_class_install_property (gobject_class,
759 ARG_DVBSRC_STATS_REPORTING_INTERVAL,
760 g_param_spec_uint ("stats-reporting-interval",
761 "stats-reporting-interval",
762 "The number of reads before reporting frontend stats",
763 0, G_MAXUINT, DEFAULT_STATS_REPORTING_INTERVAL,
764 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
766 g_object_class_install_property (gobject_class, ARG_DVBSRC_TIMEOUT,
767 g_param_spec_uint64 ("timeout", "Timeout",
768 "Post a message after timeout microseconds (0 = disabled)",
769 0, G_MAXUINT64, DEFAULT_TIMEOUT, G_PARAM_READWRITE));
771 g_object_class_install_property (gobject_class, ARG_DVBSRC_TUNING_TIMEOUT,
772 g_param_spec_uint64 ("tuning-timeout", "Tuning Timeout",
773 "Microseconds to wait before giving up tuning/locking on a signal",
774 0, G_MAXUINT64, DEFAULT_TUNING_TIMEOUT,
775 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
777 g_object_class_install_property (gobject_class,
778 ARG_DVBSRC_DVB_BUFFER_SIZE,
779 g_param_spec_uint ("dvb-buffer-size",
781 "The kernel buffer size used by the DVB api",
782 0, G_MAXUINT, DEFAULT_DVB_BUFFER_SIZE, G_PARAM_READWRITE));
784 g_object_class_install_property (gobject_class, ARG_DVBSRC_DELSYS,
785 g_param_spec_enum ("delsys", "delsys", "Delivery System",
786 GST_TYPE_DVBSRC_DELSYS, DEFAULT_DELSYS, G_PARAM_READWRITE));
788 g_object_class_install_property (gobject_class, ARG_DVBSRC_PILOT,
789 g_param_spec_enum ("pilot", "pilot", "Pilot (DVB-S2)",
790 GST_TYPE_DVBSRC_PILOT, DEFAULT_PILOT,
791 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
793 g_object_class_install_property (gobject_class, ARG_DVBSRC_ROLLOFF,
794 g_param_spec_enum ("rolloff", "rolloff", "Rolloff (DVB-S2)",
795 GST_TYPE_DVBSRC_ROLLOFF, DEFAULT_ROLLOFF,
796 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
798 g_object_class_install_property (gobject_class, ARG_DVBSRC_STREAM_ID,
799 g_param_spec_int ("stream-id", "stream-id",
800 "(DVB-T2 and DVB-S2 max 255, ISDB max 65535) Stream ID "
801 "(-1 = disabled)", -1, 65535, DEFAULT_STREAM_ID,
802 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
804 /* Additional ISDB-T properties */
806 /* Valid values are 0x1 0x2 0x4 |-ables */
807 g_object_class_install_property (gobject_class,
808 ARG_DVBSRC_ISDBT_LAYER_ENABLED,
809 g_param_spec_uint ("isdbt-layer-enabled",
810 "ISDB-T layer enabled",
811 "(ISDB-T) Layer Enabled (7 = All layers)", 1, 7,
812 DEFAULT_ISDBT_LAYER_ENABLED,
813 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
815 g_object_class_install_property (gobject_class,
816 ARG_DVBSRC_ISDBT_PARTIAL_RECEPTION,
817 g_param_spec_int ("isdbt-partial-reception",
818 "ISDB-T partial reception",
819 "(ISDB-T) Partial Reception (-1 = AUTO)", -1, 1,
820 DEFAULT_ISDBT_PARTIAL_RECEPTION,
821 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
823 g_object_class_install_property (gobject_class,
824 ARG_DVBSRC_ISDBT_SOUND_BROADCASTING,
825 g_param_spec_int ("isdbt-sound-broadcasting",
826 "ISDB-T sound broadcasting",
827 "(ISDB-T) Sound Broadcasting", 0, 1,
828 DEFAULT_ISDBT_SOUND_BROADCASTING,
829 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
831 g_object_class_install_property (gobject_class,
832 ARG_DVBSRC_ISDBT_SB_SUBCHANNEL_ID,
833 g_param_spec_int ("isdbt-sb-subchannel-id",
834 "ISDB-T SB subchannel ID",
835 "(ISDB-T) SB Subchannel ID (-1 = AUTO)", -1, 41,
836 DEFAULT_ISDBT_SB_SEGMENT_IDX,
837 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
839 g_object_class_install_property (gobject_class,
840 ARG_DVBSRC_ISDBT_SB_SEGMENT_IDX,
841 g_param_spec_int ("isdbt-sb-segment-idx",
842 "ISDB-T SB segment IDX",
843 "(ISDB-T) SB segment IDX", 0, 12,
844 DEFAULT_ISDBT_SB_SEGMENT_IDX,
845 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
847 g_object_class_install_property (gobject_class,
848 ARG_DVBSRC_ISDBT_SB_SEGMENT_COUNT,
849 g_param_spec_uint ("isdbt-sb-segment-count",
850 "ISDB-T SB segment count",
851 "(ISDB-T) SB segment count", 1, 13,
852 DEFAULT_ISDBT_SB_SEGMENT_COUNT,
853 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
855 g_object_class_install_property (gobject_class, ARG_DVBSRC_ISDBT_LAYERA_FEC,
856 g_param_spec_enum ("isdbt-layera-fec",
857 "ISDB-T layer A FEC", "(ISDB-T) layer A Forward Error Correction",
858 GST_TYPE_DVBSRC_CODE_RATE, DEFAULT_ISDBT_LAYERA_FEC,
859 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
861 g_object_class_install_property (gobject_class, ARG_DVBSRC_ISDBT_LAYERB_FEC,
862 g_param_spec_enum ("isdbt-layerb-fec",
863 "ISDB-T layer B FEC", "(ISDB-T) layer B Forward Error Correction",
864 GST_TYPE_DVBSRC_CODE_RATE, DEFAULT_ISDBT_LAYERB_FEC,
865 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
867 g_object_class_install_property (gobject_class, ARG_DVBSRC_ISDBT_LAYERC_FEC,
868 g_param_spec_enum ("isdbt-layerc-fec",
869 "ISDB-T layer A FEC", "(ISDB-T) layer C Forward Error Correction",
870 GST_TYPE_DVBSRC_CODE_RATE, DEFAULT_ISDBT_LAYERC_FEC,
871 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
873 g_object_class_install_property (gobject_class,
874 ARG_DVBSRC_ISDBT_LAYERA_MODULATION,
875 g_param_spec_enum ("isdbt-layera-modulation", "ISDBT layer A modulation",
876 "(ISDB-T) Layer A modulation type",
877 GST_TYPE_DVBSRC_MODULATION, DEFAULT_ISDBT_LAYERA_MODULATION,
878 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
880 g_object_class_install_property (gobject_class,
881 ARG_DVBSRC_ISDBT_LAYERB_MODULATION,
882 g_param_spec_enum ("isdbt-layerb-modulation", "ISDBT layer B modulation",
883 "(ISDB-T) Layer B modulation type",
884 GST_TYPE_DVBSRC_MODULATION, DEFAULT_ISDBT_LAYERB_MODULATION,
885 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
887 g_object_class_install_property (gobject_class,
888 ARG_DVBSRC_ISDBT_LAYERC_MODULATION,
889 g_param_spec_enum ("isdbt-layerc-modulation", "ISDBT layer C modulation",
890 "(ISDB-T) Layer C modulation type",
891 GST_TYPE_DVBSRC_MODULATION, DEFAULT_ISDBT_LAYERC_MODULATION,
892 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
894 g_object_class_install_property (gobject_class,
895 ARG_DVBSRC_ISDBT_LAYERA_SEGMENT_COUNT,
896 g_param_spec_int ("isdbt-layera-segment-count",
897 "ISDB-T layer A segment count",
898 "(ISDB-T) Layer A segment count (-1 = AUTO)", -1, 13,
899 DEFAULT_ISDBT_LAYERA_SEGMENT_COUNT,
900 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
902 g_object_class_install_property (gobject_class,
903 ARG_DVBSRC_ISDBT_LAYERB_SEGMENT_COUNT,
904 g_param_spec_int ("isdbt-layerb-segment-count",
905 "ISDB-T layer B segment count",
906 "(ISDB-T) Layer B segment count (-1 = AUTO)", -1, 13,
907 DEFAULT_ISDBT_LAYERB_SEGMENT_COUNT,
908 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
910 g_object_class_install_property (gobject_class,
911 ARG_DVBSRC_ISDBT_LAYERC_SEGMENT_COUNT,
912 g_param_spec_int ("isdbt-layerc-segment-count",
913 "ISDB-T layer C segment count",
914 "(ISDB-T) Layer C segment count (-1 = AUTO)", -1, 13,
915 DEFAULT_ISDBT_LAYERC_SEGMENT_COUNT,
916 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
918 g_object_class_install_property (gobject_class,
919 ARG_DVBSRC_ISDBT_LAYERA_TIME_INTERLEAVING,
920 g_param_spec_int ("isdbt-layera-time-interleaving",
921 "ISDB-T layer A time interleaving",
922 "(ISDB-T) Layer A time interleaving (-1 = AUTO)", -1, 8,
923 DEFAULT_ISDBT_LAYERA_TIME_INTERLEAVING,
924 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
926 g_object_class_install_property (gobject_class,
927 ARG_DVBSRC_ISDBT_LAYERB_TIME_INTERLEAVING,
928 g_param_spec_int ("isdbt-layerb-time-interleaving",
929 "ISDB-T layer B time interleaving",
930 "(ISDB-T) Layer B time interleaving (-1 = AUTO)", -1, 8,
931 DEFAULT_ISDBT_LAYERB_TIME_INTERLEAVING,
932 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
934 g_object_class_install_property (gobject_class,
935 ARG_DVBSRC_ISDBT_LAYERC_TIME_INTERLEAVING,
936 g_param_spec_int ("isdbt-layerc-time-interleaving",
937 "ISDB-T layer C time interleaving",
938 "(ISDB-T) Layer C time interleaving (-1 = AUTO)", -1, 8,
939 DEFAULT_ISDBT_LAYERC_TIME_INTERLEAVING,
940 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
942 /* LNB properties (Satellite distribution standards) */
944 g_object_class_install_property (gobject_class, ARG_DVBSRC_LNB_SLOF,
945 g_param_spec_uint ("lnb-slof", "Tuning Timeout",
946 "LNB's Upper bound for low band reception (kHz)",
947 0, G_MAXUINT, DEFAULT_LNB_SLOF,
948 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
950 g_object_class_install_property (gobject_class, ARG_DVBSRC_LNB_LOF1,
951 g_param_spec_uint ("lnb-lof1", "Low band local oscillator frequency",
952 "LNB's Local oscillator frequency used for low band reception (kHz)",
953 0, G_MAXUINT, DEFAULT_LNB_LOF1,
954 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
956 g_object_class_install_property (gobject_class, ARG_DVBSRC_LNB_LOF2,
957 g_param_spec_uint ("lnb-lof2", "High band local oscillator frequency",
958 "LNB's Local oscillator frequency used for high band reception (kHz)",
959 0, G_MAXUINT, DEFAULT_LNB_LOF2,
960 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
962 /* Additional DTMB properties */
964 g_object_class_install_property (gobject_class,
965 ARG_DVBSRC_INTERLEAVING,
966 g_param_spec_enum ("interleaving", "DTMB Interleaving",
967 "(DTMB) Interleaving type",
968 GST_TYPE_INTERLEAVING, DEFAULT_INTERLEAVING,
969 GST_PARAM_MUTABLE_PLAYING | G_PARAM_READWRITE));
972 * GstDvbSrc::tuning-start:
973 * @gstdvbsrc: the element on which the signal is emitted
975 * Signal emited when the element first attempts to tune the
976 * frontend tunner to a given frequency.
978 gst_dvbsrc_signals[SIGNAL_TUNING_START] =
979 g_signal_new ("tuning-start", G_TYPE_FROM_CLASS (klass),
980 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
982 * GstDvbSrc::tuning-done:
983 * @gstdvbsrc: the element on which the signal is emitted
985 * Signal emited when the tunner has successfully got a lock on a signal.
987 gst_dvbsrc_signals[SIGNAL_TUNING_DONE] =
988 g_signal_new ("tuning-done", G_TYPE_FROM_CLASS (klass),
989 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
991 * GstDvbSrc::tuning-fail:
992 * @gstdvbsrc: the element on which the signal is emitted
994 * Signal emited when the tunner failed to get a lock on the
997 gst_dvbsrc_signals[SIGNAL_TUNING_FAIL] =
998 g_signal_new ("tuning-fail", G_TYPE_FROM_CLASS (klass),
999 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
1003 * @gstdvbsrc: the element on which the signal is emitted
1005 * Signal emited from the application to the element, instructing it
1008 gst_dvbsrc_signals[SIGNAL_TUNE] =
1009 g_signal_new ("tune", G_TYPE_FROM_CLASS (klass),
1010 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1011 G_STRUCT_OFFSET (GstDvbSrcClass, do_tune),
1012 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
1016 /* initialize the new element
1017 * instantiate pads and add them to element
1019 * initialize structure
1022 gst_dvbsrc_init (GstDvbSrc * object)
1025 const gchar *adapter;
1027 GST_DEBUG_OBJECT (object, "Kernel DVB API version %d.%d", DVB_API_VERSION,
1028 DVB_API_VERSION_MINOR);
1030 /* We are a live source */
1031 gst_base_src_set_live (GST_BASE_SRC (object), TRUE);
1032 /* And we wanted timestamped output */
1033 gst_base_src_set_do_timestamp (GST_BASE_SRC (object), TRUE);
1034 gst_base_src_set_format (GST_BASE_SRC (object), GST_FORMAT_TIME);
1036 object->fd_frontend = -1;
1037 object->fd_dvr = -1;
1038 object->supported_delsys = NULL;
1040 for (i = 0; i < MAX_FILTERS; i++) {
1041 object->fd_filters[i] = -1;
1044 /* PID 8192 on DVB gets the whole transport stream */
1045 object->pids[0] = 8192;
1046 object->pids[1] = G_MAXUINT16;
1047 object->dvb_buffer_size = DEFAULT_DVB_BUFFER_SIZE;
1049 adapter = g_getenv ("GST_DVB_ADAPTER");
1051 object->adapter_number = atoi (adapter);
1053 object->adapter_number = DEFAULT_ADAPTER;
1055 object->frontend_number = DEFAULT_FRONTEND;
1056 object->diseqc_src = DEFAULT_DISEQC_SRC;
1057 object->send_diseqc = (DEFAULT_DISEQC_SRC != -1);
1058 object->tone = SEC_TONE_OFF;
1059 /* object->pol = DVB_POL_H; *//* set via G_PARAM_CONSTRUCT */
1060 object->sym_rate = DEFAULT_SYMBOL_RATE;
1061 object->bandwidth = DEFAULT_BANDWIDTH;
1062 object->code_rate_hp = DEFAULT_CODE_RATE_HP;
1063 object->code_rate_lp = DEFAULT_CODE_RATE_LP;
1064 object->guard_interval = DEFAULT_GUARD;
1065 object->modulation = DEFAULT_MODULATION;
1066 object->transmission_mode = DEFAULT_TRANSMISSION_MODE;
1067 object->hierarchy_information = DEFAULT_HIERARCHY;
1068 object->inversion = DEFAULT_INVERSION;
1069 object->stats_interval = DEFAULT_STATS_REPORTING_INTERVAL;
1070 object->delsys = DEFAULT_DELSYS;
1071 object->pilot = DEFAULT_PILOT;
1072 object->rolloff = DEFAULT_ROLLOFF;
1073 object->stream_id = DEFAULT_STREAM_ID;
1075 object->isdbt_layer_enabled = DEFAULT_ISDBT_LAYER_ENABLED;
1076 object->isdbt_partial_reception = DEFAULT_ISDBT_PARTIAL_RECEPTION;
1077 object->isdbt_sound_broadcasting = DEFAULT_ISDBT_SOUND_BROADCASTING;
1078 object->isdbt_sb_subchannel_id = DEFAULT_ISDBT_SB_SUBCHANNEL_ID;
1079 object->isdbt_sb_segment_idx = DEFAULT_ISDBT_SB_SEGMENT_IDX;
1080 object->isdbt_sb_segment_count = DEFAULT_ISDBT_SB_SEGMENT_COUNT;
1081 object->isdbt_layera_fec = DEFAULT_ISDBT_LAYERA_FEC;
1082 object->isdbt_layera_modulation = DEFAULT_ISDBT_LAYERA_MODULATION;
1083 object->isdbt_layera_segment_count = DEFAULT_ISDBT_LAYERA_SEGMENT_COUNT;
1084 object->isdbt_layera_time_interleaving =
1085 DEFAULT_ISDBT_LAYERA_TIME_INTERLEAVING;
1086 object->isdbt_layerb_fec = DEFAULT_ISDBT_LAYERB_FEC;
1087 object->isdbt_layerb_modulation = DEFAULT_ISDBT_LAYERB_MODULATION;
1088 object->isdbt_layerb_segment_count = DEFAULT_ISDBT_LAYERB_SEGMENT_COUNT;
1089 object->isdbt_layerb_time_interleaving =
1090 DEFAULT_ISDBT_LAYERB_TIME_INTERLEAVING;
1091 object->isdbt_layerc_fec = DEFAULT_ISDBT_LAYERC_FEC;
1092 object->isdbt_layerc_modulation = DEFAULT_ISDBT_LAYERC_MODULATION;
1093 object->isdbt_layerc_segment_count = DEFAULT_ISDBT_LAYERC_SEGMENT_COUNT;
1094 object->isdbt_layerc_time_interleaving =
1095 DEFAULT_ISDBT_LAYERC_TIME_INTERLEAVING;
1097 object->lnb_slof = DEFAULT_LNB_SLOF;
1098 object->lnb_lof1 = DEFAULT_LNB_LOF1;
1099 object->lnb_lof2 = DEFAULT_LNB_LOF2;
1101 object->interleaving = DEFAULT_INTERLEAVING;
1103 g_mutex_init (&object->tune_mutex);
1104 object->timeout = DEFAULT_TIMEOUT;
1105 object->tuning_timeout = DEFAULT_TUNING_TIMEOUT;
1109 gst_dvbsrc_set_pids (GstDvbSrc * dvbsrc, const gchar * pid_string)
1116 if (!strcmp (pid_string, "8192")) {
1117 /* get the whole TS */
1118 dvbsrc->pids[0] = 8192;
1119 dvbsrc->pids[1] = G_MAXUINT16;
1123 /* always add the PAT and CAT pids */
1124 dvbsrc->pids[0] = 0;
1125 dvbsrc->pids[1] = 1;
1128 tmp = pids = g_strsplit (pid_string, ":", MAX_FILTERS);
1130 while (*pids != NULL && pid_count < MAX_FILTERS) {
1131 pid = strtol (*pids, NULL, 0);
1132 if (pid > 1 && pid <= 8192) {
1133 GST_INFO_OBJECT (dvbsrc, "Parsed PID: %d", pid);
1134 dvbsrc->pids[pid_count] = pid;
1142 if (pid_count < MAX_FILTERS)
1143 dvbsrc->pids[pid_count] = G_MAXUINT16;
1146 if (GST_ELEMENT (dvbsrc)->current_state > GST_STATE_READY) {
1147 GST_INFO_OBJECT (dvbsrc, "Setting PES filters now");
1148 gst_dvbsrc_set_pes_filters (dvbsrc);
1150 GST_INFO_OBJECT (dvbsrc, "Not setting PES filters because state < PAUSED");
1154 gst_dvbsrc_set_property (GObject * _object, guint prop_id,
1155 const GValue * value, GParamSpec * pspec)
1159 g_return_if_fail (GST_IS_DVBSRC (_object));
1160 object = GST_DVBSRC (_object);
1163 case ARG_DVBSRC_ADAPTER:
1164 object->adapter_number = g_value_get_int (value);
1166 case ARG_DVBSRC_FRONTEND:
1167 object->frontend_number = g_value_get_int (value);
1169 case ARG_DVBSRC_DISEQC_SRC:
1170 if (object->diseqc_src != g_value_get_int (value)) {
1171 object->diseqc_src = g_value_get_int (value);
1172 object->send_diseqc = TRUE;
1174 GST_INFO_OBJECT (object, "Set Property: ARG_DVBSRC_DISEQC_ID");
1176 case ARG_DVBSRC_FREQUENCY:
1177 object->freq = g_value_get_uint (value);
1178 GST_INFO_OBJECT (object, "Set Property: ARG_DVBSRC_FREQUENCY (%d Hz)",
1181 case ARG_DVBSRC_POLARITY:
1183 const char *s = NULL;
1185 s = g_value_get_string (value);
1187 object->pol = (s[0] == 'h' || s[0] == 'H') ? DVB_POL_H : DVB_POL_V;
1188 GST_INFO_OBJECT (object, "Set Property: ARG_DVBSRC_POLARITY to %s",
1189 object->pol ? "Vertical" : "Horizontal");
1193 case ARG_DVBSRC_PIDS:
1195 const gchar *pid_string;
1197 pid_string = g_value_get_string (value);
1198 GST_INFO_OBJECT (object, "Set Property: ARG_DVBSRC_PIDS %s", pid_string);
1200 gst_dvbsrc_set_pids (object, pid_string);
1203 case ARG_DVBSRC_SYM_RATE:
1204 object->sym_rate = g_value_get_uint (value);
1205 GST_INFO_OBJECT (object, "Set Property: ARG_DVBSRC_SYM_RATE to value %d",
1209 case ARG_DVBSRC_BANDWIDTH_HZ:
1210 object->bandwidth = g_value_get_uint (value);
1212 case ARG_DVBSRC_BANDWIDTH:
1213 switch (g_value_get_enum (value)) {
1214 case BANDWIDTH_8_MHZ:
1215 object->bandwidth = 8000000;
1217 case BANDWIDTH_7_MHZ:
1218 object->bandwidth = 7000000;
1220 case BANDWIDTH_6_MHZ:
1221 object->bandwidth = 6000000;
1223 case BANDWIDTH_5_MHZ:
1224 object->bandwidth = 5000000;
1226 case BANDWIDTH_10_MHZ:
1227 object->bandwidth = 10000000;
1229 case BANDWIDTH_1_712_MHZ:
1230 object->bandwidth = 1712000;
1233 /* we don't know which bandwidth is set */
1234 object->bandwidth = 0;
1238 case ARG_DVBSRC_CODE_RATE_HP:
1239 object->code_rate_hp = g_value_get_enum (value);
1241 case ARG_DVBSRC_CODE_RATE_LP:
1242 object->code_rate_lp = g_value_get_enum (value);
1244 case ARG_DVBSRC_GUARD:
1245 object->guard_interval = g_value_get_enum (value);
1247 case ARG_DVBSRC_MODULATION:
1248 object->modulation = g_value_get_enum (value);
1250 case ARG_DVBSRC_TRANSMISSION_MODE:
1251 object->transmission_mode = g_value_get_enum (value);
1253 case ARG_DVBSRC_HIERARCHY_INF:
1254 object->hierarchy_information = g_value_get_enum (value);
1256 case ARG_DVBSRC_INVERSION:
1257 object->inversion = g_value_get_enum (value);
1259 case ARG_DVBSRC_TUNE:
1260 GST_INFO_OBJECT (object, "Set Property: ARG_DVBSRC_TUNE");
1261 gst_dvbsrc_do_tune (object);
1263 case ARG_DVBSRC_STATS_REPORTING_INTERVAL:
1264 object->stats_interval = g_value_get_uint (value);
1265 object->stats_counter = 0;
1267 case ARG_DVBSRC_TIMEOUT:
1268 object->timeout = g_value_get_uint64 (value);
1270 case ARG_DVBSRC_TUNING_TIMEOUT:
1271 object->tuning_timeout = g_value_get_uint64 (value);
1273 case ARG_DVBSRC_DVB_BUFFER_SIZE:
1274 object->dvb_buffer_size = g_value_get_uint (value);
1276 case ARG_DVBSRC_DELSYS:
1277 object->delsys = g_value_get_enum (value);
1279 case ARG_DVBSRC_PILOT:
1280 object->pilot = g_value_get_enum (value);
1282 case ARG_DVBSRC_ROLLOFF:
1283 object->rolloff = g_value_get_enum (value);
1285 case ARG_DVBSRC_STREAM_ID:
1286 object->stream_id = g_value_get_int (value);
1288 case ARG_DVBSRC_ISDBT_LAYER_ENABLED:
1289 object->isdbt_layer_enabled = g_value_get_uint (value);
1291 case ARG_DVBSRC_ISDBT_PARTIAL_RECEPTION:
1292 object->isdbt_partial_reception = g_value_get_int (value);
1294 case ARG_DVBSRC_ISDBT_SOUND_BROADCASTING:
1295 object->isdbt_sound_broadcasting = g_value_get_int (value);
1297 case ARG_DVBSRC_ISDBT_SB_SUBCHANNEL_ID:
1298 object->isdbt_sb_subchannel_id = g_value_get_int (value);
1300 case ARG_DVBSRC_ISDBT_SB_SEGMENT_IDX:
1301 object->isdbt_sb_segment_idx = g_value_get_int (value);
1303 case ARG_DVBSRC_ISDBT_SB_SEGMENT_COUNT:
1304 object->isdbt_sb_segment_count = g_value_get_uint (value);
1306 case ARG_DVBSRC_ISDBT_LAYERA_FEC:
1307 object->isdbt_layera_fec = g_value_get_enum (value);
1309 case ARG_DVBSRC_ISDBT_LAYERA_MODULATION:
1310 object->isdbt_layera_modulation = g_value_get_enum (value);
1312 case ARG_DVBSRC_ISDBT_LAYERA_SEGMENT_COUNT:
1313 object->isdbt_layera_segment_count = g_value_get_int (value);
1315 case ARG_DVBSRC_ISDBT_LAYERA_TIME_INTERLEAVING:
1316 object->isdbt_layera_time_interleaving = g_value_get_int (value);
1318 case ARG_DVBSRC_ISDBT_LAYERB_FEC:
1319 object->isdbt_layerb_fec = g_value_get_enum (value);
1321 case ARG_DVBSRC_ISDBT_LAYERB_MODULATION:
1322 object->isdbt_layerb_modulation = g_value_get_enum (value);
1324 case ARG_DVBSRC_ISDBT_LAYERB_SEGMENT_COUNT:
1325 object->isdbt_layerb_segment_count = g_value_get_int (value);
1327 case ARG_DVBSRC_ISDBT_LAYERB_TIME_INTERLEAVING:
1328 object->isdbt_layerb_time_interleaving = g_value_get_int (value);
1330 case ARG_DVBSRC_ISDBT_LAYERC_FEC:
1331 object->isdbt_layerc_fec = g_value_get_enum (value);
1333 case ARG_DVBSRC_ISDBT_LAYERC_MODULATION:
1334 object->isdbt_layerc_modulation = g_value_get_enum (value);
1336 case ARG_DVBSRC_ISDBT_LAYERC_SEGMENT_COUNT:
1337 object->isdbt_layerc_segment_count = g_value_get_int (value);
1339 case ARG_DVBSRC_ISDBT_LAYERC_TIME_INTERLEAVING:
1340 object->isdbt_layerc_time_interleaving = g_value_get_int (value);
1342 case ARG_DVBSRC_LNB_SLOF:
1343 object->lnb_slof = g_value_get_uint (value);
1345 case ARG_DVBSRC_LNB_LOF1:
1346 object->lnb_lof1 = g_value_get_uint (value);
1348 case ARG_DVBSRC_LNB_LOF2:
1349 object->lnb_lof2 = g_value_get_uint (value);
1351 case ARG_DVBSRC_INTERLEAVING:
1352 object->interleaving = g_value_get_enum (value);
1355 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1360 gst_dvbsrc_get_property (GObject * _object, guint prop_id,
1361 GValue * value, GParamSpec * pspec)
1365 g_return_if_fail (GST_IS_DVBSRC (_object));
1366 object = GST_DVBSRC (_object);
1369 case ARG_DVBSRC_ADAPTER:
1370 g_value_set_int (value, object->adapter_number);
1372 case ARG_DVBSRC_FRONTEND:
1373 g_value_set_int (value, object->frontend_number);
1375 case ARG_DVBSRC_FREQUENCY:
1376 g_value_set_uint (value, object->freq);
1378 case ARG_DVBSRC_POLARITY:
1379 if (object->pol == DVB_POL_H)
1380 g_value_set_static_string (value, "H");
1382 g_value_set_static_string (value, "V");
1384 case ARG_DVBSRC_SYM_RATE:
1385 g_value_set_uint (value, object->sym_rate);
1387 case ARG_DVBSRC_DISEQC_SRC:
1388 g_value_set_int (value, object->diseqc_src);
1390 case ARG_DVBSRC_BANDWIDTH_HZ:
1391 g_value_set_uint (value, object->bandwidth);
1393 case ARG_DVBSRC_BANDWIDTH:{
1395 if (!object->bandwidth)
1396 tmp = BANDWIDTH_AUTO;
1397 else if (object->bandwidth <= 1712000)
1398 tmp = BANDWIDTH_1_712_MHZ;
1399 else if (object->bandwidth <= 5000000)
1400 tmp = BANDWIDTH_5_MHZ;
1401 else if (object->bandwidth <= 6000000)
1402 tmp = BANDWIDTH_6_MHZ;
1403 else if (object->bandwidth <= 7000000)
1404 tmp = BANDWIDTH_7_MHZ;
1405 else if (object->bandwidth <= 8000000)
1406 tmp = BANDWIDTH_8_MHZ;
1407 else if (object->bandwidth <= 10000000)
1408 tmp = BANDWIDTH_10_MHZ;
1410 tmp = BANDWIDTH_AUTO;
1412 g_value_set_enum (value, tmp);
1415 case ARG_DVBSRC_CODE_RATE_HP:
1416 g_value_set_enum (value, object->code_rate_hp);
1418 case ARG_DVBSRC_CODE_RATE_LP:
1419 g_value_set_enum (value, object->code_rate_lp);
1421 case ARG_DVBSRC_GUARD:
1422 g_value_set_enum (value, object->guard_interval);
1424 case ARG_DVBSRC_MODULATION:
1425 g_value_set_enum (value, object->modulation);
1427 case ARG_DVBSRC_TRANSMISSION_MODE:
1428 g_value_set_enum (value, object->transmission_mode);
1430 case ARG_DVBSRC_HIERARCHY_INF:
1431 g_value_set_enum (value, object->hierarchy_information);
1433 case ARG_DVBSRC_INVERSION:
1434 g_value_set_enum (value, object->inversion);
1436 case ARG_DVBSRC_STATS_REPORTING_INTERVAL:
1437 g_value_set_uint (value, object->stats_interval);
1439 case ARG_DVBSRC_TIMEOUT:
1440 g_value_set_uint64 (value, object->timeout);
1442 case ARG_DVBSRC_TUNING_TIMEOUT:
1443 g_value_set_uint64 (value, object->tuning_timeout);
1445 case ARG_DVBSRC_DVB_BUFFER_SIZE:
1446 g_value_set_uint (value, object->dvb_buffer_size);
1448 case ARG_DVBSRC_DELSYS:
1449 g_value_set_enum (value, object->delsys);
1451 case ARG_DVBSRC_PILOT:
1452 g_value_set_enum (value, object->pilot);
1454 case ARG_DVBSRC_ROLLOFF:
1455 g_value_set_enum (value, object->rolloff);
1457 case ARG_DVBSRC_STREAM_ID:
1458 g_value_set_int (value, object->stream_id);
1460 case ARG_DVBSRC_ISDBT_LAYER_ENABLED:
1461 g_value_set_uint (value, object->isdbt_layer_enabled);
1463 case ARG_DVBSRC_ISDBT_PARTIAL_RECEPTION:
1464 g_value_set_int (value, object->isdbt_partial_reception);
1466 case ARG_DVBSRC_ISDBT_SOUND_BROADCASTING:
1467 g_value_set_int (value, object->isdbt_sound_broadcasting);
1469 case ARG_DVBSRC_ISDBT_SB_SUBCHANNEL_ID:
1470 g_value_set_int (value, object->isdbt_sb_subchannel_id);
1472 case ARG_DVBSRC_ISDBT_SB_SEGMENT_IDX:
1473 g_value_set_int (value, object->isdbt_sb_segment_idx);
1475 case ARG_DVBSRC_ISDBT_SB_SEGMENT_COUNT:
1476 g_value_set_uint (value, object->isdbt_sb_segment_count);
1478 case ARG_DVBSRC_ISDBT_LAYERA_FEC:
1479 g_value_set_enum (value, object->isdbt_layera_fec);
1481 case ARG_DVBSRC_ISDBT_LAYERA_MODULATION:
1482 g_value_set_enum (value, object->isdbt_layera_modulation);
1484 case ARG_DVBSRC_ISDBT_LAYERA_SEGMENT_COUNT:
1485 g_value_set_int (value, object->isdbt_layera_segment_count);
1487 case ARG_DVBSRC_ISDBT_LAYERA_TIME_INTERLEAVING:
1488 g_value_set_int (value, object->isdbt_layera_time_interleaving);
1490 case ARG_DVBSRC_ISDBT_LAYERB_FEC:
1491 g_value_set_enum (value, object->isdbt_layerb_fec);
1493 case ARG_DVBSRC_ISDBT_LAYERB_MODULATION:
1494 g_value_set_enum (value, object->isdbt_layerb_modulation);
1496 case ARG_DVBSRC_ISDBT_LAYERB_SEGMENT_COUNT:
1497 g_value_set_int (value, object->isdbt_layerb_segment_count);
1499 case ARG_DVBSRC_ISDBT_LAYERB_TIME_INTERLEAVING:
1500 g_value_set_int (value, object->isdbt_layerb_time_interleaving);
1502 case ARG_DVBSRC_ISDBT_LAYERC_FEC:
1503 g_value_set_enum (value, object->isdbt_layerc_fec);
1505 case ARG_DVBSRC_ISDBT_LAYERC_MODULATION:
1506 g_value_set_enum (value, object->isdbt_layerc_modulation);
1508 case ARG_DVBSRC_ISDBT_LAYERC_SEGMENT_COUNT:
1509 g_value_set_int (value, object->isdbt_layerc_segment_count);
1511 case ARG_DVBSRC_ISDBT_LAYERC_TIME_INTERLEAVING:
1512 g_value_set_int (value, object->isdbt_layerc_time_interleaving);
1514 case ARG_DVBSRC_LNB_SLOF:
1515 g_value_set_uint (value, object->lnb_slof);
1517 case ARG_DVBSRC_LNB_LOF1:
1518 g_value_set_uint (value, object->lnb_lof1);
1520 case ARG_DVBSRC_LNB_LOF2:
1521 g_value_set_uint (value, object->lnb_lof2);
1523 case ARG_DVBSRC_INTERLEAVING:
1524 g_value_set_enum (value, object->interleaving);
1527 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1532 gst_dvbsrc_close_devices (GstDvbSrc * object)
1534 gst_dvbsrc_unset_pes_filters (object);
1536 close (object->fd_dvr);
1537 object->fd_dvr = -1;
1538 close (object->fd_frontend);
1539 object->fd_frontend = -1;
1545 gst_dvbsrc_check_delsys (struct dtv_property *prop, guchar delsys)
1549 for (i = 0; i < prop->u.buffer.len; i++) {
1550 if (prop->u.buffer.data[i] == delsys)
1553 GST_LOG ("Adapter does not support delsys: %d", delsys);
1558 gst_dvbsrc_open_frontend (GstDvbSrc * object, gboolean writable)
1560 struct dvb_frontend_info fe_info;
1561 struct dtv_properties props;
1562 struct dtv_property dvb_prop[1];
1563 gchar *frontend_dev;
1564 GstStructure *adapter_structure;
1565 char *adapter_name = NULL;
1568 frontend_dev = g_strdup_printf ("/dev/dvb/adapter%d/frontend%d",
1569 object->adapter_number, object->frontend_number);
1570 GST_INFO_OBJECT (object, "Using frontend device: %s", frontend_dev);
1573 LOOP_WHILE_EINTR (object->fd_frontend,
1574 open (frontend_dev, writable ? O_RDWR : O_RDONLY));
1575 if (object->fd_frontend < 0) {
1578 GST_ELEMENT_ERROR (object, RESOURCE, NOT_FOUND,
1579 (_("Device \"%s\" does not exist."), frontend_dev), (NULL));
1582 GST_ELEMENT_ERROR (object, RESOURCE, OPEN_READ_WRITE,
1583 (_("Could not open frontend device \"%s\"."), frontend_dev),
1588 g_free (frontend_dev);
1592 if (object->supported_delsys)
1593 goto delsys_detection_done;
1595 /* Perform delivery system autodetection */
1597 GST_DEBUG_OBJECT (object, "Device opened, querying information");
1599 LOOP_WHILE_EINTR (err, ioctl (object->fd_frontend, FE_GET_INFO, &fe_info));
1601 GST_ELEMENT_ERROR (object, RESOURCE, SETTINGS,
1602 (_("Could not get settings from frontend device \"%s\"."),
1603 frontend_dev), GST_ERROR_SYSTEM);
1605 close (object->fd_frontend);
1606 g_free (frontend_dev);
1610 GST_DEBUG_OBJECT (object, "Get list of supported delivery systems");
1612 dvb_prop[0].cmd = DTV_ENUM_DELSYS;
1614 props.props = dvb_prop;
1616 LOOP_WHILE_EINTR (err, ioctl (object->fd_frontend, FE_GET_PROPERTY, &props));
1618 GST_ELEMENT_ERROR (object, RESOURCE, SETTINGS,
1619 (_("Cannot enumerate delivery systems from frontend device \"%s\"."),
1620 frontend_dev), GST_ERROR_SYSTEM);
1622 close (object->fd_frontend);
1623 g_free (frontend_dev);
1627 GST_INFO_OBJECT (object, "Got information about adapter: %s", fe_info.name);
1629 adapter_name = g_strdup (fe_info.name);
1631 adapter_structure = gst_structure_new ("dvb-adapter",
1632 "name", G_TYPE_STRING, adapter_name,
1633 /* Capability supported auto params */
1634 "auto-inversion", G_TYPE_BOOLEAN, fe_info.caps & FE_CAN_INVERSION_AUTO,
1635 "auto-qam", G_TYPE_BOOLEAN, fe_info.caps & FE_CAN_QAM_AUTO,
1636 "auto-transmission-mode", G_TYPE_BOOLEAN,
1637 fe_info.caps & FE_CAN_TRANSMISSION_MODE_AUTO, "auto-guard-interval",
1638 G_TYPE_BOOLEAN, fe_info.caps & FE_CAN_GUARD_INTERVAL_AUTO,
1639 "auto-hierarchy", G_TYPE_BOOLEAN, fe_info.caps & FE_CAN_HIERARCHY_AUTO,
1640 "auto-fec", G_TYPE_BOOLEAN, fe_info.caps & FE_CAN_FEC_AUTO, NULL);
1642 /* Capability delivery systems */
1643 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_DVBC_ANNEX_A)) {
1644 object->supported_delsys = g_list_append (object->supported_delsys,
1645 GINT_TO_POINTER (SYS_DVBC_ANNEX_A));
1646 gst_structure_set (adapter_structure, "dvb-c-a", G_TYPE_STRING,
1647 "DVB-C ANNEX A", NULL);
1650 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_DVBC_ANNEX_B)) {
1651 object->supported_delsys = g_list_append (object->supported_delsys,
1652 GINT_TO_POINTER (SYS_DVBC_ANNEX_B));
1653 gst_structure_set (adapter_structure, "dvb-c-b", G_TYPE_STRING,
1654 "DVB-C ANNEX B", NULL);
1657 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_DVBT)) {
1658 object->supported_delsys = g_list_append (object->supported_delsys,
1659 GINT_TO_POINTER (SYS_DVBT));
1660 gst_structure_set (adapter_structure, "dvb-t", G_TYPE_STRING, "DVB-T",
1664 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_DSS)) {
1665 object->supported_delsys = g_list_append (object->supported_delsys,
1666 GINT_TO_POINTER (SYS_DSS));
1667 gst_structure_set (adapter_structure, "dss", G_TYPE_STRING, "DSS", NULL);
1670 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_DVBS)) {
1671 object->supported_delsys = g_list_append (object->supported_delsys,
1672 GINT_TO_POINTER (SYS_DVBS));
1673 gst_structure_set (adapter_structure, "dvb-s", G_TYPE_STRING, "DVB-S",
1677 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_DVBS2)) {
1678 object->supported_delsys = g_list_append (object->supported_delsys,
1679 GINT_TO_POINTER (SYS_DVBS2));
1680 gst_structure_set (adapter_structure, "dvb-s2", G_TYPE_STRING, "DVB-S2",
1684 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_DVBH)) {
1685 object->supported_delsys = g_list_append (object->supported_delsys,
1686 GINT_TO_POINTER (SYS_DVBH));
1687 gst_structure_set (adapter_structure, "dvb-h", G_TYPE_STRING, "DVB-H",
1691 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_ISDBT)) {
1692 object->supported_delsys = g_list_append (object->supported_delsys,
1693 GINT_TO_POINTER (SYS_ISDBT));
1694 gst_structure_set (adapter_structure, "isdb-t", G_TYPE_STRING, "ISDB-T",
1698 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_ISDBS)) {
1699 object->supported_delsys = g_list_append (object->supported_delsys,
1700 GINT_TO_POINTER (SYS_ISDBS));
1701 gst_structure_set (adapter_structure, "isdb-s", G_TYPE_STRING, "ISDB-S",
1705 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_ISDBC)) {
1706 object->supported_delsys = g_list_append (object->supported_delsys,
1707 GINT_TO_POINTER (SYS_ISDBC));
1708 gst_structure_set (adapter_structure, "isdb-c", G_TYPE_STRING, "ISDB-C",
1712 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_ATSC)) {
1713 object->supported_delsys = g_list_append (object->supported_delsys,
1714 GINT_TO_POINTER (SYS_ATSC));
1715 gst_structure_set (adapter_structure, "atsc", G_TYPE_STRING, "ATSC", NULL);
1718 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_ATSCMH)) {
1719 object->supported_delsys = g_list_append (object->supported_delsys,
1720 GINT_TO_POINTER (SYS_ATSCMH));
1721 gst_structure_set (adapter_structure, "atsc-mh", G_TYPE_STRING, "ATSC-MH",
1724 #if HAVE_V5_MINOR(7)
1725 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_DTMB)) {
1726 object->supported_delsys = g_list_append (object->supported_delsys,
1727 GINT_TO_POINTER (SYS_DTMB));
1728 gst_structure_set (adapter_structure, "dtmb", G_TYPE_STRING, "DTMB", NULL);
1732 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_CMMB)) {
1733 object->supported_delsys = g_list_append (object->supported_delsys,
1734 GINT_TO_POINTER (SYS_CMMB));
1735 gst_structure_set (adapter_structure, "cmmb", G_TYPE_STRING, "CMMB", NULL);
1738 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_DAB)) {
1739 object->supported_delsys = g_list_append (object->supported_delsys,
1740 GINT_TO_POINTER (SYS_DAB));
1741 gst_structure_set (adapter_structure, "dab", G_TYPE_STRING, "DAB", NULL);
1744 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_DVBT2)) {
1745 object->supported_delsys = g_list_append (object->supported_delsys,
1746 GINT_TO_POINTER (SYS_DVBT2));
1747 gst_structure_set (adapter_structure, "dvb-t2", G_TYPE_STRING, "DVB-T2",
1751 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_TURBO)) {
1752 object->supported_delsys = g_list_append (object->supported_delsys,
1753 GINT_TO_POINTER (SYS_TURBO));
1754 gst_structure_set (adapter_structure, "turbo", G_TYPE_STRING, "TURBO",
1757 #if HAVE_V5_MINOR(6)
1758 if (gst_dvbsrc_check_delsys (&dvb_prop[0], SYS_DVBC_ANNEX_C)) {
1759 object->supported_delsys = g_list_append (object->supported_delsys,
1760 GINT_TO_POINTER (SYS_DVBC_ANNEX_C));
1761 gst_structure_set (adapter_structure, "dvb-c-c", G_TYPE_STRING,
1762 "DVB-C ANNEX C", NULL);
1766 GST_TRACE_OBJECT (object, "%s description: %" GST_PTR_FORMAT, adapter_name,
1768 gst_element_post_message (GST_ELEMENT_CAST (object), gst_message_new_element
1769 (GST_OBJECT (object), adapter_structure));
1770 g_free (adapter_name);
1772 delsys_detection_done:
1773 g_free (frontend_dev);
1779 gst_dvbsrc_open_dvr (GstDvbSrc * object)
1784 dvr_dev = g_strdup_printf ("/dev/dvb/adapter%d/dvr%d",
1785 object->adapter_number, object->frontend_number);
1786 GST_INFO_OBJECT (object, "Using DVR device: %s", dvr_dev);
1789 if ((object->fd_dvr = open (dvr_dev, O_RDONLY | O_NONBLOCK)) < 0) {
1792 GST_ELEMENT_ERROR (object, RESOURCE, NOT_FOUND,
1793 (_("Device \"%s\" does not exist."), dvr_dev), (NULL));
1796 GST_ELEMENT_ERROR (object, RESOURCE, OPEN_READ,
1797 (_("Could not open file \"%s\" for reading."), dvr_dev),
1806 GST_INFO_OBJECT (object, "Setting DVB kernel buffer size to %d",
1807 object->dvb_buffer_size);
1808 LOOP_WHILE_EINTR (err, ioctl (object->fd_dvr, DMX_SET_BUFFER_SIZE,
1809 object->dvb_buffer_size));
1811 GST_INFO_OBJECT (object, "ioctl DMX_SET_BUFFER_SIZE failed (%d)", errno);
1818 gst_dvbsrc_finalize (GObject * _object)
1822 GST_DEBUG_OBJECT (_object, "gst_dvbsrc_finalize");
1824 g_return_if_fail (GST_IS_DVBSRC (_object));
1825 object = GST_DVBSRC (_object);
1827 /* freeing the mutex segfaults somehow */
1828 g_mutex_clear (&object->tune_mutex);
1830 if (G_OBJECT_CLASS (parent_class)->finalize)
1831 G_OBJECT_CLASS (parent_class)->finalize (_object);
1836 ******************************
1838 * Plugin Realization *
1840 ******************************
1845 /* entry point to initialize the plug-in
1846 * initialize the plug-in itself
1847 * register the element factories and pad templates
1848 * register the features
1851 gst_dvbsrc_plugin_init (GstPlugin * plugin)
1853 GST_DEBUG_CATEGORY_INIT (gstdvbsrc_debug, "dvbsrc", 0, "DVB Source Element");
1855 return gst_element_register (plugin, "dvbsrc", GST_RANK_NONE,
1859 static GstFlowReturn
1860 gst_dvbsrc_read_device (GstDvbSrc * object, int size, GstBuffer ** buffer)
1864 GstBuffer *buf = gst_buffer_new_and_alloc (size);
1865 GstClockTime timeout = object->timeout * GST_USECOND;
1868 g_return_val_if_fail (GST_IS_BUFFER (buf), GST_FLOW_ERROR);
1870 if (object->fd_dvr < 0)
1871 return GST_FLOW_ERROR;
1873 gst_buffer_map (buf, &map, GST_MAP_WRITE);
1874 while (count < size) {
1875 ret_val = gst_poll_wait (object->poll, timeout);
1876 GST_LOG_OBJECT (object, "select returned %d", ret_val);
1877 if (G_UNLIKELY (ret_val < 0)) {
1880 else if (errno == EINTR)
1884 } else if (G_UNLIKELY (!ret_val)) {
1885 /* timeout, post element message */
1886 gst_element_post_message (GST_ELEMENT_CAST (object),
1887 gst_message_new_element (GST_OBJECT (object),
1888 gst_structure_new_empty ("dvb-read-failure")));
1890 int nread = read (object->fd_dvr, map.data + count, size - count);
1892 if (G_UNLIKELY (nread < 0)) {
1895 "Unable to read from device: /dev/dvb/adapter%d/dvr%d (%d)",
1896 object->adapter_number, object->frontend_number, errno);
1897 gst_element_post_message (GST_ELEMENT_CAST (object),
1898 gst_message_new_element (GST_OBJECT (object),
1899 gst_structure_new_empty ("dvb-read-failure")));
1901 count = count + nread;
1904 gst_buffer_unmap (buf, &map);
1905 gst_buffer_resize (buf, 0, count);
1913 GST_DEBUG_OBJECT (object, "stop called");
1914 gst_buffer_unmap (buf, &map);
1915 gst_buffer_unref (buf);
1916 return GST_FLOW_FLUSHING;
1920 GST_ELEMENT_ERROR (object, RESOURCE, READ, (NULL),
1921 ("select error %d: %s (%d)", ret_val, g_strerror (errno), errno));
1922 gst_buffer_unmap (buf, &map);
1923 gst_buffer_unref (buf);
1924 return GST_FLOW_ERROR;
1928 static GstFlowReturn
1929 gst_dvbsrc_create (GstPushSrc * element, GstBuffer ** buf)
1932 GstFlowReturn retval = GST_FLOW_ERROR;
1935 object = GST_DVBSRC (element);
1936 GST_LOG ("fd_dvr: %d", object->fd_dvr);
1938 buffer_size = DEFAULT_BUFFER_SIZE;
1940 /* device can not be tuned during read */
1941 g_mutex_lock (&object->tune_mutex);
1944 if (object->fd_dvr > -1) {
1945 /* --- Read TS from DVR device --- */
1946 GST_DEBUG_OBJECT (object, "Reading from DVR device");
1947 retval = gst_dvbsrc_read_device (object, buffer_size, buf);
1949 if (object->stats_interval &&
1950 ++object->stats_counter == object->stats_interval) {
1951 gst_dvbsrc_output_frontend_stats (object);
1952 object->stats_counter = 0;
1956 g_mutex_unlock (&object->tune_mutex);
1962 static GstStateChangeReturn
1963 gst_dvbsrc_change_state (GstElement * element, GstStateChange transition)
1966 GstStateChangeReturn ret;
1968 src = GST_DVBSRC (element);
1969 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1971 switch (transition) {
1972 case GST_STATE_CHANGE_NULL_TO_READY:
1973 /* open frontend then close it again, just so caps sent */
1974 if (!gst_dvbsrc_open_frontend (src, FALSE)) {
1975 GST_ERROR_OBJECT (src, "Could not open frontend device");
1976 ret = GST_STATE_CHANGE_FAILURE;
1978 if (src->fd_frontend) {
1979 close (src->fd_frontend);
1991 gst_dvbsrc_start (GstBaseSrc * bsrc)
1993 GstDvbSrc *src = GST_DVBSRC (bsrc);
1995 if (!gst_dvbsrc_open_frontend (src, TRUE)) {
1996 GST_ERROR_OBJECT (src, "Could not open frontend device");
1999 if (!gst_dvbsrc_tune (src)) {
2000 GST_ERROR_OBJECT (src, "Not able to lock on channel");
2003 if (!gst_dvbsrc_open_dvr (src)) {
2004 GST_ERROR_OBJECT (src, "Not able to open DVR device");
2007 if (!(src->poll = gst_poll_new (TRUE))) {
2008 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL),
2009 ("Could not create an fd set: %s (%d)", g_strerror (errno), errno));
2013 gst_poll_fd_init (&src->poll_fd_dvr);
2014 src->poll_fd_dvr.fd = src->fd_dvr;
2015 gst_poll_add_fd (src->poll, &src->poll_fd_dvr);
2016 gst_poll_fd_ctl_read (src->poll, &src->poll_fd_dvr, TRUE);
2021 gst_dvbsrc_unset_pes_filters (src);
2022 close (src->fd_frontend);
2027 gst_dvbsrc_stop (GstBaseSrc * bsrc)
2029 GstDvbSrc *src = GST_DVBSRC (bsrc);
2031 gst_dvbsrc_close_devices (src);
2032 g_list_free (src->supported_delsys);
2033 src->supported_delsys = NULL;
2035 gst_poll_free (src->poll);
2043 gst_dvbsrc_unlock (GstBaseSrc * bsrc)
2045 GstDvbSrc *src = GST_DVBSRC (bsrc);
2047 gst_poll_set_flushing (src->poll, TRUE);
2052 gst_dvbsrc_unlock_stop (GstBaseSrc * bsrc)
2054 GstDvbSrc *src = GST_DVBSRC (bsrc);
2056 gst_poll_set_flushing (src->poll, FALSE);
2061 gst_dvbsrc_is_seekable (GstBaseSrc * bsrc)
2067 gst_dvbsrc_is_valid_trans_mode (guint delsys, guint mode)
2069 /* FIXME: check valid transmission modes for other broadcast standards */
2072 if (mode == TRANSMISSION_MODE_AUTO || mode == TRANSMISSION_MODE_2K ||
2073 mode == TRANSMISSION_MODE_8K) {
2078 if (mode == TRANSMISSION_MODE_AUTO || mode == TRANSMISSION_MODE_1K ||
2079 mode == TRANSMISSION_MODE_2K || mode == TRANSMISSION_MODE_4K ||
2080 mode == TRANSMISSION_MODE_8K || mode == TRANSMISSION_MODE_16K ||
2081 mode == TRANSMISSION_MODE_32K) {
2085 #if HAVE_V5_MINOR(7)
2087 if (mode == TRANSMISSION_MODE_AUTO || mode == TRANSMISSION_MODE_C1 ||
2088 mode == TRANSMISSION_MODE_C3780) {
2094 GST_FIXME ("No transmission-mode sanity checks implemented for this "
2098 GST_WARNING ("Invalid transmission-mode '%d' for delivery system '%d'", mode,
2104 gst_dvbsrc_is_valid_modulation (guint delsys, guint mod)
2106 /* FIXME: check valid modulations for other broadcast standards */
2109 if (mod == QAM_AUTO || mod == QPSK || mod == QAM_16 ||
2110 mod == QAM_64 || mod == DQPSK)
2114 if (mod == VSB_8 || mod == VSB_16)
2118 if (mod == QPSK || mod == QAM_16 || mod == QAM_64)
2122 if (mod == QPSK || mod == QAM_16 || mod == QAM_64 || mod == QAM_256)
2126 GST_FIXME ("No modulation sanity-checks implemented for delivery "
2127 "system: '%d'", delsys);
2130 GST_WARNING ("Invalid modulation '%d' for delivery system '%d'", mod, delsys);
2135 gst_dvbsrc_is_valid_bandwidth (guint delsys, guint bw)
2137 /* FIXME: check valid bandwidth values for other broadcast standards */
2139 /* Bandwidth == 0 means auto, this should be valid for every delivery system
2140 * for which the bandwidth parameter makes sense */
2144 if (bw == 6000000 || bw == 7000000 || bw == 8000000 || bw == 0)
2148 if (bw == 1172000 || bw == 5000000 || bw == 6000000 || bw == 0 ||
2149 bw == 7000000 || bw == 8000000 || bw == 10000000) {
2154 if (bw == 6000000 || bw == 0)
2158 GST_FIXME ("No bandwidth sanity checks implemented for this "
2162 GST_WARNING ("Invalid bandwidth '%d' for delivery system '%d'", bw, delsys);
2167 gst_dvbsrc_get_size (GstBaseSrc * src, guint64 * size)
2173 gst_dvbsrc_do_tune (GstDvbSrc * src)
2175 /* if we are in paused/playing state tune now, otherwise in ready
2176 * to paused state change */
2177 if (GST_STATE (src) > GST_STATE_READY)
2178 gst_dvbsrc_tune (src);
2182 gst_dvbsrc_output_frontend_stats (GstDvbSrc * src)
2185 guint16 snr, signal;
2186 guint32 ber, bad_blks;
2187 GstMessage *message;
2188 GstStructure *structure;
2189 int fe_fd = src->fd_frontend;
2192 LOOP_WHILE_EINTR (err, ioctl (fe_fd, FE_READ_STATUS, &status));
2194 structure = gst_structure_new ("dvb-frontend-stats",
2195 "status", G_TYPE_INT, status,
2196 "lock", G_TYPE_BOOLEAN, status & FE_HAS_LOCK, NULL);
2198 GST_ERROR_OBJECT (src, "Error getting frontend status: '%s'",
2199 g_strerror (errno));
2204 LOOP_WHILE_EINTR (err, ioctl (fe_fd, FE_READ_SIGNAL_STRENGTH, &signal));
2206 gst_structure_set (structure, "signal", G_TYPE_INT, signal, NULL);
2208 LOOP_WHILE_EINTR (err, ioctl (fe_fd, FE_READ_SNR, &snr));
2210 gst_structure_set (structure, "snr", G_TYPE_INT, snr, NULL);
2212 LOOP_WHILE_EINTR (err, ioctl (fe_fd, FE_READ_BER, &ber));
2214 gst_structure_set (structure, "ber", G_TYPE_INT, ber, NULL);
2216 LOOP_WHILE_EINTR (err, ioctl (fe_fd, FE_READ_UNCORRECTED_BLOCKS, &bad_blks));
2218 gst_structure_set (structure, "unc", G_TYPE_INT, bad_blks, NULL);
2221 GST_WARNING_OBJECT (src,
2222 "There were errors getting frontend status information: '%s'",
2223 g_strerror (errno));
2225 GST_INFO_OBJECT (src, "Frontend stats: %" GST_PTR_FORMAT, structure);
2226 message = gst_message_new_element (GST_OBJECT (src), structure);
2227 gst_element_post_message (GST_ELEMENT (src), message);
2231 diseqc_send_msg (int fd, fe_sec_voltage_t v, struct dvb_diseqc_master_cmd *cmd,
2232 fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
2236 LOOP_WHILE_EINTR (err, ioctl (fd, FE_SET_TONE, SEC_TONE_OFF));
2238 GST_ERROR ("Setting tone to off failed");
2242 LOOP_WHILE_EINTR (err, ioctl (fd, FE_SET_VOLTAGE, v));
2244 GST_ERROR ("Setting voltage failed");
2248 g_usleep (15 * 1000);
2249 GST_LOG ("diseqc: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", cmd->msg[0],
2250 cmd->msg[1], cmd->msg[2], cmd->msg[3], cmd->msg[4], cmd->msg[5]);
2252 LOOP_WHILE_EINTR (err, ioctl (fd, FE_DISEQC_SEND_MASTER_CMD, cmd));
2254 GST_ERROR ("Sending DiSEqC command failed");
2258 g_usleep (15 * 1000);
2260 LOOP_WHILE_EINTR (err, ioctl (fd, FE_DISEQC_SEND_BURST, b));
2262 GST_ERROR ("Sending burst failed");
2266 g_usleep (15 * 1000);
2268 LOOP_WHILE_EINTR (err, ioctl (fd, FE_SET_TONE, t));
2270 GST_ERROR ("Setting tone failed");
2276 /* digital satellite equipment control,
2277 * specification is available from http://www.eutelsat.com/
2280 diseqc (int secfd, int sat_no, int voltage, int tone)
2282 struct dvb_diseqc_master_cmd cmd =
2283 { {0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4 };
2285 /* param: high nibble: reset bits, low nibble set bits,
2286 * bits are: option, position, polarizaion, band
2289 0xf0 | (((sat_no * 4) & 0x0f) | (tone == SEC_TONE_ON ? 1 : 0) |
2290 (voltage == SEC_VOLTAGE_13 ? 0 : 2));
2291 /* send twice because some DiSEqC switches do not respond correctly the
2293 diseqc_send_msg (secfd, voltage, &cmd, tone,
2294 sat_no % 2 ? SEC_MINI_B : SEC_MINI_A);
2295 diseqc_send_msg (secfd, voltage, &cmd, tone,
2296 sat_no % 2 ? SEC_MINI_B : SEC_MINI_A);
2301 set_prop (struct dtv_property *props, int *n, guint32 cmd, guint32 data)
2303 if (*n == NUM_DTV_PROPS) {
2304 g_critical ("Index out of bounds");
2306 props[*n].cmd = cmd;
2307 props[(*n)++].u.data = data;
2312 gst_dvbsrc_tune_fe (GstDvbSrc * object)
2315 struct dtv_properties props;
2316 struct dtv_property dvb_prop[NUM_DTV_PROPS];
2317 GstClockTimeDiff elapsed_time;
2321 GST_DEBUG_OBJECT (object, "Starting the frontend tuning process");
2323 if (object->fd_frontend < 0) {
2324 GST_INFO_OBJECT (object, "Frontend not open: tuning later");
2328 /* If set, confirm the choosen delivery system is actually
2329 * supported by the hardware */
2330 if (object->delsys != SYS_UNDEFINED) {
2331 GST_DEBUG_OBJECT (object, "Confirming delivery system '%u' is supported",
2333 if (!g_list_find (object->supported_delsys,
2334 GINT_TO_POINTER (object->delsys))) {
2335 GST_WARNING_OBJECT (object, "Adapter does not support delivery system "
2336 "'%u'", object->delsys);
2341 gst_dvbsrc_unset_pes_filters (object);
2343 g_mutex_lock (&object->tune_mutex);
2345 memset (dvb_prop, 0, sizeof (dvb_prop));
2346 dvb_prop[0].cmd = DTV_CLEAR;
2348 props.props = dvb_prop;
2350 LOOP_WHILE_EINTR (err, ioctl (object->fd_frontend, FE_SET_PROPERTY, &props));
2352 GST_WARNING_OBJECT (object, "Error resetting tuner: %s",
2353 g_strerror (errno));
2356 memset (dvb_prop, 0, sizeof (dvb_prop));
2357 if (!gst_dvbsrc_set_fe_params (object, &props)) {
2358 GST_WARNING_OBJECT (object, "Could not set frontend params");
2362 GST_DEBUG_OBJECT (object, "Setting %d properties", props.num);
2364 LOOP_WHILE_EINTR (err, ioctl (object->fd_frontend, FE_SET_PROPERTY, &props));
2366 GST_WARNING_OBJECT (object, "Error tuning channel: %s (%d)",
2367 g_strerror (errno), errno);
2371 g_signal_emit (object, gst_dvbsrc_signals[SIGNAL_TUNING_START], 0);
2373 start = gst_util_get_timestamp ();
2375 /* signal locking loop */
2377 LOOP_WHILE_EINTR (err, ioctl (object->fd_frontend, FE_READ_STATUS,
2380 GST_WARNING_OBJECT (object, "Failed querying frontend for tuning status"
2381 " %s (%d)", g_strerror (errno), errno);
2382 goto fail_with_signal;
2384 gst_dvbsrc_output_frontend_stats (object);
2385 /* keep retrying forever if tuning_timeout = 0 */
2386 if (object->tuning_timeout)
2387 elapsed_time = GST_CLOCK_DIFF (start, gst_util_get_timestamp ());
2388 GST_LOG_OBJECT (object,
2389 "Tuning. Time elapsed %" GST_STIME_FORMAT " Limit %" GST_TIME_FORMAT,
2390 GST_STIME_ARGS (elapsed_time), GST_TIME_ARGS (object->tuning_timeout));
2391 } while (!(status & FE_HAS_LOCK) && elapsed_time <= object->tuning_timeout);
2393 if (!(status & FE_HAS_LOCK)) {
2394 GST_WARNING_OBJECT (object,
2395 "Unable to lock on signal at desired frequency");
2396 goto fail_with_signal;
2399 GST_LOG_OBJECT (object, "status == 0x%02x", status);
2401 g_signal_emit (object, gst_dvbsrc_signals[SIGNAL_TUNING_DONE], 0);
2402 GST_DEBUG_OBJECT (object, "Successfully set frontend tuning params");
2404 g_mutex_unlock (&object->tune_mutex);
2408 g_signal_emit (object, gst_dvbsrc_signals[SIGNAL_TUNING_FAIL], 0);
2410 GST_WARNING_OBJECT (object, "Could not tune to desired frequency");
2411 g_mutex_unlock (&object->tune_mutex);
2416 gst_dvbsrc_guess_delsys (GstDvbSrc * object)
2418 GList *valid, *candidate;
2421 if (g_list_length (object->supported_delsys) == 1) {
2422 object->delsys = GPOINTER_TO_INT (object->supported_delsys->data);
2423 GST_DEBUG_OBJECT (object, "Adapter supports a single delsys: '%u'",
2425 goto autoselection_done;
2428 /* Automatic delivery system selection based on known-correct
2429 * parameter combinations */
2431 valid = g_list_copy (object->supported_delsys);
2435 GList *next = candidate->next;
2436 if (!gst_dvbsrc_is_valid_modulation (GPOINTER_TO_INT (candidate->data),
2437 object->modulation) ||
2438 !gst_dvbsrc_is_valid_trans_mode (GPOINTER_TO_INT (candidate->data),
2439 object->transmission_mode) ||
2440 !gst_dvbsrc_is_valid_bandwidth (GPOINTER_TO_INT (candidate->data),
2441 object->bandwidth)) {
2442 valid = g_list_delete_link (valid, candidate);
2447 alternatives = g_list_length (valid);
2449 switch (alternatives) {
2451 GST_WARNING_OBJECT (object, "Delivery system autodetection provided no "
2452 "valid alternative");
2453 candidate = g_list_last (object->supported_delsys);
2456 candidate = g_list_last (valid);
2457 GST_DEBUG_OBJECT (object, "Delivery system autodetection provided only "
2458 "one valid alternative: '%d'", GPOINTER_TO_INT (candidate->data));
2461 /* More than one alternative. Selection based on best guess */
2462 if (g_list_find (valid, GINT_TO_POINTER (SYS_DVBT)) &&
2463 g_list_find (valid, GINT_TO_POINTER (SYS_DVBT2))) {
2464 /* There is no way to tell one over the other when parameters seem valid
2465 * for DVB-T and DVB-T2 and the adapter supports both. Reason to go with
2466 * the former here is that, from experience, most DVB-T2 channels out
2467 * there seem to use parameters that are not valid for DVB-T, like
2469 GST_WARNING_OBJECT (object, "Channel parameters valid for DVB-T and "
2470 "DVB-T2. Choosing DVB-T");
2471 candidate = g_list_find (valid, GINT_TO_POINTER (SYS_DVBT));
2473 candidate = g_list_last (valid);
2477 object->delsys = GPOINTER_TO_INT (candidate->data);
2478 g_list_free (valid);
2481 GST_INFO_OBJECT (object, "Automatically selecting delivery system '%u'",
2486 gst_dvbsrc_set_fe_params (GstDvbSrc * object, struct dtv_properties *props)
2488 fe_sec_voltage_t voltage;
2489 unsigned int freq = object->freq;
2490 unsigned int sym_rate = object->sym_rate * 1000;
2491 int inversion = object->inversion;
2495 /* If delsys hasn't been set, ask for it to be automatically selected */
2496 if (object->delsys == SYS_UNDEFINED)
2497 gst_dvbsrc_guess_delsys (object);
2499 /* first 3 entries are reserved */
2502 /* We are not dropping out but issuing a warning in case of wrong
2503 * parameter combinations as failover behavior should be mandated
2504 * by the driver. Worst case scenario it will just fail at tuning. */
2506 switch (object->delsys) {
2510 if (freq > 2200000) {
2511 /* this must be an absolute frequency */
2512 if (freq < object->lnb_slof) {
2513 freq -= object->lnb_lof1;
2514 object->tone = SEC_TONE_OFF;
2516 freq -= object->lnb_lof2;
2517 object->tone = SEC_TONE_ON;
2521 inversion = INVERSION_AUTO;
2522 set_prop (props->props, &n, DTV_SYMBOL_RATE, sym_rate);
2523 set_prop (props->props, &n, DTV_INNER_FEC, object->code_rate_hp);
2525 GST_INFO_OBJECT (object,
2526 "Tuning DVB-S/DVB-S2/Turbo to L-Band:%u, Pol:%d, srate=%u, 22kHz=%s",
2527 freq, object->pol, sym_rate,
2528 object->tone == SEC_TONE_ON ? "on" : "off");
2530 if (object->pol == DVB_POL_H)
2531 voltage = SEC_VOLTAGE_18;
2533 voltage = SEC_VOLTAGE_13;
2535 if (object->diseqc_src == -1 || object->send_diseqc == FALSE) {
2536 set_prop (props->props, &n, DTV_VOLTAGE, voltage);
2538 /* DTV_TONE not yet implemented
2539 * set_prop (fe_props_array, &n, DTV_TONE, object->tone) */
2540 LOOP_WHILE_EINTR (err, ioctl (object->fd_frontend, FE_SET_TONE,
2543 GST_WARNING_OBJECT (object, "Couldn't set tone: %s",
2544 g_strerror (errno));
2547 GST_DEBUG_OBJECT (object, "Sending DiSEqC");
2548 diseqc (object->fd_frontend, object->diseqc_src, voltage, object->tone);
2549 /* Once DiSEqC source is set, do not set it again until
2550 * app decides to change it
2551 * object->send_diseqc = FALSE; */
2554 if ((object->delsys == SYS_DVBS2) || (object->delsys == SYS_TURBO))
2555 set_prop (props->props, &n, DTV_MODULATION, object->modulation);
2557 if (object->delsys == SYS_DVBS2) {
2558 if (object->stream_id > 255) {
2559 GST_WARNING_OBJECT (object, "Invalid (> 255) DVB-S2 stream ID '%d'. "
2560 "Disabling sub-stream filtering", object->stream_id);
2561 object->stream_id = NO_STREAM_ID_FILTER;
2563 set_prop (props->props, &n, DTV_PILOT, object->pilot);
2564 set_prop (props->props, &n, DTV_ROLLOFF, object->rolloff);
2565 set_prop (props->props, &n, DTV_STREAM_ID, object->stream_id);
2570 set_prop (props->props, &n, DTV_BANDWIDTH_HZ, object->bandwidth);
2571 set_prop (props->props, &n, DTV_CODE_RATE_HP, object->code_rate_hp);
2572 set_prop (props->props, &n, DTV_CODE_RATE_LP, object->code_rate_lp);
2573 set_prop (props->props, &n, DTV_MODULATION, object->modulation);
2574 set_prop (props->props, &n, DTV_TRANSMISSION_MODE,
2575 object->transmission_mode);
2576 set_prop (props->props, &n, DTV_GUARD_INTERVAL, object->guard_interval);
2577 set_prop (props->props, &n, DTV_HIERARCHY, object->hierarchy_information);
2579 if (object->delsys == SYS_DVBT2) {
2580 if (object->stream_id > 255) {
2581 GST_WARNING_OBJECT (object, "Invalid (> 255) DVB-T2 stream ID '%d'. "
2582 "Disabling sub-stream filtering", object->stream_id);
2583 object->stream_id = NO_STREAM_ID_FILTER;
2585 set_prop (props->props, &n, DTV_STREAM_ID, object->stream_id);
2588 GST_INFO_OBJECT (object, "Tuning DVB-T/DVB_T2 to %d Hz", freq);
2590 case SYS_DVBC_ANNEX_A:
2591 case SYS_DVBC_ANNEX_B:
2592 #if HAVE_V5_MINOR(6)
2593 case SYS_DVBC_ANNEX_C:
2595 GST_INFO_OBJECT (object, "Tuning DVB-C/ClearCable to %d, srate=%d",
2598 set_prop (props->props, &n, DTV_MODULATION, object->modulation);
2599 if (object->delsys != SYS_DVBC_ANNEX_B) {
2600 set_prop (props->props, &n, DTV_INNER_FEC, object->code_rate_hp);
2601 set_prop (props->props, &n, DTV_SYMBOL_RATE, sym_rate);
2605 GST_INFO_OBJECT (object, "Tuning ATSC to %d", freq);
2607 set_prop (props->props, &n, DTV_MODULATION, object->modulation);
2611 if (object->isdbt_partial_reception == 1 &&
2612 object->isdbt_layera_segment_count != 1) {
2613 GST_WARNING_OBJECT (object, "Wrong ISDB-T parameter combination: "
2614 "partial reception is set but layer A segment count is not 1");
2617 if (!object->isdbt_sound_broadcasting) {
2618 GST_INFO_OBJECT (object, "ISDB-T sound broadcasting is not set. "
2619 "Driver will likely ignore values set for isdbt-sb-subchannel-id, "
2620 "isdbt-sb-segment-idx and isdbt-sb-segment-count");
2623 if (object->isdbt_layerc_modulation == DQPSK &&
2624 object->isdbt_layerb_modulation != DQPSK) {
2625 GST_WARNING_OBJECT (object, "Wrong ISDB-T parameter combination: "
2626 "layer C modulation is DQPSK but layer B modulation is different");
2629 GST_INFO_OBJECT (object, "Tuning ISDB-T to %d", freq);
2630 set_prop (props->props, &n, DTV_BANDWIDTH_HZ, object->bandwidth);
2631 set_prop (props->props, &n, DTV_GUARD_INTERVAL, object->guard_interval);
2632 set_prop (props->props, &n, DTV_TRANSMISSION_MODE,
2633 object->transmission_mode);
2634 set_prop (props->props, &n, DTV_ISDBT_LAYER_ENABLED,
2635 object->isdbt_layer_enabled);
2636 set_prop (props->props, &n, DTV_ISDBT_PARTIAL_RECEPTION,
2637 object->isdbt_partial_reception);
2638 set_prop (props->props, &n, DTV_ISDBT_SOUND_BROADCASTING,
2639 object->isdbt_sound_broadcasting);
2640 set_prop (props->props, &n, DTV_ISDBT_SB_SUBCHANNEL_ID,
2641 object->isdbt_sb_subchannel_id);
2642 set_prop (props->props, &n, DTV_ISDBT_SB_SEGMENT_IDX,
2643 object->isdbt_sb_segment_idx);
2644 set_prop (props->props, &n, DTV_ISDBT_SB_SEGMENT_COUNT,
2645 object->isdbt_sb_segment_count);
2646 set_prop (props->props, &n, DTV_ISDBT_LAYERA_FEC,
2647 object->isdbt_layera_fec);
2648 set_prop (props->props, &n, DTV_ISDBT_LAYERA_MODULATION,
2649 object->isdbt_layera_modulation);
2650 set_prop (props->props, &n, DTV_ISDBT_LAYERA_SEGMENT_COUNT,
2651 object->isdbt_layera_segment_count);
2652 set_prop (props->props, &n, DTV_ISDBT_LAYERA_TIME_INTERLEAVING,
2653 object->isdbt_layera_time_interleaving);
2654 set_prop (props->props, &n, DTV_ISDBT_LAYERB_FEC,
2655 object->isdbt_layerb_fec);
2656 set_prop (props->props, &n, DTV_ISDBT_LAYERB_MODULATION,
2657 object->isdbt_layerb_modulation);
2658 set_prop (props->props, &n, DTV_ISDBT_LAYERB_SEGMENT_COUNT,
2659 object->isdbt_layerb_segment_count);
2660 set_prop (props->props, &n, DTV_ISDBT_LAYERB_TIME_INTERLEAVING,
2661 object->isdbt_layerb_time_interleaving);
2662 set_prop (props->props, &n, DTV_ISDBT_LAYERC_FEC,
2663 object->isdbt_layerc_fec);
2664 set_prop (props->props, &n, DTV_ISDBT_LAYERC_MODULATION,
2665 object->isdbt_layerc_modulation);
2666 set_prop (props->props, &n, DTV_ISDBT_LAYERC_SEGMENT_COUNT,
2667 object->isdbt_layerc_segment_count);
2668 set_prop (props->props, &n, DTV_ISDBT_LAYERC_TIME_INTERLEAVING,
2669 object->isdbt_layerc_time_interleaving);
2671 #if HAVE_V5_MINOR(7)
2673 set_prop (props->props, &n, DTV_BANDWIDTH_HZ, object->bandwidth);
2674 set_prop (props->props, &n, DTV_MODULATION, object->modulation);
2675 set_prop (props->props, &n, DTV_INVERSION, object->inversion);
2676 set_prop (props->props, &n, DTV_INNER_FEC, object->code_rate_hp);
2677 set_prop (props->props, &n, DTV_TRANSMISSION_MODE,
2678 object->transmission_mode);
2679 set_prop (props->props, &n, DTV_GUARD_INTERVAL, object->guard_interval);
2680 set_prop (props->props, &n, DTV_INTERLEAVING, object->interleaving);
2681 /* FIXME: Make the LNA on/off switch a property and proxy on dvbbasebin */
2682 /* FIXME: According to v4l advice (see libdvbv5 implementation) this
2683 * property should be set separately as not all drivers will ignore it
2684 * if unsupported. An alternative would be to get the dvb API contract
2685 * revised on this regard */
2686 set_prop (props->props, &n, DTV_LNA, LNA_AUTO);
2687 GST_INFO_OBJECT (object, "Tuning DTMB to %d Hz", freq);
2691 GST_ERROR_OBJECT (object, "Unknown frontend type %u", object->delsys);
2695 /* Informative checks */
2696 if (!gst_dvbsrc_is_valid_modulation (object->delsys, object->modulation)) {
2697 GST_WARNING_OBJECT (object,
2698 "Attempting invalid modulation '%u' for delivery system '%u'",
2699 object->modulation, object->delsys);
2701 if (!gst_dvbsrc_is_valid_trans_mode (object->delsys,
2702 object->transmission_mode)) {
2703 GST_WARNING_OBJECT (object,
2704 "Attempting invalid transmission mode '%u' for delivery system '%u'",
2705 object->transmission_mode, object->delsys);
2707 if (!gst_dvbsrc_is_valid_bandwidth (object->delsys, object->bandwidth)) {
2708 GST_WARNING_OBJECT (object,
2709 "Attempting invalid bandwidth '%u' for delivery system '%u'",
2710 object->bandwidth, object->delsys);
2713 set_prop (props->props, &n, DTV_TUNE, 0);
2715 /* set first three entries */
2717 set_prop (props->props, &n, DTV_DELIVERY_SYSTEM, object->delsys);
2718 set_prop (props->props, &n, DTV_FREQUENCY, freq);
2719 set_prop (props->props, &n, DTV_INVERSION, inversion);
2725 gst_dvbsrc_tune (GstDvbSrc * object)
2727 /* found in mail archive on linuxtv.org
2728 * What works well for us is:
2729 * - first establish a TS feed (i.e. tune the frontend and check for success)
2730 * - then set filters (PES/sections)
2731 * - then tell the MPEG decoder to start
2732 * - before tuning: first stop the MPEG decoder, then stop all filters
2734 if (!gst_dvbsrc_tune_fe (object)) {
2735 GST_WARNING_OBJECT (object, "Unable to tune frontend");
2739 gst_dvbsrc_set_pes_filters (object);
2746 gst_dvbsrc_unset_pes_filters (GstDvbSrc * object)
2750 GST_INFO_OBJECT (object, "clearing PES filter");
2752 for (i = 0; i < MAX_FILTERS; i++) {
2753 if (object->fd_filters[i] == -1)
2755 close (object->fd_filters[i]);
2756 object->fd_filters[i] = -1;
2761 gst_dvbsrc_set_pes_filters (GstDvbSrc * object)
2765 struct dmx_pes_filter_params pes_filter;
2767 gchar *demux_dev = g_strdup_printf ("/dev/dvb/adapter%d/demux%d",
2768 object->adapter_number, object->frontend_number);
2770 GST_INFO_OBJECT (object, "Setting PES filter");
2772 /* Set common params for all filters */
2773 pes_filter.input = DMX_IN_FRONTEND;
2774 pes_filter.output = DMX_OUT_TS_TAP;
2775 pes_filter.pes_type = DMX_PES_OTHER;
2776 pes_filter.flags = DMX_IMMEDIATE_START;
2778 for (i = 0; i < MAX_FILTERS; i++) {
2779 if (object->pids[i] == G_MAXUINT16)
2782 fd = &object->fd_filters[i];
2783 pid = object->pids[i];
2787 if ((*fd = open (demux_dev, O_RDWR)) < 0) {
2788 GST_ERROR_OBJECT (object, "Error opening demuxer: %s (%s)",
2789 g_strerror (errno), demux_dev);
2792 g_return_if_fail (*fd != -1);
2794 pes_filter.pid = pid;
2796 GST_INFO_OBJECT (object, "Setting PES filter: pid = %d, type = %d",
2797 pes_filter.pid, pes_filter.pes_type);
2799 LOOP_WHILE_EINTR (err, ioctl (*fd, DMX_SET_PES_FILTER, &pes_filter));
2801 GST_WARNING_OBJECT (object, "Error setting PES filter on %s: %s",
2802 demux_dev, g_strerror (errno));