Beispiel #1
0
        public void Play()
        {
            switch (AL.GetSourceState(this.alSourceId))
            {
            case ALSourceState.Playing:
                break;

            case ALSourceState.Paused:
                this.Resume();
                break;

            default:
                if (this.bufferStack.Count == this.BufferCount)
                {
                    this.Prepare(false);
                }
                else if (!this.FirstBufferPrecached)
                {
                    ALHelper.Log(string.Concat(new object[4]
                    {
                        (object)"Buffers lost for ",
                        (object)this.RealName,
                        (object)" with source ",
                        (object)this.alSourceId
                    }), "OpenAL");
                }
                AL.SourcePlay(this.alSourceId);
                this.Precaching = false;
                OggStreamer.Instance.AddStream(this);
                break;
            }
        }
Beispiel #2
0
 private void EnsureBuffersFilled()
 {
     while (!this.cancelled && !this.cancelled)
     {
         this.threadLocalStreams.Clear();
         OggStreamer.iterationLock.EnterReadLock();
         this.threadLocalStreams.AddRange((IEnumerable <OggStream>) this.streams);
         OggStreamer.iterationLock.ExitReadLock();
         if (this.threadLocalStreams.Count != 0)
         {
             int val1 = int.MaxValue;
             for (int index = this.threadLocalStreams.Count - 1; index >= 0; --index)
             {
                 OggStream oggStream = this.threadLocalStreams[index];
                 OggStreamer.iterationLock.EnterReadLock();
                 bool flag = !this.streams.Contains(oggStream);
                 OggStreamer.iterationLock.ExitReadLock();
                 if (flag)
                 {
                     this.threadLocalStreams.RemoveAt(index);
                 }
                 else
                 {
                     int num1;
                     AL.GetSource(oggStream.alSourceId, ALGetSourcei.BuffersQueued, out num1);
                     oggStream.QueuedBuffers = num1;
                     int num2;
                     AL.GetSource(oggStream.alSourceId, ALGetSourcei.BuffersProcessed, out num2);
                     oggStream.ProcessedBuffers = num2;
                     if (!oggStream.Precaching)
                     {
                         val1 = Math.Min(val1, num1 - num2);
                     }
                 }
             }
             foreach (OggStream stream in this.threadLocalStreams)
             {
                 stream.PreparationLock.EnterReadLock();
                 OggStreamer.iterationLock.EnterReadLock();
                 bool flag1 = !this.streams.Contains(stream);
                 OggStreamer.iterationLock.ExitReadLock();
                 if (flag1)
                 {
                     stream.PreparationLock.ExitReadLock();
                 }
                 else if (stream.ProcessedBuffers == 0 && stream.bufferStack.Count == 0)
                 {
                     stream.PreparationLock.ExitReadLock();
                 }
                 else if (stream.QueuedBuffers - stream.ProcessedBuffers > val1)
                 {
                     stream.PreparationLock.ExitReadLock();
                 }
                 else if (stream.Precaching && val1 <= stream.BufferCount * 2 / 3)
                 {
                     stream.PreparationLock.ExitReadLock();
                 }
                 else
                 {
                     int  num   = stream.ProcessedBuffers <= 0 ? stream.bufferStack.Pop() : AL.SourceUnqueueBuffer(stream.alSourceId);
                     bool flag2 = this.FillBuffer(stream, num);
                     if (flag2)
                     {
                         if (stream.IsLooped)
                         {
                             stream.Reader.DecodedTime = TimeSpan.Zero;
                         }
                         else
                         {
                             OggStreamer.iterationLock.EnterWriteLock();
                             this.streams.Remove(stream);
                             OggStreamer.iterationLock.ExitWriteLock();
                         }
                     }
                     AL.SourceQueueBuffer(stream.alSourceId, num);
                     if (!stream.FirstBufferPrecached)
                     {
                         Interlocked.Decrement(ref this.PendingPrecaches);
                         stream.FirstBufferPrecached = true;
                     }
                     if (flag2 && !stream.IsLooped)
                     {
                         stream.PreparationLock.ExitReadLock();
                     }
                     else
                     {
                         stream.PreparationLock.ExitReadLock();
                         stream.StoppingLock.EnterReadLock();
                         if (stream.Precaching)
                         {
                             stream.StoppingLock.ExitReadLock();
                         }
                         else
                         {
                             OggStreamer.iterationLock.EnterReadLock();
                             bool flag3 = !this.streams.Contains(stream);
                             OggStreamer.iterationLock.ExitReadLock();
                             if (flag3)
                             {
                                 stream.StoppingLock.ExitReadLock();
                             }
                             else
                             {
                                 if (AL.GetSourceState(stream.alSourceId) == ALSourceState.Stopped)
                                 {
                                     ALHelper.Log(string.Concat(new object[4]
                                     {
                                         (object)"Buffer underrun on ",
                                         (object)stream.RealName,
                                         (object)" with source ",
                                         (object)stream.alSourceId
                                     }), "OpenAL");
                                     AL.SourcePlay(stream.alSourceId);
                                 }
                                 stream.StoppingLock.ExitReadLock();
                             }
                         }
                     }
                 }
             }
         }
     }
 }