Skip to content

Commit d3c8e6d

Browse files
authored
Amlogic updates (#1285)
* Limit Amlogic grabber to 30fps * Exclude FB Grabber on Amlogic platform, as FB is included in Amlogic Grabber * Amlogic Grabber - Have continuous feed even when paused. Have no delay when pausing/unpausing * Revert back to CAP_FLAG_AT_END capture method * Clarification on Capture Frequency
1 parent 5ef8c23 commit d3c8e6d

File tree

4 files changed

+32
-38
lines changed

4 files changed

+32
-38
lines changed

assets/webconfig/i18n/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@
327327
"edt_conf_fbs_timeout_title": "Timeout",
328328
"edt_conf_fg_display_expl": "Select which desktop should be captured (multi monitor setup)",
329329
"edt_conf_fg_display_title": "Display",
330-
"edt_conf_fg_frequency_Hz_expl": "How fast new pictures are captured",
330+
"edt_conf_fg_frequency_Hz_expl": "How fast new pictures are captured, i.e. it is the sampling rate. Note: The video might be played at a higher or lower frame rate.",
331331
"edt_conf_fg_frequency_Hz_title": "Capture frequency",
332332
"edt_conf_fg_heading_title": "Screen Capture",
333333
"edt_conf_fg_height_expl": "Shrink picture to this height, as raw picture needs a lot of CPU time.",

libsrc/api/JsonAPI.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,9 @@ void JsonAPI::handleInputSourceCommand(const QJsonObject& message, const QString
15411541
delete xcbGrabber;
15421542
#endif
15431543

1544-
#ifdef ENABLE_FB
1544+
//Ignore FB for Amlogic, as it is embedded in the Amlogic grabber itself
1545+
#if defined(ENABLE_FB) && !defined(ENABLE_AMLOGIC)
1546+
15451547
FramebufferFrameGrabber* fbGrabber = new FramebufferFrameGrabber();
15461548
device = fbGrabber->discover(params);
15471549
if (!device.isEmpty() )

libsrc/grabber/amlogic/AmlogicGrabber.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const bool verbose = false;
3030
const char DEFAULT_FB_DEVICE[] = "/dev/fb0";
3131
const char DEFAULT_VIDEO_DEVICE[] = "/dev/amvideo";
3232
const char DEFAULT_CAPTURE_DEVICE[] = "/dev/amvideocap0";
33-
34-
const int AMVIDEOCAP_WAIT_MAX_MS = 50;
33+
const int AMVIDEOCAP_WAIT_MAX_MS = 40;
34+
const int AMVIDEOCAP_DEFAULT_RATE_HZ = 25;
3535

3636
} //End of constants
3737

@@ -44,7 +44,6 @@ AmlogicGrabber::AmlogicGrabber()
4444
, _grabbingModeNotification(0)
4545
{
4646
_image_ptr = _image_bgr.memptr();
47-
4847
_useImageResampler = true;
4948
}
5049

@@ -71,11 +70,16 @@ bool AmlogicGrabber::setupScreen()
7170

7271
bool AmlogicGrabber::openDevice(int &fd, const char* dev)
7372
{
73+
bool rc = true;
7474
if (fd<0)
7575
{
7676
fd = ::open(dev, O_RDWR);
77+
if ( fd < 0)
78+
{
79+
rc = false;
80+
}
7781
}
78-
return fd >= 0;
82+
return rc;
7983
}
8084

8185
void AmlogicGrabber::closeDevice(int &fd)
@@ -92,7 +96,6 @@ bool AmlogicGrabber::isVideoPlaying()
9296
bool rc = false;
9397
if(QFile::exists(DEFAULT_VIDEO_DEVICE))
9498
{
95-
9699
int videoDisabled = 1;
97100
if (!openDevice(_videoDev, DEFAULT_VIDEO_DEVICE))
98101
{
@@ -148,8 +151,6 @@ int AmlogicGrabber::grabFrame(Image<ColorRgb> & image)
148151
_lastError = 0;
149152
}
150153
rc = _fbGrabber.grabFrame(image);
151-
152-
//usleep(50 * 1000);
153154
}
154155
}
155156
return rc;
@@ -189,32 +190,26 @@ int AmlogicGrabber::grabFrame_amvideocap(Image<ColorRgb> & image)
189190

190191
// Read the snapshot into the memory
191192
ssize_t bytesRead = pread(_captureDev, _image_ptr, _bytesToRead, 0);
192-
if (bytesRead < 0)
193+
194+
if ( bytesRead < 0 && !EAGAIN && errno > 0 )
193195
{
194-
int state;
195-
ioctl(_captureDev, AMVIDEOCAP_IOR_GET_STATE, &state);
196-
if (state == AMVIDEOCAP_STATE_ON_CAPTURE)
197-
{
198-
DebugIf(_lastError != 5, _log,"Video playback has been paused");
199-
_lastError = 5;
200-
}
201-
else
202-
{
203-
ErrorIf(_lastError != 3, _log,"Read of device failed: %d - %s", errno, strerror(errno));
204-
_lastError = 3;
205-
}
196+
ErrorIf(_lastError != 3, _log,"Capture frame failed failed - Retrying. Error [%d] - %s", errno, strerror(errno));
197+
_lastError = 3;
206198
rc = -1;
207199
}
208200
else
209201
{
210-
if (static_cast<ssize_t>(_bytesToRead) != bytesRead)
202+
if (bytesRead != -1 && static_cast<ssize_t>(_bytesToRead) != bytesRead)
211203
{
212204
// Read of snapshot failed
213205
ErrorIf(_lastError != 4, _log,"Capture failed to grab entire image [bytesToRead(%d) != bytesRead(%d)]", _bytesToRead, bytesRead);
214206
_lastError = 4;
215207
rc = -1;
216208
}
217209
else {
210+
//If bytesRead = -1 but no error or EAGAIN or ENODATA, return last image to cover video pausing scenario
211+
// EAGAIN : // 11 - Resource temporarily unavailable
212+
// ENODATA: // 61 - No data available
218213
_imageResampler.processImage(static_cast<uint8_t*>(_image_ptr),
219214
_width,
220215
_height,
@@ -244,7 +239,7 @@ QJsonObject AmlogicGrabber::discover(const QJsonObject& params)
244239
int fbIdx = _fbGrabber.getPath().rightRef(1).toInt();
245240

246241
DebugIf(verbose, _log, "FB device [%s] found with resolution: %dx%d", QSTRING_CSTR(_fbGrabber.getPath()), screenSize.width(), screenSize.height());
247-
QJsonArray fps = { 1, 5, 10, 15, 20, 25, 30, 40, 50, 60 };
242+
QJsonArray fps = { 1, 5, 10, 15, 20, 25, 30};
248243

249244
QJsonObject in;
250245

@@ -282,7 +277,7 @@ QJsonObject AmlogicGrabber::discover(const QJsonObject& params)
282277
inputsDiscovered["video_inputs"] = video_inputs;
283278

284279
QJsonObject defaults, video_inputs_default, resolution_default;
285-
resolution_default["fps"] = _fps;
280+
resolution_default["fps"] = AMVIDEOCAP_DEFAULT_RATE_HZ;
286281
video_inputs_default["resolution"] = resolution_default;
287282
video_inputs_default["inputIdx"] = 0;
288283
defaults["video_input"] = video_inputs_default;
@@ -328,7 +323,7 @@ bool AmlogicGrabber::setWidthHeight(int width, int height)
328323
_height = height;
329324
_bytesToRead = _image_bgr.size();
330325
_image_ptr = _image_bgr.memptr();
331-
rc = _fbGrabber.setWidthHeight(width, height);
326+
rc = _fbGrabber.setWidthHeight(width, height);
332327
}
333328
return rc;
334329
}

libsrc/grabber/amlogic/Amvideocap.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@
3131
#define AMVIDEOCAP_IOW_SET_START_CAPTURE _IOW(AMVIDEOCAP_IOC_MAGIC, 0x32, int)
3232
#define AMVIDEOCAP_IOW_SET_CANCEL_CAPTURE _IOW(AMVIDEOCAP_IOC_MAGIC, 0x33, int)
3333

34-
#define _A_M 'S'
35-
#define AMSTREAM_IOC_GET_VIDEO_DISABLE _IOR((_A_M), 0x48, int)
36-
37-
#define AMVIDEOCAP_IOC_MAGIC 'V'
38-
#define AMVIDEOCAP_IOW_SET_START_CAPTURE _IOW(AMVIDEOCAP_IOC_MAGIC, 0x32, int)
39-
40-
enum amvideocap_state{
41-
AMVIDEOCAP_STATE_INIT=0,
42-
AMVIDEOCAP_STATE_ON_CAPTURE=200,
43-
AMVIDEOCAP_STATE_FINISHED_CAPTURE=300,
44-
AMVIDEOCAP_STATE_ERROR=0xffff,
45-
};
34+
#define AMSTREAM_IOC_MAGIC 'S'
35+
#define AMSTREAM_IOC_GET_VIDEO_DISABLE _IOR((AMSTREAM_IOC_MAGIC), 0x48, int)
36+
37+
enum amvideocap_state{
38+
AMVIDEOCAP_STATE_INIT=0,
39+
AMVIDEOCAP_STATE_ON_CAPTURE=200,
40+
AMVIDEOCAP_STATE_FINISHED_CAPTURE=300,
41+
AMVIDEOCAP_STATE_ERROR=0xffff,
42+
};

0 commit comments

Comments
 (0)