StreamParser.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using UnityEngine;
  5. namespace RenderHeads.Media.AVProVideo
  6. {
  7. public class StreamParser : MonoBehaviour
  8. {
  9. public StreamParserEvent Events
  10. {
  11. get
  12. {
  13. if (this._events == null)
  14. {
  15. this._events = new StreamParserEvent();
  16. }
  17. return this._events;
  18. }
  19. }
  20. private void LoadFile()
  21. {
  22. try
  23. {
  24. StreamParser.StreamType streamType = this._streamType;
  25. if (streamType != StreamParser.StreamType.HLS)
  26. {
  27. this._parser = new HLSStream(this._url, 0, 0, 0);
  28. }
  29. else
  30. {
  31. this._parser = new HLSStream(this._url, 0, 0, 0);
  32. }
  33. this._substreams = this._parser.GetAllStreams();
  34. this._chunks = this._parser.GetAllChunks();
  35. this._loaded = true;
  36. Debug.Log("[AVProVideo] Stream parser completed parsing stream file " + this._url);
  37. this._events.Invoke(this, StreamParserEvent.EventType.Success);
  38. }
  39. catch (Exception ex)
  40. {
  41. this._loaded = false;
  42. Debug.LogError("[AVProVideo] Parser unable to read stream " + ex.Message);
  43. this._events.Invoke(this, StreamParserEvent.EventType.Failed);
  44. }
  45. }
  46. public bool Loaded
  47. {
  48. get
  49. {
  50. return this._loaded;
  51. }
  52. }
  53. public Stream Root
  54. {
  55. get
  56. {
  57. return (!this._loaded) ? null : this._parser;
  58. }
  59. }
  60. public List<Stream> SubStreams
  61. {
  62. get
  63. {
  64. return (!this._loaded) ? null : this._substreams;
  65. }
  66. }
  67. public List<Stream.Chunk> Chunks
  68. {
  69. get
  70. {
  71. return (!this._loaded) ? null : this._chunks;
  72. }
  73. }
  74. public void ParseStream()
  75. {
  76. Thread thread = new Thread(new ThreadStart(this.LoadFile));
  77. thread.Start();
  78. }
  79. private void Start()
  80. {
  81. if (this._autoLoad)
  82. {
  83. this.ParseStream();
  84. }
  85. }
  86. public string _url;
  87. public StreamParser.StreamType _streamType;
  88. public bool _autoLoad = true;
  89. private Stream _parser;
  90. private bool _loaded;
  91. private List<Stream> _substreams;
  92. private List<Stream.Chunk> _chunks;
  93. private StreamParserEvent _events;
  94. public enum StreamType
  95. {
  96. HLS
  97. }
  98. }
  99. }