I'm trying to write an application using streamreader.dll to simply stream filtered transponder data over HTTP once a client requests that specific data. The client could be a Dreambox or OSEmu for example. Basically anything that will further process the data. After some not so great results in C++ I decided to use C# instead because I'm hoping the handling of client connections and threads plus the GUI will be somewhat easier.
streamreader.dll should work, right? And in part it does - i can tune in to a frequency and set filter, but the problem I'm having is with the callback function which is supposed to read the data. The problem is that I'm only getting one byte in the buffer, it's byte 0x47, which means it works in part, but where are the other 187 bytes? The len parameter clearly shows the streamingCB function got 188 bytes, yet the buffer contains just one. I'm stuck here and I have no idea if this is my c# coding error or incorrect use of the streamreader.dll.
Here's my code. And a screenshot of what I get is attached. Any help would be much appreciated. I think such application would be quite helpful, so far I don't think anything like this exists!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
namespace SimpleSatServer
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public class DVB_card
{
public DVB_card(string name, int id)
{
this.Name = name; this.Id = id;
}
public string Name
{ get; set; }
public int Id
{ get; set; }
}
public partial class MainWindow : Window
{
public static MainWindow GUI { get; private set; }
//
//public static extern void StreamingCB2(byte
public static extern bool StartDVBEx(Int32 index);
public static extern bool StopDVB();
public static extern bool CheckForDVB();
public static extern UInt32 GetCaps();
public delegate void DVBCallbackFunc(int index, String name);
public static extern bool CheckForDVBEx(DVBCallbackFunc func);
public static extern bool GetSignal(ulong Level, ulong Quality);
public static extern bool SetChannelEx(Int32 freq, Int32 symbrate, Int32 pol, Int32 fec, Int32 lof1, Int32 lof2, Int32 lofsw, Int32 mod);
public unsafe static extern bool GetSignalExEx(bool* pPresent, bool* pLock, int* pRFLevel, float* pSNR, float* pBER);
public unsafe delegate void StreamingCallbackFunc(byte
public unsafe static extern bool SetFilter(int pid, StreamingCallbackFunc lpFunc, Int32 CallBackType, Int32 size, Int32* lpfilter_num);
public MainWindow()
{
InitializeComponent();
log("Looking for DVB tuners... ");
CheckForDVBEx(InfoCB);
dvb_dev_list.SelectedIndex = 0;
}
public void InfoCB(int index, String name)
{
dvb_dev_list.Items.Add(new DVB_card(name, index));
log("Found DVB tuner " + name);
}
public void StreamingCB(byte[] buffer, int len)
{
log("BUFFER LEN: " + buffer.Length);
log("LEN: " + len.ToString());
log("BUFFER: " + BitConverter.ToString(buffer));
//System.IO.File.WriteAllBytes("file.ts", buffer);
}
public void log(string tolog)
{
try {
this.Dispatcher.Invoke(() =>
{
log_window.AppendText(DateTime.Now.ToString("H:mm:ss") + ": " + tolog + "\n");
log_window.ScrollToEnd();
});
}
catch
{
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
//public static extern void DisplayHelloFromDLL();
Int32 nr = dvb_dev_list.SelectedIndex;
if (!StartDVBEx(nr))
{
log(string.Format("StartDVBEx({0}) fail", nr));
dvb_dev_list.Background = Brushes.Red;
}
else
{
log(string.Format("StartDVBEx({0}) OK", nr));
dvb_dev_list.Background = Brushes.Green;
dvb_deb_stop.IsEnabled = true;
dvb_deb_start.IsEnabled = false;
dvb_dev_list.IsEnabled = false;
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (!StopDVB())
{
log(string.Format("StopDVB err"));
}
else
{
log(string.Format("StopDVB OK"));
dvb_dev_list.ClearValue(Button.BackgroundProperty);
dvb_dev_list.IsEnabled = true;
dvb_deb_start.IsEnabled = true;
dvb_deb_stop.IsEnabled = false;
sig_info_lock.ClearValue(Button.BackgroundProperty);
sig_info_snr.Content = "";
}
}
private unsafe void btn_signal_info_Click(object sender, RoutedEventArgs e)
{
sig_info_lock.ClearValue(Button.BackgroundProperty);
sig_info_snr.Content = "";
if (!SetChannelEx(11804000, 27500000, 1, 0, 97500000, 10600000, 11700000, 0))
{
log(string.Format("SetChannelEx err"));
}
bool pPresent;
bool pLock;
int pRFLevel;
float pSNR;
float pBER;
GetSignalExEx(&pPresent, &pLock, &pRFLevel, &pSNR, &pBER);
log("Signal Present: " + pPresent.ToString());
log("Signal Lock: " + pLock.ToString());
log("Signal SNR: " + pSNR.ToString());
log("Signal BER: " + pBER.ToString());
log("Signal RF: " + pRFLevel.ToString());
if (pLock)
{
sig_info_lock.Background = Brushes.Green;
sig_info_snr.Content = pSNR.ToString() + " dB";
}
int filter1;
StreamingCallbackFunc sh = StreamingCB;
if (!SetFilter(17, sh, 4, 1, &filter1))
{
log("Filter fail");
}
else
{
log("Filter set");
}
}
}
}
Category: Computer and USB Satellite Receivers and Recording