網站首頁 編程語言 正文
今天在看代碼的時候看到一個巧妙的用法:
兩個結構體,一個是V4L2Context,另外一個是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;
...
}
如果我們知道其中capture或者output的地址能不能推出來V4L2m2mContext的地址呢,這樣就可以V4L2Context少一個指針變量了。
答案是可以的:
#define container_of(ptr, type, member) ({ \
const __typeof__(((type *)0)->member ) *__mptr = (ptr); \
(type *)((char *)__mptr - offsetof(type,member) );})
關于其分析:分析
實際使用:
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);
}
原文鏈接:https://blog.csdn.net/weixin_43360707/article/details/125780922
相關推薦
- 2022-06-30 詳解Python如何實現尾遞歸優化_python
- 2022-05-22 在Centos?8.0中安裝Redis服務器的教程詳解_Redis
- 2022-09-01 C#實現簡單工廠模式_C#教程
- 2022-05-11 在 Markdown 中,如何在反引號對語句中使用反引號
- 2022-02-17 Chrome瀏覽器/Jupyter lab下載文件提示已經被禁止
- 2022-04-25 ASP.NET?Core?MVC中使用Tag?Helper組件_實用技巧
- 2023-07-08 如何讓element-ui的el-row內容居中(水平垂直)
- 2022-07-09 設置滾動條默認樣式 谷歌瀏覽器
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支