# 开发定制 GStreamer 插件

在尝试编写自己的 GStreamer 插件之前，您需要先熟悉核心概念。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by Microsoft Visio, SVG Export guidelines-gstreamer-plugin.svg guidelines-gstreamer-plugin -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:v="http://schemas.microsoft.com/visio/2003/SVGExtensions/" width="9.9225in" height="0.9167in" viewbox="0 0 714.42 66.0024" xml:space="preserve" color-interpolation-filters="sRGB" class="st7" aria-label="../_images/guidelines-gstreamer-plugin.svg" svgdefaultwidth="714"><v:documentproperties v:langid="1033" v:viewmarkup="false">	<v:userdefs>		<v:ud v:nameu="msvNoAutoConnect" v:val="VT0(1):26"></v:ud>	</v:userdefs></v:documentproperties>
<style>.svg-1 .st1 { fill: #2a2aea; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-1 .st2 { fill: #ffffff; font-family: Microsoft YaHei UI; font-size: 1.00001em; font-weight: bold }
.svg-1 .st3 { font-size: 1em }
.svg-1 .st4 { font-family: Arial; font-size: 1em }
.svg-1 .st5 { marker-end: url("#mrkr4-27"); stroke: #000000; stroke-linecap: butt; stroke-width: 2 }
.svg-1 .st6 { fill: #000000; fill-opacity: 1; stroke: #000000; stroke-opacity: 1; stroke-width: 0.44247787610619 }
.svg-1 .st7 { fill: none; fill-rule: evenodd; font-size: 12px; overflow: visible; stroke-linecap: square; stroke-miterlimit: 3 }</style>
<defs id="Markers">	<g id="lend4">		<path d="M 2 1 L 0 0 L 2 -1 L 2 1 " style="stroke:none"></path>	</g>	<marker id="mrkr4-27" class="st6" v:arrowtype="4" v:arrowsize="2" v:setback="4.52" refx="-4.52" orient="auto" markerunits="strokeWidth" overflow="visible">		<use xlink:href="#lend4" transform="scale(-2.26,-2.26) "></use>	</marker></defs><g v:mid="23" v:index="9" v:groupcontext="foregroundPage">	<title>guidelines-gstreamer-plugin</title>	<v:pageproperties v:drawingscale="0.0138889" v:pagescale="0.0138889" v:drawingunits="29" v:shadowoffsetx="9" v:shadowoffsety="-9"></v:pageproperties>	<g id="shape1-1" v:mid="1" v:groupcontext="shape" transform="translate(0.229653,0.179487)">		<title>Sheet.1</title>		<desc>最终确定 所支持的模型</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="57.1237" cy="33.0024" width="114.25" height="66"></v:textrect>		<path d="M0 62.25 A3.75009 3.75009 -180 0 0 3.75 66 L110.5 66 A3.75009 3.75009 -180 0 0 114.25 62.25 L114.25 3.75 A3.75009					 3.75009 -180 0 0 110.5 0 L3.75 0 A3.75009 3.75009 -180 0 0 -0 3.75 L0 62.25 Z" class="st1"></path>		<text x="33.12" y="29.35" class="st2" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>最终确定<v:lf></v:lf><tspan x="21.12" dy="1.216em" class="st3">所支持的模型</tspan></text>		</g>	<g id="shape2-5" v:mid="2" v:groupcontext="shape" transform="translate(450.357,0.179487)">		<title>Sheet.2</title>		<desc>实现标准 gstreamer 函数</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="57.1237" cy="33.0024" width="114.25" height="66"></v:textrect>		<path d="M0 62.25 A3.75009 3.75009 -180 0 0 3.75 66 L110.5 66 A3.75009 3.75009 -180 0 0 114.25 62.25 L114.25 3.75 A3.75009					 3.75009 -180 0 0 110.5 0 L3.75 0 A3.75009 3.75009 -180 0 0 -0 3.75 L0 62.25 Z" class="st1"></path>		<text x="33.12" y="29.35" class="st2" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>实现标准<tspan class="st4"> </tspan><tspan x="14.44" dy="1.216em" class="st4">gstreamer </tspan>函数</text>		</g>	<g id="shape3-10" v:mid="3" v:groupcontext="shape" transform="translate(150.275,0.179487)">		<title>Sheet.3</title>		<desc>实现父类</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="57.1237" cy="33.0024" width="114.25" height="66"></v:textrect>		<path d="M0 62.25 A3.75009 3.75009 -180 0 0 3.75 66 L110.5 66 A3.75009 3.75009 -180 0 0 114.25 62.25 L114.25 3.75 A3.75009					 3.75009 -180 0 0 110.5 0 L3.75 0 A3.75009 3.75009 -180 0 0 -0 3.75 L0 62.25 Z" class="st1"></path>		<text x="33.12" y="36.65" class="st2" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>实现父类</text>		</g>	<g id="shape4-13" v:mid="4" v:groupcontext="shape" transform="translate(300.312,0.179487)">		<title>Sheet.4</title>		<desc>定义源、同步和 capsule</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="57.1237" cy="33.0024" width="114.25" height="66"></v:textrect>		<path d="M0 62.25 A3.75009 3.75009 -180 0 0 3.75 66 L110.5 66 A3.75009 3.75009 -180 0 0 114.25 62.25 L114.25 3.75 A3.75009					 3.75009 -180 0 0 110.5 0 L3.75 0 A3.75009 3.75009 -180 0 0 -0 3.75 L0 62.25 Z" class="st1"></path>		<text x="15.12" y="29.45" class="st2" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>定义源、同步和<tspan class="st4"> </tspan><tspan x="34.78" dy="1.204em" class="st4">capsule</tspan></text>		</g>	<g id="shape5-18" v:mid="5" v:groupcontext="shape" transform="translate(600.395,0.179487)">		<title>Sheet.5</title>		<desc>为每个模型 实现模块</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="57.1237" cy="33.0024" width="114.25" height="66"></v:textrect>		<path d="M0 62.25 A3.75009 3.75009 -180 0 0 3.75 66 L110.5 66 A3.75009 3.75009 -180 0 0 114.25 62.25 L114.25 3.75 A3.75009					 3.75009 -180 0 0 110.5 0 L3.75 0 A3.75009 3.75009 -180 0 0 -0 3.75 L0 62.25 Z" class="st1"></path>		<text x="27.12" y="29.35" class="st2" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>为每个模型<v:lf></v:lf><tspan x="33.12" dy="1.216em" class="st3">实现模块</tspan></text>		</g>	<g id="shape154-22" v:mid="154" v:groupcontext="shape" transform="translate(114.477,-27.9744)">		<title>Sheet.154</title>		<path d="M0 66 L26.76 66" class="st5"></path>	</g>	<g id="shape155-28" v:mid="155" v:groupcontext="shape" transform="translate(264.522,-28)">		<title>Sheet.155</title>		<path d="M0 66 L26.75 66" class="st5"></path>	</g>	<g id="shape156-33" v:mid="156" v:groupcontext="shape" transform="translate(414.56,-28)">		<title>Sheet.156</title>		<path d="M0 66 L26.76 66" class="st5"></path>	</g>	<g id="shape157-38" v:mid="157" v:groupcontext="shape" transform="translate(564.605,-28.5385)">		<title>Sheet.157</title>		<path d="M0 66 L26.75 66" class="st5"></path>	</g></g>
</svg>

**实施新的 GStreamer 插件的工作流**

如需实现定制插件，您需要：

- 决定是从现有的基本模板类继承还是直接从 GstElement 主干类继承。
- 指定 pads、elements 和 caps (capabilities)。
- 实现 init、set\_caps、set\_property、transform 等关键函数。
- 注册插件。

主要教程、指南和资源

- 教程：

    [https://gstreamer.freedesktop.org/documentation/tutorials/index.html?gi-language=c](https://gstreamer.freedesktop.org/documentation/tutorials/index.html?gi-language=c)
- 插件编写者指南：

    [https://gstreamer.freedesktop.org/documentation/plugin-development/index.html?gi-language=c](https://gstreamer.freedesktop.org/documentation/plugin-development/index.html?gi-language=c)
- 其他文档：

    [https://gstreamer.freedesktop.org/documentation/additional/index.html?gi-language=c](https://gstreamer.freedesktop.org/documentation/additional/index.html?gi-language=c)
- API 参考：

    [https://gstreamer.freedesktop.org/documentation/libs.html?gi-language=c](https://gstreamer.freedesktop.org/documentation/libs.html?gi-language=c)
- Caps 功能：

    [https://gstreamer.freedesktop.org/documentation/gstreamer/gstcapsfeatures.html?gi-language=c](https://gstreamer.freedesktop.org/documentation/gstreamer/gstcapsfeatures.html?gi-language=c)
- Caps 协商：

    [https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/negotiation.html?gi-language=c](https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/negotiation.html?gi-language=c)

要点

开发新插件时请记住以下要点：

- 继承和基类

    - 每个 GStreamer 插件要么从基本模板类继承，要么直接从 GstElement 主干类继承。
    - GstElement 类可用作一个最小的框架，而开发者负责实现事件处理、查询、缓存管理和其他核心功能。
    - 当现有的基本模板类均不符合插件的要求时，开发者可以使用 GstElement 类开始进行开发。
- 基本模板类

    - GStreamer 提供了诸多基本模板类，用于处理大多数事件和查询；但是，这些基类不能管理对缓存的处理操作。
- 缓存管理

    - 根据所选的基类，开发者必须实施缓存管理并重写相关的虚方法。
    - 有些方法有默认实现，而其他方法则仅有虚函数。
- 功能

    - Caps 在 GstPadTemplates 上公开，用以指定 pad 支持的媒体类型。
    - Pads 采用 caps 来交换有关其支持的格式的信息。连接 pads 的 caps 交集决定了通信所采用的实际数据格式。
- 基类的优点

    - 基类提供了虚方法，开发者可以使用定制实现重写这些方法。
    - 利用现有基类的功能，开发者可以专注于插件设计所需的特定定制。

注释

- 这些说明基于 `imsdk.lnx.2.0.0.r1-rel` 版本。
- 本指南适用于经验丰富的开发者，
他们可通过在现有插件的基础上构建 Qualcomm IM SDK 插件
来处理不受支持的用例（例如超分辨率）。
- 创建定制 GStreamer 插件是一项进阶任务，
只能由经验丰富的 GStreamer 开发者完成。
- 在开源领域和官方 GStreamer 门户上，
提供了有关此任务的大量教程。
- 可将本指南用作模板并使用开源资源来
了解如何开发定制插件。

Last Published: Oct 23, 2025

[Previous Topic
为定制模型添加后处理支持](https://docs.qualcomm.com/bundle/publicresource/80-70018-15BY/topics/add-postprocessing-support-custom-model.md) [Next Topic
开发超分辨率插件](https://docs.qualcomm.com/bundle/publicresource/80-70018-15BY/topics/development-process-for-new-plugin.md)