The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DVB::Epg - Generate MPEG-2 transport stream chunk containing DVB Event Information table.

SYNOPSIS

This module allows generating of DVB EPG service by building EIT p/f and schedule tables. First some event information must be added to the system. A sqlite database for storage is used. Based on this event information the library builds the standardized EIT, which can then be export as a MPEG-2 Transport Stream/chunk for playout. The result of the whole process is an EIT inside a MTS.

    use DVB::Epg;

    my $myEpg = DVB::Epg->new( 'eitfile');

    # create empty database
    $myEpg->initdb();

    # add program to EIT for which to generate EPG
    $myEpg->addEit( 18, 9019, 1024, 15, 8, 1);
    
    # add dummy event data to database
    my $event = {};
    $event->{start} = time;
    $event->{stop}  = time+100;
    $event->{uid} = 15;
    $myEpg->addEvent( $event);
    
    # generate EPG tables to database
    $myEpg->updateEit( 18);

    # export EIT as MTS from database
    my $mts = $myEpg->getEit( 18);

The Library can handle multiple services and multiple tables.

CLASS Epg

METHODS

new( $dbfile )

Class initialization with sqlite3 database filename. Open existing or create new sqlite database.

dbh( )

Return database handle for direct control.

initdb( )

Initialize database with some basic table structure;

addEvent( $event)

Add an $event to event table. $event must be reference to hash containing at least fields: $event->{start}, $event->{stop}, $event->{uid}

start, stop MUST be in EPOCH

Optional fields are: $event->{id}, $event->{running_status}, $event->{free_CA_mode} and $event->{descriptors}

Return event_key of inserted row.

listEvent( $uid, $event_id, $start, $stop, $touch)

List events with $uid in cronological order.

$event_id, $start, $stop, $touch are optional parameters. $event_id is used as selection filter. $start, $stop are used as interval specification. If $touch is defined only elements with timestamp newer than $touch are returned.

Return array of events.

deleteEvent( $uid, $event_id, $start_min, $start_max, $stop_min, $stop_max)

Delete events with $uid.

$event_id, $stop_min, $stop_max, $start_min and $start_max are optional parameters. $uid and $event_id are used as selection filter.

Delete events that have start in between $start_min, $start_max and stop in between $stop_min, $stop_max. Use only defined markers.

Return number of deleted events.

addEit( $pid, $service_id, $original_network_id, $transport_stream_id, $uid, $maxsegments, $actual, $comment)

Add eit generator rule. Maxsegments defines how far in the future the tables should be generated - each segment defines 3 hour period. All parameters must be defined.

Return 1 on success.

listEit( )

List eit generator rules.

Return reference to an array of arrays of rules.

listPid( )

List all destination pid defined in eit generator rules.

Return array of pids.

deleteEit( $pid, $service_id, $original_network_id, $transport_stream_id)

Delete eit generator rule. Parameters are optional.

Return number of deleted rules.

updateEit( $pid )

Use eit rules for updateing Eit sections of given $pid in database.

Return 1 on success. Return 0 if sections are already uptodate. Return undef on error;

updateEitPresent( $rule, $forced)

Update eit sections for given $rule. $rule is reference to hash containing keys: pid, service_id, original_network_id, transport_stream_id, service_id, maxsegments, actual

Update sections only if there are changes in event table of schedule since last update or the $forced flag is set to 1.

Return undef if failed. Return 0 if sections are already uptodate. Return 1 after updating sections.

updateEitSchedule( $rule)

Update eit playout packet for given $rule. $rule is reference to hash containing keys: pid, service_id, original_network_id, transport_stream_id, service_id, maxsegments, actual

getEit( $pid, $timeFrame)

Build final EIT from all sections in table for given $pid and $timeFrame.

Return the complete TS chunk to be played within the timeframe. Default timeframe should be 60s. Return undef on error.

getSectionFrequency( $table_id, $section_number, $timeFrame)

Make lookup by $table_id and $section_number and return how often this section has to be repeated in the given interval. Default interval ($timeFrame) is 60 seconds.

getLastError( )

Return last db operation error.

_packetize( $pid, $section)

Generate MPEG transport stream for defined $pid and $section in database. Continuity counter starts at 0; Return MTS.

_unfreezeEvent( $event)

$event is a reference to hash containing elements of a row in event table. Thaw the info field and update all other keys from field values.

Return reference to updated info hash.

CLASS EventInformationTable

METHODS

new( $rule )

EIT subtable initialization with information taken from $rule.

add2Segment( $segment_number, $event)

Add $event to segment with number $segment_number. $event is reference to hash containin event data.

Return 1 on success. Return undef on error.

add2Section ( $section_number, $event)

Add $event to section with number $section_number. $event is reference to hash containin event data.

Return binary $size of all events in section (always < 4078) or negativ if section is full, undef on error.

getSections ()

Return reference to hash of sections with section_number as key and section as value.

_getDescriptorBin ( $descriptor)

Return binary representation of $descriptor.

_getByteString ( $string)

Convert $string containing only byte characters. This is for avoiding any problems with UTF8. Those string must be converted before entering data into database.

Return converted string.

_getExtendedEventDescriptorBin( $descriptor)

Return 1 or many Extended Event Descriptors

_int2bcd( $time)

Convert integer $time in seconds into 24 bit time BCD format (hour:minute:seconds).

_bcd2int( $bcd)

Convert time in 24 bit BCD format (hour:minute:seconds) in seconds from midnight;

_epoch2mjd( $time)

Convert epoch $time into 40 bit Modified Julian Date and time BCD format.

_mjd2epoch( $time)

Convert 40 bit Modified Julian Date and time BCD format into epoch.

AUTHOR

Bojan Ramsak, <BojanR@gmx.net>

BUGS

Please report any bugs or feature requests to bug-dvb-epg at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DVB-Epg. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc DVB::Epg

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2012 Bojan Ramsak.

This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License v2.0

See http://www.opensource.org/licenses/Artistic-2.0 for more information.