/// <summary> /// DVBViewer Plugin-Interface. /// </summary> static Plugin() { FileVersionInfo fvi = Globals.PluginInfo; _CopyrightString = Marshal.StringToHGlobalAnsi(fvi.LegalCopyright); _TypeString = Marshal.StringToHGlobalAnsi("Plugin"); _NameString = Marshal.StringToHGlobalAnsi(fvi.ProductName); _VersionString = Marshal.StringToHGlobalAnsi(Globals.Info); _DvbViewerHwnd = IntPtr.Zero; _CallbackData = new TTransCallData(); _Cb = new TransponderCallback(ProcessRawTs); _CallbackData.TransCall = Marshal.GetFunctionPointerForDelegate(_Cb); _NativeTsCallback = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TTransCallData))); Marshal.StructureToPtr(_CallbackData, _NativeTsCallback, false); // Adapter anlegen, macht auch direkt Verbindung zum Server auf try { _DvbAdapter = new DvbApiAdapter(Globals.PipeName, false); _DvbAdapter.AddPidRequested += AddPid; _DvbAdapter.DelPidRequested += DelPid; } catch (Exception ex) { LogProvider.Exception(cLogSection, Message.DvbvInitFailed, ex); } }
private static void AddPid(DvbApiAdapter sender, ushort pid) { if (_IsStopping) { return; } LogProvider.Add(DebugLevel.Info, cLogSection, Message.MdapiAddPid, pid); try { lock (_Filters) { int free = -1; int found = -1; for (int i = 0; i < _Filters.Length; i++) { if (_Filters[i] == null && free < 0) { free = i; } else if (_Filters[i] != null && _Filters[i].FilterPid == pid && found < 0) { found = i; } } if (found >= 0) { _Filters[found].Dispose(); _Filters[found] = new Filter.Context(_DvbAdapter, _DllName, _MdapiWindow, _188ByteSupport, _DllId, pid, (ushort)found); } else if (free >= 0) { _Filters[free] = new Filter.Context(_DvbAdapter, _DllName, _MdapiWindow, _188ByteSupport, _DllId, pid, (ushort)free); } else { LogProvider.Add(DebugLevel.Warning, cLogSection, Message.MdapiAddPidMaxFilter, pid); } } } catch (Exception ex) { LogProvider.Exception(cLogSection, Message.MdapiAddPidFailed, ex); } }
private static void DelPid(DvbApiAdapter sender, ushort pid) { LogProvider.Add(DebugLevel.Info, cLogSection, Message.MdapiDelPid, pid); lock (_Filters) { for (int i = 0; i < _Filters.Length; i++) { if (_Filters[i] != null && _Filters[i].FilterPid == pid) { LogProvider.Add(DebugLevel.Info, cLogSection, Message.MdapiStopFilter, i, pid); _Filters[i].Dispose(); _Filters[i] = null; return; } } LogProvider.Add(DebugLevel.Warning, cLogSection, Message.MdapiStopFilterFailed, pid); } }
/// <summary> /// Sendt per PostMessage Asynchron einen Request an den DVBViewer zwecks entfernen von PIDs im Pidfilter /// </summary> /// <param name="sender">DvbapiAdapter-Instanz von dem dieser Request ausgeht</param> /// <param name="pid">PID für den Filter</param> private static void DelPid(DvbApiAdapter sender, ushort pid) { PostMessage(_DvbViewerHwnd, (uint)WMessage.DvbViewer, new UIntPtr((uint)ParamMessages.StopFilter), new IntPtr(pid)); }
public Context(DvbApiAdapter adapter, byte[] dllName, IntPtr window, bool ts188Support, int dllId, ushort pid, ushort filterNum) { LogProvider.Add(DebugLevel.Info, cLogSection, Message.MdapiCtxStartFilter, pid, filterNum); _Disposed = false; _ContCounter = 0; _Cb = new FilterDataArrivalCallback(FilterDataArrival); _CbPtr = Marshal.GetFunctionPointerForDelegate(_Cb); _Adapter = adapter; _MdapiWindow = window; FilterPid = pid; FilterId = filterNum; switch (pid) { case 0x00: // PAT _FilterTables = new byte[] { 0x00 }; break; case 0x01: // CAT _FilterTables = new byte[] { 0x01 }; break; case 0x11: // SDT (nur actual) _FilterTables = new byte[] { 0x42 }; break; default: _FilterTables = new byte[] { 0x02, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f }; // PMT, ECM (0x80, 0x81) & EMM (0x82 - 0x8f) break; } _Section = new SectionBase(FilterPid, _FilterTables); // theoretisch könnte man über PMT-Pid feststellen, dass es PMT ist, dann über // die PMT selbst die einzelnen Table-IDs ermitteln um so noch sicherere Daten zu erhalten. _FilterStruct = new TStartFilter(); _FilterStruct.Name = new byte[32]; _FilterStruct.FilterId = filterNum; _FilterStruct.Pid = FilterPid; _FilterStruct.DllId = (ushort)dllId; _FilterStruct.FilterCallback = _CbPtr; Array.Copy(dllName, 0, _FilterStruct.Name, 0, Math.Min(dllName.Length, _FilterStruct.Name.Length)); _FilterStruct.Name[_FilterStruct.Name.Length - 1] = 0; if (ts188Support) { _FilterStruct.Pid |= 0x8000; // aktiviert im regulären MDAPI+ die 188byte // Nachfolgend für ProgDVB weitere Angaben _FilterStruct.Type = FilterType.Ts; _FilterStruct.ExtSize = 4; } _StructPtr = Marshal.AllocHGlobal(Marshal.SizeOf(_FilterStruct)); Marshal.StructureToPtr(_FilterStruct, _StructPtr, false); int res = (int)Plugin.SendMessage(_MdapiWindow, (uint)WMessage.User, (UIntPtr)MdApiMessages.StartFilter, _StructPtr); if (res == 0) { uint err = Plugin.GetLastError(); LogProvider.Add(DebugLevel.Warning, cLogSection, Message.MdapiCtxStartFilterFailed, err); } }
static Plugin() { try { LogProvider.Add(DebugLevel.Info, cLogSection, Message.MdapiInitStart); // Adapter anlegen, macht auch direkt Verbindung zum Server auf: _DvbAdapter = new DvbApiAdapter(Globals.PipeName, true); _188ByteSupport = false; _KeepAliveSupport = false; _Filters = new Filter.Context[64]; byte[] tmp = Encoding.UTF8.GetBytes(Globals.Info); _DllName = new byte[tmp.Length + 1]; // für terminierung Array.Copy(tmp, 0, _DllName, 0, tmp.Length); Process p = Process.GetCurrentProcess(); LogProvider.Add(DebugLevel.Info, cLogSection, Message.MdapiHost, p.ProcessName); if (p != null) { string pName = p.ProcessName.ToLowerInvariant(); // check auf progdvb, anders nicht möglich: if (pName.Contains("progdvb")) { _188ByteSupport = true; } else if (pName.Contains("mdapi")) { ProcessModule m = p.MainModule; if (m != null) { FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(m.FileName); Version v = new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart); Version min = new Version(0, 9, 0, 1615); LogProvider.Add(DebugLevel.Info, cLogSection, Message.MdapiHostVersion, v); if (v >= min) { _188ByteSupport = true; _KeepAliveSupport = true; } else { LogProvider.Add(DebugLevel.Info, cLogSection, Message.MdapiUse184); } } } else { LogProvider.Add(DebugLevel.Warning, cLogSection, Message.MdapiUnkownHost); } } _DvbAdapter.AddPidRequested += AddPid; _DvbAdapter.DelPidRequested += DelPid; _DvbAdapter.GotControlWord += SetDcw; // es wird nicht selbst entschlüsselt. _IsStopping = false; LogProvider.Add(DebugLevel.Info, cLogSection, Message.MdapiInitDone); } catch (Exception ex) { LogProvider.Exception(cLogSection, Message.MdapiInitFailed, ex); } }