Ejemplo n.º 1
0
        protected void writer()
        {
            while (true)
            {
                logger.a("awaiting pcm");
                while (!pimp.qt(enc.ext) && stdinQueue.IsEmpty)
                {
                    System.Threading.Thread.Sleep(10);
                }

                if (pimp.qt(enc.ext) || crashed || aborted)
                {
                    break;
                }

                byte[] buf;
                if (!stdinQueue.TryDequeue(out buf))
                {
                    logger.a("Queue not empty but dequeue failed");
                    throw new Exception("nani the f**k");
                }

                logger.a("putting pcm " + buf.Length);
                try
                {
                    stdin.Write(buf, 0, buf.Length);
                }
                catch
                {
                    logger.a("encoder write failed");
                    enc.FIXME_kbps = -1;
                    crashed        = true;
                }
            }
        }
Ejemplo n.º 2
0
        protected void reader()
        {
            logger.a("reader thread");
            System.IO.FileStream m = null;
            enc.i.begin    = DateTime.UtcNow;
            enc.i.filename = "Loopstream-" +
                             enc.i.begin.ToString("yyyy-MM-dd_HH.mm.ss.") +
                             enc.ext;

            if (dump)
            {
                m = new System.IO.FileStream(
                    enc.i.filename,
                    System.IO.FileMode.Create);
            }
            long bufSize = settings.samplerate * 10;

            byte[] buffer = new byte[bufSize * 4];
            try
            {
                while (true)
                {
                    if (pimp.qt())
                    {
                        break;
                    }
                    //Console.Write('!');
                    logger.a("awaiting encoder output");
                    int i = stdout.Read(buffer, 0, 4096);
                    if (m != null)
                    {
                        logger.a("writing file");
                        m.Write(buffer, 0, i);
                    }
                    try
                    {
                        logger.a("writing socket");

                        if (!string.IsNullOrEmpty(settings.host))
                        {
                            s.Write(buffer, 0, i);
                        }
                    }
                    catch
                    {
                        logger.a("socket write failed");
                        enc.FIXME_kbps = -1;
                        crashed        = true;
                        break;
                    }

                    // speed measuring
                    logger.a("speed measure");
                    lock (locker)
                    {
                        chunks[stampee] = i;
                        stamps[stampee] = DateTime.UtcNow.Ticks / 10000;
                        stampee         = ++stampee < stamps.Length ? stampee : 0;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.a("encoder readloop crash");
                //Program.ni.ShowBalloonTip("an encoder reading thread just crashed\r\n\r\nthought you might want to know");
            }
            string fn = proc.StartInfo.FileName;

            fn = fn.Substring(fn.Replace('\\', '/').LastIndexOf('/') + 1).Split('.')[0];
            Console.WriteLine("shutting down " + fn);
            if (m != null)
            {
                m.Close();
            }
            logger.a("mp3data readloop closed");
        }