public static boolean startRTSP( String localIPAddress, int rtpStreamLocalPort, String deviceAddress, int tunerNumber) { logger.entry(localIPAddress, rtpStreamLocalPort, deviceAddress, tunerNumber); logger.info( "Starting streaming from tuner number {} to local port '{}'.", tunerNumber, rtpStreamLocalPort); if (tunerNumber - 1 < 0) { logger.error("The tuner number cannot be less than 1."); return logger.exit(false); } try { String currentIP = InfiniTVStatus.getVar(deviceAddress, tunerNumber, "diag", "Streaming_IP"); String currentPort = InfiniTVStatus.getVar(deviceAddress, tunerNumber, "diag", "Streaming_Port"); String playback = InfiniTVStatus.getVar(deviceAddress, tunerNumber, "av", "TransportState"); if (currentIP.equals(localIPAddress) && currentPort.equals(String.valueOf(rtpStreamLocalPort)) && playback.equals("PLAYING")) { logger.info("The IP address and port for RTP are already set."); return logger.exit(true); } } catch (IOException e) { logger.error("Unable to get the current ip address and streaming port => {}", e); } String instanceId = "instance_id=" + String.valueOf(tunerNumber - 1); String destIp = "dest_ip=" + localIPAddress; String destPort = "dest_port=" + rtpStreamLocalPort; String protocol = "protocol=0"; // RTP String start = "start=1"; // 1 = Started (0 = Stopped) boolean returnValue = postContent( deviceAddress, "/stream_request.cgi", instanceId, destIp, destPort, protocol, start); return logger.exit(returnValue); }
public static boolean tuneChannel( String lineupName, String channel, String deviceAddress, int tunerNumber, boolean useVChannel, int retry) throws InterruptedException { logger.entry(channel, deviceAddress, tunerNumber); boolean returnValue = false; if (useVChannel) { // There is no need to look up the channel when a CableCARD is present. returnValue = tuneVChannel(channel, deviceAddress, tunerNumber, retry); } else { // This will only hang up temporarily when the channel map is still loading or being // refreshed. TVChannel tvChannel = ChannelManager.getChannel(lineupName, channel); if (tvChannel == null) { logger.error("The requested channel does not exist in the channel map."); return logger.exit(false); } try { // Check if the frequency is already correct. boolean frequencyTuned = InfiniTVStatus.getVar(deviceAddress, tunerNumber, "tuner", "Frequency") .equals(tvChannel.getFrequency()); if (!frequencyTuned) { tuneFrequency(tvChannel, deviceAddress, tunerNumber, retry); } int attempts = 10; boolean programSelected = InfiniTVStatus.getVar(deviceAddress, tunerNumber, "mux", "ProgramNumber") .equals(tvChannel.getProgram()); while (!programSelected) { // If we are not already on the correct frequency, it takes the tuner a moment // to detect the available programs. If you try to set a program before the list // is available, it will fail. Normally this happens so fast, a sleep method // isn't appropriate. We have a while loop to retry a few times if it fails. tuneProgram(tvChannel, deviceAddress, tunerNumber, retry); programSelected = InfiniTVStatus.getVar(deviceAddress, tunerNumber, "mux", "ProgramNumber") .equals(tvChannel.getProgram()); if (attempts-- == 0 && !programSelected) { logger.error("The requested program cannot be selected."); return logger.exit(false); } else if (!programSelected) { try { // Sleep if the first request fails so we don't overwhelm the device // with requests. Remember up to 6 of these kinds of request could // happen at the exact same time. Thread.sleep(10); } catch (InterruptedException e) { logger.error("tuneChannel was interrupted while selecting a program."); return logger.exit(false); } } } returnValue = true; /*} catch (InterruptedException e) { logger.debug("tuneChannel was interrupted while waiting setting the program.");*/ } catch (IOException e) { logger.debug("tuneChannel was unable to get the current program value."); } } return logger.exit(returnValue); }