57#include <CFHDEncoder.h>
67#include <condition_variable>
74#define DEFAULT_POOL_SIZE 16
75#define DEFAULT_THREAD_COUNT 8
76#define MOD_NAME "[cineform] "
103 std::condition_variable
cv;
106 std::map<uint32_t, struct timespec> times_map;
130 {
"Quality",
"quality",
"specifies encode quality, range 1-6 (default: 4)",
":quality=",
"4"},
131 {
"Threads",
"num_threads",
"specifies number of threads for encoding (default: " TOSTRING(
DEFAULT_THREAD_COUNT)
")",
":num_threads=",
""},
132 {
"Pool size",
"pool_size",
"specifies the size of encoding pool (default: " TOSTRING(
DEFAULT_POOL_SIZE)
")",
":pool_size=",
""},
136 printf(
"Cineform encoder usage:\n");
137 printf(
"\t-c cineform[:quality=<quality>][:threads=<num_threads>][:pool_size=<pool_size>]\n");
140 printf(
"\t\t<%s> %s\n", opt.key, opt.description);
145 char *
item, *save_ptr = NULL;
147 while((
item = strtok_r(
fmt,
":", &save_ptr)) != NULL) {
148 if(strncasecmp(
"help",
item, strlen(
"help")) == 0) {
151 }
else if(strncasecmp(
"quality=",
item, strlen(
"quality=")) == 0) {
152 char *quality =
item + strlen(
"quality=");
153 int qual = atoi(quality);
154 if(qual >= 1 && qual <= 6){
160 }
else if(strncasecmp(
"threads=",
item, strlen(
"threads=")) == 0) {
161 char *threads =
item + strlen(
"threads=");
163 }
else if(strncasecmp(
"pool_size=",
item, strlen(
"pool_size=")) == 0) {
164 char *pool_size =
item + strlen(
"pool_size=");
189 char *
fmt = strdup(opts);
198 CFHD_Error
status = CFHD_ERROR_OKAY;
203 if(
status != CFHD_ERROR_OKAY){
209 if(
status != CFHD_ERROR_OKAY){
235 {
UYVY, CFHD_PIXEL_FORMAT_2VUY, CFHD_ENCODED_FORMAT_YUV_422},
236 {
RGB, CFHD_PIXEL_FORMAT_RG24, CFHD_ENCODED_FORMAT_RGB_444},
237 {
RGBA, CFHD_PIXEL_FORMAT_BGRa, CFHD_ENCODED_FORMAT_RGBA_4444},
238 {
v210, CFHD_PIXEL_FORMAT_V210, CFHD_ENCODED_FORMAT_YUV_422},
239 {
R10k, CFHD_PIXEL_FORMAT_DPX0, CFHD_ENCODED_FORMAT_RGB_444},
240 {
RG48, CFHD_PIXEL_FORMAT_RG48, CFHD_ENCODED_FORMAT_RGB_444},
245 CFHD_Error
status = CFHD_ERROR_OKAY;
249 if(
status != CFHD_ERROR_OKAY){
258 to_convs[i++] =
codec.ug_codec;
264 CFHD_PixelFormat pix_fmt = CFHD_PIXEL_FORMAT_UNKNOWN;
265 CFHD_EncodedFormat enc_fmt = CFHD_ENCODED_FORMAT_UNKNOWN;
268 pix_fmt =
codec.cfhd_pixel_format;
269 enc_fmt =
codec.cfhd_encoded_format;
274 if(pix_fmt == CFHD_PIXEL_FORMAT_UNKNOWN){
284 CFHD_ENCODING_FLAGS_NONE,
287 if(
status != CFHD_ERROR_OKAY){
299 if(
status != CFHD_ERROR_OKAY){
303 uint32_t fcc_tag =
to_fourcc(
'U',
'G',
'P',
'F');
311 if(
status != CFHD_ERROR_OKAY){
316 if(
status != CFHD_ERROR_OKAY){
322 if(
status != CFHD_ERROR_OKAY){
338 auto *dst = (
unsigned char *) ret->
tiles[0].
data;
341 dst +=
static_cast<size_t>(dst_linesize) *
346 s->
dec(dst + dst_sign * i * dst_linesize, (
unsigned char *)
frame->
tiles[0].
data + i * src_linesize, dst_linesize, 16, 8, 0);
356 CFHD_Error
status = CFHD_ERROR_OKAY;
357 std::unique_lock<std::mutex>
lock(s->
mutex);
380 if(
status != CFHD_ERROR_OKAY){
386 assert(
tx->tile_count == 1);
405 clock_gettime(CLOCK_MONOTONIC_RAW, &t_0);
417 if(
status != CFHD_ERROR_OKAY){
424static void timespec_diff(
struct timespec *
start,
struct timespec *stop,
425 struct timespec *result)
427 if ((stop->tv_nsec -
start->tv_nsec) < 0) {
428 result->tv_sec = stop->tv_sec -
start->tv_sec - 1;
429 result->tv_nsec = stop->tv_nsec -
start->tv_nsec + 1000000000;
431 result->tv_sec = stop->tv_sec -
start->tv_sec;
432 result->tv_nsec = stop->tv_nsec -
start->tv_nsec;
442 std::unique_lock<std::mutex>
lock(s->
mutex);
445 CFHD_SampleBufferRef buf;
447 while(CFHD_TestForSample(s->
encoderPoolRef, &frame_num, &buf) == CFHD_ERROR_OKAY){
459 CFHD_Error
status = CFHD_ERROR_OKAY;
461 CFHD_SampleBufferRef buf;
466 struct timespec t_0, t_1, t_res;
467 clock_gettime(CLOCK_MONOTONIC_RAW, &t_1);
468 t_0 = s->times_map[frame_num];
470 timespec_diff(&t_0, &t_1, &t_res);
472 printf(
"[cineform] Encoding %u frame took %f miliseconds.\n", frame_num, t_res.tv_nsec / 1000000.0);
474 if(
status != CFHD_ERROR_OKAY){
480 std::tuple<CFHD_EncoderPoolRef, CFHD_SampleBufferRef> *t =
483 CFHD_ReleaseSampleBuffer(std::get<0>(*t), std::get<1>(*t));
489 status = CFHD_GetEncodedSample(buf,
490 (
void **) &out->tiles[0].data,
492 out->tiles[0].data_len = encoded_len;
493 if(
status != CFHD_ERROR_OKAY){
497 out->callbacks.dispose_udata =
new std::tuple<CFHD_EncoderPoolRef, CFHD_SampleBufferRef>(s->
encoderPoolRef, buf);
498 out->seq = frame_num;
516 module_info.
name =
"cineform";
520 opt.description, opt.placeholder, opt.key, opt.opt_str,
false});
struct video_frame * frame
void vf_free(struct video_frame *buf)
Frees video_frame structure.
struct video_desc video_desc_from_frame(const struct video_frame *frame)
Returns struct video_desc from video frame.
int vc_get_linesize(unsigned int width, codec_t codec)
struct video_frame * vf_alloc_desc(struct video_desc desc)
Allocates video frame accordig given desc.
struct video_frame * vf_alloc_desc_data(struct video_desc desc)
const char * get_codec_name(codec_t codec)
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_NOTICE
information that may be interesting
#define LOG_LEVEL_INFO
normal reporting
#define LOG_LEVEL_ERROR
general errors
#define LOG_LEVEL_VERBOSE
void module_init_default(struct module *module_data)
void module_register(struct module *module_data, struct module *parent)
#define VIDEO_COMPRESS_ABI_VERSION
@ LIBRARY_CLASS_VIDEO_COMPRESS
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
#define to_fourcc(a, b, c, d)
Creates FourCC word.
decoder_t get_best_decoder_from(codec_t in, const codec_t *out_candidates, codec_t *out)
decoder_func_t * decoder_t
const char * name
displayed name
std::vector< codec > codecs
std::vector< module_option > opts
char * data
Raw tile data. Pointer must be at least 4B aligned.
unsigned int width
width of every tile (!)
unsigned int height
height of every tile (!)
Struct video_frame represents a video frame and contains video description.
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
struct video_frame_callbacks callbacks
static time_ns_t get_time_in_ns()
@ PROGRESSIVE
progressive frame
@ R10k
RGB 10-bit packed - RGBX, big-endian (2 bit padding)
@ RGB
RGB 8-bit (packed into 24-bit word)
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
@ VIDEO_CODEC_NONE
dummy color spec
@ RG48
16-bit RGB little-endian (RlRhGl...)
@ VIDEO_CODEC_COUNT
count of known video codecs (including VIDEO_CODEC_NONE)
@ RGBA
RGBA 8-bit, big-endian.
@ v210
YCbCr 422 10-bit - xVY0U|xY2UY1|xUY3V|xY5VY4, little-endian (2 bit padding /'x'/),...
This is an umbrella header for video functions.
static const struct codec_info_t codec_info[]
API for video compress drivers.
void vf_clear(struct video_frame *f)
bool video_desc_eq_excl_param(struct video_desc a, struct video_desc b, unsigned int excluded_params)
Compares two video descriptions.
void vf_copy_metadata(struct video_frame *dest, const struct video_frame *src)