Beispiel #1
0
static void Close(vlc_object_t *obj)
{
    filter_t *filter = (filter_t*) obj;
    filter_sys_t *sys = filter->p_sys;
    unsigned int i, j;

    if (sys->omx_handle) {
        OMX_STATETYPE state;
        OMX_GetState(sys->omx_handle, &state);

        if (state == OMX_StateExecuting) {
            OMX_SendCommand(sys->omx_handle, OMX_CommandStateSet,
                    OMX_StateIdle, 0);
            while (1) {
                OMX_U32 cmd, state;
                WaitForSpecificOmxEvent(&sys->event_queue, OMX_EventCmdComplete,
                        &cmd, &state, 0);
                if (cmd == OMX_CommandStateSet && state == OMX_StateIdle)
                    break;
            }
        }

        OMX_GetState(sys->omx_handle, &state);
        if (state == OMX_StateIdle) {
            OMX_SendCommand(sys->omx_handle, OMX_CommandStateSet,
                    OMX_StateLoaded, 0);

            for (i = 0; i < sys->num_ports; i++) {
                OmxPort *port = &sys->ports[i];
                for (j = 0; j < sys->ports[i].i_buffers; j++) {
                    OMX_BUFFERHEADERTYPE *buffer;
                    OMX_FIFO_GET(&port->fifo, buffer);
                    OMX_FreeBuffer(sys->omx_handle, port->i_port_index,
                            buffer);
                }
            }

            WaitForSpecificOmxEvent(&sys->event_queue, OMX_EventCmdComplete,
                    0, 0, 0);
        }
        for (i = 0; i < sys->num_ports; i++)
            free(sys->ports[i].pp_buffers);
        pf_free_handle(sys->omx_handle);
        DeinitOmxEventQueue(&sys->event_queue);
    }

    free(sys);
    DeinitOmxCore();
}
Beispiel #2
0
static void Close(vlc_object_t *p_this)
{
    vout_display_t *vd = (vout_display_t *)p_this;
    vout_display_sys_t *p_sys = vd->sys;

    if (p_sys->omx_handle) {
        OMX_STATETYPE state;
        OMX_GetState(p_sys->omx_handle, &state);
        if (state == OMX_StateExecuting) {
            OMX_SendCommand(p_sys->omx_handle, OMX_CommandStateSet, OMX_StateIdle, 0);
            while (1) {
                OMX_U32 cmd, state;
                WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, &cmd, &state, 0);
                if (cmd == OMX_CommandStateSet && state == OMX_StateIdle)
                    break;
            }
        }
        OMX_GetState(p_sys->omx_handle, &state);
        if (state == OMX_StateIdle) {
            OMX_SendCommand(p_sys->omx_handle, OMX_CommandStateSet, OMX_StateLoaded, 0);
            for (unsigned int i = 0; i < p_sys->port.i_buffers; i++) {
                OMX_BUFFERHEADERTYPE *p_buffer;
                OMX_FIFO_GET(&p_sys->port.fifo, p_buffer);
                OMX_FreeBuffer(p_sys->omx_handle, p_sys->port.i_port_index, p_buffer);
            }
            WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, 0, 0, 0);
        }
        free(p_sys->port.pp_buffers);
        pf_free_handle(p_sys->omx_handle);
        DeinitOmxEventQueue(&p_sys->event_queue);
        OMX_FIFO_DESTROY(&p_sys->port.fifo);
    }

    if (p_sys->pool)
        picture_pool_Release(p_sys->pool);
    free(p_sys);
    DeinitOmxCore();
}
Beispiel #3
0
static int Open(vlc_object_t *p_this)
{
    vout_display_t *vd = (vout_display_t *)p_this;
    vout_display_t *p_dec = vd;
    char ppsz_components[MAX_COMPONENTS_LIST_SIZE][OMX_MAX_STRINGNAME_SIZE];
    picture_t** pictures = NULL;
    OMX_PARAM_PORTDEFINITIONTYPE *def;

    static OMX_CALLBACKTYPE callbacks =
        { OmxEventHandler, OmxEmptyBufferDone, OmxFillBufferDone };

    if (InitOmxCore(p_this) != VLC_SUCCESS)
        return VLC_EGENERIC;

    int components = CreateComponentsList(p_this, "iv_renderer", ppsz_components);
    if (components <= 0) {
        DeinitOmxCore();
        return VLC_EGENERIC;
    }

    /* Allocate structure */
    vout_display_sys_t *p_sys = (struct vout_display_sys_t*) calloc(1, sizeof(*p_sys));
    if (!p_sys) {
        DeinitOmxCore();
        return VLC_ENOMEM;
    }

    vd->sys     = p_sys;
    strcpy(p_sys->psz_component, ppsz_components[0]);

    /* Load component */
    OMX_ERRORTYPE omx_error = pf_get_handle(&p_sys->omx_handle,
                                            p_sys->psz_component, vd, &callbacks);
    CHECK_ERROR(omx_error, "OMX_GetHandle(%s) failed (%x: %s)",
                p_sys->psz_component, omx_error, ErrorToString(omx_error));

    InitOmxEventQueue(&p_sys->event_queue);
    OMX_FIFO_INIT(&p_sys->port.fifo, pOutputPortPrivate);
    p_sys->port.b_direct = false;
    p_sys->port.b_flushed = true;

    OMX_PORT_PARAM_TYPE param;
    OMX_INIT_STRUCTURE(param);
    omx_error = OMX_GetParameter(p_sys->omx_handle, OMX_IndexParamVideoInit, &param);
    CHECK_ERROR(omx_error, "OMX_GetParameter(OMX_IndexParamVideoInit) failed (%x: %s)",
                omx_error, ErrorToString(omx_error));

    p_sys->port.i_port_index = param.nStartPortNumber;
    p_sys->port.b_valid = true;
    p_sys->port.omx_handle = p_sys->omx_handle;

    def = &p_sys->port.definition;
    OMX_INIT_STRUCTURE(*def);
    def->nPortIndex = p_sys->port.i_port_index;
    omx_error = OMX_GetParameter(p_sys->omx_handle, OMX_IndexParamPortDefinition, def);
    CHECK_ERROR(omx_error, "OMX_GetParameter(OMX_IndexParamPortDefinition) failed (%x: %s)",
                omx_error, ErrorToString(omx_error));

#define ALIGN(x, y) (((x) + ((y) - 1)) & ~((y) - 1))

    def->format.video.nFrameWidth = vd->fmt.i_width;
    def->format.video.nFrameHeight = vd->fmt.i_height;
    def->format.video.nStride = 0;
    def->format.video.nSliceHeight = 0;
    p_sys->port.definition.format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;

    if (!strcmp(p_sys->psz_component, "OMX.broadcom.video_render")) {
        def->format.video.nSliceHeight = ALIGN(def->format.video.nFrameHeight, 16);
    }

    omx_error = OMX_SetParameter(p_sys->omx_handle, OMX_IndexParamPortDefinition, &p_sys->port.definition);
    CHECK_ERROR(omx_error, "OMX_SetParameter(OMX_IndexParamPortDefinition) failed (%x: %s)",
                omx_error, ErrorToString(omx_error));
    OMX_GetParameter(p_sys->omx_handle, OMX_IndexParamPortDefinition, &p_sys->port.definition);

    if (def->format.video.nStride < (int) def->format.video.nFrameWidth)
        def->format.video.nStride = def->format.video.nFrameWidth;
    if (def->format.video.nSliceHeight < def->format.video.nFrameHeight)
        def->format.video.nSliceHeight = def->format.video.nFrameHeight;

    p_sys->port.pp_buffers =
            malloc(p_sys->port.definition.nBufferCountActual *
                   sizeof(OMX_BUFFERHEADERTYPE*));
    p_sys->port.i_buffers = p_sys->port.definition.nBufferCountActual;

    omx_error = OMX_SendCommand(p_sys->omx_handle, OMX_CommandStateSet, OMX_StateIdle, 0);
    CHECK_ERROR(omx_error, "OMX_CommandStateSet Idle failed (%x: %s)",
                omx_error, ErrorToString(omx_error));

    unsigned int i;
    for (i = 0; i < p_sys->port.i_buffers; i++) {
        omx_error = OMX_AllocateBuffer(p_sys->omx_handle, &p_sys->port.pp_buffers[i],
                                       p_sys->port.i_port_index, 0,
                                       p_sys->port.definition.nBufferSize);
        if (omx_error != OMX_ErrorNone)
            break;
        OMX_FIFO_PUT(&p_sys->port.fifo, p_sys->port.pp_buffers[i]);
    }
    if (omx_error != OMX_ErrorNone) {
        p_sys->port.i_buffers = i;
        for (i = 0; i < p_sys->port.i_buffers; i++)
            OMX_FreeBuffer(p_sys->omx_handle, p_sys->port.i_port_index, p_sys->port.pp_buffers[i]);
        msg_Err(vd, "OMX_AllocateBuffer failed (%x: %s)",
                omx_error, ErrorToString(omx_error));
        goto error;
    }

    omx_error = WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, 0, 0, 0);
    CHECK_ERROR(omx_error, "Wait for Idle failed (%x: %s)",
                omx_error, ErrorToString(omx_error));

    omx_error = OMX_SendCommand(p_sys->omx_handle, OMX_CommandStateSet,
                                OMX_StateExecuting, 0);
    CHECK_ERROR(omx_error, "OMX_CommandStateSet Executing failed (%x: %s)",
                omx_error, ErrorToString(omx_error));
    omx_error = WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, 0, 0, 0);
    CHECK_ERROR(omx_error, "Wait for Executing failed (%x: %s)",
                omx_error, ErrorToString(omx_error));

    if (!strcmp(p_sys->psz_component, "OMX.broadcom.video_render")) {
        OMX_CONFIG_DISPLAYREGIONTYPE config_display;
        OMX_INIT_STRUCTURE(config_display);
        config_display.nPortIndex = p_sys->port.i_port_index;

        config_display.set = OMX_DISPLAY_SET_SRC_RECT;
        config_display.src_rect.width = vd->cfg->display.width;
        config_display.src_rect.height = vd->cfg->display.height;
        OMX_SetConfig(p_sys->omx_handle, OMX_IndexConfigDisplayRegion, &config_display);
        config_display.set = OMX_DISPLAY_SET_FULLSCREEN;
        config_display.fullscreen = OMX_TRUE;
        OMX_SetConfig(p_sys->omx_handle, OMX_IndexConfigDisplayRegion, &config_display);

        UpdateDisplaySize(vd, vd->cfg);
    }


    /* Setup chroma */
    video_format_t fmt = vd->fmt;

    fmt.i_chroma = VLC_CODEC_I420;
    video_format_FixRgb(&fmt);

    /* Setup vout_display */
    vd->fmt     = fmt;
    vd->pool    = Pool;
    vd->display = Display;
    vd->control = Control;
    vd->prepare = NULL;
    vd->manage  = NULL;

    /* Create the associated picture */
    pictures = calloc(p_sys->port.i_buffers, sizeof(*pictures));
    if (!pictures)
        goto error;
    for (unsigned int i = 0; i < p_sys->port.i_buffers; i++) {
        picture_sys_t *picsys = malloc(sizeof(*picsys));
        if (unlikely(picsys == NULL))
            goto error;
        picsys->sys = p_sys;

        picture_resource_t resource = { .p_sys = picsys };

        picture_t *picture = picture_NewFromResource(&fmt, &resource);
        if (unlikely(picture == NULL))
        {
            free(picsys);
            goto error;
        }
        pictures[i] = picture;
    }

    /* Wrap it into a picture pool */
    picture_pool_configuration_t pool_cfg;
    memset(&pool_cfg, 0, sizeof(pool_cfg));
    pool_cfg.picture_count = p_sys->port.i_buffers;
    pool_cfg.picture       = pictures;
    pool_cfg.lock          = LockSurface;
    pool_cfg.unlock        = UnlockSurface;

    p_sys->pool = picture_pool_NewExtended(&pool_cfg);
    if (!p_sys->pool) {
        for (unsigned int i = 0; i < p_sys->port.i_buffers; i++)
            picture_Release(pictures[i]);
        goto error;
    }

    /* Fix initial state */
    vout_display_SendEventFullscreen(vd, true);

    free(pictures);
    return VLC_SUCCESS;

error:
    free(pictures);
    Close(p_this);
    return VLC_EGENERIC;
}
Beispiel #4
0
static int Open(vlc_object_t *obj)
{
    char ppsz_components[MAX_COMPONENTS_LIST_SIZE][OMX_MAX_STRINGNAME_SIZE];
    OMX_U8 psz_role[OMX_MAX_STRINGNAME_SIZE];
    filter_t *filter = (filter_t*) obj;
    OMX_PARAM_PORTDEFINITIONTYPE def;
    OMX_PORT_PARAM_TYPE param;
    filter_t *p_dec = filter;
    OMX_ERRORTYPE omx_error;
    filter_sys_t *sys;
    unsigned int i, j;
    int components;

    static OMX_CALLBACKTYPE callbacks =
        { OmxEventHandler, OmxEmptyBufferDone, OmxFillBufferDone };

    if (InitOmxCore(obj) != VLC_SUCCESS)
        return VLC_EGENERIC;

    components = CreateComponentsList(obj, "image_fx", ppsz_components);
    if (components <= 0) {
        DeinitOmxCore();
        msg_Err(filter, "Could not find image_fx component.\n");
        return VLC_EGENERIC;
    }

    sys = calloc(1, sizeof(*sys));
    if (unlikely(sys == NULL))
            return VLC_ENOMEM;
    strcpy(sys->psz_component, ppsz_components[0]);
    filter->p_sys = sys;

    /* Initialize the OMX component */
    omx_error = pf_get_handle(&sys->omx_handle, sys->psz_component, filter,
            &callbacks);
    CHECK_ERROR(omx_error, "OMX_GetHandle(%s) failed (%x: %s)",
            sys->psz_component, omx_error, ErrorToString(omx_error));

    omx_error = OMX_ComponentRoleEnum(sys->omx_handle, psz_role, 0);
    if(omx_error == OMX_ErrorNone)
        msg_Dbg(filter, "loaded component %s of role %s", sys->psz_component, psz_role);
    else
        msg_Dbg(filter, "loaded component %s", sys->psz_component);
    PrintOmx(obj, sys->omx_handle, OMX_ALL);

    InitOmxEventQueue(&sys->event_queue);

    OMX_INIT_STRUCTURE(param);
    OMX_INIT_STRUCTURE(def);
    omx_error = OMX_GetParameter(sys->omx_handle, OMX_IndexParamImageInit, &param);
    CHECK_ERROR(omx_error, "OMX_GetParameter(OMX_IndexParamImageInit) failed (%x: %s)",
                omx_error, ErrorToString(omx_error));

    sys->num_ports = param.nPorts;
    sys->ports = &sys->out;
    for (i = 0; i < param.nPorts; i++) {
        OmxPort *p_port;

        def.nPortIndex = param.nStartPortNumber + i;
        omx_error = OMX_GetParameter(sys->omx_handle,
                OMX_IndexParamPortDefinition, &def);
        if (omx_error != OMX_ErrorNone) {
            msg_Warn(obj, "Port Defintion could not be retrieved for port %d",
                    (int)def.nPortIndex);
            continue;
        }

        if (def.eDir == OMX_DirInput) {
            msg_Dbg(obj, "Port %d is input.", (int)def.nPortIndex);
            p_port = &sys->in;
        } else {
            msg_Dbg(obj, "Port %d is output.", (int)def.nPortIndex);
            p_port = &sys->out;
        }

        def.nBufferCountActual = def.nBufferCountMin;
        omx_error = OMX_SetParameter(sys->omx_handle,
                OMX_IndexParamPortDefinition, &def);
        if (omx_error != OMX_ErrorNone) {
            msg_Warn(obj, "Port Defintion could not be updated for port %d",
                    (int)def.nPortIndex);
            continue;
        }

        p_port->b_valid = true;
        p_port->i_port_index = def.nPortIndex;
        p_port->definition = def;
        p_port->omx_handle = sys->omx_handle;
    }

    if (!sys->in.b_valid || !sys->out.b_valid) {
        omx_error = OMX_ErrorInvalidComponent;
        CHECK_ERROR(omx_error, "couldn't find an input and/or output port.");
    }

    SetFormat(filter, &sys->in);
    SetFormat(filter, &sys->out);

    /* allocate array for port buffers */
    for (i = 0; i < sys->num_ports; i++) {
        OmxPort *port = &sys->ports[i];

        vlc_mutex_init(&port->fifo.lock);
        vlc_cond_init(&port->fifo.wait);
        port->fifo.pp_last = &port->fifo.p_first;
        port->b_flushed = true;
        if (port == &sys->in) {
            port->b_direct = true;
            port->p_fmt = &filter->fmt_in;
            port->fifo.offset = offsetof(OMX_BUFFERHEADERTYPE, pOutputPortPrivate) /
                                sizeof(void*);
        } else {
            port->b_direct = true;
            port->p_fmt = &filter->fmt_out;
            port->fifo.offset = offsetof(OMX_BUFFERHEADERTYPE, pInputPortPrivate) /
                                sizeof(void*);
        }

        msg_Dbg(obj, "Allocate headroom for %u buffers.",
                (unsigned)port->definition.nBufferCountActual);
        port->pp_buffers = malloc(port->definition.nBufferCountActual *
                sizeof(OMX_BUFFERHEADERTYPE*));
        if (unlikely(port->pp_buffers == NULL)) {
            omx_error = OMX_ErrorInsufficientResources;
            CHECK_ERROR(omx_error, "memory allocation failed");
        }
        port->i_buffers = port->definition.nBufferCountActual;

        /* enable port */
        if (!port->definition.bEnabled) {
            omx_error = OMX_SendCommand(sys->omx_handle, OMX_CommandPortEnable,
                    port->i_port_index, NULL);
            CHECK_ERROR(omx_error, "OMX_CommandPortEnable on %i failed (%x)",
                    (int)port->i_port_index, omx_error);

            omx_error = WaitForSpecificOmxEvent(&sys->event_queue,
                    OMX_EventCmdComplete, 0, 0, 0);
            CHECK_ERROR(omx_error, "Wait for PortEnable on %i failed (%x)",
                    (int)port->i_port_index, omx_error);
        }
    }

    /* Put component into idle state */
    omx_error = OMX_SendCommand(sys->omx_handle, OMX_CommandStateSet, OMX_StateIdle, 0);
    CHECK_ERROR(omx_error, "OMX_CommandStateSet Idle failed (%x: %s)", omx_error,
            ErrorToString(omx_error));

    /* allocate buffers/bufferheaders for direct rendering */
    for (i = 0; i < sys->num_ports; i++) {
        OmxPort *port = &sys->ports[i];

        for (j = 0; j < port->i_buffers; j++) {
            if (port->b_direct) {
                omx_error = OMX_UseBuffer(sys->omx_handle, &port->pp_buffers[j],
                        port->i_port_index, 0, port->definition.nBufferSize,
                        (void*)1);
                CHECK_ERROR(omx_error, "OMX_UseBuffer failed (%x: %s)", omx_error,
                        ErrorToString(omx_error));
                msg_Dbg(obj, "Use direct rendering on port %u",
                        (unsigned)port->i_port_index);
                msg_Dbg(obj, "Allocated direct rendering buffer header: %p",
                        port->pp_buffers[j]);
            } else {
                omx_error = OMX_AllocateBuffer(sys->omx_handle,
                        &port->pp_buffers[j], port->i_port_index, 0,
                        port->definition.nBufferSize);
                msg_Dbg(obj, "Use indirect rendering on port %u",
                        (unsigned)port->i_port_index);
            }

            if (omx_error != OMX_ErrorNone) {
                msg_Warn(obj, "Buffer allocate failed on buffer %d for port %d (%x: %s)",
                        j, i, omx_error, ErrorToString(omx_error));
                CHECK_ERROR(omx_error, "OMX_FillBuffer failed (%x: %s)", omx_error,
                        ErrorToString(omx_error));
                break;
            }
            OMX_FIFO_PUT(&port->fifo, port->pp_buffers[j]);
        }
        msg_Dbg(obj, "Allocated %u buffers for port %u",
                (unsigned)port->i_buffers, (unsigned)port->i_port_index);
    }

    omx_error = WaitForSpecificOmxEvent(&sys->event_queue, OMX_EventCmdComplete,
            0, 0, 0);
    CHECK_ERROR(omx_error, "Wait for Idle failed (%x: %s)", omx_error,
            ErrorToString(omx_error));

    msg_Dbg(obj, "Reached Idle state, transition to Executing.");
    SetDeinterlaceMode(filter);

    omx_error = OMX_SendCommand(sys->omx_handle, OMX_CommandStateSet,
            OMX_StateExecuting, 0);
    CHECK_ERROR(omx_error, "OMX_CommandStateSet Executing failed (%x)", omx_error);

    omx_error = WaitForSpecificOmxEvent(&sys->event_queue,
            OMX_EventCmdComplete, 0, 0, 0);
    CHECK_ERROR(omx_error, "Wait for Executing failed (%x)", omx_error );

    filter->pf_video_filter = Deinterlace;
    filter->fmt_out.video.i_frame_rate *= 2;
    printf("OMXIL deinterlace filter initialized with %d->%d fps\n",
        filter->fmt_in.video.i_frame_rate,
        filter->fmt_out.video.i_frame_rate);

    return VLC_SUCCESS;

error:
    Close(obj);
    return VLC_EGENERIC;
}