Skip to content

Commit

Permalink
lavd video: check vid subs from sw_pix_fmt
Browse files Browse the repository at this point in the history
Check if video subsampling is 4:2:0 from sw_pix_fmt than iterating over
received pix_fmts. This is simplier and more effective since the SW
format is set the get_format() callback to the nominal SW format (if any).
  • Loading branch information
MartinPulec committed Oct 6, 2023
1 parent ac110f1 commit 15fe21d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
18 changes: 0 additions & 18 deletions src/libavcodec/lavc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,24 +288,6 @@ void print_decoder_error(const char *mod_name, int rc) {
}
}

bool pixfmt_has_420_subsampling(enum AVPixelFormat fmt){
const AVPixFmtDescriptor *fmt_desc = av_pix_fmt_desc_get(fmt);

return fmt_desc && (fmt_desc->log2_chroma_w == 1 && fmt_desc->log2_chroma_h == 1);
}

/// @retval true if all pixel formats have either 420 subsampling or are HW accelerated
bool pixfmt_list_has_420_subsampling(const enum AVPixelFormat *fmt){
for(const enum AVPixelFormat *it = fmt; *it != AV_PIX_FMT_NONE; it++){
const AVPixFmtDescriptor *fmt_desc = av_pix_fmt_desc_get(*it);
if (!pixfmt_has_420_subsampling(*it) && !(fmt_desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
return false;
}
}

return true;
}

const char *lavc_thread_type_to_str(int thread_type) {
static _Thread_local char buf[128];
memset(buf, 0, sizeof buf);
Expand Down
3 changes: 0 additions & 3 deletions src/libavcodec/lavc_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ extern "C" {
#endif

void print_decoder_error(const char *mod_name, int rc);
bool pixfmt_has_420_subsampling(enum AVPixelFormat fmt);
/// @retval true if all pixel formats have either 420 subsampling or are HW accelerated
bool pixfmt_list_has_420_subsampling(const enum AVPixelFormat *fmt);

void print_libav_error(int verbosity, const char *msg, int rc);
void printf_libav_error(int verbosity, int rc, const char *msg, ...) __attribute__((format (printf, 3, 4)));
Expand Down
2 changes: 1 addition & 1 deletion src/video_decompress/libavcodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ static enum AVPixelFormat get_format_callback(struct AVCodecContext *s, const en

if (hwaccel != NULL) {
struct state_libavcodec_decompress *state = (struct state_libavcodec_decompress *) s->opaque;
if (!pixfmt_list_has_420_subsampling(fmt)){
if (av_pixfmt_get_subsampling(s->sw_pix_fmt) != SUBS_420) {
log_msg(LOG_LEVEL_WARNING, "[lavd] Hw. acceleration requested "
"but incoming video has not 4:2:0 subsampling, "
"which is usually not supported by hw. accelerators\n");
Expand Down

0 comments on commit 15fe21d

Please sign in to comment.