History

fftools/ffmpeg_enc: stop using OutputStream in hw_device_setup_for_encode()

The only variable accessed from it is AVCodecContext, which we can pass directly. Also, this function currently logs into the AVCodecContext, which is wrong. Log to Encoder instead.

Anton Khirnov committed 2 years ago

Commit 1ebd5211 parent 70f7bbe1 file · +15 −14Browse files

Unified · Split

fftools/ffmpeg_enc.c+15−14
@@ -110,34 +110,35 @@ int enc_alloc(Encoder **penc, const AVCodec *codec, · 109 unmodified lines
110110 return 0;
111111 }
112112
113−static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref)
113+static int hw_device_setup_for_encode(Encoder *e, AVCodecContext *enc_ctx,
114+ AVBufferRef *frames_ref)
114115 {
115116 const AVCodecHWConfig *config;
116117 HWDevice *dev = NULL;
117118
118119 if (frames_ref &&
119120 ((AVHWFramesContext*)frames_ref->data)->format ==
120− ost->enc_ctx->pix_fmt) {
121+ enc_ctx->pix_fmt) {
121122 // Matching format, will try to use hw_frames_ctx.
122123 } else {
123124 frames_ref = NULL;
124125 }
125126
126127 for (int i = 0;; i++) {
127− config = avcodec_get_hw_config(ost->enc_ctx->codec, i);
128+ config = avcodec_get_hw_config(enc_ctx->codec, i);
128129 if (!config)
129130 break;
130131
131132 if (frames_ref &&
132133 config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX &&
133134 (config->pix_fmt == AV_PIX_FMT_NONE ||
134− config->pix_fmt == ost->enc_ctx->pix_fmt)) {
135− av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using input "
135+ config->pix_fmt == enc_ctx->pix_fmt)) {
136+ av_log(e, AV_LOG_VERBOSE, "Using input "
136137 "frames context (format %s) with %s encoder.\n",
137− av_get_pix_fmt_name(ost->enc_ctx->pix_fmt),
138− ost->enc_ctx->codec->name);
139− ost->enc_ctx->hw_frames_ctx = av_buffer_ref(frames_ref);
140− if (!ost->enc_ctx->hw_frames_ctx)
138+ av_get_pix_fmt_name(enc_ctx->pix_fmt),
139+ enc_ctx->codec->name);
140+ enc_ctx->hw_frames_ctx = av_buffer_ref(frames_ref);
141+ if (!enc_ctx->hw_frames_ctx)
141142 return AVERROR(ENOMEM);
142143 return 0;
143144 }
@@ -148,11 +149,11 @@ static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref · 4 unmodified lines
148149 }
149150
150151 if (dev) {
151− av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using device %s "
152+ av_log(e, AV_LOG_VERBOSE, "Using device %s "
152153 "(type %s) with %s encoder.\n", dev->name,
153− av_hwdevice_get_type_name(dev->type), ost->enc_ctx->codec->name);
154− ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);
155− if (!ost->enc_ctx->hw_device_ctx)
154+ av_hwdevice_get_type_name(dev->type), enc_ctx->codec->name);
155+ enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);
156+ if (!enc_ctx->hw_device_ctx)
156157 return AVERROR(ENOMEM);
157158 } else {
158159 // No device required, or no device available.
@@ -335,7 +336,7 @@ int enc_open(void *opaque, const AVFrame *frame) · 176 unmodified lines
335336
336337 enc_ctx->flags |= AV_CODEC_FLAG_FRAME_DURATION;
337338
338− ret = hw_device_setup_for_encode(ost, frame ? frame->hw_frames_ctx : NULL);
339+ ret = hw_device_setup_for_encode(e, enc_ctx, frame ? frame->hw_frames_ctx : NULL);
339340 if (ret < 0) {
340341 av_log(e, AV_LOG_ERROR,
341342 "Encoding hardware device setup failed: %s\n", av_err2str(ret));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t