mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-23 12:42:02 +00:00
FS-7500: refactor to use switch_core_video
added switch_core_codec_encode_video and switch_core_codec_decode video and add separate video implementations the switch_core_video code depends on libvpx, wraped into the switch_ namespace like switch_apr, need to figure out how to find the correct libvpx lib in autotools
This commit is contained in:
committed by
Anthony Minessale
parent
1ccd8dc447
commit
798a18a73d
@@ -143,6 +143,7 @@
|
||||
#include "switch_json.h"
|
||||
#include "switch_limit.h"
|
||||
#include "switch_core_media.h"
|
||||
#include "switch_core_video.h"
|
||||
#include <libteletone.h>
|
||||
|
||||
|
||||
|
||||
@@ -1621,6 +1621,33 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
|
||||
uint32_t encoded_rate,
|
||||
void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag);
|
||||
|
||||
/*!
|
||||
\brief Encode video data using a codec handle
|
||||
\param codec the codec handle to use
|
||||
\param img the img in I420 format
|
||||
\param encoded_data the buffer to write the encoded data to
|
||||
\param encoded_data_len the size of the encoded_data buffer
|
||||
\param flag flags to exchange
|
||||
\return SWITCH_STATUS_SUCCESS if the data was encoded
|
||||
\note encoded_data_len will be rewritten to the in-use size of encoded_data
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_codec_encode_video(switch_codec_t *codec,
|
||||
switch_image_t *img,
|
||||
void *encoded_data, uint32_t *encoded_data_len, unsigned int *flag);
|
||||
|
||||
/*!
|
||||
\brief Decode video data using a codec handle
|
||||
\param codec the codec handle to use
|
||||
\param frame the frame to be decoded
|
||||
\param img the new image in I420 format, allocated by the codec
|
||||
\param flag flags to exchange
|
||||
\return SWITCH_STATUS_SUCCESS if the data was decoded, and a non-NULL img
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_codec_decode_video(switch_codec_t *codec,
|
||||
switch_frame_t *frame,
|
||||
switch_image_t **img, unsigned int *flag);
|
||||
|
||||
|
||||
/*!
|
||||
\brief Destroy an initalized codec handle
|
||||
\param codec the codec handle to destroy
|
||||
|
||||
@@ -532,6 +532,45 @@ static inline void switch_core_codec_add_implementation(switch_memory_pool_t *po
|
||||
|
||||
///\}
|
||||
|
||||
static inline void switch_core_codec_add_video_implementation(switch_memory_pool_t *pool, switch_codec_interface_t *codec_interface,
|
||||
/*! the IANA code number */
|
||||
switch_payload_t ianacode,
|
||||
/*! the IANA code name */
|
||||
const char *iananame,
|
||||
/*! default fmtp to send (can be overridden by the init function) */
|
||||
char *fmtp,
|
||||
switch_core_codec_init_func_t init,
|
||||
/*! function to encode raw data into encoded data */
|
||||
switch_core_codec_video_encode_func_t encode,
|
||||
/*! function to decode encoded data into raw data */
|
||||
switch_core_codec_video_decode_func_t decode,
|
||||
/*! deinitalize a codec handle using this implementation */
|
||||
switch_core_codec_destroy_func_t destroy)
|
||||
{
|
||||
|
||||
switch_codec_implementation_t *impl = (switch_codec_implementation_t *) switch_core_alloc(pool, sizeof(*impl));
|
||||
memset(impl, 0, sizeof(*impl));
|
||||
impl->codec_type = SWITCH_CODEC_TYPE_VIDEO;
|
||||
impl->ianacode = ianacode;
|
||||
impl->iananame = switch_core_strdup(pool, iananame);
|
||||
impl->fmtp = switch_core_strdup(pool, fmtp);
|
||||
impl->samples_per_second = 90000;
|
||||
impl->actual_samples_per_second = 90000;
|
||||
impl->bits_per_second = 0;
|
||||
impl->microseconds_per_packet = 0;
|
||||
impl->samples_per_packet = 0;
|
||||
impl->number_of_channels = 1;
|
||||
impl->codec_frames_per_packet = 1;
|
||||
impl->init = init;
|
||||
impl->encode_video = encode;
|
||||
impl->decode_video = decode;
|
||||
impl->destroy = destroy;
|
||||
impl->codec_id = codec_interface->codec_id;
|
||||
impl->next = codec_interface->implementations;
|
||||
impl->impl_id = switch_core_codec_next_id();
|
||||
codec_interface->implementations = impl;
|
||||
}
|
||||
|
||||
#define SWITCH_DECLARE_STATIC_MODULE(init, load, run, shut) void init(void) { \
|
||||
switch_loadable_module_build_dynamic(__FILE__, load, run, shut, SWITCH_FALSE); \
|
||||
}
|
||||
|
||||
@@ -639,10 +639,6 @@ struct switch_codec {
|
||||
struct switch_codec *next;
|
||||
switch_core_session_t *session;
|
||||
switch_frame_t *cur_frame;
|
||||
/*! raw picture for encode */
|
||||
switch_picture_t enc_picture;
|
||||
/*! decoded picture */
|
||||
switch_picture_t dec_picture;
|
||||
};
|
||||
|
||||
/*! \brief A table of settings and callbacks that define a paticular implementation of a codec */
|
||||
@@ -679,6 +675,10 @@ struct switch_codec_implementation {
|
||||
switch_core_codec_encode_func_t encode;
|
||||
/*! function to decode encoded data into raw data */
|
||||
switch_core_codec_decode_func_t decode;
|
||||
/*! function to encode video raw data into encoded data */
|
||||
switch_core_codec_video_encode_func_t encode_video;
|
||||
/*! function to decode video encoded data into raw data */
|
||||
switch_core_codec_video_decode_func_t decode_video;
|
||||
/*! deinitalize a codec handle using this implementation */
|
||||
switch_core_codec_destroy_func_t destroy;
|
||||
uint32_t codec_id;
|
||||
|
||||
@@ -541,7 +541,6 @@ SWITCH_DECLARE_DATA extern switch_filenames SWITCH_GLOBAL_filenames;
|
||||
#define SWITCH_MAX_SAMPLE_LEN 48
|
||||
#define SWITCH_BYTES_PER_SAMPLE 2 /* slin is 2 bytes per sample */
|
||||
#define SWITCH_RECOMMENDED_BUFFER_SIZE 8192
|
||||
#define SWITCH_RECOMMENDED_VIDEO_BUFFER_SIZE 4096 * 1024 /* Fixme: Just Make sure it's big enough for now */
|
||||
#define SWITCH_MAX_CODECS 50
|
||||
#define SWITCH_MAX_STATE_HANDLERS 30
|
||||
#define SWITCH_CORE_QUEUE_LEN 100000
|
||||
@@ -2095,7 +2094,7 @@ typedef struct switch_caller_extension switch_caller_extension_t;
|
||||
typedef struct switch_caller_application switch_caller_application_t;
|
||||
typedef struct switch_state_handler_table switch_state_handler_table_t;
|
||||
typedef struct switch_timer switch_timer_t;
|
||||
typedef struct switch_picture switch_picture_t;
|
||||
typedef struct switch_image switch_image_t;
|
||||
typedef struct switch_codec switch_codec_t;
|
||||
typedef struct switch_core_thread_session switch_core_thread_session_t;
|
||||
typedef struct switch_codec_implementation switch_codec_implementation_t;
|
||||
@@ -2168,6 +2167,14 @@ typedef switch_status_t (*switch_core_codec_decode_func_t) (switch_codec_t *code
|
||||
uint32_t encoded_rate,
|
||||
void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag);
|
||||
|
||||
typedef switch_status_t (*switch_core_codec_video_encode_func_t) (switch_codec_t *codec,
|
||||
switch_image_t *img,
|
||||
void *encoded_data, uint32_t *encoded_data_len, unsigned int *flag);
|
||||
|
||||
typedef switch_status_t (*switch_core_codec_video_decode_func_t) (switch_codec_t *codec,
|
||||
switch_frame_t *frame,
|
||||
switch_image_t **img, unsigned int *flag);
|
||||
|
||||
typedef switch_status_t (*switch_core_codec_init_func_t) (switch_codec_t *, switch_codec_flag_t, const switch_codec_settings_t *codec_settings);
|
||||
typedef switch_status_t (*switch_core_codec_fmtp_parse_func_t) (const char *fmtp, switch_codec_fmtp_t *codec_fmtp);
|
||||
typedef switch_status_t (*switch_core_codec_destroy_func_t) (switch_codec_t *);
|
||||
|
||||
Reference in New Issue
Block a user