History

avfilter/vf_dnn_processing: refine code for better naming

Guo, Yejun committed 6 years ago

Commit ed9fc2e1 parent 54d09eb1 file · +45 −45Browse files

Unified · Split

libavfilter/vf_dnn_processing.c+45−45
@@ -136,40 +136,40 @@ static int config_input(AVFilterLink *inlink) · 135 unmodified lines
136 AVFilterContext *context = inlink->dst;136 AVFilterContext *context = inlink->dst;
137 DnnProcessingContext *ctx = context->priv;137 DnnProcessingContext *ctx = context->priv;
138 DNNReturnType result;138 DNNReturnType result;
139 DNNData dnn_data;139 DNNData model_input;
140 140
141 result = ctx->model->get_input(ctx->model->model, &dnn_data, ctx->model_inputname);141 result = ctx->model->get_input(ctx->model->model, &model_input, ctx->model_inputname);
142 if (result != DNN_SUCCESS) {142 if (result != DNN_SUCCESS) {
143 av_log(ctx, AV_LOG_ERROR, "could not get input from the model\n");143 av_log(ctx, AV_LOG_ERROR, "could not get input from the model\n");
144 return AVERROR(EIO);144 return AVERROR(EIO);
145 }145 }
146 146
147 // the design is to add explicit scale filter before this filter147 // the design is to add explicit scale filter before this filter
148 if (dnn_data.height != -1 && dnn_data.height != inlink->h) {148 if (model_input.height != -1 && model_input.height != inlink->h) {
149 av_log(ctx, AV_LOG_ERROR, "the model requires frame height %d but got %d\n",149 av_log(ctx, AV_LOG_ERROR, "the model requires frame height %d but got %d\n",
150 dnn_data.height, inlink->h);150 model_input.height, inlink->h);
151 return AVERROR(EIO);151 return AVERROR(EIO);
152 }152 }
153 if (dnn_data.width != -1 && dnn_data.width != inlink->w) {153 if (model_input.width != -1 && model_input.width != inlink->w) {
154 av_log(ctx, AV_LOG_ERROR, "the model requires frame width %d but got %d\n",154 av_log(ctx, AV_LOG_ERROR, "the model requires frame width %d but got %d\n",
155 dnn_data.width, inlink->w);155 model_input.width, inlink->w);
156 return AVERROR(EIO);156 return AVERROR(EIO);
157 }157 }
158 158
159 if (dnn_data.channels != 3) {159 if (model_input.channels != 3) {
160 av_log(ctx, AV_LOG_ERROR, "the model requires input channels %d\n",160 av_log(ctx, AV_LOG_ERROR, "the model requires input channels %d\n",
161 dnn_data.channels);161 model_input.channels);
162 return AVERROR(EIO);162 return AVERROR(EIO);
163 }163 }
164 if (dnn_data.dt != DNN_FLOAT && dnn_data.dt != DNN_UINT8) {164 if (model_input.dt != DNN_FLOAT && model_input.dt != DNN_UINT8) {
165 av_log(ctx, AV_LOG_ERROR, "only support dnn models with input data type as float32 and uint8.\n");165 av_log(ctx, AV_LOG_ERROR, "only support dnn models with input data type as float32 and uint8.\n");
166 return AVERROR(EIO);166 return AVERROR(EIO);
167 }167 }
168 168
169 ctx->input.width = inlink->w;169 ctx->input.width = inlink->w;
170 ctx->input.height = inlink->h;170 ctx->input.height = inlink->h;
171 ctx->input.channels = dnn_data.channels;171 ctx->input.channels = model_input.channels;
172 ctx->input.dt = dnn_data.dt;172 ctx->input.dt = model_input.dt;
173 173
174 result = (ctx->model->set_input_output)(ctx->model->model,174 result = (ctx->model->set_input_output)(ctx->model->model,
175 &ctx->input, ctx->model_inputname,175 &ctx->input, ctx->model_inputname,
@@ -201,28 +201,28 @@ static int config_output(AVFilterLink *outlink) · 25 unmodified lines
201 return 0;201 return 0;
202}202}
203 203
204static int copy_from_frame_to_dnn(DNNData *dnn_data, const AVFrame *in)204static int copy_from_frame_to_dnn(DNNData *dnn_input, const AVFrame *frame)
205{205{
206 // extend this function to support more formats206 // extend this function to support more formats
207 av_assert0(in->format == AV_PIX_FMT_RGB24 || in->format == AV_PIX_FMT_BGR24);207 av_assert0(frame->format == AV_PIX_FMT_RGB24 || frame->format == AV_PIX_FMT_BGR24);
208 208
209 if (dnn_data->dt == DNN_FLOAT) {209 if (dnn_input->dt == DNN_FLOAT) {
210 float *dnn_input = dnn_data->data;210 float *dnn_input_data = dnn_input->data;
211 for (int i = 0; i < in->height; i++) {211 for (int i = 0; i < frame->height; i++) {
212 for(int j = 0; j < in->width * 3; j++) {212 for(int j = 0; j < frame->width * 3; j++) {
213 int k = i * in->linesize[0] + j;213 int k = i * frame->linesize[0] + j;
214 int t = i * in->width * 3 + j;214 int t = i * frame->width * 3 + j;
215 dnn_input[t] = in->data[0][k] / 255.0f;215 dnn_input_data[t] = frame->data[0][k] / 255.0f;
216 }216 }
217 }217 }
218 } else {218 } else {
219 uint8_t *dnn_input = dnn_data->data;219 uint8_t *dnn_input_data = dnn_input->data;
220 av_assert0(dnn_data->dt == DNN_UINT8);220 av_assert0(dnn_input->dt == DNN_UINT8);
221 for (int i = 0; i < in->height; i++) {221 for (int i = 0; i < frame->height; i++) {
222 for(int j = 0; j < in->width * 3; j++) {222 for(int j = 0; j < frame->width * 3; j++) {
223 int k = i * in->linesize[0] + j;223 int k = i * frame->linesize[0] + j;
224 int t = i * in->width * 3 + j;224 int t = i * frame->width * 3 + j;
225 dnn_input[t] = in->data[0][k];225 dnn_input_data[t] = frame->data[0][k];
226 }226 }
227 }227 }
228 }228 }
@@ -230,28 +230,28 @@ static int copy_from_frame_to_dnn(DNNData *dnn_data, const AVFrame *in) · 1 unmodified line
230 return 0;230 return 0;
231}231}
232 232
233static int copy_from_dnn_to_frame(AVFrame *out, const DNNData *dnn_data)233static int copy_from_dnn_to_frame(AVFrame *frame, const DNNData *dnn_output)
234{234{
235 // extend this function to support more formats235 // extend this function to support more formats
236 av_assert0(out->format == AV_PIX_FMT_RGB24 || out->format == AV_PIX_FMT_BGR24);236 av_assert0(frame->format == AV_PIX_FMT_RGB24 || frame->format == AV_PIX_FMT_BGR24);
237 237
238 if (dnn_data->dt == DNN_FLOAT) {238 if (dnn_output->dt == DNN_FLOAT) {
239 float *dnn_output = dnn_data->data;239 float *dnn_output_data = dnn_output->data;
240 for (int i = 0; i < out->height; i++) {240 for (int i = 0; i < frame->height; i++) {
241 for(int j = 0; j < out->width * 3; j++) {241 for(int j = 0; j < frame->width * 3; j++) {
242 int k = i * out->linesize[0] + j;242 int k = i * frame->linesize[0] + j;
243 int t = i * out->width * 3 + j;243 int t = i * frame->width * 3 + j;
244 out->data[0][k] = av_clip_uintp2((int)(dnn_output[t] * 255.0f), 8);244 frame->data[0][k] = av_clip_uintp2((int)(dnn_output_data[t] * 255.0f), 8);
245 }245 }
246 }246 }
247 } else {247 } else {
248 uint8_t *dnn_output = dnn_data->data;248 uint8_t *dnn_output_data = dnn_output->data;
249 av_assert0(dnn_data->dt == DNN_UINT8);249 av_assert0(dnn_output->dt == DNN_UINT8);
250 for (int i = 0; i < out->height; i++) {250 for (int i = 0; i < frame->height; i++) {
251 for(int j = 0; j < out->width * 3; j++) {251 for(int j = 0; j < frame->width * 3; j++) {
252 int k = i * out->linesize[0] + j;252 int k = i * frame->linesize[0] + j;
253 int t = i * out->width * 3 + j;253 int t = i * frame->width * 3 + j;
254 out->data[0][k] = dnn_output[t];254 frame->data[0][k] = dnn_output_data[t];
255 }255 }
256 }256 }
257 }257 }

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