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.7 by root, Mon Apr 11 21:14:12 2005 UTC vs.
Revision 1.10 by root, Tue Apr 12 01:22:04 2005 UTC

30package Linux::DVB; 30package Linux::DVB;
31 31
32use Fcntl (); 32use Fcntl ();
33 33
34BEGIN { 34BEGIN {
35 $VERSION = '0.3'; 35 $VERSION = '0.4';
36 @ISA = qw(Exporter); 36 @ISA = qw(Exporter);
37 37
38 require XSLoader; 38 require XSLoader;
39 XSLoader::load __PACKAGE__, $VERSION; 39 XSLoader::load __PACKAGE__, $VERSION;
40 40
346 346
347=cut 347=cut
348 348
349our %nibble_to_genre = ( 349our %nibble_to_genre = (
350 0x1 => { 350 0x1 => {
351 0x0 => 'Movie / Drama', 351 0x0 => 'Movie/Drama (general)',
352 0x1 => 'Movie - detective/thriller', 352 0x1 => 'Movie - detective/thriller',
353 0x2 => 'Movie - adventure/western/war', 353 0x2 => 'Movie - adventure/western/war',
354 0x3 => 'Movie - science fiction/fantasy/horror', 354 0x3 => 'Movie - science fiction/fantasy/horror',
355 0x4 => 'Movie - comedy', 355 0x4 => 'Movie - comedy',
356 0x5 => 'Movie - soap/melodrama/folkloric', 356 0x5 => 'Movie - soap/melodrama/folkloric',
357 0x6 => 'Movie - romance', 357 0x6 => 'Movie - romance',
358 0x7 => 'Movie - serious/classical/religious/historical movie/drama', 358 0x7 => 'Movie - serious/classical/religious/historical movie/drama',
359 0x8 => 'Movie - adult movie/drama', 359 0x8 => 'Movie - adult movie/drama',
360 }, 360 },
361 0x2 => { 361 0x2 => {
362 0x0 => 'News / Current Affairs', 362 0x0 => 'News/Current Affairs (general)',
363 0x1 => 'news/weather report', 363 0x1 => 'news/weather report',
364 0x2 => 'news magazine', 364 0x2 => 'news magazine',
365 0x3 => 'documentary', 365 0x3 => 'documentary',
366 0x4 => 'discussion/interview/debate', 366 0x4 => 'discussion/interview/debate',
367 }, 367 },
368 0x3 => { 368 0x3 => {
369 0x0 => 'Show / Game Show', 369 0x0 => 'Show/Game Show (general)',
370 0x1 => 'game show/quiz/contest', 370 0x1 => 'game show/quiz/contest',
371 0x2 => 'variety show', 371 0x2 => 'variety show',
372 0x3 => 'talk show', 372 0x3 => 'talk show',
373 }, 373 },
374 0x4 => { 374 0x4 => {
375 0x0 => 'Sports', 375 0x0 => 'Sports (general)',
376 0x1 => 'special events (Olympic Games, World Cup etc.)', 376 0x1 => 'special events (Olympic Games, World Cup etc.)',
377 0x2 => 'sports magazines', 377 0x2 => 'sports magazines',
378 0x3 => 'football/soccer', 378 0x3 => 'football/soccer',
379 0x4 => 'tennis/squash', 379 0x4 => 'tennis/squash',
380 0x5 => 'team sports (excluding football)', 380 0x5 => 'team sports (excluding football)',
384 0x9 => 'winter sports', 384 0x9 => 'winter sports',
385 0xA => 'equestrian', 385 0xA => 'equestrian',
386 0xB => 'martial sports', 386 0xB => 'martial sports',
387 }, 387 },
388 0x5 => { 388 0x5 => {
389 0x0 => 'Childrens / Youth', 389 0x0 => 'Childrens/Youth (general)',
390 0x1 => "pre-school children's programmes", 390 0x1 => "pre-school children's programmes",
391 0x2 => 'entertainment programmes for 6 to 14', 391 0x2 => 'entertainment programmes for 6 to 14',
392 0x3 => 'entertainment programmes for 10 to 16', 392 0x3 => 'entertainment programmes for 10 to 16',
393 0x4 => 'informational/educational/school programmes', 393 0x4 => 'informational/educational/school programmes',
394 0x5 => 'cartoons/puppets', 394 0x5 => 'cartoons/puppets',
395 }, 395 },
396 0x6 => { 396 0x6 => {
397 0x0 => 'Music / Ballet / Dance', 397 0x0 => 'Music/Ballet/Dance (general)',
398 0x1 => 'rock/pop', 398 0x1 => 'rock/pop',
399 0x2 => 'serious music/classical music', 399 0x2 => 'serious music or classical music',
400 0x3 => 'folk/traditional music', 400 0x3 => 'folk/traditional music',
401 0x4 => 'jazz', 401 0x4 => 'jazz',
402 0x5 => 'musical/opera', 402 0x5 => 'musical/opera',
403 0x6 => 'ballet', 403 0x6 => 'ballet',
404 }, 404 },
405 0x7 => { 405 0x7 => {
406 0x0 => 'Arts / Culture', 406 0x0 => 'Arts/Culture (without music, general)',
407 0x1 => 'performing arts', 407 0x1 => 'performing arts',
408 0x2 => 'fine arts', 408 0x2 => 'fine arts',
409 0x3 => 'religion', 409 0x3 => 'religion',
410 0x4 => 'popular culture/traditional arts', 410 0x4 => 'popular culture/traditional arts',
411 0x5 => 'literature', 411 0x5 => 'literature',
415 0x9 => 'new media', 415 0x9 => 'new media',
416 0xA => 'arts/culture magazines', 416 0xA => 'arts/culture magazines',
417 0xB => 'fashion', 417 0xB => 'fashion',
418 }, 418 },
419 0x8 => { 419 0x8 => {
420 0x0 => 'Social / Policical / Economics', 420 0x0 => 'Social/Policical/Economics (general)',
421 0x1 => 'magazines/reports/documentary', 421 0x1 => 'magazines/reports/documentary',
422 0x2 => 'economics/social advisory', 422 0x2 => 'economics/social advisory',
423 0x3 => 'remarkable people', 423 0x3 => 'remarkable people',
424 }, 424 },
425 0x9 => { 425 0x9 => {
426 0x0 => 'Education / Science / Factual', 426 0x0 => 'Education/Science/Factual (general)',
427 0x1 => 'nature/animals/environment', 427 0x1 => 'nature/animals/environment',
428 0x2 => 'technology/natural sciences', 428 0x2 => 'technology/natural sciences',
429 0x3 => 'medicine/physiology/psychology', 429 0x3 => 'medicine/physiology/psychology',
430 0x4 => 'foreign countries/expeditions', 430 0x4 => 'foreign countries/expeditions',
431 0x5 => 'social/spiritual sciences', 431 0x5 => 'social/spiritual sciences',
432 0x6 => 'further education', 432 0x6 => 'further education',
433 0x7 => 'languages', 433 0x7 => 'languages',
434 }, 434 },
435 0xA => { 435 0xA => {
436 0x0 => 'Leisure / Hobbies', 436 0x0 => 'Leisure/Hobbies (general)',
437 0x1 => 'tourism/travel', 437 0x1 => 'tourism/travel',
438 0x2 => 'handicraft', 438 0x2 => 'handicraft',
439 0x3 => 'motoring', 439 0x3 => 'motoring',
440 0x4 => 'fitness & health', 440 0x4 => 'fitness & health',
441 0x5 => 'cooking', 441 0x5 => 'cooking',
442 0x6 => 'advertizement/shopping', 442 0x6 => 'advertizement/shopping',
443 0x7 => 'gardening', 443 0x7 => 'gardening',
444 }, 444 },
445 0xB => { 445 0xB => {
446 0x0 => 'Original Language', 446 0x0 => '(original language)',
447 0x1 => 'black & white', 447 0x1 => '(black & white)',
448 0x2 => 'unpublished', 448 0x2 => '(unpublished)',
449 0x3 => 'live broadcast', 449 0x3 => '(live broadcast)',
450 }, 450 },
451); 451);
452 452
453=item ($sec,$min,$hour) = Linux::DVB::Decode::time $hms
454
455=item ($mday,$mon,$year) = Linux::DVB::Decode::date $mjd
456
453=item ($sec,$min,$hour,$mday,$mon,$year) = Linux::DVB::Decode::time $mjd, $time 457=item ($sec,$min,$hour,$mday,$mon,$year) = Linux::DVB::Decode::datetime $mjd, $hms
458
459=item $sec = Linux::DVB::Decode::time_linear $hms
460
461=item $sec = Linux::DVB::Decode::datetime_linear $mjd, $hms
454 462
455Break down a "DVB time" (modified julian date + bcd encoded seconds) into 463Break 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 464it's components (non-C<_linear>) or into a seconds count (C<_linear>
457time). 465variants) since the epoch (C<datetime_linear>) or the start of the day
466(C<time_linear>).
458 467
459=cut 468The format of the returns value of the date and datetime functions is
469I<not> compatible with C<Time::Local>. Use the C<_linear> functions
470instead.
460 471
472Example:
473
474 my $time = Linux::DVB::Decode::datetime_linear $mjd, $hms
475 printf "Starts at %s\n",
476 POSIX::strftime "%Y-%m-%d %H:%M:%S",
477 localtime $time;
478
479=cut
480
461sub time($$) { 481sub time($) {
462 my ($mjd, $time) = @_; 482 my ($time) = @_;
483
484 # Time is in UTC, 24 bit, every nibble one digit in BCD from right to left
485 my $hour = sprintf "%02x", ($time >> 16) & 0xFF;
486 my $minute = sprintf "%02x", ($time >> 8) & 0xFF;
487 my $second = sprintf "%02x", ($time ) & 0xFF;
488
489 ($second, $minute, $hour)
490}
491
492sub date($) {
493 my ($mjd) = @_;
463 494
464 # Date is given in Modified Julian Date 495 # Date is given in Modified Julian Date
465 # Decoding routines taken from ANNEX C, ETSI EN 300 468 (DVB SI) 496 # Decoding routines taken from ANNEX C, ETSI EN 300 468 (DVB SI)
466 my $y_ = int ($mjd - 15078.2) / 365.25; 497 my $y_ = int (($mjd - 15078.2) / 365.25);
467 my $m_ = int (($mjd - 14956.1 - int ($y_ * 365.25)) / 30.6001); 498 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); 499 my $day = $mjd - 14956 - int ($y_ * 365.25) - int ($m_ * 30.6001);
469 my $k = $m_ == 14 or $m_ == 15 ? 1 : 0; 500 my $k = $m_ == 14 or $m_ == 15 ? 1 : 0;
470 my $year = $y_ + $k + 1900; 501 my $year = $y_ + $k + 1900;
471 my $month = $m_ - 1 - $k * 12; 502 my $month = $m_ - 1 - $k * 12;
472 503
473 # Time is in UTC, 24 bit, every nibble one digit in BCD from right to left 504 ($day, $month, $year)
474 my $hour = sprintf "%02x", ($time >> 16) & 0xFF; 505}
475 my $minute = sprintf "%02x", ($time >> 8) & 0xFF;
476 my $second = sprintf "%02x", ($time ) & 0xFF;
477 506
507sub datetime($$) {
508 (Linux::DVB::Decode::time $_[1], date $_[0])
509}
510
511sub time_linear($) {
512 my ($s, $m, $h) = Linux::DVB::Decode::time $_[0];
513
514 (($h * 60) + $m * 60) + $s
515}
516
517sub datetime_linear($$) {
478 return ($second, $minute, $hour, $day, $month, $year); 518 my ($sec, $min, $hour, $mday, $mon, $year) =
519 Linux::DVB::Decode::datetime $_[0], $_[1];
520
521 require Time::Local;
522 Time::Local::timegm ($sec, $min, $hour, $mday, $mon - 1, $year)
479} 523}
480 524
481=back 525=back
482 526
483=head1 AUTHORS 527=head1 AUTHORS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines