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

  1. /*************************START OF SPECIFICATIONS *************************/
  2. /* SOURCE FILE NAME:  IOSET.C                                             */
  3. /*                                                                        */
  4. /* DESCRIPTIVE NAME: File Format IO Proc routine for MMIOM_SET            */
  5. /*                                                                        */
  6. /* COPYRIGHT:     IBM - International Business Machines                   */
  7. /*            Copyright (c) IBM Corporation  1991, 1992, 1993             */
  8. /*                        All Rights Reserved                             */
  9. /*                                                                        */
  10. /* STATUS: OS/2 Release 2.0                                               */
  11. /*                                                                        */
  12. /* FUNCTION: This source module contains the set functions.               */
  13. /* NOTES:                                                                 */
  14. /*    DEPENDENCIES: none                                                  */
  15. /*    RESTRICTIONS: Runs in 32 bit protect mode (OS/2 2.0)                */
  16. /*                                                                        */
  17. /* ENTRY POINTS:                                                          */
  18. /*              IOProcSet                                                 */
  19. /*                                                                        */
  20. /* DATE      DEVELOPER   DEFECT  CHANGE DESCRIPTION           CHANGE FLAG */
  21. /* ---       ---------   ------  ------------------------     ----------- */
  22. /************************* END OF SPECIFICATIONS **************************/
  23.  
  24.  
  25. #include        <stdio.h>
  26. #include        <string.h>
  27. #include        <stdlib.h>
  28. #include        <memory.h>
  29.  
  30. #define         INCL_DOS                        /* #define  INCL_DOSPROCESS.*/
  31. #define         INCL_ERRORS
  32. #define         INCL_WIN
  33. #define         INCL_GPI
  34. #include        <os2.h>                         /* OS/2 headers.            */
  35. #include        <pmbitmap.h>
  36.  
  37. #define         INCL_OS2MM
  38. #define         INCL_MMIO_CODEC
  39. #define         INCL_MMIO_DOSIOPROC
  40.  
  41. #include        <os2me.h>                     /* Multi-Media IO extensions. */
  42. #include        <hhpheap.h>
  43. #include        <ioi.h>
  44.  
  45.  
  46. /************************** START OF SPECIFICATIONS *************************/
  47. /*                                                                          */
  48. /* SUBROUTINE NAME: IOProcSet                                               */
  49. /*                                                                          */
  50. /* DESCRIPTIVE NAME: Set various conditions in IO Proc                      */
  51. /*                                                                          */
  52. /* FUNCTION:                                                                */
  53. /*                                                                          */
  54. /* NOTES: None                                                              */
  55. /*                                                                          */
  56. /* ENTRY POINT: IOProcSet                                                   */
  57. /*   LINKAGE:   CALL FAR (00:32)                                            */
  58. /*                                                                          */
  59. /* INPUT:                                                                   */
  60. /*   PMMIOINFO             pmmioinfo          - ptr to instance structure.  */
  61. /*   LONG                  lParam1  - first parameter                       */
  62. /*   LONG                  lParam2  - Second parameter                      */
  63. /*                                                                          */
  64. /*                                                                          */
  65. /* EXIT-NORMAL:                                                             */
  66. /*              MMIO_SUCCESS                                                */
  67. /*                                                                          */
  68. /* EXIT-ERROR:                                                              */
  69. /*              MMIO_ERROR                                                  */
  70. /*                                                                          */
  71. /*                                                                          */
  72. /* SIDE EFFECTS:                                                            */
  73. /*                                                                          */
  74. /*************************** END OF SPECIFICATIONS **************************/
  75. LONG IOProcSet ( PMMIOINFO pmmioinfo,
  76.                  LONG lParam1,
  77.                  LONG lParam2 )
  78.  
  79. {
  80.    PINSTANCE      pinstance;
  81.    LONG           rc = MMIO_SUCCESS;
  82.    PMMEXTENDINFO  pmmextendinfo = (PMMEXTENDINFO)lParam1;
  83.    PCCB           pccb;
  84.    ULONG          ulCCBCount;
  85.    PCODECASSOC    pcodecassoc;
  86.    ULONG          ulSize;
  87.    PVOID          PtrNextAvail;
  88.    ULONG          ulTrack = 0;
  89.  
  90.    if (rc = ioGetPtrInstance(pmmioinfo,&pinstance))
  91.       return(rc);
  92.  
  93.    switch(lParam2){
  94.       /*************************/
  95.       /* SET INFO              */
  96.       /*************************/
  97.       case MMIO_SET_EXTENDEDINFO:   /* Set extended information */
  98.          if (pmmextendinfo) {     /* error check */
  99.  
  100.             /********************/
  101.             /* Set active track */
  102.             /********************/
  103.             if (pmmextendinfo->ulFlags & MMIO_TRACK) {
  104.  
  105.                if (pmmextendinfo->ulTrackID == (ULONG)MMIO_RESETTRACKS) {
  106.                   pinstance->lCurrentTrack = pmmextendinfo->ulTrackID;
  107.                   }
  108.                else {
  109.                   if (pinstance->ulFlags & OPENED_READONLY) {
  110.                      if (ioFindTracki(pinstance,pmmextendinfo->ulTrackID)) {
  111.                         pinstance->lCurrentTrack = pmmextendinfo->ulTrackID;
  112.                         }
  113.                      else {
  114.                         pmmioinfo->ulErrorRet = MMIOERR_INVALID_PARAMETER;
  115.                         rc = MMIO_ERROR;
  116.                         break;
  117.                         }
  118.                      }
  119.  
  120.                   else if (pinstance->ulFlags &
  121.                           (OPENED_READWRITE | OPENED_WRITECREATE)) {
  122.                      pinstance->lCurrentTrack = pmmextendinfo->ulTrackID;
  123.                      }
  124.  
  125.                   else {
  126.                      pmmioinfo->ulErrorRet = MMIOERR_INVALID_PARAMETER;
  127.                      rc = MMIO_ERROR;
  128.                      break;
  129.                      }
  130.                   } /* else */
  131.                }  /* MMIO_TRACK */
  132.  
  133.             /****************************************************************/
  134.             /* Reset all Non-normal reading modes.  All request audio and   */
  135.             /* video frames are returned.                                   */
  136.             /****************************************************************/
  137.             if (pmmextendinfo->ulFlags & MMIO_NORMAL_READ) {
  138.                pinstance->ulMode = MODE_NORMALREAD;
  139.                } /* MMIO_NORMAL_READ */
  140.  
  141.             /****************************************************************/
  142.             /* Set io proc into SCAN mode for the active track. Reading     */
  143.             /* will now be done, but only Key frames are returned for video */
  144.             /****************************************************************/
  145.             else if (pmmextendinfo->ulFlags & MMIO_SCAN_READ) {
  146.                pinstance->ulMode = MODE_SCANREAD;
  147.                } /* MMIO_SCAN_READ */
  148.  
  149.             /****************************************************************/
  150.             /* Set io proc into REVERSE mode for the active track. Reading  */
  151.             /* will now be done, but only Key frames are returned for video */
  152.             /****************************************************************/
  153.             else if (pmmextendinfo->ulFlags & MMIO_REVERSE_READ) {
  154.                pinstance->ulMode = MODE_REVERSEREAD;
  155.                } /* MMIO_REVERSE_READ */
  156.  
  157.             /****************************************************************/
  158.             /* Associate CODEC information for recording                    */
  159.             /****************************************************************/
  160.             if (pmmextendinfo->ulFlags & MMIO_CODEC_ASSOC) {
  161.                ULONG ulTempChangeTrack = FALSE;
  162.                LONG  lOldTrackID;
  163.  
  164. // This is a weak attempt at being backwards compatible so that the user
  165. // doesn't have to set the track with this call. If the MMIO_TRACK flag
  166. // is not set, the track is assumed to be 0.  This allows old code, which
  167. // didn't reset the track value to work.  (IE, the current track is 1, but
  168. // the code really is looking for track 0's codec.).  This will also work
  169. // for new code, as long as they set the track in the same call as the
  170. // query extended info or associate codec. WLS 5.31.94
  171.  
  172.                if (!(pmmextendinfo->ulFlags & MMIO_TRACK)) {
  173.                   ulTempChangeTrack = TRUE;
  174.                   lOldTrackID = pinstance->lCurrentTrack;
  175.                   pinstance->lCurrentTrack = 0;
  176.                   }
  177.  
  178.                /* Can only associate 1 CODEC at a time */
  179.                if (pmmextendinfo->ulNumCODECs != 1) {
  180.                   pmmioinfo->ulErrorRet = MMIOERR_INVALID_PARAMETER;
  181.                   rc = MMIO_ERROR;
  182.                   }
  183.                else {
  184.                   if (rc = ioAssociateCodec(pmmioinfo,
  185.                                             pinstance,
  186.                                             pmmextendinfo->pCODECAssoc,
  187.                                             FALSE)) {
  188.                      pmmioinfo->ulErrorRet = rc;
  189.                      rc = MMIO_ERROR;
  190.                      }
  191.                   }
  192.  
  193.                if (ulTempChangeTrack) {
  194.                   pinstance->lCurrentTrack = lOldTrackID;
  195.                   }
  196.  
  197.                } /* MMIO_CODEC_ASSOC */
  198.             } /* pmmextendedinfo */
  199.  
  200.          else { /* error - data structure missing */
  201.             pmmioinfo->ulErrorRet = MMIOERR_INVALID_PARAMETER;
  202.             rc = MMIO_ERROR;
  203.             }
  204.          break;
  205.  
  206.       /********************************/
  207.       /* QUERY BASE AND CODEC INFO    */
  208.       /********************************/
  209.       case MMIO_QUERY_EXTENDEDINFO_ALL: /* Query Also CODEC associated info */
  210.       /*********************************************************/
  211.       /* QUERY BASE INFO  (NOTE:Fall thru from previous case!) */
  212.       /*********************************************************/
  213.       case MMIO_QUERY_EXTENDEDINFO_BASE: /* Query only MMEXTENDINFO info */
  214.  
  215. // if there's no codec list and no pmmhdr, some has created a new file for
  216. // recording and are trying to query the extendinfo without ever setting
  217. // any header information.  These ifs will check for that condition and
  218. // return an empty structure.  If the pmmhdr is set (but a codec has not
  219. // been set for the file, the codec structures will be allocated with a
  220. // ioCheckCodecList call and the call will continue as before
  221.  
  222.          if (!pinstance->pccbList) {
  223.             if (!pinstance->pmmhdr) {
  224.                pmmextendinfo->ulStructLen = sizeof(MMEXTENDINFO);
  225.                pmmextendinfo->ulNumCODECs = 0;
  226.                pmmextendinfo->ulBufSize = 0;
  227.                return(rc);
  228.                }
  229.  
  230.             ioCheckCodecList(pinstance);
  231.             }
  232.  
  233. // This is a weak attempt at being backwards compatible so that the user
  234. // doesn't have to set the track with this call. If the MMIO_TRACK flag
  235. // is not set, the track is assumed to be 0.  This allows old code, which
  236. // didn't reset the track value to work.  (IE, the current track is 1, but
  237. // the code really is looking for track 0's codec.).  This will also work
  238. // for new code, as long as they set the track in the same call as the
  239. // query extended info or associate codec. WLS 5.31.94
  240.  
  241.          if (pmmextendinfo->ulFlags & MMIO_TRACK) {
  242.             ulTrack = pmmextendinfo->ulTrackID;
  243.             }
  244.          else {
  245.             ulTrack = 0;
  246.             }
  247.  
  248.          pmmextendinfo->ulStructLen = sizeof(MMEXTENDINFO);
  249.          pmmextendinfo->ulTrackID = (ULONG)pinstance->lCurrentTrack;
  250.  
  251.  
  252.          if (lParam2 == MMIO_QUERY_EXTENDEDINFO_ALL) {
  253.             /* Create the array of codecassoc structures to return to caller */
  254.             pcodecassoc = pmmextendinfo->pCODECAssoc;  /* Point to beginning */
  255.             for (pccb = pinstance->pccbList[ulTrack]; pccb; pccb = pccb->pccbNext) {
  256.                pcodecassoc->pCodecOpen = NULL;
  257.                pcodecassoc->pCODECIniFileInfo = NULL;
  258.                pcodecassoc++;
  259.                }
  260.             PtrNextAvail = (PVOID)pcodecassoc;
  261.  
  262.             /* Fill in pointers to the CODECIniFileInfo structures to follow */
  263.             ulSize = 0L;
  264.             pcodecassoc = pmmextendinfo->pCODECAssoc;  /* Point to beginning */
  265.             for (pccb = pinstance->pccbList[ulTrack]; pccb; pccb = pccb->pccbNext) {
  266.  
  267.                /* Create and copy CODECINIFILEINFO structure */
  268.                pcodecassoc->pCODECIniFileInfo = (PCODECINIFILEINFO)PtrNextAvail;
  269.                memcpy(pcodecassoc->pCODECIniFileInfo,&pccb->cifi,sizeof(CODECINIFILEINFO));
  270.                PtrNextAvail = (PVOID) (((ULONG)PtrNextAvail) + sizeof(CODECINIFILEINFO));
  271.  
  272.                /* Create and copy CODECOPEN structure */
  273.                pcodecassoc->pCodecOpen = PtrNextAvail;
  274.                memcpy(pcodecassoc->pCodecOpen,&pccb->codecopen,sizeof(CODECOPEN));
  275.                PtrNextAvail = (PVOID) (((ULONG)PtrNextAvail) + sizeof(CODECOPEN));
  276.  
  277.                /* Create and copy Pointers to structures in CODECOPEN structure */
  278.                if (pccb->codecopen.pControlHdr) {
  279.                   ulSize = *((PULONG)pccb->codecopen.pControlHdr);
  280.                   ((PCODECOPEN)pcodecassoc->pCodecOpen)->pControlHdr = (PVOID)PtrNextAvail;
  281.                   memcpy(((PCODECOPEN)pcodecassoc->pCodecOpen)->pControlHdr,
  282.                          pccb->codecopen.pControlHdr,
  283.                          ulSize);
  284.                   PtrNextAvail = (PVOID) (((ULONG)PtrNextAvail) + ulSize);
  285.                   }
  286.  
  287.                if (pccb->codecopen.pSrcHdr) {
  288.                   ulSize = *((PULONG)pccb->codecopen.pSrcHdr);
  289.                   ((PCODECOPEN)pcodecassoc->pCodecOpen)->pSrcHdr = PtrNextAvail;
  290.                   memcpy(((PCODECOPEN)pcodecassoc->pCodecOpen)->pSrcHdr,
  291.                          pccb->codecopen.pSrcHdr,
  292.                          ulSize);
  293.                   PtrNextAvail = (PVOID) (((ULONG)PtrNextAvail) + ulSize);
  294.                   }
  295.  
  296.                if (pccb->codecopen.pDstHdr) {
  297.                   ulSize = *((PULONG)pccb->codecopen.pDstHdr);
  298.                   ((PCODECOPEN)pcodecassoc->pCodecOpen)->pDstHdr = PtrNextAvail;
  299.                   memcpy(((PCODECOPEN)pcodecassoc->pCodecOpen)->pDstHdr,
  300.                          pccb->codecopen.pDstHdr,
  301.                          ulSize);
  302.                   PtrNextAvail = (PVOID) (((ULONG)PtrNextAvail) + ulSize);
  303.                   }
  304.  
  305.                if (pccb->codecopen.pOtherInfo) {
  306.                   ulSize = *((PULONG)pccb->codecopen.pOtherInfo);
  307.                   ((PCODECOPEN)pcodecassoc->pCodecOpen)->pOtherInfo = PtrNextAvail;
  308.                   memcpy(((PCODECOPEN)pcodecassoc->pCodecOpen)->pOtherInfo,
  309.                          pccb->codecopen.pOtherInfo,
  310.                          ulSize);
  311.                   PtrNextAvail = (PVOID) (((ULONG)PtrNextAvail) + ulSize);
  312.                   }
  313.                pcodecassoc++;
  314.                }
  315.             }
  316.  
  317.  
  318. // DO FOR QUERY_EXTENDED_INFO_BASE and QUERY_EXTENDED_INFO_ALL
  319.  
  320.  
  321.          /* Compute ulBufSize for complete information return */
  322.          ulSize = 0L;
  323.          for (pccb = pinstance->pccbList[ulTrack], ulCCBCount = 0;  /* Count CCB's */
  324.               pccb;
  325.               ulCCBCount++, pccb = pccb->pccbNext) {
  326.             ulSize += sizeof(CODECASSOC)+sizeof(CODECOPEN)+sizeof(CODECINIFILEINFO); /* static stuff */
  327.  
  328.             /* extract ulStructLen as first field of structure that ptr points to */
  329.             if (pccb->codecopen.pControlHdr) {
  330.                ulSize += *((PULONG)pccb->codecopen.pControlHdr);
  331.                }
  332.             if (pccb->codecopen.pSrcHdr) {
  333.                ulSize += *((PULONG)pccb->codecopen.pSrcHdr);
  334.                }
  335.             if (pccb->codecopen.pDstHdr) {
  336.                ulSize += *((PULONG)pccb->codecopen.pDstHdr);
  337.                }
  338.             if (pccb->codecopen.pOtherInfo) {
  339.                ulSize += *((PULONG)pccb->codecopen.pOtherInfo);
  340.                }
  341.             }
  342.  
  343.          pmmextendinfo->ulNumCODECs = ulCCBCount;
  344.          pmmextendinfo->ulBufSize = ulSize;
  345.          break;
  346.  
  347.       /*********/
  348.       /* ERROR */
  349.       /*********/
  350.       default:
  351.          pmmioinfo->ulErrorRet = MMIOERR_INVALID_PARAMETER;
  352.          rc = MMIO_ERROR;
  353.          break;
  354.       }/* end switch */
  355.  
  356.    return(rc);
  357. }
  358.