ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Linux-DVB/DVB.pm
(Generate patch)

Comparing Linux-DVB/DVB.pm (file contents):
Revision 1.6 by root, Tue Apr 5 03:42:21 2005 UTC vs.
Revision 1.13 by root, Wed May 24 21:03:08 2006 UTC

19 19
20Noteworthy differences to the C API: unions and sub-structs are usually 20Noteworthy differences to the C API: unions and sub-structs are usually
21translated into flat perl hashes, i.e C<struct.u.qam.symbol_rate> 21translated into flat perl hashes, i.e C<struct.u.qam.symbol_rate>
22becomes C<< $struct->{symbol_rate} >>. 22becomes C<< $struct->{symbol_rate} >>.
23 23
24Noteworthy limitations of this module include: no way to set the 24Noteworthy limitations of this module include: No interface to the video,
25frequency or diseqc. No interface to the video, audio and net devices.
26If you need this functionality bug the author. 25audio and net devices. If you need this functionality bug the author.
27 26
28=cut 27=cut
29 28
30package Linux::DVB; 29package Linux::DVB;
31 30
32use Fcntl (); 31use Fcntl ();
33 32
34BEGIN { 33BEGIN {
35 $VERSION = '0.2'; 34 $VERSION = '1.0';
36 @ISA = qw(Exporter); 35 @ISA = qw(Exporter);
37 36
38 require XSLoader; 37 require XSLoader;
39 XSLoader::load __PACKAGE__, $VERSION; 38 XSLoader::load __PACKAGE__, $VERSION;
40 39
106 %$self = ( %$self, %{ $self->frontend_info } ); 105 %$self = ( %$self, %{ $self->frontend_info } );
107 106
108 $self; 107 $self;
109} 108}
110 109
111sub frontend_info { _frontend_info ($_[0]{fd}) }
112sub status { _read_status ($_[0]{fd}) }
113sub ber { _read_ber ($_[0]{fd}) }
114sub snr { _snr ($_[0]{fd}) }
115sub signal_strength { _signal_strength ($_[0]{fd}) }
116sub uncorrected { _uncorrected ($_[0]{fd}) }
117
118=item $fe->set (parameter => value, ...) 110=item $fe->set (parameter => value, ...)
119 111
120Sets frontend parameters. All values are stuffed into the 112Sets frontend parameters. All values are stuffed into the
121C<dvb_frontend_parameters> structure without conversion and passed to 113C<dvb_frontend_parameters> structure without conversion and passed to
122FE_SET_FRONTEND. 114FE_SET_FRONTEND.
134 fec_inner => 126 fec_inner =>
135 127
136QAM frontends: 128QAM frontends:
137 129
138 symbol_rate => 130 symbol_rate =>
139 fec_inner =>
140 modulation => 131 modulation =>
141 132
142QFDM frontends: 133QFDM frontends:
143 134
144 bandwidth => 135 bandwidth =>
165 156
166 { 157 {
167 frequency => 426000000, # 426 Mhz 158 frequency => 426000000, # 426 Mhz
168 inversion => 0, # INVERSION_OFF 159 inversion => 0, # INVERSION_OFF
169 symbol_rate => 6900000, # 6.9 MB/s 160 symbol_rate => 6900000, # 6.9 MB/s
170 fec_inner => 0, # FEC_NONE
171 modulation => 3, # QAM_64 161 modulation => 3, # QAM_64
172 } 162 }
173 163
174=cut 164=cut
175 165
176sub parameters { _get ($_[0]{fd}, $_[0]{type}) } 166sub parameters { _get ($_[0]{fd}, $_[0]{type}) }
177sub get { _get ($_[0]{fd}, $_[0]{type}) } # unannounced alias 167sub get { _get ($_[0]{fd}, $_[0]{type}) } # unannounced alias
178sub event { _event ($_[0]{fd}, $_[0]{type}) } 168sub event { _event ($_[0]{fd}, $_[0]{type}) }
169
170=item $ok = $fe->diseqc_reset_overload
171
172If the bus has been automatically powered off due to power overload, this
173call restores the power to the bus. The call requires read/write access
174to the device. This call has no effect if the device is manually powered
175off. Not all DVB adapters support this call.
176
177=item $ok = $fe->diseqc_voltage (13|18)
178
179Set the DiSEqC voltage to either 13 or 18 volts.
180
181=item $ok = $fe->diseqc_tone (1|0)
182
183Enables (1) or disables (0) the DiSEqC continuous 22khz tone generation.
184
185=item $ok = $fe->diseqc_send_burst (0|1)
186
187Sends a 22KHz tone burst of type SEC_MINI_A (0) or SEC_MINI_B (1).
188
189=item $ok = $fe->diseqc_cmd ($command)
190
191Sends a DiSEqC command.
192
193=item $reply = $fe->diseqc_reply ($timeout)
194
195Receives a reply to a DiSEqC 2.0 command (or undef).
196
197=cut
179 198
180package Linux::DVB::Demux; 199package Linux::DVB::Demux;
181 200
182@ISA = qw(Linux::DVB); 201@ISA = qw(Linux::DVB);
183 202
346 365
347=cut 366=cut
348 367
349our %nibble_to_genre = ( 368our %nibble_to_genre = (
350 0x1 => { 369 0x1 => {
351 0x0 => 'Movie / Drama', 370 0x0 => 'Movie/Drama (general)',
352 0x1 => 'Movie - detective/thriller', 371 0x1 => 'Movie - detective/thriller',
353 0x2 => 'Movie - adventure/western/war', 372 0x2 => 'Movie - adventure/western/war',
354 0x3 => 'Movie - science fiction/fantasy/horror', 373 0x3 => 'Movie - science fiction/fantasy/horror',
355 0x4 => 'Movie - comedy', 374 0x4 => 'Movie - comedy',
356 0x5 => 'Movie - soap/melodrama/folkloric', 375 0x5 => 'Movie - soap/melodrama/folkloric',
357 0x6 => 'Movie - romance', 376 0x6 => 'Movie - romance',
358 0x7 => 'Movie - serious/classical/religious/historical movie/drama', 377 0x7 => 'Movie - serious/classical/religious/historical movie/drama',
359 0x8 => 'Movie - adult movie/drama', 378 0x8 => 'Movie - adult movie/drama',
360 }, 379 },
361 0x2 => { 380 0x2 => {
362 0x0 => 'News / Current Affairs', 381 0x0 => 'News/Current Affairs (general)',
363 0x1 => 'news/weather report', 382 0x1 => 'news/weather report',
364 0x2 => 'news magazine', 383 0x2 => 'news magazine',
365 0x3 => 'documentary', 384 0x3 => 'documentary',
366 0x4 => 'discussion/interview/debate', 385 0x4 => 'discussion/interview/debate',
367 }, 386 },
368 0x3 => { 387 0x3 => {
369 0x0 => 'Show / Game Show', 388 0x0 => 'Show/Game Show (general)',
370 0x1 => 'game show/quiz/contest', 389 0x1 => 'game show/quiz/contest',
371 0x2 => 'variety show', 390 0x2 => 'variety show',
372 0x3 => 'talk show', 391 0x3 => 'talk show',
373 }, 392 },
374 0x4 => { 393 0x4 => {
375 0x0 => 'Sports', 394 0x0 => 'Sports (general)',
376 0x1 => 'special events (Olympic Games, World Cup etc.)', 395 0x1 => 'special events (Olympic Games, World Cup etc.)',
377 0x2 => 'sports magazines', 396 0x2 => 'sports magazines',
378 0x3 => 'football/soccer', 397 0x3 => 'football/soccer',
379 0x4 => 'tennis/squash', 398 0x4 => 'tennis/squash',
380 0x5 => 'team sports (excluding football)', 399 0x5 => 'team sports (excluding football)',
384 0x9 => 'winter sports', 403 0x9 => 'winter sports',
385 0xA => 'equestrian', 404 0xA => 'equestrian',
386 0xB => 'martial sports', 405 0xB => 'martial sports',
387 }, 406 },
388 0x5 => { 407 0x5 => {
389 0x0 => 'Childrens / Youth', 408 0x0 => 'Childrens/Youth (general)',
390 0x1 => "pre-school children's programmes", 409 0x1 => "pre-school children's programmes",
391 0x2 => 'entertainment programmes for 6 to 14', 410 0x2 => 'entertainment programmes for 6 to 14',
392 0x3 => 'entertainment programmes for 10 to 16', 411 0x3 => 'entertainment programmes for 10 to 16',
393 0x4 => 'informational/educational/school programmes', 412 0x4 => 'informational/educational/school programmes',
394 0x5 => 'cartoons/puppets', 413 0x5 => 'cartoons/puppets',
395 }, 414 },
396 0x6 => { 415 0x6 => {
397 0x0 => 'Music / Ballet / Dance', 416 0x0 => 'Music/Ballet/Dance (general)',
398 0x1 => 'rock/pop', 417 0x1 => 'rock/pop',
399 0x2 => 'serious music/classical music', 418 0x2 => 'serious music or classical music',
400 0x3 => 'folk/traditional music', 419 0x3 => 'folk/traditional music',
401 0x4 => 'jazz', 420 0x4 => 'jazz',
402 0x5 => 'musical/opera', 421 0x5 => 'musical/opera',
403 0x6 => 'ballet', 422 0x6 => 'ballet',
404 }, 423 },
405 0x7 => { 424 0x7 => {
406 0x0 => 'Arts / Culture', 425 0x0 => 'Arts/Culture (without music, general)',
407 0x1 => 'performing arts', 426 0x1 => 'performing arts',
408 0x2 => 'fine arts', 427 0x2 => 'fine arts',
409 0x3 => 'religion', 428 0x3 => 'religion',
410 0x4 => 'popular culture/traditional arts', 429 0x4 => 'popular culture/traditional arts',
411 0x5 => 'literature', 430 0x5 => 'literature',
415 0x9 => 'new media', 434 0x9 => 'new media',
416 0xA => 'arts/culture magazines', 435 0xA => 'arts/culture magazines',
417 0xB => 'fashion', 436 0xB => 'fashion',
418 }, 437 },
419 0x8 => { 438 0x8 => {
420 0x0 => 'Social / Policical / Economics', 439 0x0 => 'Social/Policical/Economics (general)',
421 0x1 => 'magazines/reports/documentary', 440 0x1 => 'magazines/reports/documentary',
422 0x2 => 'economics/social advisory', 441 0x2 => 'economics/social advisory',
423 0x3 => 'remarkable people', 442 0x3 => 'remarkable people',
424 }, 443 },
425 0x9 => { 444 0x9 => {
426 0x0 => 'Education / Science / Factual', 445 0x0 => 'Education/Science/Factual (general)',
427 0x1 => 'nature/animals/environment', 446 0x1 => 'nature/animals/environment',
428 0x2 => 'technology/natural sciences', 447 0x2 => 'technology/natural sciences',
429 0x3 => 'medicine/physiology/psychology', 448 0x3 => 'medicine/physiology/psychology',
430 0x4 => 'foreign countries/expeditions', 449 0x4 => 'foreign countries/expeditions',
431 0x5 => 'social/spiritual sciences', 450 0x5 => 'social/spiritual sciences',
432 0x6 => 'further education', 451 0x6 => 'further education',
433 0x7 => 'languages', 452 0x7 => 'languages',
434 }, 453 },
435 0xA => { 454 0xA => {
436 0x0 => 'Leisure / Hobbies', 455 0x0 => 'Leisure/Hobbies (general)',
437 0x1 => 'tourism/travel', 456 0x1 => 'tourism/travel',
438 0x2 => 'handicraft', 457 0x2 => 'handicraft',
439 0x3 => 'motoring', 458 0x3 => 'motoring',
440 0x4 => 'fitness & health', 459 0x4 => 'fitness & health',
441 0x5 => 'cooking', 460 0x5 => 'cooking',
442 0x6 => 'advertizement/shopping', 461 0x6 => 'advertizement/shopping',
443 0x7 => 'gardening', 462 0x7 => 'gardening',
444 }, 463 },
445 0xB => { 464 0xB => {
446 0x0 => 'Original Language', 465 0x0 => '(original language)',
447 0x1 => 'black & white', 466 0x1 => '(black & white)',
448 0x2 => 'unpublished', 467 0x2 => '(unpublished)',
449 0x3 => 'live broadcast', 468 0x3 => '(live broadcast)',
450 }, 469 },
451); 470);
452 471
472=item ($sec,$min,$hour) = Linux::DVB::Decode::time $hms
473
474=item ($mday,$mon,$year) = Linux::DVB::Decode::date $mjd
475
453=item ($sec,$min,$hour,$mday,$mon,$year) = Linux::DVB::Decode::time $mjd, $time 476=item ($sec,$min,$hour,$mday,$mon,$year) = Linux::DVB::Decode::datetime $mjd, $hms
477
478=item $sec = Linux::DVB::Decode::time_linear $hms
479
480=item $sec = Linux::DVB::Decode::datetime_linear $mjd, $hms
454 481
455Break down a "DVB time" (modified julian date + bcd encoded seconds) into 482Break down a "DVB time" (modified julian date + bcd encoded seconds) into
456it's components in UTC (i.e. use Time::Local::timegm to convert to UNIX 483it's components (non-C<_linear>) or into a seconds count (C<_linear>
457time). 484variants) since the epoch (C<datetime_linear>) or the start of the day
485(C<time_linear>).
458 486
459=cut 487The format of the returns value of the date and datetime functions is
488I<not> compatible with C<Time::Local>. Use the C<_linear> functions
489instead.
460 490
491Example:
492
493 my $time = Linux::DVB::Decode::datetime_linear $mjd, $hms
494 printf "Starts at %s\n",
495 POSIX::strftime "%Y-%m-%d %H:%M:%S",
496 localtime $time;
497
498=cut
499
461sub time($$) { 500sub time($) {
462 my ($mjd, $time) = @_; 501 my ($time) = @_;
502
503 # Time is in UTC, 24 bit, every nibble one digit in BCD from right to left
504 my $hour = sprintf "%02x", ($time >> 16) & 0xFF;
505 my $minute = sprintf "%02x", ($time >> 8) & 0xFF;
506 my $second = sprintf "%02x", ($time ) & 0xFF;
507
508 ($second, $minute, $hour)
509}
510
511sub date($) {
512 my ($mjd) = @_;
463 513
464 # Date is given in Modified Julian Date 514 # Date is given in Modified Julian Date
465 # Decoding routines taken from ANNEX C, ETSI EN 300 468 (DVB SI) 515 # Decoding routines taken from ANNEX C, ETSI EN 300 468 (DVB SI)
466 my $y_ = int ($mjd - 15078.2) / 365.25; 516 my $y_ = int (($mjd - 15078.2) / 365.25);
467 my $m_ = int (($mjd - 14956.1 - int ($y_ * 365.25)) / 30.6001); 517 my $m_ = int (($mjd - 14956.1 - int ($y_ * 365.25)) / 30.6001);
468 my $day = $mjd - 14956 - int ($y_ * 365.25) - int ($m_ * 30.6001); 518 my $day = $mjd - 14956 - int ($y_ * 365.25) - int ($m_ * 30.6001);
469 my $k = $m_ == 14 or $m_ == 15 ? 1 : 0; 519 my $k = $m_ == 14 or $m_ == 15 ? 1 : 0;
470 my $year = $y_ + $k + 1900; 520 my $year = $y_ + $k + 1900;
471 my $month = $m_ - 1 - $k * 12; 521 my $month = $m_ - 1 - $k * 12;
472 522
473 # Time is in UTC, 24 bit, every nibble one digit in BCD from right to left 523 ($day, $month, $year)
474 my $hour = sprintf "%02x", ($time >> 16) & 0xFF; 524}
475 my $minute = sprintf "%02x", ($time >> 8) & 0xFF;
476 my $second = sprintf "%02x", ($time ) & 0xFF;
477 525
526sub datetime($$) {
527 (Linux::DVB::Decode::time $_[1], date $_[0])
528}
529
530sub time_linear($) {
531 my ($s, $m, $h) = Linux::DVB::Decode::time $_[0];
532
533 (($h * 60) + $m * 60) + $s
534}
535
536sub datetime_linear($$) {
478 return ($second, $minute, $hour, $day, $month, $year); 537 my ($sec, $min, $hour, $mday, $mon, $year) =
538 Linux::DVB::Decode::datetime $_[0], $_[1];
539
540 require Time::Local;
541 Time::Local::timegm ($sec, $min, $hour, $mday, $mon - 1, $year)
479} 542}
480 543
481=back 544=back
482 545
483=head1 AUTHORS 546=head1 AUTHORS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines