簡體   English   中英

如何在 C++ 中創建 GstValueArray?

[英]How do I create a GstValueArray in C++?

我正在嘗試在 C++ 中創建一個 GstValueArray 以更新某些 GStreamer 代碼中的 pad 屬性,但無法從文檔中弄清楚如何執行此操作。 我的問題是我有一個 GStreamer 元素,該元素具有帶有屬性“維度”的接收器墊,這是一個“Gint 類型的 GValues 的 GstValueArray”。 請參閱 gst-inspect-1.0 中的 output,為簡潔起見省略了一些部分:

...

Pad Templates:
  SINK template: 'sink_%u'
    Availability: On request
    Capabilities:
      ...
    Type: GstVideoComposerSinkPad
    Pad Properties:
      dimensions          : The destination rectangle width and height, if left as '0' they will be the same as input dimensions ('<WIDTH, HEIGHT>')
                            flags: readable, writable, changeable in NULL, READY, PAUSED or PLAYING state, 0x4000
0000
                            GstValueArray of GValues of type "gint"

我希望能夠從我的代碼中更新尺寸屬性。 目前,我正在嘗試這個:

const auto pad = gst_element_get_static_pad(videomixer, sink_name.c_str());
...
// Create a GValue for width
GValue width = G_VALUE_INIT;
g_value_init(&width, G_TYPE_INT);
g_value_set_int(&width, cameraUpdate["width"]);

// Create a GValue for height
GValue height = G_VALUE_INIT;
g_value_init(&height, G_TYPE_INT);
g_value_set_int(&height, cameraUpdate["height"]);

// Create the GstValueArray
GValue new_dimensions = G_VALUE_INIT;
g_value_init(&new_dimensions, GST_TYPE_ARRAY);
gst_value_array_append_value(&new_dimensions, &width);
gst_value_array_append_value(&new_dimensions, &height);

// Update the pad property "dimensions" with this array
g_object_set(pad, "dimensions", new_dimensions, nullptr);

但這有一個運行時錯誤: GLib-ERROR **: 17:21:07.582: ../../../../glib/gmem.c:135: failed to allocate 62846110096 bytes 我也不確定我在哪里意外請求了 62 GB 的 memory。

謝謝!

g_object_set是一個方便的 function,除其他外,它在內部解析屬性的 GType 並自動為您創建底層 GValue。 如果您自己創建 GValue,則需要改用g_object_set_property

將您的g_object_set替換為:

g_object_set_property (G_OBJECT(pad), “dimensions”, &new_dimensions)

順便說一句,記得在每個 GValue 上調用g_value_unset來清理所有內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM