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

Function fbdev_read_packet

libavdevice/fbdev_dec.c:152–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152static int fbdev_read_packet(AVFormatContext *avctx, AVPacket *pkt)
153{
154 FBDevContext *fbdev = avctx->priv_data;
155 int64_t curtime, delay;
156 struct timespec ts;
157 int i, ret;
158 uint8_t *pin, *pout;
159
160 if (fbdev->time_frame == AV_NOPTS_VALUE)
161 fbdev->time_frame = av_gettime_relative();
162
163 /* wait based on the frame rate */
164 while (1) {
165 curtime = av_gettime_relative();
166 delay = fbdev->time_frame - curtime;
167 av_log(avctx, AV_LOG_TRACE,
168 "time_frame:%"PRId64" curtime:%"PRId64" delay:%"PRId64"\n",
169 fbdev->time_frame, curtime, delay);
170 if (delay <= 0) {
171 fbdev->time_frame += INT64_C(1000000) / av_q2d(fbdev->framerate_q);
172 break;
173 }
174 if (avctx->flags & AVFMT_FLAG_NONBLOCK)
175 return AVERROR(EAGAIN);
176 ts.tv_sec = delay / 1000000;
177 ts.tv_nsec = (delay % 1000000) * 1000;
178 while (nanosleep(&ts, &ts) < 0 && errno == EINTR);
179 }
180
181 if ((ret = av_new_packet(pkt, fbdev->frame_size)) < 0)
182 return ret;
183
184 /* refresh fbdev->varinfo, visible data position may change at each call */
185 if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) {
186 av_log(avctx, AV_LOG_WARNING,
187 "Error refreshing variable info: %s\n", av_err2str(AVERROR(errno)));
188 }
189
190 pkt->pts = av_gettime();
191
192 /* compute visible data offset */
193 pin = fbdev->data + fbdev->bytes_per_pixel * fbdev->varinfo.xoffset +
194 fbdev->varinfo.yoffset * fbdev->fixinfo.line_length;
195 pout = pkt->data;
196
197 for (i = 0; i < fbdev->height; i++) {
198 memcpy(pout, pin, fbdev->frame_linesize);
199 pin += fbdev->fixinfo.line_length;
200 pout += fbdev->frame_linesize;
201 }
202
203 return fbdev->frame_size;
204}
205
206static av_cold int fbdev_read_close(AVFormatContext *avctx)
207{

Callers

nothing calls this directly

Calls 5

av_gettime_relativeFunction · 0.85
av_logFunction · 0.85
av_q2dFunction · 0.85
av_new_packetFunction · 0.85
av_gettimeFunction · 0.85

Tested by

no test coverage detected