Permalink
Browse files

initial checkin.

svn path=/trunk/mooncodecs/; revision=133146
  • Loading branch information...
0 parents commit 6dc3021470fb8cb8204709670a5018e154433ac6 @atsushieno atsushieno committed Apr 30, 2009
Showing with 9,174 additions and 0 deletions.
  1. +3 −0 ChangeLog
  2. +9 −0 Makefile
  3. +15 −0 README
  4. +28 −0 csadpcm/Makefile
  5. +176 −0 csadpcm/MoonAdpcm/AdpcmMediaStreamSource.cs
  6. +59 −0 csadpcm/MoonAdpcm/MoonAdpcm.csproj
  7. +101 −0 csadpcm/MoonAdpcm/StringExtensions.cs
  8. +121 −0 csadpcm/MoonAdpcm/WaveFormatExtensible.cs
  9. +8 −0 csadpcm/MoonAdpcmTest/App.xaml
  10. +66 −0 csadpcm/MoonAdpcmTest/App.xaml.cs
  11. +75 −0 csadpcm/MoonAdpcmTest/MoonAdpcmTest.csproj
  12. +9 −0 csadpcm/MoonAdpcmTest/Page.xaml
  13. +33 −0 csadpcm/MoonAdpcmTest/Page.xaml.cs
  14. +6 −0 csadpcm/MoonAdpcmTest/Properties/AppManifest.xml
  15. +35 −0 csadpcm/MoonAdpcmTest/Properties/AssemblyInfo.cs
  16. +5 −0 csadpcm/README
  17. +299 −0 csadpcm/csadpcm/.IMA_ADPCM~.cs
  18. +299 −0 csadpcm/csadpcm/ImaAdpcm.cs
  19. +37 −0 csadpcm/csadpcm/csadpcm.csproj
  20. +54 −0 csadpcm/csadpcm/csadpcm.moonlight.csproj
  21. +33 −0 csadpcm/moonadpcm.sln
  22. +97 −0 csdirac/DiracStreamSource.cs
  23. +59 −0 csdirac/DiractTest/ArithTest.cs
  24. +134 −0 csdirac/DiractTest/DecoderTest.cs
  25. +61 −0 csdirac/DiractTest/DiractTest.csproj
  26. +89 −0 csdirac/DiractTest/GeneralTest.cs
  27. +36 −0 csdirac/DiractTest/Properties/AssemblyInfo.cs
  28. +114 −0 csdirac/DiractTest/UnpackTest.cs
  29. +73 −0 csdirac/DiractTest/Wavelet2dTest.cs
  30. +30 −0 csdirac/Makefile
  31. +19 −0 csdirac/Math/Dimension.cs
  32. +20 −0 csdirac/Math/Point.cs
  33. +65 −0 csdirac/MoonDirac.csproj
  34. +82 −0 csdirac/MoonDirac/DiracStreamSource.cs
  35. +77 −0 csdirac/MoonDiracTest.csproj
  36. +8 −0 csdirac/MoonDiracTest/App.xaml
  37. +66 −0 csdirac/MoonDiracTest/App.xaml.cs
  38. +35 −0 csdirac/MoonDiracTest/App.xaml.g.cs
  39. +9 −0 csdirac/MoonDiracTest/Page.xaml
  40. +33 −0 csdirac/MoonDiracTest/Page.xaml.cs
  41. +38 −0 csdirac/MoonDiracTest/Page.xaml.g.cs
  42. +6 −0 csdirac/MoonDiracTest/Properties/AppManifest.xml
  43. +36 −0 csdirac/Properties/AssemblyInfo.cs
  44. +39 −0 csdirac/TestResult.xml
  45. +76 −0 csdirac/csdirac.csproj
  46. +79 −0 csdirac/csdirac.moonlight.csproj
  47. +26 −0 csdirac/csdirac.sln
  48. +260 −0 csdirac/csdirac/Arithmetic.cs
  49. +197 −0 csdirac/csdirac/Block.cs
  50. +61 −0 csdirac/csdirac/Buffer.cs
  51. +64 −0 csdirac/csdirac/Cache.cs
  52. +75 −0 csdirac/csdirac/ColourSpace.cs
  53. +114 −0 csdirac/csdirac/Decoder.cs
  54. +22 −0 csdirac/csdirac/Global.cs
  55. +514 −0 csdirac/csdirac/Motion.cs
  56. +121 −0 csdirac/csdirac/Parameters.cs
  57. +348 −0 csdirac/csdirac/Picture.cs
  58. +137 −0 csdirac/csdirac/Queue.cs
  59. +11 −0 csdirac/csdirac/Slice.cs
  60. +51 −0 csdirac/csdirac/Stream.cs
  61. +208 −0 csdirac/csdirac/SubBand.cs
  62. +234 −0 csdirac/csdirac/Unpack.cs
  63. +58 −0 csdirac/csdirac/Util.cs
  64. +70 −0 csdirac/csdirac/Vector.cs
  65. +280 −0 csdirac/csdirac/VideoFormat.cs
  66. +297 −0 csdirac/csdirac/Wavelet.cs
  67. +120 −0 csdirac/csiracTest.VisualState.xml
  68. +7 −0 csdirac/csiracTest.nunit
  69. +33 −0 csdirac/moondirac.sln
  70. +8 −0 csdirac/test/App.xaml
  71. +66 −0 csdirac/test/App.xaml.cs
  72. +35 −0 csdirac/test/App.xaml.g.cs
  73. +7 −0 csdirac/test/AppManifest.xaml
  74. +9 −0 csdirac/test/Page.xaml
  75. +33 −0 csdirac/test/Page.xaml.cs
  76. +38 −0 csdirac/test/Page.xaml.g.cs
  77. BIN csdirac/test/test.g.resources
  78. +74 −0 csdirac/test/test.html
  79. +30 −0 csvorbis/Makefile
  80. +35 −0 csvorbis/Makefile.moon
  81. +77 −0 csvorbis/MoonVorbis/MoonVorbis.csproj
  82. +459 −0 csvorbis/MoonVorbis/OggMediaStreamSource.cs
  83. +101 −0 csvorbis/MoonVorbis/StringExtensions.cs
  84. +121 −0 csvorbis/MoonVorbis/WaveFormatExtensible.cs
  85. +8 −0 csvorbis/MoonVorbisTest/App.xaml
  86. +66 −0 csvorbis/MoonVorbisTest/App.xaml.cs
  87. +110 −0 csvorbis/MoonVorbisTest/MoonVorbisTest.csproj
  88. +9 −0 csvorbis/MoonVorbisTest/Page.xaml
  89. +33 −0 csvorbis/MoonVorbisTest/Page.xaml.cs
  90. +6 −0 csvorbis/MoonVorbisTest/Properties/AppManifest.xml
  91. +35 −0 csvorbis/MoonVorbisTest/Properties/AssemblyInfo.cs
  92. +82 −0 csvorbis/csogg/AssemblyInfo.cs
  93. +302 −0 csvorbis/csogg/Buffer.cs
  94. +10 −0 csvorbis/csogg/Makefile
  95. +53 −0 csvorbis/csogg/Packet.cs
  96. +140 −0 csvorbis/csogg/Page.cs
  97. +581 −0 csvorbis/csogg/StreamState.cs
  98. +289 −0 csvorbis/csogg/SyncState.cs
  99. +60 −0 csvorbis/csogg/csogg.csproj
  100. +62 −0 csvorbis/csogg/csogg.moonlight.csproj
  101. +33 −0 csvorbis/csvorbis.sln
  102. +42 −0 csvorbis/moonvorbis.sln
@@ -0,0 +1,3 @@
+2009-04-30 Atsushi Enomoto <atsushi@ximian.com>
+
+ Initial checkin.
@@ -0,0 +1,9 @@
+all:
+ (cd csvorbis; make -f Makefile.moon) || exit
+ (cd csadpcm; make) || exit
+ (cd csdirac; make) || exit
+
+clean:
+ (cd csvorbis; make -f Makefile.moon clean) || exit
+ (cd csadpcm; make clean) || exit
+ (cd csdirac; make clean) || exit
15 README
@@ -0,0 +1,15 @@
+This is a collection of managed custom media codecs for Moonlight 2.0
+and Silverlight 3.0 (both not at final release in April 2009 yet.)
+
+There are three codecs so far:
+
+ - Ogg Vorbis, based on csvorbis by Marc Crichton.
+ http://anonsvn.mono-project.com/viewvc/trunk/csvorbis/
+ - Dirac, based on csdirac by Olivier Dufour.
+ http://anonsvn.mono-project.com/viewvc/trunk/csdirac/
+ - IMA ADPCM, based on the work by n7shi
+ ( http://d.hatena.ne.jp/n7shi/20090329/1238322010 )
+
+For moonlight custom media support details, see:
+http://veritas-vos-liberabit.com/monogatari/2009/03/moonvorbis.html
+
@@ -0,0 +1,28 @@
+
+ADPCM_SRC = \
+ csadpcm/ImaAdpcm.cs \
+ MoonAdpcm/AdpcmMediaStreamSource.cs \
+ MoonAdpcm/WaveFormatExtensible.cs \
+ MoonAdpcm/StringExtensions.cs
+
+ADPCM_TEST_SRC = \
+ MoonAdpcmTest/App.xaml \
+ MoonAdpcmTest/App.xaml.cs \
+ MoonAdpcmTest/Page.xaml \
+ MoonAdpcmTest/Page.xaml.cs
+
+all: build/MoonAdpcmTest.xap
+
+build/MoonAdpcmTest.xap: build/MoonAdpcm.dll $(ADPCM_TEST_SRC)
+ cp MoonAdpcmTest/*.xaml build
+ cp MoonAdpcmTest/*.xaml.cs build
+ cp MoonAdpcmTest/Properties/AppManifest.xml build/AppManifest.xaml
+ cd build; mxap --application-name=MoonAdpcmTest; cd ..
+
+build/MoonAdpcm.dll: $(ADPCM_SRC)
+ smcs -t:library -out:MoonAdpcm.dll -debug $(ADPCM_SRC)
+ mv MoonAdpcm.dll build
+ mv MoonAdpcm.dll.mdb build
+
+clean:
+ rm build/*
@@ -0,0 +1,176 @@
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Globalization;
+using System.IO;
+using System.Text;
+using System.Windows.Media;
+using MediaParsers;
+using csadpcm;
+
+namespace MoonAdpcm
+{
+ class DebugWriter : TextWriter
+ {
+ public override Encoding Encoding
+ {
+ get { return Encoding.UTF8; }
+ }
+
+ public override void WriteLine ()
+ {
+ Debug.WriteLine (String.Empty);
+ }
+
+ public override void WriteLine (string s)
+ {
+ Debug.WriteLine (s);
+ }
+ }
+
+ public class AdpcmMediaStreamSource : MediaStreamSource
+ {
+ ImaAdpcm source;
+
+// int convsize=4096*2;
+ //byte[] convbuffer=new byte[convsize]; // take 8k out of the data segment, not the stack
+// byte[] convbuffer;
+
+ TextWriter s_err = new DebugWriter(); // Console.Error;
+// Stream input;
+
+ public AdpcmMediaStreamSource (Stream input)
+ {
+ /*
+ convbuffer=new byte[convsize];
+ vb = new Block (vd);
+ if (input == null)
+ throw new ArgumentNullException ("input");
+ this.input = input;
+ */
+ source = new ImaAdpcm (input);
+ }
+
+ IEnumerable<SampleBuffer> DecodeSamples ()
+ {
+ foreach (byte [] buf in source.DecodeSamples ())
+ yield return new SampleBuffer (buf, 0, buf.Length);
+ }
+
+ struct SampleBuffer
+ {
+ byte [] buf;
+ int index, count;
+ public SampleBuffer (byte [] buf, int index, int count)
+ {
+ this.buf = buf;
+ this.index = index;
+ this.count = count;
+ }
+
+ public byte [] Data { get { return buf; } }
+ public int Index { get { return index; } }
+ public int Count { get { return count; } }
+ }
+
+ protected override void CloseMedia ()
+ {
+ this.sample_enumerator = null;
+ s_err.WriteLine("Done.");
+ }
+
+ // FIXME: should be implemented, but can be done later.
+ protected override void SwitchMediaStreamAsync (MediaStreamDescription mediaStreamDescription)
+ {
+ throw new System.NotImplementedException();
+ // ReportSwitchMediaStreamCompleted (mediaStreamDescription);
+ }
+
+ // FIXME: should be implemented, but looks like it can be left as is
+ // just to run decoder so far.
+ protected override void SeekAsync (long seekToTime)
+ {
+ ReportSeekCompleted (seekToTime);
+ }
+
+ MediaStreamDescription audioStreamDescription;
+
+ 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>();
+
+ // Initialize the Mp3 data structures used by the Media pipeline with state from the first frame.
+ WaveFormatExtensible wfx = new WaveFormatExtensible();
+ wfx.FormatTag = 1; // PCM
+ wfx.Channels = (short) this.source.Channels;
+ wfx.SamplesPerSec = this.source.SamplesPerSec;
+ wfx.BlockAlign = (short) (this.source.Channels * 2);
+ wfx.BitsPerSample = 16;
+ wfx.AverageBytesPerSecond = wfx.SamplesPerSec * wfx.Channels * 2;
+ wfx.Size = 0;
+
+ mediaStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = wfx.ToHexString();
+ this.audioStreamDescription = new MediaStreamDescription(MediaStreamType.Audio, mediaStreamAttributes);
+
+ mediaStreamDescriptions.Add(this.audioStreamDescription);
+
+ // <note>This part is mere copy of Mp3MediaStreamSource:
+ // 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(0).Ticks.ToString (CultureInfo.InvariantCulture);
+ mediaSourceAttributes[MediaSourceAttributesKeys.CanSeek] = false.ToString ();
+ // </note>
+
+ sample_enumerator = this.DecodeSamples ().GetEnumerator ();
+ this.ReportOpenMediaCompleted(mediaSourceAttributes, mediaStreamDescriptions);
+ }
+
+ Dictionary<MediaSampleAttributeKeys, string> emptyDict = new Dictionary<MediaSampleAttributeKeys, string>();
+ IEnumerator<SampleBuffer> sample_enumerator;
+
+ protected override void GetSampleAsync (MediaStreamType mediaStreamType)
+ {
+ MediaStreamSample audioSample = null;
+
+ if (!sample_enumerator.MoveNext ())
+ {
+ // If you are near the end of the file, return a null stream, which
+ // tells the MediaStreamSource and MediaElement to close down.
+ audioSample = new MediaStreamSample(
+ this.audioStreamDescription,
+ null,
+ 0,
+ 0,
+ 0,
+ emptyDict);
+ this.ReportGetSampleCompleted(audioSample);
+ }
+ else
+ {
+ // FIXME: Stream should not be created every time.
+ SampleBuffer buf = (SampleBuffer) sample_enumerator.Current;
+ audioSample = new MediaStreamSample(
+ this.audioStreamDescription,
+ new MemoryStream (buf.Data, buf.Index, buf.Count, false),
+ buf.Index,
+ buf.Count,
+ timePosition,
+ emptyDict);
+ timePosition += buf.Count * 10000000 / (44100 * 2 * 2);
+ this.ReportGetSampleCompleted(audioSample);
+ }
+ }
+ long timePosition;
+
+ // FIXME: should be implemented, but can be done later.
+ protected override void GetDiagnosticAsync (MediaStreamSourceDiagnosticKind diagnosticKind)
+ {
+ throw new System.NotImplementedException();
+ // ReportGetDiagnosticCompleted(diagnosticKind, diagnosticValue);
+ }
+ }
+}
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{A4D1AB0C-25BA-4E7D-9510-76BB4BA1D78B}</ProjectGuid>
+ <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <OutputType>Library</OutputType>
+ <SilverlightApplication>false</SilverlightApplication>
+ <ValidateXaml>true</ValidateXaml>
+ <ThrowErrorsInValidation>false</ThrowErrorsInValidation>
+ <AssemblyName>AdpcmMediaStreamSource</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>none</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System.Windows" />
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Net" />
+ <Reference Include="System.Windows.Browser" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v2.0\Microsoft.Silverlight.CSharp.targets" />
+ <ProjectExtensions>
+ <MonoDevelop>
+ <Properties InternalTargetFrameworkVersion="2.1" />
+ </MonoDevelop>
+ </ProjectExtensions>
+ <ItemGroup>
+ <Compile Include="AdpcmMediaStreamSource.cs" />
+ <Compile Include="StringExtensions.cs" />
+ <Compile Include="WaveFormatExtensible.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\csadpcm\csadpcm.moonlight.csproj">
+ <Project>{1F3AC0CD-1994-4D37-BF94-C2359C3B5E68}</Project>
+ <Name>csadpcm.moonlight</Name>
+ </ProjectReference>
+ </ItemGroup>
+</Project>
@@ -0,0 +1,101 @@
+//-----------------------------------------------------------------------
+// <copyright file="StringExtensions.cs" company="Larry Olson">
+// (c) Copyright Larry Olson.
+// This source is subject to the Microsoft Public License (Ms-PL)
+// See http://code.msdn.microsoft.com/ManagedMediaHelpers/Project/License.aspx
+// All other rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+// Supressing Code Analysis rule(s)
+[module: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes",
+ Scope = "namespace",
+ Target = "ExtensionMethods",
+ Justification = "This is appropriate as a separate namespace because it logically is separate from the ManagedMediaParsers namespace.")]
+
+[module: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes",
+ Scope = "member",
+ Target = "ExtensionMethods.StringExtensions.#ToLittleEndian(System.String)",
+ Justification = "This is appropriate to make this method look like a first class member of string.")]
+
+namespace ExtensionMethods
+{
+ using System;
+
+ /// <summary>
+ /// Extensions for the standard string class.
+ /// </summary>
+ public static class StringExtensions
+ {
+ /// <summary>
+ /// <para>
+ /// Converts a string of characters from Big Endian byte order to
+ /// Little Endian byte order.
+ /// </para>
+ /// <para>
+ /// Assumptions this makes about the string. Every two characters
+ /// make up the smallest data unit (analogous to byte). The entire
+ /// string is the size of the systems natural unit of data (analogous
+ /// to a word).
+ /// </para>
+ /// </summary>
+ /// <param name="value">
+ /// A string in Big Endian Byte order.
+ /// </param>
+ /// <returns>
+ /// A string in Little Endian Byte order.
+ /// </returns>
+ /// <remarks>
+ /// This function was designed to take in a Big Endian string of
+ /// hexadecimal digits.
+ /// <example>
+ /// input:
+ /// DEADBEEF
+ /// output:
+ /// EFBEADDE
+ /// </example>
+ /// </remarks>
+ public static string ToLittleEndian(this string value)
+ {
+ // Guard
+ if (value == null)
+ {
+ throw new NullReferenceException();
+ }
+
+ char[] bigEndianChars = value.ToCharArray();
+
+ // Guard
+ if (bigEndianChars.Length % 2 != 0)
+ {
+ return string.Empty;
+ }
+
+ int i, ai, bi, ci, di;
+ char a, b, c, d;
+
+ for (i = 0; i < bigEndianChars.Length / 2; i += 2)
+ {
+ // front byte ( in hex )
+ ai = i;
+ bi = i + 1;
+
+ // back byte ( in hex )
+ ci = bigEndianChars.Length - 2 - i;
+ di = bigEndianChars.Length - 1 - i;
+
+ a = bigEndianChars[ai];
+ b = bigEndianChars[bi];
+ c = bigEndianChars[ci];
+ d = bigEndianChars[di];
+
+ bigEndianChars[ci] = a;
+ bigEndianChars[di] = b;
+ bigEndianChars[ai] = c;
+ bigEndianChars[bi] = d;
+ }
+
+ return new string(bigEndianChars);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 6dc3021

Please sign in to comment.