gstreamer/subprojects/gst-docs/markdown/for-later/qt-gstreamer-vs-c-gstreamer.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

109 lines
3.2 KiB
Markdown
Raw Normal View History

# QtGStreamer vs C GStreamer
2016-05-16 14:30:34 +00:00
QtGStreamer is designed to mirror the C GStreamer API as closely as
possible. There are, of course, minor differences. They are documented
here.
## Common Functions
2016-05-16 14:30:34 +00:00
<table>
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<thead>
<tr class="header">
<th>C GStreamer</th>
<th>QtGStreamer</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>gst_element_factory_make()</code></td>
<td><code>QGst::ElementFactory::make(const QString &amp;factoryName, const char *elementName=NULL)</code></td>
</tr>
<tr class="even">
<td><code>gst_parse_bin_from_description()</code></td>
<td><code>QGst::Bin::fromDescription(const QString &amp;description, BinFromDescriptionOption ghostUnlinkedPads=Ghost)</code></td>
</tr>
<tr class="odd">
<td><code>gst_caps_from_string()</code></td>
<td><p><code>QGst::Caps::fromString(const QString &amp;string)</code></p></td>
</tr>
<tr class="even">
<td><code>g_signal_connect()</code></td>
<td><code>QGlib::connect(GObject* instance, const char *detailedSignal, T *receiver, R(T::*)(Args...) slot, ConnectFlags flags)</code></td>
</tr>
</tbody>
</table>
## Naming Convention
2016-05-16 14:30:34 +00:00
QtGStreamer follows a strict naming policy to help make cross
referencing easier:
#### Namespaces
2016-05-16 14:30:34 +00:00
The "G" namespace (`GObject`, `GValue`, etc...) is referred to as
"QGlib".
The "Gst" namespace (`GstObject`, `GstElement`, etc...) is referred to
as "QGst".
#### Class Names
2016-05-16 14:30:34 +00:00
Class names should be the same as their G\* equivalents, with the
namespace prefix removed. For example, "`GstObject`" becomes
"`QGst::Object`", "`GParamSpec`" becomes "`QGlib::ParamSpec`", etc...
#### Method Names
2016-05-16 14:30:34 +00:00
In general the method names should be the same as the GStreamer ones,
with the g\[st\]\_\<class\> prefix removed and converted to camel case.
For example,
2016-06-06 00:58:09 +00:00
``` c
2016-05-16 14:30:34 +00:00
gboolean gst_caps_is_emtpy(const GstCaps *caps);
```
becomes:
2016-06-06 00:58:09 +00:00
``` c
2016-05-16 14:30:34 +00:00
namespace QGst {
class Caps {
bool isEmpty() const;
}
}
```
There are cases where this may not be followed:
1. **Properties**. Most property getters have a "get" prefix, for
example, `gst_object_get_name()`. In QtGStreamer the "get" prefix is
omitted, so this becomes just `name()`.
2. **Overloaded members**. In C there is no possibility to have two
methods with the same name, so overloaded members usually have some
extra suffix, like "\_full". For example, `g_object_set_data()` and
`g_object_set_data_full()`. In C++ we just add a method with the
same name, or put optional parameters in the existing method.
3. **Other cases where the glib/gstreamer method name doesn't make much
sense**. For example, `gst_element_is_locked_state()`. That doesn't
make sense in english, as "sate" is the subject and should go before
the verb "is". So, it becomes `stateIsLocked()`.
## Reference Counting
2016-05-16 14:30:34 +00:00
Reference counting is handled the same way as Qt does. There is no need
to call `g_object_ref()`` and g_object_unref()`.
## Access to GStreamer Elements
2016-05-16 14:30:34 +00:00
QtGStreamer provides access to the underlying C objects, in case you
need them. This is accessible with a simple cast:
2016-06-06 00:58:09 +00:00
``` c
2016-05-27 18:19:02 +00:00
ElementPtr qgstElement = QGst::ElementFactory::make("playbin");
2016-05-16 14:30:34 +00:00
GstElement* gstElement = GST_ELEMENT(qgstElement);
```