123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using UnityEngine;
- namespace RenderHeads.Media.AVProVideo
- {
- public class StreamParser : MonoBehaviour
- {
- public StreamParserEvent Events
- {
- get
- {
- if (this._events == null)
- {
- this._events = new StreamParserEvent();
- }
- return this._events;
- }
- }
- private void LoadFile()
- {
- try
- {
- StreamParser.StreamType streamType = this._streamType;
- if (streamType != StreamParser.StreamType.HLS)
- {
- this._parser = new HLSStream(this._url, 0, 0, 0);
- }
- else
- {
- this._parser = new HLSStream(this._url, 0, 0, 0);
- }
- this._substreams = this._parser.GetAllStreams();
- this._chunks = this._parser.GetAllChunks();
- this._loaded = true;
- Debug.Log("[AVProVideo] Stream parser completed parsing stream file " + this._url);
- this._events.Invoke(this, StreamParserEvent.EventType.Success);
- }
- catch (Exception ex)
- {
- this._loaded = false;
- Debug.LogError("[AVProVideo] Parser unable to read stream " + ex.Message);
- this._events.Invoke(this, StreamParserEvent.EventType.Failed);
- }
- }
- public bool Loaded
- {
- get
- {
- return this._loaded;
- }
- }
- public Stream Root
- {
- get
- {
- return (!this._loaded) ? null : this._parser;
- }
- }
- public List<Stream> SubStreams
- {
- get
- {
- return (!this._loaded) ? null : this._substreams;
- }
- }
- public List<Stream.Chunk> Chunks
- {
- get
- {
- return (!this._loaded) ? null : this._chunks;
- }
- }
- public void ParseStream()
- {
- Thread thread = new Thread(new ThreadStart(this.LoadFile));
- thread.Start();
- }
- private void Start()
- {
- if (this._autoLoad)
- {
- this.ParseStream();
- }
- }
- public string _url;
- public StreamParser.StreamType _streamType;
- public bool _autoLoad = true;
- private Stream _parser;
- private bool _loaded;
- private List<Stream> _substreams;
- private List<Stream.Chunk> _chunks;
- private StreamParserEvent _events;
- public enum StreamType
- {
- HLS
- }
- }
- }
|