home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mmpm21tk.zip / TK / ULIOT / IOOPEN.C < prev    next >
C/C++ Source or Header  |  1993-04-15  |  14KB  |  310 lines

  1. /*************************START OF SPECIFICATIONS *************************/
  2. /* SOURCE FILE NAME:  IOOPEN.C                                            */
  3. /*                                                                        */
  4. /* DESCRIPTIVE NAME: File Format IO Proc routine for MMIOM_OPEN.          */
  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 open routine, and other      */
  13. /*           routines that support IOProcOpen.                            */
  14. /* NOTES:                                                                 */
  15. /*    DEPENDENCIES: none                                                  */
  16. /*    RESTRICTIONS: Runs in 32 bit protect mode (OS/2 2.0)                */
  17. /*                                                                        */
  18. /* ENTRY POINTS:                                                          */
  19. /*     IOProcOpen                                                         */
  20. /*                                                                        */
  21. /************************* END OF SPECIFICATIONS **************************/
  22.  
  23. #include        <stdio.h>
  24. #include        <string.h>
  25. #include        <stdlib.h>
  26. #include        <memory.h>
  27.  
  28. #define         INCL_DOS                        /* #define  INCL_DOSPROCESS.*/
  29. #define         INCL_ERRORS
  30. #define         INCL_WIN
  31. #define         INCL_GPI
  32. #include        <os2.h>                         /* OS/2 headers.            */
  33. #include        <pmbitmap.h>
  34.  
  35. #define         INCL_OS2MM
  36. #define         INCL_MMIO_CODEC
  37. #define         INCL_MMIO_DOSIOPROC
  38. #include        <os2me.h>                      /* Multi-Media IO extensions.*/
  39. #include        <hhpheap.h>
  40. #include        <ioi.h>
  41.  
  42.    extern HHUGEHEAP hheap;
  43.    extern HMTX hmtxGlobalHeap;
  44.  
  45. /************************** START OF SPECIFICATIONS *************************/
  46. /*                                                                          */
  47. /* SUBROUTINE NAME:  IOProcOpen                                             */
  48. /*                                                                          */
  49. /* DESCRIPTIVE NAME: open Digital Video file.                               */
  50. /*                                                                          */
  51. /* FUNCTION: This function opens digital video file, allocates instance     */
  52. /*           structure, reads header, calls file format specific open       */
  53. /*           routine to init the track information.                         */
  54. /*                                                                          */
  55. /* NOTES: None                                                              */
  56. /*                                                                          */
  57. /* ENTRY POINT: IOProcOpen                                                  */
  58. /*   LINKAGE:   CALL FAR (00:32)                                            */
  59. /*                                                                          */
  60. /* INPUT:                                                                   */
  61. /*              PMMIOINFO pmmioinfo - Pointer to MMIOINFO staus structure.  */
  62. /*              PSZ     pszFileName - Name of file to be opened.            */
  63. /*                                                                          */
  64. /* EXIT-NORMAL:                                                             */
  65. /*              MMIO_SUCCESS                                                */
  66. /*                                                                          */
  67. /* EXIT-ERROR:                                                              */
  68. /*              MMIO_ERROR                                                  */
  69. /*              MMIOERR_INVALID_ACCESS_FLAG                                 */
  70. /*              MMIOERR_OUTOFMEMORY                                         */
  71. /*              io proc specific error                                      */
  72. /*                                                                          */
  73. /* SIDE EFFECTS:                                                            */
  74. /*                                                                          */
  75. /*************************** END OF SPECIFICATIONS **************************/
  76.  
  77. LONG IOProcOpen (PMMIOINFO pmmioinfo, PSZ pszFileName) {
  78.    LONG            rc = MMIO_SUCCESS;               /* Return code.         */
  79.    LONG            lFilePosition;                   /* Logical file position*/
  80.    MMIOINFO        Localmmioinfo;                   /* For locally used.    */
  81.    PINSTANCE       pinstance;                       /* Local work structure.*/
  82.  
  83.    if (pmmioinfo == NULL) return MMIO_ERROR;
  84.  
  85.    if (CheckMem((PVOID)pmmioinfo, sizeof(MMIOINFO), PAG_WRITE))
  86.       return MMIO_ERROR;
  87.  
  88.    /**************************************************************************/
  89.    /* Validate the open flags for this File Format IO Proc                   */
  90.    /* (INVALID_OPEN_FLAGS should be defined in the ff.h - file format        */
  91.    /*  specific header file.)                                                */
  92.    /**************************************************************************/
  93.  
  94.    if (pmmioinfo->ulFlags  & INVALID_OPEN_FLAGS) {
  95.        pmmioinfo->ulErrorRet = MMIOERR_INVALID_ACCESS_FLAG;
  96.        return(MMIO_ERROR);
  97.    }
  98.  
  99.    ENTERCRITX;
  100.    if ((pinstance = (PINSTANCE)HhpAllocMem(hheap,sizeof(INSTANCE))) == NULL) {
  101.        EXITCRIT;
  102.        pmmioinfo->ulErrorRet = MMIOERR_OUTOFMEMORY;
  103.        return(MMIO_ERROR);                         /* Allocate work struct. */
  104.    }
  105.    EXITCRIT;
  106.  
  107.    pmmioinfo->pExtraInfoStruct = (PVOID) pinstance;
  108.    pmmioinfo->fccIOProc = HEX_FOURCC_FFIO;            /* Make sure this is set for codec loading */
  109.    ioInstanceInit(pinstance);
  110.  
  111.    // Validate read flags before doing read initialization
  112.  
  113.    if (( pmmioinfo->ulFlags  & MMIO_READ ) &&
  114.                 !( pmmioinfo->ulFlags & INVALID_READ_FLAGS )) {
  115.  
  116.       // IOProc identifies Storage System
  117.  
  118.       memcpy (&Localmmioinfo, pmmioinfo, sizeof(MMIOINFO));
  119.       Localmmioinfo.pIOProc = NULL;
  120.       Localmmioinfo.fccIOProc = pmmioinfo->fccChildIOProc;
  121.       Localmmioinfo.ulFlags |= MMIO_NOIDENTIFY; // Eliminate callbacks
  122.       Localmmioinfo.ulFlags &= ~MMIO_ALLOCBUF;  // Force non-buffered open
  123.  
  124.       rc = ioIdentifyStorageSystem(&Localmmioinfo,pszFileName);
  125.  
  126.       if (rc != MMIO_SUCCESS) {        /* if error,                  */
  127.          ioCleanUp(pmmioinfo);
  128.          return(rc);
  129.       }
  130.  
  131.       /****************************************************************************/
  132.       /* Allocate memory for pTempBuffer which is used when IOProcReadInterLeaved */
  133.       /* is called.                                                               */
  134.       /****************************************************************************/
  135.  
  136.       if (ENTERCRIT(rc)) {
  137.          ioCleanUp(pmmioinfo);
  138.          return(rc);
  139.       }
  140.  
  141.       if ((pinstance->pTempBuffer = HhpAllocMem(hheap, DEFAULTBUFFERSIZE)) == NULL) {
  142.          EXITCRIT;
  143.          ioCleanUp(pmmioinfo);
  144.          return(MMIOERR_OUTOFMEMORY);
  145.       }
  146.       EXITCRIT;
  147.       pinstance->ulTempBufferSize = DEFAULTBUFFERSIZE;
  148.  
  149.       /**************************************************************************/
  150.       /* Open Movie file                                                        */
  151.       /**************************************************************************/
  152.  
  153.       if ( pmmioinfo->fccChildIOProc != FOURCC_MEM ) {
  154.          Localmmioinfo.cchBuffer = 0;
  155.          Localmmioinfo.pchBuffer = NULL;
  156.       }
  157.       pinstance->hmmioFileHandle = mmioOpen(pszFileName,&Localmmioinfo,MMIO_NOIDENTIFY);
  158.       if (pinstance->hmmioFileHandle <= (HMMIO)0L) {    /* Test file open error.*/
  159.          rc = Localmmioinfo.ulErrorRet;
  160.       }
  161.  
  162.       /**************************************************************************/
  163.       /* Call file format specific open routine                                 */
  164.       /**************************************************************************/
  165.  
  166.       else if (!(rc = ffOpenRead(pmmioinfo, pinstance))) {
  167.          if(!(rc = ioAddTracksToMovieHeader(pinstance))) {
  168.  
  169.             /**************************************************************************/
  170.             /* Set lLogicalFilePos to a position pass the header block to allow       */
  171.             /* read occurring at the first byte of non-header data.                   */
  172.             /**************************************************************************/
  173.             lFilePosition = ffSeekToDataBegin(pmmioinfo,pinstance);
  174.             if (lFilePosition < MMIO_SUCCESS)
  175.                rc = MMIO_ERROR;
  176.             else
  177.                pinstance->lFileCurrentPosition = lFilePosition;
  178.          }
  179.       }
  180.  
  181.       if (rc) {
  182.          ioCleanUp(pmmioinfo);
  183.          return(rc);
  184.       }
  185.    }
  186.  
  187.    // Validate Write flags before doing initialization
  188.  
  189. #ifndef WORKSHOP
  190.  
  191.    if ((pmmioinfo->ulFlags & (MMIO_READWRITE | MMIO_WRITE)) &&
  192.                 !(pmmioinfo->ulFlags & INVALID_WRITE_FLAGS)) {
  193.  
  194.       // Open the movie file
  195.  
  196.       memset (&Localmmioinfo, '\0', sizeof(MMIOINFO));
  197.       Localmmioinfo.pIOProc   = NULL;
  198.       Localmmioinfo.fccIOProc = pmmioinfo->fccChildIOProc;
  199.  
  200.       if (pmmioinfo->fccChildIOProc != FOURCC_MEM) {
  201.          Localmmioinfo.cchBuffer = 0;
  202.          Localmmioinfo.pchBuffer = NULL;
  203.       }
  204.  
  205.       Localmmioinfo.ulFlags |= MMIO_NOIDENTIFY; // Eliminate callbacks
  206.       Localmmioinfo.ulFlags &= ~MMIO_ALLOCBUF;  // Force non-buffered open.  MMIO May do buffering.
  207.  
  208.       pinstance->hmmioFileHandle = mmioOpen(pszFileName, &Localmmioinfo,
  209.                                             MMIO_READWRITE | MMIO_NOIDENTIFY);
  210.  
  211.       if (pinstance->hmmioFileHandle <= (HMMIO)0L) // Test file open error.
  212.          rc = Localmmioinfo.ulErrorRet;
  213.       else
  214.          rc = ffOpenWrite(pmmioinfo, pinstance);   // call file format specific open routine
  215.  
  216.       if (rc != 0) {
  217.          ioCleanUp(pmmioinfo);
  218.          return(rc);
  219.       }
  220.    }
  221.  
  222. #else    // WORKSHOP next
  223.  
  224.    if ((pmmioinfo->ulFlags & (MMIO_READWRITE | MMIO_WRITE)) &&
  225.                 !(pmmioinfo->ulFlags & INVALID_WRITE_FLAGS)) {
  226.  
  227.       // Open the movie file
  228.  
  229.       memset (&Localmmioinfo, '\0', sizeof(MMIOINFO));
  230.       Localmmioinfo.pIOProc   = NULL;
  231.       Localmmioinfo.fccIOProc = pmmioinfo->fccChildIOProc;
  232.       Localmmioinfo.ulFlags  = pmmioinfo->ulFlags;
  233.       Localmmioinfo.ulFlags |= MMIO_NOIDENTIFY; // Eliminate callbacks
  234.       Localmmioinfo.ulFlags &= ~MMIO_ALLOCBUF;  // Force non-buffered open.  MMIO May do buffering.
  235.  
  236.       if (!(pmmioinfo->ulFlags & MMIO_CREATE)) {
  237.          rc = ioIdentifyStorageSystem(&Localmmioinfo, pszFileName);
  238.  
  239.          if (rc != MMIO_SUCCESS) {        // if error
  240.             pmmioinfo->ulErrorRet = rc;   // see IdentifyStorageSystem
  241.             ioCleanUp(pmmioinfo);
  242.             return(MMIO_ERROR);
  243.          }
  244.  
  245.          // Allocate memory for pTempBuffer which is used when
  246.          // IOProcReadInterLeaved is called.
  247.  
  248.          if (ENTERCRIT(rc)) {
  249.             ioCleanUp(pmmioinfo);
  250.             return MMIO_ERROR;
  251.          }
  252.  
  253.          pinstance->pTempBuffer = HhpAllocMem(hheap, DEFAULTBUFFERSIZE);
  254.          if (pinstance->pTempBuffer == NULL) {
  255.             EXITCRIT;
  256.             pmmioinfo->ulErrorRet = MMIOERR_OUTOFMEMORY;
  257.             ioCleanUp(pmmioinfo);
  258.             return MMIO_ERROR;
  259.          }
  260.          EXITCRIT;
  261.  
  262.          pinstance->ulTempBufferSize = DEFAULTBUFFERSIZE;
  263.       }
  264.  
  265.       pinstance->lFileCurrentPosition = 0;
  266.  
  267.       pinstance->hmmioFileHandle = mmioOpen(pszFileName, &Localmmioinfo, Localmmioinfo.ulFlags);
  268.  
  269.       if (pinstance->hmmioFileHandle <= (HMMIO)0L) // Test file open error.
  270.          rc = Localmmioinfo.ulErrorRet;
  271.       else {
  272.          rc = ffOpenWrite(pmmioinfo, pinstance);   // call file format specific open routine
  273.  
  274.          if (rc == 0) {
  275.             if (!(pmmioinfo->ulFlags & MMIO_CREATE)) {
  276.                rc = ioAddTracksToMovieHeader(pinstance);
  277.  
  278.                if (rc == 0) {
  279.  
  280.                   // Set lLogicalFilePos to a position pass the header block to allow
  281.                   // read occurring at the first byte of non-header data.
  282.  
  283.                   lFilePosition = ffSeekToDataBegin(pmmioinfo, pinstance);
  284.                   if (lFilePosition < MMIO_SUCCESS) rc = MMIO_ERROR;
  285.                   else pinstance->lFileCurrentPosition = lFilePosition;
  286.                }
  287.             }
  288.          }
  289.       }
  290.  
  291.       if (rc != 0) {
  292.          pmmioinfo->ulErrorRet = rc;
  293.          ioCleanUp(pmmioinfo);
  294.          return MMIO_ERROR;
  295.       }
  296.    }
  297.  
  298.    // set up the pathname in the instance structure
  299.  
  300.    if (strlen(pszFileName) < CCHMAXPATH) {
  301.       strcpy((PSZ)&(pinstance->szFileName), pszFileName);
  302.       if ((pinstance->szFileName)[1] == ':')
  303.          pinstance->ulEditFlags |= FULLY_QUALIFIED_PATH;
  304.    }
  305.  
  306. #endif
  307.  
  308.    return MMIO_SUCCESS;
  309. }
  310.