Example #1
0
void render_setparam(void *hrender, int id, void *param)
{
    if (!hrender) return;
    RENDER *render = (RENDER*)hrender;
    switch (id)
    {
    case PARAM_AUDIO_VOLUME:
        adev_setparam(render->adev, id, param);
        break;
    case PARAM_PLAY_SPEED:
        render_setspeed(render, *(int*)param);
        break;
#if CONFIG_ENABLE_VEFFECT
    case PARAM_VISUAL_EFFECT:
        render->veffect_type = *(int*)param;
        if (render->veffect_type == VISUAL_EFFECT_DISABLE) {
            veffect_render(render->veffect_context,
                render->veffect_x, render->veffect_y,
                render->veffect_w, render->veffect_h,
                VISUAL_EFFECT_DISABLE, 0, 0);
        }
        break;
#endif
    case PARAM_AVSYNC_TIME_DIFF:
    case PARAM_VDEV_POST_SURFACE:
        vdev_setparam(render->vdev, id, param);
        break;
    case PARAM_RENDER_SEEK_STEP:
        render->render_status |= RENDER_SEEKSTEP;
        break;
    }
}
Example #2
0
// 函数实现
void* render_open(int adevtype, int srate, AVSampleFormat sndfmt, int64_t ch_layout,
                  int vdevtype, void *surface, AVRational frate, AVPixelFormat pixfmt, int w, int h)
{
    RENDER *render = (RENDER*)calloc(1, sizeof(RENDER));
    if (!render) {
        av_log(NULL, AV_LOG_ERROR, "failed to allocate render context !\n");
        exit(0);
    }

    // init for video
    render->video_width  = w;
    render->video_height = h;
    render->render_wnew  = w;
    render->render_hnew  = h;
    render->frame_rate   = frate;
    render->pixel_fmt    = pixfmt;
    if (render->pixel_fmt == AV_PIX_FMT_NONE) {
        render->pixel_fmt = AV_PIX_FMT_YUV420P;
    }

    // init for audio
    render->sample_rate  = srate;
    render->sample_fmt   = sndfmt;
    render->chan_layout  = ch_layout;

    // init for visual effect
#if CONFIG_ENABLE_VEFFECT
    render->veffect_context = veffect_create(surface);
    pthread_create(&render->veffect_thread, NULL, render_veffect_thread, render);
#endif

    // create adev & vdev
    render->adev = adev_create(adevtype, 0, (int)((double)ADEV_SAMPLE_RATE * frate.den / frate.num + 0.5) * 4);
    render->vdev = vdev_create(vdevtype, surface, 0, w, h, (int)((double)frate.num / frate.den + 0.5));

    // make adev & vdev sync together
    int64_t *papts = NULL;
    vdev_getavpts(render->vdev, &papts, NULL);
    adev_syncapts(render->adev,  papts);

#ifdef WIN32
    RECT rect; GetClientRect((HWND)surface, &rect);
    render_setrect(render, 0, rect.left, rect.top, rect.right, rect.bottom);
    render_setrect(render, 1, rect.left, rect.top, rect.right, rect.bottom);
#endif

    // set default playback speed
    render_setspeed(render, 100);
    return render;
}
// 函数实现
void* render_open(void *surface, AVRational frate, int pixfmt, int w, int h,
                 int srate, AVSampleFormat sndfmt, int64_t ch_layout)
{
    RENDER *render = (RENDER*)malloc(sizeof(RENDER));
    if (!render) {
        log_printf(TEXT("failed to allocate render context !\n"));
        exit(0);
    }

    // clear it first
    memset(render, 0, sizeof(RENDER));

    // init for video
    render->nVideoWidth  = w;
    render->nVideoHeight = h;
    render->nFramePeriod = 1000 * frate.den / frate.num;
    render->FrameRate    = frate;
    render->PixelFormat  = (AVPixelFormat)pixfmt;

    // init for audio
    render->nSampleRate  = srate;
    render->SampleFormat = sndfmt;
    render->nChanLayout  = ch_layout;

    // create adev & vdev
    render->adev = adev_create(0, (int)(44100.0 * frate.den / frate.num + 0.5) * 4);
    render->vdev = vdev_create(surface, 0, 0, 0, frate.num / frate.den);

    // make adev & vdev sync together
    int64_t *papts = NULL;
    vdev_getavpts(render->vdev, &papts, NULL);
    adev_syncapts(render->adev,  papts);

    RECT rect; GetClientRect((HWND)surface, &rect);
    render_setrect (render, rect.left, rect.top, rect.right, rect.bottom);
    render_setspeed(render, 100);

    return render;
}
void render_setparam(void *hrender, DWORD id, void *param)
{
    RENDER *render = (RENDER*)hrender;
    switch (id)
    {
    case PARAM_AUDIO_VOLUME:
        render->nRenderVolume = *(int*)param;
        adev_volume(render->adev, *(int*)param);
        break;
    case PARAM_VIDEO_POSITION:
        if (*(int64_t*)param)
        {
            int64_t *papts = NULL;
            int64_t *pvpts = NULL;
            vdev_getavpts(render->vdev, &papts, &pvpts);
            if (render->adev) *papts = *(int64_t*)param;
            if (render->vdev) *pvpts = *(int64_t*)param;
        }
        break;
    case PARAM_PLAYER_SPEED:
        render_setspeed(render, *(int*)param);
        break;
    }
}