Skip to content
This repository
Browse code

dvd unique id - final

  • Loading branch information...
commit c4fe6cf7190dc9d44cb4196fc02cb69be3407fc7 1 parent 7149274
Voyager-xbmc authored
1  xbmc/ApplicationMessenger.cpp
@@ -713,6 +713,7 @@ case TMSG_POWERDOWN:
713 713 {
714 714 CMediaSource share;
715 715 share.strStatus = g_mediaManager.GetDiskLabel(share.strPath);
  716 + share.strDiskUniqueId = g_mediaManager.GetDiskUniqueId(share.strPath);
716 717 share.strPath = pMsg->strParam;
717 718 if(g_mediaManager.IsAudio(share.strPath))
718 719 share.strStatus = "Audio-CD";
40 xbmc/Autorun.cpp
@@ -53,7 +53,7 @@ CAutorun::CAutorun()
53 53 CAutorun::~CAutorun()
54 54 {}
55 55
56   -void CAutorun::ExecuteAutorun( bool bypassSettings, bool ignoreplaying, bool restart )
  56 +void CAutorun::ExecuteAutorun( bool bypassSettings, bool ignoreplaying, bool startFromBeginning )
57 57 {
58 58 if ((!ignoreplaying && (g_application.IsPlayingAudio() || g_application.IsPlayingVideo() || g_windowManager.HasModalDialog())) || g_windowManager.GetActiveWindow() == WINDOW_LOGIN_SCREEN)
59 59 return ;
@@ -79,7 +79,7 @@ void CAutorun::ExecuteAutorun( bool bypassSettings, bool ignoreplaying, bool res
79 79 }
80 80 else
81 81 {
82   - RunMedia(bypassSettings, restart);
  82 + RunMedia(bypassSettings, startFromBeginning);
83 83 }
84 84 }
85 85
@@ -100,7 +100,7 @@ void CAutorun::RunCdda()
100 100 g_playlistPlayer.Play();
101 101 }
102 102
103   -void CAutorun::RunMedia(bool bypassSettings, bool restart)
  103 +void CAutorun::RunMedia(bool bypassSettings, bool startFromBeginning)
104 104 {
105 105 if ( !bypassSettings && !g_guiSettings.GetBool("audiocds.autorun") && !g_guiSettings.GetBool("dvds.autorun"))
106 106 return ;
@@ -109,7 +109,7 @@ void CAutorun::RunMedia(bool bypassSettings, bool restart)
109 109 int nAddedToPlaylist = 0;
110 110 #ifdef _WIN32
111 111 auto_ptr<IDirectory> pDir ( CFactoryDirectory::Create( g_mediaManager.TranslateDevicePath("") ));
112   - bool bPlaying = RunDisc(pDir.get(), g_mediaManager.TranslateDevicePath(""), nAddedToPlaylist, true, bypassSettings, restart);
  112 + bool bPlaying = RunDisc(pDir.get(), g_mediaManager.TranslateDevicePath(""), nAddedToPlaylist, true, bypassSettings, startFromBeginning);
113 113 #else
114 114 CCdInfo* pInfo = g_mediaManager.GetCdInfo();
115 115
@@ -120,12 +120,12 @@ void CAutorun::RunMedia(bool bypassSettings, bool restart)
120 120 if (pInfo->IsISOUDF(1) || pInfo->IsISOHFS(1) || pInfo->IsIso9660(1) || pInfo->IsIso9660Interactive(1))
121 121 {
122 122 auto_ptr<IDirectory> pDir ( CFactoryDirectory::Create( "iso9660://" ));
123   - bPlaying = RunDisc(pDir.get(), "iso9660://", nAddedToPlaylist, true, bypassSettings, restart);
  123 + bPlaying = RunDisc(pDir.get(), "iso9660://", nAddedToPlaylist, true, bypassSettings, startFromBeginning);
124 124 }
125 125 else
126 126 {
127 127 auto_ptr<IDirectory> pDir ( CFactoryDirectory::Create( "D:\\" ) );
128   - bPlaying = RunDisc(pDir.get(), "D:\\", nAddedToPlaylist, true, bypassSettings, restart);
  128 + bPlaying = RunDisc(pDir.get(), "D:\\", nAddedToPlaylist, true, bypassSettings, startFromBeginning);
129 129 }
130 130 #endif
131 131 if ( !bPlaying && nAddedToPlaylist > 0 )
@@ -141,7 +141,7 @@ void CAutorun::RunMedia(bool bypassSettings, bool restart)
141 141 /**
142 142 * This method tries to determine what type of disc is located in the given drive and starts to play the content appropriately.
143 143 */
144   -bool CAutorun::RunDisc(IDirectory* pDir, const CStdString& strDrive, int& nAddedToPlaylist, bool bRoot, bool bypassSettings /* = false */, bool restart /* = false */)
  144 +bool CAutorun::RunDisc(IDirectory* pDir, const CStdString& strDrive, int& nAddedToPlaylist, bool bRoot, bool bypassSettings /* = false */, bool startFromBeginning /* = false */)
145 145 {
146 146 bool bPlaying(false);
147 147 CFileItemList vecItems;
@@ -179,7 +179,7 @@ bool CAutorun::RunDisc(IDirectory* pDir, const CStdString& strDrive, int& nAdded
179 179 if (pItem->GetPath().Find( "VIDEO_TS" ) != -1 && bAllowVideo
180 180 && (bypassSettings || g_guiSettings.GetBool("dvds.autorun")))
181 181 {
182   - CUtil::PlayDVD("dvd", restart);
  182 + CUtil::PlayDVD("dvd", startFromBeginning);
183 183 bPlaying = true;
184 184 return true;
185 185 }
@@ -190,7 +190,7 @@ bool CAutorun::RunDisc(IDirectory* pDir, const CStdString& strDrive, int& nAdded
190 190 if (pItem->GetPath().Find( "BDMV" ) != -1 && bAllowVideo
191 191 && (bypassSettings || g_guiSettings.GetBool("dvds.autorun")))
192 192 {
193   - CUtil::PlayDVD("bd", restart);
  193 + CUtil::PlayDVD("bd", startFromBeginning);
194 194 bPlaying = true;
195 195 return true;
196 196 }
@@ -321,7 +321,7 @@ bool CAutorun::RunDisc(IDirectory* pDir, const CStdString& strDrive, int& nAdded
321 321 {
322 322 if (pItem->GetPath() != "." && pItem->GetPath() != ".." )
323 323 {
324   - if (RunDisc(pDir, pItem->GetPath(), nAddedToPlaylist, false, bypassSettings, restart))
  324 + if (RunDisc(pDir, pItem->GetPath(), nAddedToPlaylist, false, bypassSettings, startFromBeginning))
325 325 {
326 326 bPlaying = true;
327 327 break;
@@ -366,21 +366,23 @@ bool CAutorun::IsEnabled() const
366 366 return m_bEnable;
367 367 }
368 368
369   -bool CAutorun::PlayDisc(bool restart)
  369 +bool CAutorun::PlayDisc(bool startFromBeginning)
370 370 {
371   - ExecuteAutorun(true,true, restart);
  371 + ExecuteAutorun(true,true, startFromBeginning);
372 372 return true;
373 373 }
374 374
375 375 bool CAutorun::CanResumePlayDVD()
376 376 {
377   - CStdString strPath = "removable://"; // need to put volume label for resume point in videoInfoTag
378   - strPath += g_mediaManager.GetDiskLabel();
379   - CVideoDatabase dbs;
380   - dbs.Open();
381   - CBookmark bookmark;
382   - if (dbs.GetResumeBookMark(strPath, bookmark))
383   - return true;
  377 + CStdString strUniqueId = g_mediaManager.GetDiskUniqueId();
  378 + if (!strUniqueId.IsEmpty())
  379 + {
  380 + CVideoDatabase dbs;
  381 + dbs.Open();
  382 + CBookmark bookmark;
  383 + if (dbs.GetResumeBookMark(strUniqueId, bookmark))
  384 + return true;
  385 + }
384 386 return false;
385 387 }
386 388
8 xbmc/Autorun.h
@@ -48,16 +48,16 @@ class CAutorun
48 48 CAutorun();
49 49 virtual ~CAutorun();
50 50 static bool CanResumePlayDVD();
51   - static bool PlayDisc(bool restart);
  51 + static bool PlayDisc(bool startFromBeginning);
52 52 bool IsEnabled() const;
53 53 void Enable();
54 54 void Disable();
55 55 void HandleAutorun();
56   - static void ExecuteAutorun(bool bypassSettings = false, bool ignoreplaying = false, bool restart = false);
  56 + static void ExecuteAutorun(bool bypassSettings = false, bool ignoreplaying = false, bool startFromBeginning = false);
57 57 protected:
58 58 static void RunCdda();
59   - static void RunMedia(bool bypassSettings, bool restart);
60   - static bool RunDisc(XFILE::IDirectory* pDir, const CStdString& strDrive, int& nAddedToPlaylist, bool bRoot, bool bypassSettings, bool restart);
  59 + static void RunMedia(bool bypassSettings, bool startFromBeginning);
  60 + static bool RunDisc(XFILE::IDirectory* pDir, const CStdString& strDrive, int& nAddedToPlaylist, bool bRoot, bool bypassSettings, bool startFromBeginning);
61 61 bool m_bEnable;
62 62 };
63 63 }
5 xbmc/FileItem.cpp
@@ -218,10 +218,7 @@ CFileItem::CFileItem(const CMediaSource& share)
218 218 m_strThumbnailImage = share.m_strThumbnailImage;
219 219 SetLabelPreformated(true);
220 220 if (IsDVD())
221   - {
222   - GetVideoInfoTag()->m_strFileNameAndPath = "removable://";
223   - GetVideoInfoTag()->m_strFileNameAndPath += share.strStatus; // share.strStatus contains disc volume label
224   - }
  221 + GetVideoInfoTag()->m_strFileNameAndPath = share.strDiskUniqueId; // share.strDiskUniqueId contains disc unique id
225 222 }
226 223
227 224 CFileItem::~CFileItem(void)
1  xbmc/MediaSource.h
@@ -51,6 +51,7 @@ class CMediaSource
51 51 bool IsWritable() const;
52 52 CStdString strName; ///< Name of the share, can be choosen freely.
53 53 CStdString strStatus; ///< Status of the share (eg has disk etc.)
  54 + CStdString strDiskUniqueId; ///< removable:// + DVD Label + DVD ID for resume point storage, if available
54 55 CStdString strPath; ///< Path of the share, eg. iso9660:// or F:
55 56
56 57 /*!
12 xbmc/Util.cpp
@@ -770,7 +770,7 @@ bool CUtil::ThumbCached(const CStdString& strFileName)
770 770 return CThumbnailCache::GetThumbnailCache()->IsCached(strFileName);
771 771 }
772 772
773   -void CUtil::PlayDVD(const CStdString& strProtocol, bool restart)
  773 +void CUtil::PlayDVD(const CStdString& strProtocol, bool startFromBeginning)
774 774 {
775 775 #if defined(HAS_DVDPLAYER) && defined(HAS_DVD_DRIVE)
776 776 CIoSupport::Dismount("Cdrom0");
@@ -779,10 +779,12 @@ void CUtil::PlayDVD(const CStdString& strProtocol, bool restart)
779 779 strPath.Format("%s://1", strProtocol.c_str());
780 780 CFileItem item(strPath, false);
781 781 item.SetLabel(g_mediaManager.GetDiskLabel());
782   - item.GetVideoInfoTag()->m_strFileNameAndPath = "removable://"; // need to put volume label for resume point in videoInfoTag
783   - item.GetVideoInfoTag()->m_strFileNameAndPath += g_mediaManager.GetDiskLabel();
784   - if (!restart) item.m_lStartOffset = STARTOFFSET_RESUME;
785   - g_application.PlayFile(item, restart);
  782 + item.GetVideoInfoTag()->m_strFileNameAndPath = g_mediaManager.GetDiskUniqueId();
  783 +
  784 + if (!startFromBeginning && !item.GetVideoInfoTag()->m_strFileNameAndPath.IsEmpty())
  785 + item.m_lStartOffset = STARTOFFSET_RESUME;
  786 +
  787 + g_application.PlayFile(item, false);
786 788 #endif
787 789 }
788 790
2  xbmc/Util.h
@@ -90,7 +90,7 @@ class CUtil
90 90 static bool ThumbCached(const CStdString& strFileName);
91 91 static void ThumbCacheAdd(const CStdString& strFileName, bool bFileExists);
92 92 static void ThumbCacheClear();
93   - static void PlayDVD(const CStdString& strProtocol = "dvd", bool restart = false);
  93 + static void PlayDVD(const CStdString& strProtocol = "dvd", bool startFromBeginning = false);
94 94 static CStdString GetNextFilename(const CStdString &fn_template, int max);
95 95 static CStdString GetNextPathname(const CStdString &path_template, int max);
96 96 static void TakeScreenshot();
2  xbmc/filesystem/VirtualDirectory.cpp
@@ -182,10 +182,12 @@ void CVirtualDirectory::GetSources(VECSOURCES &shares) const
182 182 {
183 183 share.strStatus = "Audio-CD";
184 184 share.strPath = "cdda://local/";
  185 + share.strDiskUniqueId = "";
185 186 }
186 187 else
187 188 {
188 189 share.strStatus = g_mediaManager.GetDiskLabel(share.strPath);
  190 + share.strDiskUniqueId = g_mediaManager.GetDiskUniqueId(share.strPath);
189 191 if (!share.strPath.length()) // unmounted CD
190 192 {
191 193 if (g_mediaManager.GetDiscPath() == "iso9660://")
114 xbmc/storage/MediaManager.cpp
@@ -25,9 +25,9 @@
25 25 #include "IoSupport.h"
26 26 #include "URL.h"
27 27 #include "Util.h"
  28 +#include "utils/URIUtils.h"
28 29 #ifdef _WIN32
29 30 #include "WIN32Util.h"
30   -#include "utils/URIUtils.h"
31 31 #endif
32 32 #include "guilib/GUIWindowManager.h"
33 33 #ifdef HAS_DVD_DRIVE
@@ -48,6 +48,12 @@
48 48 #include "AutorunMediaJob.h"
49 49 #include "settings/GUISettings.h"
50 50
  51 +#include "FileItem.h"
  52 +#include "filesystem/File.h"
  53 +#include "filesystem/FactoryDirectory.h"
  54 +#include "filesystem/Directory.h"
  55 +#include "utils/Crc32.h"
  56 +
51 57 #ifdef __APPLE__
52 58 #include "osx/DarwinStorageProvider.h"
53 59 #elif defined(_LINUX)
@@ -57,6 +63,7 @@
57 63 #endif
58 64
59 65 using namespace std;
  66 +using namespace XFILE;
60 67
61 68 const char MEDIA_SOURCES_XML[] = { "special://profile/mediasources.xml" };
62 69
@@ -435,6 +442,111 @@ CStdString CMediaManager::GetDiskLabel(const CStdString& devicePath)
435 442 #endif
436 443 }
437 444
  445 +CStdString CMediaManager::GetDiskUniqueId(const CStdString& devicePath)
  446 +{
  447 + CStdString strDevice = devicePath;
  448 +
  449 + if (strDevice.IsEmpty()) // if no value passed, use the current default disc path.
  450 + strDevice = GetDiscPath(); // in case of non-Windows we must obtain the disc path
  451 +
  452 +#ifdef _WIN32
  453 + if (!m_bhasoptical)
  454 + return "";
  455 + strDevice = TranslateDevicePath(strDevice);
  456 + URIUtils::AddSlashAtEnd(strDevice);
  457 +#endif
  458 +
  459 + CStdString strDrive = g_mediaManager.TranslateDevicePath(strDevice);
  460 +
  461 +#ifndef _WIN32
  462 + {
  463 + CSingleLock waitLock(m_muAutoSource);
  464 + CCdInfo* pInfo = g_mediaManager.GetCdInfo();
  465 + if ( pInfo )
  466 + {
  467 + if (pInfo->IsISOUDF(1) || pInfo->IsISOHFS(1) || pInfo->IsIso9660(1) || pInfo->IsIso9660Interactive(1))
  468 + strDrive = "iso9660://";
  469 + else
  470 + strDrive = "D:\\";
  471 + }
  472 + else
  473 + {
  474 + CLog::Log(LOGERROR, "GetDiskUniqueId: Failed getting CD info");
  475 + return "";
  476 + }
  477 + }
  478 +#endif
  479 +
  480 + CStdString pathVideoTS = URIUtils::AddFileToFolder(strDrive, "VIDEO_TS");
  481 + if(! CDirectory::Exists(pathVideoTS) )
  482 + return ""; // return empty
  483 +
  484 + CLog::Log(LOGDEBUG, "GetDiskUniqueId: Trying to retrieve ID for path %s", pathVideoTS.c_str());
  485 + uint32_t dvdcrc = 0;
  486 + CStdString strID;
  487 +
  488 + if (HashDVD(pathVideoTS, dvdcrc))
  489 + {
  490 + strID.Format("removable://%s_%08x", GetDiskLabel(devicePath), dvdcrc);
  491 + CLog::Log(LOGDEBUG, "GetDiskUniqueId: Got ID %s for DVD disk", strID.c_str());
  492 + }
  493 +
  494 + return strID;
  495 +}
  496 +
  497 +bool CMediaManager::HashDVD(const CStdString& dvdpath, uint32_t& crc)
  498 +{
  499 + CFileItemList vecItemsTS;
  500 + bool success = false;
  501 +
  502 + // first try to open the VIDEO_TS folder of the DVD
  503 + if (!CDirectory::GetDirectory( dvdpath, vecItemsTS, ".ifo" ))
  504 + {
  505 + CLog::Log(LOGERROR, "%s - Cannot open dvd VIDEO_TS folder -- ABORTING", __FUNCTION__);
  506 + return false;
  507 + }
  508 +
  509 + Crc32 crc32;
  510 + bool dataRead = false;
  511 +
  512 + vecItemsTS.Sort(SORT_METHOD_FILE, SORT_ORDER_ASC);
  513 + for (int i = 0; i < vecItemsTS.Size(); i++)
  514 + {
  515 + CFileItemPtr videoTSItem = vecItemsTS[i];
  516 + success = true;
  517 +
  518 + // get the file name for logging purposes
  519 + CStdString fileName = URIUtils::GetFileName(videoTSItem->GetPath());
  520 + CLog::Log(LOGDEBUG, "%s - Adding file content for dvd file: %s", __FUNCTION__, fileName.c_str());
  521 + CFile file;
  522 + if(!file.Open(videoTSItem->GetPath()))
  523 + {
  524 + CLog::Log(LOGERROR, "%s - Cannot open dvd file: %s -- ABORTING", __FUNCTION__, fileName.c_str());
  525 + return false;
  526 + }
  527 + int res;
  528 + char buf[2048];
  529 + while( (res = file.Read(buf, sizeof(buf))) > 0)
  530 + {
  531 + dataRead = true;
  532 + crc32.Compute(buf, res);
  533 + }
  534 + file.Close();
  535 + }
  536 +
  537 + if (!dataRead)
  538 + {
  539 + CLog::Log(LOGERROR, "%s - Did not read any data from the IFO files -- ABORTING", __FUNCTION__);
  540 + return false;
  541 + }
  542 +
  543 + // put result back in reference parameter
  544 + crc = (uint32_t) crc32;
  545 +
  546 + return success;
  547 +}
  548 +
  549 +
438 550 CStdString CMediaManager::GetDiscPath()
439 551 {
440 552 #ifdef _WIN32
2  xbmc/storage/MediaManager.h
@@ -72,6 +72,7 @@ class CMediaManager : public IStorageEventsCallback, public IJobCallback
72 72 CCdInfo* GetCdInfo(const CStdString& devicePath="");
73 73 bool RemoveCdInfo(const CStdString& devicePath="");
74 74 CStdString GetDiskLabel(const CStdString& devicePath="");
  75 + CStdString GetDiskUniqueId(const CStdString& devicePath="");
75 76 #endif
76 77 CStdString GetDiscPath();
77 78 void SetHasOpticalDrive(bool bstatus);
@@ -93,6 +94,7 @@ class CMediaManager : public IStorageEventsCallback, public IJobCallback
93 94 CCriticalSection m_muAutoSource, m_CritSecStorageProvider;
94 95 #ifdef HAS_DVD_DRIVE
95 96 std::map<CStdString,CCdInfo*> m_mapCdInfo;
  97 + bool HashDVD(const CStdString& dvdpath, uint32_t& crc);
96 98 #endif
97 99 bool m_bhasoptical;
98 100
2  xbmc/utils/SaveFileStateJob.h
@@ -26,7 +26,7 @@ bool CSaveFileStateJob::DoWork()
26 26 CStdString progressTrackingFile = m_item.GetPath();
27 27
28 28 if (m_item.IsDVD())
29   - progressTrackingFile = m_item.GetVideoInfoTag()->m_strFileNameAndPath; // this variable contains removable:// suffixed by disc label
  29 + progressTrackingFile = m_item.GetVideoInfoTag()->m_strFileNameAndPath; // this variable contains removable:// suffixed by disc label+uniqueid or is empty if label not uniquely identified
30 30
31 31 if (progressTrackingFile != "")
32 32 {

0 comments on commit c4fe6cf

Please sign in to comment.
Something went wrong with that request. Please try again.