UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
hwaccel_libav_common.c File Reference

This file contains functions related to hw acceleration. More...

#include "debug.h"
#include "hwaccel_libav_common.h"
#include "libavcodec/lavc_common.h"
#include "types.h"
#include "utils/color_out.h"
#include "utils/macros.h"
Include dependency graph for hwaccel_libav_common.c:

Go to the source code of this file.

Functions

enum hw_accel_type hw_accel_from_pixfmt (enum AVPixelFormat pixfmt)
 
enum hw_accel_type hw_accel_from_str (const char *str)
 
const char * hw_accel_to_str (enum hw_accel_type type)
 
codec_t hw_accel_to_ug_pixfmt (enum hw_accel_type type)
 
void hwaccel_state_init (struct hw_accel_state *hwaccel)
 Initializes hw_accel_state structure.
 
void hwaccel_state_reset (struct hw_accel_state *hwaccel)
 Uninitializes existing acceleration and resets hw_accel_state to initial state.
 

Variables

struct { 
 
   enum AVPixelFormat   av_pixfmt 
 
   const char *   name 
 
   enum hw_accel_type   type 
 
   codec_t   ug_pixfmt 
 
} accel_str_map [] 
 

Detailed Description

This file contains functions related to hw acceleration.

Author
Martin Piatka piatk.nosp@m.a@ce.nosp@m.snet..nosp@m.cz

Definition in file hwaccel_libav_common.c.

Function Documentation

◆ hw_accel_from_pixfmt()

enum hw_accel_type hw_accel_from_pixfmt ( enum AVPixelFormat pixfmt)

Definition at line 98 of file hwaccel_libav_common.c.

99{
100 for (unsigned i = 0; i < sizeof accel_str_map / sizeof accel_str_map[0];
101 i++) {
102 if (accel_str_map[i].av_pixfmt == pixfmt) {
103 return accel_str_map[i].type;
104 }
105 }
106
107 return HWACCEL_NONE;
108}
enum AVPixelFormat av_pixfmt
static const struct @20 accel_str_map[]
@ HWACCEL_NONE
Definition types.h:115

References accel_str_map, av_pixfmt, and HWACCEL_NONE.

Referenced by get_format_callback(), and libavcodec_decompress().

◆ hw_accel_from_str()

enum hw_accel_type hw_accel_from_str ( const char * str)

Definition at line 76 of file hwaccel_libav_common.c.

76 {
77 if (strcmp(str, "help") == 0) {
78 char msg[STR_LEN] = "Available decode accelerations:";
79 for (unsigned i = 0;
80 i < sizeof(accel_str_map) / sizeof(accel_str_map[0]);
81 i++) {
82 snprintf(msg + strlen(msg), sizeof msg - strlen(msg),
83 " " TBOLD("%s"), accel_str_map[i].name);
84 }
85 color_printf("%s\n", msg);
86 return HWACCEL_NONE;
87 }
88 for(unsigned i = 0; i < sizeof(accel_str_map) / sizeof(accel_str_map[0]); i++){
89 if(strcmp(str, accel_str_map[i].name) == 0){
90 return accel_str_map[i].type;
91 }
92 }
93
94 return HWACCEL_NONE;
95}
int color_printf(const char *format,...)
#define TBOLD(x)
Definition color_out.h:70
const char * name
@ STR_LEN
"standard" string length placeholder
Definition macros.h:134

References accel_str_map, color_printf(), HWACCEL_NONE, name, STR_LEN, and TBOLD.

Referenced by get_format_callback(), and validate_hwacc_param().

Here is the call graph for this function:

◆ hw_accel_to_str()

const char * hw_accel_to_str ( enum hw_accel_type type)

Definition at line 110 of file hwaccel_libav_common.c.

110 {
111 for(unsigned i = 0; i < sizeof(accel_str_map) / sizeof(accel_str_map[0]); i++){
112 if(type == accel_str_map[i].type){
113 return accel_str_map[i].name;
114 }
115 }
116
117 return "unknown";
118}
enum hw_accel_type type

References accel_str_map, and type.

◆ hw_accel_to_ug_pixfmt()

codec_t hw_accel_to_ug_pixfmt ( enum hw_accel_type type)

Definition at line 121 of file hwaccel_libav_common.c.

122{
123 for (unsigned i = 0;
124 i < sizeof(accel_str_map) / sizeof(accel_str_map[0]); i++) {
125 if (type == accel_str_map[i].type) {
126 return accel_str_map[i].ug_pixfmt;
127 }
128 }
129 return VIDEO_CODEC_NONE;
130}
@ VIDEO_CODEC_NONE
dummy color spec
Definition types.h:66

References accel_str_map, type, and VIDEO_CODEC_NONE.

Referenced by libavcodec_decompress_get_priority().

◆ hwaccel_state_init()

void hwaccel_state_init ( struct hw_accel_state * hwaccel)

Initializes hw_accel_state structure.

Definition at line 132 of file hwaccel_libav_common.c.

132 {
133 hwaccel->type = HWACCEL_NONE;
134 hwaccel->copy = false;
135 hwaccel->uninit = NULL;
136 hwaccel->tmp_frame = NULL;
137 hwaccel->uninit = NULL;
138 hwaccel->ctx = NULL;
139}
void(* uninit)(struct hw_accel_state *)
Optional uninit function ptr.
AVFrame * tmp_frame
Temporary frame used when copying.
void * ctx
Type depends on hwaccel type.
enum hw_accel_type type
bool copy
Specifies whether to use the copy mode.

References hw_accel_state::copy, hw_accel_state::ctx, HWACCEL_NONE, hw_accel_state::tmp_frame, hw_accel_state::type, and hw_accel_state::uninit.

Referenced by hwaccel_state_reset(), and libavcodec_decompress_init().

◆ hwaccel_state_reset()

void hwaccel_state_reset ( struct hw_accel_state * hwaccel)

Uninitializes existing acceleration and resets hw_accel_state to initial state.

Definition at line 141 of file hwaccel_libav_common.c.

141 {
142 if(hwaccel->ctx){
143 hwaccel->uninit(hwaccel);
144 }
145
146 if(hwaccel->tmp_frame){
147 av_frame_free(&hwaccel->tmp_frame);
148 }
149
150 hwaccel_state_init(hwaccel);
151}
void hwaccel_state_init(struct hw_accel_state *hwaccel)
Initializes hw_accel_state structure.

References hw_accel_state::ctx, hwaccel_state_init(), hw_accel_state::tmp_frame, and hw_accel_state::uninit.

Referenced by deconfigure(), and get_format_callback().

Here is the call graph for this function:

Variable Documentation

◆ [struct]

const struct { ... } accel_str_map[]
Initial value:
= {
{"vdpau", HWACCEL_VDPAU, AV_PIX_FMT_VDPAU, HW_VDPAU},
{ "vdpau-copy", HWACCEL_VDPAU, AV_PIX_FMT_VDPAU, HW_VDPAU},
{ "vaapi", HWACCEL_VAAPI, AV_PIX_FMT_VAAPI, 0 },
{ "videotoolbox", HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX, 0 },
{ "cuda", HWACCEL_CUDA, AV_PIX_FMT_CUDA, 0 },
{ "drm-prime", HWACCEL_DRM_PRIME, AV_PIX_FMT_DRM_PRIME, DRM_PRIME },
{ "vulkan", HWACCEL_VULKAN, AV_PIX_FMT_VULKAN, 0 },
}
#define AV_PIX_FMT_VULKAN
@ HWACCEL_VULKAN
Definition types.h:120
@ HWACCEL_VDPAU
Definition types.h:116
@ HWACCEL_CUDA
Definition types.h:119
@ HWACCEL_VAAPI
Definition types.h:117
@ HWACCEL_DRM_PRIME
Definition types.h:121
@ HWACCEL_VIDEOTOOLBOX
Definition types.h:118
@ HW_VDPAU
VDPAU hardware surface.
Definition types.h:91
@ DRM_PRIME
DRM Prime buffer, data contains struct drm_prime_frame.
Definition types.h:107

Referenced by hw_accel_from_pixfmt(), hw_accel_from_str(), hw_accel_to_str(), and hw_accel_to_ug_pixfmt().

◆ av_pixfmt

enum AVPixelFormat av_pixfmt

Definition at line 60 of file hwaccel_libav_common.c.

Referenced by filter(), get_av_to_ug_pixfmt(), and hw_accel_from_pixfmt().

◆ name

const char* name

Definition at line 58 of file hwaccel_libav_common.c.

Referenced by hw_accel_from_str().

◆ type

enum hw_accel_type type

Definition at line 59 of file hwaccel_libav_common.c.

Referenced by hw_accel_to_str(), and hw_accel_to_ug_pixfmt().

◆ ug_pixfmt

codec_t ug_pixfmt

Definition at line 61 of file hwaccel_libav_common.c.