用 ioctl MEDIA_IOC_G_TOPOLOGY 命令获取 /dev/mediaX 节点的拓扑结构,示例程序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <asm/types.h>
#include <linux/videodev2.h>
#include <sys/mman.h>
#include <errno.h>
#include <linux/media.h>

int main(int argc, char **argv)
{
int ret = 0, i;
int fd;
struct media_v2_topology *top;

top = calloc(1, sizeof(struct media_v2_topology));

fd = open("/dev/media0", O_RDWR);
if (fd < 0) {
    printf("open err = %d\n", fd);
    ret = fd;
    goto err;
}

ret = ioctl(fd, MEDIA_IOC_G_TOPOLOGY , top);
if (ret < 0) {
    printf("err = %d\n", ret);
    
    printf("%s\n", strerror(errno)); 
    goto err;
}

//printf("num_entities=%d\n", top->num_entities);

top->ptr_entities = (__u64)malloc(top->num_entities * sizeof(struct media_v2_entity));
top->ptr_interfaces = (__u64)malloc(top->num_interfaces * sizeof(struct media_v2_interface));
top->ptr_pads = (__u64)malloc(top->num_pads * sizeof(struct media_v2_pad));
top->ptr_links = (__u64)malloc(top->num_links * sizeof(struct media_v2_link));

ret = ioctl(fd, MEDIA_IOC_G_TOPOLOGY , top);
if (ret < 0) {
    printf("err = %d\n", ret);
    
    printf("%s\n", strerror(errno)); 
    goto err;
}

printf("\nentity\n");
for (i = 0; i < top->num_entities; i++) {
    printf("id %#x ", ((struct media_v2_entity*)top->ptr_entities + i)->id);
    printf("function %#x ", ((struct media_v2_entity*)top->ptr_entities + i)->function);
    printf("name %s \n", ((struct media_v2_entity*)top->ptr_entities + i)->name);
}

printf("\ninterface\n");
for (i = 0; i < top->num_interfaces; i++) {
    printf("id %#x ", ((struct media_v2_interface*)top->ptr_interfaces + i)->id);
    printf("intf_type %#x ", ((struct media_v2_interface*)top->ptr_interfaces + i)->intf_type);
    printf("major %d ", ((struct media_v2_interface*)top->ptr_interfaces + i)->devnode.major);
    printf("minor %d\n", ((struct media_v2_interface*)top->ptr_interfaces + i)->devnode.minor);

}

printf("\npad\n");
for (i = 0; i < top->num_pads; i++) {
    printf("id %#x ", ((struct media_v2_pad*)top->ptr_pads + i)->id);
    printf("entity_id %#x\n", ((struct media_v2_pad*)top->ptr_pads + i)->entity_id);
//    printf("index %d\n", ((struct media_v2_pad*)top->ptr_pads + i)->index);
}

printf("\nlink\n");
for (i = 0; i < top->num_links; i++) {
    printf("id %#x ", ((struct media_v2_link*)top->ptr_links + i)->id);
    printf("source_id %#x ", ((struct media_v2_link*)top->ptr_links + i)->source_id);
    printf("sink_id %#x\n", ((struct media_v2_link*)top->ptr_links + i)->sink_id);
}

err:
close(fd);

return ret;
}

结果


entity
id 0x1 function 0x10001 name stream_cif_dvp_id0 
id 0x5 function 0x10001 name stream_cif_dvp_id1 
id 0x9 function 0x10001 name stream_cif_dvp_id2 
id 0xd function 0x10001 name stream_cif_dvp_id3 
id 0x11 function 0x10001 name rkcif-mipi-luma 
id 0x14 function 0x20001 name m00_b_ar0230 4-0010 
id 0x16 function 0x20000 name rkcif-dvp-sof 

interface
id 0x3000002 intf_type 0x200 major 81 minor 0
id 0x3000006 intf_type 0x200 major 81 minor 1
id 0x300000a intf_type 0x200 major 81 minor 2
id 0x300000e intf_type 0x200 major 81 minor 3
id 0x3000012 intf_type 0x200 major 81 minor 4
id 0x3000017 intf_type 0x203 major 81 minor 5
id 0x3000019 intf_type 0x203 major 81 minor 6

pad
id 0x1000004 entity_id 0x1
id 0x1000008 entity_id 0x5
id 0x100000c entity_id 0x9
id 0x1000010 entity_id 0xd
id 0x1000015 entity_id 0x14

link
id 0x2000003 source_id 0x3000002 sink_id 0x1
id 0x2000007 source_id 0x3000006 sink_id 0x5
id 0x200000b source_id 0x300000a sink_id 0x9
id 0x200000f source_id 0x300000e sink_id 0xd
id 0x2000013 source_id 0x3000012 sink_id 0x11
id 0x2000018 source_id 0x3000017 sink_id 0x14
id 0x200001a source_id 0x3000019 sink_id 0x16
id 0x200001b source_id 0x1000015 sink_id 0x1000004

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值