Add support for DVB-T/S2 and ISDB multistream.

Generic multistream support was added in Linux 3.6 in commit 287cefd096b.

http://git.kernel.org/gitweb.cgi?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=287cefd096b

The way it is added it is backwards compatible with older kernels.

This patch implements mis support in DVBlast. Unfortunately I don't
have mis compatible hardware and a way to test it, so I'm posting
this patch as RFC and RFT.

If your frontend reports FE_CAN_MULTISTREAM (you have to use Linux 3.6
and higher) it'll be invaluable to test if multistream support is
working.
Add per output PID remapping.

This commit adds per output setting for PID remapping.
Fix compilation error against Linux 3.7 kernel headers.

The for multistream checks were wrong and when dvblast was compiled
against kernel headers that contain multistream support the build
failed with:

  CC      dvb.c
  In file included from dvb.c:47:0:
  /usr/include/linux/dvb/frontend.h:65:2: error: expected identifier before numeric constant
  dvb.c: In function ‘FrontendInfo’:
  dvb.c:776:5: error: ‘FE_CAN_2G_MODULATION’ undeclared (first use in this function)
  dvb.c:776:5: note: each undeclared identifier is reported only once for each function it appears in
  dvb.c:779:5: error: ‘FE_NEEDS_BENDING’ undeclared (first use in this function)
  dvb.c:780:5: error: ‘FE_CAN_RECOVER’ undeclared (first use in this function)
  dvb.c:781:5: error: ‘FE_CAN_MUTE_TS’ undeclared (first use in this function)
  dvb.c: In function ‘FrontendSet’:
  dvb.c:1028:30: error: ‘FE_CAN_2G_MODULATION’ undeclared (first use in this function)
  make: *** [dvb.o] Error 1
dvblastctl: Fix build error when multistream support is missing.
Prevent crash when get_pmt is called but the PMT is not initialized.
Prevent crash when new service is enabled but the PMT is not configured.
Remove only valid config entries on exit.

This prevents crash on exit when a config entry was removed while
dvblast was running and the configration was reloaded.
Enable b_select_pmts when configuration file is used.

When configuration file is used it is reasonable to assume that
services may be added/removed on the fly.

If b_select_pmts is not set, dvblast is unable to start streaming
newly added services which is not expected at all.
demux: Set eit p/f and eit schedule flags in SDT if EPG output is requested.

There are some providers that send EPG for a service but do not have
the correct flags set in SDT. This patch sets eit p/f and eit schedule
flags in SDT if the output have EPG output enabled.
support for raw IPv4 sockets

This allows setting the source address per multicast stream.
dvblastctl: Print PSI tables texts in UTF-8.
Fix bunch of warnings about GNU extension under clang.

Clang complaints are like:
./dvblast.h:136:22: warning: field 'raw_pkt_header' with variable sized type
      'struct udprawpkt' not at the end of a struct or class is a GNU extension
      [-Wgnu]
    struct udprawpkt raw_pkt_header;
                     ^
Fix enumeration value not handeled in switch.

SYS_DMBTH was introduced in DVB API version 5.0.0, and deprecated in favor
of SYS_DTMB in DVB API version 5.0.7.
Support for Deltacast ASI card

On Wed Jun 05, 2013 at 08:29:34AM +0100, Simon Lockhart wrote:
> I've found a card from Deltacast:
>
>   http://www.deltacast.tv/Products/DELTA-asi-OEM-video-input-output-PCI-Express-card.asp
>
> Up to 8 ASI receive channels on one card (although it can only fit 6 inputs on
> the back of one card, so the last 2 are on a seperate backpanel), and comes
> with Linux drivers and SDK. OEM pricing is a lot cheaper than the DVEO card.

Well, I got the cards from them, and have added support to DVBlast. Patch
below ("git diff HEAD")

This is my first attempt at a patch to DVBlast, so feel free to critique...

Hope this is helpful to people...

Simon
ecm: Stop dvblast from losing ECM pid on PMT changes.

The way ECM pids enabling/disabling works leads to condition in which
DVBlast stops streaming ECM pid on PMT changes. Consider the following
PMT updates:

debug: new PMT program=4301 version=8 pcrpid=36
debug:     - desc 0e maximum_bitrate max_bitrate=24894 max_bitrate_decoded=1244700
debug:     - desc 10 smoothing_buffer sb_leak_rate=625 sb_size=1024
debug:     - desc 0b system_clock external_clock_reference_indicator=0 clock_accuracy_integer=2 clock_accuracy_exponent=1
debug:   * ES pid=2160 streamtype=0x02 streamtype_txt="13818-2 video (MPEG-2)"
debug:     - desc 06 data_stream_alignment alignment=2 alignment_txt="Video access unit"
debug:     - desc 09 ca sysid=0xd00 pid=6190
debug:     - desc 09 ca sysid=0x664 pid=7190
debug:   * ES pid=3160 streamtype=0x04 streamtype_txt="13818-3 audio (MPEG-2)"
debug:     - desc 0a audio_language language=eng audiotype=0 audiotype_txt="undefined"
debug:     - desc 09 ca sysid=0xd00 pid=6190
debug:     - desc 09 ca sysid=0x664 pid=7190
debug: end PMT

debug: new PMT program=4301 version=9 pcrpid=2160
debug:     - desc 09 ca sysid=0xd00 pid=6190
debug:     - desc 09 ca sysid=0x664 pid=7190
debug:   * ES pid=2160 streamtype=0x02 streamtype_txt="13818-2 video (MPEG-2)"
debug:     - desc 52 stream_identifier component_tag=1
debug:   * ES pid=3160 streamtype=0x04 streamtype_txt="13818-3 audio (MPEG-2)"
debug:     - desc 52 stream_identifier component_tag=2
debug:     - desc 0a audio_language language=TUR audiotype=1 audiotype_txt="clean effects"
debug:   * ES pid=4040 streamtype=0x05 streamtype_txt="13818-1 private sections"
debug:     - desc 52 stream_identifier component_tag=4
debug:     - desc 0f private_data_indicator private_indicator=0x4f545600
debug:     - desc fe unknown length=4 value=45545634
debug:     - desc 90 unknown length=1 value=90
debug: end PMT

The first one enables ECM pids 6190 and 7190. The second one causes DVBlast
to stop streaming these PIDs because they are not mentioned in ES descriptor
loop.

This patch fixes this behaviour.
comm: Remove debug message.

A lot of debug messages are actually useful (tunning mesages, tables dump)
but not this one. When a program is run that uses comm socket a lot, dvblast
logs each answer and just polutes the log.
Simplify pid selection on PMT changes.

Consider the following PMT log:

> Enable ECM pids 6206 and 7306 and ES pids 2256, 2530, 2531.

debug: setting filter on PID 2256
debug: setting filter on PID 2530
debug: setting filter on PID 2531
debug: setting filter on PID 6306
debug: setting filter on PID 7306
debug: new PMT program=6411 version=7 pcrpid=2256
debug:   * ES pid=2256 streamtype=0x02 streamtype_txt="13818-2 video (MPEG-2)"
debug:     - desc 52 stream_identifier component_tag=1
debug:     - desc 09 ca sysid=0xd00 pid=6306
debug:     - desc 09 ca sysid=0x664 pid=7306
debug:   * ES pid=2530 streamtype=0x06 streamtype_txt="13818-1 PES private data"
debug:     - desc 52 stream_identifier component_tag=6
debug:     - desc 59 subtitling language=tur type=0x10 composition=2 ancillary=2
debug:     - desc 09 ca sysid=0xd00 pid=6306
debug:     - desc 09 ca sysid=0x664 pid=7306
debug:   * ES pid=2531 streamtype=0x06 streamtype_txt="13818-1 PES private data"
debug:     - desc 52 stream_identifier component_tag=7
debug:     - desc 59 subtitling language=eng type=0x10 composition=2 ancillary=2
debug:     - desc 09 ca sysid=0xd00 pid=6306
debug:     - desc 09 ca sysid=0x664 pid=7306
debug: end PMT

> Enable pids 6206 and 7306 but disable them again because they are not
> mentioned in the ES desc loop and in the global desc loop of the old PMT.

debug: setting filter on PID 6306
debug: setting filter on PID 7306
debug: unsetting filter on PID 6306
debug: unsetting filter on PID 7306
debug: new PMT program=6411 version=14 pcrpid=2256
debug:     - desc 09 ca sysid=0xd00 pid=6306
debug:     - desc 09 ca sysid=0x664 pid=7306
debug:   * ES pid=2256 streamtype=0x02 streamtype_txt="13818-2 video (MPEG-2)"
debug:     - desc 52 stream_identifier component_tag=1
debug:   * ES pid=2530 streamtype=0x06 streamtype_txt="13818-1 PES private data"
debug:     - desc 52 stream_identifier component_tag=6
debug:     - desc 59 subtitling language=tur type=0x10 composition=2 ancillary=2
debug:   * ES pid=2531 streamtype=0x06 streamtype_txt="13818-1 PES private data"
debug:     - desc 52 stream_identifier component_tag=7
debug:     - desc 59 subtitling language=eng type=0x10 composition=2 ancillary=2
debug: end PMT

Commit 34f232f7e8d1fbe2a2930b597e40fb410c9ac5d6 added checks for global
descriptor loop but it was not enough. Instead of adding "yet more checks"
because ECM pids can be described in two places, I used the opportunity to
simplify the code that deals with pid selection in PMT.

Now we have only one place that parses the PMT and we use a table to mark
the pids in the new and in the old table.

50 lines of code were removed and the code was made a lot simpler and easy
to follow for the price of 8k stack space. As a bonus the bug described above
was fixed.
Fix reading of BER, SNR and strength values.

According to Linux DVB docs FE_READ_SIGNAL_STRENGTH and FE_READ_SNR
have int16_t parameter, not int32_t.

Also FE_READ_BER returns uint32_t, not int32_t.

Using the wrong types caused dvblastctl to report absurd values
for strength and snr.

Reported by: Ibrahim Tachijian <barhom@gmail.com>

Signed-off-by: Georgi Chorbadzhiyski <gf@unixsol.org>
unlink comm socket before binding
refractory period: avoid triggering wdog too often