Mercurial > libdvdnav.hg
comparison vm.c @ 90:eeabf5a51b2b src
Improve chapter selection functions.
author | jcdutton |
---|---|
date | Tue, 03 Sep 2002 07:50:45 +0000 |
parents | 929f732a0135 |
children | c1dff1899bda |
comparison
equal
deleted
inserted
replaced
89:0fbef4901e2c | 90:eeabf5a51b2b |
---|---|
436 /* return 0; */ | 436 /* return 0; */ |
437 } | 437 } |
438 return vm_top_pg(vm); | 438 return vm_top_pg(vm); |
439 } | 439 } |
440 | 440 |
441 int vm_prev_part(vm_t *vm) | 441 /* Get the current title and part from the current playing position. */ |
442 { | 442 /* returns S_ERR if not in the VTS_DOMAIN */ |
443 link_t link_values; | 443 /* FIXME: Should we do some locking here ? */ |
444 int vm_get_current_title_part(vm_t *vm, int *title_result, int *part_result) | |
445 { | |
444 vts_ptt_srpt_t *vts_ptt_srpt; | 446 vts_ptt_srpt_t *vts_ptt_srpt; |
445 int title, part=0; | 447 int title=0, part=0; |
446 int found = 0; | 448 int found = 0; |
447 int16_t pgcN, pgN; | 449 int16_t pgcN, pgN; |
448 | 450 |
449 if((!vm) || (!vm->vtsi) ) | 451 if((!vm) || (!vm->vtsi) ) |
450 return S_ERR; | 452 return S_ERR; |
453 | |
454 if(!title_result || !part_result) { | |
455 fprintf(MSG_OUT, "libdvdnav:vm_get_current_title_part: Passed a NULL pointer"); | |
456 return S_ERR; | |
457 } | |
451 | 458 |
452 if(!(vm->state.pgc) ) | 459 if(!(vm->state.pgc) ) |
453 return S_ERR; | 460 return S_ERR; |
454 if (vm->state.domain != VTS_DOMAIN) | 461 if (vm->state.domain != VTS_DOMAIN) |
455 return S_ERR; | 462 return S_ERR; |
456 vts_ptt_srpt = vm->vtsi->vts_ptt_srpt; | 463 vts_ptt_srpt = vm->vtsi->vts_ptt_srpt; |
457 pgcN = get_PGCN(vm); | 464 pgcN = get_PGCN(vm); |
458 pgN = vm->state.pgN; | 465 pgN = vm->state.pgN; |
459 printf("VTS_PTT_SRPT - PGC: %3i PG: %3i\n", | 466 printf("VTS_PTT_SRPT - PGC: %3i PG: %3i\n", |
460 pgcN, pgN); | 467 pgcN, pgN); |
461 for(title=0;( (title<vts_ptt_srpt->nr_of_srpts) && (found == 0) );title++) { | 468 for(title=0;( (title < vts_ptt_srpt->nr_of_srpts) && (found == 0) );title++) { |
462 for(part=0;((part < vts_ptt_srpt->title[title].nr_of_ptts) && (found == 0));part++) { | 469 for(part=0;((part < vts_ptt_srpt->title[title].nr_of_ptts) && (found == 0));part++) { |
463 if ( (vts_ptt_srpt->title[title].ptt[part].pgcn == pgcN) && | 470 if ( (vts_ptt_srpt->title[title].ptt[part].pgcn == pgcN) && |
464 (vts_ptt_srpt->title[title].ptt[part].pgn == pgN ) ) { | 471 (vts_ptt_srpt->title[title].ptt[part].pgn == pgN ) ) { |
465 found = 1; | 472 found = 1; |
466 break; | 473 break; |
478 vts_ptt_srpt->title[title-1].ptt[part-1].pgn ); | 485 vts_ptt_srpt->title[title-1].ptt[part-1].pgn ); |
479 } else { | 486 } else { |
480 fprintf(MSG_OUT, "libdvdnav: ************ this chapter NOT FOUND!\n"); | 487 fprintf(MSG_OUT, "libdvdnav: ************ this chapter NOT FOUND!\n"); |
481 return S_ERR; | 488 return S_ERR; |
482 } | 489 } |
483 /* Make sure this is not the first chapter */ | 490 *title_result = title; |
484 if(part <= 1 ) { | 491 *part_result = part; |
485 fprintf(MSG_OUT, "libdvdnav: at first chapter. prev chapter failed.\n"); | 492 return 1; |
493 } | |
494 | |
495 /* Jump to a particlar part of a particlar title on this vts */ | |
496 /* returns S_ERR if not in the VTS_DOMAIN */ | |
497 /* FIXME: Should we do some locking here ? */ | |
498 int vm_jump_title_part(vm_t *vm, int title, int part) { | |
499 link_t link_values; | |
500 int vtsN; | |
501 | |
502 if((!vm) || (!vm->vtsi) || (!vm->vmgi) ) | |
486 return S_ERR; | 503 return S_ERR; |
487 } | 504 |
488 part--; /* Previous chapter */ | 505 if(!(vm->state.pgc) ) |
489 if(set_VTS_PTT(vm,(vm->state).vtsN, title, part) == -1) | 506 return S_ERR; |
490 assert(0); | 507 /* if ( (title < 1) || (title > vm->vtsi->vts_ptt_srpt->nr_of_srpts) || |
508 (part < 1) || (part > vm->vtsi->vts_ptt_srpt->title[title].nr_of_ptts) ) { | |
509 return S_ERR; | |
510 } | |
511 */ | |
512 if( (title < 1) || (title > vm->vmgi->tt_srpt->nr_of_srpts) ) { | |
513 return S_ERR; | |
514 } | |
515 vtsN = vm->vmgi->tt_srpt->title[title - 1].title_set_nr; | |
516 | |
517 if(set_VTS_PTT(vm, vtsN, title, part) == -1) { | |
518 return S_ERR; | |
519 } | |
491 link_values = play_PGC_PG( vm, (vm->state).pgN ); | 520 link_values = play_PGC_PG( vm, (vm->state).pgN ); |
492 link_values = process_command(vm,link_values); | 521 link_values = process_command(vm,link_values); |
493 assert(link_values.command == PlayThis); | 522 assert(link_values.command == PlayThis); |
494 (vm->state).blockN = link_values.data1; | 523 (vm->state).blockN = link_values.data1; |
495 assert( (vm->state).blockN == 0 ); | 524 assert( (vm->state).blockN == 0 ); |
496 vm->hop_channel++; | 525 vm->hop_channel++; |
497 | 526 |
498 fprintf(MSG_OUT, "libdvdnav: previous chapter done\n"); | 527 fprintf(MSG_OUT, "libdvdnav: previous chapter done\n"); |
499 | |
500 return 1; | |
501 } | |
502 | |
503 | |
504 int vm_next_part(vm_t *vm) | |
505 { | |
506 link_t link_values; | |
507 vts_ptt_srpt_t *vts_ptt_srpt; | |
508 int title, part=0; | |
509 int found = 0; | |
510 int16_t pgcN, pgN; | |
511 | |
512 if((!vm) || (!vm->vtsi) ) | |
513 return S_ERR; | |
514 | |
515 if(!(vm->state.pgc) ) | |
516 return S_ERR; | |
517 if (vm->state.domain != VTS_DOMAIN) | |
518 return S_ERR; | |
519 vts_ptt_srpt = vm->vtsi->vts_ptt_srpt; | |
520 pgcN = get_PGCN(vm); | |
521 pgN = vm->state.pgN; | |
522 printf("VTS_PTT_SRPT - PGC: %3i PG: %3i\n", | |
523 pgcN, pgN); | |
524 for(title=0;( (title<vts_ptt_srpt->nr_of_srpts) && (found == 0) );title++) { | |
525 for(part=0;((part < vts_ptt_srpt->title[title].nr_of_ptts) && (found == 0));part++) { | |
526 if ( (vts_ptt_srpt->title[title].ptt[part].pgcn == pgcN) && | |
527 (vts_ptt_srpt->title[title].ptt[part].pgn == pgN ) ) { | |
528 found = 1; | |
529 break; | |
530 } | |
531 } | |
532 if (found != 0) break; | |
533 } | |
534 title++; | |
535 part++; | |
536 if (found == 1) { | |
537 fprintf(MSG_OUT, "libdvdnav: ************ this chapter FOUND!\n"); | |
538 printf("VTS_PTT_SRPT - Title %3i part %3i: PGC: %3i PG: %3i\n", | |
539 title, part, | |
540 vts_ptt_srpt->title[title-1].ptt[part-1].pgcn , | |
541 vts_ptt_srpt->title[title-1].ptt[part-1].pgn ); | |
542 } else { | |
543 fprintf(MSG_OUT, "libdvdnav: ************ this chapter NOT FOUND!\n"); | |
544 } | |
545 /* Make sure this is not the last chapter */ | |
546 if(part >= vts_ptt_srpt->title[title-1].nr_of_ptts) { | |
547 fprintf(MSG_OUT, "libdvdnav: at last chapter. next chapter failed.\n"); | |
548 return S_ERR; | |
549 } | |
550 part++; /* Next chapter */ | |
551 if(set_VTS_PTT(vm,(vm->state).vtsN, title, part) == -1) | |
552 assert(0); | |
553 link_values = play_PGC_PG( vm, (vm->state).pgN ); | |
554 link_values = process_command(vm,link_values); | |
555 assert(link_values.command == PlayThis); | |
556 (vm->state).blockN = link_values.data1; | |
557 assert( (vm->state).blockN == 0 ); | |
558 vm->hop_channel++; | |
559 | |
560 fprintf(MSG_OUT, "libdvdnav: next chapter done\n"); | |
561 | 528 |
562 return 1; | 529 return 1; |
563 } | 530 } |
564 | 531 |
565 static domain_t menuid2domain(DVDMenuID_t menuid) | 532 static domain_t menuid2domain(DVDMenuID_t menuid) |
1693 | 1660 |
1694 (vm->state).domain = VTS_DOMAIN; | 1661 (vm->state).domain = VTS_DOMAIN; |
1695 if(vtsN != (vm->state).vtsN) | 1662 if(vtsN != (vm->state).vtsN) |
1696 ifoOpenNewVTSI(vm, vm->dvd, vtsN); /* Also sets (vm->state).vtsN */ | 1663 ifoOpenNewVTSI(vm, vm->dvd, vtsN); /* Also sets (vm->state).vtsN */ |
1697 | 1664 |
1698 assert(vts_ttn <= vm->vtsi->vts_ptt_srpt->nr_of_srpts); | 1665 if ((vts_ttn < 1) || (vts_ttn > vm->vtsi->vts_ptt_srpt->nr_of_srpts) || |
1699 assert(part <= vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].nr_of_ptts); | 1666 (part < 1) || (part > vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].nr_of_ptts) ) { |
1667 return S_ERR; | |
1668 } | |
1700 | 1669 |
1701 pgcN = vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].ptt[part - 1].pgcn; | 1670 pgcN = vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].ptt[part - 1].pgcn; |
1702 pgN = vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].ptt[part - 1].pgn; | 1671 pgN = vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].ptt[part - 1].pgn; |
1703 | 1672 |
1704 (vm->state).TT_PGCN_REG = pgcN; | 1673 (vm->state).TT_PGCN_REG = pgcN; |
1955 return pgcit; | 1924 return pgcit; |
1956 } | 1925 } |
1957 | 1926 |
1958 /* | 1927 /* |
1959 * $Log$ | 1928 * $Log$ |
1929 * Revision 1.34 2002/09/03 07:50:45 jcdutton | |
1930 * Improve chapter selection functions. | |
1931 * | |
1960 * Revision 1.33 2002/09/02 03:20:01 jcdutton | 1932 * Revision 1.33 2002/09/02 03:20:01 jcdutton |
1961 * Implement proper prev/next chapter/part. | 1933 * Implement proper prev/next chapter/part. |
1962 * I don't know why someone has not noticed the problem until now. | 1934 * I don't know why someone has not noticed the problem until now. |
1963 * | 1935 * |
1964 * Revision 1.32 2002/09/02 00:27:14 jcdutton | 1936 * Revision 1.32 2002/09/02 00:27:14 jcdutton |