diff --git a/src/argparse.cpp b/src/argparse.cpp index ee632ad..4749aab 100644 --- a/src/argparse.cpp +++ b/src/argparse.cpp @@ -48,8 +48,6 @@ void ArgParse::printHelp() } } - - std::exit(0); } void ArgParse::parse() diff --git a/src/braw.cpp b/src/braw.cpp index 5208c0c..efdd292 100644 --- a/src/braw.cpp +++ b/src/braw.cpp @@ -117,7 +117,9 @@ Braw::Braw() Braw::~Braw() { - codec->FlushJobs(); + if (codec) { + codec->FlushJobs(); + } if (clip != nullptr) clip->Release(); @@ -136,9 +138,23 @@ void Braw::openFile(std::string filepath) // Setup BRAW SDK factory = CreateBlackmagicRawFactoryInstanceFromPath(lib); + if (factory == nullptr) { + throw std::runtime_error("Failed to initialize BRAW SDK"); + } factory->CreateCodec(&codec); const char *c = info->filename.c_str(); - codec->OpenClip(c, &clip); + HRESULT hr = codec->OpenClip(c, &clip); + if (hr == E_INVALIDARG) { + throw std::runtime_error("Invalid filename: " + filepath); + } + if (hr == E_FAIL) { + throw std::runtime_error("Failed to open clip. File might be corrupt"); + } + if (hr != S_OK) { + std::stringstream ss; + ss << "Internal Braw error. HRESULT=" << hr; + throw std::runtime_error(ss.str()); + } codec->SetCallback(&frameProcessor); clip->GetFrameCount(&(info->frameCount)); diff --git a/src/main.cpp b/src/main.cpp index dc81b98..e380ca3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ void test_func() void help() { args->printHelp(); + std::exit(0); } @@ -30,13 +31,22 @@ int main(int argc, char *argv[]) std::vector files = args->getArgsRemaining(); if(files.size() == 1) { - braw_decoder.openFile(files[0]); - }else{ + try { + braw_decoder.openFile(files[0]); + } catch (std::exception& e) { + std::cerr << "ERROR: " << e.what() << std::endl; + return 1; + } + } else if (files.size() == 0) { + std::cerr << "Missing input file argument" << std::endl; + return 1; + } else { std::cerr << "Too many files provided" << std::endl; for(int i = 0; i != files.size(); ++i) { std::cerr << "[" << i << "] " << files[i] << std::endl; } + return 1; } return 0;