linux视频之media媒体框架

时间:2024-09-15 09:34:02

  linux视频媒体(kernel层分析)主要包括三个文件:

  (/drivers/media/media-device.c ,  /drivers/media/media-devnode.c , /drivers/media/media-entity.c)

一.主要分析/drivers/media/media-device.c文件,此文件中主要的结构是:

  

/*dev->driver_data points to this struct*/
struct media_device { //媒体设备结构体
struct device *dev; //Parent device
struct media_devnode devnode; //媒体设备节点
char model[];//设备型号名称
char driver_name[]; //驱动的名称,如果没有设置,就返回dev->driver->name
char serial[];//设备序列号
char bus_info[];//设备位置标识符
u32 hw_revision;
u32 driver_version; //驱动版本
u32 topology_version; //拓扑版本
u32 id;//注册的图形对象上使用的唯一ID
struct ida entity_internal_idx;
int entity_internal_idx_max;
struct list_head entities; //List of registered entities
struct list_head interfaces; //List of registered interfaces
struct list_head pads; //List of registered pads
struct list_head links; //List of registered links
   /*entity注册成功的回调通知链表*/
struct list_head entity_notify; //notify callback list invoked when a new entity is registered
spinlock_t lock; //Protects the graph objects creation/removal
struct mutex graph_mutex; //Serializes graph operations.
struct media_entity_graph pm_count_walk; //Graph walk for power state walk.
void *source_priv;//Driver Private data for enable/disable source handlers
int (*enable_source)(struct media_entity *entity, struct media_pipeline *pipe);
void (*disable_source)(struct media_entity *entity);
  /**
  * Supported link_notify @notification values.
    #define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0
    #define MEDIA_DEV_NOTIFY_POST_LINK_CH 1
  */
  int (*link_notify)(struct media_link *link, u32 flags, unsigned int notification);//Link state change notification callback
};

/*此结构体对应于struct media_device结构体中的 struct list_head entity_notify链表*/
struct media_entity_notify {
struct list_head list;
void *notify_data; // Input data to invoke the callback
void (*notify)(struct media_entity *entity, void *notify_data); //Callback function pointer
};

主要API:

  void media_device_init(struct media_device *mdev);

  void media_device_cleanup(struct media_device *mdev);

  media_device_register(mdev); // __media_device_register(struct media_device *mdev, struct module *owner);

  void media_device_unregister(struct media_device *mdev);