TsSource.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Specialized;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Text;
  7. using MatrixIO.IO.MpegTs;
  8. namespace TsViewer
  9. {
  10. public abstract class TsSource : INotifyPropertyChanged
  11. {
  12. private readonly TsDemuxer _demuxer = new TsDemuxer();
  13. public TsDemuxer Demuxer
  14. {
  15. get { return _demuxer; }
  16. }
  17. private Uri _uri;
  18. public Uri Uri
  19. {
  20. get
  21. {
  22. return _uri;
  23. }
  24. protected set
  25. {
  26. _uri = value;
  27. OnPropertyChanged("Uri");
  28. }
  29. }
  30. public abstract void Start(Uri uri);
  31. public abstract void Stop();
  32. public static TsSource Create(string uri)
  33. {
  34. return Create(new Uri(uri));
  35. }
  36. public static TsSource Create(Uri uri)
  37. {
  38. switch(uri.Scheme)
  39. {
  40. case "file":
  41. return Create<TsFileSource>(uri);
  42. case "udp":
  43. return Create<TsUdpSource>(uri);
  44. default:
  45. throw new ArgumentException("Unsupported scheme '" + uri.Scheme + "'");
  46. }
  47. }
  48. public static T Create<T>(string uri) where T: TsSource, new()
  49. {
  50. return Create<T>(new Uri(uri));
  51. }
  52. public static T Create<T>(Uri uri) where T: TsSource, new()
  53. {
  54. var newT = new T();
  55. newT.Start(uri);
  56. return newT;
  57. }
  58. public override string ToString()
  59. {
  60. return Uri == null ? "No Uri" : Uri.ToString();
  61. }
  62. public event PropertyChangedEventHandler PropertyChanged;
  63. private void OnPropertyChanged(string propertyName)
  64. {
  65. if(PropertyChanged != null)
  66. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  67. }
  68. }
  69. }