/*
 *  ======== call ========
 */
static VISA_Status call(VISA_Handle visaHandle, VISA_Msg visaMsg)
{
    _VIDTRANSCODE_Msg *msg  = (_VIDTRANSCODE_Msg *)visaMsg;
    VIDTRANSCODE_Handle handle = (VIDTRANSCODE_Handle)visaHandle;
    Int i;
    XDM1_BufDesc inBufs;
    XDM_BufDesc outBufs;
    IVIDTRANSCODE_OutArgs *pOutArgs;
    IVIDTRANSCODE_Status *pStatus;
    Int numBufs;

    /* perform the requested VIDTRANSCODE operation by parsing message. */
    switch (msg->visa.cmd) {

        case _VIDTRANSCODE_CPROCESS: {
            /* unmarshal inBufs and outBufs */
            inBufs           = msg->cmd.process.inBufs;

            outBufs.bufs     = msg->cmd.process.outBufs;
            outBufs.numBufs  = msg->cmd.process.numOutBufs;
            outBufs.bufSizes = msg->cmd.process.outBufSizes;

            if (SKEL_cachingPolicy == SKEL_LOCALBUFFERINVWB) {
                /* invalidate cache for all input buffers */
                for (i = 0, numBufs = 0; i < XDM_MAX_IO_BUFFERS; i++) {
                    if (inBufs.descs[i].buf != NULL) {
                        /* valid member of sparse array, manage it */
                        Memory_cacheInv(inBufs.descs[i].buf,
                                inBufs.descs[i].bufSize);

                        if (++numBufs == inBufs.numBufs) {
                            break;
                        }
                    }
                }

                /* invalidate cache for all output buffers */
                for (i = 0, numBufs = 0; i < XDM_MAX_IO_BUFFERS; i++) {
                    if (outBufs.bufs[i] != NULL) {
                        /* valid member of sparse array, manage it */
                        Memory_cacheInv(outBufs.bufs[i], outBufs.bufSizes[i]);

                        if (++numBufs == outBufs.numBufs) {
                            break;
                        }
                    }
                }
            }

            /* unmarshall outArgs based on the "size" of inArgs */
            pOutArgs = (IVIDTRANSCODE_OutArgs *)((UInt)(&(msg->cmd.process.inArgs)) +
                msg->cmd.process.inArgs.size);

            /*
             * Note, there's no need to invalidate cache for
             * pOutArgs->encodedBuf bufs as they're
             * not _really_ OUT buffers.  Rather they're references to
             * the _real_ OUT buffers that are provided in outBufs - which
             * were already invalidated above.
             */

            /* make the process call */
            msg->visa.status = VIDTRANSCODE_process(handle,
                &inBufs, &outBufs, &(msg->cmd.process.inArgs), pOutArgs);

            if (SKEL_cachingPolicy == SKEL_WBINVALL) {
                Memory_cacheWbInvAll();
            }
            else if (SKEL_cachingPolicy == SKEL_LOCALBUFFERINVWB) {
                /* writeback cache for encoded buffers  */
                for (i = 0; i < IVIDTRANSCODE_MAXOUTSTREAMS; i++) {
                    if ((pOutArgs->outputID[0] != 0) &&
                            (pOutArgs->encodedBuf[i].buf != NULL) &&
                            XDM_ISACCESSMODE_WRITE(pOutArgs->encodedBuf[i].accessMask)) {

                        Memory_cacheWb(pOutArgs->encodedBuf[i].buf,
                                pOutArgs->encodedBuf[i].bufSize);

                        /*
                         * Since we've cacheWb this buffer, we arguably should
                         * reflect this cache state and clear the WRITE bit in
                         * the .accessMask field.  However, we know the stub
                         * doesn't propogate this field to the calling app, so
                         * this extra buffer management detail isn't necessary:
                         *
                         * XDM_CLEARACCESSMODE_WRITE(
                         *         pOutArgs.encodedBuf[i].accessMask);
                         */
                    }
                }
            }

            /*
             * Note that any changes to individual outBufs[i] values made by
             * the codec will automatically update msg->cmd.process.outBufs
             * as we pass the outBufs array by reference.
             */

            break;
        }

        case _VIDTRANSCODE_CCONTROL: {
            /* unmarshall status based on the "size" of params */
            pStatus =
                (IVIDTRANSCODE_Status *)((UInt)(&(msg->cmd.control.dynParams)) +
                msg->cmd.control.dynParams.size);

            /* invalidate data buffer */
            if (pStatus->data.buf != NULL) {
                Memory_cacheInv(pStatus->data.buf, pStatus->data.bufSize);
            }

            msg->visa.status = VIDTRANSCODE_control(handle, msg->cmd.control.id,
                &(msg->cmd.control.dynParams), pStatus);

            /* writeback data buffer */
            if ((pStatus->data.buf != NULL) &&
                XDM_ISACCESSMODE_WRITE(pStatus->data.accessMask)) {

                Memory_cacheWb(pStatus->data.buf, pStatus->data.bufSize);

                /*
                 * Since we've cacheWb this buffer, we arguably should
                 * reflect this cache state and clear the WRITE bit in
                 * the .accessMask field.  However, we know the stub
                 * doesn't propogate this field to the calling app, so
                 * this extra buffer management detail isn't necessary:
                 *
                 * XDM_CLEARACCESSMODE_WRITE(pStatus->data.accessMask);
                 */
            }

            break;
        }

        default: {
            msg->visa.status = VISA_EFAIL;

            break;
        }
    }
    return (VISA_EOK);
}
Exemple #2
0
static int do_setupCodec(CodecEngine* _ce, const char* _codecName,
                         size_t _srcWidth, size_t _srcHeight,
                         size_t _srcLineLength, size_t _srcImageSize, uint32_t _srcFormat,
                         size_t _dstWidth, size_t _dstHeight,
                         size_t _dstLineLength, size_t _dstImageSize, uint32_t _dstFormat)
{
  if (_codecName == NULL)
    return EINVAL;

#if 1
  fprintf(stderr, "VIDTRANSCODE_control(%c%c%c%c@%zux%zu[%zu] -> %c%c%c%c@%zux%zu[%zu])\n",
          _srcFormat&0xff, (_srcFormat>>8)&0xff, (_srcFormat>>16)&0xff, (_srcFormat>>24)&0xff,
          _srcWidth, _srcHeight, _srcLineLength,
          _dstFormat&0xff, (_dstFormat>>8)&0xff, (_dstFormat>>16)&0xff, (_dstFormat>>24)&0xff,
          _dstWidth, _dstHeight, _dstLineLength);
#endif

  TRIK_VIDTRANSCODE_RESAMPLE_Params ceParams;
  memset(&ceParams, 0, sizeof(ceParams));
  ceParams.base.size = sizeof(ceParams);
  ceParams.base.numOutputStreams = 1;
  ceParams.base.formatInput = do_convertPixelFormat(_ce, _srcFormat);
  ceParams.base.formatOutput[0] = do_convertPixelFormat(_ce, _dstFormat);
  ceParams.base.maxHeightInput = _srcHeight;
  ceParams.base.maxWidthInput = _srcWidth;
  ceParams.base.maxHeightOutput[0] = _dstHeight;
  ceParams.base.maxWidthOutput[0] = _dstWidth;
  ceParams.base.dataEndianness = XDM_BYTE;

  char* codec = strdup(_codecName);
  if ((_ce->m_vidtranscodeHandle = VIDTRANSCODE_create(_ce->m_handle, codec, &ceParams.base)) == NULL)
  {
    free(codec);
    fprintf(stderr, "VIDTRANSCODE_create(%s) failed\n", _codecName);
    return EBADRQC;
  }
  free(codec);

  TRIK_VIDTRANSCODE_RESAMPLE_DynamicParams ceDynamicParams;
  memset(&ceDynamicParams, 0, sizeof(ceDynamicParams));
  ceDynamicParams.base.size = sizeof(ceDynamicParams);
  ceDynamicParams.base.keepInputResolutionFlag[0] = XDAS_FALSE;
  ceDynamicParams.base.outputHeight[0] = _dstHeight;
  ceDynamicParams.base.outputWidth[0] = _dstWidth;
  ceDynamicParams.base.keepInputFrameRateFlag[0] = XDAS_TRUE;
  ceDynamicParams.inputHeight = _srcHeight;
  ceDynamicParams.inputWidth = _srcWidth;
  ceDynamicParams.inputLineLength = _srcLineLength;
  ceDynamicParams.outputLineLength[0] = _dstLineLength;

  IVIDTRANSCODE_Status ceStatus;
  memset(&ceStatus, 0, sizeof(ceStatus));
  ceStatus.size = sizeof(ceStatus);
  XDAS_Int32 controlResult = VIDTRANSCODE_control(_ce->m_vidtranscodeHandle, XDM_SETPARAMS, &ceDynamicParams.base, &ceStatus);
  if (controlResult != IVIDTRANSCODE_EOK)
  {
    fprintf(stderr, "VIDTRANSCODE_control() failed: %"PRIi32"/%"PRIi32"\n", controlResult, ceStatus.extendedError);
    return EBADRQC;
  }

  return 0;
}