Camera

Introduction

The Camera module within the Reference app offers features to showcase real-time streaming from RTSP, UDP, and analog cameras. Additionally, it facilitates the recording of streaming content. This functionality is implemented through the utilization of two classes.

  • Camera_C: This class generates a GStreamer pipeline to capture streams from the specified camera, whether it be an RTSP, analog, or UDP camera. It also extracts video frames from the stream. Camera_C is exposed to the front end as qmlRegisterType by the name Camera.
  • CameraViewItem_C: This class is linked to the Camera Class through the "imageChanged" signal. It receives frames from the Camera Class and renders them using QSGNode. Camera_C is exposed to the front end as qmlRegisterType by the name of CameraPlayer.
Important
Both of these classes are meant to be use from QML side.

Analog Camera

MConn supports up to four analog cameras simultaneously. The signals from these cameras are routed through an internal ADC (Analog-to-Digital Converter). Each of these cameras is represented as a device file in the system, accessible at paths:

 1. /dev/video0
 2. /dev/video1  
 3. /dev/video2   
 4. /dev/video3

It's worth noting that "/dev/video0" corresponds to Video1+, and Video1- signals, and the numbering follows sequentially order for subsequent cameras.

The following table describes the pin configuration on the mating connector:

Video Pins on AMPSEAL 776273-1
Video Pins on AMPSEAL 776273-1 Mating Connector

The following is the basic diagram for connecting analog camera to video1 (video0 in application).

Connecting Analog Camera to Video1
Connecting Analog Camera to Video1

Camera_C (Camera in QML)

For Analog we need to configure following Camera Q_Property in QML. To do so, follow the steps below:

  1. type [Q_Property] (Required): For the analog camera "type" property, must be set to string "analog".
  2. captureDevice [Q_Property] (Required): For analog cameras, the developer needs to specify the capture device from "/dev/video0", "/dev/video1," "/dev/video2," or "/dev/video3."
  3. startStream[Q_INVOKABLE function]: This function starts the camera's stream.
Q_INVOKABLE void startStream();
Information
For Analog cameras only one Camera in QML can be initiated per camera.

CameraViewItem_C (CameraPlayer in QML)

For Analog we need to configure the following CameraPlayer Q_Property in QML:

source [Q_Property] (Required): Specify the identifier assigned to the camera in QML. This is essential for the Camera Player to establish a connection and receive frames from the analog camera, rendering them accordingly.

Usage

  1. Expose Camera_C and CameraViewItem_C to frontend as qmlRegisterType.
qmlRegisterType<CameraViewItem_C>("MRSComponents", 1, 0, "CameraPlayer");
qmlRegisterType<Camera_C>("MRSComponents", 1, 0, "Camera");
  1. For analog camera, use the following code:
//Create instance of camera set type to analog and in captureDevice specify analog camera device file, and upon component complete start stream 
Camera {
        id: analogCamSrc2
        type: "analog"
        captureDevice: "/dev/video1"
        Component.onCompleted: {
            analogCamSrc2.startStream()
        }
    }
Note: Do not create multiple instance of Camera with same analog camera device file.

// Create instance of CameraPlayer that will render stream of camera, provide id of analog camera to its source field 
  CameraPlayer {
        id: camera1
        source: cameraList.analogCamSrc1
        anchors.centerIn: parent
        width: 550
        height: 350
        visible: true
        // No need to initialize camera here since, camera are being initialize cameraList
    }

Ethernet Camera

Currently, MConn supports two protocols for Ethernet cameras: "RTSP" and "UDP".

Important
To guarantee proper functionality, the developer must ensure that both MConn and the camera are on the same network.

The developer needs to specify the appropriate URL for these cameras, with further details provided in the following sections. For additional protocol support, developers can contact the MConn team at MRS Electronics for assistance.

RTSP Protocol

Camera_C (Camera in QML)

For Ethernet camera with RTSP protocol we need to configure following Camera Q_Property in QML:

  1. type [Q_Property] (Required): For the RTSP camera "type" property, must be set to sting "rtsp".
  2. captureDevice [Q_Property] (Required): For the RTSP camera the developer must provide the full RTSP URL of the camera, including IP, port, and additional properties. Example: "rtsp://192.168.1.113:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif."
  3. userID [Q_Property] (Required for rtsp camera): Developer need to specify username for the rtsp camera.
  4. password [Q_Property] (Required for rtsp camera): Developer need to specify password for the rtsp camera.
  5. startStream[Q_INVOKABLE function]: This function is used to start the stream of camera.
Q_INVOKABLE void startStream();

CameraViewItem_C (CameraPlayer in QML)

For RTSP we need to configure the following CameraPlayer Q_Property in QML:

source [Q_Property] (Required): Specify the identifier assigned to the camera in QML. This is essential for the Camera Player to establish a connection and receive frames from the RTSP camera, rendering them accordingly.

Usage:

//Create instance of camera set type to rtsp and in captureDevice specify url for camera, and upon component complete start stream  
  Camera {
        id: rtspEthernetCamSrc
        type: "rtsp"
        captureDevice: "rtsp://admin:admin123@192.168.1.113:554/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif"
        userID: "admin"
        password: "admin123"
        dynamicRecordingSaveLocation: "/rw_data"
        recordingFileName: "cam1"
        Component.onCompleted: {
             rtspEthernetCamSrc.startStream()
        }
    }

// Create instance of CameraPlayer that will render stream of camera, provide id of rtsp camera to its source field
      CameraPlayer {
            id: camera5
            source: rtspEthernetCamSrc
            width: parent.width
            height: parent.height
            visible: true
        }

UDP Protocol

Camera_C (Camera in QML)

For Ethernet camera with UDP protocol we need to configure following Camera Q_Property in QML:

  1. type [Q_Property] (Required): For the UDP camera "type" property, must be set to sting "udp".
  2. captureDevice [Q_Property] (Required): For the UDP camera developer needs to specify the port of the UDP camera in this field.

CameraViewItem_C (CameraPlayer in QML)

For UDP, the developer needs to configure the following CameraPlayer Q_Property in QML:

source [Q_Property] (Required): Specify the identifier assigned to the camera in QML. This is essential for the Camera Player to establish a connection and receive frames from the UDP camera, rendering them accordingly.

Usage

//Create instance of camera set type to udp and in captureDevice specify port for camera, and upon component complete start stream  
  Camera {
        id: udpEthernetCamSrc
        type: "udp"
        captureDevice: "5014"
        dynamicRecordingSaveLocation: "/rw_data"
        recordingFileName: "cam1"
    }

// Create instance of CameraPlayer that will render stream of camera, provide id of udp camera to its source field
      CameraPlayer {
            id: camera5
            source:udpEthernetCamSrc
            width: parent.width
            height: parent.height
            visible: true
        }