Skip to content

Commit 83baf0e

Browse files
authored
Set output video and osd by plane id (#72)
Adds --video-plane-id and --osd-plane-id as parameters for pixelpilot to override defaults.
1 parent aa5e739 commit 83baf0e

File tree

3 files changed

+59
-15
lines changed

3 files changed

+59
-15
lines changed

src/drm.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ const char* drm_fourcc_to_string(uint32_t fourcc) {
213213
return result;
214214
}
215215

216-
int modeset_find_plane(int fd, struct modeset_output *out, struct drm_object *plane_out, uint32_t plane_format)
216+
int modeset_find_plane(int fd, struct modeset_output *out, struct drm_object *plane_out, uint32_t plane_format, uint32_t plane_id_override)
217217
{
218218
drmModePlaneResPtr plane_res;
219219
bool found_plane = false;
@@ -226,6 +226,33 @@ int modeset_find_plane(int fd, struct modeset_output *out, struct drm_object *pl
226226
return -ENOENT;
227227
}
228228

229+
if (plane_id_override) {
230+
// Try to use the user-specified plane id
231+
drmModePlanePtr plane = drmModeGetPlane(fd, plane_id_override);
232+
if (!plane) {
233+
fprintf(stderr, "drmModeGetPlane(%u) failed: %s\n", plane_id_override, strerror(errno));
234+
drmModeFreePlaneResources(plane_res);
235+
return -ENOENT;
236+
}
237+
if (plane->possible_crtcs & (1 << out->crtc_index)) {
238+
for (int j = 0; j < plane->count_formats; j++) {
239+
if (plane->formats[j] == plane_format) {
240+
found_plane = true;
241+
plane_out->id = plane_id_override;
242+
ret = 0;
243+
break;
244+
}
245+
}
246+
}
247+
if (!found_plane) {
248+
fprintf(stderr, "Specified plane id %u does not support required format or CRTC\n", plane_id_override);
249+
ret = -EINVAL;
250+
}
251+
drmModeFreePlane(plane);
252+
drmModeFreePlaneResources(plane_res);
253+
return ret;
254+
}
255+
229256
for (i = 0; (i < plane_res->count_planes) && !found_plane; i++) {
230257
int plane_id = plane_res->planes[i];
231258

@@ -414,7 +441,7 @@ void modeset_output_destroy(int fd, struct modeset_output *out)
414441
free(out);
415442
}
416443

417-
struct modeset_output *modeset_output_create(int fd, drmModeRes *res, drmModeConnector *conn, uint16_t mode_width, uint16_t mode_height, uint32_t mode_vrefresh)
444+
struct modeset_output *modeset_output_create(int fd, drmModeRes *res, drmModeConnector *conn, uint16_t mode_width, uint16_t mode_height, uint32_t mode_vrefresh, uint32_t video_plane_id, uint32_t osd_plane_id)
418445
{
419446
int ret;
420447
struct modeset_output *out;
@@ -475,14 +502,14 @@ struct modeset_output *modeset_output_create(int fd, drmModeRes *res, drmModeCon
475502
goto out_blob;
476503
}
477504

478-
ret = modeset_find_plane(fd, out, &out->video_plane, DRM_FORMAT_NV12);
505+
ret = modeset_find_plane(fd, out, &out->video_plane, DRM_FORMAT_NV12, video_plane_id);
479506
if (ret) {
480507
fprintf(stderr, "no valid video plane with format NV12 for crtc %u\n", out->crtc.id);
481508
goto out_blob;
482509
}
483510
fprintf(stdout, "Using plane %d (NV12) for Video\n", out->video_plane.id);
484511

485-
ret = modeset_find_plane(fd, out, &out->osd_plane, DRM_FORMAT_ARGB8888);
512+
ret = modeset_find_plane(fd, out, &out->osd_plane, DRM_FORMAT_ARGB8888, osd_plane_id);
486513
if (ret) {
487514
fprintf(stderr, "no valid osd plane with format ARGB8888 for crtc %u\n", out->crtc.id);
488515
goto out_blob;
@@ -560,7 +587,7 @@ void *modeset_print_modes(int fd)
560587

561588
}
562589

563-
struct modeset_output *modeset_prepare(int fd, uint16_t mode_width, uint16_t mode_height, uint32_t mode_vrefresh)
590+
struct modeset_output *modeset_prepare(int fd, uint16_t mode_width, uint16_t mode_height, uint32_t mode_vrefresh, uint32_t video_plane_id, uint32_t osd_plane_id)
564591
{
565592
drmModeRes *res;
566593
drmModeConnector *conn;
@@ -582,7 +609,7 @@ struct modeset_output *modeset_prepare(int fd, uint16_t mode_width, uint16_t mod
582609
continue;
583610
}
584611

585-
out = modeset_output_create(fd, res, conn, mode_width, mode_height, mode_vrefresh);
612+
out = modeset_output_create(fd, res, conn, mode_width, mode_height, mode_vrefresh, video_plane_id, osd_plane_id);
586613
drmModeFreeConnector(conn);
587614
if (out) {
588615
drmModeFreeResources(res);

src/drm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int modeset_find_crtc(int fd, drmModeRes *res, drmModeConnector *conn, struct mo
8787

8888
const char* drm_fourcc_to_string(uint32_t fourcc);
8989

90-
int modeset_find_plane(int fd, struct modeset_output *out, struct drm_object *plane_out, uint32_t plane_format);
90+
int modeset_find_plane(int fd, struct modeset_output *out, struct drm_object *plane_out, uint32_t plane_format, uint32_t plane_id_override);
9191

9292
void modeset_drm_object_fini(struct drm_object *obj);
9393

@@ -103,9 +103,9 @@ int modeset_setup_framebuffers(int fd, drmModeConnector *conn, struct modeset_ou
103103

104104
void modeset_output_destroy(int fd, struct modeset_output *out);
105105

106-
struct modeset_output *modeset_output_create(int fd, drmModeRes *res, drmModeConnector *conn, uint16_t mode_width, uint16_t mode_height, uint32_t mode_vrefresh);
106+
struct modeset_output *modeset_output_create(int fd, drmModeRes *res, drmModeConnector *conn, uint16_t mode_width, uint16_t mode_height, uint32_t mode_vrefresh, uint32_t video_plane_id, uint32_t osd_plane_id);
107107

108-
struct modeset_output *modeset_prepare(int fd, uint16_t mode_width, uint16_t mode_height, uint32_t mode_vrefresh);
108+
struct modeset_output *modeset_prepare(int fd, uint16_t mode_width, uint16_t mode_height, uint32_t mode_vrefresh, uint32_t video_plane_id, uint32_t osd_plane_id);
109109

110110
void *modeset_print_modes(int fd);
111111

src/main.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ uint32_t refresh_frequency_ms = 1000;
9898
VideoCodec codec = VideoCodec::H265;
9999
Dvr *dvr = NULL;
100100

101+
// Add global variables for plane id overrides
102+
uint32_t video_plane_id_override = 0;
103+
uint32_t osd_plane_id_override = 0;
104+
101105
void init_buffer(MppFrame frame) {
102106
output_list->video_frm_width = mpp_frame_get_width(frame);
103107
output_list->video_frm_height = mpp_frame_get_height(frame);
@@ -531,8 +535,8 @@ void printHelp() {
531535
" Supports placeholders %%Y - year, %%m - month, %%d - day,\n"
532536
" %%H - hour, %%M - minute, %%S - second. Ex: /media/DVR/%%Y-%%m-%%d_%%H-%%M-%%S.mp4\n"
533537
"\n"
534-
" --dvr-sequenced-files - Prepend a sequence number to the names of the dvr files\n"
535-
"\n"
538+
" --dvr-sequenced-files - Prepend a sequence number to the names of the dvr files\n"
539+
"\n"
536540
" --dvr-start - Start DVR immediately\n"
537541
"\n"
538542
" --dvr-framerate <rate> - Force the dvr framerate for smoother dvr, ex: 60\n"
@@ -541,12 +545,16 @@ void printHelp() {
541545
"\n"
542546
" --screen-mode <mode> - Override default screen mode. <width>x<heigth>@<fps> ex: 1920x1080@120\n"
543547
"\n"
544-
" --disable-vsync - Disable VSYNC commits\n"
545-
"\n"
548+
" --video-plane-id - Override default drm plane used for video by plane-id\n"
549+
"\n"
550+
" --osd-plane-id - Override default drm plane used for osd by plane-id\n"
551+
"\n"
552+
" --disable-vsync - Disable VSYNC commits\n"
553+
"\n"
546554
" --screen-mode-list - Print the list of supported screen modes and exit.\n"
547555
"\n"
548556
" --wfb-api-port - Port of wfb-server for cli statistics. (Default: 8003)\n"
549-
" Use \"0\" to disable this stats\n"
557+
" Use \"0\" to disable this stats\n"
550558
"\n"
551559
" --version - Show program version\n"
552560
"\n", APP_VERSION_MAJOR, APP_VERSION_MINOR
@@ -760,6 +768,15 @@ int main(int argc, char **argv)
760768
return 0;
761769
}
762770

771+
__OnArgument("--video-plane-id") {
772+
video_plane_id_override = atoi(__ArgValue);
773+
continue;
774+
}
775+
__OnArgument("--osd-plane-id") {
776+
osd_plane_id_override = atoi(__ArgValue);
777+
continue;
778+
}
779+
763780
__EndParseConsoleArguments__
764781

765782
spdlog::set_level(log_level);
@@ -796,7 +813,7 @@ int main(int argc, char **argv)
796813
return 0;
797814
}
798815

799-
output_list = modeset_prepare(drm_fd, mode_width, mode_height, mode_vrefresh);
816+
output_list = modeset_prepare(drm_fd, mode_width, mode_height, mode_vrefresh, video_plane_id_override, osd_plane_id_override);
800817
if (!output_list) {
801818
fprintf(stderr,
802819
"cannot initialize display. Is display connected? Is --screen-mode correct?\n");

0 commit comments

Comments
 (0)