当前位置:网站首页>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 .
边栏推荐
- 多分支结构
- Necessary skills for interview in large factories, 2022android will not die, I will not fall
- Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法
- Successful entry into Baidu, 35K monthly salary, 2022 Android development interview answer
- Gstreamer中的task
- Fundamentals of shell programming (Part 8: branch statements -case in)
- Fuzor 2020軟件安裝包下載及安裝教程
- webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
- Get wechat avatar and nickname with uniapp
- C#应用程序界面开发基础——窗体控制(5)——分组类控件
猜你喜欢

微波雷达感应模块技术,实时智能检测人体存在,静止微小动静感知

XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西

third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
![[AI framework basic technology] automatic derivation mechanism (autograd)](/img/9c/a5713def131dc7643cc19b3839ff0c.png)
[AI framework basic technology] automatic derivation mechanism (autograd)

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

通过POI追加数据到excel中小案例

Debezium系列之:记录mariadb数据库删除多张临时表debezium解析到的消息以及解决方法

Bitcoinwin (BCW) was invited to attend Hanoi traders fair 2022

MMO project learning 1: preheating
![[FAQ] summary of common causes and solutions of Huawei account service error 907135701](/img/1d/0e716533237c0e4463f5d6357395bd.png)
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
随机推荐
【obs】libobs-winrt :CreateDispatcherQueueController
okcc呼叫中心有什么作用
C application interface development foundation - form control (6) - menu bar, toolbar and status bar controls
Information / data
Realizing deep learning framework from zero -- LSTM from theory to practice [practice]
What are the reliable domestic low code development platforms?
函数的概念及语法
Summer Challenge database Xueba notes, quick review of exams / interviews~
The problem of returning the longtext field in MySQL and its solution
PHP利用ueditor实现上传图片添加水印
UWB超宽带定位技术,实时厘米级高精度定位应用,超宽带传输技术
How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
gst-launch的-v参数
Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
Notion 类生产力工具如何选择?Notion 、FlowUs 、Wolai 对比评测
Common - Hero Minesweeper
太牛了,看这篇足矣了
Can Leica capture the high-end market offered by Huawei for Xiaomi 12s?
再忙不能忘安全