示例#1
0
    private void run()
    {
        Debug.Log("Begin send Data");
        isInSendThread = true;
        if (!File.Exists(localPath))
        {
            Debug.Log(localPath + " not exists");
            goto end;
        }
        FileStream file = new FileStream(localPath, FileMode.Open);

        byte[] readBuff = new byte[readBuffSize];
        int    count    = 0;

        while (!applicationIsQuit && isInSendThread && player != null)
        {
            int ret = 0;
            try
            {
                ret = file.Read(readBuff, 0, readBuffSize);
                if (ret <= 0)
                {
                    throw new System.Exception("读取到结尾");
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogWarning(ex);
                goto end;
            }

            count += ret;
            //处理数据
            while (!applicationIsQuit && isInSendThread && player != null)
            {
                mutex.WaitOne();
                if (player == null)
                {
                    mutex.ReleaseMutex();
                    goto end;
                }
                if (player.PushStream2Cache(readBuff, ret))
                {
                    mutex.ReleaseMutex();
                    break;
                }
                mutex.ReleaseMutex();
                Thread.Sleep(1);
                continue;
            }
            Thread.Sleep(1);
        }
        file.Dispose();
        file.Close();

end:
        Debug.Log("Stop send data");
        isInSendThread = false;
    }
    private void run()
    {
        Debug.Log("Begin send Data");

        if (!File.Exists(localPath))
        {
            Debug.Log(localPath + " not exists");
            return;
        }
        FileStream file = new FileStream(localPath, FileMode.Open);

        byte[] readBuff = new byte[readBuffSize];
        int    count    = 0;

        while (!isExit && isSending)
        {
            int ret = 0;
            try
            {
                ret = file.Read(readBuff, 0, readBuffSize);
            }
            catch (System.Exception ex)
            {
                Debug.LogWarning(ex);
                return;
            }
            if (ret <= 0)
            {
                break;
            }
            count += ret;
            //处理数据
            while (!isExit && isSending)
            {
                if (player == null)
                {
                    break;
                }
                if (player.PushStream2Cache(readBuff, ret))
                {
                    break;
                }

                Thread.Sleep(1);
                continue;
            }
            Thread.Sleep(1);
        }
        file.Dispose();
        file.Close();
        Debug.Log("Stop send data");
    }
示例#3
0
    private void HandleDataCacheList()
    {
        if (dataCache.Count <= 0)
        {
            return;
        }
        if (isNeedDecodeHead)
        {
            lock (dataCache)
            {
                //64个字节为设备名称,2个字节为宽,2个字节为高
                if (dataCache.Count < 68)
                {
                    return;
                }
                isNeedDecodeHead = false;
                byte[] ba         = dataCache.ToArray();
                string devicename = System.Text.Encoding.Default.GetString(ba, 0, 64);
                Debug.Log("device name:" + devicename);
                Debug.Log("width:" + BitConverter.ToUInt16(new byte[2] {
                    ba[65], ba[64]
                }, 0));
                Debug.Log("height:" + BitConverter.ToInt16(new byte[2] {
                    ba[67], ba[66]
                }, 0));
                dataCache.RemoveRange(0, 64);
                player.TryBitStreamDemux();
                //做清理标记
                ClearDevices();
            }
        }

        lock (dataCache)
        {
            byte[] arr  = dataCache.ToArray();
            int    size = Mathf.Min(player.GetCacheFreeSize(), arr.Length);
            if (player.PushStream2Cache(arr, size))
            {
                dataCache.RemoveRange(0, size);
            }
        }
    }