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

  1. /*************************START OF SPECIFICATIONS *************************/
  2. /* SOURCE FILE NAME:  ULCODEC.C                                           */
  3. /*                                                                        */
  4. /* DESCRIPTIVE NAME: Ultimotion  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. /*     IOProcDecompress                                                   */
  20. /*     ffOpenCodec                                                        */
  21. /*                                                                        */
  22. /************************* END OF SPECIFICATIONS **************************/
  23.  
  24.  
  25. #include        <stdio.h>
  26. #include        <string.h>
  27. #include        <stdlib.h>
  28. #include        <memory.h>
  29.  
  30. #define         INCL_DOS                      /* #define  INCL_DOSPROCESS  */
  31. #define         INCL_ERRORS
  32. #define         INCL_WIN
  33. #define         INCL_GPI
  34. #include        <os2.h>                       /* OS/2 headers              */
  35. #include        <pmbitmap.h>
  36.  
  37. #define         INCL_OS2MM
  38. #define         INCL_MMIO_CODEC
  39. #define         INCL_MMIO_DOSIOPROC
  40. #include        <os2me.h>                     /* Multi-Media IO extensions */
  41. #include        <hhpheap.h>
  42. #include        <ioi.h>
  43.  
  44.  
  45.    extern HHUGEHEAP hheap;                        /* Heap of memory.        */
  46.    extern ULONG    ulNumColors;     
  47.    extern HMTX hmtxGlobalHeap;
  48.  
  49.  
  50. /************************** START OF SPECIFICATIONS *************************/
  51. /*                                                                          */
  52. /* SUBROUTINE NAME:  IOProcDecompress                                       */
  53. /*                                                                          */
  54. /* DESCRIPTIVE NAME:                                                        */
  55. /*                                                                          */
  56. /* FUNCTION: This function calls DCIOProc to calcultate invalid clipping    */
  57. /*           region. If the passed in is a palette block, this function     */
  58. /*           will directly perform the palette translation and return to    */
  59. /*           caller.                                                        */
  60. /*                                                                          */
  61. /* NOTES: None                                                              */
  62. /*                                                                          */
  63. /* ENTRY POINT: IOProcDecompress                                            */
  64. /*   LINKAGE:   CALL FAR (00:32)                                            */
  65. /*                                                                          */
  66. /* INPUT:                                                                   */
  67. /*        PMMIOINFO pmmioinfo       - Pointer to MMIOINFO status structure. */
  68. /*        PMMDECOMPRESS pmmdec      - Decompress structure.                 */
  69. /*                                                                          */
  70. /*                                                                          */
  71. /* EXIT-NORMAL:                                                             */
  72. /*              MMIO_SUCCESS                                                */
  73. /*                                                                          */
  74. /* EXIT-ERROR:                                                              */
  75. /*              MMIO_ERROR                                                  */
  76. /*                                                                          */
  77. /*                                                                          */
  78. /* SIDE EFFECTS:                                                            */
  79. /*                                                                          */
  80. /*************************** END OF SPECIFICATIONS **************************/
  81. LONG IOProcDecompress ( PMMIOINFO pmmioinfo,
  82.                         PMMDECOMPRESS pmmdec )
  83.  
  84. {
  85.    LONG            rc = MMIO_SUCCESS;      /* Return code of IOProc's call.  */
  86.    PCCB            pccb;                   /* Pointer to CCB structure       */
  87.    PVIDEOFRAME     pumvfHdr = NULL;        /* Pointer to record prefix block.*/
  88.    PINSTANCE       pinstance;
  89.  
  90.    if (rc = ioGetPtrInstance(pmmioinfo,&pinstance))
  91.       return(rc);
  92.  
  93.    /*****************************************************/
  94.    /* Check for invalid input flags                     */
  95.    /*****************************************************/
  96.    if (pmmdec->ulFlags & ~(VALID_DECOMPRESS_INPUTFLAGS)) {
  97.       pmmioinfo->ulErrorRet = MMIOERR_INVALID_PARAMETER;
  98.       return(MMIO_ERROR);
  99.       }
  100.  
  101.    /*****************************************************/
  102.    /* Fill in necessary information for DC IOProc;      */
  103.    /* Send msg to DC IOProc to perform decompression.   */
  104.    /*****************************************************/
  105.    pmmdec->ulFlags &= ~(MMIO_IS_PALETTE | MMIO_IS_KEY_FRAME);
  106.  
  107.    /*****************************************************/
  108.    /* Tricky - Multi-aperture check. Must make sure that*/
  109.    /* We skip the frame header only for the first call  */
  110.    /* of many multi-aperture calls. Each calls decomp-  */
  111.    /* resses only a portion of the frame.               */
  112.    /*****************************************************/
  113.    if (pinstance->pccbLastUsed) {   /* Multiaperture non-first call */
  114.       pccb = pinstance->pccbLastUsed;
  115.       if (pccb->ulLastSrcBuf != (ULONG)pmmdec->pSrcBuf) {
  116.          pmmioinfo->ulErrorRet = MMIOERR_INVALID_PARAMETER;
  117.          return(MMIO_ERROR);
  118.          }
  119.       }
  120.  
  121.    else {   /* Multiaperture first call or single aperture call */
  122.       /***************************************************************************/
  123.       /* Since only one video track for current file format...video track = 0L.  */
  124.       /* Validate the buffer as a video frame chunk.                             */
  125.       /* Find the tracki structure for THE video track.                          */
  126.       /***************************************************************************/
  127.       pumvfHdr = (PVIDEOFRAME)pmmdec->pSrcBuf;       /* Point at beginning of chunk data */
  128.  
  129.       /* Tell stream handler we had reference frame or not */
  130.       if (!(pumvfHdr->ulFrameFlags & UM_VIDEO_FRAME_FLAG_DELTAFRAME)) {
  131.          pmmdec->ulFlags |= MMIO_IS_KEY_FRAME;
  132.          }
  133.    
  134.       if (!(pccb = ioFindCodec(pinstance,pumvfHdr->ulCompressionType))) {
  135.          pmmioinfo->ulErrorRet = MMIOERR_MATCH_NOT_FOUND;
  136.          return(MMIO_ERROR);
  137.          }
  138.    
  139.       /***************************************************************************/
  140.       /* If Buffer passed contains not a palette block, do the following:        */
  141.       /* Check if DC List has valid information for DC IOProc.                   */
  142.       /***************************************************************************/
  143.       if (!pccb->hCodec) {
  144.          pmmioinfo->ulErrorRet = MMIOERR_INTERNAL_SYSTEM;
  145.          return(MMIO_ERROR);
  146.          }
  147.  
  148.       /*************************************/
  149.       /* Skip header at beginning of frame */
  150.       /*************************************/
  151.       pmmdec->pSrcBuf = (PVOID) &(pumvfHdr->bData[0]);
  152.       pmmdec->ulSrcBufLen  -= (sizeof(VIDEOFRAME) - 1);
  153.       }  /* Multiaperture first call */
  154.  
  155.  
  156.    rc = pccb->pmmioproc(&pccb->hCodec,
  157.                         MMIOM_CODEC_DECOMPRESS,
  158.                         (LONG)pmmdec,
  159.                         0L);
  160.  
  161.    if(rc != NO_ERROR) {
  162.       pmmioinfo->ulErrorRet = rc;
  163.       rc = MMIO_ERROR;
  164.       } /* end if */
  165.  
  166.  
  167.    /***********************************************/
  168.    /* Check for Multiaperture case.               */
  169.    /***********************************************/
  170.    if (pmmdec->ulSrcBufLen && pmmdec->pSrcBuf) {
  171.       pccb->ulLastSrcBuf = (ULONG)pmmdec->pSrcBuf;
  172.       pinstance->pccbLastUsed = pccb;
  173.       }
  174.  
  175.    else {
  176.       /* Make sure buffer length is zero */
  177.       pmmdec->ulSrcBufLen = 0;
  178.       pccb->ulLastSrcBuf = 0L;
  179.       pinstance->pccbLastUsed = 0L;
  180.       }
  181.  
  182.    return(rc);
  183. }
  184.  
  185.  
  186.  
  187. /************************** START OF SPECIFICATIONS *************************/
  188. /*                                                                          */
  189. /* SUBROUTINE NAME:  ffOpenCodec                                            */
  190. /*                                                                          */
  191. /* DESCRIPTIVE NAME:                                                        */
  192. /*                                                                          */
  193. /* FUNCTION: This function Opens  a codec instance for a movie instance.    */
  194. /*           This is called at movie open time once for each codec required */
  195. /*           for this particular movie instance.                            */
  196. /*                                                                          */
  197. /* NOTES: None                                                              */
  198. /*                                                                          */
  199. /* ENTRY POINT: ffOpenCodec                                                 */
  200. /*   LINKAGE:   CALL FAR (00:32)                                            */
  201. /*                                                                          */
  202. /* INPUT:                                                                   */
  203. /*           PINSTANCE   pinstance  - Movie instance structure              */
  204. /*           PCCB        pccb       - Pointer to codec control structure.   */
  205. /*           ULONG       hCodec     - Handle to codec to associate with     */
  206. /*                                    this codec. This is used where there  */
  207. /*                                    are multiple codecs per DLL, but the  */
  208. /*                                    share common data area.               */
  209. /*             PTRACKI ptracki      - Track specific information            */
  210. /*                                                                          */
  211. /* EXIT-NORMAL:                                                             */
  212. /*              MMIO_SUCCESS                                                */
  213. /*                                                                          */
  214. /* EXIT-ERROR:                                                              */
  215. /*              MMIO_ERROR                                                  */
  216. /*                                                                          */
  217. /*                                                                          */
  218. /* SIDE EFFECTS:                                                            */
  219. /*                                                                          */
  220. /*************************** END OF SPECIFICATIONS **************************/
  221. LONG ffOpenCodec ( PINSTANCE pinstance,
  222.                    PCCB pccb,
  223.                    ULONG hCodec,
  224.                    PTRACKI ptracki) 
  225.  
  226. {
  227.    LONG              rc = MMIO_SUCCESS;       /* Return code of IOProc's call. */
  228.    PMMVIDEOHEADER     pmmVideoHdr;            /* Video header node.      */
  229.    PCODECVIDEOHEADER  pcodecvidhdr;
  230.  
  231.    /**************************************************************************/
  232.    /* Fill in necessary information for DC IOProc.                           */
  233.    /**************************************************************************/
  234.    pmmVideoHdr = (PMMVIDEOHEADER)ptracki->pTrackHeader; /* Get standard track header */
  235.  
  236.    pccb->codecopen.pControlHdr = NULL;               // FOR AVI, fill in from CODEC SPECIFIC DATA SECTION OF HEADER!
  237.    pccb->codecopen.pOtherInfo = NULL;
  238.  
  239.    ENTERCRITX;
  240.    /********************************************/
  241.    /* Create Source Video Header               */
  242.    /********************************************/
  243.    if (pcodecvidhdr = (PCODECVIDEOHEADER)HhpAllocMem(hheap,(ULONG)sizeof(CODECVIDEOHEADER))) {
  244.       pccb->codecopen.pSrcHdr = (PVOID)pcodecvidhdr;
  245.  
  246.       pcodecvidhdr->ulStructLen = sizeof(CODECVIDEOHEADER);
  247.       pcodecvidhdr->cx = pmmVideoHdr->ulWidth; 
  248.       pcodecvidhdr->cy = pmmVideoHdr->ulHeight; 
  249.       pcodecvidhdr->cPlanes = 1;                          // Hardcoded
  250.       pcodecvidhdr->cBitCount = 16;                       // Hardcoded 
  251.       pcodecvidhdr->ulColorEncoding = MMIO_COMPRESSED;    // Hardcoded 
  252.  
  253.       /********************************************/
  254.       /* Create Destination Video Header          */
  255.       /********************************************/
  256.       if (pcodecvidhdr = (PCODECVIDEOHEADER)HhpAllocMem(hheap,(ULONG)sizeof(CODECVIDEOHEADER))) {
  257.          pccb->codecopen.pDstHdr = (PVOID)pcodecvidhdr;
  258.    
  259.          pcodecvidhdr->ulStructLen = sizeof(CODECVIDEOHEADER);
  260.          pcodecvidhdr->cx = pmmVideoHdr->ulWidth; 
  261.          pcodecvidhdr->cy = pmmVideoHdr->ulHeight; 
  262.          pcodecvidhdr->cPlanes = 1;                          // Hardcoded  
  263.  
  264.          /********************************************/
  265.          /* Initialize the Flags and color encoding  */
  266.          /********************************************/
  267.          pccb->codecopen.ulFlags = pccb->cifi.ulCapsFlags & (VALID_CODECOPEN_INPUTFLAGS);
  268.  
  269.          /* Set the color depth for the CODEC we want */
  270.          if (ulNumColors == 16) {
  271.             pccb->codecopen.ulFlags |= CODEC_4_BIT_COLOR;
  272.             pcodecvidhdr->cBitCount = 16;                       
  273.             pcodecvidhdr->ulColorEncoding = MMIO_PALETTIZED;
  274.             }
  275.          else if (ulNumColors > 256) {
  276.             pccb->codecopen.ulFlags |= CODEC_16_BIT_COLOR;
  277.             pcodecvidhdr->cBitCount = 256;
  278.             pcodecvidhdr->ulColorEncoding = MMIO_RGB_5_6_5;
  279.             }
  280.          else { /* 256 and anything else */
  281.             pccb->codecopen.ulFlags |= CODEC_8_BIT_COLOR;
  282.             pcodecvidhdr->cBitCount = 8;
  283.             pcodecvidhdr->ulColorEncoding = MMIO_PALETTIZED;
  284.             }
  285.  
  286.          /*****************/
  287.          /* Open the Codec
  288.          /*****************/
  289.          rc = pccb->pmmioproc(&hCodec,
  290.                               MMIOM_CODEC_OPEN,
  291.                               (LONG)&pccb->codecopen,
  292.                               0L);
  293.          if (!rc) {
  294.             pccb->hCodec = hCodec;
  295.             }
  296.          }
  297.       }
  298.  
  299.    EXITCRIT;
  300.    return(rc);
  301. }
  302.  
  303.  
  304. LONG ffAssociateCodec ( PINSTANCE pinstance,
  305.                         PMMEXTENDINFO pmmextendinfo )
  306. {
  307.    LONG  rc = MMIO_SUCCESS;
  308.    
  309.    return(rc);
  310. }
  311.