MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / process_frame

Function process_frame

tools/scale_slice_test.c:51–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49} PrivData;
50
51static int process_frame(DecodeContext *dc, AVFrame *frame)
52{
53 PrivData *pd = dc->opaque;
54 int slice_start = 0;
55 int ret;
56
57 if (!frame)
58 return 0;
59
60 if (!pd->scaler) {
61 pd->scaler = sws_getContext(frame->width, frame->height, frame->format,
62 pd->frame_ref->width, pd->frame_ref->height,
63 pd->frame_ref->format, 0, NULL, NULL, NULL);
64 if (!pd->scaler)
65 return AVERROR(ENOMEM);
66
67 av_pix_fmt_get_chroma_sub_sample(frame->format, &pd->h_shift_src, &pd->v_shift_src);
68 }
69
70 /* scale the whole input frame as reference */
71 ret = sws_scale(pd->scaler, (const uint8_t **)frame->data, frame->linesize, 0, frame->height,
72 pd->frame_ref->data, pd->frame_ref->linesize);
73 if (ret < 0)
74 return ret;
75
76 /* scale slices with randomly generated heights */
77 while (slice_start < frame->height) {
78 int slice_height;
79 const uint8_t *src[4];
80
81 slice_height = av_lfg_get(&pd->lfg) % (frame->height - slice_start);
82 slice_height = FFALIGN(FFMAX(1, slice_height), 1 << pd->v_shift_src);
83
84 for (int j = 0; j < FF_ARRAY_ELEMS(src) && frame->data[j]; j++) {
85 int shift = (j == 1 || j == 2) ? pd->v_shift_src : 0;
86 src[j] = frame->data[j] + frame->linesize[j] * (slice_start >> shift);
87 }
88
89 ret = sws_scale(pd->scaler, src, frame->linesize, slice_start, slice_height,
90 pd->frame_dst->data, pd->frame_dst->linesize);
91 if (ret < 0)
92 return ret;
93
94 slice_start += slice_height;
95 }
96
97 /* compare the two results */
98 for (int i = 0; i < 4 && pd->frame_ref->data[i]; i++) {
99 int shift = (i == 1 || i == 2) ? pd->v_shift_dst : 0;
100
101 if (memcmp(pd->frame_ref->data[i], pd->frame_dst->data[i],
102 pd->frame_ref->linesize[i] * (pd->frame_ref->height >> shift))) {
103 fprintf(stderr, "mismatch frame %"PRId64" seed %u\n",
104 dc->decoder->frame_num - 1, pd->random_seed);
105 return AVERROR(EINVAL);
106 }
107 }
108

Callers

nothing calls this directly

Calls 4

sws_getContextFunction · 0.85
sws_scaleFunction · 0.85
av_lfg_getFunction · 0.85

Tested by

no test coverage detected