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
110 return 0;110 return 0;
111}111}
112 112
113static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref)113static int hw_device_setup_for_encode(Encoder *e, AVCodecContext *enc_ctx,
114 AVBufferRef *frames_ref)
114{115{
115 const AVCodecHWConfig *config;116 const AVCodecHWConfig *config;
116 HWDevice *dev = NULL;117 HWDevice *dev = NULL;
117 118
118 if (frames_ref &&119 if (frames_ref &&
119 ((AVHWFramesContext*)frames_ref->data)->format ==120 ((AVHWFramesContext*)frames_ref->data)->format ==
120 ost->enc_ctx->pix_fmt) {121 enc_ctx->pix_fmt) {
121 // Matching format, will try to use hw_frames_ctx.122 // Matching format, will try to use hw_frames_ctx.
122 } else {123 } else {
123 frames_ref = NULL;124 frames_ref = NULL;
124 }125 }
125 126
126 for (int i = 0;; i++) {127 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);
128 if (!config)129 if (!config)
129 break;130 break;
130 131
131 if (frames_ref &&132 if (frames_ref &&
132 config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX &&133 config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX &&
133 (config->pix_fmt == AV_PIX_FMT_NONE ||134 (config->pix_fmt == AV_PIX_FMT_NONE ||
134 config->pix_fmt == ost->enc_ctx->pix_fmt)) {135 config->pix_fmt == enc_ctx->pix_fmt)) {
135 av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using input "136 av_log(e, AV_LOG_VERBOSE, "Using input "
136 "frames context (format %s) with %s encoder.\n",137 "frames context (format %s) with %s encoder.\n",
137 av_get_pix_fmt_name(ost->enc_ctx->pix_fmt),138 av_get_pix_fmt_name(enc_ctx->pix_fmt),
138 ost->enc_ctx->codec->name);139 enc_ctx->codec->name);
139 ost->enc_ctx->hw_frames_ctx = av_buffer_ref(frames_ref);140 enc_ctx->hw_frames_ctx = av_buffer_ref(frames_ref);
140 if (!ost->enc_ctx->hw_frames_ctx)141 if (!enc_ctx->hw_frames_ctx)
141 return AVERROR(ENOMEM);142 return AVERROR(ENOMEM);
142 return 0;143 return 0;
143 }144 }
@@ -148,11 +149,11 @@ static int hw_device_setup_for_encode(OutputStream *ost, AVBufferRef *frames_ref · 4 unmodified lines
148 }149 }
149 150
150 if (dev) {151 if (dev) {
151 av_log(ost->enc_ctx, AV_LOG_VERBOSE, "Using device %s "152 av_log(e, AV_LOG_VERBOSE, "Using device %s "
152 "(type %s) with %s encoder.\n", dev->name,153 "(type %s) with %s encoder.\n", dev->name,
153 av_hwdevice_get_type_name(dev->type), ost->enc_ctx->codec->name);154 av_hwdevice_get_type_name(dev->type), enc_ctx->codec->name);
154 ost->enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);155 enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);
155 if (!ost->enc_ctx->hw_device_ctx)156 if (!enc_ctx->hw_device_ctx)
156 return AVERROR(ENOMEM);157 return AVERROR(ENOMEM);
157 } else {158 } else {
158 // No device required, or no device available.159 // No device required, or no device available.
@@ -335,7 +336,7 @@ int enc_open(void *opaque, const AVFrame *frame) · 176 unmodified lines
335 336
336 enc_ctx->flags |= AV_CODEC_FLAG_FRAME_DURATION;337 enc_ctx->flags |= AV_CODEC_FLAG_FRAME_DURATION;
337 338
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);
339 if (ret < 0) {340 if (ret < 0) {
340 av_log(e, AV_LOG_ERROR,341 av_log(e, AV_LOG_ERROR,
341 "Encoding hardware device setup failed: %s\n", av_err2str(ret));342 "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