Errors when switching nvpmodel with active libargus objects on AGX with >4 cameras

We are using an Xavier AGX on the Leopard Imaging LI-XAVIER-KIT-IMX274 carrier board with 6 IMX274 cameras via the LI-JXAV-MIPI-ADPT-6CAM-FP camera breakout board. The latest 4.4.1 Jetpack is installed. I have slightly modified the oneShot example to take a photo from each of 6 cameras. If I change the nvpmodel from 2 to 0 before cleaning up the libargus objects, I get a bunch of errors:

Executing Argus Sample: one_shot
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module0
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module1
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module2
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module3
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module4
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module5
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
OFParserGetVirtualDevice: NVIDIA Camera virtual enumerator not found in proc device-tree
---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing again---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing again---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing again---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing again---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing again---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing againArgus Version: 0.97.3 (single-process)
Capturing from device 0 using sensor mode 0 (3840x2160)
CAM: serial no file already exists, skips storing againCapturing from device 1 using sensor mode 0 (3840x2160)
CAM: serial no file already exists, skips storing againCapturing from device 2 using sensor mode 0 (3840x2160)
CAM: serial no file already exists, skips storing againCapturing from device 3 using sensor mode 0 (3840x2160)
CAM: serial no file already exists, skips storing again
Wrote file: argus_cam0.jpg

Wrote file: argus_cam1.jpg

Wrote file: argus_cam2.jpg

Wrote file: argus_cam3.jpg
root@argus-wingtip:~# ./one_shot
Executing Argus Sample: one_shot
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module0
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module1
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module2
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module3
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module4
OFParserListModules: module list: /proc/device-tree/tegra-camera-platform/modules/module5
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
NvPclHwGetModuleList: WARNING: Could not map module to ISP config string
NvPclHwGetModuleList: No module data found
OFParserGetVirtualDevice: NVIDIA Camera virtual enumerator not found in proc device-tree
---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing again---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing again---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing again---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing again---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing again---- imager: Found override file [/var/nvidia/nvcam/settings/camera_overrides.isp]. ----
CAM: serial no file already exists, skips storing againArgus Version: 0.97.3 (single-process)
Capturing from device 0 using sensor mode 0 (3840x2160)
CAM: serial no file already exists, skips storing againCapturing from device 1 using sensor mode 0 (3840x2160)
CAM: serial no file already exists, skips storing againCapturing from device 2 using sensor mode 0 (3840x2160)
CAM: serial no file already exists, skips storing againCapturing from device 3 using sensor mode 0 (3840x2160)
CAM: serial no file already exists, skips storing againCapturing from device 4 using sensor mode 0 (3840x2160)
CAM: serial no file already exists, skips storing againCapturing from device 5 using sensor mode 0 (3840x2160)
CAM: serial no file already exists, skips storing again
Wrote file: argus_cam0.jpg

Wrote file: argus_cam1.jpg

Wrote file: argus_cam2.jpg

Wrote file: argus_cam3.jpg

Wrote file: argus_cam4.jpg

Wrote file: argus_cam5.jpg
NvCaptureStatusErrorDecode Stream 1.0 failed: sof_ts 2213591046720 eof_ts 2213596353184 frame 0 error 0 data 0x00000000
NvCaptureStatusErrorDecode Capture-Error: UNKNOWN (0x00000000)
(NvCapture) Error InvalidState: Channel is in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureRequestGetAttribute(), line 1870)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 871)
SCF: Error InvalidState: Capture error with status 0 (channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 880)
SCF: Error InvalidState: Sequence order error (184 received, 0 expected, channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 887)
(NvCapture) Error InvalidState: Channel in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureReleaseRequest(), line 649)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 897)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
NvCaptureStatusErrorDecode Stream 4.0 failed: sof_ts 2213579276160 eof_ts 2213596353248 frame 0 error 0 data 0x00000000
NvCaptureStatusErrorDecode Capture-Error: UNKNOWN (0x00000000)
NvCaptureStatusErrorDecode Stream 2.0 failed: sof_ts 2213586756864 eof_ts 2213596353280 frame 0 error 0 data 0x00000000
NvCaptureStatusErrorDecode Stream 0.0 failed: sof_ts 2213580901952 eof_ts 2213596353312 frame 0 error 0 data 0x00000000
NvCaptureStatusErrorDecode Capture-Error: UNKNOWN (0x00000000)
NvCaptureStatusErrorDecode Stream 5.0 failed: sof_ts 2213589584096 eof_ts 2213596353280 frame 0 error 0 data 0x00000000
NvCaptureStatusErrorDecode Capture-Error: UNKNOWN (0x00000000)
NvCaptureStatusErrorDecode Stream 3.0 failed: sof_ts 2213595696032 eof_ts 2213596353600 frame 0 error 0 data 0x00000000
NvCaptureStatusErrorDecode Capture-Error: UNKNOWN (0x00000000)
(NvCapture) Error InvalidState: Channel is in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureRequestGetAttribute(), line 1870)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 871)
SCF: Error InvalidState: Capture error with status 0 (channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 880)
(NvCapture) Error InvalidState: Channel is in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureRequestGetAttribute(), line 1870)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 871)
SCF: Error InvalidState: Capture error with status 0 (channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 880)
SCF: Error InvalidState: Sequence order error (171 received, 0 expected, channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 887)
(NvCapture) Error InvalidState: Channel in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureReleaseRequest(), line 649)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 897)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
(NvCapture) Error InvalidState: Channel is in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureRequestGetAttribute(), line 1870)
(NvCapture) Error InvalidState: Channel is in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureRequestGetAttribute(), line 1870)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 871)
SCF: Error InvalidState: Capture error with status 0 (channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 880)
SCF: Error InvalidState: Sequence order error (155 received, 0 expected, channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 887)
(NvCapture) Error InvalidState: Channel in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureReleaseRequest(), line 649)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 897)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
SCF: Error InvalidState: Sequence order error (163 received, 0 expected, channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 887)
(NvCapture) Error InvalidState: Channel in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureReleaseRequest(), line 649)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 897)
NvCaptureStatusErrorDecode Capture-Error: UNKNOWN (0x00000000)
(NvCapture) Error InvalidState: Channel is in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureRequestGetAttribute(), line 1870)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 871)
SCF: Error InvalidState: Capture error with status 0 (channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 880)
SCF: Error InvalidState: Sequence order error (195 received, 0 expected, channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 887)
(NvCapture) Error InvalidState: Channel in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureReleaseRequest(), line 649)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 897)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 871)
SCF: Error InvalidState: Capture error with status 0 (channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 880)
SCF: Error InvalidState: Sequence order error (177 received, 0 expected, channel 0) (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 887)
(NvCapture) Error InvalidState: Channel in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureReleaseRequest(), line 649)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 897)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
SCF: Error InvalidState: Something went wrong with waiting on frame end (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameEnd(), line 939)
SCF: Error InvalidState: Timeout waiting on frame start sensor guid 1, capture sequence ID = 178 (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 966)
SCF: Error InvalidState: Something went wrong with waiting on frame start (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 1021)
(NvCapture) Error InvalidState: Channel in error state, reset required (in /dvs/git/dirty/git-master_linux/camera/capture/nvcapture/capture.c, function NvCaptureGetRequest(), line 693)
SCF: Error InvalidState: (propagating from src/services/capture/NvCaptureViCsiHw.cpp, function startCaptureInternal(), line 561)
SCF: Error InvalidState: (propagating from src/services/capture/CaptureRecord.cpp, function doCSItoMemCapture(), line 517)
SCF: Error InvalidState: (propagating from src/services/capture/CaptureRecord.cpp, function issueCapture(), line 454)
SCF: Error InvalidState: (propagating from src/services/capture/CaptureServiceDevice.cpp, function issueCaptures(), line 1293)
SCF: Error InvalidState: (propagating from src/services/capture/CaptureServiceDevice.cpp, function issueBubbleFillCapturesIfNeeded(), line 676)
SCF: Error InvalidState: (propagating from src/services/capture/CaptureServiceDevice.cpp, function issueCaptures(), line 1135)
SCF: Error InvalidState: (propagating from src/common/Utils.cpp, function workerThread(), line 116)
SCF: Error InvalidState: Worker thread CaptureScheduler frameStart failed (in src/common/Utils.cpp, function workerThread(), line 133)
PowerServiceCore:handleRequests: timePassed = 1507
SCF: Error InvalidState: Timeout waiting on frame start sensor guid 3, capture sequence ID = 164 (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 966)
SCF: Error InvalidState: Something went wrong with waiting on frame start (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 1021)
SCF: Error InvalidState: Timeout waiting on frame start sensor guid 0, capture sequence ID = 196 (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 966)
SCF: Error InvalidState: Something went wrong with waiting on frame start (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 1021)
SCF: Error InvalidState: Timeout waiting on frame start sensor guid 5, capture sequence ID = 156 (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 966)
SCF: Error InvalidState: Something went wrong with waiting on frame start (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 1021)
SCF: Error InvalidState: Timeout waiting on frame start sensor guid 2, capture sequence ID = 172 (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 966)
SCF: Error InvalidState: Something went wrong with waiting on frame start (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 1021)
SCF: Error InvalidState: Timeout waiting on frame start sensor guid 4, capture sequence ID = 185 (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 966)
SCF: Error InvalidState: Something went wrong with waiting on frame start (in src/services/capture/NvCaptureViCsiHw.cpp, function waitCsiFrameStart(), line 1021)
SCF: Error Timeout: (propagating from src/services/capture/CaptureServiceEvent.cpp, function wait(), line 59)
Error: Camera HwEvents wait, this may indicate a hardware timeout occured,abort current/incoming cc
SCF: Error Timeout: (propagating from src/services/capture/CaptureServiceEvent.cpp, function wait(), line 59)
Error: Camera HwEvents wait, this may indicate a hardware timeout occured,abort current/incoming cc
SCF: Error Timeout: (propagating from src/services/capture/CaptureServiceEvent.cpp, function wait(), line 59)
Error: Camera HwEvents wait, this may indicate a hardware timeout occured,abort current/incoming cc
SCF: Error InvalidState: Not initialized (in src/components/CaptureDispatcher.cpp, function flush(), line 147)
SCF: Error Timeout: (propagating from src/services/capture/CaptureServiceEvent.cpp, function wait(), line 59)
Error: Camera HwEvents wait, this may indicate a hardware timeout occured,abort current/incoming cc
SCF: Error Timeout: (propagating from src/services/capture/CaptureServiceEvent.cpp, function wait(), line 59)
Error: Camera HwEvents wait, this may indicate a hardware timeout occured,abort current/incoming cc
SCF: Error Timeout: (propagating from src/services/capture/CaptureServiceEvent.cpp, function wait(), line 59)
Error: Camera HwEvents wait, this may indicate a hardware timeout occured,abort current/incoming cc

Here is the code I used to take jpgs from multiple cameras:

/*

  • Copyright © 2016-2018, NVIDIA CORPORATION. All rights reserved.
  • Redistribution and use in source and binary forms, with or without
  • modification, are permitted provided that the following conditions
  • are met:
    • Redistributions of source code must retain the above copyright
  • notice, this list of conditions and the following disclaimer.
    • Redistributions in binary form must reproduce the above copyright
  • notice, this list of conditions and the following disclaimer in the
  • documentation and/or other materials provided with the distribution.
    • Neither the name of NVIDIA CORPORATION nor the names of its
  • contributors may be used to endorse or promote products derived
  • from this software without specific prior written permission.
  • THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS’’ AND ANY
  • EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  • IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  • PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  • CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  • EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  • PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  • PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  • OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  • (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  • OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */

#include <stdio.h>
#include <stdlib.h>
#include <Argus/Argus.h>
#include <EGLStream/EGLStream.h>
#include “ArgusHelpers.h”
#include “CommonOptions.h”

#include // std::this_thread::sleep_for
#include // std::chrono::seconds

#define EXIT_IF_NULL(val,msg)
{if (!val) {printf("%s\n",msg); return EXIT_FAILURE;}}
#define EXIT_IF_NOT_OK(val,msg)
{if (val!=Argus::STATUS_OK) {printf("%s\n",msg); return EXIT_FAILURE;}}

#ifdef ANDROID
#define FILE_PREFIX “/sdcard/DCIM/”
#else
#define FILE_PREFIX “”
#endif

/*

  • Program: oneShot
  • Function: Capture a single image from a camera device and write to a JPG file
  • Purpose: To demonstrate the most simplistic approach to getting the Argus Framework
  •      running, submitting a capture request, retrieving the resulting image and
    
  •      then writing the image as a JPEG formatted file.
    

*/

int main(int argc, char** argv)
{
ArgusSamples::CommonOptions options(basename(argv[0]),
ArgusSamples::CommonOptions::Option_D_CameraDevice |
ArgusSamples::CommonOptions::Option_M_SensorMode);
if (!options.parse(argc, argv))
return EXIT_FAILURE;
if (options.requestedExit())
return EXIT_SUCCESS;

const uint64_t FIVE_SECONDS_IN_NANOSECONDS = 5000000000;


std::vector<Argus::UniqueObj<EGLStream::FrameConsumer>> frameConsumers;
std::vector<Argus::UniqueObj<Argus::Request>> requests;
std::vector<Argus::UniqueObj<Argus::OutputStream>> outputStreams;
std::vector<Argus::UniqueObj<Argus::CaptureSession>> captureSessions;

Argus::Status status;

/*
 * Set up Argus API Framework, identify available camera devices, and create
 * a capture session for the first available device
 */

Argus::UniqueObj<Argus::CameraProvider> cameraProvider(Argus::CameraProvider::create());

Argus::ICameraProvider *iCameraProvider =
    Argus::interface_cast<Argus::ICameraProvider>(cameraProvider);
EXIT_IF_NULL(iCameraProvider, "Cannot get core camera provider interface");
printf("Argus Version: %s\n", iCameraProvider->getVersion().c_str());

std::vector<Argus::CameraDevice *> cameraDevices;
iCameraProvider->getCameraDevices(&cameraDevices);

/*
Set up individual cameras
*/
int camera_index = 0;
for (auto device:cameraDevices) {

    Argus::SensorMode* sensorMode = ArgusSamples::ArgusHelpers::getSensorMode(
            device, options.sensorModeIndex());
    Argus::ISensorMode *iSensorMode =
        Argus::interface_cast<Argus::ISensorMode>(sensorMode);
    if (!iSensorMode)
    {
        REPORT_ERROR("Failed to get sensor mode interface");
        return EXIT_FAILURE;
    }

    printf("Capturing from device %d using sensor mode %d (%dx%d)\n",
        camera_index, options.sensorModeIndex(),
        iSensorMode->getResolution().width(), iSensorMode->getResolution().height());

    captureSessions.push_back(Argus::UniqueObj<Argus::CaptureSession>(iCameraProvider->createCaptureSession(device, &status)));
    EXIT_IF_NOT_OK(status, "Failed to create capture session");

    Argus::ICaptureSession *iSession =
        Argus::interface_cast<Argus::ICaptureSession>(captureSessions.back());
    EXIT_IF_NULL(iSession, "Cannot get Capture Session Interface");

    /*
    * Creates the stream between the Argus camera image capturing
    * sub-system (producer) and the image acquisition code (consumer).  A consumer object is
    * created from the stream to be used to request the image frame.  A successfully submitted
    * capture request activates the stream's functionality to eventually make a frame available
    * for acquisition.
    */

    Argus::UniqueObj<Argus::OutputStreamSettings> streamSettings(
        iSession->createOutputStreamSettings(Argus::STREAM_TYPE_EGL));

    Argus::IEGLOutputStreamSettings *iEGLStreamSettings =
        Argus::interface_cast<Argus::IEGLOutputStreamSettings>(streamSettings);
    EXIT_IF_NULL(iEGLStreamSettings, "Cannot get IEGLOutputStreamSettings Interface");
    iEGLStreamSettings->setPixelFormat(Argus::PIXEL_FMT_YCbCr_420_888);
    iEGLStreamSettings->setResolution(iSensorMode->getResolution());
    iEGLStreamSettings->setMetadataEnable(true);

    outputStreams.push_back(Argus::UniqueObj<Argus::OutputStream>(iSession->createOutputStream(streamSettings.get())));
    EXIT_IF_NULL(outputStreams.back(), "Failed to create EGLOutputStream");

    frameConsumers.push_back(Argus::UniqueObj<EGLStream::FrameConsumer>(EGLStream::FrameConsumer::create(outputStreams.back().get())));

    EGLStream::IFrameConsumer *iFrameConsumer =
        Argus::interface_cast<EGLStream::IFrameConsumer>(frameConsumers.back());
    EXIT_IF_NULL(iFrameConsumer, "Failed to initialize Consumer");

    requests.push_back(
        Argus::UniqueObj<Argus::Request>(iSession->createRequest(Argus::CAPTURE_INTENT_STILL_CAPTURE)));
    Argus::IRequest *iRequest = Argus::interface_cast<Argus::IRequest>(requests.back().get());
    EXIT_IF_NULL(iRequest, "Failed to get capture request interface");

    status = iRequest->enableOutputStream(outputStreams.back().get());
    EXIT_IF_NOT_OK(status, "Failed to enable stream in capture request");

    Argus::ISourceSettings *iSourceSettings =
        Argus::interface_cast<Argus::ISourceSettings>(requests.back());
    EXIT_IF_NULL(iSourceSettings, "Failed to get source settings request interface");
    iSourceSettings->setSensorMode(sensorMode);
    camera_index ++;
}

for (int camera_index=0;camera_index < cameraDevices.size();camera_index++) {
    Argus::ICaptureSession *iSession =
        Argus::interface_cast<Argus::ICaptureSession>(captureSessions[camera_index]);
    uint32_t requestId = iSession->capture(requests[camera_index].get());
    EXIT_IF_NULL(requestId, "Failed to submit capture request");

    /*
    * Acquire a frame generated by the capture request, get the image from the frame
    * and create a .JPG file of the captured image
    */
    EGLStream::IFrameConsumer *iFrameConsumer =
            Argus::interface_cast<EGLStream::IFrameConsumer>(frameConsumers[camera_index].get());
    Argus::UniqueObj<EGLStream::Frame> frame(
        iFrameConsumer->acquireFrame(FIVE_SECONDS_IN_NANOSECONDS, &status));

    EGLStream::IFrame *iFrame = Argus::interface_cast<EGLStream::IFrame>(frame);
    EXIT_IF_NULL(iFrame, "Failed to get IFrame interface");

    EGLStream::Image *image = iFrame->getImage();
    EXIT_IF_NULL(image, "Failed to get Image from iFrame->getImage()");

    EGLStream::IImageJPEG *iImageJPEG = Argus::interface_cast<EGLStream::IImageJPEG>(image);
    EXIT_IF_NULL(iImageJPEG, "Failed to get ImageJPEG Interface");

    std::string filename = std::string(FILE_PREFIX "argus_cam") + std::to_string(camera_index) + ".jpg";
    status = iImageJPEG->writeJPEG(filename.c_str());
    EXIT_IF_NOT_OK(status, "Failed to write JPEG");

    printf("\nWrote file: %s\n", filename.c_str());
}

// Changing the nvpmodel from 2->0 during this sleep causes errors!
std::this_thread::sleep_for(std::chrono::seconds(15));

frameConsumers.clear();
requests.clear();
outputStreams.clear();
captureSessions.clear();

// Shut down Argus.
cameraProvider.reset();

return EXIT_SUCCESS;

}

If I only connect to four or fewer of the cameras, regardless of which particular cameras, I can change the nvpmodel during the sleep without causing errors. When I connect to five or more, I cannot switch from nvpmodel 2 to nvpmodel 0. After the errors, the capture sessions no longer respond to capture requests.

Is there an error in the way I am using the libargus API? Can you provide any clues as to how to hunt this down?

hello cory5d01b,

please have a try to narrow down the issue, you may enable multiple camera for streaming with argus_camera sample application.
please confirm if you’re able to switch power-modes.
thanks

What is the argus_camera sample application? The above is a minimally modified example from jetson_multimedia_api/argus/samples/oneShot to extend it for multiple cameras. It works fine with 4 cameras, or if I don’t switch nvpmodels before releasing all the libargus objects.

hello cory5d01b,

it’s sample application with user-interface to demonstrate libargus for imaging applications.
you should install MMAPI through SDKManager, you may refer to the readme file for the steps of building and installing,
for example, /usr/src/jetson_multimedia_api/argus/README.TXT
thanks