PeterBee97 commented on code in PR #1449: URL: https://github.com/apache/nuttx-apps/pull/1449#discussion_r1041706056
########## include/system/nxcamera.h: ########## @@ -0,0 +1,285 @@ +/**************************************************************************** + * apps/include/system/nxcamera.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_INCLUDE_SYSTEM_NXCAMERA_H +#define __APPS_INCLUDE_SYSTEM_NXCAMERA_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <nuttx/video/video.h> +#include <nuttx/video/fb.h> +#include <mqueue.h> +#include <pthread.h> +#include <semaphore.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Standard Video Message Queue message IDs */ + +#define VIDEO_MSG_NONE 0 +#define VIDEO_MSG_DEQUEUE 1 +#define VIDEO_MSG_START 2 +#define VIDEO_MSG_STOP 3 +#define VIDEO_MSG_PAUSE 4 +#define VIDEO_MSG_RESUME 5 +#define VIDEO_MSG_DATA_REQUEST 6 +#define VIDEO_MSG_ENQUEUE 7 +#define VIDEO_MSG_COMPLETE 8 +#define VIDEO_MSG_WAKEUP 9 +#define VIDEO_MSG_COMMAND 10 +#define VIDEO_MSG_SLIENCE 11 +#define VIDEO_MSG_USER 64 + +/**************************************************************************** + * Public Type Declarations + ****************************************************************************/ + +/* This structure describes the internal state of the nxcamera */ + +struct nxcamera_s +{ + int loopstate; /* Current looper test state */ + int capture_fd; /* File descriptor of active + * capture device */ +#ifdef CONFIG_NXCAMERA_INCLUDE_PREFERRED_DEVICE + char capturedev[CONFIG_NAME_MAX]; /* Preferred capture device */ +#endif + int display_fd; /* File descriptor of active + * display device */ + char displaydev[CONFIG_NAME_MAX]; /* Display framebuffer device */ + struct fb_planeinfo_s display_pinfo; /* Display plane info */ + char ovideopath[CONFIG_NAME_MAX]; /* Output video file path */ + char oimagepath[CONFIG_NAME_MAX]; /* Output image file path */ + int crefs; /* Number of references */ + sem_t sem; /* Thread sync semaphore */ + char mqname[14]; /* Name of display message queue */ + mqd_t mq; /* Message queue for the + * loopthread */ + pthread_t loop_id; /* Thread ID of the loopthread */ + v4l2_format_t fmt; /* Buffer format */ + size_t nbuffers; /* Number of buffers */ + FAR size_t *buf_sizes; /* Buffer lengths */ + FAR uint8_t **bufs; /* Buffer pointers */ +}; + +struct video_msg_s +{ + uint16_t msg_id; /* Message ID */ + union + { + FAR void *ptr; /* Buffer being dequeued */ + uint32_t data; /* Message data */ + } u; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: nxcamera_create + * + * Allocates and Initializes a nxcamera context that is passed to all + * nxcamera routines. The looper MUST be destroyed using the + * nxcamera_destroy() routine since the context is reference counted. + * The context can be used in a mode where the caller creates the + * context, starts a looping, and then forgets about the context + * and it will self free. This is because the nxcamera_stream + * will also create a reference to the context, so the client calling + * nxcamera_destroy() won't actually de-allocate anything. The freeing + * will occur after the loopthread has completed. + * + * Alternately, the caller can create the object and hold on to it, then + * the context will persist until the original creator destroys it. + * + * Input Parameters: None + * + * Returned Value: + * Pointer to created nxcamera context or NULL if error. + ****************************************************************************/ + +FAR struct nxcamera_s *nxcamera_create(void); + +/**************************************************************************** + * Name: nxcamera_release + * + * Reduces the reference count to the looper and if it reaches zero, + * frees all memory used by the context. + * + * Input Parameters: + * pcam Pointer to the nxcamera context + * + * Returned Value: + * None + * + ****************************************************************************/ + +void nxcamera_release(FAR struct nxcamera_s *pcam); + +/**************************************************************************** + * Name: nxcamera_reference + * + * Increments the reference count to the looper. + * + * Input Parameters: + * pcam Pointer to the nxcamera context + * + * Returned Value: + * None + * + ****************************************************************************/ + +void nxcamera_reference(FAR struct nxcamera_s *pcam); + +/**************************************************************************** + * Name: nxcamera_stream + * + * nxcamera_stream() tries to capture and then display the raw data using + * the Video system. If a capture device is specified, it will try to use + * that device. + * + * Input: + * pcam Pointer to the initialized Looper context + * width Capture frame width + * height Capture frame height + * framerate Capture frame rate + * format Capture frame pixel format + * + * Returns: + * OK Video is being streamed + * -EBUSY Capture device is busy + * -ENOSYS No supported video format found + * -ENODEV No video capture or framebuffer device suitable + * + ****************************************************************************/ + +int nxcamera_stream(FAR struct nxcamera_s *pcam, + uint16_t width, uint16_t height, + uint32_t framerate, uint32_t format); Review Comment: done ########## system/nxcamera/nxcamera.c: ########## @@ -0,0 +1,905 @@ +/**************************************************************************** + * apps/system/nxcamera/nxcamera.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <debug.h> +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <pthread.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <nuttx/queue.h> +#include <nuttx/video/video.h> +#include <nuttx/video/fb.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <sys/types.h> + +#include "system/nxcamera.h" +#ifdef CONFIG_LIBYUV +#include "libyuv.h" Review Comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org