Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 034EB200C24 for ; Thu, 9 Feb 2017 00:54:40 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 01EA5160B67; Wed, 8 Feb 2017 23:54:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 00534160B49 for ; Thu, 9 Feb 2017 00:54:38 +0100 (CET) Received: (qmail 55936 invoked by uid 500); 8 Feb 2017 23:54:38 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 55924 invoked by uid 99); 8 Feb 2017 23:54:37 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Feb 2017 23:54:37 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 35F411A08F6 for ; Wed, 8 Feb 2017 23:54:37 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 4.48 X-Spam-Level: **** X-Spam-Status: No, score=4.48 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, KAM_BADIPHTTP=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001, WEIRD_PORT=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=decampo-org.20150623.gappssmtp.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id wXck85eR9Gb6 for ; Wed, 8 Feb 2017 23:54:33 +0000 (UTC) Received: from mail-ot0-f196.google.com (mail-ot0-f196.google.com [74.125.82.196]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 9B43D5F283 for ; Wed, 8 Feb 2017 23:54:32 +0000 (UTC) Received: by mail-ot0-f196.google.com with SMTP id 36so91375otx.3 for ; Wed, 08 Feb 2017 15:54:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=decampo-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=7k9/PEnJgXlC60CEwuHWdb2MMy0GVjuMePWxrpxYZus=; b=Ps7jjfXyIGZntvhMhpe5bIFzOXSW7dcXY7FMF91AHIzdbSzeIxb15N9pdm/dDaAAnT EKu8RG5cchu57+MknnxwNLhPyZG6rHsnMhK0mPbf8V3i4kRcHjee92qLGeldoYItiHeL Ef6pFh3BT+ZV4xmzenZOYe0626JTMEM0JLveaxTkFvcVZnP3QC0YEmaoyVk2nA8hQ2LT 69o+jvH0N44uyMf69vuTh1NNboiFlQQ3E4URlaIfWhBsSP125aGgnRHFy1+2SUFgz7EP HBYIEMI+h+lr+4ZqBkN0RargaZUCBI71sPQMQkzsX3VmkAPVsVH0k2CYqommL5UcWyGK ajsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=7k9/PEnJgXlC60CEwuHWdb2MMy0GVjuMePWxrpxYZus=; b=COwtFFB0S4sI2AuN05upyZUCi1+I7c+nH618gY4lK96U4twtNu5zzJb5vj/yzlEjh4 8r17OVhCJ7ShFVtg81Kkms6+oLPhRlU3EmOCPCplVvofy53Ni/rxX2kQMdL6SzXVuqil EFb4rOCNOmFq1zumSmxnVc218YpXzqBYbDCWKpCIWmJY+2WAz5oH57lATQDGN65rVcmj TCN7ibYQ2MYZcjUUubPDXjfxEgAodzGGnpXGMBelYC4DExn+B5fJg82XmhgpqSUgE/23 Z47XOx2+2i5Pg5lRD7zySCnhgFIoXGScFViyK9D8KvNiSQEgt8l23LNyJchlHuh0GMst d9TQ== X-Gm-Message-State: AMke39kG7lgq2DlGYiYu3D2R5zbjyQRzaQ8Lc9q2cXpoh725KG5gdfxFGqDC1Ae7ztZF47G1oEENHsNnW0rgWQ== X-Received: by 10.157.52.33 with SMTP id v30mr106118otb.156.1486598069510; Wed, 08 Feb 2017 15:54:29 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.75.66 with HTTP; Wed, 8 Feb 2017 15:54:29 -0800 (PST) X-Originating-IP: [72.228.81.86] In-Reply-To: References: From: Raymond DeCampo Date: Wed, 8 Feb 2017 18:54:29 -0500 Message-ID: Subject: Re: [exec] Misconcepting PumpStreamHandler's way of working with streams? To: Commons Users List Content-Type: multipart/alternative; boundary=001a114147c8db799805480d9524 archived-at: Wed, 08 Feb 2017 23:54:40 -0000 --001a114147c8db799805480d9524 Content-Type: text/plain; charset=UTF-8 OK, Edgar I pared your example down a bunch and got to a working demo. I submitted it as a pull request against the repo you created. I think the key thing was not re-using the executors. This should be enough for you to start modifying it back into what you needed it to be. HTH, Ray On Mon, Feb 6, 2017 at 12:00 PM, Edgar H wrote: > Completly forgot about ffmpeg being Windows compilation, sorry for that. > > I've already updated the git project, even though ffmpeg and Icecast still > there (I don't really know why...) the new classes don't use them anymore. > > > 2017-02-06 13:43 GMT+01:00 Raymond DeCampo : > > > Well, we are still going to run into issues when I try it on my Linux > > machine. > > > > I'd suggest just leaving ffmpeg out of it. Make a pair of simple Java > > classes which take a file and output to standard out and then one which > > reads from standard in and writes to a file; then a main class which > starts > > processes for the other two and hooks them up. > > > > > > On Sun, Feb 5, 2017 at 7:04 PM, Edgar H wrote: > > > > > There it goes, here is the link for the git repo. > > > > > > https://github.com/turbobrick/exec_dmo > > > > > > I've included ffmpeg and also Icecast so you can start the server in > your > > > machine via console and see if the mount "/stream" is active at > > > 127.0.0.1:8000 once you start streaming audio from the system via the > > test > > > app. An already compiled .jar from the SecondApp class has already been > > > generated, and it is inside /bin folder in /ffmpeg. Everything should > be > > > ready to go. > > > > > > Thanks for helping, really appreciated. > > > > > > 2017-02-05 22:51 GMT+01:00 Raymond DeCampo : > > > > > > > If I were to try to run this on my system, it would fail because > there > > is > > > > no ffmpeg.exe file on my machine. > > > > > > > > You need to make it easier for me to help you by making a truly > > > > self-contained minimal example of the issue (see > > > > http://www.catb.org/~esr/faqs/smart-questions.html#code for more > > details > > > > on > > > > this). Preferably the example will contain a pom.xml so it can be > > built > > > > easily and maybe put in on a gist in github so it can be downloaded > > > easily. > > > > > > > > > > > > > > > > On Sun, Feb 5, 2017 at 3:46 PM, Edgar H wrote: > > > > > > > > > Sure, here's a minimal example. > > > > > > > > > > The following code belongs to a "MainApp" class, which is the > > basically > > > > the > > > > > application which starts the .jar responsible of capturing live > audio > > > > data > > > > > from the system and sending it live to FFMPEG, which streams to an > > > > Icecast > > > > > Server, like a continuous stream using pipes. > > > > > > > > > > public class MainApp { > > > > > > > > > > public static void main(String[] args) { > > > > > initStream("Path to FFMPEG bin folder, which should include > > the > > > > > .jar of the second application that you need to copy and paste."); > > > > > } > > > > > > > > > > public static void initStream(String path) { > > > > > File file = new File(path); > > > > > for (File s : file.listFiles()) { > > > > > if (s.getName().equals("ffmpeg.exe")) { > > > > > try { > > > > > DefaultExecutor executor = new > DefaultExecutor(); > > > > > executor.setWorkingDirectory(file); > > > > > > > > > > CommandLine commandLine = new > > > > > CommandLine(s.getParentFile().getAbsolutePath()); > > > > > System.out.println("Path: " + > > > > commandLine.toString()); > > > > > > > > > > String executeMe = "java -jar secondapp.jar"; > // > > > > > Execute "SecondApp" .jar to start sending sound bytes to stdout. > > > > > commandLine = CommandLine.parse(executeMe); > > > > > > > > > > PipedOutputStream output = new > > PipedOutputStream(); > > > > // > > > > > Fill this with bytes. > > > > > PipedInputStream input = new > PipedInputStream(); > > > > > output.connect(input); // Send audio bytes from > > > > output > > > > > to this input stream. > > > > > > > > > > executor.setStreamHandler(new > > > > PumpStreamHandler(output, > > > > > null)); // Stream all the bytes to the output. > > > > > executor.execute(commandLine, new > > > > > DefaultExecuteResultHandler()); // Execute APP2 (The one which > > > captures > > > > > the > > > > > live audio bytes). > > > > > > > > > > String feedMe = "ffmpeg -f s16le -ar 48000 -ac > 2 > > > -i - > > > > > -f ogg -content_type application/ogg icecast://source:hackme@ > > localhost > > > > > :8000/stream"; > > > > > commandLine = CommandLine.parse(feedMe); > > > > > > > > > > executor.setStreamHandler(new > > > PumpStreamHandler(null, > > > > > null, input)); // Send the bytes being received in real time to > > FFMPEG. > > > > > executor.execute(commandLine, new > > > > > DefaultExecuteResultHandler()); // Execute FFMPEG. > > > > > } catch (IOException e) { > > > > > e.printStackTrace(); > > > > > } > > > > > } > > > > > } > > > > > } > > > > > } > > > > > > > > > > Now, this is the code for the executable .jar which is the class > > > > > "SecondApp". This one just sends bytes to the Standard Output and > > it's > > > > > started by "MainApp". > > > > > > > > > > public class SecondApp { > > > > > > > > > > public static void main(String[] args) throws > > > ClassNotFoundException, > > > > > IOException { > > > > > Mixer mixer = > > > > > AudioSystem.getMixer(AudioSystem.getMixerInfo()[ > > > > > Integer.parseInt(args[0])]); > > > > > AudioFormat af = new AudioFormat(Encoding.PCM_SIGNED, > > 48000f, > > > > 16, > > > > > 2, 4, 48000f, false); > > > > > > > > > > TargetDataLine line; > > > > > DataLine.Info info = new DataLine.Info(TargetDataLine. > class, > > > > af); > > > > > if (!AudioSystem.isLineSupported(info)) > > > > > System.out.println("Line is not supported."); > > > > > > > > > > try { > > > > > line = (TargetDataLine) mixer.getLine(info); > > > > > line.open(af); > > > > > > > > > > int bytesRead, CHUNK_SIZE = 4096; > > > > > byte[] data = new byte[line.getBufferSize() / 5]; > > > > > > > > > > line.start(); > > > > > > > > > > while (true) { > > > > > bytesRead = line.read(data, 0, CHUNK_SIZE); > > > > > System.out.write(data, 0, bytesRead); > > > > > System.out.flush(); > > > > > } > > > > > > > > > > } catch (LineUnavailableException ex) { > > > > > System.out.println("Line is unavailable."); > > > > > ex.printStackTrace(); > > > > > } > > > > > } > > > > > } > > > > > > > > > > 2017-02-05 16:31 GMT+01:00 Raymond DeCampo : > > > > > > > > > > > Edgar, I didn't see anything obvious wrong with what you posted. > > If > > > > you > > > > > > can distill it down to a minimal self-contained example that > > > reproduces > > > > > the > > > > > > behavior I can take a closer look. > > > > > > > > > > > > On Sat, Feb 4, 2017 at 1:47 PM, Edgar H > > wrote: > > > > > > > > > > > > > I've been struggling with this problem for quite some time now > as > > > > it's > > > > > my > > > > > > > very first time doing an application related to streaming and I > > > just > > > > > > can't > > > > > > > figure out why. Here's the problem... > > > > > > > > > > > > > > What I'm trying to achieve is to send a command's output as an > > > input > > > > > for > > > > > > > the next one, which is basically what the pipe operator does. > As > > I > > > > knew > > > > > > > this couldn't be executed directly with Exec library from > Apache > > > > > Commons > > > > > > I > > > > > > > started looking for ways to solve this. I've seen quite a few > > > > examples > > > > > of > > > > > > > similar things to this but none of them covers my situation: > > > > > > > > > > > > > > I have two Java applications separated, one is the main > > application > > > > and > > > > > > the > > > > > > > second one is initialized by the first one. This second > > > applications > > > > > > sends > > > > > > > to the Standard Output bytes, which FFMPEG should receive. > > > > > > > > > > > > > > The code that I have so far is the following one... > > > > > > > > > > > > > > public void initStream(String path) { > > > > > > > File file = new File(path); > > > > > > > for (File s : file.listFiles()) { > > > > > > > if (s.getName().equals("ffmpeg.exe")) { > > > > > > > try { > > > > > > > > > > > > > > // Second app, supposedly, writes here. > > > > > > > PipedOutputStream output = new > > PipedOutputStream(); > > > > > > > > > > > > > > DefaultExecutor executor = new > DefaultExecutor(); > > > > > > > //DefaultExecutor executorFFMPEG = new > > > > > DefaultExecutor(); > > > > > > > executor.setWorkingDirectory(file); > > > > > > > //executor.setWorkingDirectory(file); > > > > > > > > > > > > > > CommandLine commandLine = new > > > > > > > CommandLine(s.getParentFile().getAbsolutePath()); > > > > > > > System.out.println("Path: " + > > > > commandLine.toString()); > > > > > > > > > > > > > > String executeMe = "java -jar streamer.jar"; > > > > > > > commandLine = CommandLine.parse(executeMe); > > > > > > > > > > > > > > System.out.println("[testing] streamer about to > > > > > > launch."); > > > > > > > executor.setStreamHandler(new > > > > PumpStreamHandler(output, > > > > > > > null)); > > > > > > > executor.execute(commandLine, new > > > > > > > DefaultExecuteResultHandler()); > > > > > > > System.out.println("[testing] streamer > > started."); > > > > > > > > > > > > > > PipedInputStream input = new > PipedInputStream(); > > > > > > > output.connect(input); > > > > > > > > > > > > > > String feedMe = "ffmpeg"; // more attributes > here > > > > > > > commandLine = CommandLine.parse(feedMe); > > > > > > > > > > > > > > System.out.println("[testing] ffmpeg about to > > > > > launch."); > > > > > > > executor.setStreamHandler(new > > > PumpStreamHandler(null, > > > > > > > null, input)); > > > > > > > executor.execute(commandLine, new > > > > > > > DefaultExecuteResultHandler()); > > > > > > > System.out.println("[testing] ffmpeg > started."); > > > > > > > > > > > > > > } catch (IOException e) { > > > > > > > e.printStackTrace(); > > > > > > > } > > > > > > > } > > > > > > > }} > > > > > > > > > > > > > > And the code for the second application (the zone where I send > > data > > > > to > > > > > > > the stdout) is the following one. > > > > > > > > > > > > > > static OutputStream stdout = System.out; > > > > > > > > > > > > > > (more code and other things around here) > > > > > > > > > > > > > > try { > > > > > > > line = (TargetDataLine) mixer.getLine(info); > > > > > > > line.open(format); > > > > > > > > > > > > > > int bytesRead, CHUNK_SIZE = 4096; > > > > > > > byte[] data = new byte[line.getBufferSize() / 5]; > > > > > > > > > > > > > > line.start(); > > > > > > > > > > > > > > while (true) { > > > > > > > bytesRead = line.read(data, 0, CHUNK_SIZE); > > > > > > > stdout.write(data, 0, bytesRead); > > > > > > > stdout.flush(); > > > > > > > } > > > > > > > > > > > > > > } catch (LineUnavailableException ex) { > > > > > > > System.out.println("Line is unavailable."); > > > > > > > ex.printStackTrace(); > > > > > > > } > > > > > > > > > > > > > > At the moment, no communication seems to be made between both > > > > commands > > > > > as > > > > > > > ffmpeg isn't receiving anything. > > > > > > > > > > > > > > Hope you guys can tell what I'm missing out, or if I'm > > incorrectly > > > > > > working > > > > > > > with the library thinking it works in a way when it works in > > > another > > > > > one. > > > > > > > > > > > > > > > > > > > > > > > > > > > > --001a114147c8db799805480d9524--