当前位置:网站首页>Tasks in GStreamer
Tasks in GStreamer
2022-07-05 19:40:00 【Hui's technical notes】
stay gstreamer in , You can easily create one when you need it task As an independent thread ,task It can be ordinary task, It can also be pad task, This needs to be determined according to specific needs , So let's see v4l2 and avdemux Inside task Code for .
task The creation of
gst-plugins-good/sys/v4l2/gstv4l2videodec.c
adopt gst_pad_start_task Start a pad task,task The function is gst_v4l2_video_dec_loop. The function is to activate v4l2 The decoding task, And when the task Exit time , Input processing will be disabled in drain when unlock Input , To prevent blocking :
/* start task */
if (!gst_pad_start_task (decoder->srcpad, (GstTaskFunction) gst_v4l2_video_dec_loop, self, NULL))
goto start_task_failed;
gst-libav/ext/libav/gstavdemux.c
Create a demux->task,task The function is gst_ffmpegdemux_loop,gst_task_init Will pass gst_task_new Indirect invocation , stay init Call in function ensure_klass_pool Make sure _global_task_pool Thread pool available ,start_task Will be task adopt gst_task_pool_push Put it in task In the thread pool of , below gst_pad_start_task You can see the call stack of .
/* static GstTaskPool *_global_task_pool = NULL; */
/* new task */
demux->task = gst_task_new ((GstTaskFunction) gst_ffmpegdemux_loop, demux, NULL);
g_rec_mutex_init (&demux->task_lock);
/* set lock */
gst_task_set_lock (demux->task, &demux->task_lock);
gst_ffmpegdemux_loop and gst_v4l2_video_dec_loop The two functions are task Of loop function , stay gstreamer in ,task Unlike pthread Of task, There needs to be a loop to ensure permanent task Always exist . Instead, it runs through the previous thread pool .
task Operation of
see gst_pad_start_task You can clearly see the code and stack of task Of new,init,start It's all in gst_pad_start_task It is realized in , These are in if not through gst_pad_start_task Starting up task, Both need to be called manually .
1 gst_task_init gsttask.c 249 0x7ffff7b49fa3
2 g_type_create_instance 0x7ffff75559c5
4 g_object_new_with_properties 0x7ffff7537ee5
5 g_object_new 0x7ffff7538961
6 gst_task_new gsttask.c 482 0x7ffff7b4a5ad
7 gst_pad_start_task gstpad.c 6287 0x7ffff7b1d7fe
call start_task The stack :
1 gst_task_pool_push gsttaskpool.c 252 0x7ffff7b4b820
2 start_task gsttask.c 712 0x7ffff7b49f19
3 gst_task_set_state_unlocked gsttask.c 744 0x7ffff7b4ad3e
4 gst_task_set_state gsttask.c 792 0x7ffff7b4ad3e
7 gst_pad_start_task gstpad.c 6287 0x7ffff7b1d7fe
gst_task_pool_push Is in start_task Invocation in function , take task Put it in the thread pool , Appoint taskpool Function is gst_task_func:
/* push on the thread pool, we remember the original pool because the user * could change it later on and then we join to the wrong pool. */
priv->pool_id = gst_object_ref (priv->pool);
priv->id =
gst_task_pool_push (priv->pool_id, (GstTaskPoolFunction) gst_task_func,
task, &error);
gst_task_pool_push Continue call in GstTaskPoolClass Of push function default_push, stay default_push The function is called g_thread_pool_push The function is placed in g_thread_pool Inside , Back task The operation of is GLib Of g_thread_pool Relevant implementation .
gpointer
gst_task_pool_push (GstTaskPool * pool, GstTaskPoolFunction func,
gpointer user_data, GError ** error)
{
GstTaskPoolClass *klass;
g_return_val_if_fail (GST_IS_TASK_POOL (pool), NULL);
klass = GST_TASK_POOL_GET_CLASS (pool);
if (klass->push == NULL)
goto not_supported;
/* gsttaskpool_class->push = default_push; */
return klass->push (pool, func, user_data, error);
}
Be careful :task Not allowed no lock While using , Otherwise, an error will be reported :
task without a lock can't be set to state 0
adopt gst_task_set_lock Function prototypes can be seen , here task Needed lock yes GRecMutex type .
The following code is curlhttpsrc Code for , You can have a preliminary understanding :
subprojects/gst-plugins-bad/ext/curl/gstcurlhttpsrc.c
/* init RecMutex */
g_rec_mutex_init (&klass->multi_task_context.task_rec_mutex);
klass->multi_task_context.state = GSTCURL_MULTI_LOOP_STATE_RUNNING;
/* new task */
klass->multi_task_context.task = gst_task_new (
(GstTaskFunction) gst_curl_http_src_curl_multi_loop,
(gpointer) & klass->multi_task_context, NULL);
/* set lock */
gst_task_set_lock (klass->multi_task_context.task,
&klass->multi_task_context.task_rec_mutex);
/* start task */
if (gst_task_start (klass->multi_task_context.task) == FALSE) {
GSTCURL_ERROR_PRINT ("Couldn't start curl_multi task! Aborting.");
abort ();
}
GMutex
GMutex Structure is an opaque data structure , Represents a mutex (mutex), It can be used to protect data from shared access .
GRecMutex
GRecMutex Structure is an opaque data structure , Represents a recursive mutual exclusion . It is similar to GMutex, The difference is , It can be locked multiple times in the same thread GRecMutex Without causing deadlock . In doing so , You must pay attention to unlocking the recursive mutex when it is locked .
边栏推荐
- 函数的概念及语法
- 建议收藏,我的腾讯Android面试经历分享
- PG基础篇--逻辑结构管理(用户及权限管理)
- 如何在2022年更明智地应用智能合约?
- How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
- IFD-x 微型红外成像仪(模块)关于温度测量和成像精度的关系
- Xaas trap: all things serve (possible) is not what it really needs
- Get wechat avatar and nickname with uniapp
- Information / data
- 测试的核心价值到底是什么?
猜你喜欢

【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法

Summer Challenge database Xueba notes, quick review of exams / interviews~

Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL

Android面试,android音视频开发

众昂矿业:2022年全球萤石行业市场供给现状分析

2022 the latest big company Android interview real problem analysis, Android development will be able to technology

Android interview, Android audio and video development

acm入门day1

How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI

aggregate
随机推荐
IFD-x 微型红外成像仪(模块)关于温度测量和成像精度的关系
Information / data
手机开户选择哪家券商公司比较好哪家平台更安全
Force buckle 729 My schedule I
从零实现深度学习框架——LSTM从理论到实战【实战】
C application interface development foundation - form control (6) - menu bar, toolbar and status bar controls
【obs】QString的UTF-8中文转换到blog打印 UTF-8 char*
力扣 1200. 最小绝对差
Common - Hero Minesweeper
HiEngine:可媲美本地的云原生内存数据库引擎
JMeter 常用的几种断言方法,你会了吗?
安卓面试宝典,2022Android面试笔试总结
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
Shell编程基础(第8篇:分支语句-case in)
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
PHP uses ueditor to upload pictures and add watermarks
The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
【硬核干货】数据分析哪家强?选Pandas还是选SQL
打新债在哪里操作开户是更安全可靠的呢
使用easyexcel模板导出的两个坑(Map空数据列错乱和不支持嵌套对象)