├── .gitattributes
├── .gitignore
├── DashTools.Samples
├── App.config
├── DashTools.Samples.csproj
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── DashTools.Tests
├── DashTools.Tests.csproj
├── MediaPresentationDescriptionTests.cs
├── MpdDownloaderTests.cs
├── MpdFixture.cs
├── Properties
│ └── AssemblyInfo.cs
├── envivio.mpd
└── packages.config
├── DashTools
├── ArrayExtensions.cs
├── AspectRatio.cs
├── DashTools.csproj
├── FrameRate.cs
├── MediaPresentationDescription.cs
├── Mp4File.cs
├── Mp4InitFile.cs
├── MpdAdaptationSet.cs
├── MpdDownloader.cs
├── MpdElement.cs
├── MpdInitialization.cs
├── MpdPeriod.cs
├── MpdRepresentation.cs
├── MpdSegmentList.cs
├── MpdSegmentTemplate.cs
├── MpdSegmentUrl.cs
├── MpdWalker.cs
├── MultipleSegmentBase.cs
├── Properties
│ └── AssemblyInfo.cs
├── SegmentBase.cs
├── Track.cs
├── TrackContentType.cs
├── TrackRepresentation.cs
├── TrackRepresentationSegment.cs
└── XmlAttributeParseHelper.cs
├── LICENSE
├── NuGet
└── DashTools.csproj.nuspec
├── README.md
├── SharpDashTools.sln
└── build.ps1
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | NuGet/NuGet.exe
2 |
3 | ## Ignore Visual Studio temporary files, build results, and
4 | ## files generated by popular Visual Studio add-ons.
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | build/
23 | bld/
24 | [Bb]in/
25 | [Oo]bj/
26 |
27 | # Visual Studio 2015 cache/options directory
28 | .vs/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opensdf
80 | *.sdf
81 | *.cachefile
82 |
83 | # Visual Studio profiler
84 | *.psess
85 | *.vsp
86 | *.vspx
87 |
88 | # TFS 2012 Local Workspace
89 | $tf/
90 |
91 | # Guidance Automation Toolkit
92 | *.gpState
93 |
94 | # ReSharper is a .NET coding add-in
95 | _ReSharper*/
96 | *.[Rr]e[Ss]harper
97 | *.DotSettings.user
98 |
99 | # JustCode is a .NET coding add-in
100 | .JustCode
101 |
102 | # TeamCity is a build add-in
103 | _TeamCity*
104 |
105 | # DotCover is a Code Coverage Tool
106 | *.dotCover
107 |
108 | # NCrunch
109 | _NCrunch_*
110 | .*crunch*.local.xml
111 |
112 | # MightyMoose
113 | *.mm.*
114 | AutoTest.Net/
115 |
116 | # Web workbench (sass)
117 | .sass-cache/
118 |
119 | # Installshield output folder
120 | [Ee]xpress/
121 |
122 | # DocProject is a documentation generator add-in
123 | DocProject/buildhelp/
124 | DocProject/Help/*.HxT
125 | DocProject/Help/*.HxC
126 | DocProject/Help/*.hhc
127 | DocProject/Help/*.hhk
128 | DocProject/Help/*.hhp
129 | DocProject/Help/Html2
130 | DocProject/Help/html
131 |
132 | # Click-Once directory
133 | publish/
134 |
135 | # Publish Web Output
136 | *.[Pp]ublish.xml
137 | *.azurePubxml
138 | ## TODO: Comment the next line if you want to checkin your
139 | ## web deploy settings but do note that will include unencrypted
140 | ## passwords
141 | #*.pubxml
142 |
143 | *.publishproj
144 |
145 | # NuGet Packages
146 | *.nupkg
147 | # The packages folder can be ignored because of Package Restore
148 | **/packages/*
149 | # except build/, which is used as an MSBuild target.
150 | !**/packages/build/
151 | # Uncomment if necessary however generally it will be regenerated when needed
152 | #!**/packages/repositories.config
153 |
154 | # Windows Azure Build Output
155 | csx/
156 | *.build.csdef
157 |
158 | # Windows Store app package directory
159 | AppPackages/
160 |
161 | # Visual Studio cache files
162 | # files ending in .cache can be ignored
163 | *.[Cc]ache
164 | # but keep track of directories ending in .cache
165 | !*.[Cc]ache/
166 |
167 | # Others
168 | ClientBin/
169 | [Ss]tyle[Cc]op.*
170 | ~$*
171 | *~
172 | *.dbmdl
173 | *.dbproj.schemaview
174 | *.pfx
175 | *.publishsettings
176 | node_modules/
177 | orleans.codegen.cs
178 |
179 | # RIA/Silverlight projects
180 | Generated_Code/
181 |
182 | # Backup & report files from converting an old project file
183 | # to a newer Visual Studio version. Backup files are not needed,
184 | # because we have git ;-)
185 | _UpgradeReport_Files/
186 | Backup*/
187 | UpgradeLog*.XML
188 | UpgradeLog*.htm
189 |
190 | # SQL Server files
191 | *.mdf
192 | *.ldf
193 |
194 | # Business Intelligence projects
195 | *.rdl.data
196 | *.bim.layout
197 | *.bim_*.settings
198 |
199 | # Microsoft Fakes
200 | FakesAssemblies/
201 |
202 | # Node.js Tools for Visual Studio
203 | .ntvs_analysis.dat
204 |
205 | # Visual Studio 6 build log
206 | *.plg
207 |
208 | # Visual Studio 6 workspace options file
209 | *.opt
210 |
211 | # LightSwitch generated files
212 | GeneratedArtifacts/
213 | _Pvt_Extensions/
214 | ModelManifest.xml
215 |
--------------------------------------------------------------------------------
/DashTools.Samples/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/DashTools.Samples/DashTools.Samples.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {19125071-F9C9-4F10-AA66-621DD65F3ABE}
8 | Exe
9 | Properties
10 | Qoollo.MpegDash.Samples
11 | DashTools.Samples
12 | v4.5.2
13 | 512
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 | ..\packages\NReco.VideoConverter.1.0.8.0\lib\net20\NReco.VideoConverter.dll
38 | True
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | {d517b927-7afc-42ad-a410-27354f3217c2}
60 | DashTools
61 |
62 |
63 |
64 |
71 |
--------------------------------------------------------------------------------
/DashTools.Samples/Program.cs:
--------------------------------------------------------------------------------
1 | using NReco.VideoConverter;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Diagnostics;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace Qoollo.MpegDash.Samples
11 | {
12 | class Program
13 | {
14 | static void Main(string[] args)
15 | {
16 | Task.Run(async () =>
17 | {
18 | await MainAsync(args);
19 | }).Wait();
20 | }
21 |
22 | static async Task MainAsync(string[] args)
23 | {
24 | string dir = "envivio";
25 | string mpdUrl = "http://10.5.5.7/q/p/userapi/streams/32/mpd";
26 | //"http://10.5.7.207/userapi/streams/30/mpd";
27 | //"http://10.5.7.207/userapi/streams/11/mpd?start_time=1458816642&stop_time=1458819642";
28 | //"http://dash.edgesuite.net/envivio/EnvivioDash3/manifest.mpd";
29 | //"http://dash.edgesuite.net/dash264/TestCases/1a/netflix/exMPD_BIP_TC1.mpd";
30 | var stopwatch = Stopwatch.StartNew();
31 |
32 | var downloader = new MpdDownloader(new Uri(mpdUrl), dir);
33 | var trackRepresentation = downloader.GetTracksFor(TrackContentType.Video).First().TrackRepresentations.OrderByDescending(r => r.Bandwidth).First();
34 | var prepareTime = stopwatch.Elapsed;
35 |
36 | var chunks =
37 | //Directory.GetFiles(@"C:\Users\Alexander\Work\Github\qoollo\SharpDashTools\DashTools.Samples\bin\Debug\envivio", "*.mp4")
38 | //.Select(f => Path.GetFileName(f) == "make_chunk_path_longer_32.mp4"
39 | // ? new Mp4InitFile(Path.Combine("envivio", Path.GetFileName(f)))
40 | // : new Mp4File(Path.Combine("envivio", Path.GetFileName(f))))
41 | // .ToArray();
42 | await downloader.Download(trackRepresentation, TimeSpan.FromMinutes(60), TimeSpan.FromMinutes(60 + 60 * 6 / 6));
43 | var downloadTime = stopwatch.Elapsed - prepareTime;
44 |
45 | var ffmpeg = new FFMpegConverter();
46 | ffmpeg.LogReceived += (s, e) => Console.WriteLine(e.Data);
47 | var combined = downloader.CombineChunksFast(chunks, s => ffmpeg.Invoke(s));
48 | //downloader.CombineChunks(chunks, s => ffmpeg.Invoke(s));
49 | var combineTime = stopwatch.Elapsed - prepareTime - downloadTime;
50 |
51 | if (!ffmpeg.Stop())
52 | ffmpeg.Abort();
53 |
54 | Console.WriteLine();
55 | Console.WriteLine();
56 | Console.WriteLine("================================================================");
57 | Console.WriteLine("Prepared in {0} s", prepareTime.TotalSeconds);
58 | Console.WriteLine("Downloaded {0} chunks in {1} s", chunks.Count(), downloadTime.TotalSeconds);
59 | Console.WriteLine("Combined in {0} s", combineTime.TotalSeconds);
60 | Console.WriteLine("Total: {0} s", (prepareTime + downloadTime + combineTime).TotalSeconds);
61 | Console.ReadLine();
62 |
63 | return;
64 |
65 | string mpdFilePath = //@"C:\Users\Alexander\AppData\Local\Temp\note_5_video_5_source_2-index_00000\manifest.mpd";
66 | await DownloadMpdStreams(mpdUrl, dir);
67 | await ConcatStreams(mpdFilePath, Path.Combine(Path.GetDirectoryName(mpdFilePath), "output.mp4"));
68 | }
69 |
70 | private static async Task DownloadMpdStreams(string url, string destinationDir)
71 | {
72 | var dir = new DirectoryInfo(destinationDir);
73 | if (dir.Exists)
74 | dir.Delete(recursive: true);
75 | var downloader = new MpdDownloader(new Uri(url), dir.FullName);
76 |
77 | return await downloader.Download();
78 | }
79 |
80 | private static async Task ConcatStreams(string mpdFilePath, string outputFile)
81 | {
82 | var mpd = new MediaPresentationDescription(mpdFilePath);
83 | var walker = new MpdWalker(mpd);
84 | var track = walker.GetTracksFor(TrackContentType.Video).First();
85 | var trackRepresentation = track.TrackRepresentations.OrderByDescending(r => r.Bandwidth).First();
86 |
87 | using (var stream = File.OpenWrite(outputFile))
88 | using (var writer = new BinaryWriter(stream))
89 | {
90 | string fragmentPath = Path.Combine(Path.GetDirectoryName(mpdFilePath), trackRepresentation.InitFragmentPath);
91 | writer.Write(File.ReadAllBytes(fragmentPath));
92 |
93 | foreach (var path in trackRepresentation.FragmentsPaths)
94 | {
95 | fragmentPath = Path.Combine(Path.GetDirectoryName(mpdFilePath), path);
96 | if (!File.Exists(fragmentPath))
97 | break;
98 | writer.Write(File.ReadAllBytes(fragmentPath));
99 | }
100 | }
101 |
102 | string[] files = new[]
103 | {
104 | "v1_257-Header.m4s",
105 | "v1_257-270146-i-1.m4s",
106 | "v1_257-270146-i-2.m4s",
107 | "v1_257-270146-i-3.m4s",
108 | "v1_257-270146-i-4.m4s",
109 | "v1_257-270146-i-5.m4s",
110 | "v1_257-270146-i-6.m4s",
111 | "v1_257-270146-i-7.m4s",
112 | "v1_257-270146-i-8.m4s",
113 | "v1_257-270146-i-9.m4s",
114 | "v1_257-270146-i-10.m4s",
115 | "v1_257-270146-i-11.m4s",
116 | "v1_257-270146-i-12.m4s",
117 | "v1_257-270146-i-13.m4s",
118 | "v1_257-270146-i-14.m4s",
119 | "v1_257-270146-i-15.m4s",
120 | "v1_257-270146-i-16.m4s",
121 | "v1_257-270146-i-17.m4s",
122 | "v1_257-270146-i-18.m4s",
123 | "v1_257-270146-i-19.m4s",
124 | "v1_257-270146-i-20.m4s",
125 | "v1_257-270146-i-21.m4s",
126 | "v1_257-270146-i-22.m4s",
127 | "v1_257-270146-i-23.m4s",
128 | "v1_257-270146-i-24.m4s",
129 | "v1_257-270146-i-25.m4s",
130 | "v1_257-270146-i-26.m4s",
131 | "v1_257-270146-i-27.m4s",
132 | "v1_257-270146-i-28.m4s",
133 | "v1_257-270146-i-29.m4s",
134 | "v1_257-270146-i-30.m4s",
135 | "v1_257-270146-i-31.m4s",
136 | "v1_257-270146-i-32.m4s",
137 | "v1_257-270146-i-33.m4s",
138 | "v1_257-270146-i-34.m4s",
139 | "v1_257-270146-i-35.m4s",
140 | "v1_257-270146-i-36.m4s",
141 | "v1_257-270146-i-37.m4s",
142 | "v1_257-270146-i-38.m4s",
143 | "v1_257-270146-i-39.m4s",
144 | "v1_257-270146-i-40.m4s",
145 | "v1_257-270146-i-41.m4s",
146 | "v1_257-270146-i-42.m4s",
147 | "v1_257-270146-i-43.m4s",
148 | "v1_257-270146-i-44.m4s",
149 | "v1_257-270146-i-45.m4s",
150 | "v1_257-270146-i-46.m4s",
151 | "v1_257-270146-i-47.m4s",
152 | "v1_257-270146-i-48.m4s",
153 | "v1_257-270146-i-49.m4s",
154 | "v1_257-270146-i-50.m4s",
155 | "v1_257-270146-i-51.m4s",
156 | "v1_257-270146-i-52.m4s",
157 | "v1_257-270146-i-53.m4s",
158 | "v1_257-270146-i-54.m4s",
159 | "v1_257-270146-i-55.m4s",
160 | "v1_257-270146-i-56.m4s",
161 | "v1_257-270146-i-57.m4s",
162 | "v1_257-270146-i-58.m4s",
163 | "v1_257-270146-i-59.m4s",
164 | "v1_257-270146-i-60.m4s",
165 | "v1_257-270146-i-61.m4s",
166 | "v1_257-270146-i-62.m4s",
167 | "v1_257-270146-i-63.m4s",
168 | "v1_257-270146-i-64.m4s",
169 | "v1_257-270146-i-65.m4s",
170 | "v1_257-270146-i-66.m4s",
171 | "v1_257-270146-i-67.m4s",
172 | "v1_257-270146-i-68.m4s",
173 | "v1_257-270146-i-69.m4s",
174 | "v1_257-270146-i-70.m4s",
175 | "v1_257-270146-i-71.m4s",
176 | "v1_257-270146-i-72.m4s",
177 | "v1_257-270146-i-73.m4s",
178 | "v1_257-270146-i-74.m4s",
179 | "v1_257-270146-i-75.m4s",
180 | "v1_257-270146-i-76.m4s",
181 | "v1_257-270146-i-77.m4s",
182 | "v1_257-270146-i-78.m4s",
183 | "v1_257-270146-i-79.m4s",
184 | "v1_257-270146-i-80.m4s",
185 | "v1_257-270146-i-81.m4s",
186 | "v1_257-270146-i-82.m4s",
187 | "v1_257-270146-i-83.m4s",
188 | "v1_257-270146-i-84.m4s",
189 | "v1_257-270146-i-85.m4s",
190 | "v1_257-270146-i-86.m4s",
191 | "v1_257-270146-i-87.m4s",
192 | "v1_257-270146-i-88.m4s",
193 | "v1_257-270146-i-89.m4s",
194 | "v1_257-270146-i-90.m4s",
195 | "v1_257-270146-i-91.m4s",
196 | "v1_257-270146-i-92.m4s",
197 | "v1_257-270146-i-93.m4s",
198 | "v1_257-270146-i-94.m4s",
199 | "v1_257-270146-i-95.m4s",
200 | "v1_257-270146-i-96.m4s",
201 | "v1_257-270146-i-97.m4s",
202 | };
203 | //string outputFile = Path.Combine(Path.GetDirectoryName(mpdFilePath), "output.mp4");
204 | //using (var stream = File.OpenWrite(outputFile))
205 | //using (var writer = new BinaryWriter(stream))
206 | //{
207 | // files.Select(f => Path.Combine(Path.GetDirectoryName(mpdFilePath), f))
208 | // .ToList()
209 | // .ForEach(f => writer.Write(File.ReadAllBytes(f)));
210 | //}
211 | }
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/DashTools.Samples/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("DashTools.Samples")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("DashTools.Samples")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("19125071-f9c9-4f10-aa66-621dd65f3abe")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/DashTools.Samples/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/DashTools.Tests/DashTools.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {17D61727-C15B-4329-AC4A-381D174E76EB}
8 | Library
9 | Properties
10 | Qoollo.MpegDash.Tests
11 | DashTools.Tests
12 | v4.5.2
13 | 512
14 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 10.0
16 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
17 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
18 | False
19 | UnitTest
20 |
21 |
22 |
23 |
24 |
25 | true
26 | full
27 | false
28 | bin\Debug\
29 | DEBUG;TRACE
30 | prompt
31 | 4
32 | false
33 |
34 |
35 | pdbonly
36 | true
37 | bin\Release\
38 | TRACE
39 | prompt
40 | 4
41 | false
42 |
43 |
44 |
45 |
46 | 3.5
47 |
48 |
49 | ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll
50 | True
51 |
52 |
53 | ..\packages\xunit.assert.2.2.0-beta1-build3239\lib\dotnet\xunit.assert.dll
54 | True
55 |
56 |
57 | ..\packages\xunit.extensibility.core.2.2.0-beta1-build3239\lib\dotnet\xunit.core.dll
58 | True
59 |
60 |
61 | ..\packages\xunit.extensibility.execution.2.2.0-beta1-build3239\lib\net45\xunit.execution.desktop.dll
62 | True
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | PreserveNewest
86 |
87 |
88 |
89 |
90 |
91 | {d517b927-7afc-42ad-a410-27354f3217c2}
92 | DashTools
93 |
94 |
95 |
96 |
97 |
98 |
99 | False
100 |
101 |
102 | False
103 |
104 |
105 | False
106 |
107 |
108 | False
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
118 |
119 |
120 |
121 |
128 |
--------------------------------------------------------------------------------
/DashTools.Tests/MediaPresentationDescriptionTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using Xunit;
4 |
5 | namespace Qoollo.MpegDash.Tests
6 | {
7 | public class MediaPresentationDescriptionTests : IClassFixture
8 | {
9 | private MediaPresentationDescription mpd;
10 |
11 | public MediaPresentationDescriptionTests(MpdFixture mpdFixture)
12 | {
13 | this.mpd = mpdFixture.Mpd;
14 | }
15 |
16 | [Fact]
17 | public void Id()
18 | {
19 | Assert.Null(mpd.Id);
20 | }
21 |
22 | [Fact]
23 | public void Profiles()
24 | {
25 | Assert.Equal("urn:mpeg:dash:profile:isoff-live:2011", mpd.Profiles);
26 | }
27 |
28 | [Fact]
29 | public void Type()
30 | {
31 | Assert.Equal("static", mpd.Type);
32 | }
33 |
34 | [Fact]
35 | public void AvailabilityStartTime()
36 | {
37 | Assert.Equal(new DateTimeOffset(2016, 1, 20, 21, 10, 2, TimeSpan.Zero), mpd.AvailabilityStartTime);
38 | }
39 |
40 | [Fact]
41 | public void PublishTime()
42 | {
43 | Assert.Null(mpd.PublishTime);
44 | }
45 |
46 | [Fact]
47 | public void AvailabilityEndTime()
48 | {
49 | Assert.Null(mpd.AvailabilityEndTime);
50 | }
51 |
52 | [Fact]
53 | public void MediaPresentationDuration()
54 | {
55 | Assert.Equal(TimeSpan.FromSeconds(193.680), mpd.MediaPresentationDuration);
56 | }
57 |
58 | [Fact]
59 | public void MinimumUpdatePeriod()
60 | {
61 | Assert.Null(mpd.MinimumUpdatePeriod);
62 | }
63 |
64 | [Fact]
65 | public void MinBufferTime()
66 | {
67 | Assert.Equal(TimeSpan.FromSeconds(5), mpd.MinBufferTime);
68 | }
69 |
70 | [Fact]
71 | public void TimeShiftBufferDepth()
72 | {
73 | Assert.Null(mpd.TimeShiftBufferDepth);
74 | }
75 |
76 | [Fact]
77 | public void SuggestedPresentationDelay()
78 | {
79 | Assert.Null(mpd.SuggestedPresentationDelay);
80 | }
81 |
82 | [Fact]
83 | public void MaxSegmentDuration()
84 | {
85 | Assert.Equal(TimeSpan.FromMilliseconds(2005), mpd.MaxSegmentDuration);
86 | }
87 |
88 | [Fact]
89 | public void MaxSubsegmentDuration()
90 | {
91 | Assert.Null(mpd.MaxSubsegmentDuration);
92 | }
93 |
94 | [Fact]
95 | public void Periods_Count()
96 | {
97 | Assert.Equal(1, mpd.Periods.Count());
98 | }
99 |
100 | [Fact]
101 | public void Period_Id()
102 | {
103 | Assert.Equal("period0", mpd.Periods.First().Id);
104 | }
105 |
106 | [Fact]
107 | public void Period_Start()
108 | {
109 | Assert.Null(mpd.Periods.First().Start);
110 | }
111 |
112 | [Fact]
113 | public void Period_Duration()
114 | {
115 | Assert.Null(mpd.Periods.First().Duration);
116 | }
117 |
118 | [Fact]
119 | public void Period_BitstreamSwitching()
120 | {
121 | Assert.False(mpd.Periods.First().BitstreamSwitching);
122 | }
123 |
124 | [Fact]
125 | public void Period_AdaptationSets_Count()
126 | {
127 | Assert.Equal(2, mpd.Periods.First().AdaptationSets.Count());
128 | }
129 |
130 | [Fact]
131 | public void Period_AdaptationSets_0_Id()
132 | {
133 | Assert.Null(mpd.Periods.First().AdaptationSets.First().Id);
134 | }
135 |
136 | [Fact]
137 | public void Period_AdaptationSets_0_Group()
138 | {
139 | Assert.Null(mpd.Periods.First().AdaptationSets.First().Group);
140 | }
141 |
142 | [Fact]
143 | public void Period_AdaptationSets_0_Lang()
144 | {
145 | Assert.Null(mpd.Periods.First().AdaptationSets.First().Lang);
146 | }
147 |
148 | [Fact]
149 | public void Period_AdaptationSets_0_ContentType()
150 | {
151 | Assert.Equal("video/mp4", mpd.Periods.First().AdaptationSets.First().ContentType);
152 | }
153 |
154 | [Fact]
155 | public void Period_AdaptationSets_0_Par()
156 | {
157 | Assert.Equal("1:1", mpd.Periods.First().AdaptationSets.First().Par.RawValue);
158 | }
159 |
160 | [Fact]
161 | public void Period_AdaptationSets_0_MinBandwidth()
162 | {
163 | Assert.Null(mpd.Periods.First().AdaptationSets.First().MinBandwidth);
164 | }
165 |
166 | [Fact]
167 | public void Period_AdaptationSets_0_MaxBandwidth()
168 | {
169 | Assert.Null(mpd.Periods.First().AdaptationSets.First().MaxBandwidth);
170 | }
171 |
172 | [Fact]
173 | public void Period_AdaptationSets_0_MinWidth()
174 | {
175 | Assert.Null(mpd.Periods.First().AdaptationSets.First().MinWidth);
176 | }
177 |
178 | [Fact]
179 | public void Period_AdaptationSets_0_MaxWidth()
180 | {
181 | Assert.Equal(1920u, mpd.Periods.First().AdaptationSets.First().MaxWidth);
182 | }
183 |
184 | [Fact]
185 | public void Period_AdaptationSets_0_MinHeight()
186 | {
187 | Assert.Null(mpd.Periods.First().AdaptationSets.First().MinHeight);
188 | }
189 |
190 | [Fact]
191 | public void Period_AdaptationSets_0_MaxHeight()
192 | {
193 | Assert.Equal(1080u, mpd.Periods.First().AdaptationSets.First().MaxHeight);
194 | }
195 |
196 | [Fact]
197 | public void Period_AdaptationSets_0_MinFrameRate()
198 | {
199 | Assert.Null(mpd.Periods.First().AdaptationSets.First().MinFrameRate);
200 | }
201 |
202 | [Fact]
203 | public void Period_AdaptationSets_0_MaxFrameRate()
204 | {
205 | Assert.Equal("30000/1001", mpd.Periods.First().AdaptationSets.First().MaxFrameRate.RawValue);
206 | }
207 |
208 | [Fact]
209 | public void Period_AdaptationSets_0_SegmentAlignment()
210 | {
211 | Assert.True(mpd.Periods.First().AdaptationSets.First().SegmentAlignment);
212 | }
213 |
214 | [Fact]
215 | public void Period_AdaptationSets_0_BitstreamSwitching()
216 | {
217 | Assert.False(mpd.Periods.First().AdaptationSets.First().BitstreamSwitching);
218 | }
219 |
220 | [Fact]
221 | public void Period_AdaptationSets_0_SubsegmentAlignment()
222 | {
223 | Assert.False(mpd.Periods.First().AdaptationSets.First().SubsegmentAlignment);
224 | }
225 |
226 | [Fact]
227 | public void Period_AdaptationSets_0_SubsegmentStartsWithSAP()
228 | {
229 | Assert.Equal(1u, mpd.Periods.First().AdaptationSets.First().SubsegmentStartsWithSAP);
230 | }
231 | }
232 | }
233 |
--------------------------------------------------------------------------------
/DashTools.Tests/MpdDownloaderTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using Xunit;
5 |
6 | namespace Qoollo.MpegDash.Tests
7 | {
8 | public class MpdDownloaderTests : IClassFixture
9 | {
10 | private MediaPresentationDescription mpd;
11 |
12 | public MpdDownloaderTests(MpdFixture mpdFixture)
13 | {
14 | this.mpd = mpdFixture.Mpd;
15 | }
16 |
17 | [Fact]
18 | public void Download()
19 | {
20 | // arrange
21 | //var dir = new DirectoryInfo("envivio");
22 | //if (dir.Exists)
23 | // dir.Delete(recursive: true);
24 | //var downloader = new MpdDownloader(new Uri("http://dash.edgesuite.net/envivio/EnvivioDash3/manifest.mpd"), dir.FullName);
25 |
26 | //// act
27 | //var task = downloader.Download();
28 | //task.Wait();
29 | //var actual = task.Result;
30 |
31 | // assert
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/DashTools.Tests/MpdFixture.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace Qoollo.MpegDash.Tests
9 | {
10 | public class MpdFixture : IDisposable
11 | {
12 | public MpdFixture()
13 | {
14 | Stream = File.OpenRead("envivio.mpd");
15 | Mpd = new MediaPresentationDescription(Stream);
16 | }
17 |
18 | public void Dispose()
19 | {
20 | Stream.Dispose();
21 | }
22 |
23 | public Stream Stream { get; private set; }
24 |
25 | public MediaPresentationDescription Mpd { get; private set; }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/DashTools.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("DashTools.Tests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("DashTools.Tests")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("17d61727-c15b-4329-ac4a-381d174e76eb")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/DashTools.Tests/envivio.mpd:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/DashTools.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/DashTools/ArrayExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Qoollo.MpegDash
7 | {
8 | internal static class ArrayExtensions
9 | {
10 | ///
11 | /// Checks whether first array starts with second array.
12 | ///
13 | ///
14 | ///
15 | ///
16 | ///
17 | public static bool StartsWith(this T[] first, T[] second)
18 | where T: IComparable
19 | {
20 | bool res = true;
21 | for (int i = 0; i < second.Length && res; i++)
22 | {
23 | res = first[i].CompareTo(second[i]) == 0;
24 | }
25 | return res;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/DashTools/AspectRatio.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Qoollo.MpegDash
4 | {
5 | public class AspectRatio
6 | {
7 | public AspectRatio(string value)
8 | {
9 | if (string.IsNullOrWhiteSpace(value))
10 | throw new ArgumentNullException(nameof(value));
11 |
12 | RawValue = value;
13 | X = double.Parse(value.Split(':')[0]);
14 | Y = double.Parse(value.Split(':')[1]);
15 | }
16 |
17 | public double X { get; }
18 |
19 | public double Y { get; }
20 |
21 | public string RawValue { get; }
22 | }
23 | }
--------------------------------------------------------------------------------
/DashTools/DashTools.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {D517B927-7AFC-42AD-A410-27354F3217C2}
8 | Library
9 | Properties
10 | Qoollo.MpegDash
11 | DashTools
12 | v4.0
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
75 |
--------------------------------------------------------------------------------
/DashTools/FrameRate.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Qoollo.MpegDash
7 | {
8 | public class FrameRate
9 | {
10 | public FrameRate(string value)
11 | {
12 | if (string.IsNullOrWhiteSpace(value))
13 | throw new ArgumentNullException(nameof(value));
14 |
15 | RawValue = value;
16 | }
17 |
18 | public string RawValue { get; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/DashTools/MediaPresentationDescription.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Net;
6 | using System.Xml;
7 | using System.Xml.Linq;
8 |
9 | namespace Qoollo.MpegDash
10 | {
11 | public class MediaPresentationDescription : IDisposable
12 | {
13 | private readonly Stream stream;
14 |
15 | private readonly bool streamIsOwned;
16 |
17 | private readonly Lazy mpdTag;
18 |
19 | private readonly Lazy helper;
20 |
21 | public MediaPresentationDescription(Stream mpdStream)
22 | : this(mpdStream, false)
23 | {
24 | this.baseURL = new Lazy(ParseBaseURL);
25 | }
26 |
27 | public MediaPresentationDescription(string mpdFilePath)
28 | : this(File.OpenRead(mpdFilePath), true)
29 | {
30 | this.baseURL = new Lazy(ParseBaseURL);
31 | }
32 |
33 | private MediaPresentationDescription(Stream mpdStream, bool streamIsOwned)
34 | {
35 | stream = mpdStream;
36 | this.streamIsOwned = streamIsOwned;
37 |
38 | mpdTag = new Lazy(ReadMpdTag);
39 | fetchTime = new Lazy(() => { var v = mpdTag.Value; return DateTimeOffset.Now; });
40 | helper = new Lazy(() => new XmlAttributeParseHelper(mpdTag.Value));
41 | periods = new Lazy>(ParsePeriods);
42 | }
43 |
44 | public static MediaPresentationDescription FromUrl(Uri url, string saveFilePath = null)
45 | {
46 | if (saveFilePath == null)
47 | saveFilePath = Path.GetTempFileName();
48 | using (var client = new WebClient())
49 | {
50 | client.DownloadFile(url, saveFilePath);
51 | return new MediaPresentationDescription(saveFilePath);
52 | }
53 | }
54 |
55 | public DateTimeOffset FetchTime
56 | {
57 | get { return fetchTime.Value; }
58 | }
59 | private readonly Lazy fetchTime;
60 |
61 | public string Id
62 | {
63 | get { return mpdTag.Value.Attribute("id")?.Value; }
64 | }
65 |
66 | public string Type
67 | {
68 | get { return mpdTag.Value.Attribute("type")?.Value ?? "static"; }
69 | }
70 |
71 | public string Profiles
72 | {
73 | get { return mpdTag.Value.Attribute("profiles").Value; }
74 | }
75 |
76 | public DateTimeOffset? AvailabilityStartTime
77 | {
78 | get { return helper.Value.ParseDateTimeOffset("availabilityStartTime", Type == "dynamic"); }
79 | }
80 |
81 | public DateTimeOffset? PublishTime
82 | {
83 | get { return helper.Value.ParseOptionalDateTimeOffset("publishTime"); }
84 | }
85 |
86 | public DateTimeOffset? AvailabilityEndTime
87 | {
88 | get { return helper.Value.ParseOptionalDateTimeOffset("availabilityEndTime"); }
89 | }
90 |
91 | public TimeSpan? MediaPresentationDuration
92 | {
93 | get { return helper.Value.ParseOptionalTimeSpan("mediaPresentationDuration"); }
94 | }
95 |
96 | public TimeSpan? MinimumUpdatePeriod
97 | {
98 | get { return helper.Value.ParseOptionalTimeSpan("minimumUpdatePeriod"); }
99 | }
100 |
101 | public TimeSpan MinBufferTime
102 | {
103 | get { return XmlConvert.ToTimeSpan(mpdTag.Value.Attribute("minBufferTime").Value); }
104 | }
105 |
106 | public TimeSpan? TimeShiftBufferDepth
107 | {
108 | get { return helper.Value.ParseOptionalTimeSpan("timeShiftBufferDepth"); }
109 | }
110 |
111 | public TimeSpan? SuggestedPresentationDelay
112 | {
113 | get { return helper.Value.ParseOptionalTimeSpan("suggestedPresentationDelay"); }
114 | }
115 |
116 | public TimeSpan? MaxSegmentDuration
117 | {
118 | get { return helper.Value.ParseOptionalTimeSpan("maxSegmentDuration"); }
119 | }
120 |
121 | public TimeSpan? MaxSubsegmentDuration
122 | {
123 | get { return helper.Value.ParseOptionalTimeSpan("maxSubsegmentDuration"); }
124 | }
125 |
126 | public string BaseURL
127 | {
128 | get { return baseURL.Value; }
129 | }
130 | private readonly Lazy baseURL;
131 |
132 | private string ParseBaseURL()
133 | {
134 | return mpdTag.Value.Elements()
135 | .Where(n => n.Name.LocalName == "BaseURL")
136 | .Select(n => n.Value)
137 | .FirstOrDefault();
138 | }
139 |
140 | public IEnumerable Periods
141 | {
142 | get { return periods.Value; }
143 | }
144 | private readonly Lazy> periods;
145 |
146 | public void Save(string filename)
147 | {
148 | using (var fileStream = File.OpenWrite(filename))
149 | {
150 | stream.CopyTo(fileStream);
151 | stream.Seek(0, SeekOrigin.Begin);
152 | }
153 | }
154 |
155 | private XElement ReadMpdTag()
156 | {
157 | using (var reader = XmlReader.Create(stream))
158 | {
159 | stream.Seek(0, SeekOrigin.Begin);
160 | reader.ReadToFollowing("MPD");
161 | return XNode.ReadFrom(reader) as XElement;
162 | }
163 | }
164 |
165 | private IEnumerable ParsePeriods()
166 | {
167 | return mpdTag.Value.Elements()
168 | .Where(n => n.Name.LocalName == "Period")
169 | .Select(n => new MpdPeriod(n));
170 | }
171 |
172 | #region IDisposable
173 |
174 | public void Dispose()
175 | {
176 | if (streamIsOwned)
177 | stream.Dispose();
178 | }
179 |
180 | #endregion
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/DashTools/Mp4File.cs:
--------------------------------------------------------------------------------
1 | namespace Qoollo.MpegDash
2 | {
3 | public class Mp4File
4 | {
5 | public Mp4File(string path)
6 | {
7 | this.path = path;
8 | }
9 |
10 | public string Path
11 | {
12 | get { return path; }
13 | }
14 | private readonly string path;
15 | }
16 | }
--------------------------------------------------------------------------------
/DashTools/Mp4InitFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Qoollo.MpegDash
7 | {
8 | public class Mp4InitFile : Mp4File
9 | {
10 | public Mp4InitFile(string path)
11 | :base(path)
12 | {
13 |
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/DashTools/MpdAdaptationSet.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Xml.Linq;
5 |
6 | namespace Qoollo.MpegDash
7 | {
8 | public class MpdAdaptationSet : MpdElement
9 | {
10 | internal MpdAdaptationSet(XElement node)
11 | : base(node)
12 | {
13 | this.segmentTemplate = new Lazy(ParseSegmentTemplate);
14 | this.representations = new Lazy>(ParseRepresentations);
15 | }
16 |
17 | public uint? Id
18 | {
19 | get { return helper.ParseOptionalUint("id"); }
20 | }
21 |
22 | public uint? Group
23 | {
24 | get { return helper.ParseOptionalUint("group"); }
25 | }
26 |
27 | public string Lang
28 | {
29 | get { return node.Attribute("lang")?.Value; }
30 | }
31 |
32 | public string ContentType
33 | {
34 | get
35 | {
36 | var attr = node.Attribute("contentType") ?? node.Attribute("mimeType");
37 | return attr?.Value; }
38 | }
39 |
40 | public AspectRatio Par
41 | {
42 | get { return helper.ParseOptionalAspectRatio("par"); }
43 | }
44 |
45 | public uint? MinBandwidth
46 | {
47 | get { return helper.ParseOptionalUint("minBandwidth"); }
48 | }
49 |
50 | public uint? MaxBandwidth
51 | {
52 | get { return helper.ParseOptionalUint("maxBandwidth"); }
53 | }
54 |
55 | public uint? MinWidth
56 | {
57 | get { return helper.ParseOptionalUint("minWidth"); }
58 | }
59 |
60 | public uint? MaxWidth
61 | {
62 | get { return helper.ParseOptionalUint("maxWidth"); }
63 | }
64 |
65 | public uint? MinHeight
66 | {
67 | get { return helper.ParseOptionalUint("minHeight"); }
68 | }
69 |
70 | public uint? MaxHeight
71 | {
72 | get { return helper.ParseOptionalUint("maxHeight"); }
73 | }
74 |
75 | public FrameRate MinFrameRate
76 | {
77 | get { return helper.ParseOptionalFrameRate("minFrameRate"); }
78 | }
79 |
80 | public FrameRate MaxFrameRate
81 | {
82 | get { return helper.ParseOptionalFrameRate("maxFrameRate"); }
83 | }
84 |
85 | public bool SegmentAlignment
86 | {
87 | get { return helper.ParseOptionalBool("segmentAlignment", false); }
88 | }
89 |
90 | public bool BitstreamSwitching
91 | {
92 | get { return helper.ParseOptionalBool("bitstreamSwitching", false); }
93 | }
94 |
95 | public bool SubsegmentAlignment
96 | {
97 | get { return helper.ParseOptionalBool("subsegmentAlignment", false); }
98 | }
99 |
100 | public uint SubsegmentStartsWithSAP
101 | {
102 | get
103 | {
104 | var value = helper.ParseOptionalUint("subsegmentStartsWithSAP", null)
105 | ?? helper.ParseOptionalUint("startWithSAP", null);
106 | return value.Value;
107 | }
108 | }
109 |
110 | public MpdSegmentTemplate SegmentTemplate
111 | {
112 | get { return segmentTemplate.Value; }
113 | }
114 | private readonly Lazy segmentTemplate;
115 |
116 | public IEnumerable Representations
117 | {
118 | get { return representations.Value; }
119 | }
120 | private readonly Lazy> representations;
121 |
122 | private MpdSegmentTemplate ParseSegmentTemplate()
123 | {
124 | return node.Elements()
125 | .Where(n => n.Name.LocalName == "SegmentTemplate")
126 | .Select(n => new MpdSegmentTemplate(n))
127 | .FirstOrDefault();
128 | }
129 |
130 | private IEnumerable ParseRepresentations()
131 | {
132 | return node.Elements()
133 | .Where(n => n.Name.LocalName == "Representation")
134 | .Select(n => new MpdRepresentation(n));
135 | }
136 | }
137 | }
--------------------------------------------------------------------------------
/DashTools/MpdDownloader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Net;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace Qoollo.MpegDash
11 | {
12 | public class MpdDownloader
13 | {
14 | private readonly Uri mpdUrl;
15 |
16 | private readonly string destinationDir;
17 |
18 | private readonly Lazy mpdFileName;
19 |
20 | private readonly Lazy mpd;
21 |
22 | private readonly Lazy walker;
23 |
24 | private readonly int downloadConcurrency;
25 |
26 | public MpdDownloader(Uri mpdUrl, string destinationDir, int downloadConcurrency = 2)
27 | {
28 | if (downloadConcurrency < 1)
29 | throw new ArgumentException("downloadConcurrency cannot be less than 1.", "downloadConcurrency");
30 |
31 | this.mpdUrl = mpdUrl;
32 | this.destinationDir = destinationDir;
33 | this.downloadConcurrency = downloadConcurrency;
34 |
35 | mpdFileName = new Lazy(GetMpdFileName);
36 | mpd = new Lazy(DownloadMpd);
37 | walker = new Lazy(CreateMpdWalker);
38 | }
39 |
40 | public IEnumerable