Exemple #1
0
/******************************************************************************
 * Dmai_setLogLevel
 ******************************************************************************/
Int Dmai_setLogLevel(Dmai_LogLevel logLevel)
{
    /* Set the log level if global variable is not set */
    if (Dmai_debugLogLevel == Dmai_LogLevel_Notset) {
        switch (logLevel) {
            case 0: 
                GT_set("ti.sdo.dmai=");        
                break;
            case 1:
                GT_set("ti.sdo.dmai=67");
                break;
            case 2:
                GT_set("ti.sdo.dmai=01234567");
                break;
            default:
                /* Invalid level. */
                return Dmai_EINVAL;
        }
        
        Dmai_dbg1("Log level set to %d.\n", logLevel);
    }
    else {
        Dmai_dbg0("Using log level set by DMAI_DEBUG.\n");
    }
    
    return Dmai_EOK;
}
Exemple #2
0
/******************************************************************************
 * Dmai_init
 ******************************************************************************/
Void Dmai_init()
{
    if (ti_sdo_dmai_GTMask.modName == NULL) {
        GT_init();
        Global_init();
        Memory_init();
        Sem_init();
        
        GT_create(&ti_sdo_dmai_GTMask, Dmai_gtname);

        if (Dmai_debugLogLevel != Dmai_LogLevel_Notset) {           
            switch (Dmai_debugLogLevel) {
                case 0: 
                    GT_set("ti.sdo.dmai=");         
                    break;
                case 1:
                    GT_set("ti.sdo.dmai=67");
                    break;
                case 2:
                    GT_set("ti.sdo.dmai=01234567");
                    break;
                default:
                    /* Invalid parameter. Do nothing. */   
                    break;
            }
            Dmai_dbg1("Dmai log level set to %d.\n", Dmai_debugLogLevel);
        }
    }
    
    return;
}
Exemple #3
0
/******************************************************************************
 * validateKey
 ******************************************************************************/
static Int validateKey(Int val)
{
    if (val != Ir_Key_POWER         && val != Ir_Key_CHANINC &&
        val != Ir_Key_CHANDEC       && val != Ir_Key_VOLINC &&
        val != Ir_Key_VOLDEC        && val != Ir_Key_OK &&
        val != Ir_Key_MUTE          && val != Ir_Key_MENUDONE &&
        val != Ir_Key_INFOSELECT    && val != Ir_Key_SLEEP &&
        val != Ir_Key_SUBTITLE      && val != Ir_Key_REPEAT &&
        val != Ir_Key_1             && val != Ir_Key_2 &&
        val != Ir_Key_3             && val != Ir_Key_4 &&
        val != Ir_Key_5             && val != Ir_Key_6 &&
        val != Ir_Key_7             && val != Ir_Key_8 &&
        val != Ir_Key_9             && val != Ir_Key_0 &&
        val != Ir_Key_ENTER         && val != Ir_Key_INPUT &&
        val != Ir_Key_REWIND        && val != Ir_Key_PLAY &&
        val != Ir_Key_FASTFORWARD   && val != Ir_Key_RECORD &&
        val != Ir_Key_UP            && val != Ir_Key_DOWN &&
        val != Ir_Key_LEFT          && val != Ir_Key_RIGHT &&
        val != Ir_Key_STOP          && val != Ir_Key_PAUSE) {

        Dmai_dbg1("Ir key %d not valid\n", val);
        return 0;
    }

    return 1;
}
Exemple #4
0
/******************************************************************************
 * Idec1_process
 ******************************************************************************/
Int Idec1_process(Idec1_Handle hId, Buffer_Handle hInBuf,
                 Buffer_Handle hOutBuf)
{
    BufferGfx_Dimensions    dim;
    IMGDEC1_DynamicParams   dynParams;
    IMGDEC1_InArgs          inArgs;
    IMGDEC1_OutArgs         outArgs;
    IMGDEC1_Status          decStatus;
    XDM1_BufDesc            inBufDesc;
    XDM1_BufDesc            outBufDesc;
    XDAS_Int32              status;
    XDAS_Int8 *             inPtr;
    XDAS_Int8 *             outPtr;
    UInt32                  offset = 0;
    UInt32                  i;
    
    assert(hId);
    assert(hInBuf);
    assert(hOutBuf);
    assert(Buffer_getSize(hInBuf));   
    assert(Buffer_getUserPtr(hInBuf)); 
    assert(Buffer_getUserPtr(hOutBuf));
    assert(Buffer_getNumBytesUsed(hInBuf));
    assert(Buffer_getSize(hOutBuf));
    assert(Buffer_getType(hOutBuf) == Buffer_Type_GRAPHICS);

    BufferGfx_getDimensions(hOutBuf, &dim);
    
    inPtr  = Buffer_getUserPtr(hInBuf);
    outPtr = Buffer_getUserPtr(hOutBuf);

    inArgs.size             = sizeof(IMGDEC1_InArgs);
    inArgs.numBytes         = Buffer_getNumBytesUsed(hInBuf);

    outArgs.size            = sizeof(IMGDEC1_OutArgs);

    inBufDesc.numBufs       = 1;
    outBufDesc.numBufs      = hId->minNumOutBufs;
    
    inBufDesc.descs[0].buf = inPtr;
    inBufDesc.descs[0].bufSize = Buffer_getSize(hInBuf);

    for(i = 0; i < hId->minNumOutBufs; i++)
    {
        outBufDesc.descs[i].buf = (XDAS_Int8 *)((unsigned int)outPtr + offset);
        offset +=  hId->minOutBufSize[i];
        outBufDesc.descs[i].bufSize = hId->minOutBufSize[i];
    }   
        
    /* Decode image buffer */
    status = IMGDEC1_process(hId->hDecode, &inBufDesc, &outBufDesc, &inArgs,
                            &outArgs);

    Buffer_setNumBytesUsed(hInBuf, outArgs.bytesConsumed);

    if (status != IMGDEC1_EOK) {
        if (XDM_ISFATALERROR(outArgs.extendedError)) {
            Dmai_err2("IMGDEC1_process() failed with error (%d ext: 0x%x)\n",
                      (Int)status, (Uns) outArgs.extendedError);
            return Dmai_EFAIL;
        }
        else {
            Dmai_dbg1("IMGDEC1_process() non-fatal error 0x%x\n",
                      (Uns) outArgs.extendedError);
            return Dmai_EBITERROR;
        }
    }

    /* Get the dynamic codec status */
    decStatus.data.buf = NULL;
    decStatus.size = sizeof(IMGDEC1_Status);
    dynParams.size = sizeof(IMGDEC1_DynamicParams);
    status = IMGDEC1_control(hId->hDecode, XDM_GETSTATUS, &dynParams,
                            &decStatus);

    if (status != IMGDEC1_EOK) {
        Dmai_err1("XDM_GETSTATUS failed, status=%d\n", status);
        return Dmai_EFAIL;
    }

    /* Set output Color Format */
    switch (decStatus.outputChromaFormat) {
        case XDM_YUV_422ILE:
            BufferGfx_setColorSpace (hOutBuf, ColorSpace_UYVY); 
            break;
        case XDM_YUV_420P:
            BufferGfx_setColorSpace (hOutBuf, ColorSpace_YUV420P); 
            break;
        case XDM_YUV_422P:
            BufferGfx_setColorSpace (hOutBuf, ColorSpace_YUV422P); 
            break;
        case XDM_YUV_444P:
            BufferGfx_setColorSpace (hOutBuf, ColorSpace_YUV444P); 
            break;
        case XDM_GRAY:
            BufferGfx_setColorSpace (hOutBuf, ColorSpace_GRAY); 
            break;
        default:
            printf("Unsupported output color space.\n");
            return Dmai_EFAIL;        
    }
       
    dim.x = dim.y = 0;
    dim.width = decStatus.outputWidth;
    dim.height = decStatus.outputHeight;
    dim.lineLength = decStatus.outputWidth *
                      ColorSpace_getBpp(BufferGfx_getColorSpace(hOutBuf)) / 8;
    
    if (BufferGfx_setDimensions(hOutBuf, &dim) < 0) {
        Dmai_err0("Frame does not fit in allocated buffer\n");
        return Dmai_EFAIL;
    }

    return Dmai_EOK;
}
Exemple #5
0
/******************************************************************************
 * Idec1_create
 ******************************************************************************/
Idec1_Handle Idec1_create(Engine_Handle hEngine, Char *codecName,
                        IMGDEC1_Params *params, 
                        IMGDEC1_DynamicParams *dynParams)
{
    Idec1_Handle             hId;
    IMGDEC1_Handle           hDecode;
    IMGDEC1_Status           decStatus;
    XDAS_Int32               status;

    if (hEngine == NULL || codecName == NULL ||
        params == NULL || dynParams == NULL) {
        Dmai_err0("Cannot pass null for engine, codec name, params or "
                  "dynamic params\n");
        return NULL;
    }

    /* Allocate space for the object */
    hId = (Idec1_Handle)calloc(1, sizeof(Idec1_Object));

    if (hId == NULL) {
        Dmai_err0("Failed to allocate space for Idec1 Object\n");
        return NULL;
    }

    /* Create image decoder instance */
    hDecode = IMGDEC1_create(hEngine, codecName, params);

    if (hDecode == NULL) {
        Dmai_err0("Failed to open image decode algorithm\n");
        free(hId);
        return NULL;
    }

    Dmai_dbg0("Image decoder instance created\n");

    /* Set image decoder dynamic params */
    decStatus.data.buf = NULL;
    decStatus.size = sizeof(IMGDEC1_Status);
    status = IMGDEC1_control(hDecode, XDM_SETPARAMS, dynParams,
                            &decStatus);

    if (status != IMGDEC1_EOK) {
        Dmai_err0("XDM_SETPARAMS control failed\n");
        IMGDEC1_delete(hDecode);
        free(hId);
        return NULL;
    }

    /* Get buffer information from image decoder */
    status = IMGDEC1_control(hDecode, XDM_GETBUFINFO, dynParams,
                            &decStatus);

    if (status != IMGDEC1_EOK) {
        Dmai_err0("XDM_GETBUFINFO control failed\n");
        IMGDEC1_delete(hDecode);
        free(hId);
        return NULL;
    }

    Dmai_dbg1("Buffer size %u obtained from XDM_GETBUFINFO control call\n",
              (UInt) decStatus.bufInfo.minInBufSize[0]);

    hId->hDecode = hDecode;
    memcpy(hId->minInBufSize,
           decStatus.bufInfo.minInBufSize, sizeof(hId->minInBufSize));
    hId->minNumInBufs = decStatus.bufInfo.minNumInBufs;
    memcpy(hId->minOutBufSize,
           decStatus.bufInfo.minOutBufSize, sizeof(hId->minOutBufSize));
    hId->minNumOutBufs = decStatus.bufInfo.minNumOutBufs;

    return hId;
}
/******************************************************************************
 * Capture_detectVideoStd
 ******************************************************************************/
Int Capture_detectVideoStd(Capture_Handle hCapture, VideoStd_Type *videoStdPtr,
                           Capture_Attrs *attrs)
{
    v4l2_std_id             id;
    struct v4l2_input       input;
    Int                     index;
    Int                     fd;
    struct v4l2_standard    std;

    assert(videoStdPtr);
    assert(attrs);

    if (attrs->videoStd < 0 || attrs->videoStd > VideoStd_COUNT) {
        Dmai_err1("Invalid capture standard given (%d)\n", attrs->videoStd);
        return Dmai_EINVAL;
    }

    if (hCapture) {
        fd = hCapture->fd;
    }
    else {
        fd = open(attrs->captureDevice, O_RDWR, 0);

        if (fd == -1) {
            Dmai_err2("Cannot open %s (%s)\n", attrs->captureDevice,
                                               strerror(errno));
            return Dmai_EFAIL;
        }
    }

    /* Get any active input */
    if (ioctl(fd, VIDIOC_G_INPUT, &index) < 0) {
        Dmai_err0("VIDIOC_G_INPUT");
        return Dmai_EFAIL;
    }

    /* Display available video input */
    Dmai_dbg0("Available video input:\n");
    for (index=0;; index++) {

        input.index = index;
        if (ioctl(fd, VIDIOC_ENUMINPUT, &input) < 0) {
            if (errno == EINVAL || errno == ENOTTY)
                break;
        }

        Dmai_dbg1(" name=%s\n", input.name);
    }

    /* Set video input */
    switch (attrs->videoInput) {

        case Capture_Input_SVIDEO:
                Dmai_dbg0("Setting video input to SVIDEO\n");
                index = 1;
                break;
        case Capture_Input_COMPOSITE:
                Dmai_dbg0("Setting video input to COMPOSITE\n");
                index = 0;
                break;
        default:
                Dmai_err0("Unknown video input\n");
                return Dmai_EFAIL;
                break;
    }
        
    if (ioctl(fd, VIDIOC_S_INPUT, &index) < 0) {
        Dmai_err2("Failed VIDIOC_S_INPUT to index %d (%s)\n", 
                                    index, strerror(errno));
        return Dmai_EFAIL;
    }
 
    /* Display available video standards */
    Dmai_dbg0("Available video standard:\n");
    for (index=0;; index++) {

        std.frameperiod.numerator = 1;
        std.frameperiod.denominator = 0;
        std.index = index;

        if (ioctl(fd, VIDIOC_ENUMSTD, &std) < 0) {
            if (errno == EINVAL || errno == ENOTTY)
                break;
        }
        Dmai_dbg3(" name=%s, fps=%d/%d\n", std.name, 
                    std.frameperiod.denominator, std.frameperiod.numerator);
    }
    /* Detect the standard in the input detected */ 
    if (ioctl(fd, VIDIOC_QUERYSTD, &id) < 0) {
        Dmai_err0("VIDIOC_QUERYSTD");
        return Dmai_EFAIL;
    }

    /* Get current video standard */
    if (ioctl(fd, VIDIOC_G_STD, &id) < 0) {
        Dmai_err0("Failed VIDIOC_G_STD\n");
        return Dmai_EFAIL;
    }

    if (!hCapture) {
        close(fd);
    }

    if (id & V4L2_STD_NTSC) {
       *videoStdPtr = VideoStd_D1_NTSC;
        Dmai_dbg0("Found NTSC std input\n");
    }
    else if (id & V4L2_STD_PAL) {
        *videoStdPtr = VideoStd_D1_PAL;
        Dmai_dbg0("Found PAL std input\n");
    }
    else if (id & V4L2_STD_525_60) {
        *videoStdPtr = VideoStd_480P;
        Dmai_dbg0("Found 525_60 std input\n");
    }
    else if (id & V4L2_STD_625_50) {
        *videoStdPtr = VideoStd_576P;
        Dmai_dbg0("Found 625_50 std input\n");
    }
    else {
        Dmai_err1("Unknown video standard on capture device %s\n",
                  attrs->captureDevice);
        return Dmai_EFAIL; 
    }

    attrs->videoStd = *videoStdPtr;
    Dmai_dbg2("Capture input set to %s.  Standard: %d\n",
              captureInputString[attrs->videoInput], *videoStdPtr);

    return Dmai_EOK;
}
/******************************************************************************
 * Initialize & configure previewer in on-the-fly (continous) mode
 ******************************************************************************/
Int Previewer_continuous_config(Bool setRgbColorPallet)
{
#ifdef CONFIG_DM365_IPIPE
    Int preview_fd;
    unsigned int oper_mode, user_mode;
    struct prev_channel_config prev_chan_config;
    struct prev_continuous_config prev_cont_config;
    struct prev_cap cap;
    struct prev_module_param mod_param;
    user_mode = IMP_MODE_CONTINUOUS;
    
    preview_fd = open((const char *)PREVIEWER_DEVICE, O_RDWR);
    if(preview_fd <= 0) {
        Dmai_err0("Cannot open previewer device \n");
        return NULL;
    }

    if (ioctl(preview_fd,PREV_S_OPER_MODE, &user_mode) < 0) {
        Dmai_err1("Can't set operation mode in previewer (%s)\n", strerror(errno));
        close(preview_fd);        
        return Dmai_EFAIL;
    }

    if (ioctl(preview_fd,PREV_G_OPER_MODE, &oper_mode) < 0) {
        Dmai_err1("Can't get operation mode from previewer (%s)\n", strerror(errno));
        close(preview_fd);        
        return Dmai_EFAIL;
    }

    if (oper_mode == user_mode) {
        Dmai_dbg0("Operating mode changed successfully to continuous in previewer\n");
    } else {
        Dmai_err0("failed to set mode to continuous in previewer\n");
        close(preview_fd);
        return Dmai_EFAIL;
    }

    prev_chan_config.oper_mode = oper_mode;
    prev_chan_config.len = 0;
    prev_chan_config.config = NULL; /* to set defaults in driver */

    if (ioctl(preview_fd, PREV_S_CONFIG, &prev_chan_config) < 0) {
        Dmai_err1("Error in setting default previewer configuration (%s)\n", 
            strerror(errno));
        close(preview_fd);
        return Dmai_EFAIL;
    }

    if (setRgbColorPallet) {
        Dmai_dbg0("Setting RGB color pallet\n");
        prev_chan_config.oper_mode = oper_mode;
        prev_chan_config.len = sizeof(struct prev_continuous_config);
        prev_chan_config.config = &prev_cont_config; /* to set defaults in driver */

        if (ioctl(preview_fd, PREV_G_CONFIG, &prev_chan_config) < 0) {
            Dmai_err1("Error in setting default previewer configuration (%s)\n", 
                strerror(errno));
            close(preview_fd);
            return Dmai_EFAIL;
        }

        prev_chan_config.oper_mode = oper_mode;
        prev_chan_config.len = sizeof(struct prev_continuous_config);
        prev_chan_config.config = &prev_cont_config; /* to set defaults in driver */

        prev_cont_config.input.colp_elep= IPIPE_BLUE;
        prev_cont_config.input.colp_elop= IPIPE_GREEN_BLUE;
        prev_cont_config.input.colp_olep= IPIPE_GREEN_RED;
        prev_cont_config.input.colp_olop= IPIPE_RED;

        if (ioctl(preview_fd, PREV_S_CONFIG, &prev_chan_config) < 0) {
            Dmai_err1("Error in setting default previewer configuration (%s)\n", 
                strerror(errno));
            close(preview_fd);
            return Dmai_EFAIL;
        }

        cap.index=0;
        while (1) {
            if (ioctl(preview_fd , PREV_ENUM_CAP, &cap) < 0) {
                break;
            }

            strcpy(mod_param.version,cap.version);
            mod_param.module_id = cap.module_id;

           // using defaults
            Dmai_dbg1("Setting default for %s\n", cap.module_name);
            mod_param.param = NULL;
            if (ioctl(preview_fd, PREV_S_PARAM, &mod_param) < 0) {
                Dmai_err1("Error in Setting %s params from driver\n", cap.module_name);
                close(preview_fd);
                return Dmai_EFAIL; 
            }
            cap.index++;
        }
    }

    Dmai_dbg0("Previewer initialized\n");
    return preview_fd;
#else
    Dmai_err0("not implemented\n");
    return Dmai_ENOTIMPL;
#endif
}
Exemple #8
0
/******************************************************************************
 * Sdec_process
 ******************************************************************************/
Int Sdec_process(Sdec_Handle hSd, Buffer_Handle hInBuf, Buffer_Handle hOutBuf)
{
    SPHDEC_DynamicParams    dynamicParams;
    SPHDEC_Status           decStatus;
    XDM_BufDesc             inBufDesc;
    XDM_BufDesc             outBufDesc;
    XDAS_Int32              inBufSizeArray[1];
    XDAS_Int32              outBufSizeArray[1];
    XDAS_Int32              status;
    SPHDEC_InArgs           inArgs;
    SPHDEC_OutArgs          outArgs;
    XDAS_Int8              *inPtr;
    XDAS_Int8              *outPtr;

    assert(hSd);
    assert(hInBuf);
    assert(hOutBuf);
    assert(Buffer_getUserPtr(hInBuf));
    assert(Buffer_getUserPtr(hOutBuf));
    assert(Buffer_getNumBytesUsed(hInBuf));
    assert(Buffer_getSize(hOutBuf));

    inPtr = Buffer_getUserPtr(hInBuf);
    outPtr = Buffer_getUserPtr(hOutBuf);

    inBufSizeArray[0]          = Buffer_getNumBytesUsed(hInBuf);
    outBufSizeArray[0]         = Buffer_getSize(hOutBuf);

    inBufDesc.bufSizes         = inBufSizeArray;
    inBufDesc.bufs             = &inPtr;
    inBufDesc.numBufs          = 1;

    outBufDesc.bufSizes        = outBufSizeArray;
    outBufDesc.bufs            = &outPtr;
    outBufDesc.numBufs         = 1;

    inArgs.size                = sizeof(SPHDEC_InArgs);
    inArgs.inBufferSize        = Buffer_getNumBytesUsed(hInBuf);

    outArgs.size               = sizeof(SPHDEC_OutArgs);

    /* Decode the speech buffer */
    status = SPHDEC_process(hSd->hDecode, &inBufDesc, &outBufDesc, &inArgs,
                            &outArgs);

    if (status != SPHDEC_EOK) {
        decStatus.size = sizeof(SPHDEC_Status);
        dynamicParams.size = sizeof(SPHDEC_DynamicParams);
        status = SPHDEC_control(hSd->hDecode, XDM_GETSTATUS, &dynamicParams,
                                &decStatus);
        if (status != SPHDEC_EOK) {
            Dmai_err1("XDM_GETSTATUS failed, status=%d\n", status);
            return Dmai_EFAIL;
        }

        if (status == SPHDEC_ERUNTIME ||
            XDM_ISFATALERROR(decStatus.extendedError)) {

            Dmai_err2("SPHDEC_process() failed with error (%d ext: 0x%x)\n",
                      (Int)status, (Uns) decStatus.extendedError);
            return Dmai_EFAIL;
        }
        else {
            Dmai_dbg1("SPHDEC_process() non-fatal error 0x%x\n",
                      (Uns) decStatus.extendedError);
            return Dmai_EBITERROR;
        }
    }

    /* A fixed x2 decompression ratio, only works for g711 */
    Buffer_setNumBytesUsed(hOutBuf, Buffer_getNumBytesUsed(hInBuf) * 2);

    return Dmai_EOK;
}
Exemple #9
0
/******************************************************************************
 * Sdec_create
 ******************************************************************************/
Sdec_Handle Sdec_create(Engine_Handle hEngine, Char *codecName,
                        SPHDEC_Params *params, SPHDEC_DynamicParams *dynParams)
{
    Sdec_Handle         hSd;
    SPHDEC_Handle       hDecode;
    SPHDEC_Status       decStatus;
    XDAS_Int32          status;

    if (hEngine == NULL || codecName == NULL ||
        params == NULL || dynParams == NULL) {
        Dmai_err0("Cannot pass null for engine, codec name, params or "
                  "dynamic params\n");
        return NULL;
    }

    /* Allocate space for the object */
    hSd = (Sdec_Handle)calloc(1, sizeof(Sdec_Object));

    if (hSd == NULL) {
        Dmai_err0("Failed to allocate space for Sdec Object\n");
        return NULL;
    }

    /* Create speech decoder */
    hDecode = SPHDEC_create(hEngine, codecName, params);

    if (hDecode == NULL) {
        Dmai_err0("Failed to create speech decoder\n");
        cleanup(hSd);
        return NULL;
    }

    Dmai_dbg1("Speech decoder instance of %s created\n", codecName);

    /* Set dynamic parameters */
    decStatus.size = sizeof(SPHDEC_Status);
    status = SPHDEC_control(hDecode, XDM_SETPARAMS, dynParams, &decStatus);

    if (status != SPHDEC_EOK) {
        Dmai_err1("XDM_SETPARAMS failed, status=%d\n", status);
        SPHDEC_delete(hDecode);
        cleanup(hSd);
        return NULL;
    }

    /* Get buffer information from video decoder */
    status = SPHDEC_control(hDecode, XDM_GETBUFINFO, dynParams,
                            &decStatus);

    if (status != SPHDEC_EOK) {
        Dmai_err0("XDM_GETBUFINFO control failed\n");
        SPHDEC_delete(hDecode);
        cleanup(hSd);
        return NULL;
    }

    Dmai_dbg2("Speech decoder requires buffer sizes in %u and out %u\n",
              (Uns) decStatus.bufInfo.minInBufSize[0],
              (Uns) decStatus.bufInfo.minInBufSize[1]);

    memcpy(hSd->minInBufSize,
           decStatus.bufInfo.minInBufSize, sizeof(hSd->minInBufSize));
    hSd->minNumInBufs = decStatus.bufInfo.minNumInBufs;
    memcpy(hSd->minOutBufSize,
           decStatus.bufInfo.minOutBufSize, sizeof(hSd->minOutBufSize));
    hSd->minNumOutBufs = decStatus.bufInfo.minNumOutBufs;

    hSd->hDecode = hDecode;

    return hSd;
}