home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv6.zip / vac22os2 / ibmcobol / samples / toolkit / mm / ultimoio / iocodec.c < prev    next >
C/C++ Source or Header  |  1996-11-19  |  45KB  |  994 lines

  1. /*************************START OF SPECIFICATIONS *************************/
  2. /* SOURCE FILE NAME:  IOCODEC.C                                           */
  3. /*                                                                        */
  4. /* DESCRIPTIVE NAME: File Format IO Proc codec interfaces                 */
  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 routine.                     */
  13. /*                                                                        */
  14. /* NOTES:                                                                 */
  15. /*    DEPENDENCIES: none                                                  */
  16. /*    RESTRICTIONS: Runs in 32 bit protect mode (OS/2 2.0)                */
  17. /*                                                                        */
  18. /* ENTRY POINTS:                                                          */
  19. /*     ioDetermineCodec                                                   */
  20. /*     ioLoadCodecDLL                                                     */
  21. /*     ioLoadCodec                                                        */
  22. /*     ioFindCodec                                                        */
  23. /*     ioCloseCodec                                                       */
  24. /*     ioInitCodecopen                                                    */
  25. /*     ioAssociateCodec                                                   */
  26. /*                                                                        */
  27. /* DATE      DEVELOPER   DEFECT  CHANGE DESCRIPTION           CHANGE FLAG */
  28. /* ---       ---------   ------  ------------------------     ----------- */
  29. /* 07/29/93  DJ Dobkin   9983    Associate codec to new file  @D01        */
  30. /* 08-02-93  LL Post     9744    ioAssociateCodecPlay and                 */
  31. /*                               ioDetermineCodecPlay (new                */
  32. /*                               functions)                               */
  33. /* 04-20-94  LL Post     12236   Add MM_DosLoadModule for speed @LP01     */
  34. /* 05.31.94  WL Sharp    12384   Integrate Compressed Audio Support       */
  35. /* 06.22.94  WL Sharp    12757   Add MPEG Hardware Playback Support @W1   */
  36. /* 08.29.94  W. Sharp    13674   DIVE fixes for I-frame healing           */
  37. /* 09.15.94  WL Sharp    14079   Default to comprssn if codec does both   */
  38. /* 09.20.94  LL Post     14079   Dont in case of audio compression @LP02  */
  39. /* 09.23.94  WL Sharp    14235   Fix RT record of MONDO                   */
  40. /************************* END OF SPECIFICATIONS **************************/
  41.  
  42.  
  43. #include        <stdio.h>
  44. #include        <string.h>
  45. #include        <stdlib.h>
  46. #include        <memory.h>
  47.  
  48. #define         INCL_DOS                      /* #define  INCL_DOSPROCESS  */
  49. #define         INCL_ERRORS
  50. #define         INCL_WIN
  51. #define         INCL_GPI
  52. #include        <os2.h>                       /* OS/2 headers              */
  53. #include        <pmbitmap.h>
  54.  
  55. #define         INCL_OS2MM
  56. #define         INCL_MMIO_CODEC
  57. #define         INCL_MMIO_DOSIOPROC
  58. #include        <os2me.h>                     /* Multi-Media IO extensions */
  59. #include        <hhpheap.h>
  60. #include        <ioi.h>
  61. #include        <mmdsload.h>               /* MM_DosLoadModule defines @LP01 */
  62.  
  63.  
  64.    extern HHUGEHEAP hheap;                        /* Heap of memory.        */
  65.    extern CODECINIFILEINFO acifiTable[];
  66.    extern ULONG    ulNumColors;                   /* added to correct multiinstance problem */
  67.    extern HMTX hmtxGlobalHeap;
  68.  
  69.  
  70. LONG ioCheckCodecList(PINSTANCE pinstance)
  71.  
  72. {
  73.  
  74. //
  75. // Check for existance of pccbList and create it if it doesn't exist
  76. // Is there a better place to do this???
  77. // WLS 3.15.94
  78. //
  79.  
  80.    if (!pinstance->pccbList) {
  81.       pinstance->pccbList = HhpAllocMem(hheap, pinstance->pmmhdr->ulNumEntries * sizeof (PCCB));
  82.       if (!pinstance->pccbList) {
  83.          return(MMIOERR_OUTOFMEMORY);
  84.          }
  85.       }
  86.  
  87.    return(MMIO_SUCCESS);
  88. }
  89.  
  90. LONG ioDetermineBitCount(PCODECINIFILEINFO pcifi)
  91.  
  92. {
  93.    HPS               hps;                /* only used to query color support */
  94.    HAB               hab;                /* anchor block */
  95.  
  96. //
  97. //WLS 3.15.94 - Don't get color stuff for Audio Codec
  98. //There should be a better way to determine the color depth needed!!!!!!
  99. //
  100.  
  101.    if ((pcifi->ulCapsFlags & CODEC_DECOMPRESS) && (pcifi->ulMediaType != MMIO_MEDIATYPE_AUDIO)) {
  102.       /* Query the display mode */
  103.       if (ulNumColors == 0) {       /* Get this info once per process */
  104.          hab  = WinInitialize(0);
  105.  
  106.          hps  = WinGetPS(HWND_DESKTOP);
  107.          DevQueryCaps ( GpiQueryDevice(hps),
  108.                         CAPS_COLORS,
  109.                         1L,
  110.                         (PLONG)&ulNumColors);
  111.  
  112.          WinReleasePS (hps);
  113.          WinTerminate (hab);
  114.          }
  115.  
  116.       /* Set the color depth for the CODEC we want */
  117.       if (ulNumColors == 16)
  118.          pcifi->ulCapsFlags |= CODEC_4_BIT_COLOR;
  119.       else if (ulNumColors == 65536)
  120.          pcifi->ulCapsFlags |= CODEC_16_BIT_COLOR;
  121.       else if (ulNumColors == 16777216)
  122.          pcifi->ulCapsFlags |= CODEC_24_BIT_COLOR;
  123.       else  /* 256 and anything else */
  124.          pcifi->ulCapsFlags |= CODEC_8_BIT_COLOR;
  125.       }
  126.  
  127.    return(MMIO_SUCCESS);
  128. }
  129.  
  130. /************************** START OF SPECIFICATIONS *************************/
  131. /*                                                                          */
  132. /* SUBROUTINE NAME: ioDetermineCodec                                        */
  133. /*                                                                          */
  134. /* DESCRIPTIVE NAME: Determine which codec should be loaded for this        */
  135. /*                   FOURCC, COMPRESSTYPE, CAPSFLAGS, ColorDepth,           */
  136. /*                   COMPRESS or DECOMPRESS.                                */
  137. /*                                                                          */
  138. /* FUNCTION: This function Determines the CODEC to load.                    */
  139. /*                                                                          */
  140. /* NOTES: Picks the default if there is one.                                */
  141. /*                                                                          */
  142. /* ENTRY POINT: ioDetermineCodec                                            */
  143. /*   LINKAGE:   CALL FAR (00:32)                                            */
  144. /*                                                                          */
  145. /* INPUT:                                                                   */
  146. /*              PINSTANCE  pinstance                                        */
  147. /*              ULONG      ulSearchFlags                                    */
  148. /*              PCODECINIFILEINFO pcifi                                     */
  149. /*                                                                          */
  150. /* EXIT-NORMAL:                                                             */
  151. /*              pcifi  contains found codec info                            */
  152. /*              rc = MMIO_SUCCESS                                           */
  153. /* EXIT-ERROR:                                                              */
  154. /*              MMIO_ERROR                                                  */
  155. /*              MMIOERR_CODEC_NOT_SUPPORTED                                 */
  156. /*                                                                          */
  157. /* SIDE EFFECTS:                                                            */
  158. /*                                                                          */
  159. /*************************** END OF SPECIFICATIONS **************************/
  160. LONG ioDetermineCodec ( PINSTANCE pinstance,
  161.                         ULONG ulSearchFlags,
  162.                         PCODECINIFILEINFO pcifi )
  163.  
  164. {
  165.    LONG              rc = MMIO_SUCCESS;  /* Return code of IOProc's call. */
  166.    USHORT            i;                  /* Loop index.       */
  167.    ULONG             ulFlags = 0;
  168.    ULONG             ulExtraFlags = 0;
  169.  
  170. // ADD EXTRA SEARCH FLAGS IF VALUES ARE NOT EMPTY
  171.  
  172.    if (strcmp(pcifi->szDLLName, "")) {
  173.       ulExtraFlags |= MMIO_MATCHDLL;
  174.       }
  175.  
  176.    if (strcmp(pcifi->szProcName, "")) {
  177.       ulExtraFlags |= MMIO_MATCHPROCEDURENAME;
  178.       }
  179.  
  180.    /***************************************************************************/
  181.    /* Search for the DEFAULT codec of this type from the MMIO INI file        */
  182.    /***************************************************************************/
  183.    /***************************************************************************/
  184.    /* If no default, find first one and use it from the MMIO INI file         */
  185.    /***************************************************************************/
  186.  
  187.    pcifi->ulCapsFlags |= CODEC_DEFAULT;   /* Pick default */
  188.    for (i = 0; i < 2; i++) {
  189.  
  190.       ulFlags = ulSearchFlags | ulExtraFlags |
  191.                  MMIO_MATCHFOURCC |
  192.                  MMIO_MATCHCOMPRESSTYPE |
  193.                  MMIO_MATCHCAPSFLAGS |
  194.                  MMIO_MATCHFIRST |
  195.                  MMIO_FINDPROC;
  196.  
  197.       if (!(rc = mmioIniFileCODEC(pcifi,ulFlags))) {
  198.          return(MMIO_SUCCESS);
  199.          }
  200.  
  201.       pcifi->ulCapsFlags &= ~CODEC_DEFAULT;
  202.       }
  203.  
  204. //
  205. // LESSEN THE SEARCH - DON'T INCLUDE DLLNAME OR PROCNAME
  206. //
  207.  
  208.    /***************************************************************************/
  209.    /* Search for the DEFAULT codec of this type from the MMIO INI file        */
  210.    /***************************************************************************/
  211.    /***************************************************************************/
  212.    /* If no default, find first one and use it from the MMIO INI file         */
  213.    /***************************************************************************/
  214.  
  215.    pcifi->ulCapsFlags |= CODEC_DEFAULT;   /* Pick default */
  216.    for (i = 0; i < 2; i++) {
  217.       ulFlags = ulSearchFlags |
  218.                 MMIO_MATCHFOURCC |
  219.                 MMIO_MATCHCOMPRESSTYPE |
  220.                 MMIO_MATCHCAPSFLAGS |
  221.                 MMIO_MATCHFIRST |
  222.                 MMIO_FINDPROC;
  223.  
  224.       if (!(rc = mmioIniFileCODEC(pcifi,ulFlags))) {
  225.          return(MMIO_SUCCESS);
  226.          }
  227.  
  228.       pcifi->ulCapsFlags &= ~CODEC_DEFAULT;
  229.       }
  230.  
  231.    /***************************************************************************/
  232.    /* Search any internal CODEC tables for the necessary CODEC to load.       */
  233.    /* Note: This is used for debugging new CODEC's that have not been added   */
  234.    /*       to the mmpmmmio.ini file.                                         */
  235.    /***************************************************************************/
  236.    for (i = 0; i < NUMBER_CODEC_TABLE; i++) {
  237.  
  238.       if ((acifiTable[i].ulCompressType == pcifi->ulCompressType) &&
  239.           ((acifiTable[i].ulCapsFlags & pcifi->ulCapsFlags) == pcifi->ulCapsFlags)) {
  240.  
  241.          *pcifi = acifiTable[i];         /* Copy contents */
  242.          return(MMIO_SUCCESS);
  243.          }
  244.       }
  245.  
  246.  
  247.    return(MMIOERR_CODEC_NOT_SUPPORTED);
  248. }
  249.  
  250.  
  251.  
  252. /************************** START OF SPECIFICATIONS *************************/
  253. /*                                                                          */
  254. /* SUBROUTINE NAME:  ioLoadCodecDLL                                         */
  255. /*                                                                          */
  256. /* DESCRIPTIVE NAME: Load a CODEC IO Proc and add it the PCCB list          */
  257. /*                                                                          */
  258. /* FUNCTION: This function loads a CODEC IO Proc and adds it to the linked  */
  259. /*           list of CODECs currently loaded for this movie instance.       */
  260. /*                                                                          */
  261. /* NOTES:                                                                   */
  262. /*                                                                          */
  263. /* ENTRY POINT: ioLoadCodecDLL                                              */
  264. /*   LINKAGE:   CALL FAR (00:32)                                            */
  265. /*                                                                          */
  266. /* INPUT:                                                                   */
  267. /*             PINSTANCE pinstance     - Instant structure.                 */
  268. /*             PCODECINIFILEINFO pcifi - CODEC ini file information         */
  269. /*             PULONG phCodec          - Returns hCodec of any sibling codec*/
  270. /*                                                                          */
  271. /* EXIT-NORMAL:                                                             */
  272. /*              pccb                                                        */
  273. /*                                                                          */
  274. /* EXIT-ERROR:                                                              */
  275. /*              0L                                                          */
  276. /*                                                                          */
  277. /* SIDE EFFECTS:                                                            */
  278. /*                                                                          */
  279. /*************************** END OF SPECIFICATIONS **************************/
  280. PCCB ioLoadCodecDLL ( PINSTANCE pinstance,
  281.                       PCODECINIFILEINFO pcifi,
  282.                       PULONG phCodec,
  283.                       ULONG ulTrack )
  284.  
  285. {
  286.    LONG      rc = MMIO_SUCCESS;           /* Return code of IOProc's call. */
  287.    SZ        szLoadError[260];            /* Error returns.          */
  288.    PCCB      pccbNew;
  289.    PCCB      pccb;
  290.    HMODULE   hmod = 0L;
  291.    PMMIOPROC pmmioproc;
  292.    ULONG     hCodec = 0L;
  293.    ULONG     ulCount;
  294.  
  295.    ioCheckCodecList(pinstance);
  296.  
  297.    /**************************************************************************/
  298.    /* Search if the CCB entry has been created for the passed in             */
  299.    /* pszDLLName and pszProcName,if yes, then sets pccb    pointer of        */
  300.    /* ptracki to that node.(different track may share a same CCB)            */
  301.    /**************************************************************************/
  302.    for (ulCount = 0; ulCount < pinstance->pmmhdr->ulNumEntries; ulCount++) {
  303.       for (pccb = pinstance->pccbList[ulCount]; pccb; pccb = pccb->pccbNext) {
  304.  
  305.          if (!stricmp(pcifi->szDLLName,pccb->cifi.szDLLName)) {
  306.             hCodec = pccb->hCodec;
  307.  
  308.             if (!stricmp(pcifi->szProcName,pccb->cifi.szProcName)) {
  309.                /* Proc entry names match */
  310.                return(pccb);
  311.                }
  312.             }
  313.          } /* end loop */
  314.       }
  315.  
  316.    /**************************************************************************/
  317.    /* the above searching can't find the DCIO node, if a same DLLName was    */
  318.    /* found, query IOProc address directly, else load module then query I/O  */
  319.    /* address before allocates a new pccb node.                              */
  320.    /**************************************************************************/
  321.    if (MM_DosLoadModule(szLoadError,                         //@LP01
  322.                      (ULONG)sizeof(szLoadError),
  323.                      pcifi->szDLLName,
  324.                      &hmod))   {
  325.       /* Load Error - MMIOERR_INVALID_DLLNAME */
  326.       return(NULL);
  327.       }
  328.  
  329.    if (DosQueryProcAddr(hmod,
  330.                         0L,
  331.                         pcifi->szProcName,
  332.                         (PFN *)&pmmioproc))   {
  333.       /* Query Error - MMIOERR_INVALID_PROCEDURENAME */
  334.       return(NULL);
  335.       }
  336.  
  337.    /**************************************************************************/
  338.    /* The above loading and querying was successful, then create a new node  */
  339.    /* for the DCIO. If HhpAllocMem fails, call DosFreeModule to free DCIO    */
  340.    /* module before returning error.                                         */
  341.    /**************************************************************************/
  342.    if (ENTERCRIT(rc)) {
  343.       return(NULL);
  344.       }
  345.  
  346.    pccbNew = (PCCB)HhpAllocMem(hheap,(ULONG)sizeof(CCB));
  347.  
  348.    EXITCRIT;
  349.  
  350.    if(!pccbNew) {
  351.       DosFreeModule(hmod);
  352.       /* Allocate error - MMIOERR_OUTOFMEMORY */
  353.       return(NULL);
  354.       }
  355.  
  356.    /**************************************************************************/
  357.    /* Assigns the Decompress IOProc information, which is in record map      */
  358.    /* table, to the new DCIO node.                                           */
  359.    /**************************************************************************/
  360.    pccbNew->cifi = *pcifi;
  361.    pccbNew->hmodule = hmod;
  362.    pccbNew->pmmioproc = pmmioproc;
  363.    pccbNew->hCodec = 0L;
  364.    pccbNew->ulLastSrcBuf = 0L;
  365.    pccbNew->ulMisc1 = 0L;
  366.    pccbNew->ulMisc2 = 0L;
  367.  
  368.    /**************************************************************************/
  369.    /* adds new node to the beginning of ccb list.                            */
  370.    /**************************************************************************/
  371.    pccbNew->pccbNext = pinstance->pccbList[ulTrack];
  372.    pinstance->pccbList[ulTrack] = pccbNew;
  373.  
  374.    *phCodec = hCodec;
  375.    return(pccbNew);
  376. }
  377.  
  378.  
  379.  
  380. /************************** START OF SPECIFICATIONS *************************/
  381. /*                                                                          */
  382. /* SUBROUTINE NAME:  ioLoadCodec                                            */
  383. /*                                                                          */
  384. /* DESCRIPTIVE NAME: Load a CODEC IO Proc and add it the PCCB list          */
  385. /*                                                                          */
  386. /* FUNCTION: This function loads a CODEC IO Proc and adds it to the linked  */
  387. /*           list of CODECs currently loaded for this movie instance.       */
  388. /*                                                                          */
  389. /* NOTES:                                                                   */
  390. /*                                                                          */
  391. /* ENTRY POINT: ioLoadCodec                                                 */
  392. /*   LINKAGE:   CALL FAR (00:32)                                            */
  393. /*                                                                          */
  394. /* INPUT:                                                                   */
  395. /*             PINSTANCE pinstance     - Instant structure.                 */
  396. /*             PTRACKI ptracki         - Track specific information         */
  397. /*             PCODECINIFILEINFO pcifi - CODEC ini file information         */
  398. /*                                                                          */
  399. /* EXIT-NORMAL:                                                             */
  400. /*              pccb                                                        */
  401. /*                                                                          */
  402. /* EXIT-ERROR:                                                              */
  403. /*              0L                                                          */
  404. /*                                                                          */
  405. /* SIDE EFFECTS:                                                            */
  406. /*                                                                          */
  407. /*************************** END OF SPECIFICATIONS **************************/
  408. PCCB ioLoadCodec ( PMMIOINFO pmmioinfo,         //@W1
  409.                    PINSTANCE pinstance,
  410.                    PTRACKI ptracki,
  411.                    PCODECINIFILEINFO pcifi )
  412.  
  413. {
  414.    LONG      rc = MMIO_SUCCESS;           /* Return code of IOProc's call. */
  415.    PCCB      pccbNew;
  416.    ULONG     hCodec = 0L;
  417.    ULONG     ulTrack = ptracki->ulTrackID;
  418.  
  419.    ioCheckCodecList(pinstance);
  420.  
  421.    if (pccbNew = ioLoadCodecDLL(pinstance,pcifi,&hCodec, ulTrack)) {
  422.  
  423.       /**************************************************************************/
  424.       /* Open the Codec IO Proc and save the hCodec in the pccb structure       */
  425.       /**************************************************************************/
  426.       if (rc = ffOpenCodec(pmmioinfo, pinstance, pccbNew, hCodec, ptracki)) {  //@W1
  427.  
  428.          pinstance->pccbList[ulTrack] = pccbNew->pccbNext;   /* unlink from list */
  429.          ioCloseCodec(pccbNew);
  430.          pccbNew = NULL;  /* return error condition */
  431.          }
  432.       }
  433.  
  434.    return(pccbNew);
  435. }
  436.  
  437.  
  438.  
  439. /************************** START OF SPECIFICATIONS *************************/
  440. /*                                                                          */
  441. /* SUBROUTINE NAME:  ioFindCodec                                            */
  442. /*                                                                          */
  443. /* DESCRIPTIVE NAME:                                                        */
  444. /*                                                                          */
  445. /* FUNCTION: This function finds a compression/decompression control block  */
  446. /*           for this compression type.                                     */
  447. /*                                                                          */
  448. /* NOTES: None                                                              */
  449. /*                                                                          */
  450. /* ENTRY POINT: ioFindCodec                                                 */
  451. /*   LINKAGE:   CALL FAR (00:32)                                            */
  452. /*                                                                          */
  453. /* INPUT:                                                                   */
  454. /*           PINSTANCE   pinstance  - Movie instance structure              */
  455. /*           ULONG       ulCompressType - Compression type                  */
  456. /*                                                                          */
  457. /*                                                                          */
  458. /* EXIT-NORMAL:                                                             */
  459. /*              pccb                                                        */
  460. /*                                                                          */
  461. /* EXIT-ERROR:                                                              */
  462. /*              NULL - 0L                                                   */
  463. /*                                                                          */
  464. /*                                                                          */
  465. /* SIDE EFFECTS:                                                            */
  466. /*                                                                          */
  467. /*************************** END OF SPECIFICATIONS **************************/
  468. PCCB ioFindCodec ( PINSTANCE pinstance,
  469.                    ULONG ulCompressType )
  470.  
  471. {
  472.    PCCB   pccb;
  473.    ULONG  ulCount;
  474.  
  475.    ioCheckCodecList(pinstance);
  476.  
  477.    for (ulCount = 0; ulCount < pinstance->pmmhdr->ulNumEntries; ulCount++) {
  478.       for (pccb = pinstance->pccbList[ulCount]; pccb; pccb = pccb->pccbNext) {
  479.          if (pccb->cifi.ulCompressType == ulCompressType)
  480.             return(pccb);
  481.          }
  482.       }
  483.    return(NULL);  /* not found */
  484. }
  485.  
  486.  
  487.  
  488. /************************** START OF SPECIFICATIONS *************************/
  489. /*                                                                          */
  490. /* SUBROUTINE NAME:  ioCloseCodec                                           */
  491. /*                                                                          */
  492. /* DESCRIPTIVE NAME:                                                        */
  493. /*                                                                          */
  494. /* FUNCTION: This function Closes a codec instance for a movie instance.    */
  495. /*           This is called upon a unrecoverable error or on movie close.   */
  496. /*                                                                          */
  497. /* NOTES: None                                                              */
  498. /*                                                                          */
  499. /* ENTRY POINT: ioCloseCodec                                                */
  500. /*   LINKAGE:   CALL FAR (00:32)                                            */
  501. /*                                                                          */
  502. /* INPUT:                                                                   */
  503. /*           PCCB        pccb       - Pointer to codec control structure.   */
  504. /*                                                                          */
  505. /*                                                                          */
  506. /* EXIT-NORMAL:                                                             */
  507. /*              MMIO_SUCCESS                                                */
  508. /*                                                                          */
  509. /* EXIT-ERROR:                                                              */
  510. /*              MMIO_ERROR                                                  */
  511. /*                                                                          */
  512. /*                                                                          */
  513. /* SIDE EFFECTS:                                                            */
  514. /*                                                                          */
  515. /*************************** END OF SPECIFICATIONS **************************/
  516. LONG ioCloseCodec ( PCCB pccb )
  517.  
  518. {
  519.    LONG       rc = MMIO_SUCCESS;           /* Return code of IOProc's call. */
  520.  
  521.    ENTERCRITX;
  522.    if (pccb->codecopen.pSrcHdr) {
  523.       HhpFreeMem(hheap,(PVOID)pccb->codecopen.pSrcHdr);
  524.       }
  525.  
  526.    if (pccb->codecopen.pDstHdr) {
  527.       HhpFreeMem(hheap,(PVOID)pccb->codecopen.pDstHdr);
  528.       }
  529.  
  530.    if (pccb->codecopen.pControlHdr) {
  531.       HhpFreeMem(hheap,(PVOID)pccb->codecopen.pControlHdr);
  532.       }
  533.  
  534.    if (pccb->codecopen.pOtherInfo) {
  535.       HhpFreeMem(hheap,(PVOID)pccb->codecopen.pOtherInfo);
  536.       }
  537.  
  538.    if (pccb->hCodec) {
  539.       rc = pccb->pmmioproc(&pccb->hCodec,
  540.                            MMIOM_CODEC_CLOSE,
  541.                            0L,
  542.                            0L);
  543.  
  544.       if (!rc) {
  545.          pccb->hCodec = 0L;
  546.          }
  547.       }
  548.  
  549.    if (pccb->hmodule) {
  550. //----DosFreeModule(pccb->hmodule);
  551.       pccb->hmodule = 0;
  552.       }
  553.  
  554.    HhpFreeMem(hheap,(PVOID)pccb);
  555.    pccb = NULL;
  556.    EXITCRIT;
  557.  
  558.    return(rc);
  559. }
  560.  
  561.  
  562. /************************** START OF SPECIFICATIONS *************************/
  563. /*                                                                          */
  564. /* SUBROUTINE NAME: ioInitCodecopen                                         */
  565. /*                                                                          */
  566. /* DESCRIPTIVE NAME: Allocate and initialize a CODECOPEN structure to be    */
  567. /*                   saved in the CCB. Copy info from input CODECOPEN.      */
  568. /*                                                                          */
  569. /* FUNCTION: This function allocates a CODECOPEN structure.                 */
  570. /*                                                                          */
  571. /* NOTES: None                                                              */
  572. /*                                                                          */
  573. /* ENTRY POINT: ioInitCodecopen                                             */
  574. /*   LINKAGE:   CALL FAR (00:32)                                            */
  575. /*                                                                          */
  576. /* INPUT:                                                                   */
  577. /*              PCCB          pccb                                          */
  578. /*              PCODECOPEN    pcodecopen                                    */
  579. /*                                                                          */
  580. /* EXIT-NORMAL:                                                             */
  581. /*              rc = MMIO_SUCCESS                                           */
  582. /* EXIT-ERROR:                                                              */
  583. /*              MMIO_ERROR                                                  */
  584. /*                                                                          */
  585. /* SIDE EFFECTS:                                                            */
  586. /*                                                                          */
  587. /*************************** END OF SPECIFICATIONS **************************/
  588. LONG ioInitCodecopen ( PCCB pccb,
  589.                        PCODECOPEN pcodecopen)
  590.  
  591. {
  592.    ULONG             ulSize;
  593.  
  594.  
  595.    ENTERCRITX;
  596.    pccb->codecopen.ulFlags = pcodecopen->ulFlags;
  597.  
  598.    /* Create and copy Pointers to structures in CODECOPEN structure */
  599.    if (pcodecopen->pControlHdr) {
  600.       ulSize = *((PULONG)pcodecopen->pControlHdr);
  601.       if (!(pccb->codecopen.pControlHdr = (PVOID)HhpAllocMem(hheap,ulSize))) {
  602.          return(MMIO_ERROR);
  603.          }
  604.       memcpy(pccb->codecopen.pControlHdr, pcodecopen->pControlHdr, ulSize);
  605.       }
  606.  
  607.    if (pcodecopen->pSrcHdr) {
  608.       ulSize = *((PULONG)pcodecopen->pSrcHdr);
  609.       if (!(pccb->codecopen.pSrcHdr = (PVOID)HhpAllocMem(hheap,ulSize))) {
  610.          return(MMIO_ERROR);
  611.          }
  612.       memcpy(pccb->codecopen.pSrcHdr, pcodecopen->pSrcHdr, ulSize);
  613.       }
  614.  
  615.    if (pcodecopen->pDstHdr) {
  616.       ulSize = *((PULONG)pcodecopen->pDstHdr);
  617.       if (!(pccb->codecopen.pDstHdr = (PVOID)HhpAllocMem(hheap,ulSize))) {
  618.          return(MMIO_ERROR);
  619.          }
  620.       memcpy(pccb->codecopen.pDstHdr, pcodecopen->pDstHdr, ulSize);
  621.       }
  622.  
  623.    if (pcodecopen->pOtherInfo) {
  624.       ulSize = *((PULONG)pcodecopen->pOtherInfo);
  625.       if (!(pccb->codecopen.pOtherInfo = (PVOID)HhpAllocMem(hheap,ulSize))) {
  626.          return(MMIO_ERROR);
  627.          }
  628.       memcpy(pccb->codecopen.pOtherInfo, pcodecopen->pOtherInfo, ulSize);
  629.       }
  630.  
  631.    EXITCRIT;
  632.    return(MMIO_SUCCESS);
  633. }
  634.  
  635.  
  636.  
  637. /************************** START OF SPECIFICATIONS *************************/
  638. /*                                                                          */
  639. /* SUBROUTINE NAME: ioAssociateCodec                                        */
  640. /*                                                                          */
  641. /* DESCRIPTIVE NAME: Associate CODECs with a file(track). Use this codec    */
  642. /*                   to compress frames to be written to a file.            */
  643. /*                                                                          */
  644. /* FUNCTION: This function associates a CODEC with a file (track).          */
  645. /*                                                                          */
  646. /* NOTES: None                                                              */
  647. /*                                                                          */
  648. /* ENTRY POINT: ioAssociateCodec                                            */
  649. /*   LINKAGE:   CALL FAR (00:32)                                            */
  650. /*                                                                          */
  651. /* INPUT:                                                                   */
  652. /*              PINSTANCE  pinstance                                        */
  653. /*              PMMEXTENDEDINFO pmmextendedinfo                             */
  654. /*                                                                          */
  655. /* EXIT-NORMAL:                                                             */
  656. /*              rc = MMIO_SUCCESS                                           */
  657. /* EXIT-ERROR:                                                              */
  658. /*              MMIO_ERROR                                                  */
  659. /*                                                                          */
  660. /* SIDE EFFECTS:                                                            */
  661. /*              Codec is added to CCB link-list and the codecs are opened.  */
  662. /*                                                                          */
  663. /*************************** END OF SPECIFICATIONS **************************/
  664.  
  665.  
  666. #ifdef MMDEBUG
  667. int print_codec_structure(PCODECOPEN pco)
  668.  
  669. {
  670.    if (pco->pControlHdr) {
  671.       printf("pControlHdr (CODEC SPECIFIC INFO) : %0x%x\n", pco->pControlHdr);
  672.       }
  673.  
  674.    if (pco->pSrcHdr) {
  675.       PCODECVIDEOHEADER pcoHdr = (PCODECVIDEOHEADER) (pco->pSrcHdr);
  676.       printf("pSrcHdr (CODECVIDEOHEADER)\n");
  677.       printf("ulStructLen     : %d\n",   pcoHdr->ulStructLen     );
  678.       printf("cx              : %d\n",   pcoHdr->cx              );
  679.       printf("cy              : %d\n",   pcoHdr->cy              );
  680.       printf("cPlanes         : %d\n",   pcoHdr->cPlanes         );
  681.       printf("cBitCount       : %d\n",   pcoHdr->cBitCount       );
  682.       printf("ulColorEncoding : 0x%x\n", pcoHdr->ulColorEncoding );
  683.       printf("genpal\n");
  684.       printf("   ulStartIndex: %d\n",   pcoHdr->genpal.ulStartIndex);
  685.       printf("   ulNumColors : %d\n",   pcoHdr->genpal.ulNumColors);
  686.       printf("   prgb2Entries: 0x%x\n", pcoHdr->genpal.prgb2Entries);
  687.       printf("\n");
  688.       }
  689.  
  690.    if (pco->pDstHdr) {
  691.       PCODECVIDEOHEADER pcoHdr = (PCODECVIDEOHEADER) (pco->pDstHdr);
  692.       printf("pDstHdr (CODECVIDEOHEADER)\n");
  693.       printf("ulStructLen     : %d\n",   pcoHdr->ulStructLen     );
  694.       printf("cx              : %d\n",   pcoHdr->cx              );
  695.       printf("cy              : %d\n",   pcoHdr->cy              );
  696.       printf("cPlanes         : %d\n",   pcoHdr->cPlanes         );
  697.       printf("cBitCount       : %d\n",   pcoHdr->cBitCount       );
  698.       printf("ulColorEncoding : 0x%x\n", pcoHdr->ulColorEncoding );
  699.       printf("genpal          : 0x%x\n", pcoHdr->genpal          );
  700.       printf("genpal\n");
  701.       printf("   ulStartIndex: %d\n",   pcoHdr->genpal.ulStartIndex);
  702.       printf("   ulNumColors : %d\n",   pcoHdr->genpal.ulNumColors);
  703.       printf("   prgb2Entries: 0x%x\n", pcoHdr->genpal.prgb2Entries);
  704.       printf("\n");
  705.       }
  706.  
  707.    if (pco->pOtherInfo) {
  708.       PMMVIDEOOPEN mmvo = (PMMVIDEOOPEN) pco->pOtherInfo;
  709.       printf("pOtherInfo (MMVIDEOOPEN)\n");
  710.       printf("ulStructLen          : %d\n", mmvo->ulStructLen          );
  711.       printf("ulQuality            : %d\n", mmvo->ulQuality            );
  712.       printf("ulKeyFrameRate       : %d\n", mmvo->ulKeyFrameRate       );
  713.       printf("ulScale              : %d\n", mmvo->ulScale              );
  714.       printf("ulRate               : %d\n", mmvo->ulRate               );
  715.       printf("ulDataConstraint     : %d\n", mmvo->ulDataConstraint     );
  716.       printf("ulConstraintInterval : %d\n", mmvo->ulConstraintInterval );
  717.       printf("\n");
  718.       }
  719. }
  720. #endif
  721.  
  722.  
  723. #define CODEC_BIT_FLAGS ~(CODEC_4_BIT_COLOR | CODEC_16_BIT_COLOR | \
  724.                           CODEC_8_BIT_COLOR | CODEC_24_BIT_COLOR)
  725.  
  726. LONG ioAssociateCodec ( PMMIOINFO pmmioinfo,
  727.                         PINSTANCE pinstance,
  728.                         PCODECASSOC pcodecassoc,
  729.                         ULONG fUseDefaultBitCount)
  730.  
  731. {
  732.    PCODECINIFILEINFO  pcifi = pcodecassoc->pCODECIniFileInfo;
  733.    PCODECOPEN         pco;
  734.    PCODECVIDEOHEADER  pcoDstHdr;
  735.    PCODECVIDEOHEADER  pcoSrcHdr;
  736.    PMMVIDEOHEADER     pmmVidHdr;
  737.    PMMVIDEOOPEN       pmmVidOpn;
  738.    PTRACKI            ptracki;
  739.    LONG   rc = MMIO_SUCCESS;  /* Return code of IOProc's call. */
  740.    PCCB   pccb;
  741.    ULONG  hCodec;  /* Possibly returned from ioLoadCodecDLL */
  742.    ULONG  ulType = 0;
  743.    ULONG  ulTrack = pinstance->lCurrentTrack;
  744.    ULONG  ulFPS;
  745.  
  746.    ioCheckCodecList(pinstance);
  747.  
  748.    /* Check for NULL pointers */
  749.    if (!pcodecassoc->pCodecOpen || !pcodecassoc->pCODECIniFileInfo) {
  750.       return (MMIOERR_INVALID_PARAMETER);
  751.       }
  752.  
  753.    /* Force the correct values into the codecinfileinfo structure */
  754.    pcifi->ulStructLen = sizeof(CODECINIFILEINFO);
  755. // Can't do for WAVE stuff
  756.    if (!pcifi->fcc)
  757.       pcifi->fcc = pmmioinfo->fccIOProc;
  758.  
  759.  
  760. //
  761. // If we are associating a new compressor, we must update the header
  762. // information in the file and load the codec based upon the colorspace
  763. // defined in the CAPSFLAG.  If we are opening up a decompressor, we don't
  764. // need to modify the file at all.  If no CAPSFLAGs are defined for the
  765. // bitcount, we will use the bit count from the Destination Header.
  766. //
  767.  
  768. // if the codec can do both, default to compression - Mondo, Indeo 2.1
  769.  
  770. //   if (pcifi->ulCapsFlags & CODEC_DECOMPRESS) {
  771. //   if (!(pcifi->ulCapsFlags & CODEC_COMPRESS)) {
  772.    if ((!(pcifi->ulCapsFlags & CODEC_COMPRESS)) && (pcifi->ulCapsFlags & CODEC_DECOMPRESS)) { //14235
  773.       ulType = CODEC_DECOMPRESS;
  774.       pcifi->ulCapsFlags = CODEC_DECOMPRESS;
  775.       if (fUseDefaultBitCount) {
  776.          ioDetermineBitCount(pcifi);
  777.          }
  778.       else {
  779.  
  780.          if (pcifi->ulMediaType != MMIO_MEDIATYPE_AUDIO) {
  781.  
  782.             pco       = (PCODECOPEN)        (pcodecassoc->pCodecOpen);
  783.             pcoDstHdr = (PCODECVIDEOHEADER) (pco->pDstHdr);
  784.             pcoSrcHdr = (PCODECVIDEOHEADER) (pco->pSrcHdr);
  785.  
  786. //////////////////////////////////////////////////////////////
  787. ////////HACK HACK HACK HACK - RECORDER HACK
  788.  
  789.             if (pcoDstHdr->genpal.ulNumColors == 65536) {
  790. #ifdef MMDEBUG
  791.                if (pcoDstHdr->cBitCount != 16)
  792.                   printf("HACK : Change Dst->cBitCount from %d to 16\n", pcoDstHdr->cBitCount);
  793. #endif
  794.                pcoDstHdr->cBitCount = 16;
  795.                }
  796.  
  797.             if (pcoSrcHdr->genpal.ulNumColors == 65536) {
  798. #ifdef MMDEBUG
  799.                if (pcoSrcHdr->cBitCount != 16)
  800.                   printf("HACK : Change Src->cBitCount from %d to 16\n", pcoSrcHdr->cBitCount);
  801. #endif
  802.                pcoSrcHdr->cBitCount = 16;
  803.                }
  804.  
  805. ////////DON'T BLAME ME - NOT MY FAULT!!
  806. //////////////////////////////////////////////////////////////
  807.  
  808. //
  809. // This limits the CAPSFLAG search to just a decompressor with a certain
  810. // pixel depth.  None of the other flags are used during this search. If
  811. // the user passes in a DLL name or a Proc name, that will be used during
  812. // the first search.  If the first search fails, DLL name and Proc name
  813. // will not be used.  (See ioDetermineCodec in this module)
  814. //
  815.  
  816.             switch(pcoDstHdr->cBitCount) {
  817.                case 4:
  818. #ifdef VERBOSE
  819.    if (!(pcifi->ulCapsFlags & CODEC_4_BIT_COLOR)) {
  820.       printf("DstHdr->cBitCount does not match ulCapsFlags (4)\n");
  821.       }
  822. #endif
  823.                   pcifi->ulCapsFlags |= CODEC_4_BIT_COLOR;
  824.                   break;
  825.                case 16:
  826. #ifdef VERBOSE
  827.    if (!(pcifi->ulCapsFlags & CODEC_16_BIT_COLOR)) {
  828.       printf("DstHdr->cBitCount does not match ulCapsFlags (16)\n");
  829.       }
  830. #endif
  831.                   pcifi->ulCapsFlags |= CODEC_16_BIT_COLOR;
  832.                   break;
  833.                case 24:
  834. #ifdef VERBOSE
  835.    if (!(pcifi->ulCapsFlags & CODEC_24_BIT_COLOR)) {
  836.       printf("DstHdr->cBitCount does not match ulCapsFlags (24)\n");
  837.       }
  838. #endif
  839.                   pcifi->ulCapsFlags |= CODEC_24_BIT_COLOR;
  840.                   break;
  841.                default:
  842. #ifdef VERBOSE
  843.    if (!(pcifi->ulCapsFlags & CODEC_8_BIT_COLOR)) {
  844.       printf("DstHdr->cBitCount does not match ulCapsFlags (8)\n");
  845.       }
  846. #endif
  847.                   pcifi->ulCapsFlags |= CODEC_8_BIT_COLOR;
  848.                   break;
  849.                }
  850.             }
  851.          }
  852.       }
  853.    else { // if its not a decompressor, it better be a compressor
  854. #ifdef MMDEBUG
  855.    printf("ioAssociateCodec : Compressor\n");
  856. #endif
  857.       ulType = CODEC_COMPRESS; // save flag in case it is overwritten
  858.  
  859.       /* Don't allow a COMPRESSOR association for read only files */
  860.       if ((pinstance->ulFlags & OPENED_READONLY) &&
  861.           (!(pcifi->ulFlags & CODEC_DECOMPRESS)) &&
  862.           (pcifi->ulFlags & CODEC_COMPRESS)) {
  863.          return(MMIOERR_INVALID_PARAMETER);
  864.          }
  865.  
  866. //////////////////////////////////////////////////////////////
  867. ////////HACK HACK HACK HACK - RECORDER HACK
  868.  
  869.       if (pcifi->ulMediaType != MMIO_MEDIATYPE_AUDIO) {
  870.          pco       = (PCODECOPEN)        (pcodecassoc->pCodecOpen);
  871.          pmmVidOpn = (PMMVIDEOOPEN)      (pco->pOtherInfo);
  872.          pcoDstHdr = (PCODECVIDEOHEADER) (pco->pDstHdr);
  873.          pcoSrcHdr = (PCODECVIDEOHEADER) (pco->pSrcHdr);
  874.  
  875. #ifdef MMDEBUG
  876.          print_codec_structure(pco);
  877. #endif
  878.  
  879.          if (pmmVidOpn) {
  880.             if (pmmVidOpn->ulDataConstraint) {
  881.                ptracki = ioFindTracki (pinstance, ulTrack);
  882.                pmmVidHdr = ptracki->pTrackHeader;
  883.                ulFPS = (ULONG) (((float) (pmmVidHdr->ulRate) /
  884.                                  (float) (pmmVidHdr->ulScale)) + 0.5);
  885.  
  886.                if (!pmmVidOpn->ulConstraintInterval) {
  887. #ifdef MMDEBUG
  888.                   printf("HACK : Change pmmVidOpn->ulConstraintInterval to %d\n", ulFPS);
  889. #endif
  890.                   pmmVidOpn->ulConstraintInterval = ulFPS;
  891.                   }
  892.                if (!pmmVidOpn->ulRate) {
  893. #ifdef MMDEBUG
  894.                   printf("HACK : Change pmmVidOpn->ulRate to %d\n", ulFPS);
  895. #endif
  896.                   pmmVidOpn->ulRate  = ulFPS;
  897.                   }
  898.                }
  899.             }
  900.  
  901.          if (pcoDstHdr->genpal.ulNumColors == 65536) {
  902. #ifdef MMDEBUG
  903.             if (pcoDstHdr->cBitCount != 16)
  904.                printf("HACK : Change Dst->cBitCount from %d to 16\n", pcoDstHdr->cBitCount);
  905. #endif
  906.             pcoDstHdr->cBitCount = 16;
  907.             }
  908.  
  909.          if (pcoSrcHdr->genpal.ulNumColors == 65536) {
  910. #ifdef MMDEBUG
  911.             if (pcoSrcHdr->cBitCount != 16)
  912.                printf("HACK : Change Src->cBitCount from %d to 16\n", pcoSrcHdr->cBitCount);
  913.             pcoSrcHdr->cBitCount = 16;
  914. #endif
  915.             }
  916.          }
  917. ////////DON'T BLAME ME - NOT MY FAULT!!
  918. //////////////////////////////////////////////////////////////
  919.  
  920.       }
  921.  
  922.  
  923.    /* Find the codec to load */
  924.    if (rc = ioDetermineCodec(pinstance, 0, pcifi)) {
  925.       return(rc); /* return error */
  926.       }
  927.  
  928.    else { /* load and open the compression codec */
  929.  
  930.       /***********************************************/
  931.       /* Check for previously installed codecs.      */
  932.       /* de-installed any loaded, load new one       */
  933.       /* allows only 1 codec to be loaded at a time  */
  934.       /***********************************************/
  935.       if (pinstance->pccbList[ulTrack]) {
  936.          pccb = pinstance->pccbList[ulTrack];
  937.          pinstance->pccbList[ulTrack] = pccb->pccbNext;   /* unlink from list */
  938.          ioCloseCodec(pccb);
  939.          }
  940.  
  941.       /* Load the codec dll */
  942.       if (pccb = ioLoadCodecDLL(pinstance,
  943.                                 pcifi,
  944.                                 &hCodec, ulTrack)) {
  945.  
  946. /////////if (ulType == CODEC_DECOMPRESS) {
  947.          if ((ulType == CODEC_DECOMPRESS) &&
  948.              (pcifi->ulMediaType != MMIO_MEDIATYPE_AUDIO)){      //@LP02
  949.             /* Save the codec open information in the ccb */
  950.             ((PCODECOPEN)pcodecassoc->pCodecOpen)->ulFlags =
  951.                            pcodecassoc->pCODECIniFileInfo->ulCapsFlags & ~CODEC_COMPRESS;
  952.  
  953. // don't let COMPRESS flag be set if decompress - indeo.dll doesn't like it!?!
  954.             }
  955.          else { /* Force open of compressor */
  956.            ((PCODECOPEN)pcodecassoc->pCodecOpen)->ulFlags |= CODEC_COMPRESS;
  957.             }
  958.  
  959.          if (!(rc = ioInitCodecopen(pccb,(PCODECOPEN)pcodecassoc->pCodecOpen))) {
  960.  
  961.             /* Open the codec */
  962.             if (!(rc = pccb->pmmioproc(&hCodec,
  963.                                        MMIOM_CODEC_OPEN,
  964.                                        (LONG)&pccb->codecopen,
  965.                                        0L)))  {
  966.                pccb->hCodec = hCodec;       /* save handle to codec */
  967.                }
  968.             }
  969.  
  970.          /* handle error conditions */
  971.          if (rc) {
  972.             pinstance->pccbList[ulTrack] = pccb->pccbNext;   /* unlink from list */
  973.             ioCloseCodec(pccb);
  974.             }
  975.          }
  976.       else {
  977.          rc = MMIO_ERROR;
  978.          }
  979.       }
  980.  
  981.  
  982.    if (rc == MMIO_SUCCESS) {
  983.       if (ulType == CODEC_COMPRESS) {
  984.          pcodecassoc->pCodecOpen = (PVOID) &pccb->codecopen;
  985.          rc = ffAssociateCodec(pinstance, pcodecassoc);
  986.          }
  987.       }
  988.  
  989.    return(rc);
  990. }
  991.  
  992.  
  993.  
  994.