diff --git a/Kyoo.Transcoder/src/Stream.h b/Kyoo.Transcoder/src/Stream.h index f873a835..7a53aa89 100644 --- a/Kyoo.Transcoder/src/Stream.h +++ b/Kyoo.Transcoder/src/Stream.h @@ -9,13 +9,13 @@ extern "C" struct Stream { - std::string title; - std::string language; - std::string format; + const char* title; + const char* language; + const char* format; bool isDefault; bool isForced; - std::string path; + const char* path; - Stream(std::string title, std::string languageCode, std::string format, bool isDefault, bool isForced, std::string path) + Stream(const char* title, const char* languageCode, const char* format, bool isDefault, bool isForced, const char* path) : title(title), language(languageCode), format(format), isDefault(isDefault), isForced(isForced), path(path) { } }; \ No newline at end of file diff --git a/Kyoo.Transcoder/src/Transcoder.cpp b/Kyoo.Transcoder/src/Transcoder.cpp index 24ac4a50..ff426763 100644 --- a/Kyoo.Transcoder/src/Transcoder.cpp +++ b/Kyoo.Transcoder/src/Transcoder.cpp @@ -21,7 +21,7 @@ int Init() return 42; } -int ExtractSubtitles(const char* path, const char* outPath, Stream* streams) +Stream* ExtractSubtitles(const char* path, const char* outPath, int* streamCount) { AVFormatContext* inputContext = NULL; @@ -39,7 +39,7 @@ int ExtractSubtitles(const char* path, const char* outPath, Stream* streams) av_dump_format(inputContext, 0, path, false); - std::vector subtitleStreams; + std::vector* subtitleStreams = new std::vector(); const unsigned int outputCount = inputContext->nb_streams; AVFormatContext** outputList = new AVFormatContext*[outputCount]; @@ -61,7 +61,7 @@ int ExtractSubtitles(const char* path, const char* outPath, Stream* streams) false, //isForced "path"); //path - subtitleStreams.push_back(stream); + subtitleStreams->push_back(stream); std::cout << "Stream #" << i << "(" << stream.language << "), stream type: " << inputCodecpar->codec_type << " codec: " << inputCodecpar->codec_tag << std::endl; @@ -213,7 +213,6 @@ int ExtractSubtitles(const char* path, const char* outPath, Stream* streams) delete[] outputList; - //std::copy() - //streams = subtitleStreams.data(); //SHOULDN'T COPY LIKE THAT, WE OVERRIDE THE POINTER HERE. - return subtitleStreams.size(); + *streamCount = subtitleStreams->size(); + return subtitleStreams->data(); } \ No newline at end of file diff --git a/Kyoo.Transcoder/src/Transcoder.h b/Kyoo.Transcoder/src/Transcoder.h index 77f5f536..2f3c9982 100644 --- a/Kyoo.Transcoder/src/Transcoder.h +++ b/Kyoo.Transcoder/src/Transcoder.h @@ -12,4 +12,4 @@ extern "C" API int Init(); //Take the path of the file and the path of the output directory. It will return the list of subtitle streams in the streams variable. The int returned is the number of subtitles extracted. -extern "C" API int ExtractSubtitles(const char* path, const char* outPath, Stream* streams); +extern "C" API Stream* ExtractSubtitles(const char* path, const char* outPath, int* streamsCount); diff --git a/Kyoo/InternalAPI/Transcoder/TranscoderAPI.cs b/Kyoo/InternalAPI/Transcoder/TranscoderAPI.cs index 4d9b6aa4..ada36745 100644 --- a/Kyoo/InternalAPI/Transcoder/TranscoderAPI.cs +++ b/Kyoo/InternalAPI/Transcoder/TranscoderAPI.cs @@ -12,13 +12,13 @@ namespace Kyoo.InternalAPI.TranscoderLink public extern static int Init(); [DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)] - private extern static int ExtractSubtitles(string path, string outPath, out IntPtr streams); + private extern static IntPtr ExtractSubtitles(string path, string outPath, out int streams); public static void ExtractSubtitles(string path, string outPath, out Stream[] streams) { int size = Marshal.SizeOf(); - int length = ExtractSubtitles(path, outPath, out IntPtr streamsPtr); //The streamsPtr is always nullptr + IntPtr streamsPtr = ExtractSubtitles(path, outPath, out int length); if (length > 0) { streams = new Stream[length]; diff --git a/Kyoo/Models/Stream.cs b/Kyoo/Models/Stream.cs index 28deb770..a1cf78e7 100644 --- a/Kyoo/Models/Stream.cs +++ b/Kyoo/Models/Stream.cs @@ -8,14 +8,14 @@ namespace Kyoo.Models.Watch Audio, Subtitle, Unknow } - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public class Stream { public string Title; public string Language; public string Format; - public bool IsDefault; - public bool IsForced; + [MarshalAs(UnmanagedType.I1)] public bool IsDefault; + [MarshalAs(UnmanagedType.I1)] public bool IsForced; [JsonIgnore] public string Path; //[JsonIgnore] public StreamType type;