GStreamer插件优先级

当我们直接使用高层的playbin来进行媒体播放时,没有可操作的途径来选择解码器,只能通过调整默认的解码器优先级来实现选择。

GST_PLUGIN_FEATURE_RANK. (Since: 1.18)
This environment variable can be used to adjust rank of each plugin feature.
The variable takes a comma-separated list of plugin_feature:rank pairs to set specific ranks for the individual plugin features. The rank can be an arbitrary numerical value or one of pre-defined rank values from NONE(0) to PRIMARY(256) in case-insensitive manner. In addition to the pre-defined rank values, MAX is an acceptable value to set higher rank than the rank of other existing plugin features.
Example: GST_PLUGIN_FEATURE_RANK=foo:PRIMARY,bar:primary,foobar:128
As a result of the above example, the foo andbar plugin feature rank values are PRIMARY(256) and SECONDARY(128) rank value will be assigned to foobar.

通过宏调整优先级

GST_PLUGIN_FEATURE_RANK=foo:PRIMARY,bar:primary,foobar:128

如以下方式播放音频

gst-launch-1.0 playbin uri=file:///backup/1.flac audiosink=alsasink

GStreamer中demuxer,decoder,encoder类型的element都有自己的优先级,在注册时通过rank值指定。该值的基本类型定义在 gst/gstpluginfeature.h 中,如下:

typedef enum {
GST_RANK_NONE = 0,
GST_RANK_MARGINAL = 64,
GST_RANK_SECONDARY = 128,
GST_RANK_PRIMARY = 256
} GstRank;

这些element的优先级,通过注册element时传入的rank值决定,注册element的API位于 gst/gstelementfactory.h中,如下:

gboolean gst_element_register(GstPlugin *plugin, const gchar *name, guint rank, GType type)

比如libav中的音频解码器注册

gboolean
gst_ffmpegauddec_register (GstPlugin * plugin)
{
    ...
    /* (Ronald) MPEG-4 gets a higher priority because it has been well-
     * tested and by far outperforms divxdec/xviddec - so we prefer it.
     * msmpeg4v3 same, as it outperforms divxdec for divx3 playback.
     * VC1/WMV3 are not working and thus unpreferred for now. */
    switch (in_plugin->id) {
      case AV_CODEC_ID_RA_144:
      case AV_CODEC_ID_RA_288:
      case AV_CODEC_ID_COOK:
        rank = GST_RANK_PRIMARY;
        break;
        /* SIPR: decoder should have a higher rank than realaudiodec.
         */
      case AV_CODEC_ID_SIPR:
        rank = GST_RANK_SECONDARY;
        break;
      case AV_CODEC_ID_MP3:
        rank = GST_RANK_NONE;
        break;
      default:
        rank = GST_RANK_MARGINAL;
        break;
    }
    if (!gst_element_register (plugin, type_name, rank, type)) {
      g_warning ("Failed to register %s", type_name);
      g_free (type_name);
      return FALSE;
    }
    
    ...
 }

gst-inspect查看优先级flac

root@telechips-tcc8971-lcn-2:# gst-inspect-1.0 | grep flac

libav: avdec_flac: libav FLAC (Free Lossless Audio Codec) decoder
omx: omxflacdec: Free Lossless audio decoder
audioparsers: flacparse: FLAC audio parser
typefindfunctions: application/x-id3v2: mp3, mp2, mp1, mpga, ogg, flac, tta
typefindfunctions: application/x-id3v1: mp3, mp2, mp1, mpga, ogg, flac, tta
typefindfunctions: audio/x-flac: flac

avdec_flac优先级值

root@telechips-tcc8971-lcn-2:# gst-inspect-1.0 avdec_flac

Factory Details:
Rank marginal (64)
Long-name libav FLAC (Free Lossless Audio Codec) decoder
Klass Codec/Decoder/Audio
...

root@telechips-tcc8971-lcn-2:# gst-inspect-1.0 omxflacdec

Factory Details:
Rank primary + 1 (257)
Long-name Free Lossless audio decoder
Klass Codec/Decoder/Audio
...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值