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

  1. /*************************START OF SPECIFICATIONS *************************/
  2. /* SOURCE FILE NAME:  ULOPEN.C                                            */
  3. /*                                                                        */
  4. /* DESCRIPTIVE NAME: Ultimotion 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. /*     ffOpenRead                                                         */
  20. /*     ffOpenWrite                                                        */
  21. /*     ffReadHeader                                                       */
  22. /*     ffProcessVideoHeader                                               */
  23. /*     ffInitCodecs                                                       */
  24. /*                                                                        */
  25. /************************* END OF SPECIFICATIONS **************************/
  26.  
  27.  
  28. #include        <stdio.h>
  29. #include        <string.h>
  30. #include        <stdlib.h>
  31. #include        <memory.h>
  32.  
  33. #define         INCL_DOS                        /* #define  INCL_DOSPROCESS.*/
  34. #define         INCL_ERRORS
  35. #define         INCL_WIN
  36. #define         INCL_GPI
  37. #include        <os2.h>                         /* OS/2 headers.            */
  38. #include        <pmbitmap.h>
  39.  
  40. #define         INCL_OS2MM
  41. #define         INCL_MMIO_CODEC
  42. #define         INCL_MMIO_DOSIOPROC
  43. #include        <os2me.h>                      /* Multi-Media IO extensions.*/
  44. #include        <hhpheap.h>
  45. #include        <ioi.h>
  46.  
  47.  
  48.    extern HHUGEHEAP hheap;
  49.    extern HMTX hmtxGlobalHeap;
  50.  
  51.  
  52. /************************** START OF SPECIFICATIONS *************************/
  53. /*                                                                          */
  54. /* SUBROUTINE NAME:  ffOpenWrite                                            */
  55. /*                                                                          */
  56. /* DESCRIPTIVE NAME: PhotoMotion specific open routines                     */
  57. /*                                                                          */
  58. /* FUNCTION: Creates track lists and codec lists for the file.              */
  59. /*                                                                          */
  60. /* NOTES: None                                                              */
  61. /*                                                                          */
  62. /* ENTRY POINT: ffOpenWrite                                                 */
  63. /*   LINKAGE:   CALL FAR (00:32)                                            */
  64. /*                                                                          */
  65. /* INPUT:                                                                   */
  66. /*              PMMIOINFO pmmioinfo - Pointer to MMIOINFO staus structure.  */
  67. /*              PINSTANCE pinstance - Pointer to file instance structure.   */
  68. /*                                                                          */
  69. /* EXIT-NORMAL:                                                             */
  70. /*              MMIO_SUCCESS                                                */
  71. /*                                                                          */
  72. /* EXIT-ERROR:                                                              */
  73. /*              MMIO_ERROR                                                  */
  74. /*                                                                          */
  75. /* SIDE EFFECTS:                                                            */
  76. /*                                                                          */
  77. /*************************** END OF SPECIFICATIONS **************************/
  78. LONG ffOpenWrite( PMMIOINFO pmmioinfo,
  79.                   PINSTANCE pinstance )
  80.  
  81. {
  82.    return(MMIO_SUCCESS);                      /* Nothing failed, return OK. */
  83. }
  84.  
  85.  
  86. /************************** START OF SPECIFICATIONS *************************/
  87. /*                                                                          */
  88. /* SUBROUTINE NAME:  ffOpenRead                                             */
  89. /*                                                                          */
  90. /* DESCRIPTIVE NAME: Ulitmotion file format specific open routine           */
  91. /*                                                                          */
  92. /* FUNCTION: This function opens UltiMotion file, allocates UltiMotion      */
  93. /*           status structure, reads header, creates track list; DCIO proc  */
  94. /*           list; track header.                                            */
  95. /*                                                                          */
  96. /* NOTES: None                                                              */
  97. /*                                                                          */
  98. /* ENTRY POINT: ffOpenRead                                                  */
  99. /*   LINKAGE:   CALL FAR (00:32)                                            */
  100. /*                                                                          */
  101. /* INPUT:                                                                   */
  102. /*              PMMIOINFO pmmioinfo - Pointer to MMIOINFO staus structure.  */
  103. /*              PINSTANCE pinstance - Pointer to instance structure.        */
  104. /*                                                                          */
  105. /* EXIT-NORMAL:                                                             */
  106. /*              MMIO_SUCCESS                                                */
  107. /*                                                                          */
  108. /* EXIT-ERROR:                                                              */
  109. /*             MMIO_ERROR, pmmioinfo->ulErrorRet = rc                       */
  110. /*                                                                          */
  111. /* SIDE EFFECTS:                                                            */
  112. /*                                                                          */
  113. /*************************** END OF SPECIFICATIONS **************************/
  114. LONG ffOpenRead ( PMMIOINFO pmmioinfo,
  115.                   PINSTANCE pinstance )
  116.  
  117. {
  118.    LONG            rc = MMIO_SUCCESS;
  119.    MMCKINFO        mmckinfoHdr;
  120.    PBYTE           pPosition;
  121.    PVOID           pHdr;
  122.    PUMCHUNKHEADER  pumchPosition;
  123.    ULONG           ulNumTracks;      /* Keep # of tracks handy until mmhdr is allocated */
  124.    ULONG           ulSize;
  125.    PULONG          pulListForm;
  126.  
  127.  
  128.    ENTERCRITX;
  129.    ulNumTracks = 0L;
  130.    if (!(rc = ffReadHeader(pmmioinfo,pinstance,&mmckinfoHdr))) {
  131.  
  132.       /**********************************************************************/
  133.       /* Identify each chunk in the header LIST and save in the appropriate */
  134.       /* place in the instance structure.                                   */
  135.       /**********************************************************************/
  136.       pPosition = (PBYTE)pinstance->pRawHdr;     /* point past form in hdr list */
  137.       while (((ULONG)pPosition <
  138.               ((ULONG)pinstance->pRawHdr + pinstance->ulRawHdrLength)) &&
  139.              !rc) {
  140.  
  141.          /****************************************************/
  142.          /* Match the chunk id up with the known chunk types */
  143.          /****************************************************/
  144.          pumchPosition = (PUMCHUNKHEADER)pPosition;
  145.          pHdr = pPosition + sizeof(UMCHUNKHEADER);
  146.          switch (pumchPosition->ulChunkID)  {
  147.  
  148.             /************************/
  149.             case HEX_UMID_VIDEOHEADER:
  150.             /************************/
  151.                if (!(rc = ffProcessVideoHeader(pinstance,pHdr,pmmioinfo))) {
  152.                   ulNumTracks++;
  153.                   }
  154.                break;
  155.  
  156.             /************************/
  157.             case  HEX_UMID_VIDEOTITLE:
  158.             /************************/
  159. //##BILL-------rc = ffProcessVideoTitle(pinstance,pHdr);
  160.                break;
  161.  
  162.             /***************/
  163.             case FOURCC_LIST:
  164.             /***************/
  165.                pulListForm = (PULONG)pHdr;  /* point to form fourcc */
  166.                pHdr = (PVOID)((ULONG)pHdr + SIZEOF_FORM); /* Point to real header start */
  167.                ulSize = pumchPosition->ulChunkLength - SIZEOF_FORM;
  168.  
  169.                switch (*pulListForm) {
  170.  
  171.                   /***************************/
  172.                   case HEX_UMFORM_AUDIOHDRLIST:
  173.                   /***************************/
  174.                      rc = ffProcessAudioHeaderList(pinstance,
  175.                                                    pHdr,
  176.                                                    ulSize,
  177.                                                    &ulNumTracks);
  178.                      break;
  179.  
  180.                   /**************************/
  181.                   case HEX_UMFORM_TEXTHDRLIST:
  182.                   /**************************/
  183. //##BILL-------------rc = ffProcessTextHeaderList(pinstance,
  184. //                                                pHdr,
  185. //                                                ulSize,
  186. //------------------------------------------------&ulNumTracks);
  187.                      break;
  188.  
  189.                   /******/
  190.                   default:  /* skip unknown LIST chunks */
  191.                   /******/
  192.                      break;
  193.                   }
  194.                break;
  195.  
  196.             /******/
  197.             default: /* skip unknown LIST chunks */
  198.             /******/
  199.                break;
  200.             }
  201.  
  202.          if (!rc) {
  203.             /* Move position pointer to beginning of next chunk */
  204.             pPosition += sizeof(UMCHUNKHEADER) + pumchPosition->ulChunkLength;
  205.             if ((ULONG)pPosition % 2)  /* account for even chunk boundary */
  206.                pPosition++;
  207.             }
  208.  
  209.          } /* while */
  210.  
  211.       /***************************************************************************/
  212.       /* Allocate MMHDR and update some of the information.                      */
  213.       /***************************************************************************/
  214.       if (!rc) {
  215.          ulSize = (sizeof(MMTRACKINFO)*ulNumTracks) + sizeof(MMMOVIEHEADER);     //Jack this line changed!
  216.          if (!(pinstance->pmmhdr = (PMMMOVIEHEADER)HhpAllocMem(hheap, ulSize))) {
  217.             rc = MMIOERR_OUTOFMEMORY;
  218.             }
  219.          else {
  220.             pinstance->ulMmHdrLength = ulSize;
  221.             pinstance->pmmhdr->ulStructLen = sizeof(MMMOVIEHEADER);
  222.             pinstance->pmmhdr->ulMediaType = MMIO_MEDIATYPE_MOVIE;
  223.             pinstance->pmmhdr->ulNumEntries = ulNumTracks;
  224.             pinstance->pmmhdr->pmmTrackInfoList = (PMMTRACKINFO)((ULONG)pinstance->pmmhdr + sizeof(MMMOVIEHEADER));
  225.             pinstance->pmmhdr->ulMaxBytesPerSec = 0L;                       //TEMP TEMP
  226.             pinstance->pmmhdr->ulPaddingGranularity = 0L;                   //TEMP TEMP
  227.             pinstance->pmmhdr->ulSuggestedBufferSize = 0L;                  //TEMP TEMP
  228.             pinstance->pmmhdr->ulStart = 0L;                                //TEMP TEMP
  229.             pinstance->pmmhdr->ulLength = 0L;                               //TEMP TEMP
  230.             pinstance->pmmhdr->ulNextTrackID = 0L;                          //TEMP TEMP
  231.             pinstance->pmmhdr->pszMovieTitle = 0L;                          //TEMP TEMP
  232.             pinstance->pmmhdr->ulCountry = 0L;                              //TEMP TEMP
  233.             pinstance->pmmhdr->ulCodePage = 0L;                             //TEMP TEMP
  234.             pinstance->pmmhdr->ulMovieCapsFlags = MOVIE_HAS_VIDEO+          //TEMP TEMP
  235.                                                   MOVIE_HAS_AUDIO+
  236.                                                   MOVIE_CAN_SCAN;
  237.             }
  238.          }
  239.       }
  240.  
  241.    EXITCRIT;
  242.    if (rc) {
  243.       pmmioinfo->ulErrorRet = rc;
  244.       return(MMIO_ERROR);
  245.       }
  246.    else {
  247.       pinstance->ulFlags = OPENED_READONLY;
  248.       return(MMIO_SUCCESS);                      /* Nothing failed, return OK. */
  249.       }
  250. }
  251.  
  252.  
  253. /************************** START OF SPECIFICATIONS *************************/
  254. /*                                                                          */
  255. /* SUBROUTINE NAME: ffReadHeader                                            */
  256. /*                                                                          */
  257. /* DESCRIPTIVE NAME: Read header                                            */
  258. /*                                                                          */
  259. /* FUNCTION: Validate that the file is a valid SMV RIFF file.               */
  260. /*           Determines file size                                           */
  261. /*           Read SMV Header list into allocated memory for parsing         */
  262. /*                                                                          */
  263. /* NOTES:                                                                   */
  264. /*           (Caller must deallocate header memory)                         */
  265. /*                                                                          */
  266. /* ENTRY POINT: ffReadHeader                                                */
  267. /*   LINKAGE:   CALL FAR (00:32)                                            */
  268. /*                                                                          */
  269. /* INPUT:     PMMIOINFO   pmmioinfo - Pointer to MMIOINFO staus structure.  */
  270. /*            PINSTANCE   pinstance - instance structure of I/O Procedure.  */
  271. /*            PMMCKINFO   pmmckinfoHdr - Return pointer to Headr chunk      */
  272. /*                                       (Parent of header descends)        */
  273. /*                                                                          */
  274. /* EXIT-NORMAL:                                                             */
  275. /*              MMIO_SUCCESS                                                */
  276. /*                                                                          */
  277. /* EXIT-ERROR:                                                              */
  278. /*              MMIO_ERROR                                                  */
  279. /*              Message specific error                                      */
  280. /*                                                                          */
  281. /* SIDE EFFECTS:                                                            */
  282. /*                                                                          */
  283. /*************************** END OF SPECIFICATIONS **************************/
  284. LONG ffReadHeader ( PMMIOINFO pmmioinfo,
  285.                     PINSTANCE pinstance,
  286.                     PMMCKINFO pmmckinfoHdr )
  287.  
  288. {
  289.    LONG            rc = MMIO_SUCCESS;                      /* Return code.         */
  290.    LONG            lFilePosition;                          /* File position.       */
  291.  
  292.  
  293.    /* set file pointer to beginning of file.*/
  294.    lFilePosition = ioSeekFile((PLONG)&pmmioinfo->ulErrorRet,pinstance->hmmioFileHandle,0L);
  295.    if (lFilePosition < MMIO_SUCCESS) {
  296.       return(MMIO_ERROR);
  297.       } /* end if */
  298.  
  299.    /* Find SMV Riff chunk (This verifies the file is an SMV movie file also */
  300.    memset (pmmckinfoHdr, '\0', sizeof(MMCKINFO));
  301.    pmmckinfoHdr->fccType = HEX_UMFORM_MOVIE;
  302.    if (rc = mmioDescend(pinstance->hmmioFileHandle,
  303.                         pmmckinfoHdr,
  304.                         NULL,
  305.                         MMIO_FINDRIFF))
  306.       return (rc);
  307.  
  308.    /* update length of file */
  309.    pinstance->ulFileLen = pmmckinfoHdr->ckSize + sizeof(UMCHUNKHEADER);
  310.  
  311.    /* Find the SMV headers list (All headers are in this chunk) */
  312.    memset (pmmckinfoHdr, '\0', sizeof(MMCKINFO));
  313.    pmmckinfoHdr->fccType = HEX_UMFORM_HEADERLIST;
  314.    if (rc = mmioDescend(pinstance->hmmioFileHandle,
  315.                         pmmckinfoHdr,
  316.                         NULL,
  317.                         MMIO_FINDLIST))
  318.       return (rc);
  319.    pinstance->ulRawHdrLength = pmmckinfoHdr->ckSize - SIZEOF_FORM;
  320.  
  321.    /* allocate enough memory to read in the entire header LIST */
  322.    if ((pinstance->pRawHdr =
  323.         (PRAWFILEHEADER)HhpAllocMem(hheap,
  324.                                     pinstance->ulRawHdrLength)) == NULL) {
  325.       return(MMIOERR_OUTOFMEMORY);
  326.       }
  327.  
  328.    /* Read in the entire header LIST */
  329.    rc = mmioRead(pinstance->hmmioFileHandle,
  330.                  pinstance->pRawHdr,
  331.                  pinstance->ulRawHdrLength);
  332.    if (rc != pinstance->ulRawHdrLength) {
  333.        return (MMIO_ERROR);
  334.        }
  335.    pinstance->lFileCurrentPosition = pmmckinfoHdr->ulDataOffset +
  336.                                      rc + SIZEOF_FORM;
  337.  
  338.    return(MMIO_SUCCESS);
  339. }
  340.  
  341.  
  342. /************************** START OF SPECIFICATIONS *************************/
  343. /*                                                                          */
  344. /* SUBROUTINE NAME:  ffInitCodecs                                           */
  345. /*                                                                          */
  346. /* DESCRIPTIVE NAME: Initialize all codecs for this movie file.             */
  347. /*                                                                          */
  348. /* FUNCTION: This function is a file format specific routine that determines*/
  349. /*           the codecs that need to be loaded to process this file.        */
  350. /*           The codecs are then loaded.                                    */
  351. /*                                                                          */
  352. /* NOTES: None                                                              */
  353. /*                                                                          */
  354. /* ENTRY POINT: ffInitCodecs                                                */
  355. /*   LINKAGE:   CALL FAR (00:32)                                            */
  356. /*                                                                          */
  357. /* INPUT:                                                                   */
  358. /*        PINSTANCE      pinstance  - Ptr to instance structure.            */
  359. /*        PTRACKI        ptracki    - Ptr to track instance structure.      */
  360. /*        PMMIOINFO      pmmioinfo - Pointer to MMIOINFO staus structure.   */
  361. /*                                                                          */
  362. /* EXIT-NORMAL:                                                             */
  363. /*              MMIO_SUCCESS                                                */
  364. /*                                                                          */
  365. /* EXIT-ERROR:                                                              */
  366. /*              MMIO_ERROR                                                  */
  367. /*                                                                          */
  368. /* SIDE EFFECTS:                                                            */
  369. /*                                                                          */
  370. /*************************** END OF SPECIFICATIONS **************************/
  371. LONG ffInitCodecs ( PINSTANCE pinstance,
  372.                     PTRACKI ptracki,
  373.                     PMMIOINFO pmmioinfo )
  374.  
  375. {
  376.    LONG              rc;
  377.    PUMVIDEOHEADER    pumvh;
  378.    USHORT            i;
  379.    CODECINIFILEINFO  cifi;
  380.    PCCB              pccb;
  381.  
  382.    pumvh = (PUMVIDEOHEADER)ptracki->pRawHdr;
  383.  
  384.    for (i=0; i < pumvh->usNumCompressionTypes; i++) {
  385.       memset (&cifi, '\0', sizeof(CODECINIFILEINFO));
  386.       cifi.ulStructLen = sizeof(CODECINIFILEINFO);
  387.       cifi.fcc = pmmioinfo->fccIOProc;
  388.       cifi.ulCompressType = pumvh->aulCompressionTypes[i];
  389.       cifi.ulCompressSubType = 0L;
  390.       cifi.ulCapsFlags = CODEC_DECOMPRESS;
  391.       cifi.szHWID[0] = 0L;               /* Software algorithm */
  392.  
  393.       if (rc = ioDetermineCodec(pinstance, 0, &cifi)) {
  394.          return(rc);
  395.          }
  396.       else {
  397.          if (!(pccb = ioLoadCodec(pmmioinfo, pinstance, ptracki, &cifi)))
  398.             return(MMIO_ERROR);
  399.          }
  400.       }
  401.  
  402.    return(MMIO_SUCCESS);
  403. }
  404.  
  405.  
  406. /************************** START OF SPECIFICATIONS *************************/
  407. /*                                                                          */
  408. /* SUBROUTINE NAME:  ffProcessVideoHeader                                   */
  409. /*                                                                          */
  410. /* DESCRIPTIVE NAME: Process a video header from the header LIST            */
  411. /*                                                                          */
  412. /* FUNCTION: This function creates a track header node based on the track   */
  413. /*           media type.                                                    */
  414. /*                                                                          */
  415. /* NOTES:                                                                   */
  416. /*        ** This code assumes that there is only one video track!          */
  417. /*                                                                          */
  418. /* ENTRY POINT: ffProcessVideoHeader                                        */
  419. /*   LINKAGE:   CALL FAR (00:32)                                            */
  420. /*                                                                          */
  421. /* INPUT:                                                                   */
  422. /*        PINSTANCE      pinstance  - Ptr to instance structure.            */
  423. /*        PUMVIDEOHEADER pumvhHdr   - Ptr to header (data in chunk)         */
  424. /*        PMMIOINFO      pmmioinfo - Pointer to MMIOINFO staus structure.   */
  425. /*                                                                          */
  426. /* EXIT-NORMAL:                                                             */
  427. /*              MMIO_SUCCESS                                                */
  428. /*                                                                          */
  429. /* EXIT-ERROR:                                                              */
  430. /*              MMIO_ERROR                                                  */
  431. /*                                                                          */
  432. /* SIDE EFFECTS:                                                            */
  433. /*                                                                          */
  434. /*************************** END OF SPECIFICATIONS **************************/
  435. LONG ffProcessVideoHeader ( PINSTANCE pinstance,
  436.                             PUMVIDEOHEADER  pumvhHdr,
  437.                             PMMIOINFO pmmioinfo )
  438.  
  439. {
  440.    LONG              rc = MMIO_SUCCESS;            /* Return code.         */
  441.    PTRACKI           ptracki;                      /* New node of ptracki. */
  442.    PMMVIDEOHEADER    pmmVideoHdr;                  /* Video header node.      */
  443.    PVOID             pRawHdr;
  444.  
  445.    if (ptracki = ioFindTracki(pinstance,0L)) {
  446.       /* duplicate video track headers found */
  447.       return(MMIOERR_INVALID_FILE);
  448.       }
  449.    else {
  450.       if (pumvhHdr == NULL)
  451.          return(MMIO_ERROR);
  452.  
  453.       /**********************************************************/
  454.       /* If this is a new track, creates a track node, fill     */
  455.       /* in necessary information to node.                      */
  456.       /**********************************************************/
  457.       if (!(ptracki = (PTRACKI)HhpAllocMem(hheap,(ULONG)sizeof(TRACKI)))) {
  458.          return(MMIOERR_OUTOFMEMORY);
  459.          }
  460.  
  461.       ptracki->ulTrackID     = 0L;       /* Assume only one track for now */
  462.       ptracki->ulMediaType = MMIO_MEDIATYPE_DIGITALVIDEO;
  463.  
  464.       /**********************************************************/
  465.       /* adds new node to the beginning of track list, sets     */
  466.       /* pointer ptracki of record map table to ptrackiList     */
  467.       /* that directs to decompress IOProc.                     */
  468.       /**********************************************************/
  469.       ptracki->ptrackiNext = pinstance->ptrackiList;
  470.       pinstance->ptrackiList    = ptracki;
  471.  
  472.       /***************************************************************************/
  473.       /* Allocates Standard Presentation Video Header and fills in the info.     */
  474.       /***************************************************************************/
  475.       if (!(pmmVideoHdr = (PMMVIDEOHEADER)HhpAllocMem(hheap,sizeof(MMVIDEOHEADER)))) {
  476.          return(MMIOERR_OUTOFMEMORY);
  477.          }
  478.  
  479.       pmmVideoHdr->ulStructLen = sizeof(MMVIDEOHEADER);
  480.       pmmVideoHdr->ulContentType = MMIO_VIDEO_DATA;
  481.       pmmVideoHdr->ulMediaType = ptracki->ulMediaType;
  482.       pmmVideoHdr->ulVideoCapsFlags = 0L;
  483.       pmmVideoHdr->ulWidth = (ULONG)pumvhHdr->usMaxFrameX;
  484.       pmmVideoHdr->ulHeight = (ULONG)pumvhHdr->usMaxFrameY;
  485.       pmmVideoHdr->ulScale = 1L;
  486.       pmmVideoHdr->ulStart = 0L;                                    //TEMP TEMP
  487.       pmmVideoHdr->ulLength = 0L;                                   //TEMP TEMP
  488.       pmmVideoHdr->ulTotalFrames = 0L;                              //TEMP TEMP
  489.       pmmVideoHdr->ulInitialFrames = 0L;                            //TEMP TEMP
  490. //    pmmVideoHdr->ulSuggestedBufferSize = 0L;                      //TEMP TEMP
  491.  
  492.       if (pumvhHdr->usNomFrameDuration == 0) {
  493.          pmmVideoHdr->mmtimePerFrame = 0L;
  494.          pmmVideoHdr->ulRate = 0L;
  495.          }
  496.       else {
  497.          pmmVideoHdr->mmtimePerFrame = (MMTIME)pumvhHdr->usNomFrameDuration;
  498.          pmmVideoHdr->ulRate = (ULONG)(MMTIMEUNIT / (ULONG)pumvhHdr->usNomFrameDuration);
  499.          }
  500.  
  501.       ptracki->pTrackHeader = (PVOID)pmmVideoHdr;
  502.       ptracki->ulTrackHdrLength = sizeof(MMVIDEOHEADER);
  503.  
  504.       /***************************************************************************/
  505.       /* Allocates Raw Video Header and fills in the info.                       */
  506.       /***************************************************************************/
  507.       if (!(pRawHdr = (PVOID)HhpAllocMem(hheap,sizeof(UMVIDEOHEADER)))) {
  508.          return(MMIOERR_OUTOFMEMORY);
  509.          }
  510.       memcpy(pRawHdr,pumvhHdr,sizeof(UMVIDEOHEADER));
  511.       ptracki->pRawHdr = pRawHdr;
  512.       ptracki->ulRawHdrLength = sizeof(UMVIDEOHEADER);
  513.  
  514.       /****************************************************/
  515.       /* Initialize all of the codecs needed for this     */
  516.       /* video track. Load the codec IO Procs if necessary*/
  517.       /****************************************************/
  518.       if (rc = ffInitCodecs(pinstance, ptracki, pmmioinfo))
  519.          return(rc);
  520.       } /* else */
  521.  
  522.    return(MMIO_SUCCESS);
  523. }
  524.  
  525.  
  526. /************************** START OF SPECIFICATIONS *************************/
  527. /*                                                                          */
  528. /* SUBROUTINE NAME:  ffProcessAudioHeaderList                               */
  529. /*                                                                          */
  530. /* DESCRIPTIVE NAME: Process an audio header LIST.                          */
  531. /*                                                                          */
  532. /* FUNCTION: This function creates a track header node based on the track   */
  533. /*           media type. One track is created for each audio header         */
  534. /*           found in the LIST.                                             */
  535. /*                                                                          */
  536. /* NOTES: none                                                              */
  537. /*                                                                          */
  538. /* ENTRY POINT: ffProcessAudioHeaderList                                    */
  539. /*   LINKAGE:   CALL FAR (00:32)                                            */
  540. /*                                                                          */
  541. /* INPUT:                                                                   */
  542. /*        PINSTANCE      pinstance  - Ptr to instance structure.            */
  543. /*        PVOID          pHdr       - Ptr to header (data in chunk)         */
  544. /*        ULONG          ulChunkLength - length of LIST chunk               */
  545. /*        PULONG         pulNumTracks - Update number of tracks             */
  546. /*                                                                          */
  547. /* EXIT-NORMAL:                                                             */
  548. /*              MMIO_SUCCESS                                                */
  549. /*                                                                          */
  550. /* EXIT-ERROR:                                                              */
  551. /*              MMIO_ERROR                                                  */
  552. /*                                                                          */
  553. /* SIDE EFFECTS:                                                            */
  554. /*                                                                          */
  555. /*************************** END OF SPECIFICATIONS **************************/
  556. LONG ffProcessAudioHeaderList ( PINSTANCE pinstance,
  557.                                 PVOID  pListHdr,
  558.                                 ULONG  ulChunkLength,
  559.                                 PULONG pulNumTracks )
  560.  
  561. {
  562.    LONG            rc = MMIO_SUCCESS;            /* Return code.         */
  563.    PBYTE           pPosition;
  564.    ULONG           ulLastTrackFound = 0L;
  565.    PUMCHUNKHEADER  pumchPosition;
  566.    PVOID           pHdr;
  567.  
  568.    /**********************************************************************/
  569.    /* Identify each chunk in the Audio header LIST and save in the       */
  570.    /* appropriate place in the instance structure.                       */
  571.    /**********************************************************************/
  572.    pPosition = (PBYTE)pListHdr;  /* point past form in hdr list */
  573.    while (((ULONG)pPosition <
  574.            ((ULONG)pListHdr + ulChunkLength)) &&
  575.           !rc) {
  576.  
  577.       /****************************************************/
  578.       /* Match the chunk id up with the known chunk types */
  579.       /****************************************************/
  580.       pumchPosition = (PUMCHUNKHEADER)pPosition;
  581.       pHdr = pPosition + sizeof(UMCHUNKHEADER);
  582.       switch (pumchPosition->ulChunkID)  {
  583.  
  584.          /*************************/
  585.          case HEX_UMID_EXTAUDIONAME:
  586.          /*************************/
  587. //----------rc = ffProcessExtAudioHeader(pinstance,
  588. //                                       (PEXTAUDIONAME)pHdr,
  589. //                                       pumchPosition->ulChunkLength);
  590. //----------(*pulNumTracks)++;
  591.             break;
  592.  
  593.          /*************************/
  594.          case  HEX_UMID_AUDIOHEADER:
  595.          /*************************/
  596.             if (!(rc = ffProcessIntAudioHeader(pinstance,
  597.                                          (PAUDIOHEADER)pHdr,
  598.                                          pumchPosition->ulChunkLength))) {
  599.                (*pulNumTracks)++;
  600.                }
  601.             break;
  602.  
  603.          /************************/
  604.          case  HEX_UMID_AUDIOTITLE:
  605.          /************************/
  606. //----------if (ulLastTrackFound)   /* ignore if no audio track defined */
  607. //--##BILL-----rc = ffProcessAudioTitle(pinstance,pHdr,ulLastTrackFound);
  608.             break;
  609.  
  610.          /******/
  611.          default: /* skip unknown chunks */
  612.          /******/
  613.             break;
  614.          }
  615.  
  616.       if (!rc) {
  617.          /* Move position pointer to beginning of next chunk */
  618.          pPosition += sizeof(UMCHUNKHEADER) + pumchPosition->ulChunkLength;
  619.          if ((ULONG)pPosition % 2)  /* account for even chunk boundary */
  620.             pPosition++;
  621.          }
  622.  
  623.       } /* while */
  624.  
  625.    return(rc);
  626. }
  627.  
  628.  
  629. /************************** START OF SPECIFICATIONS *************************/
  630. /*                                                                          */
  631. /* SUBROUTINE NAME:  ffProcessExtAudioHeader                                */
  632. /*                                                                          */
  633. /* DESCRIPTIVE NAME: Process an audio header LIST.                          */
  634. /*                                                                          */
  635. /* FUNCTION: Process an external audio file name header.                    */
  636. /*                                                                          */
  637. /* NOTES: none                                                              */
  638. /*                                                                          */
  639. /* ENTRY POINT: ffProcessExtAudioHeader                                     */
  640. /*   LINKAGE:   CALL FAR (00:32)                                            */
  641. /*                                                                          */
  642. /* INPUT:                                                                   */
  643. /*        PINSTANCE      pinstance  - Ptr to instance structure.            */
  644. /*        PEXTAUDIONAME  pumeaHdr   - Ptr to header (data in chunk)         */
  645. /*        ULONG          ulHdrLength - Length of header                     */
  646. /*                                                                          */
  647. /* EXIT-NORMAL:                                                             */
  648. /*              MMIO_SUCCESS                                                */
  649. /*                                                                          */
  650. /* EXIT-ERROR:                                                              */
  651. /*              MMIO_ERROR                                                  */
  652. /*                                                                          */
  653. /* SIDE EFFECTS:                                                            */
  654. /*                                                                          */
  655. /*************************** END OF SPECIFICATIONS **************************/
  656. LONG ffProcessExtAudioHeader ( PINSTANCE pinstance,
  657.                                PEXTAUDIONAME pumeaHdr,
  658.                                ULONG ulHdrLength )
  659.  
  660. {
  661. //   LONG              rc = MMIO_SUCCESS;            /* Return code.         */
  662. //   PTRACKI           ptracki;                      /* New node of ptracki. */
  663. //   WAVE_HEADER      *pRawHdr;
  664. //   PEXTAUDIONAME     pumea;
  665. //   PMMAUDIOHEADER    pmmAudioHdr;                  /* Audio header node.      */
  666. //   MMIOINFO          Localmmioinfo;                /* For locally used.    */
  667. //   PMMCKINFO         pmmckinfoHdr;
  668. //
  669. //   if (ulHdrLength != sizeof(EXTAUDIONAME)) {
  670. //      return(MMIOERR_INVALID_FILE);
  671. //      }
  672. //
  673. //   if (pumeaHdr == NULL)
  674. //      return(MMIO_ERROR);
  675. //
  676. //   if (ptracki = ioFindTracki(pinstance,pumeaHdr->usTrackNumber)) {
  677. //      /* duplicate audio track headers found */
  678. //      return(MMIOERR_INVALID_FILE);
  679. //      }
  680. //
  681. //   /**********************************************************/
  682. //   /* If this is a new track, creates a track node, fill     */
  683. //   /* in necessary information to node.                      */
  684. //   /**********************************************************/
  685. //   if (!(ptracki = (PTRACKI)HhpAllocMem(hheap,(ULONG)sizeof(TRACKI)))) {
  686. //      return(MMIOERR_OUTOFMEMORY);
  687. //      }
  688. //
  689. //   /**********************************************************/
  690. //   /* Open the waveform file and read the header. It should  */
  691. //   /* be a riff wave file. Descend to the WAVE fmt chunk.    */
  692. //   /**********************************************************/
  693. //   ptracki->hmmioTrackFileHandle = mmioOpen(pumea->szFileName,&Localmmioinfo,MMIO_NOIDENTIFY);
  694. //   if (ptracki->hmmioTrackFileHandle == (HMMIO)0L) {    /* Test file open error.*/
  695. //      rc = Localmmioinfo.ulErrorRet;
  696. //      }
  697. //
  698. //   memset (pmmckinfoHdr, '\0', sizeof(MMCKINFO));
  699. //   pmmckinfoHdr->fccType = mmioFOURCC('W','A','V','E');
  700. //   if (rc = mmioDescend(ptracki->hmmioTrackFileHandle,
  701. //                        pmmckinfoHdr,
  702. //                        NULL,
  703. //                        MMIO_FINDRIFF))
  704. //      return (rc);
  705. //
  706. //   /* Find the WAVE fmt chunk */
  707. //   memset (pmmckinfoHdr, '\0', sizeof(MMCKINFO));
  708. //   pmmckinfoHdr->fccType = mmioFOURCC('f','m','t',' ');
  709. //   if (rc = mmioDescend(ptracki->hmmioTrackFileHandle,
  710. //                        pmmckinfoHdr,
  711. //                        NULL,
  712. //                        MMIO_FINDLIST))
  713. //      return (rc);
  714. //
  715. //   /***************************************************************************/
  716. //   /* Allocates Raw Audio Header and read header from file.                   */
  717. //   /***************************************************************************/
  718. //   if (!(pRawHdr = (WAVE_HEADER *)HhpAllocMem(hheap,sizeof(WAVE_HEADER)))) {
  719. //      return(MMIOERR_OUTOFMEMORY);
  720. //      }
  721. //   ptracki->pRawHdr = (PVOID)pRawHdr;
  722. //   ptracki->ulRawHdrLength = sizeof(WAVE_HEADER);
  723. //
  724. //   /* Read in the entire WAV header */
  725. //   rc = mmioRead(ptracki->hmmioTrackFileHandle,
  726. //                 ptracki->pRawHdr,
  727. //                 ptracki->ulRawHdrLength);
  728. //   if (rc != ptracki->ulRawHdrLength) {
  729. //       return (MMIO_ERROR);
  730. //       }
  731. //
  732. //   ptracki->ulTrackID     = (ULONG)pumeaHdr->usTrackNumber;
  733. //   ptracki->ulMediaType = MMIO_MEDIATYPE_AUDIO;                //##BILL - see comment below!
  734. //
  735. //   /**********************************************************/
  736. //   /* adds new node to the beginning of track list, sets     */
  737. //   /* pointer ptracki of record map table to ptrackiList     */
  738. //   /* that directs to decompress IOProc.                     */
  739. //   /**********************************************************/
  740. //   ptracki->ptrackiNext = pinstance->ptrackiList;
  741. //   pinstance->ptrackiList = ptracki;
  742. //
  743. //   /***************************************************************************/
  744. //   /* Allocates Standard Presentation Audio Header and fills in the info.     */
  745. //   /***************************************************************************/
  746. //   if (!(pmmAudioHdr = (PMMAUDIOHEADER)HhpAllocMem(hheap,sizeof(MMAUDIOHEADER)))) {
  747. //      return(MMIOERR_OUTOFMEMORY);
  748. //      }
  749. //
  750. //   pmmAudioHdr->ulHeaderLength = sizeof(MMAUDIOHEADER);
  751. //   pmmAudioHdr->ulContentType  = MMIO_AUDIO_MUSIC;            //UMB specific
  752. //   pmmAudioHdr->ulMediaType    = MMIO_MEDIATYPE_AUDIO;        //UMB specific
  753. //
  754. //   /*
  755. //    * Assign information to MMXWAV_HEADER.
  756. //    */
  757. //   pmmAudioHdr->mmXWAVHeader.WAVEHeader.usFormatTag      = pRawHdr->usFormatTag;
  758. //   pmmAudioHdr->mmXWAVHeader.WAVEHeader.usChannels       = pRawHdr->usChannels;
  759. //   pmmAudioHdr->mmXWAVHeader.WAVEHeader.ulSamplesPerSec  = pRawHdr->ulSamplesPerSec;
  760. //   pmmAudioHdr->mmXWAVHeader.WAVEHeader.ulAvgBytesPerSec = pRawHdr->ulAvgBytesPerSec;
  761. //   pmmAudioHdr->mmXWAVHeader.WAVEHeader.usBlockAlign     = pRawHdr->usBlockAlign;
  762. //   pmmAudioHdr->mmXWAVHeader.WAVEHeader.usBitsPerSample  = pRawHdr->usBitsPerSample;
  763. //
  764. //   ptracki->pTrackHeader = (PVOID)pmmAudioHdr;
  765. //   ptracki->ulTrackHdrLength = sizeof(MMAUDIOHEADER);
  766. //
  767. //   /* Find the Data chunk */
  768. //   memset (pmmckinfoHdr, '\0', sizeof(MMCKINFO));
  769. //   pmmckinfoHdr->fccType = mmioFOURCC('d','a','t','a');
  770. //   if (rc = mmioDescend(ptracki->hmmioTrackFileHandle,
  771. //                        pmmckinfoHdr,
  772. //                        NULL,
  773. //                        MMIO_FINDLIST))
  774. //      return (rc);
  775. //
  776. //   ptracki->ulMisc1 = 0L; /* init the amount of left-over audio data by which we need to ketchup! */
  777. //
  778. ////-ptracki->ulMisc1 = pmmckinfoHdr->ckSize;  /* Save audio data length */              /*OLD_EXTAUDIO*/
  779. ////                                                                                     /*OLD_EXTAUDIO*/
  780. //// /************************************************************/                      /*OLD_EXTAUDIO*/
  781. //// /* Allocates Read buffer for external audio file reads.     */                      /*OLD_EXTAUDIO*/
  782. //// /************************************************************/                      /*OLD_EXTAUDIO*/
  783. //// if ((ptracki->ulMisc2 = (ULONG)HhpAllocMem(hheap, DEFAULTEXTAUDIOBUFFER)) == NULL) {/*OLD_EXTAUDIO*/
  784. ////    return (MMIOERR_OUTOFMEMORY);                                                    /*OLD_EXTAUDIO*/
  785. ////    }                                                                                /*OLD_EXTAUDIO*/
  786. ////                                                                                     /*OLD_EXTAUDIO*/
  787. //// /***************************************/                                           /*OLD_EXTAUDIO*/
  788. //// /* Pre-fill the read buffer with data. */                                           /*OLD_EXTAUDIO*/
  789. //// /***************************************/                                           /*OLD_EXTAUDIO*/
  790. //// rc = mmioRead(ptracki->hmmioTrackFileHandle,                                        /*OLD_EXTAUDIO*/
  791. ////               ptracki->ulMisc2,                                                     /*OLD_EXTAUDIO*/
  792. ////               DEFAULTEXTAUDIOBUFFER);                                               /*OLD_EXTAUDIO*/
  793. //// ptracki->ulMisc3 = ptracki->ulMisc2;  /* Point to beginning of data buffer */       /*OLD_EXTAUDIO*/
  794. ////-ptracki->ulMisc4 = rc;                /* Fill in length of data */                  /*OLD_EXTAUDIO*/
  795.  
  796.    return(MMIO_SUCCESS);
  797. }
  798.  
  799.  
  800. /************************** START OF SPECIFICATIONS *************************/
  801. /*                                                                          */
  802. /* SUBROUTINE NAME:  ffProcessIntAudioHeader                                */
  803. /*                                                                          */
  804. /* DESCRIPTIVE NAME: Process an audio header LIST.                          */
  805. /*                                                                          */
  806. /* FUNCTION: Process an interleaved audio track header.                     */
  807. /*                                                                          */
  808. /* NOTES: none                                                              */
  809. /*                                                                          */
  810. /* ENTRY POINT: ffProcessIntAudioHeader                                     */
  811. /*   LINKAGE:   CALL FAR (00:32)                                            */
  812. /*                                                                          */
  813. /* INPUT:                                                                   */
  814. /*        PINSTANCE      pinstance  - Ptr to instance structure.            */
  815. /*        PAUDIOHEADER   pumahHdr   - Ptr to header (data in chunk)         */
  816. /*        ULONG          ulHdrLength - Length of header                     */
  817. /*                                                                          */
  818. /* EXIT-NORMAL:                                                             */
  819. /*              MMIO_SUCCESS                                                */
  820. /*                                                                          */
  821. /* EXIT-ERROR:                                                              */
  822. /*              MMIO_ERROR                                                  */
  823. /*              MMIOERR_INVALID_FILE                                        */
  824. /*                                                                          */
  825. /* SIDE EFFECTS:                                                            */
  826. /*                                                                          */
  827. /*************************** END OF SPECIFICATIONS **************************/
  828. LONG ffProcessIntAudioHeader ( PINSTANCE pinstance,
  829.                                PAUDIOHEADER pumahHdr,
  830.                                ULONG ulHdrLength )
  831.  
  832. {
  833.    LONG              rc = MMIO_SUCCESS;            /* Return code.         */
  834.    PTRACKI           ptracki;                      /* New node of ptracki. */
  835.    PVOID             pRawHdr;
  836.    PMMAUDIOHEADER    pmmAudioHdr;                  /* Audio header node.      */
  837.  
  838.    if (ulHdrLength != sizeof(AUDIOHEADER)) {
  839.       return(MMIOERR_INVALID_FILE);
  840.       }
  841.  
  842.    if (pumahHdr == NULL)
  843.       return(MMIO_ERROR);
  844.  
  845.    if (ptracki = ioFindTracki(pinstance,pumahHdr->usTrackNumber)) {
  846.       /* duplicate audio track headers found */
  847.       return(MMIOERR_INVALID_FILE);
  848.       }
  849.    else {
  850.  
  851.       /**********************************************************/
  852.       /* If this is a new track, creates a track node, fill     */
  853.       /* in necessary information to node.                      */
  854.       /**********************************************************/
  855.       if (!(ptracki = (PTRACKI)HhpAllocMem(hheap,(ULONG)sizeof(TRACKI)))) {
  856.          return(MMIOERR_OUTOFMEMORY);
  857.          }
  858.       ptracki->ulTrackID  = (ULONG)pumahHdr->usTrackNumber;
  859.       ptracki->ulMediaType = MMIO_MEDIATYPE_AUDIO;                //##BILL - see comment below!
  860.  
  861.  
  862.       /**********************************************************/
  863.       /* adds new node to the beginning of track list, sets     */
  864.       /* pointer ptracki of record map table to ptrackiList     */
  865.       /* that directs to decompress IOProc.                     */
  866.       /**********************************************************/
  867.       ptracki->ptrackiNext = pinstance->ptrackiList;
  868.       pinstance->ptrackiList = ptracki;
  869.  
  870.       /***************************************************************************/
  871.       /* Allocates Standard Presentation Audio Header and fills in the info.     */
  872.       /***************************************************************************/
  873.       if (!(pmmAudioHdr = (PMMAUDIOHEADER)HhpAllocMem(hheap,sizeof(MMAUDIOHEADER)))) {
  874.          return(MMIOERR_OUTOFMEMORY);
  875.          }
  876.  
  877.       pmmAudioHdr->ulHeaderLength = sizeof(MMAUDIOHEADER);
  878.       pmmAudioHdr->ulContentType  = MMIO_AUDIO_MUSIC;            //UMB specific
  879.       pmmAudioHdr->ulMediaType    = MMIO_MEDIATYPE_AUDIO;        //UMB specific
  880.  
  881.       /*
  882.        * Assign information to MMXWAV_HEADER.
  883.        */
  884.       pmmAudioHdr->mmXWAVHeader.WAVEHeader.usFormatTag      = pumahHdr->usFormatTag;
  885.       pmmAudioHdr->mmXWAVHeader.WAVEHeader.usChannels       = pumahHdr->usChannels;
  886.       pmmAudioHdr->mmXWAVHeader.WAVEHeader.ulSamplesPerSec  = pumahHdr->ulSamplesPerSec;
  887.       pmmAudioHdr->mmXWAVHeader.WAVEHeader.ulAvgBytesPerSec = pumahHdr->ulAvgBytesPerSec;
  888.       pmmAudioHdr->mmXWAVHeader.WAVEHeader.usBlockAlign     = pumahHdr->usBlockAlign;
  889.       pmmAudioHdr->mmXWAVHeader.WAVEHeader.usBitsPerSample  = pumahHdr->usBitsPerSample;
  890.  
  891.       ptracki->pTrackHeader = (PVOID)pmmAudioHdr;
  892.       ptracki->ulTrackHdrLength = sizeof(MMAUDIOHEADER);
  893.  
  894.       /***************************************************************************/
  895.       /* Allocates Raw Audio Header and fills in the info.                       */
  896.       /***************************************************************************/
  897.       if (!(pRawHdr = (PVOID)HhpAllocMem(hheap,sizeof(AUDIOHEADER)))) {
  898.          return(MMIOERR_OUTOFMEMORY);
  899.          }
  900.       memcpy(pRawHdr,pumahHdr,sizeof(AUDIOHEADER));
  901.       ptracki->pRawHdr = pRawHdr;
  902.       ptracki->ulRawHdrLength = sizeof(AUDIOHEADER);
  903.       } /* else */
  904.  
  905.    return(MMIO_SUCCESS);
  906. }
  907.  
  908.  
  909. //################################################################################################
  910. //################################################################################################
  911. //################################################################################################
  912. //LONG ffProcessVideoTitle ( PINSTANCE pinstance,
  913. //                           PVOID  pHdr )
  914. //
  915. //{
  916. //   // BETA - UNSUPPORTED FUNCTION!!!!!!!
  917. //   //
  918. //   // Cases to handle:
  919. //   //          - Search last video tracki (Only one in theis case)
  920. //   //          - if none, error
  921. //   //          - else, add the video title to the list of video titles in tracki structure!
  922. //   //
  923. //   return(MMIO_SUCCESS);
  924. //}
  925. //################################################################################################
  926. ///* pHdr points to the data in the chunk */
  927. //LONG ffProcessTextHeaderList ( PINSTANCE pinstance,
  928. //                               PVOID  pHdr,
  929. //                               ULONG  ulChunkLength )
  930. //
  931. //{
  932. //   // BETA - UNSUPPORTED FUNCTION!!!!!!!
  933. //   //
  934. //   // Cases to handle:
  935. //   //          - case HEX_UMID_TEXTHEADER
  936. //   //          - Create track
  937. //   //          - Read video header
  938. //   //
  939. //   return(MMIO_SUCCESS);
  940. //}
  941.