private void TestMisc() { long l; m_Writer.GetWriterTime(out l); Debug.Assert(l == 0); }
/// <summary> /// Write a script command into the stream /// </summary> /// <param name="type"></param> /// <param name="script"></param> /// <param name="packScript">Use both bytes of the unicode script string. This is /// used to more efficiently transmit Base64 encoded data in a script.</param> /// <returns></returns> /// The writer expects two null terminated WCHARs (two bytes per character). public bool SendScript(String type, String script, bool packScript) { IntPtr typePtr, scriptPtr, bufPtr; byte[] sampleBuf; INSSBuffer sample; ulong curTime; uint typesz, scriptsz, nulls; //ScriptStreamNumber == 0 means there is no script stream in the profile. if (scriptStreamNumber == 0) { return(false); } if (packScript) { typesz = (uint)(2 * (type.Length + 1)); //To make the script looks like unicode, need to terminate with two nulls, and //the total length needs to be an even number. scriptsz = (uint)script.Length; if (scriptsz % 2 == 0) { nulls = 2; } else { nulls = 3; } sampleBuf = new byte[typesz + scriptsz + nulls]; typePtr = Marshal.StringToCoTaskMemUni(type); scriptPtr = Marshal.StringToCoTaskMemAnsi(script); Marshal.Copy(typePtr, sampleBuf, 0, (int)typesz); Marshal.Copy(scriptPtr, sampleBuf, (int)typesz, (int)scriptsz); for (uint i = typesz + scriptsz + nulls - 1; i >= typesz + scriptsz; i--) { sampleBuf[i] = 0; } scriptsz += nulls; Marshal.FreeCoTaskMem(typePtr); Marshal.FreeCoTaskMem(scriptPtr); } else { //Marshal both strings as unicode. typesz = (uint)(2 * (type.Length + 1)); scriptsz = (uint)(2 * (script.Length + 1)); sampleBuf = new byte[typesz + scriptsz]; typePtr = Marshal.StringToCoTaskMemUni(type); scriptPtr = Marshal.StringToCoTaskMemUni(script); Marshal.Copy(typePtr, sampleBuf, 0, (int)typesz); Marshal.Copy(scriptPtr, sampleBuf, (int)typesz, (int)scriptsz); Marshal.FreeCoTaskMem(typePtr); Marshal.FreeCoTaskMem(scriptPtr); } try { lock (this) { writer.AllocateSample((typesz + scriptsz), out sample); sample.GetBuffer(out bufPtr); Marshal.Copy(sampleBuf, 0, bufPtr, (int)(typesz + scriptsz)); // Let the writer tell us what time it wants to use to avoid // rebuffering and other nastiness. Can this cause a loss of sync issue? writerAdvanced.GetWriterTime(out curTime); //writerAdvanced.WriteStreamSample(scriptStreamNumber,curTime,0,0,0,sample); if (lastWriteTime == 0) { lastWriteTime = curTime; } //Write to one second later than last AV write. This seems to give good sync?? writerAdvanced.WriteStreamSample(scriptStreamNumber, lastWriteTime + 10000000, 0, 0, 0, sample); Marshal.ReleaseComObject(sample); } } catch (Exception e) { eventLog.WriteEntry("Failed to write script: " + e.ToString(), EventLogEntryType.Error, 1000); Debug.WriteLine("Failed to write script: " + e.ToString()); return(false); } return(true); }