ffmpeg移植到android,异常退出机制的移植

1.原生的ffmpeg退出机制与基础的退出处理方法:

ffmpeg的退出函数是:ffmpeg_cleanup。

ffmpeg首先会在main入口注册这个回调。

register_exit(ffmpeg_cleanup);

void register_exit(void (*cb)(int ret))
{
    program_exit = cb;
}

然后,在其他的地方调用,exit_program方法。

void exit_program(int ret)
{
    if (program_exit)
        program_exit(ret);

    exit(ret);
}

exit_program

如果是c,我们可以把对应的位置都改成返回值。因为android都是支持c++的,所以我们可以注册自己的退出方法,然后给调用层抛一个异常。实现方法:

void on_exit(int ret) {
  ffmpeg_cleanup(ret);

#ifdef DEBUG
    logd("ffmpeg exit: %d", ret);
#endif

    throw ret;
}
调用方式:
register_exit(on_exit);

2.cleanup的歧义:

这个函数是容易产生歧义的,根据一般的语法习惯,cleanup是清内存操作。可是ffmpeg的demo工程里面有个

term_exit();

这个函数的实现是:

static void term_exit_sigsafe(void)
{
#if HAVE_TERMIOS_H
    if(restore_tty)
        tcsetattr (0, TCSANOW, &oldtty);
#endif
}

void term_exit(void)
{
    av_log(NULL, AV_LOG_QUIET, "%s", "");
    term_exit_sigsafe();
}

这是个清空输出终端的函数,个人感觉和cleanup分开比较好。

而且当我移植到android上时,是没有终端操作到。所以,全部去掉就好。

3.term相关调用,很简单,所有相关的都删掉。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值