diff --git a/src/net/majorkernelpanic/streaming/audio/AACStream.java b/src/net/majorkernelpanic/streaming/audio/AACStream.java index 9d829c1..878f2ed 100644 --- a/src/net/majorkernelpanic/streaming/audio/AACStream.java +++ b/src/net/majorkernelpanic/streaming/audio/AACStream.java @@ -92,12 +92,16 @@ public AACStream() throws IOException { if (!AACStreamingSupported()) { Log.e(TAG,"AAC not supported on this phone"); throw new AACNotSupportedException(); + } else { + Log.d(TAG,"AAC supported on this phone"); } - if (mMode == MODE_MEDIARECORDER_API) + if (mMode == MODE_MEDIARECORDER_API) { + mQuality = new AudioQuality(16000,32000); mPacketizer = new AACADTSPacketizer(); - else + } else { mPacketizer = new AACLATMPacketizer(); + } } @@ -125,16 +129,9 @@ public void start() throws IllegalStateException, IOException { } @Override - @SuppressLint("InlinedApi") protected void encodeWithMediaRecorder() throws IOException { testADTS(); ((AACADTSPacketizer)mPacketizer).setSamplingRate(mActualSamplingRate); - setAudioEncoder(MediaRecorder.AudioEncoder.AAC); - try { - Field name = MediaRecorder.OutputFormat.class.getField("AAC_ADTS"); - setOutputFormat(name.getInt(null)); - } - catch (Exception ignore) {} super.encodeWithMediaRecorder(); } @@ -274,8 +271,31 @@ public String generateSessionDescription() throws IllegalStateException, IOExcep * @throws IOException * @throws IllegalStateException */ + @SuppressLint("InlinedApi") private void testADTS() throws IllegalStateException, IOException { + setAudioEncoder(MediaRecorder.AudioEncoder.AAC); + try { + Field name = MediaRecorder.OutputFormat.class.getField("AAC_ADTS"); + setOutputFormat(name.getInt(null)); + } + catch (Exception ignore) { + setOutputFormat(6); + } + + // Checks if the user has supplied an exotic sampling rate + int i=0; + for (;i12) { + Log.e(TAG,"Not a valid sampling rate: "+mQuality.samplingRate); + mQuality.samplingRate = 24000; + } + if (mSettings!=null) { if (mSettings.contains("aac-"+mQuality.samplingRate)) { String[] s = mSettings.getString("aac-"+mQuality.samplingRate, "").split(","); @@ -305,13 +325,14 @@ private void testADTS() throws IllegalStateException, IOException { mMediaRecorder.setAudioSamplingRate(mQuality.samplingRate); mMediaRecorder.setAudioEncodingBitRate(mQuality.bitRate); mMediaRecorder.setOutputFile(TESTFILE); + mMediaRecorder.setMaxDuration(1000); mMediaRecorder.prepare(); mMediaRecorder.start(); // We record for 1 sec // TODO: use the MediaRecorder.OnInfoListener try { - Thread.sleep(1000); + Thread.sleep(2000); } catch (InterruptedException e) {} mMediaRecorder.stop(); @@ -331,7 +352,7 @@ private void testADTS() throws IllegalStateException, IOException { raf.read(buffer,1,5); - mSamplingRateIndex = (buffer[1]&0x3C) >> 2; + mSamplingRateIndex = (buffer[1]&0x3C)>>2 ; mProfile = ( (buffer[1]&0xC0) >> 6 ) + 1 ; mChannel = (buffer[1]&0x01) << 2 | (buffer[2]&0xC0) >> 6 ; mActualSamplingRate = AUDIO_SAMPLING_RATES[mSamplingRateIndex]; diff --git a/src/net/majorkernelpanic/streaming/rtp/H264Packetizer.java b/src/net/majorkernelpanic/streaming/rtp/H264Packetizer.java index 908ca31..88f0fce 100644 --- a/src/net/majorkernelpanic/streaming/rtp/H264Packetizer.java +++ b/src/net/majorkernelpanic/streaming/rtp/H264Packetizer.java @@ -45,7 +45,9 @@ public class H264Packetizer extends AbstractPacketizer implements Runnable { private long delay = 0, oldtime = 0; private Statistics stats = new Statistics(); private byte[] sps = null, pps = null; - + private int count = 0; + + public H264Packetizer() throws IOException { super(); socket.setClockFrequency(90000); @@ -77,6 +79,8 @@ public void run() { long duration = 0, delta2 = 0; Log.d(TAG,"H264 packetizer started !"); stats.reset(); + count = 0; + // This will skip the MPEG4 header if this step fails we can't stream anything :( try { byte buffer[] = new byte[4]; @@ -163,8 +167,13 @@ private void send() throws IOException, InterruptedException { // The stream already contains NAL unit type 7 or 8, we don't need // to add them to the stream ourselves - if (type == 7) sps = null; - if (type == 8) pps = null; + if (type == 7 || type == 8) { + count++; + if (count>4) { + sps = null; + pps = null; + } + } // Updates the timestamp ts += delay; diff --git a/src/net/majorkernelpanic/streaming/rtp/RtpSocket.java b/src/net/majorkernelpanic/streaming/rtp/RtpSocket.java index c5174da..032e0f5 100644 --- a/src/net/majorkernelpanic/streaming/rtp/RtpSocket.java +++ b/src/net/majorkernelpanic/streaming/rtp/RtpSocket.java @@ -227,7 +227,7 @@ public void run() { if ((mTimestamps[mBufferOut]-mOldTimestamp)>0) { stats.push(mTimestamps[mBufferOut]-mOldTimestamp); long d = stats.average()/1000000; - Log.d(TAG,"delay: "+d+" d: "+(mTimestamps[mBufferOut]-mOldTimestamp)/1000000); + //Log.d(TAG,"delay: "+d+" d: "+(mTimestamps[mBufferOut]-mOldTimestamp)/1000000); // We ensure that packets are sent at a constant and suitable rate no matter how the RtpSocket is used. Thread.sleep(d); } diff --git a/src/net/majorkernelpanic/streaming/video/VideoStream.java b/src/net/majorkernelpanic/streaming/video/VideoStream.java index 9f8acd5..ac5b5a5 100644 --- a/src/net/majorkernelpanic/streaming/video/VideoStream.java +++ b/src/net/majorkernelpanic/streaming/video/VideoStream.java @@ -76,7 +76,6 @@ public VideoStream(int camera) { setCamera(camera); // TODO: Remove this when encoding with the MediaCodec API is ready setMode(MODE_MEDIARECORDER_API); - Log.e(TAG,"MODE: "+mMode); } /**