private int queue_page(Xiph.ogg_page page)
 {
     if (this.theora_p != 0)
     {
         Xiph.ogg_stream_pagein(this.to, page);
     }
     return(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);
 }
Exemple #3
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);
 }