home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / TOOLKIT / MM / ULTIMOIO / IOCLOSE.C < prev    next >
C/C++ Source or Header  |  1994-11-17  |  10KB  |  234 lines

  1. /*************************START OF SPECIFICATIONS *************************/
  2. /* SOURCE FILE NAME:  IOCLOSE.C                                           */
  3. /*                                                                        */
  4. /* DESCRIPTIVE NAME: File Format IO Proc routine for MMIOM_CLOSE          */
  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 close routine.               */
  13. /*                                                                        */
  14. /* NOTES:                                                                 */
  15. /*    DEPENDENCIES: none                                                  */
  16. /*    RESTRICTIONS: Runs in 32 bit protect mode (OS/2 2.0)                */
  17. /*                                                                        */
  18. /* ENTRY POINTS:                                                          */
  19. /*      IOProcClose                                                       */
  20. /*      ioCleanUp                                                         */
  21. /*                                                                        */
  22. /************************* END OF SPECIFICATIONS **************************/
  23.  
  24. #define         INCL_DOS                        /* #define  INCL_DOSPROCESS.*/
  25. #define         INCL_ERRORS
  26. #define         INCL_WIN
  27. #define         INCL_GPI
  28. #include        <os2.h>                         /* OS/2 headers.*/
  29. #include        <pmbitmap.h>
  30.  
  31. #define         INCL_OS2MM
  32. #define         INCL_MMIO_CODEC
  33. #define         INCL_MMIO_DOSIOPROC
  34. #include        <os2me.h>                       /* Multi-Media IO extensions.*/
  35. #include        <hhpheap.h>
  36. #include        <ioi.h>
  37.  
  38.    extern HHUGEHEAP hheap;
  39.    extern HMTX hmtxGlobalHeap;
  40.  
  41. /************************** START OF SPECIFICATIONS *************************/
  42. /*                                                                          */
  43. /* SUBROUTINE NAME:  IOProcClose                                            */
  44. /*                                                                          */
  45. /* DESCRIPTIVE NAME: close file.                                            */
  46. /*                                                                          */
  47. /* FUNCTION: This function closes Digital Video file if opened,             */
  48. /*           free allocated buffers.                                        */
  49. /*                                                                          */
  50. /* NOTES: None                                                              */
  51. /*                                                                          */
  52. /* ENTRY POINT: IOProcClose                                                 */
  53. /*   LINKAGE:   CALL FAR (00:32)                                            */
  54. /*                                                                          */
  55. /* INPUT:    PMMIOINFO  pmmioinfo - pointer to MMIOINFO instance structure. */
  56. /*                                                                          */
  57. /*                                                                          */
  58. /* EXIT-NORMAL:                                                             */
  59. /*              MMIO_SUCCESS                                                */
  60. /*                                                                          */
  61. /* EXIT-ERROR:                                                              */
  62. /*              MMIO_ERROR                                                  */
  63. /*                                                                          */
  64. /* SIDE EFFECTS:                                                            */
  65. /*                                                                          */
  66. /*************************** END OF SPECIFICATIONS **************************/
  67.  
  68. LONG IOProcClose(PMMIOINFO pmmioinfo) {
  69.    LONG rc;
  70.    PINSTANCE  pinstance;
  71.  
  72.    if (rc = ioGetPtrInstance(pmmioinfo,&pinstance))
  73.       return(rc);
  74.  
  75.    pmmioinfo->ulErrorRet = 0L;
  76.  
  77.    ioCleanUp(pmmioinfo); /* mmioClose is called in CleanUp */
  78.  
  79.    if (pmmioinfo->ulErrorRet != 0L) return MMIO_ERROR;
  80.  
  81.    return MMIO_SUCCESS;
  82. }
  83.  
  84. /************************** START OF SPECIFICATIONS *************************/
  85. /*                                                                          */
  86. /* SUBROUTINE NAME: ioCleanUp                                               */
  87. /*                                                                          */
  88. /* DESCRIPTIVE NAME: Clean up on error or before closing file.              */
  89. /*                                                                          */
  90. /* FUNCTION: Close any open file and free allocated instance control        */
  91. /*           blocks and any temporary buffers created.                      */
  92. /*                                                                          */
  93. /* NOTES: None                                                              */
  94. /*                                                                          */
  95. /* ENTRY POINT: ioCleanUp                                                   */
  96. /*   LINKAGE:   CALL FAR (00:32)                                            */
  97. /*                                                                          */
  98. /* INPUT:                                                                   */
  99. /*              PMMIOINFO pmmioinfo - pointer to MMIOINFO status structure. */
  100. /*                                                                          */
  101. /* EXIT-NORMAL:                                                             */
  102. /*              (none)                                                      */
  103. /*                                                                          */
  104. /* EXIT-ERROR:                                                              */
  105. /*              (none)                                                      */
  106. /*                                                                          */
  107. /* SIDE EFFECTS:                                                            */
  108. /*                                                                          */
  109. /*************************** END OF SPECIFICATIONS **************************/
  110.  
  111. VOID ioCleanUp(PMMIOINFO pmmioinfo) {
  112.    LONG            rc;              /* Return code.           */
  113.    PINSTANCE       pinstance;       /* Local work structure.  */
  114.    PTRACKI         ptracki;         /* Pointer to track list. */
  115.    PCCB            pccb;            /* Pointer to CCB list.   */
  116.    PMMVIDEOHEADER  pmmVideoHdr;     /* Video header node.     */
  117.    ULONG           ulTrack;
  118.  
  119.    // Make sure the instant structure has been allocated, no memory need to
  120.    // be freed otherwise
  121.  
  122.    if (pmmioinfo->pExtraInfoStruct) {
  123.       pinstance = (PINSTANCE)pmmioinfo->pExtraInfoStruct;
  124.       if (!pinstance) {
  125.          pmmioinfo->ulErrorRet |= MMIOERR_INVALID_STRUCTURE;
  126.          return;
  127.       }
  128.    }
  129.    else {
  130.       pmmioinfo->ulErrorRet |= MMIOERR_INVALID_STRUCTURE;
  131.       return;
  132.    }
  133.  
  134.    // Call File Format specific clean up routine
  135.  
  136.    ffCleanUp(pinstance);
  137.  
  138.    // If file is opened, close it
  139.  
  140.    if (pinstance->hmmioFileHandle) {
  141.       rc = (LONG)mmioClose(pinstance->hmmioFileHandle,(WORD)0L);
  142.  
  143.       if (rc != MMIO_SUCCESS) pmmioinfo->ulErrorRet = rc;
  144.  
  145.       pinstance->hmmioFileHandle = 0;
  146.    }
  147.  
  148.    pmmioinfo->hmmio = 0L;
  149.  
  150.    if (ENTERCRIT(rc)) return;
  151.  
  152.    // Free pTempBuffer in instant structure
  153.  
  154.    if(pinstance->pTempBuffer) {
  155.       HhpFreeMem(hheap,pinstance->pTempBuffer);
  156.       pinstance->pTempBuffer = NULL;
  157.    }
  158.  
  159.    // pccbList is a link list, CleanUp free every node of link list
  160.  
  161. //
  162. // pccbList is an array of link list for each track in the file.
  163. // WLS 3.15.94
  164. //
  165.  
  166.    if (pinstance->pccbList) {
  167.       for (ulTrack = 0; ulTrack < pinstance->pmmhdr->ulNumEntries; ulTrack++) {
  168.          while (pinstance->pccbList[ulTrack]) {
  169.             pccb = pinstance->pccbList[ulTrack];
  170.             if (pccb) {
  171.                pinstance->pccbList[ulTrack] = pccb->pccbNext;
  172.                ioCloseCodec(pccb);
  173.             }
  174.          }
  175.       }
  176.       HhpFreeMem(hheap, pinstance->pccbList);
  177.    }
  178.  
  179.    if (pinstance->pccbLastUsed) {
  180.       HhpFreeMem(hheap, pinstance->pccbLastUsed);
  181.    }
  182.  
  183.  
  184.    // ptrackiList is a link list, CleanUp free every node of link list
  185.  
  186.    while (pinstance->ptrackiList) {
  187.       ptracki = pinstance->ptrackiList;
  188.  
  189.       if (ptracki) {
  190.  
  191.          if (ptracki->pTrackHeader) {
  192.  
  193.             // Delete movie video track specific data
  194.  
  195.             if (IS_VIDEO_TRACK(ptracki->ulMediaType)) {
  196.                pmmVideoHdr = (PMMVIDEOHEADER)ptracki->pTrackHeader;
  197.  
  198.                if (pmmVideoHdr->pmmXDIBHeader)
  199.                   HhpFreeMem(hheap,(PVOID)pmmVideoHdr->pmmXDIBHeader);
  200.  
  201.                if (pmmVideoHdr->genpalVideo.prgb2Entries)
  202.                   HhpFreeMem(hheap,(PVOID)pmmVideoHdr->genpalVideo.prgb2Entries);
  203.  
  204.             }
  205.  
  206.             HhpFreeMem(hheap,(PVOID)ptracki->pTrackHeader);
  207.          }
  208.  
  209.          if (ptracki->pRawHdr) HhpFreeMem(hheap,(PVOID)ptracki->pRawHdr);
  210.  
  211.          pinstance->ptrackiList = ptracki->ptrackiNext;
  212.          HhpFreeMem(hheap,(PVOID)ptracki);
  213.       }
  214.    }
  215.  
  216.    if (pinstance->pRawHdr) {
  217.       HhpFreeMem(hheap,(PVOID) pinstance->pRawHdr);       /* Free header */
  218.       pinstance->pRawHdr = NULL;
  219.    }
  220.  
  221.    if (pinstance->pmmhdr) {
  222.       HhpFreeMem(hheap, (PVOID)pinstance->pmmhdr);        /* Free header */
  223.       pinstance->pmmhdr = NULL;
  224.    }
  225.  
  226. #ifndef CANT_EDIT
  227.    ioEditCleanup(pinstance);                 // free clipboard editing control blocks
  228. #endif
  229.  
  230.    HhpFreeMem(hheap, (PVOID)pinstance);      // Free instance structure
  231.    pmmioinfo->pExtraInfoStruct = (PVOID)NULL;
  232.    EXITCRIT;
  233. }
  234.