Ejemplo n.º 1
0
        public BitmapStream askBitmapStream(int streamCount)
        {
            video_stream_fractions = new List <byte[]>(NUM_FRACTION);
            video         = new List <int>(NUM_FRACTION);
            video_writing = new List <int>(NUM_FRACTION);
            for (int i = 0; i < NUM_FRACTION; i++)
            {
                video_stream_fractions.Add(new byte[0]);
                video.Add(0);
                video_writing.Add(0);
            }
            video_stream = new CompressedBitmapStream();

            //“有这个视频”名单空的,返回null
            if (video_client.Count == 0)
            {
                return(null);
            }

            //给所有名单里的人发请求
            Connector conn = find_conn(conn_video_header, video_client[streamCount % video_client.Count]);
            Package   pack = new Package("request_video");

            pack.header.Add("" + streamCount);
            conn.send(pack);

            while (true)
            {
                //等待回复
                //如果某个线程知道有回复了,就把video改成1,然后读data写到video_stream(buffer)里面
                int tag = 1;
                for (int i = 0; i < NUM_FRACTION; i++)
                {
                    if (video[i] == 0)
                    {
                        tag = 0;
                        break;
                    }
                }
                if (tag == 1)
                {
                    MemoryStream    stream    = new MemoryStream();
                    BinaryFormatter formatter = new BinaryFormatter();
                    for (int i = 0; i < NUM_FRACTION; i++)
                    {
                        stream.Write(video_stream_fractions[i], 0, video_stream_fractions[i].Length);
                    }
                    stream.Position = 0;

                    //解压缩一下。。。

                    /*byte[] data = stream.ToArray();
                     * stream = new MemoryStream();
                     * GZipStream decomp = new GZipStream(stream,CompressionMode.Decompress);
                     * decomp.Read(data, 0, data.Length);
                     */

                    video_stream = (CompressedBitmapStream)formatter.Deserialize(stream);
                    return(video_stream.toBitmapStream());
                }
            }
        }