Commit 4dac37e9 authored by NzSN's avatar NzSN

Merge branch 'master' into WASM

parents 3ac59c2c 14e8b4f7
......@@ -19,6 +19,8 @@ option(DEBUG "Only enable during development" OFF)
include_directories(${INCLUDE})
if(DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
message("Fetching googletest...")
# Google Test
include(FetchContent)
......
......@@ -88,6 +88,7 @@ void MovMemProto::close_internal() {
while (!s.empty()) {
auto mem = s.front();
mem.data = nullptr;
s.pop();
}
}
......
......@@ -3,18 +3,34 @@
namespace Utils {
static void close_input_file(AVFormatContext **ctx_ptr)
{
int i;
AVFormatContext *fmt_ctx = *ctx_ptr;
/* close decoder for each stream */
for (i = 0; i < fmt_ctx->nb_streams; i++) {
AVStream *stream = fmt_ctx->streams[i];
avcodec_close(stream->codec);
}
avformat_close_input(ctx_ptr);
}
static AVFormatContext* AVFormatInputContextConstructor(
std::string path, AVIOContext *customIO) {
const char *filename = path.c_str();
AVFormatContext *ctx = nullptr;
if (customIO != nullptr) {
ctx = avformat_alloc_context();
ctx->pb = customIO;
filename = nullptr;
}
printf("Open format\n");
if (avformat_open_input(&ctx, path.c_str(), nullptr, nullptr) < 0) {
if (avformat_open_input(&ctx, filename, nullptr, nullptr) < 0) {
return nullptr;
}
......@@ -22,7 +38,7 @@ static AVFormatContext* AVFormatInputContextConstructor(
printf("Find stream\n");
if (avformat_find_stream_info(ctx, nullptr) < 0) {
avformat_close_input(&ctx);
close_input_file(&ctx);
return nullptr;
}
printf("Done\n");
......@@ -31,7 +47,9 @@ static AVFormatContext* AVFormatInputContextConstructor(
}
static void AVFormatInputContextDestructor(AVFormatContext *ctx) {
avformat_close_input(&ctx);
if (ctx != nullptr) {
avformat_close_input(&ctx);
}
}
AVFormatContextShared makeInAVFormat(std::string path, AVIOContext *customIO) {
......@@ -62,7 +80,11 @@ static AVFormatContext* AVFormatOutputContextConstructor(
}
static void AVFormatOutputContextDestructor(AVFormatContext *ctx) {
avformat_close_input(&ctx);
if (ctx != nullptr) {
if (ctx->pb && strnlen(ctx->filename, 1024) > 0)
avio_close(ctx->pb);
avformat_free_context(ctx);
}
}
AVFormatContextShared makeOutAVFormat(
......
......@@ -235,7 +235,7 @@ TEST_F(IOCTX_With_MovMem_Proto_Fixture, Initialize) {
t1.detach();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::this_thread::sleep_for(std::chrono::milliseconds(500));
inCtxMM = new IOCtx::InCtx("", mmProto);
AVStream *s = inCtxMM->getStream([](AVStream *s) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment