mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-23 15:30:34 -04:00
Making a few test with the C# memory management.
This commit is contained in:
parent
51694fbc53
commit
229be6e4b9
@ -205,11 +205,12 @@ Stream *ExtractSubtitles(const char *path, const char *outPath, int *streamCount
|
||||
AVFormatContext *inputContext = NULL;
|
||||
|
||||
if (open_input_context(&inputContext, path) != 0)
|
||||
return 0;
|
||||
return nullptr;
|
||||
|
||||
*streamCount = inputContext->nb_streams;
|
||||
*subtitleCount = 0;
|
||||
Stream *subtitleStreams = new Stream[*streamCount];
|
||||
|
||||
const unsigned int outputCount = inputContext->nb_streams;
|
||||
AVFormatContext **outputList = new AVFormatContext*[outputCount];
|
||||
|
||||
@ -259,7 +260,7 @@ Stream *ExtractSubtitles(const char *path, const char *outPath, int *streamCount
|
||||
|
||||
subtitleStreams[i] = stream;
|
||||
*subtitleCount += 1;
|
||||
//subtitleStreams->push_back(stream);
|
||||
|
||||
std::cout << "Stream #" << i << "(" << stream.language << "), stream type: " << inputCodecpar->codec_type << " codec: " << stream.codec << std::endl;
|
||||
|
||||
AVFormatContext *outputContext = NULL;
|
||||
@ -340,13 +341,24 @@ Stream *ExtractSubtitles(const char *path, const char *outPath, int *streamCount
|
||||
}
|
||||
|
||||
delete[] outputList;
|
||||
|
||||
return subtitleStreams;
|
||||
//*streamCount = subtitleStreams->size();
|
||||
//return subtitleStreams->data();
|
||||
}
|
||||
|
||||
void FreeMemory(Stream *streamsPtr)
|
||||
{
|
||||
delete[] streamsPtr;
|
||||
}
|
||||
|
||||
Stream *TestMemory(const char *path, const char *outPath, int *streamCount, int *subtitleCount)
|
||||
{
|
||||
*streamCount = 4;
|
||||
*subtitleCount = 2;
|
||||
|
||||
Stream *streams = new Stream[*streamCount];
|
||||
streams[0] = Stream(NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
streams[1] = Stream(NULL, "eng", "ass", false, false, NULL);
|
||||
streams[2] = Stream(NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
streams[3] = Stream(NULL, "fre", "ass", false, false, NULL);
|
||||
|
||||
return streams;
|
||||
}
|
@ -17,3 +17,5 @@ extern "C" API int Transmux(const char *path, const char *outPath);
|
||||
extern "C" API Stream* ExtractSubtitles(const char *path, const char *outPath, int *streamCount, int *subtitleCount);
|
||||
|
||||
extern "C" API void FreeMemory(Stream *streamsPtr);
|
||||
|
||||
extern "C" API Stream* TestMemory(const char *path, const char *outPath, int *streamCount, int *subtitleCount);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using Kyoo.Models;
|
||||
using Kyoo.Models.Watch;
|
||||
@ -27,7 +28,7 @@ namespace Kyoo.InternalAPI.TranscoderLink
|
||||
|
||||
IntPtr ptr = ExtractSubtitles(path, outPath, out int arrayLength, out int trackCount);
|
||||
IntPtr streamsPtr = ptr;
|
||||
if (trackCount > 0)
|
||||
if (trackCount > 0 && ptr != IntPtr.Zero)
|
||||
{
|
||||
tracks = new Track[trackCount];
|
||||
|
||||
@ -47,6 +48,11 @@ namespace Kyoo.InternalAPI.TranscoderLink
|
||||
tracks = null;
|
||||
|
||||
FreeMemory(ptr);
|
||||
}
|
||||
Debug.WriteLine("&One loop done");
|
||||
}
|
||||
|
||||
[DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)]
|
||||
private extern static IntPtr TestMemory(string path, string outPath, out int arrayLength, out int trackCount);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user