/** @param pad */ public void linkNewInputToPad(Pad pad) { String addedUrl = inputURLs.get(inputURLs.size() - 1); final Element newInput = inputElements.get(addedUrl); EVENT_PROBE probeListener = new EVENT_PROBE() { public boolean eventReceived(Pad pad, Event event) { String type = event.getStructure().toString(); if (DEBUG) System.out.println("eventReceived: " + type); if (type.toLowerCase().indexOf("error") >= 0) { System.out.println("Error"); return false; } return true; } }; adder.getSrcPads().get(0).addEventProbe(probeListener); Element identity = ElementFactory.make("identity", "identity" + INDEX); identity.set("sync", true); identity.set("single-segment", true); // identity.set("silent", false); // Element mux = ElementFactory.make("flvmux", "mux-timestamp" + INDEX); // Element enc = ElementFactory.make("lamemp3enc", "enc-timestamp" + // INDEX); // Element demux = ElementFactory.make("flvdemux", "demux-timestamp" + // INDEX); // Element dec = ElementFactory.make("flump3dec", "dec-timestamp" + // INDEX); // // // identity.set("silent", false); // pipe.addMany(identity, enc, mux, demux, dec); // // identity.setState(State.PAUSED); // mux.setState(State.PAUSED); // enc.setState(State.PAUSED); // demux.setState(State.PAUSED); // dec.setState(State.PAUSED); // pipe.addMany(newInput, identity); PadLinkReturn linked = newInput.getSrcPads().get(0).link(identity.getSinkPads().get(0)); System.out.println("new input linked: " + linked); // // boolean l = Element.linkMany(identity, enc, mux, demux, dec); // System.out.println("mux demux linked: "+l); // // PadLinkReturn linked2 = dec.getSrcPads().get(0).link(pad); // System.out.println("new dec linked: " + linked2); if (pipe.isPlaying()) { State state = State.READY; // newInput.setState(state); pipe.setState(state); } PadLinkReturn linked3 = identity.getSrcPads().get(0).link(pad); System.out.println("new identity linked: " + linked3); }
public void removeInput(final String url) { if (!inputElements.containsKey(url)) return; System.out.println("\n------------\nremoveInput: " + url + "\n-------------\n"); removedInput = inputElements.get(url); boolean playing = pipe.isPlaying(); Pad inputSrcPad = removedInput.getSrcPads().get(0); removedIdentity = inputSrcPad.getPeer().getParentElement(); Pad adderSinkPad = removedIdentity.getSrcPads().get(0).getPeer(); pipe.setState(State.READY); boolean removed = adder.removePad(adderSinkPad); System.out.println("Pad removed: " + removed); inputElements.remove(url); if (playing) { System.out.println("Adder inputs: " + adder.getSinkPads()); pipe.setState(State.PLAYING); } }
private void addInput(String url) { INDEX++; int i = INDEX; System.out.println("\n------------\naddInput[" + i + "]: " + url + "\n-------------\n"); Element input = null; if (!FAKE_INPUT) { /* create audio output */ final Bin audioBin = new Bin("Audio Bin" + i); Element src = null; if (url.contains("http://")) { src = ElementFactory.make("gnomevfssrc", "Input" + i); src.set("location", url); } else if (url.contains("rtmp") && url.contains("://")) { src = ElementFactory.make("rtmpsrc", "Input" + i); // src.set("do-timestamp", true); src.set("location", url); } else { src = ElementFactory.make("filesrc", "Input" + i); src.set("location", url); } DecodeBin2 decodeBin = new DecodeBin2("Decode Bin" + i); Element decodeQueue = ElementFactory.make("queue2", "Decode Queue" + i); Element conv = ElementFactory.make("audioconvert", "Audio Convert" + i); Element resample = ElementFactory.make("audioresample", "Audio Resample" + i); Element volume = ElementFactory.make("volume", "Audio Volume" + i); volume.set("volume", 1.0f); volumeElements.put(url, volume); audioBin.addMany(conv, resample, volume); Element.linkMany(conv, resample, volume); audioBin.addPad(new GhostPad("src", volume.getStaticPad("src"))); audioBin.addPad(new GhostPad("sink", conv.getStaticPad("sink"))); input = new Bin("Input Bin" + i); ((Bin) input).addMany(src, decodeQueue, decodeBin, audioBin); Element.linkMany(src, decodeQueue, decodeBin, audioBin); input.addPad(new GhostPad("src", audioBin.getSrcPads().get(0))); decodeBin.connect( new DecodeBin2.NEW_DECODED_PAD() { public void newDecodedPad(Element elem, Pad pad, boolean last) { /* only link once */ if (pad.isLinked()) { return; } /* check media type */ Caps caps = pad.getCaps(); Structure struct = caps.getStructure(0); if (struct.getName().startsWith("audio/")) { System.out.println("Linking audio pad: " + struct.getName()); if (audioBin.getStaticPad("sink").getPeer() == null) { PadLinkReturn linked = pad.link(audioBin.getStaticPad("sink")); System.out.println("Decodebin linked " + linked); } } else if (struct.getName().startsWith("video/")) { System.out.println("Linking video pad: " + struct.getName()); } else { System.out.println("Unknown pad [" + struct.getName() + "]"); } } }); } else { input = ElementFactory.make("audiotestsrc", "Audio Fake" + i); int w = i; if (i > 1) w = 5; input.set("wave", w); input.set("is-live", true); } if (!inputURLs.contains(url)) { inputURLs.add(url); } inputElements.put(url, input); boolean playing = pipe.isPlaying(); Pad adderSink = adder.getRequestPad("sink%d"); if (playing) { System.out.println("Adder inputs: " + adder.getSinkPads()); pipe.setState(State.PLAYING); } }