private bool findSPSandPPS() { /* * SPS and PPS parameters are stored in the avcC box * You may find really useful information about this box * in the document ISO-IEC 14496-15, part 5.2.4.1.1 * The box's structure is described there * <pre> * aligned(8) class AVCDecoderConfigurationRecord { * unsigned int(8) configurationVersion = 1; * unsigned int(8) AVCProfileIndication; * unsigned int(8) profile_compatibility; * unsigned int(8) AVCLevelIndication; * bit(6) reserved = ‘111111’b; * unsigned int(2) lengthSizeMinusOne; * bit(3) reserved = ‘111’b; * unsigned int(5) numOfSequenceParameterSets; * for (i=0; i< numOfSequenceParameterSets; i++) { * unsigned int(16) sequenceParameterSetLength ; * bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit; * } * unsigned int(8) numOfPictureParameterSets; * for (i=0; i< numOfPictureParameterSets; i++) { * unsigned int(16) pictureParameterSetLength; * bit(8*pictureParameterSetLength) pictureParameterSetNALUnit; * } * } * </pre> */ try { // TODO: Here we assume that numOfSequenceParameterSets = 1, numOfPictureParameterSets = 1 ! // Here we extract the SPS parameter fis.SkipBytes(7); spsLength = 0xFF & fis.ReadByte(); sps = new byte[spsLength]; fis.Read(sps, 0, spsLength); // Here we extract the PPS parameter fis.SkipBytes(2); ppsLength = 0xFF & fis.ReadByte(); pps = new byte[ppsLength]; fis.Read(pps, 0, ppsLength); } catch (IOException e) { return(false); } return(true); }
public void WriteByteTest() { string filePath = "WriteByteTest.arr"; RandomAccessFile target = InitRAF(filePath); byte b = 7; target.WriteByte(b); target.Seek(0); byte actual = target.ReadByte(); Assert.AreEqual(b, actual); target.Close(); }
public void ReadByteTest() { string filePath = "RAFReadByteTest.arr"; RandomAccessFile target = InitRAF(filePath); byte expected = 88; target.WriteByte(expected); target.Seek(0); byte actual = target.ReadByte(); Assert.AreEqual(expected, actual); target.Close(); }
/** * Records a short sample of AAC ADTS from the microphone to find out what the sampling rate really is * On some phone indeed, no error will be reported if the sampling rate used differs from the * one selected with setAudioSamplingRate * @throws IOException * @throws IllegalStateException */ private void testADTS() { setAudioEncoder((int)Android.Media.AudioEncoder.Aac); try { Type mType = typeof(MediaRecorder.OutputFormat); if (mType.GetField("AAC_ADTS") == null) { return; } setOutputFormat((int)Android.Media.AudioEncoder.Aac); } catch (System.Exception ignore) { setOutputFormat(6); } System.String key = PREF_PREFIX + "aac-" + mQuality.samplingRate; if (mSettings != null && mSettings.Contains(key)) { System.String[] s = mSettings.GetString(key, "").Split(','); mQuality.samplingRate = (int)Integer.ValueOf(s[0]); mConfig = (int)Integer.ValueOf(s[1]); mChannel = (int)Integer.ValueOf(s[2]); return; } System.String TESTFILE = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/spydroid-test.adts"; if (!Android.OS.Environment.ExternalStorageState.Equals(Android.OS.Environment.MediaMounted)) { throw new IllegalStateException("No external storage or external storage not ready !"); } // The structure of an ADTS packet is described here: http://wiki.multimedia.cx/index.php?title=ADTS // ADTS header is 7 or 9 bytes long byte[] buffer = new byte[9]; mMediaRecorder = new MediaRecorder(); mMediaRecorder.SetAudioSource((AudioSource)mAudioSource); mMediaRecorder.SetOutputFormat((OutputFormat)mOutputFormat); mMediaRecorder.SetAudioEncoder((AudioEncoder)mAudioEncoder); mMediaRecorder.SetAudioChannels(1); 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(2000); } catch (InterruptedException e) { } mMediaRecorder.Stop(); mMediaRecorder.Release(); mMediaRecorder = null; File file = new File(TESTFILE); RandomAccessFile raf = new RandomAccessFile(file, "r"); // ADTS packets start with a sync word: 12bits set to 1 while (true) { if ((raf.ReadByte() & 0xFF) == 0xFF) { buffer[0] = (byte)raf.ReadByte(); if ((buffer[0] & 0xF0) == 0xF0) { break; } } } raf.Read(buffer, 1, 5); mSamplingRateIndex = (buffer[1] & 0x3C) >> 2; mProfile = ((buffer[1] & 0xC0) >> 6) + 1; mChannel = (buffer[1] & 0x01) << 2 | (buffer[2] & 0xC0) >> 6; mQuality.samplingRate = AUDIO_SAMPLING_RATES[mSamplingRateIndex]; // 5 bits for the object type / 4 bits for the sampling rate / 4 bits for the channel / padding mConfig = (mProfile & 0x1F) << 11 | (mSamplingRateIndex & 0x0F) << 7 | (mChannel & 0x0F) << 3; Log.Info(TAG, "MPEG VERSION: " + ((buffer[0] & 0x08) >> 3)); Log.Info(TAG, "PROTECTION: " + (buffer[0] & 0x01)); Log.Info(TAG, "PROFILE: " + AUDIO_OBJECT_TYPES[mProfile]); Log.Info(TAG, "SAMPLING FREQUENCY: " + mQuality.samplingRate); Log.Info(TAG, "CHANNEL: " + mChannel); raf.Close(); if (mSettings != null) { ISharedPreferencesEditor editor = mSettings.Edit(); editor.PutString(key, mQuality.samplingRate + "," + mConfig + "," + mChannel); editor.Commit(); } if (!file.Delete()) { Log.Error(TAG, "Temp file could not be erased"); } }
public static string GetCh(int entry, string charType) { try { byte[] dict = GetDictPart(entry); if (charType.Equals("original")) { int i = entries.Get(entry); while (dict[i++] < 0) { ; } //return StringHelperClass.NewString(dict, entries.Get(entry), i - entries.Get(entry) - 1, "UTF-8"); return(Encoding.UTF8.GetString(dict, entries.Get(entry), i - entries.Get(entry) - 1)); } else if (charType.Equals("simplified")) { int i = entries.Get(entry); while (dict[i] < 0) { i++; } if (dict[i++] == 0) { int index = 0, mult = 1; while (i < dict.Length && dict[i] >= 0) { index += mult * dict[i++]; mult *= 128; } i = entries.Get(index); dict = GetDictPart(index); while (dict[i++] < 0) { ; } //return StringHelperClass.NewString(dict, entries.Get(index), i - entries.Get(index) - 1, "UTF-8"); return(Encoding.UTF8.GetString(dict, entries.Get(index), i - entries.Get(index) - 1)); } //return StringHelperClass.NewString(dict, entries.Get(entry), i - entries.Get(entry) - 1, "UTF-8"); return(Encoding.UTF8.GetString(dict, entries.Get(entry), i - entries.Get(entry) - 1)); } else if (charType.Equals("traditional")) { int i = entries.Get(entry); while (dict[i] < 0) { i++; } if (dict[i++] == 0) { //return StringHelperClass.NewString(dict, entries.Get(entry), i - entries.Get(entry), "UTF-8"); return(Encoding.UTF8.GetString(dict, entries.Get(entry), i - entries.Get(entry))); } else { while (dict[i++] != 0) { ; } int index = 0, mult = 1; while (i < dict.Length && dict[i] >= 0) { index += mult * dict[i++]; mult *= 128; } try { dictFile.Seek(index); sbyte ch; int j = 0; while ((ch = dictFile.ReadByte()) < 0) { byteBuffer[j++] = (byte)ch; } //return StringHelperClass.NewString(byteBuffer, 0, j, "UTF-8"); return(Encoding.UTF8.GetString(byteBuffer, 0, j)); } catch (Exception e) { System.Console.WriteLine("Dict GetCh ERROR => " + e.Message); } } } return(""); } catch (Exception e) { System.Console.WriteLine("Dict GetCh ERROR => " + e.Message); return(""); } }