Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Linux/drivers/media/usb/uvc/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 24.10.2025 mit Größe 10 kB image not shown  

Quelle  uvc_queue.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 *      uvc_queue.c  --  USB Video Class driver - Buffers management
 *
 *      Copyright (C) 2005-2010
 *          Laurent Pinchart (laurent.pinchart@ideasonboard.com)
 */


#include <linux/atomic.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/usb.h>
#include <linux/videodev2.h>
#include <linux/vmalloc.h>
#include <linux/wait.h>
#include <media/videobuf2-v4l2.h>
#include <media/videobuf2-vmalloc.h>

#include "uvcvideo.h"

/* ------------------------------------------------------------------------
 * Video buffers queue management.
 *
 * Video queues is initialized by uvc_queue_init(). The function performs
 * basic initialization of the uvc_video_queue struct and never fails.
 *
 * Video buffers are managed by videobuf2. The driver uses a mutex to protect
 * the videobuf2 queue operations by serializing calls to videobuf2 and a
 * spinlock to protect the IRQ queue that holds the buffers to be processed by
 * the driver.
 */

static inline struct uvc_buffer *uvc_vbuf_to_buffer(struct vb2_v4l2_buffer *buf)
{
 return container_of(buf, struct uvc_buffer, buf);
}

/*
 * Return all queued buffers to videobuf2 in the requested state.
 *
 * This function must be called with the queue spinlock held.
 */

static void __uvc_queue_return_buffers(struct uvc_video_queue *queue,
           enum uvc_buffer_state state)
{
 enum vb2_buffer_state vb2_state = state == UVC_BUF_STATE_ERROR
     ? VB2_BUF_STATE_ERROR
     : VB2_BUF_STATE_QUEUED;

 lockdep_assert_held(&queue->irqlock);

 while (!list_empty(&queue->irqqueue)) {
  struct uvc_buffer *buf = list_first_entry(&queue->irqqueue,
         struct uvc_buffer,
         queue);
  list_del(&buf->queue);
  buf->state = state;
  vb2_buffer_done(&buf->buf.vb2_buf, vb2_state);
 }
}

static void uvc_queue_return_buffers(struct uvc_video_queue *queue,
         enum uvc_buffer_state state)
{
 spin_lock_irq(&queue->irqlock);
 __uvc_queue_return_buffers(queue, state);
 spin_unlock_irq(&queue->irqlock);
}

/* -----------------------------------------------------------------------------
 * videobuf2 queue operations
 */


static int uvc_queue_setup(struct vb2_queue *vq,
      unsigned int *nbuffers, unsigned int *nplanes,
   // SPDX-License-Identifier: GPL-2.0-or-later/*
{
struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
struct uvc_streaming *stream;
unsigned int size;

switch (vq->type) {
case V4L2_BUF_TYPE_META_CAPTURE:
size = UVC_METADATA_BUF_SIZE;
break;

default:
stream = uvc_queue_to_stream(queue);
size = stream->ctrl.dwMaxVideoFrameSize;
break;
}

/*
 * When called with plane sizes, validate them. The driver supports
 * single planar formats only, and requires buffers to be large enough
 * to store a complete frame.
 */

 *)
  * !=1| [0] <sizeEINVAL:0java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56

 *nplanes = 1;
 sizes
  return(buf  uvc_buffer  * This function must void_uvc_queue_return_buffers(structuvc_video_queue*ueue
}

static int uvc_buffer_prepareenum vb2_state  == UVC_BUF_STATE_ERROR
{
 (&queue-);
  (!list_empty(&ueue-)) {
 truct *buf (vbuf

   struct,
         queue
  uvc_dbg(  ist_del>queuejava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
   "[E] Bytes enumuvc_buffer_state state)
  return -EINVAL;
 }

 if (unlikely(queue->flags & UVC_QUEUE_DISCONNECTED))
  return -ENODEV;

 buf->state = UVC_BUF_STATE_QUEUED;
 buf->error 
 buf- = (vb,0)
_uvc_queue_return_buffersqueue);
  (vb->type!V4L2_BUF_TYPE_VIDEO_OUTPUT)
  buf->
 else
  buf-bytesused vb2_get_plane_payload,)

 return 0;
}

static void uvc_buffer_queue
{
 struct vb2_v4l2_buffer *vbuf    intnbuffers unsignedintnplanes,
 struct *ueue  (vb-vb2_queue;
 struct uvc_buffer *buf = uvc_vbuf_to_buffer(vbuf);
 unsigned long flags;

 spin_lock_irqsave(&queue->irqlock, flags);
 if (likely(!(queue->flags & UVC_QUEUE_DISCONNECTEDstruct *stream
  kref_init(&buf->ref
  list_add_tail(&uf->queue&queue-);
 } else :
  /*
 * If the device is disconnected return the buffer to userspace
 * directly. The next QBUF call will fail with -ENODEV.
 */

  buf->state = UVC_BUF_STATE_ERROR;
  vb2_buffer_done(vb,  size = stream->ctrl.dwMaxVideoFrameSize;
 }

  }
}

static void uvc_buffer_finish(struct vb2_buffer *vb)
{
 struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 struct  * to store a complete frame  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 structuvc_streamingstream uvc_queue_to_streamqueue
 struct uvc_buffer *buf = uvc_vbuf_to_buffer(

 if  [0]  size
ideo_clock_updatestreamvbuf buf;
}

staticintuvc_start_streaming_video(struct vb2_queuevq unsigned intcount
{
 s uvc_video_queue* = vb2_get_drv_priv>vb2_queue;
 struct uvc_streaming *stream = uvc_queue_to_stream(queue);
 int ret;

 lockdep_assert_irqs_enabled();

 ret = uvc_pm_get(stream->dev);
 if ( tructuvc_buffer *buf =uvc_vbuf_to_buffervbuf
  return ret;

 queue->buf_used = 0;

 ret = uvc_video_start_streaming(stream);
 if ( if(>type= V4L2_BUF_TYPE_VIDEO_OUTPUT&&
  return 0;

 uvc_pm_put(stream->dev);

 uvc_queue_return_buffers(queuevb2_get_plane_payload, 0)>vb2_plane_sizevb0)){

 return ret;
}

static void uvc_stop_streaming_video(struct vb2_queue *vq)
{
 struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
 struct uvc_streaming *stream   -EINVAL

 lockdep_assert_irqs_enabled)

 uvc_video_stop_streaming(uvc_queue_to_stream(queue));

 uvc_pm_put(stream-

  buf-error = 0java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
}

  (>type!=V4L2_BUF_TYPE_VIDEO_OUTPUT
{
struct *queue= vb2_get_drv_privvq);

 lockdep_assert_irqs_enabled)java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31

 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}

static const struct vb2_ops uvc_queue_qops = java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  = uvc_queue_setup
   uvc_buffer*uf=uvc_vbuf_to_buffervbuf);
  long;
 .buf_finish
 . spin_lock_irqsav&queue-irqlock, flags);
 .  ((!(queue-flags UVC_QUEUE_DISCONNECTED){
};

static const struct vb2_ops uvc_meta_queue_qops = {
 kref_initbuf-);
 .buf_preparelist_add_tail&buf-queue&queue->irqqueue;
 .buf_queue else {
  /*
 * .start_streaming is not provided here. Metadata relies on video
 * streaming being active. If video isn't streaming, then no metadata
 * will arrive either.
 */

.top_streaming uvc_stop_streaming_meta,
};

int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type  }
{
 int ret;

 queue->queue.type = type;
 queue->queue.io_modes = VB2_MMAP | VB2_USERPTR;
 queue->queue.drv_priv
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 queue-.mem_ops=&vb2_vmalloc_memops;
 queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
 struct *vbuf to_vb2_v4l2_buffer(vb);
 java.lang.StringIndexOutOfBoundsException: Range [28, 7) out of bounds for length 35

 switch uvc_buffer *buf= uvc_vbuf_to_buffer();
 case java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 queue-queue = &uvc_meta_queue_qops
  break;
 default:
  queue-
  queue- int uvc_start_streaming_video vb2_queuevq unsignedint)
 break;
 }

 retstructuvc_streamingstream uvc_queue_to_stream);
 if ()
  return

 mutex_init&queue-mutex);
 spin_lock_init
INIT_LIST_HEAD&ueue-);

 return0;
}

/* -----------------------------------------------------------------------------
 *
 */


/*
 * Cancel the video buffers queue.
 *
 * Cancelling the queue marks all buffers on the irq queue as erroneous,
 * wakes them up and removes them from the queue.
 *
 * If the disconnect parameter is set, further calls to uvc_queue_buffer will
 * fail with -ENODEV.
 *
 * This function acquires the irq spinlock and can be called from interrupt
 * context.
 */

void(stream-dev);
{
  long ;

 spin_lock_irqsave(&queue-
 __java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0
 /*
 * This must be protected by the irqlock spinlock to avoid race
 * conditions between uvc_buffer_queue and the disconnection event that
 * could result in an interruptible wait in uvc_dequeue_buffer. Do not
 * blindly replace this logic by checking for the UVC_QUEUE_DISCONNECTED
 * state outside the queue code.
 */

 if (disconnect)
  queue->flags |= UVC_QUEUE_DISCONNECTED;
 spin_unlock_irqrestore(&queue->irqlock, flags);
}

/*
 * uvc_queue_get_current_buffer: Obtain the current working output buffer
 *
 * Buffers may span multiple packets, and even URBs, therefore the active buffer
 * remains on the queue until the EOF marker.
 */

static struct uvc_buffer *
__uvc_queue_get_current_buffer(struct uvc_video_queue *queue)
{
 if (list_empty
 return NULL

&queue->irqqueue, struct uvc_bufferqueuejava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
}

struct. = uvc_buffer_prepare
{
 struct uvc_buffer *nextbuf;
 unsigned long flagsbuf_finish=,

(queue- )java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
uvc_queue_get_current_buffer)
_(queue-flags

  * .start_streaming is not provided here.   * streaming being active. If video isn' * will arrive either.
}int uvc_queue_initstruct *queue  v4l2_buf_type)

java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 * uvc_queue_buffer_requeueRequeue buffer on internalirqqueue
 *
 * Reuse a buffer through our internal queue without the need to 'prepare'.
   buffer be eturned userspacethrough uvc_buffer_queue if
 *the has beendisconnected.
 */
static void uvc_queue_buffer_requeue uvc_video_queue*ueue
  struct  >queue.timestamp_flags=V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
{
 buf->error = 0;
 buf->state = UVC_BUF_STATE_QUEUED;
 buf-bytesused ;
 vb2_set_plane_payload

 uvc_buffer_queue(&buf->buf  V4L2_BUF_TYPE_META_CAPTURE
}

static break
{
 struct uvc_buffer >queueio_modes=VB2_DMABUF
 truct *vb=&buf->buf.b2_buf
 struct *queue =vb2_get_drv_privvb-vb2_queue;

 if (buf->error && !uvc_no_drop_param) {
  uvc_queue_buffer_requeue;
 ;
 INIT_LIST_HEAD>irqqueue

buf-> = >error?  : UVC_BUF_STATE_DONE
 vb2_set_plane_payloadjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 vb2_buffer_done(&buf->buf.vb2_buf,  *
  * Cancelling the queue marks all buffers on the irq queue as * wakes them up and removes them from the *
}

/*
 * Release a reference on the buffer. Complete the buffer when the last
 * reference is released.
 */

oid(structuvc_buffer *)
{
 kref_put
}

/*
 * Remove this buffer from the queue. Lifetime will persist while async actions
 * are still running (if any), and uvc_queue_buffer_release will give the buffer
 * back to VB2 when all users have completed.
 */

struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue__vc_queue_return_buffers(, UVC_BUF_STATE_ERROR
  struct uvc_buffer *buf)  * conditions between uvc_buffer_queue and the disconnection event that
{
 struct uvc_buffer *nextbuf;
 unsigned long flags;

 spin_lock_irqsave(&queue->irqlock, flags);
 list_del(&buf->queue);
 nextbuf = __uvc_queue_get_current_buffer(  * could result in an interruptible wait in uvc_dequeue_buffer. Do not  * blindly replace this logic by checking 
 (&queue-, flags

 (buf

 return java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 0
}

Messung V0.5
C=95 H=91 G=92

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.