VPS/PDC Program ID
Low Level Decoding

Functions to decode VPS/PDC Program IDs and helper functions. More...

## Data Structures

struct | vbi_program_id
| Program Identification. More...

## Macros

#define | VBI_PIL(month, day, hour, minute)
| Macro to create a PIL.
#define | VBI_PIL_MONTH(pil)
#define | VBI_PIL_DAY(pil)
#define | VBI_PIL_HOUR(pil)
#define | VBI_PIL_MINUTE(pil)

## Typedefs

typedef unsigned int | vbi_pil
| Program Identification Label.

## Enumerations

enum | { VBI_PIL_TIMER_CONTROL = VBI_PIL (15, 0, 31, 63) , VBI_PIL_INHIBIT_TERMINATE = VBI_PIL (15, 0, 30, 63) , VBI_PIL_INTERRUPTION = VBI_PIL (15, 0, 29, 63) , VBI_PIL_CONTINUE = VBI_PIL (15, 0, 28, 63) , VBI_PIL_NSPV = VBI_PIL (15, 15, 31, 63) , VBI_PIL_END = VBI_PIL (15, 15, 31, 63) }
| PIL Service Codes. More...
enum | vbi_pid_channel { VBI_PID_CHANNEL_LCI_0 = 0 , VBI_PID_CHANNEL_LCI_1 , VBI_PID_CHANNEL_LCI_2 , VBI_PID_CHANNEL_LCI_3 , VBI_PID_CHANNEL_VPS , VBI_PID_CHANNEL_PDC_DESCRIPTOR , VBI_PID_CHANNEL_XDS_CURRENT , VBI_PID_CHANNEL_XDS_FUTURE , VBI_MAX_PID_CHANNELS }
| Sources of PIDs. More...
enum | vbi_pcs_audio { VBI_PCS_AUDIO_UNKNOWN = 0 , VBI_PCS_AUDIO_MONO , VBI_PCS_AUDIO_STEREO , VBI_PCS_AUDIO_BILINGUAL }
| PDC Program Control Status - Audio. More...

## Functions

vbi_bool | vbi_pil_is_valid_date (vbi_pil pil)
time_t | vbi_pil_to_time (vbi_pil pil, time_t start, const char *tz)
time_t | vbi_pil_lto_to_time (vbi_pil pil, time_t start, int seconds_east)
vbi_bool | vbi_pty_validity_window (time_t *begin, time_t *end, time_t time, const char *tz)
vbi_bool | vbi_pil_validity_window (time_t *begin, time_t *end, vbi_pil pil, time_t start, const char *tz)
vbi_bool | vbi_pil_lto_validity_window (time_t *begin, time_t *end, vbi_pil pil, time_t start, int seconds_east)

## Detailed Description

Functions to decode VPS/PDC Program IDs and helper functions.

Program IDs are transmitted by networks to remotely control video recorders. They can be used to

- start and stop recording exactly when a program starts and ends, even when the program is early or late or overruns,
- pause recording during a planned or unplanned interruption (you can safely assume that no station transmits a pause code during commercial breaks),
- keep recording a program which continues on a different channel,
- record a program after it has been postponed to a later date and possibly a different channel,
- record all episodes of a series without prior knowledge of the broadcast times,
- alert the user about emergency messages.

The basic principle is to transmit a label along with the program containing the originally announced start date and time. When the label is no longer transmitted the program has ended. When two programs on different channels are scheduled for recording the recorder may have to scan the channels alternately. Better accuracy than a few seconds within the actual start should not be expected.

Libzvbi supports Program IDs transmitted in Teletext packet 8/30 format 2 and in VPS packets as defined in EN 300 231 "Television systems; Specification of the domestic video Programme Delivery Control system (PDC)", and DVB PDC descriptors as defined in EN 300 468 "Specification for Service Information (SI) in DVB systems". Support for XDS Current/Future Program ID packets as defined in EIA 608-B "Recommended Practice for Line 21 Data Service" is planned but not implemented yet.

Program IDs are available through the low level functions vbi_decode_teletext_8302_pdc(), vbi_decode_vps_pdc(), vbi_decode_dvb_pdc_descriptor() and the vbi_decoder event `VBI_EVENT_PROG_ID`.

## Macro Definition Documentation

## VBI_PIL

#define VBI_PIL | ( |  | month,
|  |  | day,
|  |  | hour,
|  |  | minute )

Value:
(((day) << 15) | ((month) << 11) | ((hour) << 6) | (minute))

Macro to create a PIL.

Valid values for month are 1 ... 12, for day 1 ... 31, for hour 0 ... 23 and for minute 0 ... 59.

Note in the PDC system (EN 300 231) networks may also transmit unreal dates or times like 14-00 25:63. You can determine if a PIL represents a valid date and time with the vbi_pil_is_valid_date() function.

Since
  0.2.34

Examples
  examples/pdc2.c.

## VBI_PIL_MONTH

#define VBI_PIL_MONTH | ( |  | pil | ) |

Value:
(((pil) >> 11) & 15)

Extract the month from a PIL. Valid values are in range 1 ... 12.

Examples
  examples/pdc1.c, and examples/pdc2.c.

Referenced by vbi_pil_is_valid_date(), vbi_pil_lto_validity_window(), and vbi_pil_validity_window().

## VBI_PIL_DAY

#define VBI_PIL_DAY | ( |  | pil | ) |

Value:
(((pil) >> 15) & 31)

Extract the day from a PIL. Valid values are in range 1 ... 31.

Examples
  examples/pdc1.c, and examples/pdc2.c.

Referenced by vbi_pil_is_valid_date(), vbi_pil_lto_validity_window(), and vbi_pil_validity_window().

## VBI_PIL_HOUR

#define VBI_PIL_HOUR | ( |  | pil | ) |

Value:
(((pil) >> 6) & 31)

Extract the hour from a PIL. Valid values are in range 0 ... 23.

Examples
  examples/pdc1.c, and examples/pdc2.c.

Referenced by vbi_pil_is_valid_date(), and vbi_pil_to_time().

## VBI_PIL_MINUTE

#define VBI_PIL_MINUTE | ( |  | pil | ) |

Value:
((pil) & 63)

Extract the minute from a PIL. Valid values are in range 0 ... 59.

Examples
  examples/pdc1.c, and examples/pdc2.c.

Referenced by vbi_pil_is_valid_date(), and vbi_pil_to_time().

## Typedef Documentation

## vbi_pil

typedef unsigned int vbi_pil

Program Identification Label.

This is a packed representation of the originally announced start date and time ("AT-2" in EN 300 231 parlance, "Scheduled Start Time" in EIA 608-B) of a program.

Since
  0.2.34

Examples
  examples/pdc1.c, and examples/pdc2.c.

## Enumeration Type Documentation

## anonymous enum

anonymous enum

PIL Service Codes.

PILs can be zero, or specify a valid date and time, or an unreal time such as 31:00 if a new label has been assigned to a program but no transmission time has been decided yet. Some PILs with unreal date and time have a special meaning.

These codes are defined in EN 300 231 Section 6.2, Annex E.3 and Annex F, and in EIA 608-B Section 9.5.1.1.

Since
  0.2.34

Enumerator
VBI_PIL_TIMER_CONTROL | Only in Teletext packets 8/30 format 2, VPS packets and DVB PDC descriptors: "Timer Control". No program IDs are available, use the timer to control recording.
VBI_PIL_INHIBIT_TERMINATE | Teletext, VPS, DVB: "Recording Inhibit/Terminate". When the PIL changes from a valid program label to `VBI_PIL_INHIBIT_TERMINATE` the current program has ended and the next program has not started yet. VCRs recording the current program shall stop recording and remove the program from their schedule. VCRs waiting for a new PIL shall continue waiting.

VBI_PIL_INTERRUPTION

Teletext, VPS, DVB: "Interruption".

When the PIL changes from a valid program label to `VBI_PIL_INTERRUPTION`, the current program has stopped but will continue later. This code is transmitted for example at the start of a halftime pause or at a film break. VCRs recording the current program shall stop recording, but not delete the program from their schedule. The network may broadcast other programs with different PILs before the interrupted program continues. VCRs waiting for a new PIL shall continue waiting.

VBI_PIL_CONTINUE | Teletext, VPS, DVB: "Continuation code". This code is transmitted during a service interruption, the PDC service should resume operation shortly. VCRs recording the current program shall continue recording, VCRs waiting for a new PIL shall continue waiting.
VBI_PIL_NSPV | Teletext, VPS, DVB: "No Specific PIL Value". Networks may transmit this label with an unplanned program such as an emergency message. The program type (PTY) field may still be valid.
VBI_PIL_END | Only in XDS Current Program ID packets: The current program has ended and the next program not started yet.

## vbi_pid_channel

enum vbi_pid_channel

Sources of PIDs.

A program identification can be transmitted on different logical channels. Teletext packet 8/30 format 2 contains a Label Channel Identifier. XDS Program ID packets can refer to the current or next program.

This information is returned in struct vbi_program_id by the low level functions vbi_decode_teletext_8302_pdc(), vbi_decode_vps_pdc(), vbi_decode_dvb_pdc_descriptor() and the vbi_decoder event `VBI_EVENT_PROG_ID`.

Since
  0.2.34

Enumerator

VBI_PID_CHANNEL_LCI_0

Data from Teletext packet 8/30 format 2, Label Channel 0 (EN 300 706 section 9.8.2, EN 300 231 section 8.2.1).

Teletext packets contain a CNI, PIL, LUF, MI, PRF, PCS and PTY. They are transmitted once per second for each Label Channel in use.

The purpose of Label Channels is to transmit overlapping PIDs, for example one referring the current program and another announcing the imminent start of the next program. Programs can also have multiple PIDs, for example a sports magazine with several segments, where the entire program has a PID and each segment has its own PID, transmitted on a different Label Channel.

Label Channels are used in no particular order or hierarchy.

VBI_PID_CHANNEL_LCI_1 | Data from Teletext packet 8/30 format 2, Label Channel 1.
VBI_PID_CHANNEL_LCI_2 | Data from Teletext packet 8/30 format 2, Label Channel 2.
VBI_PID_CHANNEL_LCI_3 | Data from Teletext packet 8/30 format 2, Label Channel 3.
VBI_PID_CHANNEL_VPS | Data from a VPS packet (EN 300 231). These packets contain a CNI, PIL, PCS and PTY. They are transmitted once in each frame, i.e. 25 times per second.
VBI_PID_CHANNEL_PDC_DESCRIPTOR | Data from a DVB PDC descriptor (EN 300 468 Section 6.2.29). DVB PDC descriptors contain the same PIL as a VPS packet, but no CNI, PCS or PTY.
VBI_PID_CHANNEL_XDS_CURRENT | Data from an XDS Current Program ID packet (EIA 608-B Section 9). XDS Current/Future Program ID packets contain a PIL and tape-delayed flag. Current class packets refer to the currently transmitted program, Future class packets to the next program. Decoding of XDS Current/Future Program ID packets is not implemented yet.
VBI_PID_CHANNEL_XDS_FUTURE | Data from an XDS Future Program ID packet.
VBI_MAX_PID_CHANNELS | Note this value may change.

Examples
  examples/pdc2.c.

## vbi_pcs_audio

enum vbi_pcs_audio

PDC Program Control Status - Audio.

This information is available with Teletext and VPS program IDs and returned in struct vbi_program_id by the low level functions vbi_decode_teletext_8302_pdc(), vbi_decode_vps_pdc() and the vbi_decoder event `VBI_EVENT_PROG_ID`.

Since
  0.2.34

Enumerator
VBI_PCS_AUDIO_UNKNOWN | Nothing known about audio channels.
VBI_PCS_AUDIO_MONO | Mono audio is broadcast.
VBI_PCS_AUDIO_STEREO | Stereo audio.
VBI_PCS_AUDIO_BILINGUAL | Primary language on left channel, secondary on right.

## Function Documentation

## vbi_pil_is_valid_date()

vbi_bool vbi_pil_is_valid_date | ( | vbi_pil | pil | ) |

extern

Parameters

  pil | Program Identification Label.

Determines if pil represents a valid date and time.

Since PILs have no year field February 29th is considered valid. You can find out if this date is valid in a given year with the vbi_pil_to_time() function.

24:00 is not valid (an unreal hour) as defined in EN 300 231 Annex F and EIA 608-B Section 9.5.1.1.

Returns
  `TRUE` if pil represents a valid date and time, `FALSE` if pil contains an unreal date or time (e.g. Jan 0 27:61), a service code or unallocated code.

Since
  0.2.34

References VBI_PIL_DAY, VBI_PIL_HOUR, VBI_PIL_MINUTE, and VBI_PIL_MONTH.

Referenced by vbi_pil_lto_to_time(), and vbi_pil_to_time().

## vbi_pil_to_time()

time_t vbi_pil_to_time | ( | vbi_pil | pil,
|  | time_t | start,
|  | const char * | tz )

extern

Parameters

  pil | Program Identification Label (PIL) to convert.
  start | The most recently announced start time of the program. If zero the current system time will be used.
  tz | A time zone name in the same format as the TZ environment variable. If `NULL` the current value of TZ will be used.

This function converts a PIL to a time_t in the same manner localtime() converts a broken-down time to time_t.

Since PILs do not contain a year field, the year is determined from the start parameter, that is the most recently announced start time of the program or "AT-1" in EN 300 231 parlance. If pil contains a month more than five months after start, pil is assumed to refer to an earlier date than start.

pil is assumed to be a time in the time zone tz. start will be converted to a local time in the same time zone to determine the correct year.

Teletext packet 8/30 format 2, VPS and DVB PDC descriptors give a PIL relative to the time zone of the intended audience of the program. Ideally the time zone would be specified as a geographic area like "Europe/London", such that the function can determine the correct offset from UTC and if daylight-saving time is in effect at the specified date. See the documentation of the localtime() function and the TZ environment variable for details.

XDS Current/Future Program ID packets give a PIL relative to UTC. Just specify time zone "UTC" in this case.

Returns
  The PIL as a time_t, that is the number of seconds since 1970-01-01 00:00 UTC. On error the function returns (time_t) -1:
  - pil does not contain a valid date or time. February 29th is a valid date only if the estimated year is a leap year.
  - tz is empty or contains an equal sign '='.
  - start is zero and the current system time could not be determined.
  - The time specified by pil, start and tz cannot be represented as a time_t value.
  - Insufficient memory was available.

Since
  0.2.34

Bug
  This function is not thread safe unless tz is `NULL`. That is a limitation of the C library which permits the conversion of a broken-down time in an arbitrary time zone only by setting the TZ environment variable. The function may also fail to restore the value of TZ if insufficient memory is available.

References VBI_PIL_HOUR, vbi_pil_is_valid_date(), and VBI_PIL_MINUTE.

## vbi_pil_lto_to_time()

time_t vbi_pil_lto_to_time | ( | vbi_pil | pil,
|  | time_t | start,
|  | int | seconds_east )

extern

Parameters

  pil | Program Identification Label (PIL) to convert.
  start | The most recently announced start time of the program. If zero the current system time will be used.
  seconds_east | A time zone specified as an offset in seconds east of UTC, for example +1 * 60 * 60 for CET. seconds_east may include a daylight-saving time (DST) offset.

This function converts a PIL to a time_t in the same manner localtime() converts a broken-down time to time_t.

Since PILs do not contain a year field, the year is determined from the start parameter, that is the most recently announced start time of the program or "AT-1" in EN 300 231 parlance. If pil contains a month more than five months after start, pil is assumed to refer to an earlier date than start.

pil is assumed to be a time in the time zone specified by seconds_east. start will be converted to a local time in the same time zone to determine the correct year.

Teletext packet 8/30 format 2, VPS and DVB PDC descriptors give a PIL relative to the time zone of the intended audience of the program. An offset from UTC including the DST offset in effect at the specified date may be available on Teletext program announcement pages (see struct vbi_preselection). Another offset from UTC including the current DST offset is available as `VBI_EVENT_LOCAL_TIME`, but of course that information is insufficient to determine if DST is in effect at other dates.

XDS Current/Future Program ID packets give a PIL relative to UTC, so seconds_east should be zero.

Returns
  The PIL as a time_t, that is the number of seconds since 1970-01-01 00:00 UTC. On error the function returns (time_t) -1:
  - pil does not contain a valid date or time. February 29th is a valid date only if the estimated year is a leap year.
  - start is zero and the current system time could not be determined.
  - The time specified by pil, start and seconds_east cannot be represented as a time_t value (2038 is closer than you think!).

Since
  0.2.34

Bug
  This function is not thread safe. That is a limitation of the C library which permits the conversion of a broken-down time in an arbitrary time zone only by setting the TZ environment variable. The function may also fail to restore the value of TZ if insufficient memory is available.

References vbi_pil_is_valid_date().

## vbi_pty_validity_window()

vbi_bool vbi_pty_validity_window | ( | time_t * | begin,
|  | time_t * | end,
|  | time_t | last_transm,
|  | const char * | tz )

extern

Parameters

  begin | The begin of the validity of the PTY will be stored here.
  end | The end of the validity of the PTY will be stored here.
  last_transm | The last time when a program ID with the PTY in question was broadcast by the network.
  tz | A time zone name in the same format as the TZ environment variable. If `NULL` the current value of TZ will be used.

This function calculates the validity time window of a Program Type (PTY) code according to EN 300 231. That is the time window where a network can be expected to broadcast another program with the same PTY, approximately up to four weeks after its last transmission. When the PTY is a series code (>= 0x80) and not transmitted again before end, the network may assign the code to another series.

tz is the time zone of the intended audience of the program. Ideally the time zone would be specified as a geographic area like "Europe/London", such that the function can determine if daylight-saving time is in effect at time or at the end of the validity time window. See the documentation of the localtime() function and the TZ environment variable for details. If no time zone name is available "UTC" should be specified, the returned end time may be off by one hour in this case.

Returns
  On error the function returns `FALSE` and *begin and *end remain unchanged:
  - tz is empty or contains an equal sign '='.
  - The end time cannot be represented as a time_t value (December 2037 is closer than you think!).
  - Insufficient memory was available.

Since
  0.2.34

Bug
  This function is not thread safe unless tz is `NULL`. That is a limitation of the C library which permits the conversion of a broken-down time in an arbitrary time zone only by setting the TZ environment variable. The function may also fail to restore the value of TZ if insufficient memory is available.

Referenced by vbi_pil_validity_window().

## vbi_pil_validity_window()

vbi_bool vbi_pil_validity_window | ( | time_t * | begin,
|  | time_t * | end,
|  | vbi_pil | pil,
|  | time_t | start,
|  | const char * | tz )

extern

Parameters

  begin | The start of the validity of the PIL will be stored here.
  end | The end of the validity of the PIL will be stored here.
  pil | Program Identification Label (PIL).
  start | The most recently announced start time of the program. If zero the current system time will be used.
  tz | A time zone name in the same format as the TZ environment variable. If `NULL` the current value of TZ will be used.

This function calculates the validity time window of a PIL according to EN 300 231. That is the time window where a network can be expected to broadcast this PIL, usually from 00:00 on the same day until 04:00 on the next day.

Since PILs do not contain a year field, the year is determined from the start parameter, that is the most recently announced start time of the program or "AT-1" in EN 300 231 parlance. If pil contains a month more than five months after start, pil is assumed to refer to an earlier date than start.

pil is assumed to be a time in the time zone specified by seconds_east. start will be converted to a local time in the same time zone to determine the correct year.

Teletext packet 8/30 format 2, VPS and DVB PDC descriptors give a PIL relative to the time zone of the intended audience of the program. Ideally the time zone would be specified as a geographic area like "Europe/London", such that the function can determine the correct offset from UTC and if daylight-saving time is in effect at any time within the validity window. See the documentation of the localtime() function and the TZ environment variable for details.

If pil is `VBI_PIL_NSPV` this function returns the same values as vbi_pty_validity_window().

Returns
  On error the function returns `FALSE:`
  - pil is not `VBI_PIL_NSPV` and does not contain a valid date or time. February 29th is a valid date only if the estimated year is a leap year.
  - tz is empty or contains an equal sign '='.
  - start is zero and the current system time could not be determined.
  - The time specified by pil, start and tz cannot be represented as a time_t value.
  - Insufficient memory was available.

Since
  0.2.34

Bug
  This function is not thread safe unless tz is `NULL`. That is a limitation of the C library which permits the conversion of a broken-down time in an arbitrary time zone only by setting the TZ environment variable. The function may also fail to restore the value of TZ if insufficient memory is available.

References VBI_PIL_CONTINUE, VBI_PIL_DAY, VBI_PIL_INHIBIT_TERMINATE, VBI_PIL_INTERRUPTION, VBI_PIL_MONTH, VBI_PIL_NSPV, VBI_PIL_TIMER_CONTROL, and vbi_pty_validity_window().

## vbi_pil_lto_validity_window()

vbi_bool vbi_pil_lto_validity_window | ( | time_t * | begin,
|  | time_t * | end,
|  | vbi_pil | pil,
|  | time_t | start,
|  | int | seconds_east )

extern

Parameters

  begin | The start of the validity of the PIL will be stored here.
  end | The end of the validity of the PIL will be stored here.
  pil | Program Identification Label (PIL).
  start | The most recently announced start time of the program. If zero the current system time will be used.
  seconds_east | A time zone specified as an offset in seconds east of UTC, for example +1 * 60 * 60 for CET. seconds_east may include a daylight-saving time (DST) offset.

This function calculates the validity time window of a PIL according to EN 300 231. That is the time window where a network can be expected to broadcast this PIL, usually from 00:00 on the same day until exclusive 04:00 on the next day.

Since PILs do not contain a year field, the year is determined from the start parameter, that is the most recently announced start time of the program or "AT-1" in EN 300 231 parlance. If pil contains a month more than five months after start, pil is assumed to refer to an earlier date than start.

pil is assumed to be a time in the time zone specified by seconds_east. start will be converted to a local time in the same time zone to determine the correct year.

Teletext packet 8/30 format 2, VPS and DVB PDC descriptors give a PIL relative to the time zone of the intended audience of the program. An offset from UTC including the DST offset in effect at the specified date may be available on Teletext program announcement pages (see struct vbi_preselection). Another offset from UTC including the current DST offset is available as `VBI_EVENT_LOCAL_TIME`. But of course these offsets are insufficient to determine if DST is in effect at any given date, so the returned begin or end may be off by one hour if the validity window straddles a DST discontinuity.

If pil is `VBI_PIL_NSPV` this function ignores seconds_east and returns the same values as vbi_pty_validity_window().

Returns
  On error the function returns `FALSE:`
  - pil is not `VBI_PIL_NSPV` and does not contain a valid date or time. February 29th is a valid date only if the estimated year is a leap year.
  - start is zero and the current system time could not be determined.
  - The time specified by pil, start and seconds_east cannot be represented as a time_t value.

Since
  0.2.34

Bug
  This function is not thread safe. That is a limitation of the C library which permits the conversion of a broken-down time in an arbitrary time zone only by setting the TZ environment variable. The function may also fail to restore the value of TZ if insufficient memory is available.

References VBI_PIL_CONTINUE, VBI_PIL_DAY, VBI_PIL_INHIBIT_TERMINATE, VBI_PIL_INTERRUPTION, VBI_PIL_MONTH, VBI_PIL_NSPV, and VBI_PIL_TIMER_CONTROL.