Skip to content

Commit 76ee892

Browse files
authored
Merge pull request #2 from OpenBricks/master
don't hardcode dri device
2 parents fb839c4 + acd8b5f commit 76ee892

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

main.c

+17-6
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,13 @@ static int drm_open(const char *path)
317317
return -1;
318318
}
319319

320-
static int drm_init(unsigned int fourcc)
320+
static int drm_init(unsigned int fourcc, const char *device)
321321
{
322322
struct drm_dev *dev_head, *dev;
323323
int fd;
324324
int ret;
325325

326-
fd = drm_open("/dev/dri/card0");
326+
fd = drm_open(device);
327327
if (fd < 0)
328328
return -1;
329329

@@ -417,7 +417,7 @@ static int display(struct drm_buffer *drm_buf, int width, int height)
417417
}
418418

419419
static void decode_and_display(AVCodecContext *dec_ctx, AVFrame *frame,
420-
AVPacket *pkt)
420+
AVPacket *pkt, const char *device)
421421
{
422422
AVDRMFrameDescriptor *desc = NULL;
423423
struct drm_buffer drm_buf;
@@ -447,7 +447,7 @@ static void decode_and_display(AVCodecContext *dec_ctx, AVFrame *frame,
447447

448448
if (!pdev) {
449449
/* initialize DRM with the format returned in the frame */
450-
ret = drm_init(desc->layers[0].format);
450+
ret = drm_init(desc->layers[0].format, device);
451451
if (ret) {
452452
err("Error initializing drm\n");
453453
exit(1);
@@ -496,6 +496,12 @@ static const struct option options[] = {
496496
.has_arg = 1,
497497
.flag = NULL,
498498
},
499+
{
500+
#define device_opt 5
501+
.name = "device",
502+
.has_arg = 1,
503+
.flag = NULL,
504+
},
499505
{
500506
.name = NULL,
501507
},
@@ -509,6 +515,7 @@ static void usage(void)
509515
fprintf(stderr, "--codec=<name> ffmpeg codec: ie h264_v4l2m2m\n");
510516
fprintf(stderr, "--width=<value> frame width\n");
511517
fprintf(stderr, "--height=<value> frame height\n");
518+
fprintf(stderr, "--device=<value> dri device to use\n");
512519
fprintf(stderr, "\n");
513520
}
514521

@@ -527,6 +534,7 @@ int main(int argc, char *argv[])
527534
int lindex, opt;
528535
unsigned int frame_width = 0, frame_height = 0;
529536
char *codec_name = NULL, *video_name = NULL;
537+
char *device_name = "/dev/dri/card0";
530538

531539
for (;;) {
532540
lindex = -1;
@@ -551,6 +559,9 @@ int main(int argc, char *argv[])
551559
case height_opt:
552560
frame_height = atoi(optarg);
553561
break;
562+
case device_opt:
563+
device_name = optarg;
564+
break;
554565
default:
555566
usage();
556567
exit(1);
@@ -637,12 +648,12 @@ int main(int argc, char *argv[])
637648
data_size -= ret;
638649

639650
if (pkt->size)
640-
decode_and_display(c, frame, pkt);
651+
decode_and_display(c, frame, pkt, device_name);
641652
}
642653
}
643654
fclose(f);
644655

645-
decode_and_display(c, frame, NULL);
656+
decode_and_display(c, frame, NULL, device_name);
646657

647658
av_parser_close(parser);
648659
avcodec_free_context(&c);

0 commit comments

Comments
 (0)