mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
The transcoder now uses long running tasks
This commit is contained in:
parent
c5a8a1111e
commit
6950b6750a
@ -1,12 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Controllers.TranscoderLink;
|
using Kyoo.Controllers.TranscoderLink;
|
||||||
|
|
||||||
#pragma warning disable 4014
|
#pragma warning disable 4014
|
||||||
|
|
||||||
namespace Kyoo.Controllers
|
namespace Kyoo.Controllers
|
||||||
@ -27,24 +25,28 @@ namespace Kyoo.Controllers
|
|||||||
throw new BadTranscoderException();
|
throw new BadTranscoderException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Track[]> GetTrackInfo(string path)
|
public Task<Track[]> GetTrackInfo(string path)
|
||||||
{
|
{
|
||||||
return await Task.Run(() =>
|
return Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
TranscoderAPI.GetTrackInfo(path, out Track[] tracks);
|
TranscoderAPI.GetTrackInfo(path, out Track[] tracks);
|
||||||
return tracks;
|
return tracks;
|
||||||
});
|
}, TaskCreationOptions.LongRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Track[]> ExtractSubtitles(string path)
|
public Task<Track[]> ExtractSubtitles(string path)
|
||||||
{
|
{
|
||||||
string output = Path.Combine(Path.GetDirectoryName(path), "Subtitles");
|
string dir = Path.GetDirectoryName(path);
|
||||||
|
if (dir == null)
|
||||||
|
throw new ArgumentException("Invalid path.");
|
||||||
|
|
||||||
|
string output = Path.Combine(dir, "Subtitles");
|
||||||
Directory.CreateDirectory(output);
|
Directory.CreateDirectory(output);
|
||||||
return await Task.Run(() =>
|
return Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
TranscoderAPI.ExtractSubtitles(path, output, out Track[] tracks);
|
TranscoderAPI.ExtractSubtitles(path, output, out Track[] tracks);
|
||||||
return tracks;
|
return tracks;
|
||||||
});
|
}, TaskCreationOptions.LongRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> Transmux(Episode episode)
|
public async Task<string> Transmux(Episode episode)
|
||||||
@ -65,11 +67,12 @@ namespace Kyoo.Controllers
|
|||||||
await Console.Error.WriteLineAsync($"Access to the path {manifest} is denied. Please change your transmux path in the config.");
|
await Console.Error.WriteLineAsync($"Access to the path {manifest} is denied. Please change your transmux path in the config.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Task.Run(() =>
|
|
||||||
|
Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
transmuxFailed = TranscoderAPI.transmux(episode.Path, manifest.Replace('\\', '/'), out playableDuration) != 0;
|
transmuxFailed = TranscoderAPI.transmux(episode.Path, manifest.Replace('\\', '/'), out playableDuration) != 0;
|
||||||
});
|
}, TaskCreationOptions.LongRunning);
|
||||||
while (playableDuration < 10 || (!File.Exists(manifest) && !transmuxFailed))
|
while (playableDuration < 10 || !File.Exists(manifest) && !transmuxFailed)
|
||||||
await Task.Delay(10);
|
await Task.Delay(10);
|
||||||
return transmuxFailed ? null : manifest;
|
return transmuxFailed ? null : manifest;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Kyoo.Models.Watch;
|
using Kyoo.Models.Watch;
|
||||||
@ -27,8 +25,8 @@ namespace Kyoo.Controllers.TranscoderLink
|
|||||||
[DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern IntPtr extract_subtitles(string path, string out_path, out int array_length, out int track_count);
|
private static extern IntPtr extract_subtitles(string path, string out_path, out int array_length, out int track_count);
|
||||||
|
|
||||||
[DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)]
|
// [DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void free_streams(IntPtr stream_ptr);
|
// private static extern void free_streams(IntPtr stream_ptr);
|
||||||
|
|
||||||
[DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)]
|
||||||
private static extern void free(IntPtr ptr);
|
private static extern void free(IntPtr ptr);
|
||||||
@ -48,7 +46,7 @@ namespace Kyoo.Controllers.TranscoderLink
|
|||||||
for (int i = 0; i < arrayLength; i++)
|
for (int i = 0; i < arrayLength; i++)
|
||||||
{
|
{
|
||||||
Stream stream = Marshal.PtrToStructure<Stream>(streamsPtr);
|
Stream stream = Marshal.PtrToStructure<Stream>(streamsPtr);
|
||||||
if (stream.Type != StreamType.Unknow)
|
if (stream!.Type != StreamType.Unknow)
|
||||||
{
|
{
|
||||||
tracks[j] = new Track(stream);
|
tracks[j] = new Track(stream);
|
||||||
j++;
|
j++;
|
||||||
@ -76,7 +74,7 @@ namespace Kyoo.Controllers.TranscoderLink
|
|||||||
for (int i = 0; i < arrayLength; i++)
|
for (int i = 0; i < arrayLength; i++)
|
||||||
{
|
{
|
||||||
Stream stream = Marshal.PtrToStructure<Stream>(streamsPtr);
|
Stream stream = Marshal.PtrToStructure<Stream>(streamsPtr);
|
||||||
if (stream.Type != StreamType.Unknow)
|
if (stream!.Type != StreamType.Unknow)
|
||||||
{
|
{
|
||||||
tracks[j] = new Track(stream);
|
tracks[j] = new Track(stream);
|
||||||
j++;
|
j++;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore;
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 7c117aaed04d693b12baf6b0061f77de084d56be
|
Subproject commit 3216846879e75fdc1b9ec4efc1da7599ee6e9e2c
|
Loading…
x
Reference in New Issue
Block a user