mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-03 13:44:33 -04:00
Finishing c# marshmalling.
This commit is contained in:
parent
1ced45a763
commit
5459e3cde6
@ -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) { }
|
||||
};
|
@ -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<Stream> subtitleStreams;
|
||||
std::vector<Stream>* subtitleStreams = new std::vector<Stream>();
|
||||
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();
|
||||
}
|
@ -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);
|
||||
|
@ -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<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)
|
||||
{
|
||||
streams = new Stream[length];
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user