⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svlc_interface.c

📁 Last change: 2008-02-03 This is the source code of KCeasy。
💻 C
📖 第 1 页 / 共 2 页
字号:
}

/**
 * Zoom video. This only has an effect if fitwindow is false.
 *
 * @param zoom  Zoom factor (e.g. 0.5, 1.0, 1.5, 2.0).
 *
 * @return  0 Success.
 *         -1 Error.
 */
static int SVLC_CC if_set_zoom (HSVLC svlc, float zoom)
{
    vlc_t *vlc;
    vout_thread_t *vout;
    playlist_t *playlist;
	vlc_value_t val;
    
	if (zoom <= 0)
		return -1;

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

	val.f_float = zoom;

    if ((vout = vlc_object_find (vlc, VLC_OBJECT_VOUT, FIND_CHILD)))
    {
		var_Set (vout, "zoom", val);

		/* FIXME: This will recreate the picture buffers and everything. I
		 * believe that's a Bad Thing.
		 */
	    vout->i_changes |= VOUT_SIZE_CHANGE;
	    vlc_object_release (vout);
    }

    if ((playlist = vlc_object_find (vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD)))
    {
		var_Set (playlist, "zoom", val);
        vlc_object_release (playlist);
    }

	var_Set (vlc, "zoom", val);

    release_vlc (vlc);
    
	return 0;
}


/*****************************************************************************
 * Audio output
 *****************************************************************************/

/**
 * Get audio volume.
 *
 * @return >= 0 Current volume in [0,1].
 *           -1 Error.
 */
static float SVLC_CC if_get_volume (HSVLC svlc)
{
    vlc_t *vlc;
    audio_volume_t volume;

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

	if (svlc->saved_volume >= 0)
		volume = svlc->saved_volume;
	else
		aout_VolumeGet (vlc, &volume);
	
    release_vlc (vlc);
    
	return ((float)volume) / AOUT_VOLUME_DEFAULT;
}

/**
 * Set audio volume.
 *
 * @param volume  Volume in [0,1].
 *
 * @return  0 Success.
 *         -1 Error.
 */
static int SVLC_CC if_set_volume (HSVLC svlc, float volume)
{
    vlc_t *vlc;

	if (volume < 0) volume = 0;
	if (volume > 1) volume = 1;

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

	/* Note: We use AOUT_VOLUME_DEFAULT instead of AOUT_VOLUME_MAX because the
	 * current software scaling used by vlc uses AOUT_VOLUME_DEFAULT as 100%
	 * of original volume. This prevents sound distortion when going above it.
	 */
	volume *= AOUT_VOLUME_DEFAULT;

	if (svlc->saved_volume >= 0)
		svlc->saved_volume = volume;
	else
	    aout_VolumeSet (vlc, (audio_volume_t)volume);

    release_vlc (vlc);
    
	return 0;
}

/**
 * Get audio mute.
 *
 * @return  1 Muted.
 *          0 Not muted.
 *         -1 Error.
 */
static int SVLC_CC if_get_mute (HSVLC svlc)
{
	return (svlc->saved_volume < 0) ? 0 : 1;
}

/**
 * Set audio mute.
 *
 * @param mute  1 Mute audio
 *              0 Unmute audio
 *             -1 Toggle mute
 *
 * @return  0 Success.
 *         -1 Error.
 */
static int SVLC_CC if_set_mute (HSVLC svlc, int mute)
{
    vlc_t *vlc;
    audio_volume_t volume;
	int res = 0;

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

	/* if svlc->saved_volume is negative we are not muted */
    
	if (svlc->saved_volume < 0 && (mute == 1 || mute == -1))
	{
		/* Mute */
		aout_VolumeGet (vlc, &volume);
	    svlc->saved_volume = (int)volume;
        res = aout_VolumeSet (vlc, AOUT_VOLUME_MIN);
	}
	else if (svlc->saved_volume >= 0 && (mute == 0 || mute == -1))
	{
		/* Un-Mute */
        res = aout_VolumeSet (vlc, (audio_volume_t)svlc->saved_volume);
		svlc->saved_volume = -1;
	}

	release_vlc (vlc);

	return res;
}


/*****************************************************************************
 * Playback
 *****************************************************************************/

/**
 * Play target.
 *
 * @param target  Target to play, e.g. filename.
 *
 * @return  0 Success.
 *         -1 Error.
 */
static int SVLC_CC if_play (HSVLC svlc, const char *target)
{
    vlc_t *vlc;
    playlist_t *playlist;

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

	/* get playlist or create one if necessary */
    if (!(playlist = vlc_object_find (vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD)))
    {
        msg_Dbg (vlc, "no playlist present, creating one" );

        if (!(playlist = playlist_Create (vlc)))
        {
			release_vlc (vlc);
            return -1;
        }

        vlc_object_yield (playlist);

		/* reregister playlist hooks */
		svlc_event_register_callbacks (svlc, vlc);
    }

	/* set loading state */
	svlc_event_set_playback_state (svlc, SVLC_PLAYBACK_LOADING);

	/* empty playlist */
	playlist_Clear (playlist);

	/* add target to playlist and start playback */
    playlist_Add (playlist, target, target, PLAYLIST_INSERT | PLAYLIST_GO, 0);

    vlc_object_release (playlist);
	release_vlc (vlc);

	return 0;
}

/**
 * Stop playback and remove any targets.
 *
 * @return  0 Success.
 *         -1 Error.
 */
static int SVLC_CC if_stop (HSVLC svlc)
{
    vlc_t *vlc;
    playlist_t *playlist;

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

    if (!(playlist = vlc_object_find (vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD)))
    {
        msg_Dbg (vlc, "no playlist to stop" );
		release_vlc (vlc);
        return -1;
    }

	/* stop playlist */
    playlist_Stop (playlist);

#if 0 /* race condition with input */
	/* empty playlist */
	playlist_Clear (playlist);
#endif

    vlc_object_release (playlist);
	release_vlc (vlc);

	return 0;
}

/**
 * Set pause.
 *
 * @param pause  1 Pause playback
 *               0 Resume playback
 *              -1 Toggle pause
 *
 * @return  0 Success.
 *         -1 Error.
 */
static int SVLC_CC if_pause (HSVLC svlc, int pause)
{
    vlc_t *vlc;
    input_thread_t *input;
    vlc_value_t status;

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

    if (!(input = vlc_object_find (vlc, VLC_OBJECT_INPUT, FIND_CHILD)))
    {
	    release_vlc (vlc);
        return -1;
    }

	var_Get (input, "state", &status);
	
	if (status.i_int == PAUSE_S)
	{
		if (pause == -1 || pause == 0)
		{
			status.i_int = PLAYING_S;
			/* calling var_Set twice with PAUSE_S resumes playback */
			var_Set (input, "state", status);
		}
	}
	else
	{
		if (pause == -1 || pause == 1)
		{
			status.i_int = PAUSE_S;
			var_Set (input, "state", status);
		}
	}

    vlc_object_release (input);
	release_vlc (vlc);

	return 0;
}

/**
 * Retrieve playback state.
 *
 * @return  See declaration of SVlcPlaybackState
 */
static SVlcPlaybackState SVLC_CC if_get_playback_state (HSVLC svlc)
{
#if 0
    vlc_t *vlc;
    input_thread_t *input;
    vlc_value_t status;

    if (!(vlc = aquire_vlc (svlc)))
        return SVLC_PLAYBACK_STOPPED;

    if (!(input = vlc_object_find (vlc, VLC_OBJECT_INPUT, FIND_CHILD)))
    {
	    release_vlc (vlc);
        return SVLC_PLAYBACK_CLOSED;
    }

	var_Get (input, "state", &status);

    vlc_object_release (input);
	release_vlc (vlc);

	switch (status.i_int)
	{
	case INIT_S:		return SVLC_PLAYBACK_LOADING;
	case PLAYING_S:		return SVLC_PLAYBACK_PLAYING;
	case PAUSE_S:		return SVLC_PLAYBACK_PAUSED;
	case END_S:         return SVLC_PLAYBACK_STOPPED;
	}

	return SVLC_PLAYBACK_CLOSED;
#else
	return svlc->playback_state;
#endif
}

/**
 * Get current stream position.
 *
 * @return >= 0 Current postition in [0,1].
 *           -1 Error.
 */
static float SVLC_CC if_get_position (HSVLC svlc)
{
    vlc_t *vlc;
    input_thread_t *input;
    vlc_value_t position;

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

    if (!(input = vlc_object_find (vlc, VLC_OBJECT_INPUT, FIND_CHILD)))
    {
	    release_vlc (vlc);
        return -1;
    }

    vlc_mutex_lock (&input->object_lock);
	var_Get (input, "position", &position);
    vlc_mutex_unlock (&input->object_lock);

    vlc_object_release (input);
	release_vlc (vlc);

	return position.f_float;
}

/**
 * Seek to new stream position (if seekable).
 *
 * @param position  Position in [0,1] to seek to.
 *
 * @return  0 Success.
 *         -1 Error.
 */
static int SVLC_CC if_set_position (HSVLC svlc, float position)
{
    vlc_t *vlc;
    input_thread_t *input;
    vlc_value_t val;

	if (position < 0) position = 0;
	if (position > 1) position = 1;

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

    if (!(input = vlc_object_find (vlc, VLC_OBJECT_INPUT, FIND_CHILD)))
    {
	    release_vlc (vlc);
        return -1;
    }

	var_Get (input, "seekable", &val);

	if (!val.b_bool)
	{
	    vlc_object_release (input);
		release_vlc (vlc);
		return -1;
	}

	val.f_float = position;
	var_Set (input, "position", val);

    vlc_object_release (input);
	release_vlc (vlc);

	return 0;
}

/**
 * Get seekability of current stream.
 *
 * @return  1 Current stream is seekable
 *          0 Current stream is not seekable
 *         -1 Error.
 */
static int SVLC_CC if_is_seekable (HSVLC svlc)
{
    vlc_t *vlc;
    input_thread_t *input;
    vlc_value_t val;

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

    if (!(input = vlc_object_find (vlc, VLC_OBJECT_INPUT, FIND_CHILD)))
    {
	    release_vlc (vlc);
        return -1;
    }

	var_Get (input, "seekable", &val);

    vlc_object_release (input);
	release_vlc (vlc);

	return val.b_bool;
}

/**
 * Get play length of current stream.
 *
 * @return > 0 Stream duration in milliseconds.
 *           0 No time data available for this stream.
 *          -1 Error.
 */
static int SVLC_CC if_get_duration (HSVLC svlc)
{
    vlc_t *vlc;
    input_thread_t *input;
    vlc_value_t length;

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

    if (!(input = vlc_object_find (vlc, VLC_OBJECT_INPUT, FIND_CHILD)))
    {
	    release_vlc (vlc);
        return -1;
    }

    var_Get (input, "length", &length);

    vlc_object_release (input);
	release_vlc (vlc);

	return (length.i_time / 1000);
}

/**
 * Get information about an the currently opened stream.
 *
 * @param info  Pointer to SVlcStreamInfo which is filled with the data.
 *
 * @return  0 Success.
 *         -1 Error.
 */
int SVLC_CC if_get_stream_info (HSVLC svlc, SVlcStreamInfo *info)
{
    vlc_t *vlc;
    input_thread_t *input;
	vlc_value_t val;

	if (!info)
		return -1;

	if (svlc->playback_state != SVLC_PLAYBACK_OPEN &&
	    svlc->playback_state != SVLC_PLAYBACK_PLAYING &&
	    svlc->playback_state != SVLC_PLAYBACK_PAUSED &&
	    svlc->playback_state != SVLC_PLAYBACK_STOPPED)
	{
		return -1;
	}

    if (!(vlc = aquire_vlc (svlc)))
        return -1;

    if (!(input = vlc_object_find (vlc, VLC_OBJECT_INPUT, FIND_CHILD)))
    {
	    release_vlc (vlc);
        return -1;
    }

	/* audio */
    var_Change (input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL);
	/* - 1 for "Disabled" choice */
	info->audio_streams = val.i_int > 0 ? val.i_int - 1 : 0;

	/* video */
    var_Change (input, "video-es", VLC_VAR_CHOICESCOUNT, &val, NULL);
	/* - 1 for "Disabled" choice */
	info->video_streams = val.i_int > 0 ? val.i_int - 1 : 0;

#ifdef DEBUG
	msg_Dbg (input, "audio streams: %d, video_streams: %d",
	         info->audio_streams, info->video_streams);
#endif

    vlc_object_release (input);
	release_vlc (vlc);

	/* demuxer doesn't yet know how much streams there are */
	if (info->audio_streams == 0 && info->video_streams == 0)
		return -1;

	return 0;
}

/*****************************************************************************
 * Interface initialization
 *****************************************************************************/

int svlc_init_interface (SVlcInterface *intf)
{
	if (intf == NULL)
		return -1;

	/* instance management */
	intf->create				= if_create;
	intf->destroy				= if_destroy;
	intf->set_callback			= if_set_callback;
	intf->get_vlc_version		= if_get_vlc_version;
	intf->set_udata				= if_set_udata;
	intf->get_udata				= if_get_udata;

	/* video out */
	intf->set_window			= if_set_window;
	intf->set_visualization     = if_set_visualization;
	intf->set_fullscreen		= if_set_fullscreen;
	intf->get_fullscreen		= if_get_fullscreen;
	intf->set_fitwindow			= if_set_fitwindow;
	intf->get_fitwindow			= if_get_fitwindow;
	intf->set_zoom				= if_set_zoom;
	intf->get_zoom				= if_get_zoom;

	/* audio out */
	intf->set_volume			= if_set_volume;
	intf->get_volume			= if_get_volume;
	intf->set_mute				= if_set_mute;
	intf->get_mute				= if_get_mute;

	/* playback */
	intf->play					= if_play;
	intf->stop					= if_stop;
	intf->pause					= if_pause;
	intf->get_playback_state	= if_get_playback_state;
	intf->set_position			= if_set_position;
	intf->get_position			= if_get_position;
	intf->is_seekable			= if_is_seekable;
	intf->get_duration			= if_get_duration;
	intf->get_stream_info		= if_get_stream_info;

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -