History

avfilter/vf_blackdetect: use the name 's' for the pointer to the private context

This is consistent across filters and also is less typing.

Paul B Mahol committed 5 years ago

Commit 0bcba121 parent d8b2fae1 file · +32 −33Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_blackdetect.c+32−33
@@ -89,48 +89,47 @@ static int query_formats(AVFilterContext *ctx) · 88 unmodified lines
8989 static int config_input(AVFilterLink *inlink)
9090 {
9191 AVFilterContext *ctx = inlink->dst;
92− BlackDetectContext *blackdetect = ctx->priv;
92+ BlackDetectContext *s = ctx->priv;
9393
94− blackdetect->black_min_duration =
95− blackdetect->black_min_duration_time / av_q2d(inlink->time_base);
94+ s->black_min_duration = s->black_min_duration_time / av_q2d(inlink->time_base);
9695
97− blackdetect->pixel_black_th_i = ff_fmt_is_in(inlink->format, yuvj_formats) ?
96+ s->pixel_black_th_i = ff_fmt_is_in(inlink->format, yuvj_formats) ?
9897 // luminance_minimum_value + pixel_black_th * luminance_range_size
99− blackdetect->pixel_black_th * 255 :
100− 16 + blackdetect->pixel_black_th * (235 - 16);
98+ s->pixel_black_th * 255 :
99+ 16 + s->pixel_black_th * (235 - 16);
101100
102− av_log(blackdetect, AV_LOG_VERBOSE,
101+ av_log(s, AV_LOG_VERBOSE,
103102 "black_min_duration:%s pixel_black_th:%f pixel_black_th_i:%d picture_black_ratio_th:%f\n",
104− av_ts2timestr(blackdetect->black_min_duration, &inlink->time_base),
105− blackdetect->pixel_black_th, blackdetect->pixel_black_th_i,
106− blackdetect->picture_black_ratio_th);
103+ av_ts2timestr(s->black_min_duration, &inlink->time_base),
104+ s->pixel_black_th, s->pixel_black_th_i,
105+ s->picture_black_ratio_th);
107106 return 0;
108107 }
109108
110109 static void check_black_end(AVFilterContext *ctx)
111110 {
112− BlackDetectContext *blackdetect = ctx->priv;
111+ BlackDetectContext *s = ctx->priv;
113112 AVFilterLink *inlink = ctx->inputs[0];
114113
115− if ((blackdetect->black_end - blackdetect->black_start) >= blackdetect->black_min_duration) {
116− av_log(blackdetect, AV_LOG_INFO,
114+ if ((s->black_end - s->black_start) >= s->black_min_duration) {
115+ av_log(s, AV_LOG_INFO,
117116 "black_start:%s black_end:%s black_duration:%s\n",
118− av_ts2timestr(blackdetect->black_start, &inlink->time_base),
119− av_ts2timestr(blackdetect->black_end, &inlink->time_base),
120− av_ts2timestr(blackdetect->black_end - blackdetect->black_start, &inlink->time_base));
117+ av_ts2timestr(s->black_start, &inlink->time_base),
118+ av_ts2timestr(s->black_end, &inlink->time_base),
119+ av_ts2timestr(s->black_end - s->black_start, &inlink->time_base));
121120 }
122121 }
123122
124123 static int request_frame(AVFilterLink *outlink)
125124 {
126125 AVFilterContext *ctx = outlink->src;
127− BlackDetectContext *blackdetect = ctx->priv;
126+ BlackDetectContext *s = ctx->priv;
128127 AVFilterLink *inlink = ctx->inputs[0];
129128 int ret = ff_request_frame(inlink);
130129
131− if (ret == AVERROR_EOF && blackdetect->black_started) {
130+ if (ret == AVERROR_EOF && s->black_started) {
132131 // FIXME: black_end should be set to last_picref_pts + last_picref_duration
133− blackdetect->black_end = blackdetect->last_picref_pts;
132+ s->black_end = s->last_picref_pts;
134133 check_black_end(ctx);
135134 }
136135 return ret;
@@ -139,18 +138,18 @@ static int request_frame(AVFilterLink *outlink) · 2 unmodified lines
139138 static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
140139 {
141140 AVFilterContext *ctx = inlink->dst;
142− BlackDetectContext *blackdetect = ctx->priv;
141+ BlackDetectContext *s = ctx->priv;
143142 double picture_black_ratio = 0;
144143 const uint8_t *p = picref->data[0];
145144 int x, i;
146145
147146 for (i = 0; i < inlink->h; i++) {
148147 for (x = 0; x < inlink->w; x++)
149− blackdetect->nb_black_pixels += p[x] <= blackdetect->pixel_black_th_i;
148+ s->nb_black_pixels += p[x] <= s->pixel_black_th_i;
150149 p += picref->linesize[0];
151150 }
152151
153− picture_black_ratio = (double)blackdetect->nb_black_pixels / (inlink->w * inlink->h);
152+ picture_black_ratio = (double)s->nb_black_pixels / (inlink->w * inlink->h);
154153
155154 av_log(ctx, AV_LOG_DEBUG,
156155 "frame:%"PRId64" picture_black_ratio:%f pts:%s t:%s type:%c\n",
@@ -158,25 +157,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) · 1 unmodified line
158157 av_ts2str(picref->pts), av_ts2timestr(picref->pts, &inlink->time_base),
159158 av_get_picture_type_char(picref->pict_type));
160159
161− if (picture_black_ratio >= blackdetect->picture_black_ratio_th) {
162− if (!blackdetect->black_started) {
160+ if (picture_black_ratio >= s->picture_black_ratio_th) {
161+ if (!s->black_started) {
163162 /* black starts here */
164− blackdetect->black_started = 1;
165− blackdetect->black_start = picref->pts;
163+ s->black_started = 1;
164+ s->black_start = picref->pts;
166165 av_dict_set(&picref->metadata, "lavfi.black_start",
167− av_ts2timestr(blackdetect->black_start, &inlink->time_base), 0);
166+ av_ts2timestr(s->black_start, &inlink->time_base), 0);
168167 }
169− } else if (blackdetect->black_started) {
168+ } else if (s->black_started) {
170169 /* black ends here */
171− blackdetect->black_started = 0;
172− blackdetect->black_end = picref->pts;
170+ s->black_started = 0;
171+ s->black_end = picref->pts;
173172 check_black_end(ctx);
174173 av_dict_set(&picref->metadata, "lavfi.black_end",
175− av_ts2timestr(blackdetect->black_end, &inlink->time_base), 0);
174+ av_ts2timestr(s->black_end, &inlink->time_base), 0);
176175 }
177176
178− blackdetect->last_picref_pts = picref->pts;
179− blackdetect->nb_black_pixels = 0;
177+ s->last_picref_pts = picref->pts;
178+ s->nb_black_pixels = 0;
180179 return ff_filter_frame(inlink->dst->outputs[0], picref);
181180 }
182181

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