当前位置:网站首页>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 .
边栏推荐
- Force buckle 1200 Minimum absolute difference
- 【无标题】
- 40000 word Wenshuo operator new & operator delete
- What do software test engineers do? How about the prospect of treatment?
- 多分支结构
- The binary string mode is displayed after the value with the field type of longtext in MySQL is exported
- Fundamentals of machine learning (III) -- KNN / naive Bayes / cross validation / grid search
- vagrant2.2.6支持virtualbox6.1版本
- What does software testing do? What are the requirements for learning?
- Using repositoryprovider to simplify the value passing of parent-child components
猜你喜欢
Webuploader file upload drag upload progress monitoring type control upload result monitoring control
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
【硬核干货】数据分析哪家强?选Pandas还是选SQL
Common - Hero Minesweeper
Recommended collection, my Tencent Android interview experience sharing
What are the reliable domestic low code development platforms?
PHP利用ueditor实现上传图片添加水印
MMO project learning 1: preheating
强化学习-学习笔记4 | Actor-Critic
redis集群模拟消息队列
随机推荐
shell编程基础(第9篇:循环)
Django使用mysqlclient服务连接并写入数据库的操作过程
建议收藏,我的腾讯Android面试经历分享
The binary string mode is displayed after the value with the field type of longtext in MySQL is exported
Which securities company is better and which platform is safer for mobile account opening
id选择器和类选择器的区别
What are general items
软件测试是干什么的?学习有啥要求?
Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
手机股票开户安全吗?靠不靠谱啊?
What do software test engineers do? How about the prospect of treatment?
Mysql如何对json数据进行查询及修改
城链科技数字化创新战略峰会圆满召开
IFD-x 微型红外成像仪(模块)关于温度测量和成像精度的关系
[untitled]
Common - Hero Minesweeper
Fuzor 2020软件安装包下载及安装教程
Fuzor 2020軟件安裝包下載及安裝教程
Do you know several assertion methods commonly used by JMeter?
40000 word Wenshuo operator new & operator delete