home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / mm / admct / admccap.c next >
C/C++ Source or Header  |  1999-05-11  |  14KB  |  407 lines

  1. /****************************************************************************
  2. *
  3. * SOURCE FILE NAME: ADMCCAP.C
  4. *
  5. * DESCRIPTIVE NAME: Reports device capabilities
  6. *
  7. *              Copyright (c) IBM Corporation  1991, 1993
  8. *                        All Rights Reserved
  9. *
  10. *
  11. * NOTES:  This file illustrates the following concepts:
  12. *  A. How to process the capability message commands.
  13. *      These are messages which this MCD supports (such as play, close etc.)
  14. *      Messages (or commands to the caller) such as sysinfo are
  15. *      not supported by this MCD.
  16. *  B. How to process the capability item flag.
  17. *      Items describe particular features (such as the ability to record)
  18. *      which the MCD either does or does not support.
  19. *
  20. *********************** END OF SPECIFICATIONS ********************************/
  21. #define INCL_BASE
  22. #define INCL_DOSMODULEMGR
  23. #define INCL_DOSSEMAPHORES
  24.  
  25. #include <os2.h>                        // OS2 defines.
  26. #include <string.h>                     // String functions.
  27. #include <os2medef.h>                   // MME includes files.
  28. #include <math.h>                       // Standard Math Lib
  29. #include <stdlib.h>                     // Standard Library
  30. #include <ssm.h>                        // SSM spi includes.
  31. #include <mcios2.h>                     // MM Error Messages.
  32. #include <mmioos2.h>                    // MMIO Include.
  33. #include <mmdrvos2.h>                   // MCI Driver include.
  34. #include <mcd.h>                        // AudioIFDriverInterface.
  35. #include <hhpheap.h>                    // Heap Manager Definitions
  36. #include <qos.h>
  37. #include <audiomcd.h>                   // Component Definitions.
  38. #include <admcfunc.h>
  39. #include <checkmem.h>
  40.  
  41.  
  42.  
  43. /********************* START OF SPECIFICATIONS *******************************
  44. *
  45. * SUBROUTINE NAME:              MCDCAPS
  46. *
  47. * DESCRIPTIVE NAME: Waveform Device Capabilities.
  48. *
  49. * FUNCTION: Get Waveform Device Static Capabilities.
  50. *
  51. * NOTES:
  52. *
  53. * ENTRY POINTS:
  54. *
  55. * INPUT: MCI_GETDEVCAPS message.
  56. *
  57. * EXIT-NORMAL: MCIERR_SUCCESS.
  58. *
  59. * EXIT_ERROR:  Error Code.
  60. *
  61. * EFFECTS:
  62. *
  63. * INTERNAL REFERENCES:
  64. *
  65. * EXTERNAL REFERENCES: None.
  66. *
  67. *********************** END OF SPECIFICATIONS ********************************/
  68.  
  69. RC MCICaps( FUNCTION_PARM_BLOCK *pFuncBlock )
  70. {
  71.   ULONG                  ulrc;                // MME Error Value
  72.   ULONG                  ulParam1;            // Msg Flags
  73.   INSTANCE               *ulpInstance;       // Local Instance
  74.   PMCI_GETDEVCAPS_PARMS  pParams;             // Msg Data Ptr
  75.   ULONG                  ulType;              // Msgs supported.
  76.   ULONG                  ulCapsFlags;         // Mask for Incoming MCI Flags
  77.   PMCI_WAVE_GETDEVCAPS_PARMS   pExtDevCaps;
  78.  
  79.  
  80.   /**************************************
  81.   * Derefernce Pointers.
  82.   **************************************/
  83.   ulParam1    = pFuncBlock->ulParam1;
  84.  
  85.   pParams     = ( PMCI_GETDEVCAPS_PARMS) pFuncBlock->ulParam2;
  86.  
  87.   ulpInstance = (INSTANCE *) pFuncBlock->ulpInstance;
  88.  
  89.   ulCapsFlags = ulParam1;
  90.  
  91.   /* Mask out all of the flags that we support */
  92.  
  93.   ulCapsFlags &= ~( MCI_WAIT + MCI_NOTIFY +
  94.                     MCI_GETDEVCAPS_MESSAGE + MCI_GETDEVCAPS_ITEM +
  95.                     MCI_GETDEVCAPS_EXTENDED );
  96.  
  97.   /************************************************
  98.   * If there are any other flags, they are invalid.
  99.   ************************************************/
  100.  
  101.   if (ulCapsFlags > 0 )
  102.       return ( MCIERR_INVALID_FLAG );
  103.  
  104.   /********************************************
  105.   * Check for Invalid Combination of flags
  106.   ********************************************/
  107.  
  108.   if (ulParam1 & MCI_GETDEVCAPS_ITEM && ulParam1 & MCI_GETDEVCAPS_MESSAGE)
  109.       return ( MCIERR_FLAGS_NOT_COMPATIBLE );
  110.  
  111.   /*********************************************
  112.   * Ensure that the devcaps parms that the caller
  113.   * used a valid.
  114.   *********************************************/
  115.   ulrc = CheckMem ( (PVOID)pParams,
  116.                     sizeof (MCI_GETDEVCAPS_PARMS),
  117.                     PAG_READ | PAG_WRITE );
  118.  
  119.   if (ulrc != MCIERR_SUCCESS)
  120.       return ( MCIERR_MISSING_PARAMETER );
  121.  
  122.   ulType = ulParam1 & (MCI_GETDEVCAPS_MESSAGE | MCI_GETDEVCAPS_ITEM | MCI_GETDEVCAPS_EXTENDED);
  123.  
  124.   /************************************
  125.   * The caller MUST specify either the
  126.   * devcaps message or item flags.
  127.   *************************************/
  128.  
  129.   if ( !ulType )
  130.      {
  131.      return (MCIERR_MISSING_FLAG);
  132.      }
  133.  
  134.   if ( ulType == MCI_GETDEVCAPS_MESSAGE )
  135.      {
  136.  
  137.      switch ( pParams->usMessage )
  138.        {
  139.        /*************************************************
  140.        * The MCD currently supports the messages below:
  141.        * If we support the messages return TRUE and
  142.        * a true/false return.
  143.        *************************************************/
  144.  
  145.        case MCI_RELEASEDEVICE :
  146.        case MCI_ACQUIREDEVICE :
  147.        case MCI_OPEN          :
  148.        case MCI_PLAY          :
  149.        case MCI_PAUSE         :
  150.        case MCI_SEEK          :
  151.        case MCI_RECORD        :
  152.        case MCI_CLOSE         :
  153.        case MCI_INFO          :
  154.        case MCI_GETDEVCAPS    :
  155.        case MCI_SET           :
  156.        case MCI_STATUS        :
  157.        case MCI_MASTERAUDIO   :
  158.        case MCI_CUE           :
  159.        case MCI_STOP          :
  160.        case MCI_LOAD          :
  161.        case MCI_RESUME        :
  162.        case MCI_SET_POSITION_ADVISE:
  163.        case MCI_SET_CUEPOINT  :
  164.        case MCI_CONNECTOR     :
  165.        case MCI_SET_SYNC_OFFSET:
  166.        case MCI_SAVE          :
  167.  
  168.             pParams->ulReturn = MCI_TRUE;
  169.             ulrc = MAKEULONG (ulrc, MCI_TRUE_FALSE_RETURN);
  170.            break;
  171.  
  172.        /******************************
  173.         * List Unsupported Functions
  174.        ******************************/
  175.  
  176.  
  177.       case MCI_DEVICESETTINGS:
  178.       case MCI_STEP:
  179.       case MCI_SYSINFO:
  180.       case MCI_UPDATE:
  181.       case MCI_GETTOC:
  182.       case MCI_SPIN:
  183.       case MCI_ESCAPE:
  184.            pParams->ulReturn = MCI_FALSE;
  185.            ulrc = MAKEULONG (ulrc, MCI_TRUE_FALSE_RETURN);
  186.           break;
  187.  
  188.       default:
  189.           return ( MCIERR_UNRECOGNIZED_COMMAND );
  190.  
  191.       } /* switch of message */
  192.  
  193.     } /* message flag was sent */
  194.   else if ( ulType & MCI_GETDEVCAPS_EXTENDED )
  195.     {
  196.     /*********************************************
  197.     * Ensure that the devcaps parms that the caller
  198.     * used a valid (these are wave specific).
  199.     *********************************************/
  200.     pExtDevCaps = ( PMCI_WAVE_GETDEVCAPS_PARMS ) pParams;
  201.     ulrc = CheckMem ( (PVOID)pExtDevCaps,
  202.                       sizeof (MCI_WAVE_GETDEVCAPS_PARMS ),
  203.                       PAG_READ | PAG_WRITE );
  204.  
  205.     if (ulrc != MCIERR_SUCCESS)
  206.         return ( MCIERR_MISSING_PARAMETER );
  207.  
  208.     /*********************************************
  209.     * Determine if the connection network supports
  210.     * the mode the caller wants to query.
  211.     *********************************************/
  212.  
  213.     ulrc = TestNetwork( ulpInstance, pExtDevCaps );
  214.  
  215.  
  216. // 6421--can't call VSD directly--how am I supposed to get this info??????
  217. // solved: try the test connection call and look to see if it succeeds.
  218.  
  219. //    ulHoldOperation = ulpInstance->ulOperation;
  220. // 6421--when operation_play is gone--so will the if/else statements
  221.  
  222. //    if ( pExtDevCaps->ulFormatMode == MCI_PLAY )
  223. //       {
  224. //       ulpInstance->ulOperation = OPERATION_PLAY;
  225. //       }
  226. //    else
  227. //       {
  228. ////       ulpInstance->ulOperation = OPERATION_RECORD;
  229. //       }
  230. //   /* Call generic routine to fill ssm parms for test_connection call */
  231. //
  232. //   PackSSMStruct(ulpInstance, &mssm );
  233. //
  234. //   /* Setup the caller's parameters in the test connection spcb */
  235. //
  236. //   spcbkey.ulDataType    =  pExtDevCaps->ulFormatTag ;
  237. //   spcbkey.ulDataType    += ( pExtDevCaps->ulChannels << 16);
  238. //   spcbkey.ulDataType    += (pExtDevCaps->ulBitsPerSample << 19);
  239. //   spcbkey.ulDataSubType =  pExtDevCaps->ulSamplesPerSec;
  240. //
  241. //   mssm.pspcbkey = &spcbkey;
  242. //
  243. //   mconn.ulConnectionScheme = MCI_SSM_CONNECTION;
  244. //   mconn.ulConnectionInfo = ( ULONG ) &mssm;
  245. //
  246.  
  247. //    ulrc = ulpInstance->pfnVSD ( &MIX,
  248. //                                 MCI_GETDEVCAPS,
  249. //                                 pParams->ulItem,
  250. //                                 (LONG)  &pExtDevCaps,
  251. //                                 0L);
  252.  
  253. //   ulrc = mciSendCommand ( ulpInstance->usAmpDeviceID,
  254. //                           MCI_TEMPCONNECTION,
  255. //                           MCI_WAIT | MCI_TEST_CONNECTION,
  256. //                           (PVOID) &mconn,
  257. //                           0 );
  258.  
  259.     /* Restore value as before */
  260.  
  261. //    ulpInstance->ulOperation = ulHoldOperation;
  262.     pExtDevCaps->ulReturn = !( ulrc) ;
  263.  
  264.     if ( !ulrc )
  265.        {
  266.        ulrc = MAKEULONG (ulrc, MCI_TRUE_FALSE_RETURN);
  267.        }
  268.  
  269.     return ( ulrc );
  270.  
  271.     } /* extended devcaps */
  272.  
  273.  
  274.   else /* if ( ulType == MCI_GETDEVCAPS_ITEM ) */
  275.  
  276.     {
  277.        switch (pParams->ulItem)
  278.        {
  279.  
  280.        case MCI_GETDEVCAPS_DEVICE_TYPE:
  281.             pParams->ulReturn = MCI_DEVTYPE_WAVEFORM_AUDIO;
  282.             ulrc = MAKEULONG (ulrc, MCI_DEVICENAME_RETURN);
  283.             break;
  284. // CONNECTION FEATURE--ask if network can stream
  285.        case MCI_GETDEVCAPS_CAN_PLAY:
  286.             {
  287.  
  288.             pParams->ulReturn = !(CanPlayRecord( ulpInstance, MCIDRV_CONNECT_TARGET ));
  289.             ulrc = MAKEULONG (ulrc, MCI_TRUE_FALSE_RETURN);
  290.             }
  291.             break;
  292. // CONNECTION FEATURE
  293.        case MCI_GETDEVCAPS_CAN_RECORD:
  294.              /***************************************
  295.              * When we loaded the file, we found out
  296.              * from the IO proc if it has the ability
  297.              * to record so examine this flag.
  298.              ****************************************/
  299. // CONNECTION FEATURE--can I pass direction via call????
  300.  
  301.              if (ulpInstance->ulCapabilities & CAN_RECORD)
  302.                  {
  303. //// 6421--retrive value from init majic.
  304.                  /***********************************************
  305.                  * When the MCI driver connected, it was informed
  306.                  * of the playback/record capabilities of the
  307.                  * connected MCI driver.  Simply return this info.
  308.                  ********************************************** */
  309. //                 pParams->ulReturn = ulpInstance->fCanStreamFrom;
  310. // conn feature--undefined function
  311.  
  312.                  pParams->ulReturn = !(CanPlayRecord( ulpInstance, MCIDRV_CONNECT_SOURCE ));
  313. //                 ulrc = ulpInstance->pfnVSD ( &MIX,
  314. //                                              MCI_GETDEVCAPS,
  315. //                                              pParams->ulItem,
  316. //                                              (LONG)  &pParams->ulReturn,
  317. //                                              0 );
  318.  
  319.                  }
  320.              else
  321.                  {
  322.                  pParams->ulReturn = MCI_FALSE;
  323.                  }
  324.             ulrc = MAKEULONG (ulrc, MCI_TRUE_FALSE_RETURN);
  325.             break;
  326.  
  327.        case MCI_GETDEVCAPS_CAN_SETVOLUME:
  328.            {
  329. #ifdef CONNECTION
  330.            ulrc = FindAmp( ulpInstance );
  331.            if ( ulrc )
  332.               {
  333.               return ( ulrc );
  334.               }
  335. #endif
  336.            ulrc = mciSendCommand ( ulpInstance->usAmpDeviceID,
  337.                                    MCI_GETDEVCAPS,
  338.                                    ulParam1,
  339.                                    (PVOID) pParams,
  340.                                    pFuncBlock->usUserParm);
  341.            }
  342.  
  343. //            ulrc = MAKEULONG (ulrc, MCI_TRUE_FALSE_RETURN);
  344.  
  345.        break;
  346.  
  347.        /* We have the following static capabilities */
  348.  
  349.        case MCI_GETDEVCAPS_HAS_AUDIO:
  350.        case MCI_GETDEVCAPS_USES_FILES:
  351.        case MCI_GETDEVCAPS_CAN_STREAM:
  352.             pParams->ulReturn = MCI_TRUE;
  353.             ulrc = MAKEULONG (ulrc, MCI_TRUE_FALSE_RETURN);
  354.             break;
  355.  
  356.        case MCI_GETDEVCAPS_HAS_VIDEO:
  357.        case MCI_GETDEVCAPS_CAN_EJECT:
  358.        case MCI_GETDEVCAPS_CAN_PROCESS_INTERNAL:
  359.        case MCI_GETDEVCAPS_CAN_LOCKEJECT:
  360.             pParams->ulReturn = MCI_FALSE;
  361.             ulrc = MAKEULONG (ulrc, MCI_TRUE_FALSE_RETURN);
  362.             break;
  363.  
  364.        case MCI_GETDEVCAPS_CAN_SAVE:
  365.              /***************************************
  366.              * When we loaded the file, we found out
  367.              * from the IO proc if it has the ability
  368.              * to save so examine this flag.
  369.              ****************************************/
  370.              pParams->ulReturn = (ulpInstance->ulCapabilities & CAN_SAVE) ? 1 : 0;
  371.  
  372.              ulrc = MAKEULONG (ulrc, MCI_TRUE_FALSE_RETURN);
  373.              break;
  374.  
  375.        case MCI_GETDEVCAPS_CAN_RECORD_INSERT:
  376.              /***************************************
  377.              * When we loaded the file, we found out
  378.              * from the IO proc if it has the ability
  379.              * to save so examine this flag.
  380.              ****************************************/
  381.              pParams->ulReturn = (ulpInstance->ulCapabilities & CAN_INSERT) ? 1 : 0;
  382.  
  383.              ulrc = MAKEULONG (ulrc, MCI_TRUE_FALSE_RETURN);
  384.              break;
  385.  
  386.        case MCI_GETDEVCAPS_PREROLL_TYPE:
  387.             pParams->ulReturn = MCI_PREROLL_NOTIFIED;
  388.             ulrc = MAKEULONG (ulrc, MCI_PREROLL_TYPE_RETURN );
  389.             break;
  390.  
  391.        case MCI_GETDEVCAPS_PREROLL_TIME:
  392.             pParams->ulReturn = 0;
  393.             ulrc = MAKEULONG (ulrc, MCI_INTEGER_RETURNED);
  394.             break;
  395.  
  396.        default:
  397.             return ( MCIERR_UNSUPPORTED_FLAG );
  398.  
  399.        } /* items of item */
  400.  
  401.     } /* GETDEVCAPS item flag passed */
  402.   return (ulrc);
  403.  
  404. } /* MCICaps */
  405.  
  406.  
  407.