VLC-Android退出流程

最近在分析一个播放器退出ANR的问题时,详细地跟踪了VLC的退出流程,这里问题的分析先按下不表,我们先结合代码详细了解下播放器的退出流程。

1. java—>jni—>native的Stop调用流程,没什么好说的,直接上代码

//MediaPlayer.java

/**

 * Stops the playing media

 *

 */

public void stop() {

    synchronized (this) {

        mPlayRequested = false;

        mPlaying = false;

        mAudioReset = true;

    }

    //调用native方法

    nativeStop();

    if (mAfd != nulltry {

        mAfd.close();

    catch (IOException ignored) {}

}

//libvlcjni-mediaplayer.c

void

Java_org_videolan_libvlc_MediaPlayer_nativeStop(JNIEnv *env, jobject thiz)

{

    LOGI("libvlc_MediaPlayer_nativeStop +++ ");

    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)

    {

        LOGI("libvlc_MediaPlayer_nativeStop -- ");

        return;

    }

    //jni只是桥梁,这里调用真正的stop

    libvlc_media_player_stop(p_obj->u.p_mp);

    LOGI("libvlc_MediaPlayer_nativeStop ---");

}

//media_player.c

/*

 * Release the associated input thread.

 *

 * Object lock is NOT held.

 * Input lock is held or instance is being destroyed.

 */

static void release_input_thread( libvlc_media_player_t *p_mi )

{

    assert( p_mi );

    input_thread_t *p_input_thread = p_mi->input.p_thread;

    if( !p_input_thread )

        return;

    p_mi->input.p_thread = NULL;

    media_detach_preparsed_event( p_mi->p_md );

    //删除回调函数

    var_DelCallback( p_input_thread, "can-seek",

                     input_seekable_changed, p_mi );

    var_DelCallback( p_input_thread, "can-pause",

                    input_pausable_changed, p_mi );

    var_DelCallback( p_input_thread, "program-scrambled",

                    input_scrambled_changed, p_mi );

    var_DelCallback( p_input_thread, "intf-event",

                     input_event_changed, p_mi );

    del_es_callbacks( p_input_thread, p_mi );

    //这里先后调用了input_thread的input_Stop和input_Close函数

    /* We owned this one */

    input_Stop( p_input_thread );

    input_Close( p_input_thread );

}

2.input_thread本身是一个while循环,是播放的主线程,不停地demux数据并处理控制事件。在退出主线程前,需要先将播放器的其他线程全部退出。

/**

 * Close an input

 *

 * It does not call input_Stop itself.

 */

void input_Close( input_thread_t *p_input )

{

    if( input_priv(p_input)->is_running )

        //input_Close函数关闭了播放主线程

        vlc_join( input_priv(p_input)->thread, NULL );

    vlc_interrupt_deinit( &input_priv(p_input)->interrupt );

    vlc_object_release( p_input );

}

/*****************************************************************************

 * Run: main thread loop

 * This is the "normal" thread that spawns the input processing chain,

 * reads the stream, cleans up and waits

 *****************************************************************************/

static void *Run( void *data )

{

    input_thread_private_t *priv = data;

    input_thread_t *p_input = &priv->input;

    vlc_interrupt_set(&priv->interrupt);

    if( !Init( p_input ) )

    {

        if( priv->b_can_pace_control && priv->b_out_pace_control )

        {

            /* We don't want a high input priority here or we'll

             * end-up sucking up all the CPU time */

            vlc_set_priority( priv->thread, VLC_THREAD_PRIORITY_LOW );

        }

        //MainLoop函数中有一个while循环,在播放退出时该函数返回

        MainLoop( p_input, true ); /* FIXME it can be wrong (like with VLM) */

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值