yolobs-studio/libobs/obs-encoder.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

282 lines
8.4 KiB
C
Raw Permalink Normal View History

2016-02-23 23:16:51 +00:00
/******************************************************************************
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
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#pragma once
/**
* @file
* @brief header for modules implementing encoders.
*
* Encoders are modules that implement some codec that can be used by libobs
* to process output data.
*/
#ifdef __cplusplus
extern "C" {
#endif
2019-09-22 21:19:10 +00:00
#define OBS_ENCODER_CAP_DEPRECATED (1 << 0)
#define OBS_ENCODER_CAP_PASS_TEXTURE (1 << 1)
#define OBS_ENCODER_CAP_DYN_BITRATE (1 << 2)
2020-03-25 08:07:22 +00:00
#define OBS_ENCODER_CAP_INTERNAL (1 << 3)
2016-05-24 19:53:01 +00:00
2016-02-23 23:16:51 +00:00
/** Specifies the encoder type */
enum obs_encoder_type {
OBS_ENCODER_AUDIO, /**< The encoder provides an audio codec */
OBS_ENCODER_VIDEO /**< The encoder provides a video codec */
};
/** Encoder output packet */
struct encoder_packet {
2019-09-22 21:19:10 +00:00
uint8_t *data; /**< Packet data */
size_t size; /**< Packet size */
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
int64_t pts; /**< Presentation timestamp */
int64_t dts; /**< Decode timestamp */
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
int32_t timebase_num; /**< Timebase numerator */
int32_t timebase_den; /**< Timebase denominator */
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
enum obs_encoder_type type; /**< Encoder type */
2016-02-23 23:16:51 +00:00
2019-09-22 21:19:10 +00:00
bool keyframe; /**< Is a keyframe */
2016-02-23 23:16:51 +00:00
/* ---------------------------------------------------------------- */
/* Internal video variables (will be parsed automatically) */
/* DTS in microseconds */
2019-09-22 21:19:10 +00:00
int64_t dts_usec;
2016-02-23 23:16:51 +00:00
2016-08-28 12:07:43 +00:00
/* System DTS in microseconds */
2019-09-22 21:19:10 +00:00
int64_t sys_dts_usec;
2016-08-28 12:07:43 +00:00
2016-02-23 23:16:51 +00:00
/**
* Packet priority
*
* This is generally use by video encoders to specify the priority
* of the packet.
*/
2019-09-22 21:19:10 +00:00
int priority;
2016-02-23 23:16:51 +00:00
/**
* Dropped packet priority
*
* If this packet needs to be dropped, the next packet must be of this
* priority or higher to continue transmission.
*/
2019-09-22 21:19:10 +00:00
int drop_priority;
2016-02-23 23:16:51 +00:00
/** Audio track index (used with outputs) */
2019-09-22 21:19:10 +00:00
size_t track_idx;
2016-02-23 23:16:51 +00:00
/** Encoder from which the track originated from */
2019-09-22 21:19:10 +00:00
obs_encoder_t *encoder;
2016-02-23 23:16:51 +00:00
};
/** Encoder input frame */
struct encoder_frame {
/** Data for the frame/audio */
2019-09-22 21:19:10 +00:00
uint8_t *data[MAX_AV_PLANES];
2016-02-23 23:16:51 +00:00
/** size of each plane */
2019-09-22 21:19:10 +00:00
uint32_t linesize[MAX_AV_PLANES];
2016-02-23 23:16:51 +00:00
/** Number of frames (audio only) */
2019-09-22 21:19:10 +00:00
uint32_t frames;
2016-02-23 23:16:51 +00:00
/** Presentation timestamp */
2019-09-22 21:19:10 +00:00
int64_t pts;
2016-02-23 23:16:51 +00:00
};
/**
* Encoder interface
*
* Encoders have a limited usage with OBS. You are not generally supposed to
* implement every encoder out there. Generally, these are limited or specific
* encoders for h264/aac for streaming and recording. It doesn't have to be
* *just* h264 or aac of course, but generally those are the expected encoders.
*
* That being said, other encoders will be kept in mind for future use.
*/
struct obs_encoder_info {
/* ----------------------------------------------------------------- */
/* Required implementation*/
/** Specifies the named identifier of this encoder */
const char *id;
/** Specifies the encoder type (video or audio) */
enum obs_encoder_type type;
/** Specifies the codec */
const char *codec;
/**
* Gets the full translated name of this encoder
*
* @param type_data The type_data variable of this structure
* @return Translated name of the encoder
*/
const char *(*get_name)(void *type_data);
/**
* Creates the encoder with the specified settings
*
* @param settings Settings for the encoder
* @param encoder OBS encoder context
* @return Data associated with this encoder context, or
* NULL if initialization failed.
*/
void *(*create)(obs_data_t *settings, obs_encoder_t *encoder);
/**
* Destroys the encoder data
*
* @param data Data associated with this encoder context
*/
void (*destroy)(void *data);
/**
* Encodes frame(s), and outputs encoded packets as they become
* available.
*
* @param data Data associated with this encoder
* context
* @param[in] frame Raw audio/video data to encode
* @param[out] packet Encoder packet output, if any
* @param[out] received_packet Set to true if a packet was received,
* false otherwise
* @return true if successful, false otherwise.
*/
bool (*encode)(void *data, struct encoder_frame *frame,
2019-09-22 21:19:10 +00:00
struct encoder_packet *packet, bool *received_packet);
2016-02-23 23:16:51 +00:00
/** Audio encoder only: Returns the frame size for this encoder */
size_t (*get_frame_size)(void *data);
/* ----------------------------------------------------------------- */
/* Optional implementation */
/**
* Gets the default settings for this encoder
*
* @param[out] settings Data to assign default settings to
*/
void (*get_defaults)(obs_data_t *settings);
/**
* Gets the property information of this encoder
*
* @return The properties data
*/
obs_properties_t *(*get_properties)(void *data);
/**
* Updates the settings for this encoder (usually used for things like
2017-06-29 19:01:10 +00:00
* changing bitrate while active)
2016-02-23 23:16:51 +00:00
*
* @param data Data associated with this encoder context
* @param settings New settings for this encoder
* @return true if successful, false otherwise
*/
bool (*update)(void *data, obs_data_t *settings);
/**
* Returns extra data associated with this encoder (usually header)
*
* @param data Data associated with this encoder context
* @param[out] extra_data Pointer to receive the extra data
* @param[out] size Pointer to receive the size of the extra
* data
* @return true if extra data available, false
* otherwise
*/
bool (*get_extra_data)(void *data, uint8_t **extra_data, size_t *size);
/**
* Gets the SEI data, if any
*
* @param data Data associated with this encoder context
* @param[out] sei_data Pointer to receive the SEI data
* @param[out] size Pointer to receive the SEI data size
* @return true if SEI data available, false otherwise
*/
bool (*get_sei_data)(void *data, uint8_t **sei_data, size_t *size);
/**
* Returns desired audio format and sample information
*
* @param data Data associated with this encoder context
* @param[in/out] info Audio format information
*/
void (*get_audio_info)(void *data, struct audio_convert_info *info);
/**
* Returns desired video format information
*
* @param data Data associated with this encoder context
* @param[in/out] info Video format information
*/
void (*get_video_info)(void *data, struct video_scale_info *info);
void *type_data;
void (*free_type_data)(void *type_data);
2016-05-24 19:53:01 +00:00
uint32_t caps;
2019-07-27 12:47:10 +00:00
/**
* Gets the default settings for this encoder
2019-09-22 21:19:10 +00:00
*
* If get_defaults is also defined both will be called, and the first
* call will be to get_defaults, then to get_defaults2.
2019-07-27 12:47:10 +00:00
*
* @param[out] settings Data to assign default settings to
* @param[in] typedata Type Data
*/
void (*get_defaults2)(obs_data_t *settings, void *type_data);
/**
* Gets the property information of this encoder
*
* @param[in] data Pointer from create (or null)
* @param[in] typedata Type Data
* @return The properties data
*/
obs_properties_t *(*get_properties2)(void *data, void *type_data);
bool (*encode_texture)(void *data, uint32_t handle, int64_t pts,
2019-09-22 21:19:10 +00:00
uint64_t lock_key, uint64_t *next_key,
struct encoder_packet *packet,
bool *received_packet);
2016-02-23 23:16:51 +00:00
};
EXPORT void obs_register_encoder_s(const struct obs_encoder_info *info,
2019-09-22 21:19:10 +00:00
size_t size);
2016-02-23 23:16:51 +00:00
/**
* Register an encoder definition to the current obs context. This should be
* used in obs_module_load.
*
* @param info Pointer to the source definition structure.
*/
#define obs_register_encoder(info) \
obs_register_encoder_s(info, sizeof(struct obs_encoder_info))
#ifdef __cplusplus
}
#endif