comparison dvdnav.c @ 134:d9d75a22a061 src

- new event on cell changes to report program and cell number and some time info - get rid of memcopies in event handling
author mroi
date Tue, 25 Mar 2003 12:46:29 +0000
parents f2e86078a5dc
children 5204d4e4cd3b
comparison
equal deleted inserted replaced
133:d09a81cf65ce 134:d9d75a22a061
201 201
202 if(!this) 202 if(!this)
203 return "Hey! You gave me a NULL pointer you naughty person!"; 203 return "Hey! You gave me a NULL pointer you naughty person!";
204 204
205 return this->err_str; 205 return this->err_str;
206 }
207
208 /* converts a dvd_time_t to PTS ticks */
209 static int64_t dvdnav_convert_time(dvd_time_t *time) {
210 int64_t result;
211 int frames;
212
213 result = (time->hour & 0xf0) * 10 * 60 * 60 * 90000;
214 result += (time->hour & 0x0f) * 60 * 60 * 90000;
215 result += (time->minute & 0xf0) * 10 * 60 * 90000;
216 result += (time->minute & 0x0f) * 60 * 90000;
217 result += (time->second & 0xf0) * 10 * 90000;
218 result += (time->second & 0x0f) * 90000;
219 frames = (time->frame_u & 0x30) * 10 ;
220 frames += (time->frame_u & 0x0f) ;
221 if (time->frame_u & 0x80)
222 result += frames * 3000;
223 else
224 result += frames * 3600;
225
226 return result;
206 } 227 }
207 228
208 /* 229 /*
209 * Returns 1 if block contains NAV packet, 0 otherwise. 230 * Returns 1 if block contains NAV packet, 0 otherwise.
210 * Precesses said NAV packet if present. 231 * Precesses said NAV packet if present.
456 return S_OK; 477 return S_OK;
457 } 478 }
458 479
459 /* Check the HIGHLIGHT flag */ 480 /* Check the HIGHLIGHT flag */
460 if(this->position_current.button != this->position_next.button) { 481 if(this->position_current.button != this->position_next.button) {
461 dvdnav_highlight_event_t hevent; 482 dvdnav_highlight_event_t *hevent = (dvdnav_highlight_event_t *)*buf;
462 483
463 (*event) = DVDNAV_HIGHLIGHT; 484 (*event) = DVDNAV_HIGHLIGHT;
464 #ifdef LOG_DEBUG 485 #ifdef LOG_DEBUG
465 fprintf(MSG_OUT, "libdvdnav: HIGHLIGHT\n"); 486 fprintf(MSG_OUT, "libdvdnav: HIGHLIGHT\n");
466 #endif 487 #endif
467 (*len) = sizeof(hevent); 488 (*len) = sizeof(dvdnav_highlight_event_t);
468 hevent.display = 1; 489 hevent->display = 1;
469 hevent.buttonN = this->position_next.button; 490 hevent->buttonN = this->position_next.button;
470 memcpy(*buf, &(hevent), sizeof(hevent));
471 this->position_current.button = this->position_next.button; 491 this->position_current.button = this->position_next.button;
472 pthread_mutex_unlock(&this->vm_lock); 492 pthread_mutex_unlock(&this->vm_lock);
473 return S_OK; 493 return S_OK;
474 } 494 }
475 495
487 /* Check to see if we need to change the currently opened VOB */ 507 /* Check to see if we need to change the currently opened VOB */
488 if((this->position_current.vts != this->position_next.vts) || 508 if((this->position_current.vts != this->position_next.vts) ||
489 (this->position_current.domain != this->position_next.domain)) { 509 (this->position_current.domain != this->position_next.domain)) {
490 dvd_read_domain_t domain; 510 dvd_read_domain_t domain;
491 int vtsN; 511 int vtsN;
492 dvdnav_vts_change_event_t vts_event; 512 dvdnav_vts_change_event_t *vts_event = (dvdnav_vts_change_event_t *)*buf;
493 513
494 if(this->file) { 514 if(this->file) {
495 DVDCloseFile(this->file); 515 DVDCloseFile(this->file);
496 this->file = NULL; 516 this->file = NULL;
497 } 517 }
498 518
499 vts_event.old_vtsN = this->open_vtsN; 519 vts_event->old_vtsN = this->open_vtsN;
500 vts_event.old_domain = this->open_domain; 520 vts_event->old_domain = this->open_domain;
501 521
502 /* Use the DOMAIN to find whether to open menu or title VOBs */ 522 /* Use the DOMAIN to find whether to open menu or title VOBs */
503 switch(this->position_next.domain) { 523 switch(this->position_next.domain) {
504 case FP_DOMAIN: 524 case FP_DOMAIN:
505 case VMGM_DOMAIN: 525 case VMGM_DOMAIN:
522 542
523 this->position_current.vts = this->position_next.vts; 543 this->position_current.vts = this->position_next.vts;
524 this->position_current.domain = this->position_next.domain; 544 this->position_current.domain = this->position_next.domain;
525 dvdnav_read_cache_clear(this->cache); 545 dvdnav_read_cache_clear(this->cache);
526 this->file = DVDOpenFile(vm_get_dvd_reader(this->vm), vtsN, domain); 546 this->file = DVDOpenFile(vm_get_dvd_reader(this->vm), vtsN, domain);
527 vts_event.new_vtsN = this->position_next.vts; 547 vts_event->new_vtsN = this->position_next.vts;
528 vts_event.new_domain = this->position_next.domain; 548 vts_event->new_domain = this->position_next.domain;
529 549
530 /* If couldn't open the file for some reason, moan */ 550 /* If couldn't open the file for some reason, moan */
531 if(this->file == NULL) { 551 if(this->file == NULL) {
532 printerrf("Error opening vtsN=%i, domain=%i.", vtsN, domain); 552 printerrf("Error opening vtsN=%i, domain=%i.", vtsN, domain);
533 pthread_mutex_unlock(&this->vm_lock); 553 pthread_mutex_unlock(&this->vm_lock);
537 /* File opened successfully so return a VTS change event */ 557 /* File opened successfully so return a VTS change event */
538 (*event) = DVDNAV_VTS_CHANGE; 558 (*event) = DVDNAV_VTS_CHANGE;
539 #ifdef LOG_DEBUG 559 #ifdef LOG_DEBUG
540 fprintf(MSG_OUT, "libdvdnav: VTS_CHANGE\n"); 560 fprintf(MSG_OUT, "libdvdnav: VTS_CHANGE\n");
541 #endif 561 #endif
542 (*len) = sizeof(vts_event); 562 (*len) = sizeof(dvdnav_vts_change_event_t);
543 memcpy(*buf, &(vts_event), sizeof(vts_event));
544 563
545 this->spu_clut_changed = 1; 564 this->spu_clut_changed = 1;
546 this->position_current.cell = -1; /* Force an update */ 565 this->position_current.cell = -1; /* Force an update */
547 this->position_current.spu_channel = -1; /* Force an update */ 566 this->position_current.spu_channel = -1; /* Force an update */
548 this->position_current.audio_channel = -1; /* Force an update */; 567 this->position_current.audio_channel = -1; /* Force an update */;
553 572
554 /* Check if the cell changed */ 573 /* Check if the cell changed */
555 if( (this->position_current.cell != this->position_next.cell) || 574 if( (this->position_current.cell != this->position_next.cell) ||
556 (this->position_current.cell_restart != this->position_next.cell_restart) || 575 (this->position_current.cell_restart != this->position_next.cell_restart) ||
557 (this->position_current.cell_start != this->position_next.cell_start) ) { 576 (this->position_current.cell_start != this->position_next.cell_start) ) {
577 dvdnav_cell_change_event_t *cell_event = (dvdnav_cell_change_event_t *)*buf;
578 int first_cell_nr, last_cell_nr, i;
579 dvd_state_t *state = &this->vm->state;
558 580
559 (*event) = DVDNAV_CELL_CHANGE; 581 (*event) = DVDNAV_CELL_CHANGE;
560 #ifdef LOG_DEBUG 582 #ifdef LOG_DEBUG
561 fprintf(MSG_OUT, "libdvdnav: CELL_CHANGE\n"); 583 fprintf(MSG_OUT, "libdvdnav: CELL_CHANGE\n");
562 #endif 584 #endif
563 (*len) = 0; 585 (*len) = sizeof(dvdnav_cell_change_event_t);
586
587 cell_event->cellN = state->cellN;
588 cell_event->pgN = state->pgN;
589 cell_event->cell_length =
590 dvdnav_convert_time(&state->pgc->cell_playback[state->cellN-1].playback_time);
591 cell_event->pg_length = 0;
592 /* Find start cell of program. */
593 first_cell_nr = state->pgc->program_map[state->pgN-1];
594 /* Find end cell of program */
595 if(state->pgN < state->pgc->nr_of_programs)
596 last_cell_nr = state->pgc->program_map[state->pgN] - 1;
597 else
598 last_cell_nr = state->pgc->nr_of_cells;
599 for (i = first_cell_nr; i <= last_cell_nr; i++)
600 cell_event->pg_length +=
601 dvdnav_convert_time(&state->pgc->cell_playback[i - 1].playback_time);
602 cell_event->pgc_length = dvdnav_convert_time(&state->pgc->playback_time);
564 603
565 this->position_current.cell = this->position_next.cell; 604 this->position_current.cell = this->position_next.cell;
566 this->position_current.cell_restart = this->position_next.cell_restart; 605 this->position_current.cell_restart = this->position_next.cell_restart;
567 this->position_current.cell_start = this->position_next.cell_start; 606 this->position_current.cell_start = this->position_next.cell_start;
568 this->position_current.block = this->position_next.block; 607 this->position_current.block = this->position_next.block;
596 return S_OK; 635 return S_OK;
597 } 636 }
598 637
599 /* has the SPU channel changed? */ 638 /* has the SPU channel changed? */
600 if(this->position_current.spu_channel != this->position_next.spu_channel) { 639 if(this->position_current.spu_channel != this->position_next.spu_channel) {
601 dvdnav_spu_stream_change_event_t stream_change; 640 dvdnav_spu_stream_change_event_t *stream_change = (dvdnav_spu_stream_change_event_t *)*buf;
602 641
603 (*event) = DVDNAV_SPU_STREAM_CHANGE; 642 (*event) = DVDNAV_SPU_STREAM_CHANGE;
604 #ifdef LOG_DEBUG 643 #ifdef LOG_DEBUG
605 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE\n"); 644 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE\n");
606 #endif 645 #endif
607 (*len) = sizeof(dvdnav_spu_stream_change_event_t); 646 (*len) = sizeof(dvdnav_spu_stream_change_event_t);
608 stream_change.physical_wide = vm_get_subp_active_stream(this->vm, 0); 647 stream_change->physical_wide = vm_get_subp_active_stream(this->vm, 0);
609 stream_change.physical_letterbox = vm_get_subp_active_stream(this->vm, 1); 648 stream_change->physical_letterbox = vm_get_subp_active_stream(this->vm, 1);
610 stream_change.physical_pan_scan = vm_get_subp_active_stream(this->vm, 2); 649 stream_change->physical_pan_scan = vm_get_subp_active_stream(this->vm, 2);
611 memcpy(*buf, &(stream_change), sizeof(dvdnav_spu_stream_change_event_t));
612 this->position_current.spu_channel = this->position_next.spu_channel; 650 this->position_current.spu_channel = this->position_next.spu_channel;
613 #ifdef LOG_DEBUG 651 #ifdef LOG_DEBUG
614 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE stream_id_wide=%d\n",stream_change.physical_wide); 652 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE stream_id_wide=%d\n",stream_change.physical_wide);
615 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE stream_id_letterbox=%d\n",stream_change.physical_letterbox); 653 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE stream_id_letterbox=%d\n",stream_change.physical_letterbox);
616 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE stream_id_pan_scan=%d\n",stream_change.physical_pan_scan); 654 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE stream_id_pan_scan=%d\n",stream_change.physical_pan_scan);
617 #endif 655 #endif
618 if (stream_change.physical_wide != -1 && 656 if (stream_change->physical_wide != -1 &&
619 stream_change.physical_letterbox != -1 && 657 stream_change->physical_letterbox != -1 &&
620 stream_change.physical_pan_scan != -1) { 658 stream_change->physical_pan_scan != -1) {
621 #ifdef LOG_DEBUG 659 #ifdef LOG_DEBUG
622 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE returning S_OK\n"); 660 fprintf(MSG_OUT, "libdvdnav: SPU_STREAM_CHANGE returning S_OK\n");
623 #endif 661 #endif
624 pthread_mutex_unlock(&this->vm_lock); 662 pthread_mutex_unlock(&this->vm_lock);
625 return S_OK; 663 return S_OK;
626 } 664 }
627 } 665 }
628 666
629 /* has the audio channel changed? */ 667 /* has the audio channel changed? */
630 if(this->position_current.audio_channel != this->position_next.audio_channel) { 668 if(this->position_current.audio_channel != this->position_next.audio_channel) {
631 dvdnav_audio_stream_change_event_t stream_change; 669 dvdnav_audio_stream_change_event_t *stream_change = (dvdnav_audio_stream_change_event_t *)*buf;
632 670
633 (*event) = DVDNAV_AUDIO_STREAM_CHANGE; 671 (*event) = DVDNAV_AUDIO_STREAM_CHANGE;
634 #ifdef LOG_DEBUG 672 #ifdef LOG_DEBUG
635 fprintf(MSG_OUT, "libdvdnav: AUDIO_STREAM_CHANGE\n"); 673 fprintf(MSG_OUT, "libdvdnav: AUDIO_STREAM_CHANGE\n");
636 #endif 674 #endif
637 (*len) = sizeof(dvdnav_audio_stream_change_event_t); 675 (*len) = sizeof(dvdnav_audio_stream_change_event_t);
638 stream_change.physical = vm_get_audio_active_stream( this->vm ); 676 stream_change->physical = vm_get_audio_active_stream( this->vm );
639 memcpy(*buf, &(stream_change), sizeof( dvdnav_audio_stream_change_event_t));
640 this->position_current.audio_channel = this->position_next.audio_channel; 677 this->position_current.audio_channel = this->position_next.audio_channel;
641 #ifdef LOG_DEBUG 678 #ifdef LOG_DEBUG
642 fprintf(MSG_OUT, "libdvdnav: AUDIO_STREAM_CHANGE stream_id=%d returning S_OK\n",stream_change.physical); 679 fprintf(MSG_OUT, "libdvdnav: AUDIO_STREAM_CHANGE stream_id=%d returning S_OK\n",stream_change.physical);
643 #endif 680 #endif
644 pthread_mutex_unlock(&this->vm_lock); 681 pthread_mutex_unlock(&this->vm_lock);
645 return S_OK; 682 return S_OK;
646 } 683 }
647 684
648 /* Check the STILLFRAME flag */ 685 /* Check the STILLFRAME flag */
649 if(this->position_current.still != 0) { 686 if(this->position_current.still != 0) {
650 dvdnav_still_event_t still_event; 687 dvdnav_still_event_t *still_event = (dvdnav_still_event_t *)*buf;
651 688
652 (*event) = DVDNAV_STILL_FRAME; 689 (*event) = DVDNAV_STILL_FRAME;
653 #ifdef LOG_DEBUG 690 #ifdef LOG_DEBUG
654 fprintf(MSG_OUT, "libdvdnav: STILL_FRAME\n"); 691 fprintf(MSG_OUT, "libdvdnav: STILL_FRAME\n");
655 #endif 692 #endif
656 (*len) = sizeof(dvdnav_still_event_t); 693 (*len) = sizeof(dvdnav_still_event_t);
657 still_event.length = this->position_current.still; 694 still_event->length = this->position_current.still;
658 memcpy(*buf, &(still_event), sizeof(dvdnav_still_event_t));
659 pthread_mutex_unlock(&this->vm_lock); 695 pthread_mutex_unlock(&this->vm_lock);
660 return S_OK; 696 return S_OK;
661 } 697 }
662 698
663 /* Have we reached the end of a VOBU? */ 699 /* Have we reached the end of a VOBU? */
978 return this->position_next.still; 1014 return this->position_next.still;
979 } 1015 }
980 1016
981 /* 1017 /*
982 * $Log$ 1018 * $Log$
1019 * Revision 1.46 2003/03/25 12:46:26 mroi
1020 * - new event on cell changes to report program and cell number and some time info
1021 * - get rid of memcopies in event handling
1022 *
983 * Revision 1.45 2003/03/15 20:18:50 mroi 1023 * Revision 1.45 2003/03/15 20:18:50 mroi
984 * start blockN from 0 1024 * start blockN from 0
985 * 1025 *
986 * Revision 1.44 2003/03/14 18:49:28 mroi 1026 * Revision 1.44 2003/03/14 18:49:28 mroi
987 * less overwhelming TRACE info 1027 * less overwhelming TRACE info