当前位置:网站首页>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 .
边栏推荐
- Fuzor 2020軟件安裝包下載及安裝教程
- 通过POI追加数据到excel中小案例
- What are the reliable domestic low code development platforms?
- Worthy of being a boss, byte Daniel spent eight months on another masterpiece
- 【obs】libobs-winrt :CreateDispatcherQueueController
- Fuzor 2020软件安装包下载及安装教程
- 浮动元素与父级、兄弟盒子的关系
- Apprentissage du projet MMO I: préchauffage
- Add data to excel small and medium-sized cases through poi
- HiEngine:可媲美本地的云原生内存数据库引擎
猜你喜欢
aggregate
UWB ultra wideband positioning technology, real-time centimeter level high-precision positioning application, ultra wideband transmission technology
No matter how busy you are, you can't forget safety
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
IFD-x 微型红外成像仪(模块)关于温度测量和成像精度的关系
Xaas trap: all things serve (possible) is not what it really needs
How to realize the Online timer and offline timer in the game
HiEngine:可媲美本地的云原生内存数据库引擎
太牛了,看这篇足矣了
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
随机推荐
Tutoriel de téléchargement et d'installation du progiciel fuzor 2020
毫米波雷达人体感应器,智能感知静止存在,人体存在检测应用
MySql中的longtext字段的返回问题及解决
Summer Challenge database Xueba notes, quick review of exams / interviews~
从零实现深度学习框架——LSTM从理论到实战【实战】
Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
信息/数据
How to realize the Online timer and offline timer in the game
Fuzor 2020軟件安裝包下載及安裝教程
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
【C语言】字符串函数及模拟实现strlen&&strcpy&&strcat&&strcmp
打新债在哪里操作开户是更安全可靠的呢
How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
Using repositoryprovider to simplify the value passing of parent-child components
2022 the latest big company Android interview real problem analysis, Android development will be able to technology
XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
The problem of returning the longtext field in MySQL and its solution
通过POI追加数据到excel中小案例
Fundamentals of shell programming (Part 8: branch statements -case in)