public async Task <List <ChannelInfo> > Scan(TunerHostInfo info, CancellationToken cancellationToken)
        {
            var ini      = info.SourceA.Split('|')[1];
            var resource = GetType().Assembly.GetManifestResourceNames().FirstOrDefault(i => i.EndsWith(ini, StringComparison.OrdinalIgnoreCase));

            _logger.Info("Opening ini file {0}", resource);
            var list = new List <ChannelInfo>();

            using (var stream = GetType().Assembly.GetManifestResourceStream(resource))
            {
                using (var reader = new StreamReader(stream))
                {
                    var parser = new StreamIniDataParser();
                    var data   = parser.ReadData(reader);

                    var count = GetInt(data, "DVB", "0", 0);

                    _logger.Info("DVB Count: {0}", count);

                    var index  = 1;
                    var source = "1";

                    while (index <= count)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        using (var rtspSession = new RtspSession(info.Url, _logger))
                        {
                            float percent = count == 0 ? 0 : (float)(index) / count;
                            percent = Math.Max(percent * 100, 100);

                            //SetControlPropertyThreadSafe(pgbSearchResult, "Value", (int)percent);
                            var strArray = data["DVB"][index.ToString(CultureInfo.InvariantCulture)].Split(',');

                            string tuning;
                            if (strArray[4] == "S2")
                            {
                                tuning = string.Format("src={0}&freq={1}&pol={2}&sr={3}&fec={4}&msys=dvbs2&mtype={5}&plts=on&ro=0.35&pids=0,16,17,18,20", source, strArray[0], strArray[1].ToLower(), strArray[2].ToLower(), strArray[3], strArray[5].ToLower());
                            }
                            else
                            {
                                tuning = string.Format("src={0}&freq={1}&pol={2}&sr={3}&fec={4}&msys=dvbs&mtype={5}&pids=0,16,17,18,20", source, strArray[0], strArray[1].ToLower(), strArray[2], strArray[3], strArray[5].ToLower());
                            }

                            rtspSession.Setup(tuning, "unicast");

                            rtspSession.Play(string.Empty);

                            int signallevel;
                            int signalQuality;
                            rtspSession.Describe(out signallevel, out signalQuality);

                            await Task.Delay(500).ConfigureAwait(false);

                            index++;
                        }
                    }
                }
            }

            return(list);
        }
Exemplo n.º 2
0
        static void test3()
        {
            IvrWORX x = new IvrWORX();

            x.Init("dotnet.json");

            //
            // Allocate RTP endpoint for RTSP session.
            //
            RtpProxySession rtspRtpSession = new RtpProxySession(x);
            AbstractOffer   dummyOffer     = new AbstractOffer();

            dummyOffer.Type = "application/sdp";
            dummyOffer.Body = @"v=0" + "\n"
                              + "o=alice 2890844526 2890844526 IN IP4 0.0.0.0" + "\n"
                              + "s=" + "\n"
                              + "c=IN IP4 0.0.0.0" + "\n"
                              + "t=0 0" + "\n"
                              + "m=audio 0 RTP/AVP 8" + "\n"
                              + "a=rtpmap:0 PCMA/8000" + "\n\n";;

            ApiErrorCode res = rtspRtpSession.Allocate(dummyOffer);

            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtpProxySession(1) Allocated failed err:" + res);
            }


            //
            // Set up RTSP session and update its RTP endpoint.
            //
            RtspSession rtsp = new RtspSession(x);

            res = rtsp.Setup("rtsp://10.116.100.78/IvrScript.wav", rtspRtpSession.LocalOffer());
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtspSession Setup failed err:" + res);
            }

            res = rtspRtpSession.Modify(rtsp.RemoteOffer());
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtspSession Modify failed err:" + res);
            }


            //
            // Allocate sip RTP session
            //
            RtpProxySession sipRtpSession = new RtpProxySession(x);

            res = sipRtpSession.Allocate(dummyOffer);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtpProxySession(1) Allocated failed err:" + res);
            }


            //
            // Make call
            //
            SipCall sipCall = new SipCall(x);

            res = sipCall.MakeCall("sip:[email protected]", sipRtpSession.LocalOffer(), null, null, DEFAULT_TIMEOUT);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("MakeCall failed err:" + res);
            }

            sipRtpSession.Modify(sipCall.RemoteOffer());
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Modify failed err:" + res);
            }

            rtspRtpSession.Bridge(sipRtpSession, false);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("Bridge failed err:" + res);
            }



            res = rtsp.Play(0.0, 0.0, 1);
            if (res != ApiErrorCode.API_SUCCESS)
            {
                throw new Exception("RtpProxySession(1) Allocated failed err:" + res);
            }

            Thread.Sleep(10000);


            sipCall.Dispose();

            Console.WriteLine("MakeCall res=" + res);
        }