void CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag) { CVideoDatabase videoDatabase; CBookmark bookmark; bookmark.timeInSeconds = (int)g_application.GetTime(); bookmark.totalTimeInSeconds = (int)g_application.GetTotalTime(); if( g_application.m_pPlayer ) bookmark.playerState = g_application.m_pPlayer->GetPlayerState(); else bookmark.playerState.Empty(); bookmark.player = CPlayerCoreFactory::GetPlayerName(g_application.GetCurrentPlayer()); // create the thumbnail image #ifdef HAS_VIDEO_PLAYBACK float aspectRatio = g_renderManager.GetAspectRatio(); #else float aspectRatio = 1.0f; #endif int width = BOOKMARK_THUMB_WIDTH; int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio); if (height > BOOKMARK_THUMB_WIDTH) { height = BOOKMARK_THUMB_WIDTH; width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio); } { #ifdef HAS_VIDEO_PLAYBACK CRenderCapture* thumbnail = g_renderManager.AllocRenderCapture(); g_renderManager.Capture(thumbnail, width, height, CAPTUREFLAG_IMMEDIATELY); if (thumbnail->GetUserState() == CAPTURESTATE_DONE) { Crc32 crc; crc.ComputeFromLowerCase(g_application.CurrentFile()); bookmark.thumbNailImage.Format("%08x_%i.jpg", (unsigned __int32) crc, m_vecItems->Size() + 1); bookmark.thumbNailImage = URIUtils::AddFileToFolder(g_settings.GetBookmarksThumbFolder(), bookmark.thumbNailImage); if (!CPicture::CreateThumbnailFromSurface(thumbnail->GetPixels(), width, height, thumbnail->GetWidth() * 4, bookmark.thumbNailImage)) bookmark.thumbNailImage.Empty(); } else CLog::Log(LOGERROR,"CGUIDialogVideoBookmarks: failed to create thumbnail"); g_renderManager.ReleaseRenderCapture(thumbnail); #endif } videoDatabase.Open(); if (tag) videoDatabase.AddBookMarkForEpisode(*tag, bookmark); else videoDatabase.AddBookMarkToFile(g_application.CurrentFile(), bookmark, CBookmark::STANDARD); videoDatabase.Close(); Update(); }
void CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag) { CVideoDatabase videoDatabase; CBookmark bookmark; bookmark.timeInSeconds = (int)g_application.GetTime(); bookmark.totalTimeInSeconds = (int)g_application.GetTotalTime(); if( g_application.m_pPlayer ) bookmark.playerState = g_application.m_pPlayer->GetPlayerState(); else bookmark.playerState.Empty(); bookmark.player = CPlayerCoreFactory::GetPlayerName(g_application.GetCurrentPlayer()); // create the thumbnail image #ifdef HAS_VIDEO_PLAYBACK float aspectRatio = g_renderManager.GetAspectRatio(); #else float aspectRatio = 1.0f; #endif int width = BOOKMARK_THUMB_WIDTH; int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio); if (height > BOOKMARK_THUMB_WIDTH) { height = BOOKMARK_THUMB_WIDTH; width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio); } { CSingleLock lock(g_graphicsContext); // we're really just using the CTexture here as a pixel buffer CTexture texture(width, height, XB_FMT_B8G8R8A8); #ifdef HAS_VIDEO_PLAYBACK //g_renderManager.CreateThumbnail(&texture, width, height); #endif Crc32 crc; crc.ComputeFromLowerCase(g_application.CurrentFile()); bookmark.thumbNailImage.Format("%08x_%i.jpg", (unsigned __int32) crc, m_vecItems->Size() + 1); bookmark.thumbNailImage = CUtil::AddFileToFolder(g_settings.GetBookmarksThumbFolder(), bookmark.thumbNailImage); if (!CPicture::CreateThumbnailFromSurface(texture.GetPixels(), width, height, texture.GetPitch(), bookmark.thumbNailImage)) bookmark.thumbNailImage.Empty(); } videoDatabase.Open(); if (tag) videoDatabase.AddBookMarkForEpisode(*tag, bookmark); else videoDatabase.AddBookMarkToFile(g_application.CurrentFile(), bookmark, CBookmark::STANDARD); videoDatabase.Close(); Update(); }
bool CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag) { CVideoDatabase videoDatabase; CBookmark bookmark; bookmark.timeInSeconds = (int)g_application.GetTime(); bookmark.totalTimeInSeconds = (int)g_application.GetTotalTime(); if( g_application.m_pPlayer->HasPlayer() ) bookmark.playerState = g_application.m_pPlayer->GetPlayerState(); else bookmark.playerState.clear(); bookmark.player = g_application.GetCurrentPlayer(); // create the thumbnail image float aspectRatio = g_application.m_pPlayer->GetRenderAspectRatio(); int width = BOOKMARK_THUMB_WIDTH; int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio); if (height > (int)BOOKMARK_THUMB_WIDTH) { height = BOOKMARK_THUMB_WIDTH; width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio); } uint8_t *pixels = (uint8_t*)malloc(height * width * 4); unsigned int captureId = g_application.m_pPlayer->RenderCaptureAlloc(); g_application.m_pPlayer->RenderCapture(captureId, width, height, CAPTUREFLAG_IMMEDIATELY); bool hasImage = g_application.m_pPlayer->RenderCaptureGetPixels(captureId, 1000, pixels, height * width * 4); if (hasImage) { auto crc = Crc32::ComputeFromLowerCase(g_application.CurrentFile()); bookmark.thumbNailImage = StringUtils::Format("%08x_%i.jpg", crc, (int)bookmark.timeInSeconds); bookmark.thumbNailImage = URIUtils::AddFileToFolder(CProfilesManager::GetInstance().GetBookmarksThumbFolder(), bookmark.thumbNailImage); if (!CPicture::CreateThumbnailFromSurface(pixels, width, height, width * 4, bookmark.thumbNailImage)) { bookmark.thumbNailImage.clear(); } else CLog::Log(LOGERROR,"CGUIDialogVideoBookmarks: failed to create thumbnail"); g_application.m_pPlayer->RenderCaptureRelease(captureId); } else CLog::Log(LOGERROR,"CGUIDialogVideoBookmarks: failed to create thumbnail 2"); free(pixels); videoDatabase.Open(); if (tag) videoDatabase.AddBookMarkForEpisode(*tag, bookmark); else { std::string path = g_application.CurrentFile(); if (g_application.CurrentFileItem().HasProperty("original_listitem_url") && !URIUtils::IsVideoDb(g_application.CurrentFileItem().GetProperty("original_listitem_url").asString())) path = g_application.CurrentFileItem().GetProperty("original_listitem_url").asString(); videoDatabase.AddBookMarkToFile(path, bookmark, CBookmark::STANDARD); } videoDatabase.Close(); return true; }
bool CGUIDialogVideoBookmarks::AddBookmark(CVideoInfoTag* tag) { CVideoDatabase videoDatabase; CBookmark bookmark; bookmark.timeInSeconds = (int)g_application.GetTime(); bookmark.totalTimeInSeconds = (int)g_application.GetTotalTime(); if( g_application.m_pPlayer->HasPlayer() ) bookmark.playerState = g_application.m_pPlayer->GetPlayerState(); else bookmark.playerState.clear(); bookmark.player = CPlayerCoreFactory::Get().GetPlayerName(g_application.GetCurrentPlayer()); // create the thumbnail image #ifdef HAS_VIDEO_PLAYBACK float aspectRatio = g_renderManager.GetAspectRatio(); #else float aspectRatio = 1.0f; #endif int width = BOOKMARK_THUMB_WIDTH; int height = (int)(BOOKMARK_THUMB_WIDTH / aspectRatio); if (height > (int)BOOKMARK_THUMB_WIDTH) { height = BOOKMARK_THUMB_WIDTH; width = (int)(BOOKMARK_THUMB_WIDTH * aspectRatio); } { #ifdef HAS_VIDEO_PLAYBACK CRenderCapture* thumbnail = g_renderManager.AllocRenderCapture(); if (thumbnail) { g_renderManager.Capture(thumbnail, width, height, CAPTUREFLAG_IMMEDIATELY); if (thumbnail->GetUserState() == CAPTURESTATE_DONE) { Crc32 crc; crc.ComputeFromLowerCase(g_application.CurrentFile()); bookmark.thumbNailImage = StringUtils::Format("%08x_%i.jpg", (unsigned __int32) crc, (int)bookmark.timeInSeconds); bookmark.thumbNailImage = URIUtils::AddFileToFolder(CProfilesManager::Get().GetBookmarksThumbFolder(), bookmark.thumbNailImage); if (!CPicture::CreateThumbnailFromSurface(thumbnail->GetPixels(), width, height, thumbnail->GetWidth() * 4, bookmark.thumbNailImage)) bookmark.thumbNailImage.clear(); } else CLog::Log(LOGERROR,"CGUIDialogVideoBookmarks: failed to create thumbnail"); g_renderManager.ReleaseRenderCapture(thumbnail); } #endif } videoDatabase.Open(); if (tag) videoDatabase.AddBookMarkForEpisode(*tag, bookmark); else { std::string path = g_application.CurrentFile(); if (g_application.CurrentFileItem().HasProperty("original_listitem_url") && !URIUtils::IsVideoDb(g_application.CurrentFileItem().GetProperty("original_listitem_url").asString())) path = g_application.CurrentFileItem().GetProperty("original_listitem_url").asString(); videoDatabase.AddBookMarkToFile(path, bookmark, CBookmark::STANDARD); } videoDatabase.Close(); return true; }