[MPlayer-users] Mapping DVD drive eject and forward buttons

Gert van Biljon gertvb at webmail.co.za
Fri Aug 5 21:25:08 CEST 2005


Hi There!

Thanks for all the replies, got my problem sorted, in a bit
of a weird way but it works for now.

Modified a program that I found on the web, it basically
does an ioctl to the drive requesting the status of the
eject button, based on this I rename a marker file, and
based on the name of the marker file a new perl script then
kills mplayer, and the script then calls eject.

Thanks

Gert van Biljon

PS Code attached:

/******************************************************************************
*
                                                            
               *
* File Name          : eject_button_test.c
                                   *
*
                                                            
               *
* Description        : Program to enquire from the cdrom if
the eject button  *
*                      was pressed with a disk in the drive
                  *
*
                                                            
               *
* What I Do          : Basically do a CDROM_SEND_PACKET to
the CD Drive,      *
*                      requesting
GPCMD_GET_EVENT_STATUS_NOTIFICATION         *
*
                                                            
               *
* Why?               : When mplayer plays a dvd, it
disables the eject button *
*                      on the cdrom drive, and it can thus
not be ejected     *
*                      This program just retrieves the
button state so a perl *
*                      script can then kill mplayer if the
user wants to eject*
*                      a disk
                                                *
*
                                                            
               *
* Parameters         : None
                                                  *
*
                                                            
               *
* Return             : int
                                                   *
*                       3 : if eject was pressed with a
disk in the drive     *
*                       0 : in all other cases
                               *
*                      -1 : if I cannot do a file open on
the cd drive        *
*                      -2 : if I cannot do an ioctl
                          *
*
                                                            
               *
* Required           : read write access to /dev/hdc
                         *
*                      Linux :-), use that other OS at your
own peril         *
*
                                                            
               *
******************************************************************************/

#include <stdio.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <linux/cdrom.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>

int Get_Eject_Button_Pressed_State()
{
  struct   cdrom_generic_command   CD_Rom_Generic_Command;
  struct   request_sense           Request_Sense;
  char     CD_Rom_Drive_Name[40] = "/dev/hdc";
  unsigned char
                   CD_Rom_Generic_Command_Buffer[8];
  int                              CD_Drive_File_Handle;
  int                              IO_Control_Return_Value;

  CD_Drive_File_Handle = open(CD_Rom_Drive_Name, O_RDONLY |
O_NONBLOCK);
  if (CD_Drive_File_Handle == -1)
  {
    fprintf(stderr, "CD Drive open error!\n");
    return -1;
  }

  memset((&CD_Rom_Generic_Command), 0, sizeof(struct
cdrom_generic_command));
  memset(CD_Rom_Generic_Command_Buffer, 0, 8);
  memset(&Request_Sense, 0, sizeof(struct request_sense));
	
  CD_Rom_Generic_Command.cmd[0]         =
GPCMD_GET_EVENT_STATUS_NOTIFICATION;
  CD_Rom_Generic_Command.cmd[1]         = 1;
  CD_Rom_Generic_Command.cmd[4]         = 16;
  CD_Rom_Generic_Command.cmd[8]         = 8;
  CD_Rom_Generic_Command.timeout        = 1000;
  CD_Rom_Generic_Command.buffer         =
CD_Rom_Generic_Command_Buffer;
  CD_Rom_Generic_Command.buflen         = 8;
  CD_Rom_Generic_Command.data_direction = CGC_DATA_READ;
  CD_Rom_Generic_Command.sense          = &Request_Sense;
  CD_Rom_Generic_Command.quiet          = 1;

  IO_Control_Return_Value = ioctl(CD_Drive_File_Handle,
CDROM_SEND_PACKET, &CD_Rom_Generic_Command);
  if (IO_Control_Return_Value == -1) 
  {
    fprintf(stderr, "IO Control Error!\n");
    return -2;
  }

  close(CD_Drive_File_Handle);

  /**************************************************************************
 
  * Pressing the eject button results in the following
values               *
  *
                                                            
           *
  * CD_Rom_Generic_Command_Buffer[4]
                                       *
  * 0 : 0000 : Nothing
                                                     *
  * 1 : 0001 : Eject button pressed, with tray closed,
without any disk     *
  * 2 : 0010 : Eject button pressed, with tray open,   with
a disk          *
  * 3 : 0011 : Eject button pressed, with tray closed, with
a disk          *
  *
                                                            
           *
  * CD_Rom_Generic_Command_Buffer[5]
                                       *
  * 0 : Tray Closed, Tray no disk
                                          *
  * 1 : Tray Open
                                                          *
  * 2 : Tray Closed, Tray contains a disk
                                  *
  *
                                                            
           *
  **************************************************************************/
 
  if (CD_Rom_Generic_Command_Buffer[4] > 0)
    return 1;
  else
    return 0;
}

int main(int argc, char *argv[])
{
  int  Eject_Button_Pressed_With_Disk_In_Tray = 0;
  char Move_Marker_Command[100];
  struct timespec sleeptime;
  
  sleeptime.tv_sec = 0;
  sleeptime.tv_nsec = 10;

  while(1)
  {
    Eject_Button_Pressed_With_Disk_In_Tray =
Get_Eject_Button_Pressed_State();
    if (Eject_Button_Pressed_With_Disk_In_Tray > 0)
    {
      snprintf(Move_Marker_Command,
sizeof(Move_Marker_Command)-1, "mv
/root/jukebox/noeject.txt /root/jukebox/eject.txt");
      if (system(Move_Marker_Command) == -1 ) 
      {
        fprintf(stderr, "Cannot move marker file!\n");
      }//if (system...
    }//if (Eject_Button...
    nanosleep(&sleeptime, NULL);
  }//while
}//main
 

On Thu, 04 Aug 2005 00:18:04 +0200
 "Gert van Biljon" <gertvb at webmail.co.za> wrote:
>Hi There!
>
>I've got a linux box at home, sitting in the corner acting
>as a jukebox.  It runs a few perl scripts, mainly
>continiously playing mp3s, occasionally switching to the
>news broadcast on radio, as well as checking for the
>presence of either a CD or DVD disk in the drive, if a CD
>is present it kills the mp3/radio playback and starts cdp
>and if its a dvd, mplayer is fired up - all of the above
>works perfectly fine
>
>The box however has NO mouse, keyboard or any other input
>mechanism.  
>
>When I use cdp to play a CD I can however use the eject
>and
>skip/forward buttons on the dvd drive to eject/advance the
>playback of the cd.  
>
>With Mplayer I seemingly cannot use these two buttons, my
>biggest need is the eject button to stop the playback of a
>DVD.
>
>Is it possible to have mplayer react to input from any of
>these two buttons? Googled quite a bit but didnt find
>anything
>
>Thanks
>
>Gert
>_________________________________________________________________
>Need software for your hardware? Click here
>http://www.asg.co.za
>
>_______________________________________________
>MPlayer-users mailing list
>MPlayer-users at mplayerhq.hu
>http://mplayerhq.hu/mailman/listinfo/mplayer-users

_________________________________________________________________
Need software for your hardware? Click here http://www.asg.co.za




More information about the MPlayer-users mailing list