UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
video_decompress.cpp File Reference
#include <stdio.h>
#include <string.h>
#include <string>
#include "debug.h"
#include "video_codec.h"
#include "video_decompress.h"
#include "lib_common.h"
Include dependency graph for video_decompress.cpp:

Go to the source code of this file.

Classes

struct  state_decompress
 

Macros

#define DECOMPRESS_MAGIC   0xdff34f21u
 

Functions

 ADD_TO_PARAM ("decompress", "* decompress=<name>[:<codec>]\n" " Forces specified decompress module (will fail if not able to decompress\n" " the received compression). Optionally also force codec to decode to." " See 'uv --list-modules' to see available decompress modules.\n")
 
void decompress_done (struct state_decompress *s)
 
decompress_status decompress_frame (struct state_decompress *s, unsigned char *dst, unsigned char *compressed, unsigned int compressed_len, int frame_seq, struct video_frame_callbacks *callbacks, struct pixfmt_desc *internal_prop)
 Decompresses video frame.
 
int decompress_get_property (struct state_decompress *s, int property, void *val, size_t *len)
 
static struct state_decompress * decompress_init (const video_decompress_info *vdi)
 
bool decompress_init_multi (codec_t compression, struct pixfmt_desc internal_prop, codec_t out_codec, struct state_decompress **out, int count)
 Initializes (multiple) decompress states.
 
int decompress_reconfigure (struct state_decompress *s, struct video_desc desc, int rshift, int gshift, int bshift, int pitch, codec_t out_codec)
 
static int find_best_decompress (codec_t compression, struct pixfmt_desc internal_prop, codec_t out_pixfmt, int prio_min, int prio_max, const struct video_decompress_info **vdi, string &name)
 
static bool try_initialize_decompress (const video_decompress_info *vdi, struct state_decompress **decompress_state, int substreams)
 

Detailed Description

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file video_decompress.cpp.

Macro Definition Documentation

◆ DECOMPRESS_MAGIC

#define DECOMPRESS_MAGIC   0xdff34f21u

Function Documentation

◆ ADD_TO_PARAM()

ADD_TO_PARAM ( "decompress" )

◆ decompress_init()

static struct state_decompress * decompress_init ( const video_decompress_info * vdi)
static

Initializes decompressor

Return values
NULLif initialization failed
not-NULLstate of new decompressor

Definition at line 127 of file video_decompress.cpp.

128{
129 struct state_decompress *s;
130
131 s = (struct state_decompress *) calloc(1, sizeof(struct state_decompress));
133 s->functions = vdi;
134 s->state = s->functions->init();
135 if (s->state == NULL) {
136 free(s);
137 return NULL;
138 }
139 return s;
140}
const struct video_decompress_info * functions
pointer to selected decoder functions
void * state
decoder driver state
uint32_t magic
selected decoder magic
decompress_init_t init
#define DECOMPRESS_MAGIC

References DECOMPRESS_MAGIC, state_decompress::functions, video_decompress_info::init, state_decompress::magic, and state_decompress::state.

Referenced by try_initialize_decompress().

◆ find_best_decompress()

static int find_best_decompress ( codec_t compression,
struct pixfmt_desc internal_prop,
codec_t out_pixfmt,
int prio_min,
int prio_max,
const struct video_decompress_info ** vdi,
string & name )
static
Parameters
[in]compressioninput compression
[in]out_pixfmtoutput pixel format
[in]prio_minminimal priority that can be probed
[in]prio_maxmaximal priority that can be probed
[out]magicif decompressor was found here is stored its magic
Return values
-1if no found
prioritybest decoder's priority

Definition at line 78 of file video_decompress.cpp.

79 {
81
82 int best_priority = prio_max + 1;
83 string force_module;
84
85 if (commandline_params.find("decompress") != commandline_params.end()) {
86 char *tmp = strdup(commandline_params.at("decompress").c_str());
87 if (strchr(tmp, ':')) {
88 // if out_pixfmt specified and doesn't match, return
89 if (out_pixfmt != get_codec_from_name(strchr(tmp, ':') + 1)) {
90 free(tmp);
91 return -1;
92 }
93 *strchr(tmp, ':') = '\0';
94 }
95 force_module = tmp;
96 free(tmp);
97 }
98
99 for (const auto & d : decomps) {
100 // if user has explicitly requested decoder, skip all others
101 if (!force_module.empty() && d.first != force_module) {
102 continue;
103 }
104 // first pass - find the one with best priority (least)
105 int priority = static_cast<const video_decompress_info *>(d.second)->get_decompress_priority(compression, internal_prop, out_pixfmt);
106 if (priority < 0) { // decoder not valid for given properties combination
107 continue;
108 }
109 if (priority <= prio_max && priority >= prio_min && priority < best_priority) {
110 best_priority = priority;
111 *vdi = static_cast<const video_decompress_info *>(d.second);
112 name = d.first;
113 }
114 }
115
116 if(best_priority == prio_max + 1)
117 return -1;
118 return best_priority;
119}
codec_t get_codec_from_name(const char *name)
std::unordered_map< std::string, std::string > commandline_params
Definition host.cpp:184
map< string, const void * > get_libraries_for_class(enum library_class cls, int abi_version, bool include_hidden)
@ LIBRARY_CLASS_VIDEO_DECOMPRESS
Definition lib_common.h:81
const char * name
Definition settings.cpp:193
#define VIDEO_DECOMPRESS_ABI_VERSION

References commandline_params, get_codec_from_name(), video_decompress_info::get_decompress_priority, get_libraries_for_class(), LIBRARY_CLASS_VIDEO_DECOMPRESS, name, and VIDEO_DECOMPRESS_ABI_VERSION.

Referenced by decompress_init_multi().

Here is the call graph for this function:

◆ try_initialize_decompress()

static bool try_initialize_decompress ( const video_decompress_info * vdi,
struct state_decompress ** decompress_state,
int substreams )
static

Attemps to initialize decompress of given magic

Parameters
[in]vdimetadata struct of requested decompressor
[out]decompress_statedecoder state
[in]substreamsnumber of decoders to be created
Returns
true if initialization succeeded

Definition at line 150 of file video_decompress.cpp.

152{
153 for(int i = 0; i < substreams; ++i) {
154 decompress_state[i] = decompress_init(vdi);
155
156 if (!decompress_state[i]) {
157 for(int j = 0; j < i; ++j) {
158 if (decompress_state[j] != nullptr) {
159 decompress_done(decompress_state[j]);
160 }
161 decompress_state[j] = nullptr;
162 }
163 return false;
164 }
165 }
166
167 return true;
168}
void decompress_done(struct state_decompress *s)
static struct state_decompress * decompress_init(const video_decompress_info *vdi)

References decompress_done(), and decompress_init().

Referenced by decompress_init_multi().

Here is the call graph for this function: