2018-09-14

Moudle 数据结构,在plugins目录下load

struct obs_module {
    char *mod_name;
    const char *file;
    char *bin_path;
    char *data_path;
    void *module;
    bool loaded;

    bool        (*load)(void);                                                /**< 初始化module,并注册组件obs_register_*** */
    void        (*unload)(void);
    void        (*post_load)(void);
    void        (*set_locale)(const char *locale);
    void        (*free_locale)(void);
    uint32_t    (*ver)(void);
    void        (*set_pointer)(obs_module_t *module);    
    const char *(*name)(void);
    const char *(*description)(void);
    const char *(*author)(void);

    struct obs_module *next;
};

View 数据结构

struct obs_view {
    pthread_mutex_t                 channels_mutex;
    obs_source_t                    *channels[MAX_CHANNELS];
};

Display 数据结构

struct obs_display {
    bool                            size_changed;
    bool                            enabled;
    uint32_t                        cx, cy;
    uint32_t                        background_color;
    gs_swapchain_t                  *swap;                      //一个display对应一个swpchain
    pthread_mutex_t                 draw_callbacks_mutex;
    pthread_mutex_t                 draw_info_mutex;
    DARRAY(struct draw_callback)    draw_callbacks;

    struct obs_display              *next;
    struct obs_display              **prev_next;
};

Core-video 核心视频数据结构

struct obs_vframe_info {
    uint64_t timestamp;
    int count;
};

struct obs_core_video {
    graphics_t                      *graphics;                                 //Subsystem d3d、opengl
    gs_stagesurf_t                  *copy_surfaces[NUM_TEXTURES];
    gs_texture_t                    *render_textures[NUM_TEXTURES];
    gs_texture_t                    *output_textures[NUM_TEXTURES];
    gs_texture_t                    *convert_textures[NUM_TEXTURES];
    bool                            textures_rendered[NUM_TEXTURES];
    bool                            textures_output[NUM_TEXTURES];
    bool                            textures_copied[NUM_TEXTURES];
    bool                            textures_converted[NUM_TEXTURES];
    struct circlebuf                vframe_info_buffer;
    gs_effect_t                     *default_effect;
    gs_effect_t                     *default_rect_effect;
    gs_effect_t                     *opaque_effect;
    gs_effect_t                     *solid_effect;
    gs_effect_t                     *conversion_effect;
    gs_effect_t                     *bicubic_effect;
    gs_effect_t                     *lanczos_effect;
    gs_effect_t                     *bilinear_lowres_effect;
    gs_effect_t                     *premultiplied_alpha_effect;
    gs_samplerstate_t               *point_sampler;
    gs_stagesurf_t                  *mapped_surface;
    int                             cur_texture;
    long                            raw_active;

    uint64_t                        video_time;
    uint64_t                        video_avg_frame_time_ns;
    double                          video_fps;
    video_t                         *video;                                    //VideoOutput
    pthread_t                       video_thread;
    uint32_t                        total_frames;
    uint32_t                        lagged_frames;
    bool                            thread_initialized;

    bool                            gpu_conversion;
    const char                      *conversion_tech;
    uint32_t                        conversion_height;
    uint32_t                        plane_offsets[3];
    uint32_t                        plane_sizes[3];
    uint32_t                        plane_linewidth[3];

    uint32_t                        output_width;
    uint32_t                        output_height;
    uint32_t                        base_width;
    uint32_t                        base_height;
    float                           color_matrix[16];
    enum obs_scale_type             scale_type;

    gs_texture_t                    *transparent_texture;

    gs_effect_t                     *deinterlace_discard_effect;
    gs_effect_t                     *deinterlace_discard_2x_effect;
    gs_effect_t                     *deinterlace_linear_effect;
    gs_effect_t                     *deinterlace_linear_2x_effect;
    gs_effect_t                     *deinterlace_blend_effect;
    gs_effect_t                     *deinterlace_blend_2x_effect;
    gs_effect_t                     *deinterlace_yadif_effect;
    gs_effect_t                     *deinterlace_yadif_2x_effect;

    struct obs_video_info           ovi;
};

Core-data 核心数据结构

struct obs_core_data {
    struct obs_source               *first_source;
    struct obs_source               *first_audio_source;
    struct obs_display              *first_display;
    struct obs_output               *first_output;
    struct obs_encoder              *first_encoder;
    struct obs_service              *first_service;

    pthread_mutex_t                 sources_mutex;
    pthread_mutex_t                 displays_mutex;
    pthread_mutex_t                 outputs_mutex;
    pthread_mutex_t                 encoders_mutex;
    pthread_mutex_t                 services_mutex;
    pthread_mutex_t                 audio_sources_mutex;
    pthread_mutex_t                 draw_callbacks_mutex;
    DARRAY(struct draw_callback)    draw_callbacks;
    DARRAY(struct tick_callback)    tick_callbacks;

    struct obs_view                 main_view;

    long long                       unnamed_index;

    volatile bool                   valid;
};

Core 内核

全局唯一

包含以上核心数据,video、audio、data、hotkeys

struct obs_core {
    struct obs_module               *first_module;
    DARRAY(struct obs_module_path)  module_paths;
/*--------------------------------------source info--------------------------------------------*/
 /**
按照source类型,分类存储每一个被注册的source的source_info
enum obs_source_type {
    OBS_SOURCE_TYPE_INPUT,
    OBS_SOURCE_TYPE_FILTER,
    OBS_SOURCE_TYPE_TRANSITION,
    OBS_SOURCE_TYPE_SCENE,
}; 
 */
    DARRAY(struct obs_source_info)  source_types;                         
    DARRAY(struct obs_source_info)  input_types;
    DARRAY(struct obs_source_info)  filter_types;
    DARRAY(struct obs_source_info)  transition_types;
    DARRAY(struct obs_output_info)  output_types;
/*--------------------------------------encoder info--------------------------------------------*/
/*
enum obs_encoder_type {
    OBS_ENCODER_AUDIO, 
    OBS_ENCODER_VIDEO  
};
*/
    DARRAY(struct obs_encoder_info) encoder_types;
    DARRAY(struct obs_service_info) service_types;
    DARRAY(struct obs_modal_ui)     modal_ui_callbacks;
    DARRAY(struct obs_modeless_ui)  modeless_ui_callbacks;

    signal_handler_t                *signals;
    proc_handler_t                  *procs;

    char                            *locale;
    char                            *module_config_path;
    bool                            name_store_owned;
    profiler_name_store_t           *name_store;

    /* segmented into multiple sub-structures to keep things a bit more
     * clean and organized */
    struct obs_core_video           video;
    struct obs_core_audio           audio;
    struct obs_core_data            data;
    struct obs_core_hotkeys         hotkeys;
};

Context 共享的上下文环境数据

struct obs_context_data {
    char                            *name;                                             /**< source 名称eg."Window Capture" *** */
    void                            *data;                                               /**< source.create,source 相关联的源对象 *** */
    obs_data_t                      *settings;                                    /**< 对souces的json配置文件里 settings属性的引用 *** */  
    signal_handler_t                *signals;                                  /** < singnal句柄,绑定source_signals回调函数 *** */
    proc_handler_t                  *procs;
    enum obs_obj_type               type;                                     /**< obj类型source、output、encoder
、service *** */  

    DARRAY(obs_hotkey_id)           hotkeys;
    DARRAY(obs_hotkey_pair_id)      hotkey_pairs;
    obs_data_t                      *hotkey_data;

    DARRAY(char*)                   rename_cache;
    pthread_mutex_t                 rename_cache_mutex;

    pthread_mutex_t                 *mutex;
    struct obs_context_data         *next;
    struct obs_context_data         **prev_next;

    bool                            private;                                             /**< 是否私有化,source为filter时是true *** */                                
};

Soucre 源数据结构

struct obs_source {
    struct obs_context_data         context;
    struct obs_source_info          info;
    struct obs_weak_source          *control;

    /* general exposed flags that can be set for the source */
    uint32_t                        flags;
    uint32_t                        default_flags;

    /* indicates ownership of the info.id buffer */
    bool                            owns_info_id;

    /* signals to call the source update in the video thread */
    bool                            defer_update;

    /* ensures show/hide are only called once */
    volatile long                   show_refs;

    /* ensures activate/deactivate are only called once */
    volatile long                   activate_refs;

    /* used to indicate that the source has been removed and all
     * references to it should be released (not exactly how I would prefer
     * to handle things but it's the best option) */
    bool                            removed;

    bool                            active;
    bool                            showing;

    /* used to temporarily disable sources if needed */
    bool                            enabled;

    /* timing (if video is present, is based upon video) */
    volatile bool                   timing_set;
    volatile uint64_t               timing_adjust;
    uint64_t                        resample_offset;
    uint64_t                        last_audio_ts;
    uint64_t                        next_audio_ts_min;
    uint64_t                        next_audio_sys_ts_min;
    uint64_t                        last_frame_ts;
    uint64_t                        last_sys_timestamp;
    bool                            async_rendered;

    /* audio */
    bool                            audio_failed;
    bool                            audio_pending;
    bool                            pending_stop;
    bool                            user_muted;
    bool                            muted;
    struct obs_source               *next_audio_source;
    struct obs_source               **prev_next_audio_source;
    uint64_t                        audio_ts;
    struct circlebuf                audio_input_buf[MAX_AUDIO_CHANNELS];
    size_t                          last_audio_input_buf_size;
    DARRAY(struct audio_action)     audio_actions;
    float                           *audio_output_buf[MAX_AUDIO_MIXES][MAX_AUDIO_CHANNELS];
    struct resample_info            sample_info;
    audio_resampler_t               *resampler;
    pthread_mutex_t                 audio_actions_mutex;
    pthread_mutex_t                 audio_buf_mutex;
    pthread_mutex_t                 audio_mutex;
    pthread_mutex_t                 audio_cb_mutex;
    DARRAY(struct audio_cb_info)    audio_cb_list;
    struct obs_audio_data           audio_data;
    size_t                          audio_storage_size;
    uint32_t                        audio_mixers;
    float                           user_volume;
    float                           volume;
    int64_t                         sync_offset;
    int64_t                         last_sync_offset;

    /* async video data */
    gs_texture_t                    *async_texture;
    gs_texrender_t                  *async_texrender;
    struct obs_source_frame         *cur_async_frame;
    bool                            async_gpu_conversion;
    enum video_format               async_format;
    enum video_format               async_cache_format;
    enum gs_color_format            async_texture_format;
    float                           async_color_matrix[16];
    bool                            async_full_range;
    float                           async_color_range_min[3];
    float                           async_color_range_max[3];
    int                             async_plane_offset[2];
    bool                            async_flip;
    bool                            async_active;
    bool                            async_update_texture;
    bool                            async_unbuffered;
    bool                            async_decoupled;
    struct obs_source_frame         *async_preload_frame;
    DARRAY(struct async_frame)      async_cache;
    DARRAY(struct obs_source_frame*)async_frames;
    pthread_mutex_t                 async_mutex;
    uint32_t                        async_width;
    uint32_t                        async_height;
    uint32_t                        async_cache_width;
    uint32_t                        async_cache_height;
    uint32_t                        async_convert_width;
    uint32_t                        async_convert_height;

    /* async video deinterlacing */
    uint64_t                        deinterlace_offset;
    uint64_t                        deinterlace_frame_ts;
    gs_effect_t                     *deinterlace_effect;
    struct obs_source_frame         *prev_async_frame;
    gs_texture_t                    *async_prev_texture;
    gs_texrender_t                  *async_prev_texrender;
    uint32_t                        deinterlace_half_duration;
    enum obs_deinterlace_mode       deinterlace_mode;
    bool                            deinterlace_top_first;
    bool                            deinterlace_rendered;

    /* filters */
    struct obs_source               *filter_parent;
    struct obs_source               *filter_target;
    DARRAY(struct obs_source*)      filters;
    pthread_mutex_t                 filter_mutex;
    gs_texrender_t                  *filter_texrender;
    enum obs_allow_direct_render    allow_direct;
    bool                            rendering_filter;

    /* sources specific hotkeys */
    obs_hotkey_pair_id              mute_unmute_key;
    obs_hotkey_id                   push_to_mute_key;
    obs_hotkey_id                   push_to_talk_key;
    bool                            push_to_mute_enabled;
    bool                            push_to_mute_pressed;
    bool                            user_push_to_mute_pressed;
    bool                            push_to_talk_enabled;
    bool                            push_to_talk_pressed;
    bool                            user_push_to_talk_pressed;
    uint64_t                        push_to_mute_delay;
    uint64_t                        push_to_mute_stop_time;
    uint64_t                        push_to_talk_delay;
    uint64_t                        push_to_talk_stop_time;

    /* transitions */
    uint64_t                        transition_start_time;
    uint64_t                        transition_duration;
    pthread_mutex_t                 transition_tex_mutex;
    gs_texrender_t                  *transition_texrender[2];
    pthread_mutex_t                 transition_mutex;
    obs_source_t                    *transition_sources[2];
    bool                            transitioning_video;
    bool                            transitioning_audio;
    bool                            transition_source_active[2];
    uint32_t                        transition_alignment;
    uint32_t                        transition_actual_cx;
    uint32_t                        transition_actual_cy;
    uint32_t                        transition_cx;
    uint32_t                        transition_cy;
    uint32_t                        transition_fixed_duration;
    bool                            transition_use_fixed_duration;
    enum obs_transition_mode        transition_mode;
    enum obs_transition_scale_type  transition_scale_type;
    struct matrix4                  transition_matrices[2];

    struct audio_monitor            *monitor;
    enum obs_monitoring_type        monitoring_type;

    obs_data_t                      *private_settings;
};

VideoInof 视频配置信息 首次从配置文件中获取

struct obs_video_info {
#ifndef SWIG
    /**
     * Graphics module to use (usually "libobs-opengl" or "libobs-d3d11")
     */
    const char          *graphics_module;
#endif

    uint32_t            fps_num;       /**< Output FPS numerator */
    uint32_t            fps_den;       /**< Output FPS denominator */

    uint32_t            base_width;    /**< Base compositing width */
    uint32_t            base_height;   /**< Base compositing height */

    uint32_t            output_width;  /**< Output width */
    uint32_t            output_height; /**< Output height */
    enum video_format   output_format; /**< Output format */

    /** Video adapter index to use (NOTE: avoid for optimus laptops) */
    uint32_t            adapter;

    /** Use shaders to convert to different color formats */
    bool                gpu_conversion;

    enum video_colorspace colorspace;  /**< YUV type (if YUV) */
    enum video_range_type range;       /**< YUV range (if YUV) */

    enum obs_scale_type scale_type;    /**< How to scale if scaling */
};

VideoOutPut 数据结构

struct video_output {
    struct video_output_info   info;

    pthread_t                  thread;
    pthread_mutex_t            data_mutex;
    bool                       stop;

    os_sem_t                   *update_semaphore;
    uint64_t                   frame_time;              //每一帧的时间,纳秒级别,例如fps=30则为33333333
    uint32_t                   skipped_frames;
    uint32_t                   total_frames;

    bool                       initialized;

    pthread_mutex_t            input_mutex;
    DARRAY(struct video_input) inputs;

    size_t                     available_frames;
    size_t                     first_added;
    size_t                     last_added;
    struct cached_frame_info   cache[MAX_CACHE_SIZE];
};
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,992评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,212评论 3 388
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,535评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,197评论 1 287
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,310评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,383评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,409评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,191评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,621评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,910评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,084评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,763评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,403评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,083评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,318评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,946评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,967评论 2 351

推荐阅读更多精彩内容