Revamp API and start using doxygen
The API used to be designed in such a way to where it would expect exports for each individual source/output/encoder/etc. You would export functions for each and it would automatically load those functions based on a specific naming scheme from the module. The idea behind this was that I wanted to limit the usage of structures in the API so only functions could be used. It was an interesting idea in theory, but this idea turned out to be flawed in a number of ways: 1.) Requiring exports to create sources/outputs/encoders/etc meant that you could not create them by any other means, which meant that things like faruton's .net plugin would become difficult. 2.) Export function declarations could not be checked, therefore if you created a function with the wrong parameters and parameter types, the compiler wouldn't know how to check for that. 3.) Required overly complex load functions in libobs just to handle it. It makes much more sense to just have a load function that you call manually. Complexity is the bane of all good programs. 4.) It required that you have functions of specific names, which looked and felt somewhat unsightly. So, to fix these issues, I replaced it with a more commonly used API scheme, seen commonly in places like kernels and typical C libraries with abstraction. You simply create a structure that contains the callback definitions, and you pass it to a function to register that definition (such as obs_register_source), which you call in the obs_module_load of the module. It will also automatically check the structure size and ensure that it only loads the required values if the structure happened to add new values in an API change. The "main" source file for each module must include obs-module.h, and must use OBS_DECLARE_MODULE() within that source file. Also, started writing some doxygen documentation in to the main library headers. Will add more detailed documentation as I go.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
|
||||
Copyright (C) 2013-2014 by Hugh Bailey <obs.jim@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -17,125 +17,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "util/c99defs.h"
|
||||
#include "util/dstr.h"
|
||||
|
||||
/*
|
||||
* ===========================================
|
||||
* Encoders
|
||||
* ===========================================
|
||||
*
|
||||
* An encoder context allows data to be encoded from raw output, and allow
|
||||
* it to be used to output contexts (such as outputting to stream).
|
||||
*
|
||||
* A module with encoders needs to export these functions:
|
||||
* + enum_encoders
|
||||
*
|
||||
* Each individual encoder is then exported by it's name. For example, an
|
||||
* encoder named "myencoder" would have the following exports:
|
||||
* + myencoder_getname
|
||||
* + myencoder_create
|
||||
* + myencoder_destroy
|
||||
* + myencoder_update
|
||||
* + myencoder_reset
|
||||
* + myencoder_encode
|
||||
* + myencoder_getheader
|
||||
*
|
||||
* [and optionally]
|
||||
* + myencoder_properties
|
||||
* + myencoder_setbitrate
|
||||
* + myencoder_request_keyframe
|
||||
*
|
||||
* ===========================================
|
||||
* Primary Exports
|
||||
* ===========================================
|
||||
* const char *enum_encoders(size_t idx);
|
||||
* idx: index of the encoder.
|
||||
* Return value: Encoder identifier name. NULL when no more available.
|
||||
*
|
||||
* ===========================================
|
||||
* Encoder Exports
|
||||
* ===========================================
|
||||
* const char *[name]_getname(const char *locale);
|
||||
* Returns the full translated name of the encoder type
|
||||
* (seen by the user).
|
||||
*
|
||||
* ---------------------------------------------------------
|
||||
* void *[name]_create(obs_data_t settings, const char *name,
|
||||
* obs_encoder_t encoder);
|
||||
* Creates an encoder.
|
||||
*
|
||||
* settings: Settings of the encoder.
|
||||
* name: Name of the encoder.
|
||||
* encoder: Pointer to encoder context.
|
||||
* Return value: Internal encoder pointer, or NULL if failed.
|
||||
*
|
||||
* ---------------------------------------------------------
|
||||
* void [name]_destroy(void *data);
|
||||
* Destroys the encoder.
|
||||
*
|
||||
* ---------------------------------------------------------
|
||||
* void [name]_update(void *data, obs_data_t settings)
|
||||
* Updates the encoder's settings
|
||||
*
|
||||
* settings: New settings of the encoder
|
||||
*
|
||||
* ---------------------------------------------------------
|
||||
* bool [name]_reset(void *data)
|
||||
* Restarts encoder
|
||||
*
|
||||
* Return value: true if successful
|
||||
*
|
||||
* ---------------------------------------------------------
|
||||
* int [name]_encode(void *data, void *frames, size_t size,
|
||||
* struct encoder_packet **packets)
|
||||
* Encodes data.
|
||||
*
|
||||
* frames: frame data
|
||||
* size: size of data pointed to by the frame parameter
|
||||
* packets: returned packets, or NULL if none
|
||||
* Return value: number of encoder frames
|
||||
*
|
||||
* ---------------------------------------------------------
|
||||
* int [name]_getheader(void *data, struct encoder_packet **packets)
|
||||
* Returns the header packets for this encoder.
|
||||
*
|
||||
* packets: returned packets, or NULL if none
|
||||
* Return value: number of encoder frames
|
||||
*
|
||||
* ===========================================
|
||||
* Optional Encoder Exports
|
||||
* ===========================================
|
||||
* obs_properties_t [name]_properties(const char *locale);
|
||||
* Returns the properties of this particular encoder type, if any.
|
||||
*
|
||||
* ---------------------------------------------------------
|
||||
* bool [name]_setbitrate(void *data, uint32_t bitrate, uint32_t buffersize);
|
||||
* Sets the bitrate of the encoder
|
||||
*
|
||||
* bitrate: Bitrate
|
||||
* buffersize: Buffer size
|
||||
* Returns true if successful/compatible
|
||||
*
|
||||
* ---------------------------------------------------------
|
||||
* bool [name]_request_keyframe(void *data)
|
||||
* Requests a keyframe from the encoder
|
||||
*
|
||||
* Returns true if successful/compatible.
|
||||
*/
|
||||
|
||||
struct obs_encoder;
|
||||
|
||||
struct encoder_info {
|
||||
struct obs_encoder_info {
|
||||
const char *id;
|
||||
|
||||
const char *(*getname)(const char *locale);
|
||||
|
||||
void *(*create)(obs_data_t settings, struct obs_encoder *encoder);
|
||||
void *(*create)(obs_data_t settings, obs_encoder_t encoder);
|
||||
void (*destroy)(void *data);
|
||||
|
||||
void (*update)(void *data, obs_data_t settings);
|
||||
|
||||
bool (*reset)(void *data);
|
||||
|
||||
int (*encode)(void *data, void *frames, size_t size,
|
||||
@@ -143,26 +32,12 @@ struct encoder_info {
|
||||
int (*getheader)(void *data, struct encoder_packet **packets);
|
||||
|
||||
/* optional */
|
||||
void (*update)(void *data, obs_data_t settings);
|
||||
|
||||
obs_properties_t (*properties)(const char *locale);
|
||||
|
||||
bool (*setbitrate)(void *data, uint32_t bitrate, uint32_t buffersize);
|
||||
bool (*request_keyframe)(void *data);
|
||||
};
|
||||
|
||||
struct obs_encoder_callback {
|
||||
void (*new_packet)(void *param, struct encoder_packet *packet);
|
||||
void *param;
|
||||
};
|
||||
|
||||
struct obs_encoder {
|
||||
char *name;
|
||||
void *data;
|
||||
struct encoder_info callbacks;
|
||||
obs_data_t settings;
|
||||
|
||||
pthread_mutex_t data_callbacks_mutex;
|
||||
DARRAY(struct obs_encoder_callback) data_callbacks;
|
||||
};
|
||||
|
||||
extern bool load_encoder_info(void *module, const char *module_name,
|
||||
const char *encoder_name, struct encoder_info *info);
|
||||
EXPORT void obs_register_encoder(const struct obs_encoder_info *info);
|
||||
|
Reference in New Issue
Block a user