I think they are using MediaRecorder. Perhaps the main problem is that it is difficult to write data from it to something other than a file in local storage. To work with it, you can create a channel. Then use its file descriptor as input fd for MediaRecorder. Then the pipe output can be controlled by some stream that will read audio packets (in one format, aac or .. wav even), and then do whatever you want with the data.
Here is the code. Note that this proto may not even compile, just to give you an idea.
private final static int SOCKET_BUF_SIZE = 2 * 1024 * 1000; private void openSockets() throws IOException { receiver = new LocalSocket(); receiver.connect(new LocalSocketAddress("com.companyname.media-" + socketId)); receiver.setReceiveBufferSize(SOCKET_BUF_SIZE); sender = lss.accept(); sender.setSendBufferSize(SOCKET_BUF_SIZE); } private void closeSockets() { try { if (sender != null) { sender.close(); sender = null; } if (receiver != null) { receiver.close(); receiver = null; } } catch (Exception ignore) { } } public void prepare() throws IllegalStateException, IOException { int samplingRate; openSockets(); if (mode == MODE_TESTING) { samplingRate = requestedSamplingRate; } else { samplingRate = actualSamplingRate; } mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); try { Field name = MediaRecorder.OutputFormat.class.getField("AAC_ADTS"); if (BuildConfig.DEBUG) Log.d(StreamingApp.TAG, "AAC ADTS seems to be supported: AAC_ADTS=" + name.getInt(null)); mediaRecorder.setOutputFormat(name.getInt(null)); } catch (Exception e) { throw new IOException("AAC is not supported."); } try { mediaRecorder.setMaxDuration(-1); mediaRecorder.setMaxFileSize(Integer.MAX_VALUE); } catch (RuntimeException e) { Log.e(StreamingApp.TAG, "setMaxDuration or setMaxFileSize failed!"); } mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); mediaRecorder.setAudioChannels(1); mediaRecorder.setAudioSamplingRate(samplingRate); mediaRecorder.setOutputFile(sender.getFileDescriptor()); startListenThread(receiver.getInputStream()); mediaRecorder.start(); }
source share