Skip to content

Commit

Permalink
Print error if not device found or failed initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Gervais <[email protected]>
  • Loading branch information
g-maxime committed Jun 17, 2024
1 parent 51d0648 commit 1331ab2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 41 deletions.
18 changes: 10 additions & 8 deletions Source/Common/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,34 @@ Core::~Core()
vector<file*> PerFile;
return_value Core::Process()
{
return_value ToReturn = ReturnValue_OK;

// Analyze files (asynchronous)
PerFile_Clear();
PerFile.reserve(Inputs.size());
std::vector<std::future<size_t>> futures;
std::vector<std::future<return_value>> futures;
for (const auto& Input : Inputs)
{
PerFile.push_back(new file());
futures.emplace_back(std::async(std::launch::async, [](size_t param, const String& Input) {
PerFile[param]->Parse(Input);
return param;
futures.emplace_back(std::async(std::launch::async, [](size_t index, const String& Input) {
return PerFile[index]->Parse(Input);
}, PerFile.size()-1, Input));
}
for (auto &future : futures) {
future.get();
if (auto ToReturn2 = future.get())
ToReturn = ToReturn2;
}
if (Device_Command)
return ReturnValue_OK;
return ToReturn;

if (!Merge_Out.empty())
{
PerFile[0]->Merge_Finish();
if (!XmlFile)
return ReturnValue_OK;
return ToReturn;
}

// Set output defaults
return_value ToReturn = ReturnValue_OK;
if (!XmlFile)
XmlFile = Out;

Expand Down
82 changes: 50 additions & 32 deletions Source/Common/ProcessFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ file::file()
}

//---------------------------------------------------------------------------
void file::Parse(const String& FileName)
return_value file::Parse(const String& FileName)
{
MI.Option(__T("File_Event_CallBackFunction"), __T("CallBack=memory://") + Ztring::ToZtring((size_t)&Event_CallBackFunction) + __T(";UserHandler=memory://") + Ztring::ToZtring((size_t)this));
MI.Option(__T("File_DvDif_Analysis"), __T("1"));
Expand Down Expand Up @@ -275,7 +275,7 @@ void file::Parse(const String& FileName)
#endif
if (Device_Command == 4) //JSON
cout << "]" << '\n';
return;
return ReturnValue_OK;
}
#ifdef ENABLE_SONY9PIN
else if (Device_Command == 5 || Device_Command == 6)
Expand Down Expand Up @@ -321,7 +321,7 @@ void file::Parse(const String& FileName)
if (!Controller)
{
cerr << "Error: unable to open control port: " << Control_Port << endl;
return;
return ReturnValue_ERROR;
}
}
#endif
Expand All @@ -345,48 +345,64 @@ void file::Parse(const String& FileName)
if (iss.fail() || !iss.eof())
Device_Pos = (uint64_t)-1;

if (false)
;
#ifdef ENABLE_SIMULATOR
try {
if (false)
;
#ifdef ENABLE_SIMULATOR
else if ((Device_Pos-=Device_Offset) < (Device_Offset=SimulatorWrapper::GetDeviceCount()))
{
Capture = new SimulatorWrapper(Device_Pos);
if (((SimulatorWrapper*)Capture)->IsMatroska())
CaptureMode = Capture_Mode_DeckLink;
}
#endif
#ifdef ENABLE_AVFCTL
#endif
#ifdef ENABLE_AVFCTL
else if ((Device_Pos-=Device_Offset) < (Device_Offset=AVFCtlWrapper::GetDeviceCount()))
Capture = new AVFCtlWrapper(Device_Pos, Controller);
else if (AVFCtlWrapper::GetDeviceIndex(Device) != (size_t)-1)
Capture = new AVFCtlWrapper(Device, Controller);
#endif
#ifdef ENABLE_DECKLINK
#endif
#ifdef ENABLE_DECKLINK
else if ((Device_Pos-=Device_Offset) < (Device_Offset=DecklinkWrapper::GetDeviceCount()))
try { CaptureMode = Capture_Mode_DeckLink;
Capture = new DecklinkWrapper(Device_Pos,
(decklink_video_mode)DeckLinkVideoMode,
(decklink_video_source)DeckLinkVideoSource,
(decklink_audio_source)DeckLinkAudioSource,
(decklink_timecode_format)DeckLinkTimecodeFormat,
Controller,
DeckLinkNativeControl); } catch(...) {}
{
CaptureMode = Capture_Mode_DeckLink;
Capture = new DecklinkWrapper(Device_Pos,
(decklink_video_mode)DeckLinkVideoMode,
(decklink_video_source)DeckLinkVideoSource,
(decklink_audio_source)DeckLinkAudioSource,
(decklink_timecode_format)DeckLinkTimecodeFormat,
Controller,
DeckLinkNativeControl);
}
else if (DecklinkWrapper::GetDeviceIndex(Device) != (size_t)-1)
try { CaptureMode = Capture_Mode_DeckLink;
Capture = new DecklinkWrapper(Device,
(decklink_video_mode)DeckLinkVideoMode,
(decklink_video_source)DeckLinkVideoSource,
(decklink_audio_source)DeckLinkAudioSource,
(decklink_timecode_format)DeckLinkTimecodeFormat,
Controller,
DeckLinkNativeControl); } catch(...) {}
#endif
#ifdef ENABLE_LNX1394
{
CaptureMode = Capture_Mode_DeckLink;
Capture = new DecklinkWrapper(Device,
(decklink_video_mode)DeckLinkVideoMode,
(decklink_video_source)DeckLinkVideoSource,
(decklink_audio_source)DeckLinkAudioSource,
(decklink_timecode_format)DeckLinkTimecodeFormat,
Controller,
DeckLinkNativeControl);
}
#endif
#ifdef ENABLE_LNX1394
else if ((Device_Pos-=Device_Offset) < (Device_Offset=LinuxWrapper::GetDeviceCount()))
try { Capture = new LinuxWrapper(Device_Pos); } catch(...) {}
Capture = new LinuxWrapper(Device_Pos);
else if (LinuxWrapper::GetDeviceIndex(Device) != (size_t)-1)
try { Capture = new LinuxWrapper(Device); } catch(...) {}
#endif
Capture = new LinuxWrapper(Device);
#endif
else
{
cerr << "Error: device not found: " << Device << endl;
return ReturnValue_ERROR;
}
}
catch(std::exception& e)
{
cerr << "Error: " << e.what() << endl;
return ReturnValue_ERROR;
}
}
if (Capture)
{
Expand All @@ -409,7 +425,7 @@ void file::Parse(const String& FileName)
{
InputControl_Char(this, Device_Command);
}
return;
return ReturnValue_OK;
}
Speed_Before = Capture->GetSpeed();
auto InputHelper = InControl ? new thread(InputControl, this) : nullptr;
Expand Down Expand Up @@ -472,6 +488,8 @@ void file::Parse(const String& FileName)
FrameRate = Ztring(MI.Get(Stream_Video, 0, __T("FrameRate"))).To_float64();
if (!FrameRate || (FrameRate >= 29.97 && FrameRate <= 29.98))
FrameRate = double(30 / 1.001); // Default if no frame rate available, or better rounding

return ReturnValue_OK;
}

//---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/ProcessFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class file
file();
~file();

void Parse(const String& FileName);
return_value Parse(const String& FileName);
void Parse_Buffer(const uint8_t* Buffer, size_t Buffer_Size);
void Terminate();

Expand Down

0 comments on commit 1331ab2

Please sign in to comment.