当前位置:网站首页>Structure gets the address of the main structure (struct) through member variables
Structure gets the address of the main structure (struct) through member variables
2022-07-19 04:12:00 【Taylor lance】
I saw a clever usage when looking at the code today :
Two structures , One is V4L2Context, The other is V4L2m2mContext;
typedef struct V4L2m2mContext {
char devname[PATH_MAX];
int fd;
/* the codec context queues */
V4L2Context capture;
V4L2Context output;
/* dynamic stream reconfig */
AVCodecContext *avctx;
sem_t refsync;
atomic_uint refcount;
int reinit;
...
}
If we know one capture perhaps output Can you push out the address of V4L2m2mContext What's the address? , In this way, we can V4L2Context One pointer variable is missing .
The answer is yes :
#define container_of(ptr, type, member) ({
\ const __typeof__(((type *)0)->member ) *__mptr = (ptr); \ (type *)((char *)__mptr - offsetof(type,member) );})
About its analysis : analysis
The actual use :
static inline V4L2m2mContext *buf_to_m2mctx(V4L2Buffer *buf)
{
return V4L2_TYPE_IS_OUTPUT(buf->context->type) ?
container_of(buf->context, V4L2m2mContext, output) :
container_of(buf->context, V4L2m2mContext, capture);
}
边栏推荐
- Chapter 5 performance platform godeye source code analysis - third party module
- 寻找数组的中心下标
- Chapter 4 performance platform godeye source code analysis - monitoring module
- 06 MAUI,WPF使用 MVVM Toolkit 框架 构建 MVVM 程序
- 小程序毕设作品之微信电子书阅读小程序毕业设计(3)后台功能
- [MySQL] install and configure MySQL on the ECS and connect with idea
- 图形验证码验证
- How to filter viruses / spam more effectively!
- 【数据库】期末必知必会-----第八章 数据库安全
- 通过Dao投票STI的销毁,SeekTiger真正做到由社区驱动
猜你喜欢

小程序毕设作品之微信在线教育视频点播学习小程序毕业设计(3)后台功能

Chapter 4 performance platform godeye source code analysis - monitoring module

How to use Google Earth client and KML Download

让程序员早点下班的《技术写作指南》

小程序毕设作品之微信电子书阅读小程序毕业设计(1)开发概要

Wechat online education video on demand learning applet graduation project (4) opening report

图形验证码验证

Common functions of JMeter - parametric introduction

priority_queue的介绍及其使用

Which computer painting software works well: try artweaver plus, which is comparable to Sai painting software | download the latest version of artweaver
随机推荐
Chapter 5 performance platform godeye source code analysis - third party module
Codeforces Round #807 (Div. 2) A~D
Unity - 如何修改一个 Package 或是如何将 Package Local化
PAC Decade: witness HPC from CPU era to XPU Era
C# 字符串(string)常用方法
leetcode7-dfs+动态规划+双指针
机器学习09:无监督学习
EAS(能量感知调度)绿色节能调度器
通过Dao投票STI的销毁,SeekTiger真正做到由社区驱动
高性能与经济性兼备:傲腾 持久内存助力移动云应对严苛内存挑战
Chapter 0 performance platform godeye source code analysis - Course Introduction
寻找数组的中心下标
Cocos creator 3.0 Basics - common operations
MAUI 框架入门学习05 MVVM数据模型理解
GNN series GCN brief derivation and understanding and DGL source code analysis
Wechat official account page authorization 40029 error "suggested collection"
Asp. Using grpc in NETCORE
Some problems after xcode11 new project
[database] must know and be able at the end of the term ----- Chapter 1 database overview
Skillfully use enterprise network disk to collect reports or summaries