Skip to content

Commit 181db91

Browse files
committed
Address #5 by adding debug options via shift menu
1 parent 5b0c27d commit 181db91

16 files changed

Lines changed: 189 additions & 82 deletions

native/recorder/src/FrameProcessor.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ FrameProcessor::FrameProcessor(const std::string directory,
3737
const std::string prefix,
3838
std::shared_ptr<VideoRecorder> videoRecorder,
3939
int durationSecs, FRectangle cropArea,
40-
Guide guide)
40+
Guide guide, bool addTimeOverlay)
4141
: directory(directory), prefix(prefix), cropArea(cropArea),
42-
pxCropArea(Rectangle(0, 0, 0, 0)), guide(guide),
42+
pxCropArea(Rectangle(0, 0, 0, 0)), guide(guide), addTimeOverlay(addTimeOverlay),
4343
videoRecorder(videoRecorder), durationSecs(durationSecs), running(true),
4444
processThread(&FrameProcessor::processFrames, this)
4545
{
@@ -293,7 +293,10 @@ void FrameProcessor::processFrames()
293293
}
294294

295295
encodeTimestamp(cropped->data, cropped->stride, video_frame->timestamp);
296-
// overlayTime(cropped->data, cropped->stride, video_frame->timestamp);
296+
if (addTimeOverlay)
297+
{
298+
overlayTime(cropped->data, cropped->stride, video_frame->timestamp);
299+
}
297300

298301
auto err = videoRecorder->writeVideoFrame(cropped);
299302
if (!err.empty())

native/recorder/src/FrameProcessor.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class FrameProcessor
6464
*/
6565
FrameProcessor(const std::string directory, const std::string prefix,
6666
std::shared_ptr<VideoRecorder> videoRecorder, int durationSecs,
67-
FRectangle cropArea, Guide guide);
67+
FRectangle cropArea, Guide guide, bool addTimeOverlay);
6868

6969
void addFrame(FramePtr frame);
7070

@@ -102,6 +102,8 @@ class FrameProcessor
102102
FRectangle cropArea;
103103
Rectangle pxCropArea;
104104
Guide guide;
105+
bool addTimeOverlay;
106+
105107
std::shared_ptr<VideoRecorder> videoRecorder;
106108
uint64_t durationSecs;
107109
uint64_t nextStartTime = 0;

native/recorder/src/NdiReader.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,27 @@ class NdiReader : public VideoReader
250250

251251
auto msPerFrame =
252252
1000 * video_frame.frame_rate_D / video_frame.frame_rate_N;
253+
254+
if (frameCount < (2000 / msPerFrame))
255+
{
256+
// Ignore the first two seconds as there are often missing or badly timestamped frames
257+
break;
258+
}
253259
if (deltaMs == 0 || (lastTS != 0 && deltaMs >= 2 * msPerFrame))
254260
{
255261
std::stringstream timestring;
256262
timestring << std::put_time(local_time, "%H:%M:%S") << "." << std::setw(3)
257263
<< std::setfill('0') << milli % 1000;
258264

259265
// For diagnostic purposes
260-
std::cerr << "Gap=" << deltaMs << "ms, msPerFrame=" << msPerFrame << " at " << timestring.str() << std::endl;
266+
std::stringstream message;
267+
message << "Gap=" << deltaMs << "ms (" << std::max(0.0, std::round(deltaMs / msPerFrame - 1)) << "frames missing) prior to " << timestring.str();
268+
std::cerr << message.str() << std::endl;
261269

262-
if (lastTS != 0 && deltaMs >= 100)
270+
if ((lastTS != 0 && deltaMs >= 110) || reportAllGaps)
263271
{
264-
// Only designate an error if past the 2s frame mark as startup often misses some
265-
std::stringstream ss;
266-
ss << (frameCount > (2000 / msPerFrame) ? "Error: " : "") << "Gap of " << deltaMs << "ms at " << timestring.str();
267-
SystemEventQueue::push("NDI", ss.str());
272+
const auto errmsg = std::string("Error: ") + message.str();
273+
SystemEventQueue::push("NDI", errmsg);
268274
}
269275
}
270276

native/recorder/src/RecorderAPI.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ nativeVideoRecorder(const Napi::CallbackInfo &info)
191191
return ret;
192192
}
193193
}
194+
bool reportAllGaps = false;
195+
if (props.Has("reportAllGaps"))
196+
{
197+
reportAllGaps = props.Get("reportAllGaps").As<Napi::Boolean>();
198+
}
199+
bool addTimeOverlay = false;
200+
if (props.Has("addTimeOverlay"))
201+
{
202+
addTimeOverlay = props.Get("addTimeOverlay").As<Napi::Boolean>();
203+
}
194204
auto folder = props.Get("recordingFolder").As<Napi::String>().Utf8Value();
195205
auto prefix = props.Get("recordingPrefix").As<Napi::String>().Utf8Value();
196206
auto networkCamera =
@@ -215,7 +225,7 @@ nativeVideoRecorder(const Napi::CallbackInfo &info)
215225
guide.pt2 = guideObj.Get("pt2").As<Napi::Number>().FloatValue();
216226

217227
auto result = recorder->start(networkCamera, "ffmpeg", folder, prefix,
218-
interval, cropRect, guide);
228+
interval, cropRect, guide, reportAllGaps, addTimeOverlay);
219229
if (!result.empty())
220230
{
221231
std::cerr << "Error: " << result << std::endl;
@@ -331,7 +341,7 @@ nativeVideoRecorder(const Napi::CallbackInfo &info)
331341
ret.Set("width", Napi::Number::New(env, uyvy422Frame->xres));
332342
ret.Set("height", Napi::Number::New(env, uyvy422Frame->yres));
333343
ret.Set("totalBytes", Napi::Number::New(env, totalBytes));
334-
ret.Set("tsMilli", Napi::Number::New(env, uyvy422Frame->timestamp/10000));
344+
ret.Set("tsMilli", Napi::Number::New(env, uyvy422Frame->timestamp / 10000));
335345
return ret;
336346
}
337347
else if (op == "send-visca-cmd")

native/recorder/src/VideoController.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ class VideoController
104104
const std::string dir, const std::string prefix,
105105
const int interval,
106106
const FrameProcessor::FRectangle cropArea,
107-
const FrameProcessor::Guide guide)
107+
const FrameProcessor::Guide guide,
108+
const bool reportAllGaps, const bool addTimeOverlay)
108109
{
109110
std::lock_guard<std::recursive_mutex> lock(controlMutex);
110111
this->srcName = srcName;
@@ -157,8 +158,9 @@ class VideoController
157158
}
158159

159160
frameProcessor = std::shared_ptr<FrameProcessor>(new FrameProcessor(
160-
dir, prefix, videoRecorder, interval, cropArea, guide));
161+
dir, prefix, videoRecorder, interval, cropArea, guide, addTimeOverlay));
161162

163+
videoReader->setProperties(reportAllGaps);
162164
retval = videoReader->start(srcName, [this](FramePtr frame)
163165
{ this->frameProcessor->addFrame(frame); });
164166
if (!retval.empty())

native/recorder/src/VideoReader.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class VideoReader
99
{
10+
protected:
11+
bool reportAllGaps = false;
12+
1013
public:
1114
using AddFrameFunction = std::function<void(FramePtr)>;
1215
typedef struct CameraInfo
@@ -21,6 +24,10 @@ class VideoReader
2124
virtual std::string start(const std::string srcName,
2225
AddFrameFunction addFrameFunction) = 0;
2326
virtual std::string stop() = 0;
27+
virtual void setProperties(bool reportAllGaps)
28+
{
29+
this->reportAllGaps = reportAllGaps;
30+
}
2431
virtual std::vector<CameraInfo> getCameraList()
2532
{
2633
return std::vector<CameraInfo>();

native/recorder/src/VideoUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <algorithm>
22
#include <chrono>
33
#include <iostream>
4+
#include <vector>
45
#include <stdint.h>
56
#include "VideoUtils.hpp"
67

@@ -220,7 +221,7 @@ void overlayTime(uint8_t *ptr, int stride, uint64_t ts100ns, const std::tm *loca
220221
int local_minutes = local_time->tm_min;
221222
int local_secs = local_time->tm_sec;
222223

223-
Point point = Point(stride / 8, 40);
224+
Point point = Point(40, 40); // Point(stride / 8, 40);
224225

225226
overlayDigits(screen, stride, point, local_hours, 2);
226227
setDigitPixels(screen, 10, point, stride, timeColor, black);

0 commit comments

Comments
 (0)