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

  1. /********************* START OF SPECIFICATIONS *********************
  2. *
  3. * SUBROUTINE NAME: MCISEEK.C
  4. *
  5. * DESCRIPTIVE
  6. *
  7. *
  8. *              Copyright (c) IBM Corporation  1991, 1993
  9. *                        All Rights Reserved
  10. *
  11. *
  12. * FUNCTION:  Waveform Seek.
  13. *
  14. *  On a seek, a streaming MCD should perform the following commands:
  15. *
  16. *  A. Verify that the flags passed are valid.
  17. *  B. Verify the MCI_FROM, MCI_TO parameter if they were passed in.
  18. *  C. Ensure that any pointers passed are valid.
  19. *  D. Stop any commands which are active on another thread.
  20. *  E. If no stream has been created, then create one.
  21. *  F. If a stream had previously been created, ensure that it is in
  22. *     stopped state.
  23. *
  24. * NOTES:
  25. *
  26. * ENTRY POINTS:
  27. *
  28. * INPUT: MCI_SEEK message.
  29. *
  30. * EXIT-NORMAL: MCIERR_SUCCESS.
  31. *
  32. * EXIT_ERROR:  Error Code.
  33. *
  34. * EFFECTS:
  35. *
  36. * INTERNAL REFERENCES: MCIERR ().
  37. *
  38. * EXTERNAL REFERENCES: spiStopStream()     - SSM Spi
  39. *                      spiSeekStream()     - SSM Spi
  40. *
  41. *********************** END OF SPECIFICATIONS **********************/
  42.  
  43.  
  44. #define INCL_DOSSEMAPHORES
  45. #define INCL_DOSPROCESS
  46. #define INCL_ERRORS
  47.  
  48. #include <os2.h>                        // OS2 defines.
  49. #include <string.h>                     // String functions.
  50. #include <os2medef.h>                   // MME includes files.
  51. #include <ssm.h>                        // SSM spi includes.
  52. #include <mcios2.h>                     // MM Error Messages.
  53. #include <mmioos2.h>                    // MMIO Include.
  54. #include <mmdrvos2.h>                     // MCI Driver Include.
  55. #include <mcd.h>                        // AudioIFDriverInterface.
  56. #include <qos.h>
  57. #include <hhpheap.h>                    // Heap Manager Definitions
  58. #include <audiomcd.h>                   // Component Definitions
  59. #include "admcfunc.h"                   // Function Prototypes
  60. #include <checkmem.h>
  61.  
  62.  
  63. RC MCISeek (FUNCTION_PARM_BLOCK *pFuncBlock)
  64.  
  65. {
  66.   ULONG         ulrc;                    // Return Code
  67.   ULONG         ulParam1;                // Flags For this message
  68.   ULONG         ulAbortNotify = FALSE;   // abort notification messages
  69.   ULONG         ulCnt;                    // Semaphore Post Count
  70.   ULONG         ulTemp1;                 // Temporary Variable
  71.   ULONG         ulSpiFlags = 0L;           // Flags For Spi Seek
  72.   ULONG         ulSeekFlags;             // Incoming Seek Flags From MCI
  73.   ULONG         ulFileLength;            // Element Length in MM
  74.  
  75.   PMCI_SEEK_PARMS pSeekParms;
  76.  
  77.   INSTANCE      * ulpInstance;           // Local Instance Ptr
  78.  
  79.   /********************************************
  80.   * Dereference Pointers From Thread Block
  81.   ********************************************/
  82.  
  83.   ulParam1 = pFuncBlock->ulParam1;
  84.   pSeekParms = ( PMCI_SEEK_PARMS ) pFuncBlock->ulParam2;
  85.  
  86.   /*******************************************
  87.   * Mask Wait and Notify Bits
  88.   ********************************************/
  89.  
  90.   ulParam1 &= ~( MCI_NOTIFY + MCI_WAIT);
  91.   ulSeekFlags = ulParam1;
  92.  
  93.   /********************************************
  94.   * Mask For Valid Flags on MCI_SEEK
  95.   *********************************************/
  96.  
  97.   ulSeekFlags &= ~(MCI_TO + MCI_TO_START + MCI_TO_END);
  98.  
  99.   /* If any excess flags are passed in, return an error */
  100.  
  101.   if (ulSeekFlags > 0)
  102.       return (MCIERR_INVALID_FLAG);
  103.  
  104.   /* We cannot seek in two different directions at once */
  105.  
  106.   if ( ( ulParam1 & MCI_TO_START && ulParam1 & MCI_TO_END ) ||
  107.        ( ulParam1 & MCI_TO_START && ulParam1 & MCI_TO     ) ||
  108.        ( ulParam1 & MCI_TO && ulParam1 & MCI_TO_END ) )
  109.      {
  110.      return (MCIERR_FLAGS_NOT_COMPATIBLE);
  111.      }
  112.  
  113.   /******************************************
  114.   * We MUST be able to seek to some point in
  115.   * the file, thus to, to end or to start
  116.   * must be passed in.
  117.   *******************************************/
  118.  
  119.   if ( !( ulParam1 & MCI_TO_START ||
  120.           ulParam1 & MCI_TO_END   ||
  121.           ulParam1 & MCI_TO))
  122.  
  123.       return (MCIERR_MISSING_FLAG);
  124.  
  125.   ulpInstance= (INSTANCE *)pFuncBlock->ulpInstance;
  126.  
  127.  
  128.   /*************************************************
  129.   ** If the to parameter was sent, then the caller
  130.   ** is required to pass in the seek parms struct
  131.   ** so ensure that the memory is valid
  132.   **************************************************/
  133.  
  134.   if (ulParam1 & MCI_TO)
  135.      {
  136.      ulrc = CheckMem ( (PVOID) pSeekParms,
  137.                        sizeof (MCI_SEEK_PARMS),
  138.                        PAG_READ);
  139.  
  140.      if (ulrc != MCIERR_SUCCESS)
  141.         {
  142.         return (MCIERR_MISSING_PARAMETER);
  143.         }
  144.  
  145.      }
  146.  
  147.   /************************************
  148.   * If a file has not been opened, then
  149.   * a seek is not possible
  150.   *************************************/
  151.  
  152.   // change to ulFile + only use TRUE/FALSE for variable
  153.  
  154.   if ( ulpInstance->fFileExists == FALSE )
  155.      {
  156.      return (MCIERR_FILE_NOT_FOUND);
  157.      }
  158.  
  159.   /*********************************************
  160.   * MCI_SEEK aborts any ongoing PLAY/RECORD.
  161.   * ensure that the play/record threads can be
  162.   * aborted by acquire a semaphore and then
  163.   * post the aborted message
  164.   *********************************************/
  165.  
  166.   GetNotifyAbortAccess ( ulpInstance, &ulAbortNotify );
  167.  
  168.   if ( ulAbortNotify )
  169.      {
  170.      /* Stop the command on another thread */
  171.  
  172.      GenericThreadAbort( ulpInstance, pFuncBlock, 0  );
  173.  
  174.      }  /* There was a pending Notify */
  175.  
  176.  
  177.   /***********************************************
  178.   * If a set was performed on an existing stream,
  179.   * destroy the stream and get new spcb keys
  180.   ***********************************************/
  181.  
  182.   DestroySetStream ( ulpInstance );
  183.  
  184.  
  185.  
  186.   /*******************************************
  187.   * In order to perform a seek, a stream must
  188.   * exist.  If it does not exist, create one.
  189.   ********************************************/
  190.  
  191.   if (ulpInstance->ulCreateFlag != PREROLL_STATE)
  192.     {
  193.     /*******************************
  194.     * Do stream set up work and then
  195.     * create the stream
  196.     *******************************/
  197.  
  198.  
  199.     ulrc = PrepareAndCreateStream( ulpInstance, ulpInstance->ulOperation, TRUE );
  200.  
  201.     if ( ulrc )
  202.        {
  203.        return ( ulrc );
  204.        }
  205.  
  206.     /******************************
  207.     * UpDate State to created
  208.     *******************************/
  209.  
  210.     ulpInstance->ulCreateFlag = PREROLL_STATE;
  211.  
  212.     }  /* Stream Creation */
  213.  
  214.   /*right now, we do a brute stop always, should
  215.   *  only do it if we are not in stopped state.*/
  216.  
  217.   DosResetEventSem (ulpInstance->hEventSem, &ulCnt);
  218.  
  219.   ulrc = ADMCStopStream (ulpInstance, SPI_STOP_DISCARD);
  220.  
  221.   if ( !ulrc )
  222.      {
  223.      DosWaitEventSem (ulpInstance->hEventSem, (ULONG) -1);
  224.      }
  225.  
  226.   /*************************************************
  227.   * Stream Seek.  Note, since we can not be sure how
  228.   * long a playlist is, do not bother to check the
  229.   * length
  230.   *************************************************/
  231.  
  232.   if (ulpInstance->usPlayLstStrm != TRUE)
  233.      {
  234.  
  235.      if (ulParam1 & MCI_TO)
  236.         {
  237.         /*
  238.         ** Convert whatever time format we are currently
  239.         ** in to mmtime
  240.         */
  241.  
  242.         ConvertTimeUnits ( ulpInstance,
  243.                            &ulFileLength,
  244.                            FILE_LENGTH );
  245.  
  246.         /*-------------------------------------------------
  247.         ** If the caller wants to seek past the end of the
  248.         ** file refuse the request
  249.         --------------------------------------------------*/
  250.  
  251.         ulTemp1 = pSeekParms->ulTo;
  252.  
  253.         if (ulTemp1 > ulFileLength)
  254.             return (MCIERR_OUTOFRANGE);
  255.  
  256.         } /* To Flag On */
  257.  
  258.      } /* Non PlayList */
  259.  
  260.   /********************************************************
  261.   * Parse Different Seek Flags to Translate into ulSpiFlags
  262.   ********************************************************/
  263.  
  264.   if (ulParam1 & MCI_TO_START)
  265.      {
  266.      ulTemp1 = 0;
  267.      ulSpiFlags = SPI_SEEK_ABSOLUTE;
  268.      }
  269.  
  270.   if (ulParam1 & MCI_TO_END)
  271.      {
  272.      ulTemp1 = 0;
  273.      ulSpiFlags = SPI_SEEK_FROMEND;
  274.      }
  275.  
  276.   if (ulParam1 & MCI_TO)
  277.      {
  278.      ulSpiFlags = SPI_SEEK_ABSOLUTE;
  279.      }
  280.  
  281.    /*********************************************
  282.    * Convert Seek Units to MMTime
  283.    * This translates Stream Seek units to MMTIME
  284.    * ONLY if the user requested a number
  285.    *********************************************/
  286.    if ( pSeekParms && ( ulParam1 & MCI_TO ) )
  287.       {
  288.       ConvertToMM ( ulpInstance,
  289.                     &ulTemp1,
  290.                     pSeekParms->ulTo);
  291.       }
  292.  
  293.   /* Do the seek */
  294.  
  295.   ulrc = ADMCSeekStream ( ulpInstance,
  296.                          ulSpiFlags,
  297.                          (LONG) ulTemp1);
  298.  
  299.   /**************************************************
  300.   * Update the stream state so that other routines
  301.   * such as status, play, record can take appropriate
  302.   * actions
  303.   **************************************************/
  304.  
  305.   STRMSTATE = MCI_STOP;
  306.  
  307.   return (ulrc);
  308.  
  309. } /* MCISeek */
  310.  
  311.