Finishing c# marshmalling.

This commit is contained in:
Zoe Roux 2019-09-16 01:13:50 +02:00
parent 1ced45a763
commit 5459e3cde6
5 changed files with 16 additions and 17 deletions

View File

@ -9,13 +9,13 @@
extern "C" struct Stream extern "C" struct Stream
{ {
std::string title; const char* title;
std::string language; const char* language;
std::string format; const char* format;
bool isDefault; bool isDefault;
bool isForced; 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) { } : title(title), language(languageCode), format(format), isDefault(isDefault), isForced(isForced), path(path) { }
}; };

View File

@ -21,7 +21,7 @@ int Init()
return 42; 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; AVFormatContext* inputContext = NULL;
@ -39,7 +39,7 @@ int ExtractSubtitles(const char* path, const char* outPath, Stream* streams)
av_dump_format(inputContext, 0, path, false); av_dump_format(inputContext, 0, path, false);
std::vector<Stream> subtitleStreams; std::vector<Stream>* subtitleStreams = new std::vector<Stream>();
const unsigned int outputCount = inputContext->nb_streams; const unsigned int outputCount = inputContext->nb_streams;
AVFormatContext** outputList = new AVFormatContext*[outputCount]; AVFormatContext** outputList = new AVFormatContext*[outputCount];
@ -61,7 +61,7 @@ int ExtractSubtitles(const char* path, const char* outPath, Stream* streams)
false, //isForced false, //isForced
"path"); //path "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; 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; delete[] outputList;
//std::copy() *streamCount = subtitleStreams->size();
//streams = subtitleStreams.data(); //SHOULDN'T COPY LIKE THAT, WE OVERRIDE THE POINTER HERE. return subtitleStreams->data();
return subtitleStreams.size();
} }

View File

@ -12,4 +12,4 @@
extern "C" API int Init(); 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. //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);

View File

@ -12,13 +12,13 @@ namespace Kyoo.InternalAPI.TranscoderLink
public extern static int Init(); public extern static int Init();
[DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)] [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) public static void ExtractSubtitles(string path, string outPath, out Stream[] streams)
{ {
int size = Marshal.SizeOf<Stream>(); int size = Marshal.SizeOf<Stream>();
int length = ExtractSubtitles(path, outPath, out IntPtr streamsPtr); //The streamsPtr is always nullptr IntPtr streamsPtr = ExtractSubtitles(path, outPath, out int length);
if (length > 0) if (length > 0)
{ {
streams = new Stream[length]; streams = new Stream[length];

View File

@ -8,14 +8,14 @@ namespace Kyoo.Models.Watch
Audio, Subtitle, Unknow Audio, Subtitle, Unknow
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class Stream public class Stream
{ {
public string Title; public string Title;
public string Language; public string Language;
public string Format; public string Format;
public bool IsDefault; [MarshalAs(UnmanagedType.I1)] public bool IsDefault;
public bool IsForced; [MarshalAs(UnmanagedType.I1)] public bool IsForced;
[JsonIgnore] public string Path; [JsonIgnore] public string Path;
//[JsonIgnore] public StreamType type; //[JsonIgnore] public StreamType type;