/
DVDInputStreamNavigator.cpp
1332 lines (1119 loc) · 37.9 KB
/
DVDInputStreamNavigator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "DVDInputStreamNavigator.h"
#include "Util.h"
#include "LangCodeExpander.h"
#include "DVDDemuxSPU.h"
#include "DVDStateSerializer.h"
#include "GUISettings.h"
#include "LangInfo.h"
#include "utils/log.h"
#include "Geometry.h"
#ifdef __APPLE__
#include "CocoaInterface.h"
#endif
#define HOLDMODE_NONE 0
#define HOLDMODE_HELD 1 /* set internally when we wish to flush demuxer */
#define HOLDMODE_SKIP 2 /* set by inputstream user, when they wish to skip the held mode */
#define HOLDMODE_DATA 3 /* set after hold mode has been exited, and action that inited it has been executed */
CDVDInputStreamNavigator::CDVDInputStreamNavigator(IDVDPlayer* player) : CDVDInputStream(DVDSTREAM_TYPE_DVD)
{
m_dvdnav = 0;
m_pDVDPlayer = player;
m_bCheckButtons = false;
m_iCellStart = 0;
m_iVobUnitStart = 0LL;
m_iVobUnitStop = 0LL;
m_iVobUnitCorrection = 0LL;
m_bInMenu = false;
m_holdmode = HOLDMODE_NONE;
m_iTitle = m_iTitleCount = 0;
m_iPart = m_iPartCount = 0;
m_iTime = m_iTotalTime = 0;
}
CDVDInputStreamNavigator::~CDVDInputStreamNavigator()
{
Close();
}
bool CDVDInputStreamNavigator::Open(const char* strFile, const std::string& content)
{
char* strDVDFile;
m_icurrentGroupId = 0;
if (!CDVDInputStream::Open(strFile, "video/x-dvd-mpeg"))
return false;
// load libdvdnav.dll
if (!m_dll.Load())
return false;
// load the dvd language codes
// g_LangCodeExpander.LoadStandardCodes();
// since libdvdnav automaticly play's the dvd if the directory contains VIDEO_TS.IFO
// we strip it here.
strDVDFile = strdup(strFile);
#ifndef _LINUX
if (strnicmp(strDVDFile + strlen(strDVDFile) - 12, "VIDEO_TS.IFO", 12) == 0)
#else
if (strncasecmp(strDVDFile + strlen(strDVDFile) - 12, "VIDEO_TS.IFO", 12) == 0)
#endif
{
strDVDFile[strlen(strDVDFile) - 13] = '\0';
}
#if defined(__APPLE__)
// if physical DVDs, libdvdnav wants "/dev/rdiskN" device name for OSX,
// strDVDFile will get realloc'ed and replaced IF this is a physical DVD.
Cocoa_MountPoint2DeviceName(strDVDFile);
#endif
// open up the DVD device
if (m_dll.dvdnav_open(&m_dvdnav, strDVDFile) != DVDNAV_STATUS_OK)
{
free(strDVDFile);
CLog::Log(LOGERROR,"Error on dvdnav_open\n");
Close();
return false;
}
free(strDVDFile);
int region = g_guiSettings.GetInt("dvds.playerregion");
int mask = 0;
if(region > 0)
mask = 1 << (region-1);
else
{
// find out what region dvd reports itself to be from, and use that as mask if available
vm_t* vm = m_dll.dvdnav_get_vm(m_dvdnav);
if (vm && vm->vmgi && vm->vmgi->vmgi_mat)
mask = ((vm->vmgi->vmgi_mat->vmg_category >> 16) & 0xff) ^ 0xff;
}
if(!mask)
mask = 0xff;
CLog::Log(LOGDEBUG, "%s - Setting region mask %02x", __FUNCTION__, mask);
m_dll.dvdnav_set_region_mask(m_dvdnav, mask);
// get default language settings
char language_menu[3];
strncpy(language_menu, g_langInfo.GetDVDMenuLanguage().c_str(), sizeof(language_menu)-1);
language_menu[2] = '\0';
char language_audio[3];
strncpy(language_audio, g_langInfo.GetDVDAudioLanguage().c_str(), sizeof(language_audio)-1);
language_audio[2] = '\0';
char language_subtitle[3];
strncpy(language_subtitle, g_langInfo.GetDVDSubtitleLanguage().c_str(), sizeof(language_subtitle)-1);
language_subtitle[2] = '\0';
// set language settings in case they are not set in xbmc's configuration
if (language_menu[0] == '\0') strcpy(language_menu, "en");
if (language_audio[0] == '\0') strcpy(language_audio, "en");
if (language_subtitle[0] == '\0') strcpy(language_subtitle, "en");
// set default language settings
if (m_dll.dvdnav_menu_language_select(m_dvdnav, (char*)language_menu) != DVDNAV_STATUS_OK)
{
CLog::Log(LOGERROR, "Error on setting default menu language: %s\n", m_dll.dvdnav_err_to_string(m_dvdnav));
CLog::Log(LOGERROR, "Defaulting to \"en\"");
m_dll.dvdnav_menu_language_select(m_dvdnav, (char*)"en");
}
if (m_dll.dvdnav_audio_language_select(m_dvdnav, (char*)language_audio) != DVDNAV_STATUS_OK)
{
CLog::Log(LOGERROR, "Error on setting default audio language: %s\n", m_dll.dvdnav_err_to_string(m_dvdnav));
CLog::Log(LOGERROR, "Defaulting to \"en\"");
m_dll.dvdnav_audio_language_select(m_dvdnav, (char*)"en");
}
if (m_dll.dvdnav_spu_language_select(m_dvdnav, (char*)language_subtitle) != DVDNAV_STATUS_OK)
{
CLog::Log(LOGERROR, "Error on setting default subtitle language: %s\n", m_dll.dvdnav_err_to_string(m_dvdnav));
CLog::Log(LOGERROR, "Defaulting to \"en\"");
m_dll.dvdnav_spu_language_select(m_dvdnav, (char*)"en");
}
// set read ahead cache usage
if (m_dll.dvdnav_set_readahead_flag(m_dvdnav, 1) != DVDNAV_STATUS_OK)
{
CLog::Log(LOGERROR,"Error on dvdnav_set_readahead_flag: %s\n", m_dll.dvdnav_err_to_string(m_dvdnav));
Close();
return false;
}
// set the PGC positioning flag to have position information relatively to the
// whole feature instead of just relatively to the current chapter
if (m_dll.dvdnav_set_PGC_positioning_flag(m_dvdnav, 1) != DVDNAV_STATUS_OK)
{
CLog::Log(LOGERROR,"Error on dvdnav_set_PGC_positioning_flag: %s\n", m_dll.dvdnav_err_to_string(m_dvdnav));
Close();
return false;
}
// jump directly to title menu
if(g_guiSettings.GetBool("dvds.automenu"))
{
int len, event;
uint8_t buf[2048];
uint8_t* buf_ptr = buf;
// must startup vm and pgc
m_dll.dvdnav_get_next_cache_block(m_dvdnav,&buf_ptr,&event,&len);
m_dll.dvdnav_sector_search(m_dvdnav, 0, SEEK_SET);
if(m_dll.dvdnav_menu_call(m_dvdnav, DVD_MENU_Title) != DVDNAV_STATUS_OK)
CLog::Log(LOGERROR,"Error on dvdnav_menu_call(Title): %s\n", m_dll.dvdnav_err_to_string(m_dvdnav));
}
m_bEOF = false;
m_bCheckButtons = false;
m_iCellStart = 0;
m_iVobUnitStart = 0LL;
m_iVobUnitStop = 0LL;
m_iVobUnitCorrection = 0LL;
m_bInMenu = false;
m_holdmode = HOLDMODE_NONE;
m_iTitle = m_iTitleCount = 0;
m_iPart = m_iPartCount = 0;
m_iTime = m_iTotalTime = 0;
return true;
}
void CDVDInputStreamNavigator::Close()
{
if (!m_dvdnav) return;
// finish off by closing the dvdnav device
if (m_dll.dvdnav_close(m_dvdnav) != DVDNAV_STATUS_OK)
{
CLog::Log(LOGERROR,"Error on dvdnav_close: %s\n", m_dll.dvdnav_err_to_string(m_dvdnav));
return ;
}
CDVDInputStream::Close();
m_dvdnav = NULL;
m_bEOF = true;
}
int CDVDInputStreamNavigator::Read(BYTE* buf, int buf_size)
{
if (!m_dvdnav || m_bEOF) return 0;
if (buf_size < DVD_VIDEO_BLOCKSIZE)
{
CLog::Log(LOGERROR, "CDVDInputStreamNavigator: buffer size is to small, %d bytes, should be 2048 bytes", buf_size);
return -1;
}
int navresult;
int iBytesRead;
while(true) {
navresult = ProcessBlock(buf, &iBytesRead);
if (navresult == NAVRESULT_HOLD) return 0; // return 0 bytes read;
else if (navresult == NAVRESULT_ERROR) return -1;
else if (navresult == NAVRESULT_DATA) return iBytesRead;
}
return iBytesRead;
}
// not working yet, but it is the recommanded way for seeking
__int64 CDVDInputStreamNavigator::Seek(__int64 offset, int whence)
{
if (!m_dvdnav) return -1;
uint32_t pos=0, len=1;
if (m_dll.dvdnav_sector_search(m_dvdnav, (uint64_t)(offset / DVD_VIDEO_LB_LEN), (int32_t)whence) != DVDNAV_STATUS_ERR)
{
m_dll.dvdnav_get_position(m_dvdnav, &pos, &len);
}
else
{
CLog::Log(LOGDEBUG, "dvdnav: %s", m_dll.dvdnav_err_to_string(m_dvdnav));
return -1;
}
return (int)(pos * DVD_VIDEO_LB_LEN);
}
int CDVDInputStreamNavigator::ProcessBlock(BYTE* dest_buffer, int* read)
{
if (!m_dvdnav) return -1;
int result;
int len;
int iNavresult = NAVRESULT_NOP;
// m_tempbuffer will be used for anything that isn't a normal data block
uint8_t* buf = m_lastblock;
iNavresult = -1;
if(m_holdmode == HOLDMODE_HELD)
return NAVRESULT_HOLD;
try
{
// the main reading function
if(m_holdmode == HOLDMODE_SKIP)
{ /* we where holding data, return the data held */
m_holdmode = HOLDMODE_DATA;
result = DVDNAV_STATUS_OK;
}
else
result = m_dll.dvdnav_get_next_cache_block(m_dvdnav, &buf, &m_lastevent, &len);
}
catch (...)
{
CLog::Log(LOGERROR, "CDVDInputStreamNavigator::ProcessBlock - exception thrown in dvdnav_get_next_cache_block.");
// okey, we are probably holding a vm_lock here so leave it.. this could potentialy cause problems if we aren't holding it
// but it's more likely that we do
LeaveCriticalSection((LPCRITICAL_SECTION)&(m_dvdnav->vm_lock));
m_bEOF = true;
return NAVRESULT_ERROR;
}
if (result == DVDNAV_STATUS_ERR)
{
CLog::Log(LOGERROR,"Error getting next block: %s\n", m_dll.dvdnav_err_to_string(m_dvdnav));
m_bEOF = true;
return NAVRESULT_ERROR;
}
switch (m_lastevent)
{
case DVDNAV_BLOCK_OK:
{
// We have received a regular block of the currently playing MPEG stream.
// buf contains the data and len its length (obviously!) (which is always 2048 bytes btw)
m_holdmode = HOLDMODE_NONE;
memcpy(dest_buffer, buf, len);
*read = len;
iNavresult = NAVRESULT_DATA;
}
break;
case DVDNAV_NOP:
// Nothing to do here.
break;
case DVDNAV_STILL_FRAME:
{
// We have reached a still frame. A real player application would wait
// the amount of time specified by the still's length while still handling
// user input to make menus and other interactive stills work.
// A length of 0xff means an indefinite still which has to be skipped
// indirectly by some user interaction.
iNavresult = m_pDVDPlayer->OnDVDNavResult(buf, DVDNAV_STILL_FRAME);
/* if user didn't care for action, just skip it */
if(iNavresult == NAVRESULT_NOP)
SkipStill();
}
break;
case DVDNAV_WAIT:
{
// We have reached a point in DVD playback, where timing is critical.
// Player application with internal fifos can introduce state
// inconsistencies, because libdvdnav is always the fifo's length
// ahead in the stream compared to what the application sees.
// Such applications should wait until their fifos are empty
// when they receive this type of event.
if(m_holdmode == HOLDMODE_NONE)
{
CLog::Log(LOGDEBUG, " - DVDNAV_WAIT (HOLDING)");
m_holdmode = HOLDMODE_HELD;
iNavresult = NAVRESULT_HOLD;
}
else
iNavresult = m_pDVDPlayer->OnDVDNavResult(buf, DVDNAV_WAIT);
/* if user didn't care for action, just skip it */
if(iNavresult == NAVRESULT_NOP)
SkipWait();
}
break;
case DVDNAV_SPU_CLUT_CHANGE:
// Player applications should pass the new colour lookup table to their
// SPU decoder. The CLUT is given as 16 uint32_t's in the buffer.
{
iNavresult = m_pDVDPlayer->OnDVDNavResult(buf, DVDNAV_SPU_CLUT_CHANGE);
}
break;
case DVDNAV_SPU_STREAM_CHANGE:
// Player applications should inform their SPU decoder to switch channels
{
dvdnav_spu_stream_change_event_t* event = (dvdnav_spu_stream_change_event_t*)buf;
//libdvdnav never sets logical, why.. don't know..
event->logical = GetActiveSubtitleStream();
if(event->logical<0 && GetSubTitleStreamCount()>0)
{
/* this will not take effect in this event */
CLog::Log(LOGINFO, "%s - none or invalid subtitle stream selected, defaulting to first", __FUNCTION__);
SetActiveSubtitleStream(0);
}
m_bCheckButtons = true;
iNavresult = m_pDVDPlayer->OnDVDNavResult(buf, DVDNAV_SPU_STREAM_CHANGE);
}
break;
case DVDNAV_AUDIO_STREAM_CHANGE:
// Player applications should inform their audio decoder to switch channels
{
//dvdnav_get_audio_logical_stream actually does the oposite to the docs..
//taking a audiostream as given on dvd, it gives the physical stream that
//refers to in the mpeg file
dvdnav_audio_stream_change_event_t* event = (dvdnav_audio_stream_change_event_t*)buf;
//wroong... stupid docs..
//event->logical = dvdnav_get_audio_logical_stream(m_dvdnav, event->physical);
//logical should actually be set to the (vm->state).AST_REG
event->logical = GetActiveAudioStream();
if(event->logical<0)
{
/* this will not take effect in this event */
CLog::Log(LOGINFO, "%s - none or invalid audio stream selected, defaulting to first", __FUNCTION__);
SetActiveAudioStream(0);
}
iNavresult = m_pDVDPlayer->OnDVDNavResult(buf, DVDNAV_AUDIO_STREAM_CHANGE);
}
break;
case DVDNAV_HIGHLIGHT:
{
iNavresult = m_pDVDPlayer->OnDVDNavResult(buf, DVDNAV_HIGHLIGHT);
}
break;
case DVDNAV_VTS_CHANGE:
// Some status information like video aspect and video scale permissions do
// not change inside a VTS. Therefore this event can be used to query such
// information only when necessary and update the decoding/displaying
// accordingly.
{
if(m_holdmode == HOLDMODE_NONE)
{
CLog::Log(LOGDEBUG, " - DVDNAV_VTS_CHANGE (HOLDING)");
m_holdmode = HOLDMODE_HELD;
iNavresult = NAVRESULT_HOLD;
}
else
iNavresult = m_pDVDPlayer->OnDVDNavResult(buf, DVDNAV_VTS_CHANGE);
m_bInMenu = (0 == m_dll.dvdnav_is_domain_vts(m_dvdnav));
}
break;
case DVDNAV_CELL_CHANGE:
{
// Some status information like the current Title and Part numbers do not
// change inside a cell. Therefore this event can be used to query such
// information only when necessary and update the decoding/displaying
// accordingly.
// this may lead to a discontinuity, but it's also the end of the
// vobunit, so make sure everything in demuxer is output
if(m_holdmode == HOLDMODE_NONE)
{
CLog::Log(LOGDEBUG, "DVDNAV_CELL_CHANGE (HOLDING)");
m_holdmode = HOLDMODE_HELD;
iNavresult = NAVRESULT_HOLD;
break;
}
uint32_t pos, len;
m_dll.dvdnav_current_title_info(m_dvdnav, &m_iTitle, &m_iPart);
m_dll.dvdnav_get_number_of_titles(m_dvdnav, &m_iTitleCount);
if(m_iTitle > 0)
m_dll.dvdnav_get_number_of_parts(m_dvdnav, m_iTitle, &m_iPartCount);
else
m_iPartCount = 0;
m_dll.dvdnav_get_position(m_dvdnav, &pos, &len);
CLog::Log(LOGDEBUG, "%s - Cell change: Title %d, Chapter %d\n", __FUNCTION__, m_iTitle, m_iPart);
CLog::Log(LOGDEBUG, "%s - At position %.0f%% inside the feature\n", __FUNCTION__, 100 * (double)pos / (double)len);
//Get total segment time
dvdnav_cell_change_event_t* cell_change_event = (dvdnav_cell_change_event_t*)buf;
m_iCellStart = cell_change_event->cell_start; // store cell time as we need that for time later
m_iTotalTime = (int) (cell_change_event->pgc_length / 90);
m_icurrentGroupId = cell_change_event->pgN * 1000 + cell_change_event->cellN;
iNavresult = m_pDVDPlayer->OnDVDNavResult(buf, DVDNAV_CELL_CHANGE);
}
break;
case DVDNAV_NAV_PACKET:
{
// A NAV packet provides PTS discontinuity information, angle linking information and
// button definitions for DVD menus. Angles are handled completely inside libdvdnav.
// For the menus to work, the NAV packet information has to be passed to the overlay
// engine of the player so that it knows the dimensions of the button areas.
// Applications with fifos should not use these functions to retrieve NAV packets,
// they should implement their own NAV handling, because the packet you get from these
// functions will already be ahead in the stream which can cause state inconsistencies.
// Applications with fifos should therefore pass the NAV packet through the fifo
// and decoding pipeline just like any other data.
// Calculate current time
//unsigned int pos, len;
//m_dll.dvdnav_get_position(m_dvdnav, &pos, &len);
//m_iTime = (int)(((__int64)m_iTotalTime * pos) / len);
pci_t* pci = m_dll.dvdnav_get_current_nav_pci(m_dvdnav);
m_dll.dvdnav_get_current_nav_dsi(m_dvdnav);
if(!pci)
{
iNavresult = NAVRESULT_NOP;
break;
}
/* if we have any buttons or are not in vts domain we assume we are in meny */
m_bInMenu = pci->hli.hl_gi.hli_ss || (0 == m_dll.dvdnav_is_domain_vts(m_dvdnav));
/* check for any gap in the stream, this is likely a discontinuity */
__int64 gap = (__int64)pci->pci_gi.vobu_s_ptm - m_iVobUnitStop;
if(gap)
{
/* make sure demuxer is flushed before we change any correction */
if(m_holdmode == HOLDMODE_NONE)
{
CLog::Log(LOGDEBUG, "DVDNAV_NAV_PACKET (HOLDING)");
m_holdmode = HOLDMODE_HELD;
iNavresult = NAVRESULT_HOLD;
break;
}
m_iVobUnitCorrection += gap;
CLog::Log(LOGDEBUG, "DVDNAV_NAV_PACKET - DISCONTINUITY FROM:%"PRId64" TO:%"PRId64" DIFF:%"PRId64, (m_iVobUnitStop * 1000)/90, ((__int64)pci->pci_gi.vobu_s_ptm*1000)/90, (gap*1000)/90);
}
m_iVobUnitStart = pci->pci_gi.vobu_s_ptm;
m_iVobUnitStop = pci->pci_gi.vobu_e_ptm;
m_iTime = (int) ( m_dll.dvdnav_convert_time( &(pci->pci_gi.e_eltm) ) + m_iCellStart ) / 90;
if (m_bCheckButtons)
{
CheckButtons();
m_bCheckButtons = false;
}
iNavresult = m_pDVDPlayer->OnDVDNavResult((void*)pci, DVDNAV_NAV_PACKET);
}
break;
case DVDNAV_HOP_CHANNEL:
// This event is issued whenever a non-seamless operation has been executed.
// Applications with fifos should drop the fifos content to speed up responsiveness.
{
iNavresult = m_pDVDPlayer->OnDVDNavResult(NULL, DVDNAV_HOP_CHANNEL);
}
break;
case DVDNAV_STOP:
{
// Playback should end here.
// don't read any further, it could be libdvdnav had some problems reading
// the disc. reading further results in a crash
m_bEOF = true;
m_pDVDPlayer->OnDVDNavResult(NULL, DVDNAV_STOP);
iNavresult = NAVRESULT_ERROR;
}
break;
default:
{
CLog::Log(LOGDEBUG,"CDVDInputStreamNavigator: Unknown event (%i)\n", m_lastevent);
}
break;
}
// check if libdvdnav gave us some other buffer to work with
// probably not needed since function will check if buf
// is part of the internal cache, but do it for good measure
if( buf != m_lastblock )
m_dll.dvdnav_free_cache_block(m_dvdnav, buf);
return iNavresult;
}
bool CDVDInputStreamNavigator::SetActiveAudioStream(int iId)
{
int streamId = ConvertAudioStreamId_XBMCToExternal(iId);
CLog::Log(LOGDEBUG, "%s - id: %d, stream: %d", __FUNCTION__, iId, streamId);
if (!m_dvdnav)
return false;
vm_t* vm = m_dll.dvdnav_get_vm(m_dvdnav);
if (!vm)
return false;
if (!vm->state.pgc)
return false;
/* make sure stream is valid, if not don't allow it */
if (streamId < 0 || streamId >= 8)
return false;
else if ( !(vm->state.pgc->audio_control[streamId] & (1<<15)) )
return false;
if (vm->state.domain != VTS_DOMAIN && streamId != 0)
return false;
vm->state.AST_REG = streamId;
return true;
}
bool CDVDInputStreamNavigator::SetActiveSubtitleStream(int iId)
{
int streamId = ConvertSubtitleStreamId_XBMCToExternal(iId);
CLog::Log(LOGDEBUG, "%s - id: %d, stream: %d", __FUNCTION__, iId, streamId);
if (!m_dvdnav)
return false;
vm_t* vm = m_dll.dvdnav_get_vm(m_dvdnav);
if (!vm)
return false;
if (!vm->state.pgc)
return false;
/* make sure stream is valid, if not don't allow it */
if (streamId < 0 || streamId >= 32)
return false;
else if ( !(vm->state.pgc->subp_control[streamId] & (1<<31)) )
return false;
if (vm->state.domain != VTS_DOMAIN && streamId != 0)
return false;
/* set subtitle stream without modifying visibility */
vm->state.SPST_REG = streamId | (vm->state.SPST_REG & 0x40);
return true;
}
void CDVDInputStreamNavigator::ActivateButton()
{
if (m_dvdnav)
{
m_dll.dvdnav_button_activate(m_dvdnav, m_dll.dvdnav_get_current_nav_pci(m_dvdnav));
}
}
void CDVDInputStreamNavigator::SelectButton(int iButton)
{
if (!m_dvdnav) return;
m_dll.dvdnav_button_select(m_dvdnav, m_dll.dvdnav_get_current_nav_pci(m_dvdnav), iButton);
}
int CDVDInputStreamNavigator::GetCurrentButton()
{
int button;
if (m_dvdnav)
{
m_dll.dvdnav_get_current_highlight(m_dvdnav, &button);
return button;
}
return -1;
}
void CDVDInputStreamNavigator::CheckButtons()
{
if (m_dvdnav)
{
pci_t* pci = m_dll.dvdnav_get_current_nav_pci(m_dvdnav);
int iCurrentButton = GetCurrentButton();
if( iCurrentButton > 0 && iCurrentButton < 37 )
{
btni_t* button = &(pci->hli.btnit[iCurrentButton-1]);
// menu buttons are always cropped overlays, so if there is no such information
// we assume the button is invalid
if ((button->x_start || button->x_end || button->y_start || button->y_end))
{
// button has info, it's valid
return;
}
}
// select first valid button.
for (int i = 0; i < 36; i++)
{
if (pci->hli.btnit[i].x_start ||
pci->hli.btnit[i].x_end ||
pci->hli.btnit[i].y_start ||
pci->hli.btnit[i].y_end)
{
CLog::Log(LOGWARNING, "CDVDInputStreamNavigator: found invalid button(%d)", iCurrentButton);
CLog::Log(LOGWARNING, "CDVDInputStreamNavigator: switching to button(%d) instead", i + 1);
m_dll.dvdnav_button_select(m_dvdnav, pci, i + 1);
break;
}
}
}
}
int CDVDInputStreamNavigator::GetTotalButtons()
{
if (!m_dvdnav) return 0;
pci_t* pci = m_dll.dvdnav_get_current_nav_pci(m_dvdnav);
int counter = 0;
for (int i = 0; i < 36; i++)
{
if (pci->hli.btnit[i].x_start ||
pci->hli.btnit[i].x_end ||
pci->hli.btnit[i].y_start ||
pci->hli.btnit[i].y_end)
{
counter++;
}
}
return counter;
}
void CDVDInputStreamNavigator::OnUp()
{
if (m_dvdnav) m_dll.dvdnav_upper_button_select(m_dvdnav, m_dll.dvdnav_get_current_nav_pci(m_dvdnav));
}
void CDVDInputStreamNavigator::OnDown()
{
if (m_dvdnav) m_dll.dvdnav_lower_button_select(m_dvdnav, m_dll.dvdnav_get_current_nav_pci(m_dvdnav));
}
void CDVDInputStreamNavigator::OnLeft()
{
if (m_dvdnav) m_dll.dvdnav_left_button_select(m_dvdnav, m_dll.dvdnav_get_current_nav_pci(m_dvdnav));
}
void CDVDInputStreamNavigator::OnRight()
{
if (m_dvdnav) m_dll.dvdnav_right_button_select(m_dvdnav, m_dll.dvdnav_get_current_nav_pci(m_dvdnav));
}
bool CDVDInputStreamNavigator::OnMouseMove(const CPoint &point)
{
if (m_dvdnav)
{
pci_t* pci = m_dll.dvdnav_get_current_nav_pci(m_dvdnav);
return (DVDNAV_STATUS_OK == m_dll.dvdnav_mouse_select(m_dvdnav, pci, (int32_t)point.x, (int32_t)point.y));
}
return false;
}
bool CDVDInputStreamNavigator::OnMouseClick(const CPoint &point)
{
if (m_dvdnav)
{
pci_t* pci = m_dll.dvdnav_get_current_nav_pci(m_dvdnav);
return (DVDNAV_STATUS_OK == m_dll.dvdnav_mouse_activate(m_dvdnav, pci, (int32_t)point.x, (int32_t)point.y));
}
return false;
}
void CDVDInputStreamNavigator::OnMenu()
{
if (m_dvdnav) m_dll.dvdnav_menu_call(m_dvdnav, DVD_MENU_Escape);
}
void CDVDInputStreamNavigator::OnBack()
{
if (m_dvdnav) m_dll.dvdnav_go_up(m_dvdnav);
}
// we don't allow skipping in menu's cause it will remove menu overlays
void CDVDInputStreamNavigator::OnNext()
{
if (m_dvdnav && !IsInMenu())
{
m_dll.dvdnav_next_pg_search(m_dvdnav);
}
}
// we don't allow skipping in menu's cause it will remove menu overlays
void CDVDInputStreamNavigator::OnPrevious()
{
if (m_dvdnav && !IsInMenu())
{
m_dll.dvdnav_prev_pg_search(m_dvdnav);
}
}
void CDVDInputStreamNavigator::SkipStill()
{
if (!m_dvdnav) return ;
m_dll.dvdnav_still_skip(m_dvdnav);
}
void CDVDInputStreamNavigator::SkipWait()
{
if (!m_dvdnav) return ;
m_dll.dvdnav_wait_skip(m_dvdnav);
}
void CDVDInputStreamNavigator::SkipHold()
{
if(IsHeld())
m_holdmode = HOLDMODE_SKIP;
}
bool CDVDInputStreamNavigator::IsHeld()
{
return m_holdmode == HOLDMODE_HELD;
}
int CDVDInputStreamNavigator::GetActiveSubtitleStream()
{
int activeStream = 0;
if (m_dvdnav)
{
vm_t* vm = m_dll.dvdnav_get_vm(m_dvdnav);
if (vm && vm->state.pgc)
{
// get the current selected audiostream, for non VTS_DOMAIN it is always stream 0
int subpN = 0;
if (vm->state.domain == VTS_DOMAIN)
{
subpN = vm->state.SPST_REG & ~0x40;
/* make sure stream is valid, if not don't allow it */
if (subpN < 0 || subpN >= 32)
subpN = -1;
else if ( !(vm->state.pgc->subp_control[subpN] & (1<<31)) )
subpN = -1;
}
activeStream = ConvertSubtitleStreamId_ExternalToXBMC(subpN);
}
}
return activeStream;
}
std::string CDVDInputStreamNavigator::GetSubtitleStreamLanguage(int iId)
{
if (!m_dvdnav) return NULL;
CStdString strLanguage;
subp_attr_t subp_attributes;
int streamId = ConvertSubtitleStreamId_XBMCToExternal(iId);
if( m_dll.dvdnav_get_stitle_info(m_dvdnav, streamId, &subp_attributes) == DVDNAV_STATUS_OK )
{
if (subp_attributes.type == DVD_SUBPICTURE_TYPE_Language ||
subp_attributes.type == DVD_SUBPICTURE_TYPE_NotSpecified)
{
if (!g_LangCodeExpander.Lookup(strLanguage, subp_attributes.lang_code)) strLanguage = "Unknown";
switch (subp_attributes.lang_extension)
{
case DVD_SUBPICTURE_LANG_EXT_NotSpecified:
case DVD_SUBPICTURE_LANG_EXT_NormalCaptions:
case DVD_SUBPICTURE_LANG_EXT_BigCaptions:
case DVD_SUBPICTURE_LANG_EXT_ChildrensCaptions:
break;
case DVD_SUBPICTURE_LANG_EXT_NormalCC:
case DVD_SUBPICTURE_LANG_EXT_BigCC:
case DVD_SUBPICTURE_LANG_EXT_ChildrensCC:
strLanguage+= " (CC)";
break;
case DVD_SUBPICTURE_LANG_EXT_Forced:
strLanguage+= " (Forced)";
break;
case DVD_SUBPICTURE_LANG_EXT_NormalDirectorsComments:
case DVD_SUBPICTURE_LANG_EXT_BigDirectorsComments:
case DVD_SUBPICTURE_LANG_EXT_ChildrensDirectorsComments:
strLanguage+= " (Directors Comments)";
break;
}
}
else
{
strLanguage = "Unknown";
}
}
return strLanguage;
}
int CDVDInputStreamNavigator::GetSubTitleStreamCount()
{
if (!m_dvdnav) return 0;
vm_t* vm = m_dll.dvdnav_get_vm(m_dvdnav);
if (!vm) return 0;
if (!vm->state.pgc) return 0;
if (vm->state.domain == VTS_DOMAIN)
{
int streamN = 0;
for (int i = 0; i < 32; i++)
{
if (vm->state.pgc->subp_control[i] & (1<<31))
streamN++;
}
return streamN;
}
else
{
/* just for good measure say that non vts domain always has one */
return 1;
}
}
int CDVDInputStreamNavigator::GetActiveAudioStream()
{
int activeStream = -1;
if (m_dvdnav)
{
vm_t* vm = m_dll.dvdnav_get_vm(m_dvdnav);
if (vm && vm->state.pgc)
{
// get the current selected audiostream, for non VTS_DOMAIN it is always stream 0
int audioN = 0;
if (vm->state.domain == VTS_DOMAIN)
{
audioN = vm->state.AST_REG;
/* make sure stream is valid, if not don't allow it */
if (audioN < 0 || audioN >= 8)
audioN = -1;
else if ( !(vm->state.pgc->audio_control[audioN] & (1<<15)) )
audioN = -1;
}
activeStream = ConvertAudioStreamId_ExternalToXBMC(audioN);
}
}
return activeStream;
}
std::string CDVDInputStreamNavigator::GetAudioStreamLanguage(int iId)
{
if (!m_dvdnav) return NULL;
CStdString strLanguage;
audio_attr_t audio_attributes;
int streamId = ConvertAudioStreamId_XBMCToExternal(iId);
if( m_dll.dvdnav_get_audio_info(m_dvdnav, streamId, &audio_attributes) == DVDNAV_STATUS_OK )
{
if (!g_LangCodeExpander.Lookup(strLanguage, audio_attributes.lang_code)) strLanguage = "Unknown";
switch( audio_attributes.lang_extension )
{
case DVD_AUDIO_LANG_EXT_VisuallyImpaired:
strLanguage+= " (Visually Impaired)";
break;
case DVD_AUDIO_LANG_EXT_DirectorsComments1:
strLanguage+= " (Directors Comments)";
break;
case DVD_AUDIO_LANG_EXT_DirectorsComments2:
strLanguage+= " (Directors Comments 2)";
break;
case DVD_AUDIO_LANG_EXT_NotSpecified:
case DVD_AUDIO_LANG_EXT_NormalCaptions:
default:
break;
}
}
return strLanguage;
}
int CDVDInputStreamNavigator::GetAudioStreamCount()
{
if (!m_dvdnav) return 0;
vm_t* vm = m_dll.dvdnav_get_vm(m_dvdnav);
if (!vm) return 0;
if (!vm->state.pgc) return 0;
if (vm->state.domain == VTS_DOMAIN)
{
int streamN = 0;
for (int i = 0; i < 8; i++)
{
if (vm->state.pgc->audio_control[i] & (1<<15))
streamN++;
}
return streamN;
}
else
{
/* just for good measure say that non vts domain always has one */
return 1;
}