Swap Camera Bandwidth Issues

Hello,
I am a programmer from team 4028, and I have been tasked with being able to swap between camera streams with the push of a button. I have been able to do so with the code below.

package org.usfirst.frc.team4028.robot;

import org.opencv.core.Mat;

import edu.wpi.cscore.CvSink;
import edu.wpi.cscore.CvSource;
import edu.wpi.cscore.MjpegServer;
import edu.wpi.cscore.UsbCamera;
import edu.wpi.cscore.VideoSink;
import edu.wpi.first.wpilibj.CameraServer;

public class MakeItWork
{	
	private String _cameraname;
	
	public MakeItWork(String cameraname)
	{
		_cameraname = cameraname;
		Thread cameraThread = new Thread(JavadotMakeItWork);
		cameraThread.start();
	}

	public String GetString()
	{
		return _cameraname;
	}
	
	public void SwapCamera(String cameraname) 
	{
		_cameraname = cameraname;
	}	
	
	private Runnable JavadotMakeItWork = new Runnable()
	{

		@Override
		public void run() {
			
			// TODO Auto-generated method stub
			UsbCamera _cam0 = new UsbCamera("cam0", 0); //CameraServer.getInstance().startAutomaticCapture(0);
           
            
            UsbCamera _cam1 = new UsbCamera("cam1", 1); //= CameraServer.getInstance().startAutomaticCapture(1);
            
            
            UsbCamera _cam2 = new UsbCamera("cam2", 2); //= CameraServer.getInstance().startAutomaticCapture(1);
           
            CvSink cvSink1 = CameraServer.getInstance().getVideo(_cam0);
            CvSink cvSink2 = CameraServer.getInstance().getVideo(_cam1);
            CvSink cvSink3 = CameraServer.getInstance().getVideo(_cam2);
            
            CvSource outputStream = CameraServer.getInstance().putVideo("Switcher", 640, 480);
            
            Mat image = new Mat();
            
            MjpegServer server = new MjpegServer("server", 1181);
            
            server.setSource(outputStream);
            
            while(!Thread.interrupted()) 
            {
            	if(_cameraname == "cam0")
            	{         

            		_cam0.setFPS(16);
            		_cam1.setFPS(0);
            		_cam2.setFPS(0);
            		_cam0.setResolution(640, 480);
            		cvSink1.grabFrame(image);
            	
            	} 
            	else if(_cameraname == "cam1")
            	{

            		_cam0.setFPS(0);
            		_cam1.setFPS(16);
            		_cam2.setFPS(0);
            		_cam1.setResolution(640, 480);
            		cvSink2.grabFrame(image);
        
            		
            	}
            	else if(_cameraname =="cam2")
            	{

            		_cam0.setFPS(0);
            		_cam1.setFPS(0);
            		_cam2.setFPS(16);
            		_cam2.setResolution(640, 480);
            		cvSink3.grabFrame(image);
            	}
                
                outputStream.putFrame(image);
            }
		}

	};

}

However, the problem is with the resolution and FPS. In order to have enough bandwidth to stream all 3 (and possibly more) cameras, the resolution and FPS has to be so bad it is not practical to use it in competition. Does anyone have any ideas as to how to cancel previous camera streams via alterations to my code or the source code itself? Any help would be much appreciated.

I have discovered that there is an option to disable CvSinks, as shown here.

              cvSink1.setEnabled(false);
            		cvSink2.setEnabled(false);
            		cvSink3.setEnabled(true);

This would go in the while set of your code under each individual if statement.

G’day Nick - you might want to take a look at this thread as well