Permalink
Browse files

Initial import of csdirac

svn path=/trunk/csdirac/; revision=130937
  • Loading branch information...
0 parents commit 745ca298b5529bb29e33dfec50f6f0300a39edc1 Olivier Dufour committed Apr 3, 2009
Showing with 15,420 additions and 0 deletions.
  1. +82 −0 DiracStreamSource.cs
  2. +59 −0 DiractTest/ArithTest.cs
  3. +134 −0 DiractTest/DecoderTest.cs
  4. +61 −0 DiractTest/DiractTest.csproj
  5. +89 −0 DiractTest/GeneralTest.cs
  6. +36 −0 DiractTest/Properties/AssemblyInfo.cs
  7. +114 −0 DiractTest/UnpackTest.cs
  8. +73 −0 DiractTest/Wavelet2dTest.cs
  9. BIN DiractTest/bin/Debug/DiractTest.dll
  10. BIN DiractTest/bin/Debug/DiractTest.pdb
  11. BIN DiractTest/bin/Debug/csdirac.dll
  12. BIN DiractTest/bin/Debug/csdirac.pdb
  13. BIN DiractTest/bin/Debug/nunit.framework.dll
  14. +5,622 −0 DiractTest/bin/Debug/nunit.framework.xml
  15. BIN DiractTest/bin/Release/DiractTest.dll
  16. BIN DiractTest/bin/Release/DiractTest.pdb
  17. BIN DiractTest/bin/Release/System.Core.dll
  18. BIN DiractTest/bin/Release/System.Net.dll
  19. BIN DiractTest/bin/Release/System.Runtime.Serialization.dll
  20. BIN DiractTest/bin/Release/System.Windows.dll
  21. BIN DiractTest/bin/Release/csdirac.dll
  22. BIN DiractTest/bin/Release/csdirac.pdb
  23. BIN DiractTest/bin/Release/nunit.framework.dll
  24. +5,622 −0 DiractTest/bin/Release/nunit.framework.xml
  25. +9 −0 DiractTest/obj/Debug/DiractTest.csproj.FileListAbsolute.txt
  26. BIN DiractTest/obj/Debug/DiractTest.dll
  27. BIN DiractTest/obj/Debug/DiractTest.pdb
  28. BIN DiractTest/obj/Debug/ResolveAssemblyReference.cache
  29. +13 −0 DiractTest/obj/Release/DiractTest.csproj.FileListAbsolute.txt
  30. BIN DiractTest/obj/Release/DiractTest.dll
  31. BIN DiractTest/obj/Release/DiractTest.pdb
  32. BIN DiractTest/obj/Release/ResolveAssemblyReference.cache
  33. +19 −0 Math/Dimension.cs
  34. +20 −0 Math/Point.cs
  35. +36 −0 Properties/AssemblyInfo.cs
  36. +39 −0 TestResult.xml
  37. BIN bin/Debug/csdirac.dll
  38. BIN bin/Debug/csdirac.pdb
  39. BIN bin/Release/System.Core.dll
  40. BIN bin/Release/System.Net.dll
  41. BIN bin/Release/System.Runtime.Serialization.dll
  42. BIN bin/Release/System.Windows.dll
  43. BIN bin/Release/csdirac.dll
  44. BIN bin/Release/csdirac.pdb
  45. +76 −0 csdirac.csproj
  46. +1 −0 csdirac.csproj.user
  47. +26 −0 csdirac.sln
  48. BIN csdirac.suo
  49. +260 −0 csdirac/Arithmetic.cs
  50. +197 −0 csdirac/Block.cs
  51. +61 −0 csdirac/Buffer.cs
  52. +64 −0 csdirac/Cache.cs
  53. +75 −0 csdirac/ColourSpace.cs
  54. +114 −0 csdirac/Decoder.cs
  55. +22 −0 csdirac/Global.cs
  56. +514 −0 csdirac/Motion.cs
  57. +121 −0 csdirac/Parameters.cs
  58. +369 −0 csdirac/Picture.cs
  59. +137 −0 csdirac/Queue.cs
  60. +11 −0 csdirac/Slice.cs
  61. +51 −0 csdirac/Stream.cs
  62. +208 −0 csdirac/SubBand.cs
  63. +234 −0 csdirac/Unpack.cs
  64. +58 −0 csdirac/Util.cs
  65. +70 −0 csdirac/Vector.cs
  66. +280 −0 csdirac/VideoFormat.cs
  67. +297 −0 csdirac/Wavelet.cs
  68. +120 −0 csiracTest.VisualState.xml
  69. +7 −0 csiracTest.nunit
  70. +5 −0 obj/Debug/csdirac.csproj.FileListAbsolute.txt
  71. BIN obj/Debug/csdirac.dll
  72. BIN obj/Debug/csdirac.pdb
  73. BIN obj/Release/Refactor/csdirac.dll
  74. BIN obj/Release/ResolveAssemblyReference.cache
  75. +14 −0 obj/Release/csdirac.csproj.FileListAbsolute.txt
  76. BIN obj/Release/csdirac.dll
  77. BIN obj/Release/csdirac.pdb
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Media;
+using System.IO;
+using System.Globalization;
+
+
+namespace csdirac
+{
+ public class DiracStreamSource : MediaStreamSource
+ {
+ public DiracStreamSource(Stream videoStream)
+ {
+ this.videoStream = videoStream;
+ }
+
+ protected override void CloseMedia()
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override void GetDiagnosticAsync(MediaStreamSourceDiagnosticKind diagnosticKind)
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override void GetSampleAsync(MediaStreamType mediaStreamType)
+ {
+ throw new NotImplementedException();
+ }
+ private MediaStreamDescription streamDescription;
+ private Stream videoStream;
+
+ protected override void OpenMediaAsync()
+ {
+ // Initialize data structures to pass to the Media pipeline via the MediaStreamSource
+ Dictionary<MediaSourceAttributesKeys, string> mediaSourceAttributes = new Dictionary<MediaSourceAttributesKeys, string>();
+ Dictionary<MediaStreamAttributeKeys, string> mediaStreamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
+ List<MediaStreamDescription> mediaStreamDescriptions = new List<MediaStreamDescription>();
+
+ // Pull in the entire Audio stream.
+ byte[] videoData = new byte[this.videoStream.Length];
+ if (videoData.Length != this.videoStream.Read(videoData, 0, videoData.Length))
+ {
+ throw new IOException("Could not read in the VideoStream");
+ }
+ //TODO parse until first frame
+ //todo find what is the offset of first frame and put it in push len param
+ org.diracvideo.Jirac.Decoder dec = new org.diracvideo.Jirac.Decoder();
+ dec.Push(videoData, 0, videoData.Length);
+ dec.Decode();
+
+ mediaStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = dec.format.ToString();
+ this.streamDescription = new MediaStreamDescription(MediaStreamType.Video, mediaStreamAttributes);
+
+ mediaStreamDescriptions.Add(streamDescription);
+
+ // Setting a 0 duration to avoid the math to calcualte the Mp3 file length in minutes and seconds.
+ // This was done just to simplify this initial version of the code for other people reading it.
+ mediaSourceAttributes[MediaSourceAttributesKeys.Duration] = TimeSpan.FromMinutes(5).Ticks.ToString(CultureInfo.InvariantCulture);
+ mediaSourceAttributes[MediaSourceAttributesKeys.CanSeek] = "0";
+
+ // Report that the DiracMediaStreamSource has finished initializing its internal state and can now
+ // pass in Dirac Samples.
+ this.ReportOpenMediaCompleted(mediaSourceAttributes, mediaStreamDescriptions);
+
+ //this.currentFrameStartPosition = result;
+ //this.currentFrameSize = mpegLayer3Frame.FrameSize;
+ }
+
+ protected override void SeekAsync(long seekToTime)
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override void SwitchMediaStreamAsync(MediaStreamDescription mediaStreamDescription)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
@@ -0,0 +1,59 @@
+using org.diracvideo.Jirac;
+using System;
+using System.IO;
+using NUnit.Framework;
+using System.Collections.Generic;
+namespace org.diracvideo.Jirac.Test
+{
+ /** A test for the arithmetic decoder.
+ *
+ * Decodes a arithmetic encoded file from arith_file */
+
+ [TestFixture]
+ public class ArithTest {
+ [Test]
+ public void main() {
+ //TODO dialogue to ask string
+ string[] a = new string[0];
+ FileStream input = TryOpen(a);
+ byte[] d = new byte[input.Length];
+ input.Read(d, 0, (int)input.Length);
+ input.Close();
+ input.Dispose();
+ Arithmetic ar = new Arithmetic(d);
+ TestArithmetic(ar);
+ }
+
+ private FileStream TryOpen(String[] a)
+ {
+ for(int i = 0; i < a.Length; i++) {
+ if (File.Exists(a[i]))
+ {
+ return File.Open(a[i], FileMode.Open);
+ }
+ }
+ List<string> files = new List<string>();
+
+ foreach(string f in Directory.GetFiles(".")) {
+ if(f.Length == f.LastIndexOf(".sundae") + 7 && File.Exists(f))
+ return new FileStream(f, FileMode.Open);
+ }
+ Console.WriteLine("No arith file was found");
+ Environment.Exit(0);
+ return null;
+ }
+
+ private void TestArithmetic(Arithmetic a) {
+ byte[] d = new byte[a.BytesLeft()];
+ for(int i = 0; i < d.Length; i++) {
+ byte c = 0;
+ for(int j = 0; j < 8; j++) {
+ c = (byte)((c << 1) | a.DecodeBit(j));
+ }
+ d[i] = c;
+ }
+ String s = System.Text.Encoding.Default.GetString(d);
+ Console.WriteLine(s);
+ }
+ }
+}
@@ -0,0 +1,134 @@
+using org.diracvideo.Jirac;
+using NUnit.Framework;
+using System.IO;
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+using System.Threading;
+
+namespace org.diracvideo.Jirac.Test
+{
+ [TestFixture]
+ public class DecoderTest {
+ [Test]
+ public void main() {
+ //TODO dialogue to ask string
+ string[] a = new string[0];
+
+ Decoder dec = new Decoder();
+ int ev = 0;
+ FileStream input = null;
+ Form win;
+ try {
+ input = tryOpen(a);
+ byte[] packet;
+ while(dec.format == null) {
+ packet = readPacket(input);
+ dec.Push(packet, 0, packet.Length);
+ }
+ ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object o) { dec.Decode(); }));
+
+ win = createWindow(dec);
+ while(input.Length > 0 && !dec.Done()) {
+ packet = readPacket(input);
+ dec.Push(packet, 0, packet.Length);
+ }
+ dec.status = Decoder.Status.DONE;
+ input.Close();
+ win.Visible = false;
+ win.Dispose();
+ } catch(Exception e) {
+ Console.WriteLine(e);
+ ev = 1;
+ } finally {
+ Environment.Exit(ev);
+ }
+ }
+
+ private byte[] readPacket(FileStream input) {
+ if(true) {
+ int read = (int)System.Math.Min(input.Length, 100);
+ byte[] packet = new byte[read];
+ input.Read(packet, 0, read);
+ return packet;
+ } else {
+ byte[] header = new byte[13];
+ input.Read(header, 0, 13);
+ Unpack u = new Unpack(header);
+ if(u.DecodeLit32() != 0x42424344) {
+ throw new IOException("Cannot parse dirac stream");
+ }
+ if(u.Bits(8) == 0x10) {
+ return header;
+ }
+ int size = u.DecodeLit32();
+ byte[] packet = new byte[size];
+ Array.Copy(header, 0, packet, 0, 13);
+ input.Read(packet, 13, size - 13);
+ return packet;
+ }
+ }
+
+
+ private FileStream tryOpen(string[] a) {
+ foreach (string f in a)
+ {
+ if (File.Exists(f))
+ {
+ try
+ {
+ return new FileStream(f, FileMode.Open);
+ }
+ catch (IOException e)
+ {
+ Console.WriteLine(e);
+ }
+ }
+ }
+
+ foreach (string f in Directory.GetFiles("."))
+ {
+ if (f.Length == f.LastIndexOf(".drc") + 4 && File.Exists(f))
+ {
+ try
+ {
+ return new FileStream(f, FileMode.Open);
+ }
+ catch (IOException e)
+ {
+ Console.WriteLine(e);
+ }
+ }
+ }
+ Console.WriteLine("No dirac file was found");
+ Environment.Exit(0);
+ return null;
+ }
+
+ private Form createWindow(Decoder dec)
+ {
+ Form fr = new Form();
+ fr.FormClosed += new FormClosedEventHandler(delegate(object sender, FormClosedEventArgs args) { Environment.Exit(0); });
+ PictureBox b = new PictureBox();
+ b.Size = new Size(dec.format.width, dec.format.height);
+ b.Paint += new PaintEventHandler(delegate(object sender, PaintEventArgs args) {
+ //Need b.Invoke or not?
+ int wait = (1000 * dec.format.frame_rate_denominator) / dec.format.frame_rate_numerator;
+
+ Picture pic = dec.Pull();
+ while (pic.status != Decoder.Status.DONE)
+ {
+ if (pic != null &&
+ pic.error == null)
+ {
+ b.Image = pic.GetImage();
+ }
+ Thread.Sleep(wait);
+ }
+ });
+ fr.Controls.Add(b);
+ fr.Show();
+ return fr;
+ }
+ }
+}
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.21022</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{0D7DF30A-8A9B-4559-9A9F-D34DB6E8FBF2}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DiractTest</RootNamespace>
+ <AssemblyName>DiractTest</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
+ <Reference Include="System" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Windows.Forms" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ArithTest.cs" />
+ <Compile Include="DecoderTest.cs" />
+ <Compile Include="GeneralTest.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="UnpackTest.cs" />
+ <Compile Include="Wavelet2dTest.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\csdirac.csproj">
+ <Project>{9BE09FC4-05EF-450C-9852-708EB91DE326}</Project>
+ <Name>csdirac</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
Oops, something went wrong.

0 comments on commit 745ca29

Please sign in to comment.