Exemplo n.º 1
0
extern "C" void __declspec(dllexport) initAddin(IDispatch* pDesigner)
{
#ifdef _DEBUG
	MessageBox(0, L"attach debugger and press ok", L"Debug message", MB_OK);
#endif

	InitLibrary(g_CurrentModule);
	if(!PrepareTypeInfo())
	{
		return;
	}

	HRESULT hr;
	VARIANT addins;
	addins.vt = VT_DISPATCH;
	VariantInit(&addins);
	hr = invoke(pDesigner, DISPATCH_PROPERTYGET, &addins, NULL, NULL, L"addins", NULL);
	if(FAILED(hr))
	{
		return;
	}
	
	IDispatch* addinsObj = V_DISPATCH(&addins);

	IUnknown* loader = GetLoader(pDesigner);
	hr = invoke(addinsObj, DISPATCH_METHOD, NULL, NULL, NULL, L"registerLoader", L"U", loader);
}
Exemplo n.º 2
0
int opendevice(int i)
{
    struct stat st;

    sprintf(dev_name,"/dev/video%d",i);

    if (-1 == stat (dev_name, &st)) {
        LOGE("Cannot identify '%s': %d, %s", dev_name, errno, strerror (errno));
        return ERROR_LOCAL;
    }

    if (!S_ISCHR (st.st_mode)) {
        LOGE("%s is no device", dev_name);
        return ERROR_LOCAL;
    }

    fd = open (dev_name, O_RDWR | O_NONBLOCK, 0);

    if (-1 == fd) {
        LOGE("Cannot open '%s': %d, %s", dev_name, errno, strerror (errno));
        return ERROR_LOCAL;
    }


    InitLibrary(dev_name);

    return SUCCESS_LOCAL;
}
Exemplo n.º 3
0
// This is called every time a new object is created
// and set new object's initial values
BOOL CSmartDB::InitInstance()
{
	m_bConnected = FALSE;

	m_bLibLoaded = InitLibrary();
	return TRUE;
}
Exemplo n.º 4
0
int main(void) 
{
	InitLibrary();
	//Put your code here
	CloseLibrary();	
	return 0;
}
Exemplo n.º 5
0
nsWinGesture::nsWinGesture() :
  mFeedbackActive(PR_FALSE),
  mXAxisFeedback(PR_FALSE),
  mYAxisFeedback(PR_FALSE),
  mPanActive(PR_FALSE),
  mPanInertiaActive(PR_FALSE)
{
  (void)InitLibrary();
  mPixelScrollOverflow = 0;
}
Exemplo n.º 6
0
static int Open(vlc_object_t *p_this) {
    vout_display_t *vd = (vout_display_t *)p_this;
    vout_display_sys_t *sys;
    void *p_library;

    /* */
    if (vlc_mutex_trylock(&single_instance) != 0) {
        msg_Err(vd, "Can't start more than one instance at a time");
        return VLC_EGENERIC;
    }

    /* Allocate structure */
    sys = (struct vout_display_sys_t*) calloc(1, sizeof(*sys));
    if (!sys) {
        vlc_mutex_unlock(&single_instance);
        return VLC_ENOMEM;
    }

    /* */
    sys->p_library = p_library = InitLibrary(sys);
    if (!p_library) {
        free(sys);
        msg_Err(vd, "Could not initialize libui.so/libgui.so/libsurfaceflinger_client.so!");
        vlc_mutex_unlock(&single_instance);
        return VLC_EGENERIC;
    }

    /* Setup chroma */
    video_format_t fmt = vd->fmt;
    fmt.i_chroma = VLC_CODEC_RGB32;
    fmt.i_rmask  = 0x000000ff;
    fmt.i_gmask  = 0x0000ff00;
    fmt.i_bmask  = 0x00ff0000;
    video_format_FixRgb(&fmt);

    /* Create the associated picture */
    picture_resource_t *rsc = &sys->resource;
    rsc->p_sys = malloc(sizeof(*rsc->p_sys));
    if (!rsc->p_sys)
        goto enomem;
    rsc->p_sys->sys = sys;

    for (int i = 0; i < PICTURE_PLANE_MAX; i++) {
        rsc->p[i].p_pixels = NULL;
        rsc->p[i].i_pitch = 0;
        rsc->p[i].i_lines = 0;
    }
    picture_t *picture = picture_NewFromResource(&fmt, rsc);
    if (!picture)
        goto enomem;

    /* Wrap it into a picture pool */
    picture_pool_configuration_t pool_cfg;
    memset(&pool_cfg, 0, sizeof(pool_cfg));
    pool_cfg.picture_count = 1;
    pool_cfg.picture       = &picture;
    pool_cfg.lock          = AndroidLockSurface;
    pool_cfg.unlock        = AndroidUnlockSurface;

    sys->pool = picture_pool_NewExtended(&pool_cfg);
    if (!sys->pool) {
        picture_Release(picture);
        goto enomem;
    }

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

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

    sys->i_sar_num = vd->source.i_sar_num;
    sys->i_sar_den = vd->source.i_sar_den;

    return VLC_SUCCESS;

enomem:
    free(rsc->p_sys);
    free(sys);
    dlclose(p_library);
    vlc_mutex_unlock(&single_instance);
    return VLC_ENOMEM;
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
    int initialized=0;
    int err;
    unsigned char motor;
    char *function_name;
    unsigned long addr;

    if (argc < 3) {
        goto printusage;
    }
    
    motor = (unsigned char)atoi(argv[2]);
    printf("Motor: %d\n", motor);

    if ((err = InitLibrary()) != 0) {
        abort();
    }
    initialized = 1;
    pshm = GetSharedMemPtr();

    if (!strcmp(argv[1], "-l")) {
        printf("Loading ISR function\n");
        if (argc < 4)
            goto printusage;

        function_name = argv[3];
        if (function_name[0] == '$' && strlen(function_name) > 1) {
            addr = (int)strtol(&function_name[1], NULL, 16);
            printf("Address: %lx\n", addr);
            err = load_isr_function_from_addr(addr, motor);
        } else {
            printf("Function name: %s\n", function_name);
            err = load_isr_function(function_name, motor);
        }
        if (!err)
            printf("Load ISR function from addr failed\n");

    } else if (!strcmp(argv[1], "-e")) {
        if (!(err = enable_isr(motor))) {
            printf("Enable ISR returned: %d\n", err);
        }
    } else if (!strcmp(argv[1], "-d")) {
        if (!(err = disable_isr(motor))) {
            printf("Disable ISR failed\n");
        }
    } else {
        goto printusage;
    }

    CloseLibrary();
    return !err;

printusage:
    printf("User phase loading tool\n");
    printf("%s [-l/-e/-d] motor [function_name]\n", argv[0]);
    printf("Examples:\n");
    printf("    Load function on motor 1: %s -l 1 function_name\n", argv[0]);
    printf("    Enable motor phase: %s -e 1\n", argv[0]);
    printf("    Disable motor phase: %s -d 1\n", argv[0]);
    if (initialized)
        CloseLibrary();

    return 0;

}
Exemplo n.º 8
0
status_t AudioTrack_open(int sampleRate, uint64_t channelLayout, enum AVSampleFormat sampleFormat)
{
	LOGI("AudioTrack_open() samplerate %d, channel_layout %lld, format %d", sampleRate, channelLayout, sampleFormat);

    if (InitLibrary() != OK) {
        LOGE("AudioTrack_open() InitLibrary failed");
        return ERROR;
    }

	LOGI("AudioTrack_open() InitLibrary succeeded");

    int32_t rate = sampleRate;

    int32_t channel = CHANNEL_OUT_STEREO;
    switch(channelLayout) {
    case AV_CH_LAYOUT_MONO:
        channel = CHANNEL_OUT_MONO;
        break;
    case AV_CH_LAYOUT_STEREO:
        channel = CHANNEL_OUT_STEREO;
        break;
    case AV_CH_LAYOUT_2POINT1:
    case AV_CH_LAYOUT_2_1:
    case AV_CH_LAYOUT_SURROUND:
    case AV_CH_LAYOUT_3POINT1:
    case AV_CH_LAYOUT_4POINT0:
    case AV_CH_LAYOUT_2_2:
    case AV_CH_LAYOUT_QUAD:
        channel = CHANNEL_OUT_QUAD;
        break;
    case AV_CH_LAYOUT_4POINT1:
    case AV_CH_LAYOUT_5POINT0:
    case AV_CH_LAYOUT_5POINT1:
    case AV_CH_LAYOUT_5POINT0_BACK:
    case AV_CH_LAYOUT_5POINT1_BACK:
    case AV_CH_LAYOUT_6POINT0:
        channel = CHANNEL_OUT_5POINT1;
        break;
    case AV_CH_LAYOUT_6POINT0_FRONT:
    case AV_CH_LAYOUT_HEXAGONAL:
    case AV_CH_LAYOUT_6POINT1:
    case AV_CH_LAYOUT_6POINT1_BACK:
    case AV_CH_LAYOUT_6POINT1_FRONT:
    case AV_CH_LAYOUT_7POINT0:
    case AV_CH_LAYOUT_7POINT0_FRONT:
    case AV_CH_LAYOUT_7POINT1:
        channel = CHANNEL_OUT_7POINT1;
        break;
    case AV_CH_LAYOUT_7POINT1_WIDE:
    case AV_CH_LAYOUT_7POINT1_WIDE_BACK:
    case AV_CH_LAYOUT_OCTAGONAL:
    case AV_CH_LAYOUT_STEREO_DOWNMIX:
        channel = CHANNEL_OUT_ALL;
        break;
    default:
        channel = CHANNEL_OUT_STEREO;
        break;
    }

    LOGD("audio output channel: %d", channel);

    int32_t format = 0;
    switch(sampleFormat) {
    case AV_SAMPLE_FMT_U8:
        format = PCM_8_BIT;
        break;
    case AV_SAMPLE_FMT_S16:
        format = PCM_16_BIT;
        break;
    default:
        format = PCM_16_BIT;
        break;
    }
    LOGI("audio output format: %d", format);
    
    int32_t stream_type = MUSIC;
/*
    // Get the minimum buffer value
    int32_t size;
    int32_t afSampleRate, afFrameCount, afLatency, minBufCount, minFrameCount;
    if (!at_getMinFrameCount) {
        status = as_getOutputSamplingRate(&afSampleRate, stream_type);
        status ^= as_getOutputFrameCount(&afFrameCount, stream_type);
        status ^= as_getOutputLatency((uint32_t*)(&afLatency), stream_type);
        if (status != 0) {
            LOGE("Could not query the AudioStream parameters");
            return ERROR;
        }
        minBufCount = afLatency / ((1000 * afFrameCount) / afSampleRate);
        if (minBufCount < 2)
            minBufCount = 2;
        minFrameCount = (afFrameCount * rate * minBufCount) / afSampleRate;
    }
    else {
        status = at_getMinFrameCount(&minFrameCount, stream_type, rate);
        if (status != 0) {
            LOGE("Could not query the AudioTrack parameters");
            return ERROR;
        }
        LOGD("minFrameCount: %d", minFrameCount);
    }

    size = minFrameCount * (channel >= CHANNEL_OUT_STEREO ? 2 : 1);// * 4;
*/
    /* Sizeof(AudioTrack) == 0x58 (not sure) on 2.2.1, this should be enough */
    AudioTrack = malloc(SIZE_OF_AUDIOTRACK);
    if (!AudioTrack)
        return ERROR;

    *((uint32_t *) ((uint32_t)AudioTrack + SIZE_OF_AUDIOTRACK - 4)) = 0xbaadbaad;
    // Higher than android 2.2
    if (at_ctor != NULL)
    {
        at_ctor(AudioTrack, stream_type, rate, format, channel, 0, 0, NULL, NULL, 0, 0);
    }
    // Higher than android 1.6
    else if (at_ctor_legacy != NULL)
    {
        at_ctor_legacy(AudioTrack, stream_type, rate, format, channel, 0, 0, NULL, NULL, 0);
    }
	else if(at_ctor_api18 != NULL)
	{
		at_ctor_api18(AudioTrack, stream_type, rate, format, channel, 0, 0, NULL, NULL, 0, 0);
	}
	else if(at_ctor_api19 != NULL)
	{
		at_ctor_api19(AudioTrack, stream_type, rate, format, channel, 0, 0, NULL, NULL, 0, 0, 0, NULL);
	}
	else if(at_ctor_api19_4_4_2 != NULL)
	{
		at_ctor_api19_4_4_2(AudioTrack, stream_type, rate, format, channel, 0, 0, NULL, NULL, 0, 0, 0, NULL, 0);
	}

    if( (*((uint32_t *) ((uint32_t)AudioTrack + SIZE_OF_AUDIOTRACK - 4)) != 0xbaadbaad) )
    {
        LOGE("AudioTrack ctor failed.");
        free(AudioTrack);
        return ERROR;
    }
    
    int32_t status = 0;
	if(at_initCheck != NULL)
	{
    	status = at_initCheck(AudioTrack);
	}
	
    /* android 1.6 uses channel count instead of stream_type */
    if (status != 0 && at_ctor_legacy != NULL) {
        channel = (channel == CHANNEL_OUT_STEREO) ? 2 : 1;
        at_ctor_legacy(AudioTrack, stream_type, rate, format, channel, 0, 0, NULL, NULL, 0);
        status = at_initCheck(AudioTrack);
    }
	
    if (status != 0) {
        LOGE("Cannot create AudioTrack!");
        free(AudioTrack);
        return ERROR;
    }

	return OK;
}
Exemplo n.º 9
0
MADDriverClass::MADDriverClass(MADDriverSettings *init)
{
	inited = InitLibrary(init);
}
Exemplo n.º 10
0
//	Constructors.
MADDriverClass::MADDriverClass()
{
	MADDriverSettings init = CreateDefaultDriver();
	inited = InitLibrary(&init);
}
Exemplo n.º 11
0
static int Open(vlc_object_t *p_this) {
    vout_display_t *vd = (vout_display_t *)p_this;
    vout_display_sys_t *sys;
    void *p_library;

    /* */
    if (vlc_mutex_trylock(&single_instance) != 0) {
        msg_Err(vd, "Can't start more than one instance at a time");
        return VLC_EGENERIC;
    }

    /* Allocate structure */
    sys = (struct vout_display_sys_t*) calloc(1, sizeof(*sys));
    if (!sys) {
        vlc_mutex_unlock(&single_instance);
        return VLC_ENOMEM;
    }

    /* */
    sys->p_library = p_library = InitLibrary(sys);
    if (!p_library) {
        free(sys);
        msg_Err(vd, "Could not initialize libui.so/libgui.so/libsurfaceflinger_client.so!");
        vlc_mutex_unlock(&single_instance);
        return VLC_EGENERIC;
    }

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

    char *psz_fcc = var_InheritString(vd, CFG_PREFIX "chroma");
    if( psz_fcc ) {
        fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, psz_fcc);
        free(psz_fcc);
    } else
        fmt.i_chroma = VLC_CODEC_RGB32;

    switch(fmt.i_chroma) {
        case VLC_CODEC_YV12:
            /* avoid swscale usage by asking for I420 instead since the
             * vout already has code to swap the buffers */
            fmt.i_chroma = VLC_CODEC_I420;
        case VLC_CODEC_I420:
            break;

        case VLC_CODEC_RGB16:
            fmt.i_bmask = 0x0000001f;
            fmt.i_gmask = 0x000007e0;
            fmt.i_rmask = 0x0000f800;
            break;

        case VLC_CODEC_RGB32:
            fmt.i_rmask  = 0x000000ff;
            fmt.i_gmask  = 0x0000ff00;
            fmt.i_bmask  = 0x00ff0000;
            break;

        default:
            return VLC_EGENERIC;
    }
    video_format_FixRgb(&fmt);

    msg_Dbg(vd, "Pixel format %4.4s", (char*)&fmt.i_chroma);

    /* Create the associated picture */
    picture_resource_t *rsc = &sys->resource;
    rsc->p_sys = malloc(sizeof(*rsc->p_sys));
    if (!rsc->p_sys)
        goto enomem;
    rsc->p_sys->sys = sys;

    for (int i = 0; i < PICTURE_PLANE_MAX; i++) {
        rsc->p[i].p_pixels = NULL;
        rsc->p[i].i_pitch = 0;
        rsc->p[i].i_lines = 0;
    }
    picture_t *picture = picture_NewFromResource(&fmt, rsc);
    if (!picture)
        goto enomem;

    /* Wrap it into a picture pool */
    picture_pool_configuration_t pool_cfg;
    memset(&pool_cfg, 0, sizeof(pool_cfg));
    pool_cfg.picture_count = 1;
    pool_cfg.picture       = &picture;
    pool_cfg.lock          = AndroidLockSurface;
    pool_cfg.unlock        = AndroidUnlockSurface;

    sys->pool = picture_pool_NewExtended(&pool_cfg);
    if (!sys->pool) {
        picture_Release(picture);
        goto enomem;
    }

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

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

    sys->i_sar_num = vd->source.i_sar_num;
    sys->i_sar_den = vd->source.i_sar_den;

    return VLC_SUCCESS;

enomem:
    free(rsc->p_sys);
    free(sys);
    dlclose(p_library);
    vlc_mutex_unlock(&single_instance);
    return VLC_ENOMEM;
}
Exemplo n.º 12
0
static int Open(vlc_object_t *p_this) {
    struct aout_sys_t *p_sys;
    void *p_library;
    aout_instance_t *p_aout = (aout_instance_t*)(p_this);
    int status;
    int afSampleRate, afFrameCount, afLatency, minBufCount, minFrameCount;
    int type, channel, rate, format, size;

    p_library = InitLibrary(p_this);
    if (!p_library) {
        msg_Err(VLC_OBJECT(p_this), "Could not initialize libmedia.so now!");
        return VLC_EGENERIC;
    }
    p_sys = (struct aout_sys_t*)malloc(sizeof(aout_sys_t));
    if (p_sys == NULL)
        return VLC_ENOMEM;
    p_sys->libmedia = p_library;
    // AudioSystem::MUSIC = 3
    type = 3;
    p_sys->type = type;
    // 4000 <= frequency <= 48000
    if (p_aout->output.output.i_rate < 4000)
        p_aout->output.output.i_rate = 4000;
    if (p_aout->output.output.i_rate > 48000)
        p_aout->output.output.i_rate = 48000;
    rate = p_aout->output.output.i_rate;
    p_sys->rate = rate;
    // U8/S16 only
    if (p_aout->output.output.i_format != VLC_CODEC_U8 && p_aout->output.output.i_format != VLC_CODEC_S16L)
        p_aout->output.output.i_format = VLC_CODEC_S16L;
    // AudioSystem::PCM_16_BIT = 1
    // AudioSystem::PCM_8_BIT = 2
    format = (p_aout->output.output.i_format == VLC_CODEC_S16L) ? 1 : 2;
    p_sys->format = format;
    // TODO: android supports more channels

    msg_Err(VLC_OBJECT(p_this), "Open TAG 14");
    channel = aout_FormatNbChannels(&p_aout->output.output);
    if (channel > 2) {
        channel = 2;
        p_aout->output.output.i_physical_channels = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
    }
    // AudioSystem::CHANNEL_OUT_STEREO = 12
    // AudioSystem::CHANNEL_OUT_MONO = 4
    channel = (channel == 2) ? 12 : 4;
    p_sys->channel = channel;
    // use the minium value
    if (!at_getMinFrameCount) {
        msg_Err(VLC_OBJECT(p_this), "Open TAG 1");

        status = as_getOutputSamplingRate(&afSampleRate, type);
        msg_Err(VLC_OBJECT(p_this), "Open TAG 1-2");

        status ^= as_getOutputFrameCount(&afFrameCount, type);
        msg_Err(VLC_OBJECT(p_this), "Open TAG 1-3");

        if (as_getOutputLatency) { // added for 4.1.x
            msg_Err(VLC_OBJECT(p_this), "Open TAG 1-4");
            status ^= as_getOutputLatency((uint32_t*)(&afLatency), type);

            msg_Err(VLC_OBJECT(p_this), "Open TAG 3");
        }
        if (status != 0) {
            msg_Err(VLC_OBJECT(p_this), "Open TAG 16");

            free(p_sys);
            return VLC_EGENERIC;
        }

        if (as_getOutputLatency) { // added for 4.1.x
            msg_Err(VLC_OBJECT(p_this), "Open TAG 13");

            minBufCount = afLatency / ((1000 * afFrameCount) / afSampleRate);
        } else {
            minBufCount = 2;
        }

        if (minBufCount < 2) {
            minBufCount = 2;
        }

        msg_Err(VLC_OBJECT(p_this), "Open TAG 17");
        minFrameCount = (afFrameCount * rate * minBufCount) / afSampleRate;
        p_aout->output.i_nb_samples = minFrameCount;

        msg_Err(VLC_OBJECT(p_this), "Open TAG 2");
    }
    else {
        msg_Err(VLC_OBJECT(p_this), "Open TAG 5");

        status = at_getMinFrameCount(&p_aout->output.i_nb_samples, type, rate);
        if (status != 0) {

            msg_Err(VLC_OBJECT(p_this), "Open TAG 12");
            free(p_sys);
            return VLC_EGENERIC;
        }
    }
    p_aout->output.i_nb_samples <<= 1;
    p_sys->size = p_aout->output.i_nb_samples;
    // sizeof(AudioTrack) == 0x58 (not sure) on 2.2.1, this should be enough
    p_sys->AudioTrack = malloc(256);
    if (!p_sys->AudioTrack) {
        msg_Err(VLC_OBJECT(p_this), "Open TAG 15");

        free(p_sys);
        return VLC_ENOMEM;
    }
    // higher than android 2.2
    if (at_ctor) {
        msg_Err(VLC_OBJECT(p_this), "Open TAG 7");
        at_ctor(p_sys->AudioTrack, p_sys->type, p_sys->rate, p_sys->format, p_sys->channel, p_sys->size, 0, NULL, NULL, 0, 0);
    }
    // higher than android 1.6
    else if (at_ctor_legacy) {
        msg_Err(VLC_OBJECT(p_this), "Open TAG 8");
        at_ctor_legacy(p_sys->AudioTrack, p_sys->type, p_sys->rate, p_sys->format, p_sys->channel, p_sys->size, 0, NULL, NULL, 0);
    }
    status = at_initCheck(p_sys->AudioTrack);
    // android 1.6
    if (status != 0) {
        msg_Err(VLC_OBJECT(p_this), "Open TAG 9");

        p_sys->channel = (p_sys->channel == 12) ? 2 : 1;
        at_ctor_legacy(p_sys->AudioTrack, p_sys->type, p_sys->rate, p_sys->format, p_sys->channel, p_sys->size, 0, NULL, NULL, 0);
        status = at_initCheck(p_sys->AudioTrack);
    }
    if (status != 0) {
        msg_Err(VLC_OBJECT(p_this), "Open TAG 10");

        msg_Err(p_aout, "Cannot create AudioTrack!");
        free(p_sys->AudioTrack);
        free(p_sys);
        return VLC_EGENERIC;
    }

    msg_Err(VLC_OBJECT(p_this), "Open TAG 11");
    p_aout->output.p_sys = p_sys;
    p_aout->output.pf_play = Play;

    at_start(p_sys->AudioTrack);

    return VLC_SUCCESS;
}
Exemplo n.º 13
0
Arquivo: surface.c Projeto: Kubink/vlc
static int Open(vlc_object_t *p_this)
{
    vout_display_t *vd = (vout_display_t *)p_this;
    video_format_t fmt;
    video_format_ApplyRotation(&fmt, &vd->fmt);

    if (fmt.i_chroma == VLC_CODEC_ANDROID_OPAQUE)
        return VLC_EGENERIC;
    if (vout_display_IsWindowed(vd))
        return VLC_EGENERIC;

    /* Allocate structure */
    vout_display_sys_t *sys = (struct vout_display_sys_t*) calloc(1, sizeof(*sys));
    if (!sys)
        goto error;

    /* */
    sys->p_library = InitLibrary(sys);
    if (!sys->p_library) {
        msg_Err(vd, "Could not initialize libandroid.so/libui.so/libgui.so/libsurfaceflinger_client.so!");
        goto error;
    }

    /* Setup chroma */
    char *psz_fcc = var_InheritString(vd, CFG_PREFIX "chroma");
    if( psz_fcc ) {
        fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, psz_fcc);
        free(psz_fcc);
    } else
        fmt.i_chroma = VLC_CODEC_RGB32;

    switch(fmt.i_chroma) {
        case VLC_CODEC_RGB16:
            fmt.i_bmask = 0x0000001f;
            fmt.i_gmask = 0x000007e0;
            fmt.i_rmask = 0x0000f800;
            break;

        case VLC_CODEC_YV12:
        case VLC_CODEC_I420:
            fmt.i_chroma = VLC_CODEC_RGB32;
        case VLC_CODEC_RGB32:
            fmt.i_rmask  = 0x000000ff;
            fmt.i_gmask  = 0x0000ff00;
            fmt.i_bmask  = 0x00ff0000;
            break;

        default:
            return VLC_EGENERIC;
    }
    video_format_FixRgb(&fmt);

    msg_Dbg(vd, "Pixel format %4.4s", (char*)&fmt.i_chroma);
    sys->i_android_hal = ChromaToAndroidHal(fmt.i_chroma);
    if (sys->i_android_hal == -1)
        goto error;

    sys->fmt = fmt;
    UpdateLayout(sys);

    /* Create the associated picture */
    picture_sys_t *picsys = calloc(1, sizeof(picture_sys_t));
    if (unlikely(picsys == NULL))
        goto error;
    picsys->sys = sys;

    picture_resource_t resource = { .p_sys = picsys };
    picture_t *picture = picture_NewFromResource(&fmt, &resource);
    if (!picture) {
        free(picsys);
        goto error;
    }

    /* Wrap it into a picture pool */
    picture_pool_configuration_t pool_cfg;
    memset(&pool_cfg, 0, sizeof(pool_cfg));
    pool_cfg.picture_count = 1;
    pool_cfg.picture       = &picture;
    pool_cfg.lock          = AndroidLockSurface;
    pool_cfg.unlock        = AndroidUnlockSurface;

    sys->pool = picture_pool_NewExtended(&pool_cfg);
    if (!sys->pool) {
        picture_Release(picture);
        goto error;
    }

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

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

    return VLC_SUCCESS;

error:
    Close(p_this);
    return VLC_ENOMEM;
}