@@ -317,13 +317,13 @@ static int drm_open(const char *path)
317
317
return -1 ;
318
318
}
319
319
320
- static int drm_init (unsigned int fourcc )
320
+ static int drm_init (unsigned int fourcc , const char * device )
321
321
{
322
322
struct drm_dev * dev_head , * dev ;
323
323
int fd ;
324
324
int ret ;
325
325
326
- fd = drm_open ("/dev/dri/card0" );
326
+ fd = drm_open (device );
327
327
if (fd < 0 )
328
328
return -1 ;
329
329
@@ -417,7 +417,7 @@ static int display(struct drm_buffer *drm_buf, int width, int height)
417
417
}
418
418
419
419
static void decode_and_display (AVCodecContext * dec_ctx , AVFrame * frame ,
420
- AVPacket * pkt )
420
+ AVPacket * pkt , const char * device )
421
421
{
422
422
AVDRMFrameDescriptor * desc = NULL ;
423
423
struct drm_buffer drm_buf ;
@@ -447,7 +447,7 @@ static void decode_and_display(AVCodecContext *dec_ctx, AVFrame *frame,
447
447
448
448
if (!pdev ) {
449
449
/* 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 );
451
451
if (ret ) {
452
452
err ("Error initializing drm\n" );
453
453
exit (1 );
@@ -496,6 +496,12 @@ static const struct option options[] = {
496
496
.has_arg = 1 ,
497
497
.flag = NULL ,
498
498
},
499
+ {
500
+ #define device_opt 5
501
+ .name = "device" ,
502
+ .has_arg = 1 ,
503
+ .flag = NULL ,
504
+ },
499
505
{
500
506
.name = NULL ,
501
507
},
@@ -509,6 +515,7 @@ static void usage(void)
509
515
fprintf (stderr , "--codec=<name> ffmpeg codec: ie h264_v4l2m2m\n" );
510
516
fprintf (stderr , "--width=<value> frame width\n" );
511
517
fprintf (stderr , "--height=<value> frame height\n" );
518
+ fprintf (stderr , "--device=<value> dri device to use\n" );
512
519
fprintf (stderr , "\n" );
513
520
}
514
521
@@ -527,6 +534,7 @@ int main(int argc, char *argv[])
527
534
int lindex , opt ;
528
535
unsigned int frame_width = 0 , frame_height = 0 ;
529
536
char * codec_name = NULL , * video_name = NULL ;
537
+ char * device_name = "/dev/dri/card0" ;
530
538
531
539
for (;;) {
532
540
lindex = -1 ;
@@ -551,6 +559,9 @@ int main(int argc, char *argv[])
551
559
case height_opt :
552
560
frame_height = atoi (optarg );
553
561
break ;
562
+ case device_opt :
563
+ device_name = optarg ;
564
+ break ;
554
565
default :
555
566
usage ();
556
567
exit (1 );
@@ -637,12 +648,12 @@ int main(int argc, char *argv[])
637
648
data_size -= ret ;
638
649
639
650
if (pkt -> size )
640
- decode_and_display (c , frame , pkt );
651
+ decode_and_display (c , frame , pkt , device_name );
641
652
}
642
653
}
643
654
fclose (f );
644
655
645
- decode_and_display (c , frame , NULL );
656
+ decode_and_display (c , frame , NULL , device_name );
646
657
647
658
av_parser_close (parser );
648
659
avcodec_free_context (& c );
0 commit comments