Esempio n. 1
0
 public void InBackground()
 {
     if (!this.loaded && this.instream != null)
     {
         this.LoadVideo();
     }
     if (!this.control_.Ready)
     {
         return;
     }
     if (!this.control_.Play)
     {
         return;
     }
     if (this.rnd_frame != this.rdy_frame)
     {
         if (this.cur_frame == this.rdy_frame)
         {
             if (!this.skip)
             {
                 Color32[] array = this.colors_y_rnd;
                 this.colors_y_rnd = this.colors_y;
                 this.colors_y     = array;
             }
             this.rdy_frame = this.rnd_frame;
             this.skip      = true;
         }
         return;
     }
     while (this.theora_p != 0 && this.videobuf_ready == 0)
     {
         if (Xiph.ogg_stream_packetout(this.to, this.op) <= 0)
         {
             break;
         }
         if (Xiph.th_decode_packetin(this.td, this.op, ref this.videobuf_granulepos) >= 0)
         {
             this.videobuf_time  = Xiph.th_granule_time(this.td.state, this.videobuf_granulepos);
             this.videobuf_ready = 1;
         }
     }
     if (this.videobuf_ready == 0 && this.instream.Length == this.instream_pos)
     {
         if (this.control_.Loop)
         {
             this.control_.PlaySession += 1u;
             this.LoadVideo();
         }
         else
         {
             this.control_.Playing = false;
         }
         return;
     }
     if (this.videobuf_ready == 0)
     {
         this.buffer_data(this.instream, this.oy);
         while (Xiph.ogg_sync_pageout(this.oy, this.og) > 0)
         {
             this.queue_page(this.og);
         }
     }
     else
     {
         this.rnd_frame++;
         if (this.cur_frame == this.rdy_frame)
         {
             if (!this.skip)
             {
                 Color32[] array2 = this.colors_y_rnd;
                 this.colors_y_rnd = this.colors_y;
                 this.colors_y     = array2;
             }
             this.rdy_frame = this.rnd_frame;
             this.skip      = true;
         }
     }
     this.videobuf_ready = 0;
 }
Esempio n. 2
0
 public void InBackground()
 {
     if (this.instream == null)
     {
         return;
     }
     if (this.playSession != this.control_.PlaySession)
     {
         this.playSession  = this.control_.PlaySession;
         this.Pcm          = null;
         this.control_.Pcm = this.Pcm;
         this.loaded       = false;
     }
     if (!this.loaded)
     {
         this.control_.AudioAvailable = this.LoadAudio();
         this.loaded = true;
         return;
     }
     if (!this.control_.AudioAvailable)
     {
         return;
     }
     if (!this.control_.Ready)
     {
         return;
     }
     if (!this.control_.Playing)
     {
         return;
     }
     while (!this.eos && this.vorbis_p && this.need_more_data && this.need_next_pcm)
     {
         int num = this.buffer_data(this.instream, this.oy);
         if (num <= 0)
         {
             this.need_next_pcm  = false;
             this.need_more_data = false;
             this.eos            = true;
             break;
         }
         int num2 = Xiph.ogg_sync_pageout(this.oy, this.og);
         if (num2 != 0)
         {
             if (num2 < 0)
             {
                 this.error = "Corrupt or missing data in bitstream; continuing...\n";
                 break;
             }
             this.need_more_data = false;
         }
     }
     if (!this.eos && this.vorbis_p && !this.need_more_data && this.need_next_pcm)
     {
         this.DecodePage();
     }
     if (!this.need_next_pcm)
     {
         long num3 = (long)(this.control_.ElapsedTime * (double)this.control_.PcmRate) + 44100L;
         if (this.Pcm != null && this.curPcmOffset < 352800 && !this.eos && num3 > this.PcmSampleOffset + (long)(176400 / this.PcmChannels))
         {
             this.control_.SamplesPerMillisecond = (double)this.control_.Scale * 44.1;
             this.need_next_pcm = true;
         }
         if ((this.Pcm == null && this.curPcmOffset >= 352800) || (this.last_buf && num3 > this.PcmSampleOffset + (long)(264600 / this.PcmChannels)) || (!this.need_next_pcm && num3 > this.PcmSampleOffset + (long)(264600 / this.PcmChannels)))
         {
             this.last_buf      = false;
             this.curPcmOffset -= 176400;
             float[] array = this.curPcm;
             this.curPcm = this.nxtPcm;
             this.nxtPcm = this.rdyPcm;
             this.rdyPcm = array;
             if (this.curPcmOffset > 176400)
             {
                 for (int i = 0; i < this.curPcmOffset - 352800 + 176400; i++)
                 {
                     int num4 = i + 352800 - 176400;
                     if (num4 >= 352800)
                     {
                         Debug.LogError("(i > srcind)");
                     }
                     this.nxtPcm[i] = this.curPcm[num4];
                 }
             }
             this.PcmSampleOffset += (long)(176400 / this.PcmChannels);
             this.Pcm              = this.rdyPcm;
             this.lastReadIdx++;
             long num5 = DateTime.Now.Ticks / 10000L;
             if (this.lastReadIdx > 9)
             {
                 for (int j = 1; j < 10; j++)
                 {
                     this.lastReadSamples[j - 1] = this.lastReadSamples[j];
                     this.lastReadTime[j - 1]    = this.lastReadTime[j];
                 }
                 this.lastReadIdx = 9;
             }
             this.lastReadSamples[this.lastReadIdx] = 176400 / this.PcmChannels;
             this.lastReadTime[this.lastReadIdx]    = num5;
             long num6 = 0L;
             long num7 = 0L;
             for (int k = 1; k <= this.lastReadIdx; k++)
             {
                 num6 += (long)this.lastReadSamples[k - 1];
                 num7 += this.lastReadTime[k] - this.lastReadTime[k - 1];
             }
             if (num6 > 0L)
             {
                 this.readspeed = (double)num6 / (double)num7;
             }
             this.control_.Pcm                   = this.Pcm;
             this.control_.PcmSampleOffset       = this.PcmSampleOffset;
             this.control_.PcmSampleCount        = this.PcmSampleCount;
             this.control_.SamplesPerMillisecond = this.readspeed;
         }
     }
 }
Esempio n. 3
0
 private bool LoadVideo()
 {
     this.op           = new Xiph.ogg_packet();
     this.og           = new Xiph.ogg_page();
     this.to           = new Xiph.ogg_stream_state();
     this.oy           = new Xiph.ogg_sync_state();
     this.ti           = default(Xiph.th_info);
     this.tc           = new Xiph.th_comment();
     this.ts           = null;
     this.fps          = 0f;
     this.frame_in_sec = 0f;
     this.instream_pos = 0L;
     this.stateflag    = 0;
     this.theora_p     = 0;
     this.theora_processing_headers = 0;
     this.videobuf_time             = 0.0;
     this.videobuf_ready            = 0;
     this.videobuf_granulepos       = -1L;
     this.rnd_frame = -1;
     this.rdy_frame = -1;
     this.cur_frame = -1;
     this.elapsedTimeSamples.Clear();
     this.elapsedTimeTimestamps.Clear();
     Xiph.ogg_sync_init(this.oy);
     Xiph.th_comment_init(this.tc);
     Xiph.th_info_init(ref this.ti);
     while (this.stateflag == 0)
     {
         if (this.buffer_data(this.instream, this.oy) == 0)
         {
             break;
         }
         while (Xiph.ogg_sync_pageout(this.oy, this.og) > 0)
         {
             Xiph.ogg_stream_state os = new Xiph.ogg_stream_state();
             if (Xiph.ogg_page_bos(this.og) == 0)
             {
                 this.queue_page(this.og);
                 this.stateflag = 1;
                 break;
             }
             Xiph.ogg_stream_init(os, Xiph.ogg_page_serialno(this.og));
             Xiph.ogg_stream_pagein(os, this.og);
             int num = Xiph.ogg_stream_packetpeek(os, this.op);
             if (num == 1 && this.theora_p == 0 && (this.theora_processing_headers = Xiph.th_decode_headerin(ref this.ti, this.tc, ref this.ts, this.op)) >= 0)
             {
                 this.to       = Xiph.ogg_stream_clone(os);
                 this.theora_p = 1;
                 if (this.theora_processing_headers != 0)
                 {
                     Xiph.ogg_stream_packetout(this.to, null);
                 }
             }
             else
             {
                 Xiph.ogg_stream_clear(os);
             }
         }
     }
     while (this.theora_p != 0 && this.theora_processing_headers != 0)
     {
         int num2;
         while (this.theora_processing_headers != 0 && (num2 = Xiph.ogg_stream_packetpeek(this.to, this.op)) != 0)
         {
             if (num2 >= 0)
             {
                 this.theora_processing_headers = Xiph.th_decode_headerin(ref this.ti, this.tc, ref this.ts, this.op);
                 if (this.theora_processing_headers < 0)
                 {
                     this.error = "Error parsing Theora stream headers; corrupt stream?\n";
                     return(false);
                 }
                 if (this.theora_processing_headers > 0)
                 {
                     Xiph.ogg_stream_packetout(this.to, null);
                 }
                 this.theora_p++;
             }
         }
         if (this.theora_p == 0 || this.theora_processing_headers == 0)
         {
             break;
         }
         if (Xiph.ogg_sync_pageout(this.oy, this.og) > 0)
         {
             this.queue_page(this.og);
         }
         else if (this.buffer_data(this.instream, this.oy) == 0)
         {
             this.error = "End of file while searching for codec headers.\n";
             return(false);
         }
     }
     if (this.theora_p != 0)
     {
         this.dump_comments(this.tc);
         this.td   = Xiph.th_decode_alloc(this.ti, this.ts);
         this.info = string.Format("Ogg logical stream {0} is Theora {1}x{2} {3} fps video\nEncoded frame content is {4}x{5} with {6}x{7} offset\n", new object[]
         {
             this.to.serialno,
             this.ti.frame_width,
             this.ti.frame_height,
             this.ti.fps_numerator / this.ti.fps_denominator,
             this.ti.pic_width,
             this.ti.pic_height,
             this.ti.pic_x,
             this.ti.pic_y
         });
         this.fps          = this.ti.fps_numerator / this.ti.fps_denominator;
         this.frame_in_sec = 1f / this.fps;
     }
     else
     {
         Xiph.th_info_clear(ref this.ti);
         Xiph.th_comment_clear(this.tc);
     }
     Xiph.th_setup_free(this.ts);
     if (this.theora_p != 0)
     {
         this.open_video();
     }
     this.stateflag = 0;
     while (Xiph.ogg_sync_pageout(this.oy, this.og) > 0)
     {
         this.queue_page(this.og);
     }
     this.colors_y_1   = new Color32[this.width * this.height];
     this.colors_y_2   = new Color32[this.width * this.height];
     this.colors_y     = this.colors_y_1;
     this.colors_y_rnd = this.colors_y_2;
     while (this.theora_p != 0 && this.videobuf_ready == 0)
     {
         if (Xiph.ogg_stream_packetout(this.to, this.op) <= 0)
         {
             break;
         }
         if (Xiph.th_decode_packetin(this.td, this.op, ref this.videobuf_granulepos) >= 0)
         {
             this.videobuf_time  = Xiph.th_granule_time(this.td.state, this.videobuf_granulepos);
             this.videobuf_ready = 1;
         }
     }
     this.loaded = true;
     return(true);
 }
Esempio n. 4
0
 private bool LoadAudio()
 {
     this.oy              = new Xiph.ogg_sync_state();
     this.os              = new Xiph.ogg_stream_state();
     this.og              = new Xiph.ogg_page();
     this.op              = new Xiph.ogg_packet();
     this.vi              = new Xiph.vorbis_info();
     this.vc              = new Xiph.vorbis_comment();
     this.vd              = new Xiph.vorbis_dsp_state();
     this.vb              = new Xiph.vorbis_block();
     this.instream_pos    = 0L;
     this.eos             = false;
     this.last_buf        = false;
     this.need_more_data  = false;
     this.need_next_pcm   = true;
     this.vorbis_p        = false;
     this.stateflag       = false;
     this.comments_header = false;
     this.instream_pos    = 0L;
     this.curPcmOffset    = 0;
     this.Pcm             = null;
     this.PcmSampleCount  = 0L;
     this.PcmSampleOffset = 0L;
     this.readspeed       = (double)this.control_.Scale + 44.1;
     this.lastReadIdx     = -1;
     Xiph.ogg_sync_init(this.oy);
     Xiph.vorbis_info_init(this.vi);
     Xiph.vorbis_comment_init(this.vc);
     while (!this.stateflag)
     {
         if (this.buffer_data(this.instream, this.oy) == 0)
         {
             break;
         }
         while (Xiph.ogg_sync_pageout(this.oy, this.og) > 0)
         {
             Xiph.ogg_stream_state ogg_stream_state = new Xiph.ogg_stream_state();
             if (Xiph.ogg_page_bos(this.og) == 0)
             {
                 this.stateflag = true;
                 break;
             }
             Xiph.ogg_stream_init(ogg_stream_state, Xiph.ogg_page_serialno(this.og));
             Xiph.ogg_stream_pagein(ogg_stream_state, this.og);
             int num = Xiph.ogg_stream_packetpeek(ogg_stream_state, this.op);
             if (num == 1 && !this.vorbis_p && Xiph.vorbis_synthesis_headerin(this.vi, this.vc, this.op) >= 0)
             {
                 this.os       = Xiph.ogg_stream_clone(ogg_stream_state);
                 this.vorbis_p = true;
                 Xiph.ogg_stream_packetout(this.os, null);
             }
             else
             {
                 Xiph.ogg_stream_clear(ogg_stream_state);
             }
         }
     }
     while (this.vorbis_p && !this.comments_header)
     {
         int num2;
         while ((num2 = Xiph.ogg_stream_packetpeek(this.os, this.op)) != 0)
         {
             if (num2 >= 0)
             {
                 if (Xiph.vorbis_synthesis_headerin(this.vi, this.vc, this.op) < 0)
                 {
                     this.error = "Error parsing Theora stream vorbis; corrupt stream?\n";
                     return(false);
                 }
                 Xiph.ogg_stream_packetout(this.os, null);
                 this.comments_header = true;
             }
         }
         if (Xiph.ogg_sync_pageout(this.oy, this.og) > 0)
         {
             Xiph.ogg_stream_pagein(this.os, this.og);
         }
         else if (this.buffer_data(this.instream, this.oy) == 0)
         {
             this.error = "End of file while searching for codec headers.\n";
             return(false);
         }
     }
     if (this.vorbis_p)
     {
         if (this.buffer_data(this.instream, this.oy) == 0)
         {
             this.error = "End of file before finding all Vorbis headers!\n";
             return(false);
         }
         this.PcmRate                        = this.vi.rate;
         this.PcmChannels                    = this.vi.channels;
         this.PcmSampleOffset                = (long)(-176400 / this.PcmChannels);
         this.PcmSampleCount                 = (long)(88200 / this.PcmChannels);
         this.curPcmOffset                   = 88200;
         this.control_.PcmChannels           = this.PcmChannels;
         this.control_.PcmRate               = this.PcmRate;
         this.control_.SamplesPerMillisecond = (double)this.control_.Scale * 44.1;
         this.dump_comments(this.vi, this.vc);
         if (Xiph.vorbis_synthesis_init(this.vd, this.vi) != 0)
         {
             this.error = "Wrong Vorbis stream!\n";
             return(false);
         }
         Xiph.vorbis_block_init(this.vd, this.vb);
     }
     return(this.vorbis_p);
 }