home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / mm / ultimoio / ioopen.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  11KB  |  260 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. /*                                                                        */
  17. /* ENTRY POINTS:                                                          */
  18. /*     IOProcOpen                                                         */
  19. /*                                                                        */
  20. /************************* END OF SPECIFICATIONS **************************/
  21.  
  22. #define         INCL_DOS
  23. #define         INCL_DOSPROCESS
  24. #define         INCL_DOSDATETIME
  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. #define         INCL_DBCSCRT
  37. #include        <mmiocrt.h>
  38. #include        <ioi.h>
  39.  
  40.    extern HHUGEHEAP hheap;
  41.    extern HMTX hmtxGlobalHeap;
  42.  
  43. /************************** START OF SPECIFICATIONS *************************/
  44. /*                                                                          */
  45. /* SUBROUTINE NAME:  IOProcOpen                                             */
  46. /*                                                                          */
  47. /* DESCRIPTIVE NAME: open Digital Video file.                               */
  48. /*                                                                          */
  49. /* FUNCTION: This function opens digital video file, allocates instance     */
  50. /*           structure, reads header, calls file format specific open       */
  51. /*           routine to init the track information.                         */
  52. /*                                                                          */
  53. /* NOTES: None                                                              */
  54. /*                                                                          */
  55. /* ENTRY POINT: IOProcOpen                                                  */
  56. /*   LINKAGE:   CALL FAR (00:32)                                            */
  57. /*                                                                          */
  58. /* INPUT:                                                                   */
  59. /*              PMMIOINFO pmmioinfo - Pointer to MMIOINFO staus structure.  */
  60. /*              PSZ     pszFileName - Name of file to be opened.            */
  61. /*                                                                          */
  62. /* EXIT-NORMAL:                                                             */
  63. /*              MMIO_SUCCESS                                                */
  64. /*                                                                          */
  65. /* EXIT-ERROR:                                                              */
  66. /*              MMIO_ERROR                                                  */
  67. /*              MMIOERR_INVALID_ACCESS_FLAG                                 */
  68. /*              MMIOERR_OUTOFMEMORY                                         */
  69. /*              io proc specific error                                      */
  70. /*                                                                          */
  71. /* SIDE EFFECTS:                                                            */
  72. /*                                                                          */
  73. /*************************** END OF SPECIFICATIONS **************************/
  74.  
  75. LONG IOProcOpen (PMMIOINFO pmmioinfo, PSZ pszFileName) {
  76.    LONG            rc = MMIO_SUCCESS, openType = -1;
  77.    LONG            lFilePosition;         // Logical file position
  78.    MMIOINFO        Localmmioinfo;         // Locally used
  79.    PINSTANCE       pinstance;
  80.    PTIB            ptib;                  // thread info block
  81.    PPIB            ppib;                  // process info block
  82.  
  83.    if (pmmioinfo == NULL) return MMIO_ERROR;
  84.  
  85.    if (CheckMem((PVOID)pmmioinfo, sizeof(MMIOINFO), PAG_WRITE))
  86.       return MMIO_ERROR;
  87.  
  88.    // Validate the open flags for this File Format IO Proc
  89.    // INVALID_OPEN_FLAGS must be defined in the ff.h - file format
  90.    // specific header file
  91.  
  92.    if (pmmioinfo->ulFlags  & INVALID_OPEN_FLAGS) {
  93.        pmmioinfo->ulErrorRet = MMIOERR_INVALID_ACCESS_FLAG;
  94.        return MMIOERR_INVALID_ACCESS_FLAG;
  95. //     return MMIO_ERROR;
  96.    }
  97.  
  98.    // Allocate local instance structure
  99.  
  100.    ENTERCRITX;
  101.    if ((pinstance = (PINSTANCE)HhpAllocMem(hheap,sizeof(INSTANCE))) == NULL) {
  102.        EXITCRIT;
  103.        pmmioinfo->ulErrorRet = MMIOERR_OUTOFMEMORY;
  104.        return MMIOERR_OUTOFMEMORY;
  105. //     return MMIO_ERROR;
  106.    }
  107.    EXITCRIT;
  108.  
  109.    pmmioinfo->pExtraInfoStruct = (PVOID)pinstance;    // save it's address
  110.    pmmioinfo->fccIOProc = HEX_FOURCC_FFIO;            // Make sure this is set for codec loading
  111.    ioInstanceInit(pinstance);
  112.  
  113.    // Allocate memory for pTempBuffer which is used when
  114.    // IOProcReadInterLeaved is called.
  115.  
  116.    if (ENTERCRIT(rc)) {
  117.       ioCleanUp(pmmioinfo);
  118.       return MMIO_ERROR;
  119.    }
  120.  
  121.    pinstance->pTempBuffer = HhpAllocMem(hheap, DEFAULTBUFFERSIZE);
  122.  
  123.    if (pinstance->pTempBuffer == NULL) {
  124.       EXITCRIT;
  125.       pmmioinfo->ulErrorRet = MMIOERR_OUTOFMEMORY;
  126.       ioCleanUp(pmmioinfo);
  127.       return MMIO_ERROR;
  128.    }
  129.    EXITCRIT;
  130.  
  131.    pinstance->ulTempBufferSize     = DEFAULTBUFFERSIZE;
  132.    pinstance->lFileCurrentPosition = 0;
  133.  
  134.    // set up the local MMIOINFO structure
  135.  
  136.    Localmmioinfo = *pmmioinfo;               // copy the original
  137.    Localmmioinfo.pIOProc = NULL;
  138.    Localmmioinfo.fccIOProc = pmmioinfo->fccChildIOProc;
  139.    Localmmioinfo.ulFlags |= MMIO_NOIDENTIFY; // Eliminate callbacks
  140.    Localmmioinfo.ulFlags &= ~MMIO_ALLOCBUF;  // Force non-buffered open
  141.  
  142.    // Determine if it is open for readonly or for write access
  143.  
  144.    if ((pmmioinfo->ulFlags  & MMIO_READ) && !(pmmioinfo->ulFlags & INVALID_READ_FLAGS))
  145.       openType = MMIO_READ;
  146.    else
  147.       if ((pmmioinfo->ulFlags & (MMIO_READWRITE | MMIO_WRITE)) &&!(pmmioinfo->ulFlags & INVALID_WRITE_FLAGS))
  148.          openType = MMIO_WRITE;
  149.  
  150.    // Perform either read or write specific open processing
  151.  
  152.    switch (openType) {
  153.  
  154.       case MMIO_READ:
  155.  
  156.          rc = ioIdentifyStorageSystem(&Localmmioinfo,pszFileName); // IOProc identifies Storage System
  157.          if (rc != MMIO_SUCCESS) break;
  158.  
  159.          // Open the Movie file
  160.  
  161.          if (pmmioinfo->fccChildIOProc != FOURCC_MEM ) {
  162.             Localmmioinfo.cchBuffer = 0;
  163.             Localmmioinfo.pchBuffer = NULL;
  164.          }
  165.  
  166.          pinstance->hmmioFileHandle = mmioOpen(pszFileName, &Localmmioinfo, MMIO_NOIDENTIFY);
  167.  
  168.          if (pinstance->hmmioFileHandle == 0) {
  169.             rc = Localmmioinfo.ulErrorRet;
  170.             break;
  171.          }
  172.  
  173.          // call file format specific routine
  174.  
  175.          rc = ffOpenRead(pmmioinfo, pinstance);
  176.          if (rc != MMIO_SUCCESS) break;
  177.  
  178.          rc = ioAddTracksToMovieHeader(pinstance);
  179.          if (rc != MMIO_SUCCESS) break;
  180.  
  181.          lFilePosition = ffSeekToDataBegin(pmmioinfo,pinstance);
  182.          pinstance->lFileCurrentPosition = lFilePosition;
  183.          if (lFilePosition < 0) rc = MMIOERR_INTERNAL_SYSTEM;
  184.  
  185.          break;
  186.  
  187.       case MMIO_WRITE:
  188.  
  189.          if (!(pmmioinfo->ulFlags & MMIO_CREATE)) {
  190.             rc = ioIdentifyStorageSystem(&Localmmioinfo, pszFileName);
  191.             if (rc != MMIO_SUCCESS) break;
  192.          }
  193.  
  194.          // Open the movie file
  195.  
  196.          pinstance->hmmioFileHandle = mmioOpen(pszFileName, &Localmmioinfo, Localmmioinfo.ulFlags);
  197.  
  198.          if (pinstance->hmmioFileHandle == 0) {
  199.             rc = Localmmioinfo.ulErrorRet;
  200.             break;
  201.          }
  202.  
  203.          // call file format specific routine
  204.  
  205.          rc = ffOpenWrite(pmmioinfo, pinstance);   // call file format specific open routine
  206.          if (rc != MMIO_SUCCESS) break;
  207.  
  208.          if (!(pmmioinfo->ulFlags & MMIO_CREATE)) {
  209.             rc = ioAddTracksToMovieHeader(pinstance);
  210.             if (rc != MMIO_SUCCESS) break;
  211.  
  212.             lFilePosition = ffSeekToDataBegin(pmmioinfo, pinstance);
  213.             pinstance->lFileCurrentPosition = lFilePosition;
  214.             if (lFilePosition < 0) rc = MMIOERR_INTERNAL_SYSTEM;
  215.          }
  216.          break;
  217.  
  218.       default:
  219.          rc = MMIOERR_INTERNAL_SYSTEM;
  220.          break;
  221.    }
  222.  
  223.    if (rc != MMIO_SUCCESS) {
  224.       ioCleanUp(pmmioinfo);
  225.       pmmioinfo->ulErrorRet = rc;
  226.       return rc;
  227.  
  228. //    valid return codes for MMIOM_OPEN are MMIO_SUCCESS or either
  229. //    a DOS error code or a MMIO error code is returned.
  230. //    return MMIO_ERROR;
  231.    }
  232.  
  233. #ifndef CANT_EDIT
  234.    // obtain PID used to mark clipboard entries and a dummy time stamp
  235.  
  236.    DosGetInfoBlocks(&ptib, &ppib);
  237.    pinstance->pidPID = ppib->pib_ulpid;
  238.    DosGetDateTime(&(pinstance->dtClipbrdTime));
  239.  
  240.    // set up the pathname in the instance structure for clipboard editing
  241.  
  242.    if ((pszFileName != NULL) && (strlen(pszFileName) < CCHMAXPATH)) {
  243.       rc = ioEditGetFullName(pszFileName, (PSZ)&(pinstance->szFileName));
  244.       if (rc != MMIO_SUCCESS) {
  245.          pmmioinfo->ulErrorRet = rc;
  246.          return rc;
  247. //       return MMIO_ERROR;
  248.       }
  249.       pinstance->ulEditFlags |= FULLY_QUALIFIED_PATH;
  250.    }
  251.    else {
  252.       pinstance->szFileName[0] = '\0';
  253.       pinstance->ulEditFlags |= CANNOT_CUT_OR_COPY;   // don't know the file name
  254.    }                                                  // can't put stuff into the clipboard
  255. #endif
  256.  
  257.    pmmioinfo->ulErrorRet = 0;
  258.    return MMIO_SUCCESS;
  259. }
  260.