Lines Matching defs:avbuf

51 static inline AVRational v4l2_get_timebase(V4L2Buffer *avbuf)
53 V4L2m2mContext *s = buf_to_m2mctx(avbuf);
73 static inline int64_t v4l2_get_pts(V4L2Buffer *avbuf)
78 v4l2_pts = (int64_t)avbuf->buf.timestamp.tv_sec * USEC_PER_SEC +
79 avbuf->buf.timestamp.tv_usec;
81 return av_rescale_q(v4l2_pts, v4l2_timebase, v4l2_get_timebase(avbuf));
214 V4L2Buffer* avbuf = opaque;
215 V4L2m2mContext *s = buf_to_m2mctx(avbuf);
217 if (atomic_fetch_sub(&avbuf->context_refcount, 1) == 1) {
224 if (s->draining && V4L2_TYPE_IS_OUTPUT(avbuf->context->type)) {
226 avbuf->status = V4L2BUF_AVAILABLE;
228 else if (avbuf->context->streamon)
229 ff_v4l2_buffer_enqueue(avbuf);
232 av_buffer_unref(&avbuf->context_ref);
299 static int v4l2_buffer_buf_to_swframe(AVFrame *frame, V4L2Buffer *avbuf)
303 frame->format = avbuf->context->av_pix_fmt;
305 for (i = 0; i < avbuf->num_planes; i++) {
306 ret = v4l2_buf_to_bufref(avbuf, i, &frame->buf[i]);
310 frame->linesize[i] = avbuf->plane_info[i].bytesperline;
315 switch (avbuf->context->av_pix_fmt) {
318 if (avbuf->num_planes > 1)
320 frame->linesize[1] = avbuf->plane_info[0].bytesperline;
321 frame->data[1] = frame->buf[0]->data + avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height;
325 if (avbuf->num_planes > 1)
327 frame->linesize[1] = avbuf->plane_info[0].bytesperline >> 1;
328 frame->linesize[2] = avbuf->plane_info[0].bytesperline >> 1;
329 frame->data[1] = frame->buf[0]->data + avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height;
330 frame->data[2] = frame->data[1] + ((avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height) >> 2);
418 int ff_v4l2_buffer_buf_to_avframe(AVFrame *frame, V4L2Buffer *avbuf)
425 ret = v4l2_buffer_buf_to_swframe(frame, avbuf);
430 frame->key_frame = !!(avbuf->buf.flags & V4L2_BUF_FLAG_KEYFRAME);
431 frame->color_primaries = v4l2_get_color_primaries(avbuf);
432 frame->colorspace = v4l2_get_color_space(avbuf);
433 frame->color_range = v4l2_get_color_range(avbuf);
434 frame->color_trc = v4l2_get_color_trc(avbuf);
435 frame->pts = v4l2_get_pts(avbuf);
439 frame->height = avbuf->context->height;
440 frame->width = avbuf->context->width;
441 frame->sample_aspect_ratio = avbuf->context->sample_aspect_ratio;
444 if (avbuf->buf.flags & V4L2_BUF_FLAG_ERROR) {
445 av_log(logger(avbuf), AV_LOG_ERROR, "%s: driver decode error\n", avbuf->context->name);
452 int ff_v4l2_buffer_buf_to_avpkt(AVPacket *pkt, V4L2Buffer *avbuf)
457 ret = v4l2_buf_to_bufref(avbuf, 0, &pkt->buf);
461 pkt->size = V4L2_TYPE_IS_MULTIPLANAR(avbuf->buf.type) ? avbuf->buf.m.planes[0].bytesused : avbuf->buf.bytesused;
464 if (avbuf->buf.flags & V4L2_BUF_FLAG_KEYFRAME)
467 if (avbuf->buf.flags & V4L2_BUF_FLAG_ERROR) {
468 av_log(logger(avbuf), AV_LOG_ERROR, "%s driver encode error\n", avbuf->context->name);
472 pkt->dts = pkt->pts = v4l2_get_pts(avbuf);
493 int ff_v4l2_buffer_initialize(V4L2Buffer* avbuf, int index)
495 V4L2Context *ctx = avbuf->context;
498 avbuf->buf.memory = V4L2_MEMORY_MMAP;
499 avbuf->buf.type = ctx->type;
500 avbuf->buf.index = index;
503 avbuf->buf.length = VIDEO_MAX_PLANES;
504 avbuf->buf.m.planes = avbuf->planes;
507 ret = ioctl(buf_to_m2mctx(avbuf)->fd, VIDIOC_QUERYBUF, &avbuf->buf);
512 avbuf->num_planes = 0;
514 for (i = 0; i < avbuf->buf.length; i++) {
515 if (avbuf->buf.m.planes[i].length)
516 avbuf->num_planes++;
519 avbuf->num_planes = 1;
521 for (i = 0; i < avbuf->num_planes; i++) {
523 avbuf->plane_info[i].bytesperline = V4L2_TYPE_IS_MULTIPLANAR(ctx->type) ?
528 avbuf->plane_info[i].length = avbuf->buf.m.planes[i].length;
529 avbuf->plane_info[i].mm_addr = mmap(NULL, avbuf->buf.m.planes[i].length,
531 buf_to_m2mctx(avbuf)->fd, avbuf->buf.m.planes[i].m.mem_offset);
533 avbuf->plane_info[i].length = avbuf->buf.length;
534 avbuf->plane_info[i].mm_addr = mmap(NULL, avbuf->buf.length,
536 buf_to_m2mctx(avbuf)->fd, avbuf->buf.m.offset);
539 if (avbuf->plane_info[i].mm_addr == MAP_FAILED)
543 avbuf->status = V4L2BUF_AVAILABLE;
549 avbuf->buf.m.planes = avbuf->planes;
550 avbuf->buf.length = avbuf->num_planes;
553 avbuf->buf.bytesused = avbuf->planes[0].bytesused;
554 avbuf->buf.length = avbuf->planes[0].length;
557 return ff_v4l2_buffer_enqueue(avbuf);
560 int ff_v4l2_buffer_enqueue(V4L2Buffer* avbuf)
564 avbuf->buf.flags = avbuf->flags;
566 ret = ioctl(buf_to_m2mctx(avbuf)->fd, VIDIOC_QBUF, &avbuf->buf);
570 avbuf->status = V4L2BUF_IN_DRIVER;