private ThreadStart AllJobs() { return(() => executeWithExecutor(executor => { CleanupJob job = null; do { try { job = _jobs.poll(100, TimeUnit.MILLISECONDS); if (job != null) { job.Run(executor); } } catch (Exception) { // There's no audience for these exceptions. The jobs themselves know if they've failed and communicates // that to its tree. The scheduled job is just a vessel for running these cleanup jobs. } finally { if (job != null) { job.Close(); } } } while (!_jobs.Empty || !_started); // Even if there are no jobs in the queue then continue looping until we go to started state })); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var commandBuffer = _commandBufferSystem.CreateCommandBuffer().ToConcurrent(); var updateJob = new UpdateJob { attackTemplate = _enemyAttack, movementTemplate = _enemyMovement, entityType = GetArchetypeChunkEntityType(), raycastResultStateType = GetArchetypeChunkComponentType <RaycastResultState>(false), raycastResultType = GetArchetypeChunkComponentType <RaycastResult>(true), movementType = GetArchetypeChunkComponentType <Movement>(true), attackType = GetArchetypeChunkComponentType <EnemyAttack>(true), targetType = GetArchetypeChunkComponentType <TargetOwnership>(false), commands = commandBuffer }; var cleanupJob = new CleanupJob { commands = commandBuffer }; inputDeps = updateJob.Schedule(_updateQuery, inputDeps); inputDeps = updateJob.Schedule(_updateQueryNoState, inputDeps); inputDeps = cleanupJob.Schedule(_cleanupQuery, inputDeps); _commandBufferSystem.AddJobHandleForProducer(inputDeps); return(inputDeps); }
public override void Add(CleanupJob job) { if (_started) { throw new System.InvalidOperationException("Index clean jobs can't be added after collector start."); } _jobs.add(job); }
public LogItem postprocess() { audioFiles = vUtil.getAllDemuxedAudio(job.AudioTracks, job.Output, 8); fillInAudioInformation(); log.LogValue("Desired size", job.PostprocessingProperties.OutputSize); log.LogValue("Split size", job.PostprocessingProperties.Splitting); VideoCodecSettings videoSettings = job.PostprocessingProperties.VideoSettings; string videoOutput = Path.Combine(Path.GetDirectoryName(job.Output), Path.GetFileNameWithoutExtension(job.Output) + "_Video"); string muxedOutput = job.PostprocessingProperties.FinalOutput; //Open the video Dar? dar; string videoInput = openVideo(job.Output, job.PostprocessingProperties.DAR, job.PostprocessingProperties.HorizontalOutputResolution, job.PostprocessingProperties.SignalAR, log, job.PostprocessingProperties.AvsSettings, job.PostprocessingProperties.AutoDeinterlace, videoSettings, out dar); VideoStream myVideo = new VideoStream(); ulong length; double framerate; JobUtil.getInputProperties(out length, out framerate, videoInput); myVideo.Input = videoInput; myVideo.Output = videoOutput; myVideo.NumberOfFrames = length; myVideo.Framerate = (decimal)framerate; myVideo.DAR = dar; myVideo.VideoType = new MuxableType((new VideoEncoderProvider().GetSupportedOutput(videoSettings.EncoderType))[0], videoSettings.Codec); myVideo.Settings = videoSettings; List <string> intermediateFiles = new List <string>(); intermediateFiles.Add(videoInput); intermediateFiles.Add(job.Output); intermediateFiles.AddRange(audioFiles.Values); if (!string.IsNullOrEmpty(videoInput)) { //Create empty subtitles for muxing (subtitles not supported in one click mode) MuxStream[] subtitles = new MuxStream[0]; JobChain c = vUtil.GenerateJobSeries(myVideo, muxedOutput, job.PostprocessingProperties.AudioJobs, subtitles, job.PostprocessingProperties.ChapterFile, job.PostprocessingProperties.OutputSize, job.PostprocessingProperties.Splitting, job.PostprocessingProperties.Container, false, job.PostprocessingProperties.DirectMuxAudio, log); if (c == null) { log.Warn("Job creation aborted"); return(log); } c = CleanupJob.AddAfter(c, intermediateFiles); mainForm.Jobs.addJobsWithDependencies(c); } return(log); }
public void postprocess() { audioFiles = vUtil.getAllDemuxedAudio(job.Output, 8); fillInAudioInformation(); logBuilder.Append("Desired size of this automated encoding series: " + job.PostprocessingProperties.OutputSize + " split size: " + job.PostprocessingProperties.Splitting + "\r\n"); VideoCodecSettings videoSettings = job.PostprocessingProperties.VideoSettings; string videoOutput = Path.Combine(Path.GetDirectoryName(job.Output), Path.GetFileNameWithoutExtension(job.Output) + "_Video"); string muxedOutput = job.PostprocessingProperties.FinalOutput; //Open the video Dar? dar; string videoInput = openVideo(job.Output, job.PostprocessingProperties.DAR, job.PostprocessingProperties.HorizontalOutputResolution, job.PostprocessingProperties.SignalAR, logBuilder, job.PostprocessingProperties.AvsSettings, job.PostprocessingProperties.AutoDeinterlace, videoSettings, out dar); VideoStream myVideo = new VideoStream(); ulong length; double framerate; JobUtil.getInputProperties(out length, out framerate, videoInput); myVideo.Input = videoInput; myVideo.Output = videoOutput; myVideo.NumberOfFrames = length; myVideo.Framerate = (decimal)framerate; myVideo.DAR = dar; myVideo.VideoType = new MuxableType((new VideoEncoderProvider().GetSupportedOutput(videoSettings.EncoderType))[0], videoSettings.Codec); myVideo.Settings = videoSettings; List <string> intermediateFiles = new List <string>(); intermediateFiles.Add(videoInput); intermediateFiles.Add(job.Output); intermediateFiles.AddRange(audioFiles.Values); if (!string.IsNullOrEmpty(videoInput)) { //Create empty subtitles for muxing (subtitles not supported in one click mode) MuxStream[] subtitles = new MuxStream[0]; JobChain c = vUtil.GenerateJobSeries(myVideo, muxedOutput, job.PostprocessingProperties.AudioJobs, subtitles, job.PostprocessingProperties.ChapterFile, job.PostprocessingProperties.OutputSize, job.PostprocessingProperties.Splitting, job.PostprocessingProperties.Container, false, job.PostprocessingProperties.DirectMuxAudio); /* vUtil.generateJobSeries(videoInput, videoOutput, muxedOutput, videoSettings, * audioStreams, audio, subtitles, job.PostprocessingProperties.ChapterFile, * job.PostprocessingProperties.OutputSize, job.PostprocessingProperties.SplitSize, * containerOverhead, type, new string[] { job.Output, videoInput });*/ c = CleanupJob.AddAfter(c, intermediateFiles); mainForm.Jobs.addJobsWithDependencies(c); } mainForm.addToLog(logBuilder.ToString()); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps = new CleanupJob { Ecb = m_EntityCommandBuffer.CreateCommandBuffer().ToConcurrent(), EntityType = GetArchetypeChunkEntityType(), DurationComponents = GetArchetypeChunkComponentType<GameplayEffectDurationComponent>(), AttributeEntityComponents = GetArchetypeChunkComponentType<GameplayEffectAttributeEntityComponent>() }.Schedule(m_Group, inputDeps); m_EntityCommandBuffer.AddJobHandleForProducer(inputDeps); return inputDeps; }
public override void Add(CleanupJob job) { ExecuteWithExecutor(executor => { try { job.Run(executor); } finally { job.Close(); } }); }
private void ExecuteCleanupJob() { CleanupJob job = _tenant.Container.Resolve <CleanupJob>(); IJobExecutionContext context = NSubstitute.Substitute.For <IJobExecutionContext>(); IJobDetail jobDetail = NSubstitute.Substitute.For <IJobDetail>(); IDictionary <string, object> mapd = new Dictionary <string, object>() { { JobKeys.TenantId.ToString(), _tenant.Id.ToString() } }; JobDataMap map = new JobDataMap(mapd); jobDetail.JobDataMap.Returns(map); context.JobDetail.Returns(jobDetail); job.Execute(context); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var job = new CleanupJob { DataForCleanup = BucketSystems.RockEntitiesBucketedByIndex, }.Schedule(JobHandle.CombineDependencies(DependencyJobs, inputDeps)); DependencyJobs = default; job = new CleanupJob { DataForCleanup = BucketSystems.TinCanEntitiesBucketedByIndex, }.Schedule(job); ecbSystem.AddJobHandleForProducer(job); return(job); }
protected override JobHandle OnUpdate(JobHandle inputDependencies) { var commandBuffer = _bufferSystem.CreateCommandBuffer().ToConcurrent(); //Create New Maps var createJob = Entities.WithAll <WorldMapViewData>().WithNone <WorldMapViewSystemData>().ForEach((int nativeThreadIndex, Entity entity) => { commandBuffer.AddComponent(nativeThreadIndex, entity, new WorldMapViewSystemData()); }).Schedule(inputDependencies); _bufferSystem.AddJobHandleForProducer(createJob); //Clean Up Destroyed Maps var destroyJob = Entities.WithAll <WorldMapViewSystemData>().WithNone <WorldMapViewData>().ForEach((int nativeThreadIndex, Entity entity) => { //Cleanup Destroyed Maps commandBuffer.RemoveComponent <WorldMapViewSystemData>(nativeThreadIndex, entity); }).Schedule(createJob); _bufferSystem.AddJobHandleForProducer(destroyJob); var tileArchetype = _tileArchetype; var cleanupJob = new CleanupJob { commandBuffer = _bufferSystem.CreateCommandBuffer().ToConcurrent(), mapViews = worldMapViewDataQuery.ToComponentDataArray <WorldMapViewData>(Allocator.TempJob) }; var cleanupJobHandle = cleanupJob.Schedule(worldMapTiles, destroyJob); _bufferSystem.AddJobHandleForProducer(cleanupJobHandle); var spawnJob = new SpawnJob() { CommandBuffer = _bufferSystem.CreateCommandBuffer().ToConcurrent(), OutOfViewTiles = outOfViewQuery.ToEntityArray(Allocator.TempJob), TileArchetype = tileArchetype }.Schedule(viewChangedQuery, cleanupJobHandle); _bufferSystem.AddJobHandleForProducer(spawnJob); return(spawnJob); }
private async void btnProcess_Click(object sender, EventArgs e) { SetState(AppState.Processing); m_ProcessCancelSource = new CancellationTokenSource(); var cleanupJob = new CleanupJob(m_LoadedRootFolder, m_CleanupJobSettings, m_ProcessCancelSource.Token); cleanupJob.ProgressUpdate += JobOnProgressUpdate; await cleanupJob.Run(); cleanupJob.ProgressUpdate -= JobOnProgressUpdate; if (m_ProcessCancelSource.IsCancellationRequested) { lblFilesProcessed.Text += " (Cancelled)"; } SetState(AppState.Loaded); }
private void StartPostProcessing() { Thread t = null; try { _log.LogEvent("Processing thread started"); raiseEvent("Preprocessing... ***PLEASE WAIT***"); _start = DateTime.Now; t = new Thread(new ThreadStart(delegate { while (true) { updateTime(); Thread.Sleep(1000); } })); t.Start(); List <string> arrAudioFilesDelete = new List <string>(); audioFiles = new Dictionary <int, string>(); List <AudioTrackInfo> arrAudioTracks = new List <AudioTrackInfo>(); List <AudioJob> arrAudioJobs = new List <AudioJob>(); List <MuxStream> arrMuxStreams = new List <MuxStream>(); List <string> intermediateFiles = new List <string>(); FileUtil.ensureDirectoryExists(job.PostprocessingProperties.WorkingDirectory); foreach (OneClickAudioTrack oAudioTrack in job.PostprocessingProperties.AudioTracks) { if (oAudioTrack.ExtractMKVTrack) { audioFiles.Add(oAudioTrack.AudioTrackInfo.TrackID, job.PostprocessingProperties.WorkingDirectory + "\\" + oAudioTrack.AudioTrackInfo.DemuxFileName); arrAudioFilesDelete.Add(job.PostprocessingProperties.WorkingDirectory + "\\" + oAudioTrack.AudioTrackInfo.DemuxFileName); } else if (oAudioTrack.AudioTrackInfo != null) { arrAudioTracks.Add(oAudioTrack.AudioTrackInfo); } if (oAudioTrack.AudioJob != null) { if (job.PostprocessingProperties.IndexType == FileIndexerWindow.IndexType.NONE && String.IsNullOrEmpty(oAudioTrack.AudioJob.Input)) { oAudioTrack.AudioJob.Input = job.Input; } arrAudioJobs.Add(oAudioTrack.AudioJob); } if (oAudioTrack.DirectMuxAudio != null) { arrMuxStreams.Add(oAudioTrack.DirectMuxAudio); } } if (audioFiles.Count == 0 && job.PostprocessingProperties.IndexType != FileIndexerWindow.IndexType.NONE && !job.PostprocessingProperties.Eac3toDemux) { audioFiles = vUtil.getAllDemuxedAudio(arrAudioTracks, new List <AudioTrackInfo>(), out arrAudioFilesDelete, job.IndexFile, _log); } fillInAudioInformation(arrAudioJobs, arrMuxStreams); if (!String.IsNullOrEmpty(job.PostprocessingProperties.VideoFileToMux)) { _log.LogEvent("Don't encode video: True"); } else { _log.LogEvent("Desired size: " + job.PostprocessingProperties.OutputSize); } _log.LogEvent("Split size: " + job.PostprocessingProperties.Splitting); // chapter file handling if (String.IsNullOrEmpty(job.PostprocessingProperties.ChapterFile)) { job.PostprocessingProperties.ChapterFile = null; } else if (job.PostprocessingProperties.Container == ContainerType.AVI) { _log.LogEvent("Chapter handling disabled because of the AVI target container"); job.PostprocessingProperties.ChapterFile = null; } else if (!File.Exists(job.PostprocessingProperties.ChapterFile)) { if (job.PostprocessingProperties.ChapterFile.StartsWith("<") || job.PostprocessingProperties.ChapterExtracted) { // internal chapter file string strTempFile = job.PostprocessingProperties.ChapterFile; if (Path.GetExtension(job.PostprocessingProperties.VideoInput).ToLower(System.Globalization.CultureInfo.InvariantCulture).Equals(".mkv")) { MediaInfoFile oInfo = new MediaInfoFile(job.PostprocessingProperties.VideoInput, ref _log); if (oInfo.hasMKVChapters()) { job.PostprocessingProperties.ChapterFile = Path.Combine(job.PostprocessingProperties.WorkingDirectory, Path.GetFileNameWithoutExtension(job.IndexFile) + " - Chapter Information.txt"); if (oInfo.extractMKVChapters(job.PostprocessingProperties.ChapterFile)) { intermediateFiles.Add(job.PostprocessingProperties.ChapterFile); job.PostprocessingProperties.ChapterExtracted = true; } else { job.PostprocessingProperties.ChapterFile = strTempFile; } } } else if (File.Exists(job.PostprocessingProperties.IFOInput)) { job.PostprocessingProperties.ChapterFile = VideoUtil.getChaptersFromIFO(job.PostprocessingProperties.IFOInput, false, job.PostprocessingProperties.WorkingDirectory, job.PostprocessingProperties.TitleNumberToProcess); if (!String.IsNullOrEmpty(job.PostprocessingProperties.ChapterFile)) { intermediateFiles.Add(job.PostprocessingProperties.ChapterFile); job.PostprocessingProperties.ChapterExtracted = true; } else { job.PostprocessingProperties.ChapterFile = strTempFile; } } } if (!File.Exists(job.PostprocessingProperties.ChapterFile)) { _log.LogEvent("File not found: " + job.PostprocessingProperties.ChapterFile, ImageType.Error); job.PostprocessingProperties.ChapterFile = null; } } else if (job.PostprocessingProperties.ChapterExtracted) { intermediateFiles.Add(job.PostprocessingProperties.ChapterFile); } string avsFile = String.Empty; VideoStream myVideo = new VideoStream(); VideoCodecSettings videoSettings = job.PostprocessingProperties.VideoSettings; if (String.IsNullOrEmpty(job.PostprocessingProperties.VideoFileToMux)) { //Open the video Dar?dar; avsFile = createAVSFile(job.IndexFile, job.Input, job.PostprocessingProperties.DAR, job.PostprocessingProperties.HorizontalOutputResolution, job.PostprocessingProperties.SignalAR, _log, job.PostprocessingProperties.AvsSettings, job.PostprocessingProperties.AutoDeinterlace, videoSettings, out dar, job.PostprocessingProperties.AutoCrop, job.PostprocessingProperties.KeepInputResolution, job.PostprocessingProperties.UseChaptersMarks); ulong length; double framerate; JobUtil.getInputProperties(out length, out framerate, avsFile); myVideo.Input = avsFile; myVideo.Output = Path.Combine(job.PostprocessingProperties.WorkingDirectory, Path.GetFileNameWithoutExtension(job.Input) + "_Video"); myVideo.NumberOfFrames = length; myVideo.Framerate = (decimal)framerate; myVideo.DAR = dar; myVideo.VideoType = new MuxableType((new VideoEncoderProvider().GetSupportedOutput(videoSettings.EncoderType))[0], videoSettings.Codec); myVideo.Settings = videoSettings; } else { myVideo.Output = job.PostprocessingProperties.VideoFileToMux; myVideo.Settings = videoSettings; MediaInfoFile oInfo = new MediaInfoFile(myVideo.Output, ref _log); videoSettings.VideoName = oInfo.VideoInfo.Track.Name; myVideo.Framerate = (decimal)oInfo.VideoInfo.FPS; } intermediateFiles.Add(avsFile); intermediateFiles.Add(job.IndexFile); intermediateFiles.AddRange(audioFiles.Values); if (!string.IsNullOrEmpty(qpfile)) { intermediateFiles.Add(qpfile); } foreach (string file in arrAudioFilesDelete) { intermediateFiles.Add(file); } if (File.Exists(Path.Combine(Path.GetDirectoryName(job.Input), Path.GetFileNameWithoutExtension(job.Input) + "._log"))) { intermediateFiles.Add(Path.Combine(Path.GetDirectoryName(job.Input), Path.GetFileNameWithoutExtension(job.Input) + "._log")); } foreach (string file in job.PostprocessingProperties.FilesToDelete) { intermediateFiles.Add(file); } if (!string.IsNullOrEmpty(avsFile) || !String.IsNullOrEmpty(job.PostprocessingProperties.VideoFileToMux)) { MuxStream[] subtitles; if (job.PostprocessingProperties.SubtitleTracks.Count == 0) { //Create empty subtitles for muxing subtitles = new MuxStream[0]; } else { subtitles = new MuxStream[job.PostprocessingProperties.SubtitleTracks.Count]; int i = 0; foreach (OneClickStream oTrack in job.PostprocessingProperties.SubtitleTracks) { if (oTrack.TrackInfo.IsMKVContainer()) { //demuxed MKV string trackFile = Path.GetDirectoryName(job.IndexFile) + "\\" + oTrack.TrackInfo.DemuxFileName; if (File.Exists(trackFile)) { intermediateFiles.Add(trackFile); if (Path.GetExtension(trackFile).ToLower(System.Globalization.CultureInfo.InvariantCulture).Equals(".idx")) { intermediateFiles.Add(FileUtil.GetPathWithoutExtension(trackFile) + ".sub"); } subtitles[i] = new MuxStream(trackFile, oTrack.Language, oTrack.Name, oTrack.Delay, oTrack.DefaultStream, oTrack.ForcedStream, null); } else { _log.LogEvent("File not found: " + trackFile, ImageType.Error); } } else { subtitles[i] = new MuxStream(oTrack.DemuxFilePath, oTrack.Language, oTrack.Name, oTrack.Delay, oTrack.DefaultStream, oTrack.ForcedStream, null); } i++; } } JobChain c = vUtil.GenerateJobSeries(myVideo, job.PostprocessingProperties.FinalOutput, arrAudioJobs.ToArray(), subtitles, job.PostprocessingProperties.ChapterFile, job.PostprocessingProperties.OutputSize, job.PostprocessingProperties.Splitting, job.PostprocessingProperties.Container, job.PostprocessingProperties.PrerenderJob, arrMuxStreams.ToArray(), _log, job.PostprocessingProperties.DeviceOutputType, null, job.PostprocessingProperties.VideoFileToMux, job.PostprocessingProperties.AudioTracks.ToArray()); if (c == null) { _log.Warn("Job creation aborted"); return; } c = CleanupJob.AddAfter(c, intermediateFiles, job.PostprocessingProperties.FinalOutput); mainForm.Jobs.addJobsWithDependencies(c); // batch processing other input files if necessary if (job.PostprocessingProperties.FilesToProcess.Count > 0) { OneClickWindow ocw = new OneClickWindow(mainForm); ocw.setBatchProcessing(job.PostprocessingProperties.FilesToProcess, job.PostprocessingProperties.OneClickSetting); } } } catch (Exception e) { t.Abort(); if (e is ThreadAbortException) { _log.LogEvent("Aborting..."); su.WasAborted = true; su.IsComplete = true; raiseEvent(); } else { _log.LogValue("An error occurred", e, ImageType.Error); su.HasError = true; su.IsComplete = true; raiseEvent(); } return; } t.Abort(); su.IsComplete = true; raiseEvent(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { m_SerialSpawnChunks.Clear(); // Make sure the list of connections and connection state is up to date var connections = connectionGroup.ToEntityArray(Allocator.TempJob); var existing = new NativeHashMap <Entity, int>(connections.Length, Allocator.Temp); for (int i = 0; i < connections.Length; ++i) { existing.TryAdd(connections[i], 1); int stateIndex; if (!m_ConnectionStateLookup.TryGetValue(connections[i], out stateIndex)) { m_ConnectionStates.Add(new ConnectionStateData { Entity = connections[i], SerializationState = new NativeHashMap <ArchetypeChunk, SerializationState>(1024, Allocator.Persistent) }); m_ConnectionStateLookup.TryAdd(connections[i], m_ConnectionStates.Count - 1); } } connections.Dispose(); for (int i = 0; i < m_ConnectionStates.Count; ++i) { int val; if (!existing.TryGetValue(m_ConnectionStates[i].Entity, out val)) { m_ConnectionStateLookup.Remove(m_ConnectionStates[i].Entity); m_ConnectionStates[i].Dispose(); if (i != m_ConnectionStates.Count - 1) { m_ConnectionStates[i] = m_ConnectionStates[m_ConnectionStates.Count - 1]; m_ConnectionStateLookup.Remove(m_ConnectionStates[i].Entity); m_ConnectionStateLookup.TryAdd(m_ConnectionStates[i].Entity, i); } m_ConnectionStates.RemoveAt(m_ConnectionStates.Count - 1); } } // Find the latest tick which has been acknowledged by all clients and cleanup all ghosts destroyed ebfore that uint currentTick = m_ServerSimulation.ServerTick; var ackedByAll = new NativeArray <uint>(1, Allocator.TempJob); ackedByAll[0] = currentTick; var findAckJob = new FindAckedByAllJob { tick = ackedByAll }; inputDeps = findAckJob.ScheduleSingle(this, inputDeps); EntityCommandBuffer commandBuffer = m_Barrier.CreateCommandBuffer(); var ghostCleanupJob = new CleanupGhostJob { currentTick = currentTick, tick = ackedByAll, commandBuffer = commandBuffer.ToConcurrent(), freeGhostIds = m_FreeGhostIds.AsParallelWriter(), ghostStateType = ComponentType.ReadWrite <GhostSystemStateComponent>() }; inputDeps = ghostCleanupJob.Schedule(this, inputDeps); var entityType = GetArchetypeChunkEntityType(); var ghostSystemStateType = GetArchetypeChunkComponentType <GhostSystemStateComponent>(); serializers.BeginSerialize(this); // Extract all newly spawned ghosts and set their ghost ids JobHandle spawnChunkHandle; var spawnChunks = ghostSpawnGroup.CreateArchetypeChunkArray(Allocator.TempJob, out spawnChunkHandle); var spawnJob = new SpawnGhostJob { spawnChunks = spawnChunks, serialSpawnChunks = m_SerialSpawnChunks, entityType = entityType, serializers = serializers, freeGhostIds = m_FreeGhostIds, allocatedGhostIds = m_AllocatedGhostIds, commandBuffer = commandBuffer }; inputDeps = spawnJob.Schedule(JobHandle.CombineDependencies(inputDeps, spawnChunkHandle)); // This was the last job using the commandBuffer m_Barrier.AddJobHandleForProducer(inputDeps); JobHandle despawnChunksHandle, ghostChunksHandle; var despawnChunks = ghostDespawnGroup.CreateArchetypeChunkArray(Allocator.TempJob, out despawnChunksHandle); var ghostChunks = ghostGroup.CreateArchetypeChunkArray(Allocator.TempJob, out ghostChunksHandle); inputDeps = JobHandle.CombineDependencies(inputDeps, despawnChunksHandle, ghostChunksHandle); var serialDep = new NativeArray <JobHandle>(m_ConnectionStates.Count + 1, Allocator.Temp); // In case there are 0 connections serialDep[0] = inputDeps; for (int con = 0; con < m_ConnectionStates.Count; ++con) { var connectionEntity = m_ConnectionStates[con].Entity; var chunkSerializationData = m_ConnectionStates[con].SerializationState; var serializeJob = new SerializeJob { driver = m_ReceiveSystem.ConcurrentDriver, unreliablePipeline = m_ReceiveSystem.UnreliablePipeline, despawnChunks = despawnChunks, ghostChunks = ghostChunks, connectionEntity = connectionEntity, chunkSerializationData = chunkSerializationData, ackFromEntity = GetComponentDataFromEntity <NetworkSnapshotAckComponent>(true), connectionFromEntity = GetComponentDataFromEntity <NetworkStreamConnection>(true), serialSpawnChunks = m_SerialSpawnChunks, entityType = entityType, ghostSystemStateType = ghostSystemStateType, serializers = serializers, compressionModel = m_CompressionModel, currentTick = currentTick, localTime = NetworkTimeSystem.TimestampMS }; // FIXME: disable safety for BufferFromEntity is not working serialDep[con + 1] = serializeJob.Schedule(serialDep[con]); } inputDeps = JobHandle.CombineDependencies(serialDep); var cleanupJob = new CleanupJob { despawnChunks = despawnChunks, spawnChunks = spawnChunks, ghostChunks = ghostChunks, serialSpawnChunks = m_SerialSpawnChunks }; inputDeps = cleanupJob.Schedule(inputDeps); return(inputDeps); }
protected override void RunInThread() { JobChain c = null; List <string> intermediateFiles = new List <string>(); bool bError = false; try { log.LogEvent("Processing thread started"); su.Status = "Preprocessing... ***PLEASE WAIT***"; su.ResetTime(); List <string> arrAudioFilesDelete = new List <string>(); audioFiles = new Dictionary <int, string>(); List <AudioTrackInfo> arrAudioTracks = new List <AudioTrackInfo>(); List <AudioJob> arrAudioJobs = new List <AudioJob>(); List <MuxStream> arrMuxStreams = new List <MuxStream>(); FileUtil.ensureDirectoryExists(job.PostprocessingProperties.WorkingDirectory); // audio handling foreach (OneClickAudioTrack oAudioTrack in job.PostprocessingProperties.AudioTracks) { if (IsJobStopped()) { return; } if (oAudioTrack.AudioTrackInfo != null) { if (oAudioTrack.AudioTrackInfo.ExtractMKVTrack) { if (job.PostprocessingProperties.ApplyDelayCorrection && File.Exists(job.PostprocessingProperties.IntermediateMKVFile)) { MediaInfoFile oFile = new MediaInfoFile(job.PostprocessingProperties.IntermediateMKVFile, ref log); bool bFound = false; foreach (AudioTrackInfo oAudioInfo in oFile.AudioInfo.Tracks) { if (oAudioInfo.MMGTrackID == oAudioTrack.AudioTrackInfo.MMGTrackID) { bFound = true; } } int mmgTrackID = 0; if (!bFound) { mmgTrackID = oFile.AudioInfo.Tracks[oAudioTrack.AudioTrackInfo.TrackIndex].MMGTrackID; } else { mmgTrackID = oAudioTrack.AudioTrackInfo.MMGTrackID; } foreach (AudioTrackInfo oAudioInfo in oFile.AudioInfo.Tracks) { if (oAudioInfo.MMGTrackID == mmgTrackID) { if (oAudioTrack.DirectMuxAudio != null) { oAudioTrack.DirectMuxAudio.delay = oAudioInfo.Delay; } if (oAudioTrack.AudioJob != null) { oAudioTrack.AudioJob.Delay = oAudioInfo.Delay; } break; } } } if (!audioFiles.ContainsKey(oAudioTrack.AudioTrackInfo.TrackID)) { audioFiles.Add(oAudioTrack.AudioTrackInfo.TrackID, job.PostprocessingProperties.WorkingDirectory + "\\" + oAudioTrack.AudioTrackInfo.DemuxFileName); arrAudioFilesDelete.Add(job.PostprocessingProperties.WorkingDirectory + "\\" + oAudioTrack.AudioTrackInfo.DemuxFileName); } } else { arrAudioTracks.Add(oAudioTrack.AudioTrackInfo); } } if (oAudioTrack.AudioJob != null) { if (job.PostprocessingProperties.IndexType == FileIndexerWindow.IndexType.NONE && String.IsNullOrEmpty(oAudioTrack.AudioJob.Input)) { oAudioTrack.AudioJob.Input = job.Input; } arrAudioJobs.Add(oAudioTrack.AudioJob); } if (oAudioTrack.DirectMuxAudio != null) { arrMuxStreams.Add(oAudioTrack.DirectMuxAudio); } } if (audioFiles.Count == 0 && !job.PostprocessingProperties.Eac3toDemux && job.PostprocessingProperties.IndexType != FileIndexerWindow.IndexType.NONE && job.PostprocessingProperties.IndexType != FileIndexerWindow.IndexType.AVISOURCE) { if ((job.PostprocessingProperties.IndexType == FileIndexerWindow.IndexType.DGI || job.PostprocessingProperties.IndexType == FileIndexerWindow.IndexType.DGM) && File.Exists(Path.ChangeExtension(job.IndexFile, ".log"))) { job.PostprocessingProperties.FilesToDelete.Add(Path.ChangeExtension(job.IndexFile, ".log")); audioFiles = AudioUtil.GetAllDemuxedAudioFromDGI(arrAudioTracks, out arrAudioFilesDelete, job.IndexFile, log); } else { audioFiles = VideoUtil.getAllDemuxedAudio(arrAudioTracks, new List <AudioTrackInfo>(), out arrAudioFilesDelete, job.IndexFile, log); } } FillInAudioInformation(ref arrAudioJobs, arrMuxStreams); if (!String.IsNullOrEmpty(job.PostprocessingProperties.VideoFileToMux)) { log.LogEvent("Don't encode video: True"); } else { log.LogEvent("Desired size: " + job.PostprocessingProperties.OutputSize); } log.LogEvent("Split size: " + job.PostprocessingProperties.Splitting); if (IsJobStopped()) { return; } // video file handling string avsFile = String.Empty; VideoStream myVideo = new VideoStream(); VideoCodecSettings videoSettings = job.PostprocessingProperties.VideoSettings; if (String.IsNullOrEmpty(job.PostprocessingProperties.VideoFileToMux)) { //Open the video try { avsFile = CreateAVSFile(job.IndexFile, job.Input, job.PostprocessingProperties.DAR, job.PostprocessingProperties.HorizontalOutputResolution, log, job.PostprocessingProperties.AvsSettings, job.PostprocessingProperties.AutoDeinterlace, videoSettings, job.PostprocessingProperties.AutoCrop, job.PostprocessingProperties.KeepInputResolution, job.PostprocessingProperties.UseChaptersMarks); } catch (Exception ex) { log.LogValue("An error occurred creating the AVS file", ex, ImageType.Error); } if (IsJobStopped()) { return; } if (!String.IsNullOrEmpty(avsFile)) { // check AVS file JobUtil.GetInputProperties(avsFile, out ulong frameCount, out double frameRate); myVideo.Input = avsFile; myVideo.Output = Path.Combine(job.PostprocessingProperties.WorkingDirectory, Path.GetFileNameWithoutExtension(job.Input) + "_Video"); myVideo.NumberOfFrames = frameCount; myVideo.Framerate = (decimal)frameRate; myVideo.VideoType = new MuxableType((new VideoEncoderProvider().GetSupportedOutput(videoSettings.EncoderType))[0], videoSettings.Codec); myVideo.Settings = videoSettings; } else { bError = true; } } else { myVideo.DAR = job.PostprocessingProperties.ForcedDAR; myVideo.Output = job.PostprocessingProperties.VideoFileToMux; MediaInfoFile oInfo = new MediaInfoFile(myVideo.Output, ref log); if (Path.GetExtension(job.PostprocessingProperties.VideoFileToMux).Equals(".unknown") && !String.IsNullOrEmpty(oInfo.ContainerFileTypeString)) { job.PostprocessingProperties.VideoFileToMux = Path.ChangeExtension(job.PostprocessingProperties.VideoFileToMux, oInfo.ContainerFileTypeString.ToLowerInvariant()); File.Move(myVideo.Output, job.PostprocessingProperties.VideoFileToMux); myVideo.Output = job.PostprocessingProperties.VideoFileToMux; job.PostprocessingProperties.FilesToDelete.Add(myVideo.Output); } myVideo.Settings = videoSettings; myVideo.Framerate = (decimal)oInfo.VideoInfo.FPS; myVideo.NumberOfFrames = oInfo.VideoInfo.FrameCount; } if (IsJobStopped()) { return; } intermediateFiles.Add(avsFile); intermediateFiles.Add(job.IndexFile); intermediateFiles.AddRange(audioFiles.Values); foreach (string file in arrAudioFilesDelete) { intermediateFiles.Add(file); } intermediateFiles.Add(Path.ChangeExtension(job.Input, ".log")); foreach (string file in job.PostprocessingProperties.FilesToDelete) { intermediateFiles.Add(file); } // subtitle handling List <MuxStream> subtitles = new List <MuxStream>(); if (job.PostprocessingProperties.SubtitleTracks.Count > 0) { foreach (OneClickStream oTrack in job.PostprocessingProperties.SubtitleTracks) { if (oTrack.TrackInfo.ExtractMKVTrack) { //demuxed MKV string trackFile = Path.GetDirectoryName(job.IndexFile) + "\\" + oTrack.TrackInfo.DemuxFileName; if (File.Exists(trackFile)) { intermediateFiles.Add(trackFile); if (Path.GetExtension(trackFile).ToLowerInvariant().Equals(".idx")) { intermediateFiles.Add(FileUtil.GetPathWithoutExtension(trackFile) + ".sub"); } subtitles.Add(new MuxStream(trackFile, oTrack.Language, oTrack.Name, oTrack.Delay, oTrack.DefaultStream, oTrack.ForcedStream, null)); } else { log.LogEvent("Ignoring subtitle as the it cannot be found: " + trackFile, ImageType.Warning); } } else { // sometimes the language is detected differently by vsrip and the IFO parser. Therefore search also for other files string strDemuxFile = oTrack.DemuxFilePath; if (!File.Exists(strDemuxFile) && Path.GetFileNameWithoutExtension(strDemuxFile).Contains("_")) { string strDemuxFileName = Path.GetFileNameWithoutExtension(strDemuxFile); strDemuxFileName = strDemuxFileName.Substring(0, strDemuxFileName.LastIndexOf("_")) + "_*" + Path.GetExtension(strDemuxFile); foreach (string strFileName in Directory.GetFiles(Path.GetDirectoryName(strDemuxFile), strDemuxFileName)) { strDemuxFile = Path.Combine(Path.GetDirectoryName(strDemuxFile), strFileName); intermediateFiles.Add(strDemuxFile); intermediateFiles.Add(Path.ChangeExtension(strDemuxFile, ".sub")); log.LogEvent("Subtitle + " + oTrack.DemuxFilePath + " cannot be found. " + strFileName + " will be used instead", ImageType.Information); break; } } if (File.Exists(strDemuxFile)) { string strTrackName = oTrack.Name; // check if a forced stream is available string strForcedFile = Path.Combine(Path.GetDirectoryName(strDemuxFile), Path.GetFileNameWithoutExtension(strDemuxFile) + "_forced.idx"); if (File.Exists(strForcedFile)) { subtitles.Add(new MuxStream(strForcedFile, oTrack.Language, SubtitleUtil.ApplyForcedStringToTrackName(true, oTrack.Name), oTrack.Delay, oTrack.DefaultStream, true, null)); intermediateFiles.Add(strForcedFile); intermediateFiles.Add(Path.ChangeExtension(strForcedFile, ".sub")); } subtitles.Add(new MuxStream(strDemuxFile, oTrack.Language, SubtitleUtil.ApplyForcedStringToTrackName(false, oTrack.Name), oTrack.Delay, oTrack.DefaultStream, (File.Exists(strForcedFile) ? false : oTrack.ForcedStream), null)); } else { log.LogEvent("Ignoring subtitle as the it cannot be found: " + oTrack.DemuxFilePath, ImageType.Warning); } } } } if (IsJobStopped()) { return; } if (!bError) { c = VideoUtil.GenerateJobSeries(myVideo, job.PostprocessingProperties.FinalOutput, arrAudioJobs.ToArray(), subtitles.ToArray(), job.PostprocessingProperties.Attachments, job.PostprocessingProperties.TimeStampFile, job.PostprocessingProperties.ChapterInfo, job.PostprocessingProperties.OutputSize, job.PostprocessingProperties.Splitting, job.PostprocessingProperties.Container, job.PostprocessingProperties.PrerenderJob, arrMuxStreams.ToArray(), log, job.PostprocessingProperties.DeviceOutputType, null, job.PostprocessingProperties.VideoFileToMux, job.PostprocessingProperties.AudioTracks.ToArray(), true); } if (c != null && !String.IsNullOrEmpty(job.PostprocessingProperties.TimeStampFile) && c.Jobs[c.Jobs.Length - 1].Job is MuxJob && (c.Jobs[c.Jobs.Length - 1].Job as MuxJob).MuxType == MuxerType.MP4BOX) { // last job is a mp4box job and vfr timecode data has to be applied MP4FpsModJob mp4FpsMod = new MP4FpsModJob(((MuxJob)c.Jobs[c.Jobs.Length - 1].Job).Output, job.PostprocessingProperties.TimeStampFile); c = new SequentialChain(c, new SequentialChain(mp4FpsMod)); } } catch (Exception e) { log.LogValue("An error occurred", e, ImageType.Error); bError = true; } if (c == null || bError) { log.Error("Job creation aborted"); su.HasError = true; } // add cleanup job also in case of an error c = CleanupJob.AddAfter(c, intermediateFiles, job.PostprocessingProperties.FinalOutput); MainForm.Instance.Jobs.AddJobsWithDependencies(c, false); // batch processing other input files if necessary if (job.PostprocessingProperties.FilesToProcess.Count > 0) { OneClickWindow ocw = new OneClickWindow(); ocw.setBatchProcessing(job.PostprocessingProperties.FilesToProcess, job.PostprocessingProperties.OneClickSetting); } su.IsComplete = true; }
/// <summary> /// Adds <seealso cref="CleanupJob"/> to this collector. /// </summary> /// <param name="job"> cleanup job to perform, now or at some point in the future. </param> internal abstract void Add(CleanupJob job);
public override void Add(CleanupJob job) { job.Close(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (units.entities.Length == 0) { return(inputDeps); } Profiler.BeginSample("Explosion wait"); spellSystem.CombinedExplosionHandle.Complete(); // TODO try to remove this Profiler.EndSample(); inputDeps.Complete(); Profiler.BeginSample("Spawn "); if (!deathQueue.IsCreated) { deathQueue = new NativeQueue <Entity>(Allocator.Persistent); } if (!createdArrows.IsCreated) { createdArrows = new NativeQueue <ArrowData>(Allocator.Persistent); } while (createdArrows.Count > 0) { var data = createdArrows.Dequeue(); Spawner.Instance.SpawnArrow(data); } UpdateInjectedComponentGroups(); var cleanupJob = new CleanupJob { deathQueue = deathQueue, minionData = units.data, entitites = units.entities }; var moveUnitsJob = new MoveUnitsBelowGround() { dyingUnitData = dyingUnits.dyingData, transforms = dyingUnits.transforms, time = Time.time }; var cleanupJobFence = cleanupJob.Schedule(units.Length, SimulationState.BigBatchSize, inputDeps); var moveUnitsBelowGroundFence = moveUnitsJob.Schedule(dyingUnits.Length, SimulationState.HugeBatchSize, spellSystem.CombinedExplosionHandle); Profiler.EndSample(); cleanupJobFence.Complete(); moveUnitsBelowGroundFence.Complete(); Profiler.BeginSample("LifeCycleManager - Main Thread"); float time = Time.time; if (dyingUnits.Length > 0) { for (int i = 0; i < dyingUnits.Length; i++) { if (time > dyingUnits.dyingData[i].TimeAtWhichToExpire) { var entityToKill = dyingUnits.entities[i]; queueForKillingEntities.Enqueue(entityToKill); } //else if (time > dyingData[i].TimeAtWhichToExpire - 2f) //{ // float t = (dyingData[i].TimeAtWhichToExpire - time) / 2f; // var transform = transforms[i]; // transform.Position.y = math.lerp(dyingData[i].StartingYCoord, dyingData[i].StartingYCoord - 1f, t); // transforms[i] = transform; //} } } if (dyingArrows.Length > 0) { for (int i = 0; i < dyingArrows.Length; i++) { if (time > dyingArrows.dyingData[i].TimeAtWhichToExpire) { var arrowToKill = dyingArrows.entities[i]; queueForKillingEntities.Enqueue(arrowToKill); } } } Profiler.EndSample(); Profiler.BeginSample("Queue processing"); float timeForUnitExpiring = Time.time + 5f; float timeForArrowExpiring = Time.time + 1f; Profiler.BeginSample("Death queue"); int processed = 0; while (deathQueue.Count > 0) { var entityToKill = deathQueue.Dequeue(); if (EntityManager.HasComponent <MinionData>(entityToKill)) { EntityManager.RemoveComponent <MinionData>(entityToKill); entitiesThatNeedToBeKilled.Enqueue(entityToKill); } if (EntityManager.HasComponent <ArrowData>(entityToKill)) { EntityManager.AddComponentData(entityToKill, new DyingUnitData(timeForArrowExpiring, 0)); } } Profiler.EndSample(); Profiler.BeginSample("Explosion wait"); spellSystem.CombinedExplosionHandle.Complete(); Profiler.EndSample(); Profiler.BeginSample("Killing minionEntities"); // TODO try batched replacing while (entitiesThatNeedToBeKilled.Count > 0 && processed < MaxDyingUnitsPerFrame) { processed++; var entityToKill = entitiesThatNeedToBeKilled.Dequeue(); if (EntityManager.HasComponent <MinionTarget>(entityToKill)) { EntityManager.RemoveComponent <MinionTarget>(entityToKill); if (EntityManager.HasComponent <AliveMinionData>(entityToKill)) { EntityManager.RemoveComponent <AliveMinionData>(entityToKill); } var textureAnimatorData = EntityManager.GetComponentData <TextureAnimatorData>(entityToKill); textureAnimatorData.NewAnimationId = AnimationName.Death; var transform = EntityManager.GetComponentData <UnitTransformData>(entityToKill); EntityManager.AddComponentData(entityToKill, new DyingUnitData(timeForUnitExpiring, transform.Position.y)); EntityManager.SetComponentData(entityToKill, textureAnimatorData); var formations = GetComponentDataFromEntity <FormationData>(); var formation = formations[transform.FormationEntity]; formation.UnitCount--; formation.Width = (int)math.ceil((math.sqrt(formation.UnitCount / 2f) * 2f)); if (formation.UnitCount == 0) { formation.FormationState = FormationData.State.AllDead; } formations[transform.FormationEntity] = formation; } } Profiler.EndSample(); processed = 0; Profiler.BeginSample("Flying queue"); while (entitiesForFlying.Count > 0 && processed < MaxDyingUnitsPerFrame) { processed++; var entity = entitiesForFlying.Dequeue(); if (EntityManager.Exists(entity) && !EntityManager.HasComponent <FlyingData>(entity)) { if (EntityManager.HasComponent(entity, typeof(AliveMinionData))) { EntityManager.RemoveComponent <AliveMinionData>(entity); } EntityManager.AddComponentData(entity, new FlyingData()); } } Profiler.EndSample(); Profiler.BeginSample("Destroying entities"); while (queueForKillingEntities.Count > 0) { EntityManager.DestroyEntity(queueForKillingEntities.Dequeue()); } Profiler.EndSample(); Profiler.EndSample(); return(new JobHandle()); }