bug fixes

This commit is contained in:
chudov
2010-04-16 04:30:51 +00:00
parent a866b79341
commit 08722c0255
46 changed files with 1990 additions and 420 deletions

View File

@@ -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.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8FC5DA7C-F6AC-4D04-85BC-1233DDF569E7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CUETools.Codecs.Icecast</RootNamespace>
<AssemblyName>CUETools.Codecs.Icecast</AssemblyName>
<TargetFrameworkVersion>v2.0</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="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IcecastWriter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CUETools.Codecs.LAME\CUETools.Codecs.LAME.csproj">
<Project>{1AF02E2C-2CB2-44B5-B417-37653071FEC6}</Project>
<Name>CUETools.Codecs.LAME</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\CUETools.Codecs\CUETools.Codecs.csproj">
<Project>{6458A13A-30EF-45A9-9D58-E5031B17BEE2}</Project>
<Name>CUETools.Codecs</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>

View File

@@ -0,0 +1,264 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Web;
using CUETools.Codecs;
namespace CUETools.Codecs.Icecast
{
public class IcecastWriter: IAudioDest
{
private long _sampleOffset = 0;
private AudioPCMConfig pcm = AudioPCMConfig.RedBook;
private LAME.LAMEEncoderCBR encoder = null;
private HttpWebRequest req = null;
private HttpWebResponse resp = null;
private Stream reqStream;
private IcecastSettingsData settings = null;
public IAudioDest Encoder
{
get
{
return encoder;
}
}
public IcecastWriter(AudioPCMConfig pcm, IcecastSettingsData settings)
{
this.pcm = pcm;
this.settings = settings;
}
#region IAudioDest Members
public HttpWebResponse Response
{
get
{
return resp;
}
}
public void Connect()
{
Uri uri = new Uri("http://" + settings.Server + ":" + settings.Port + settings.Mount);
req = (HttpWebRequest)WebRequest.Create(uri);
//req.Proxy = proxy;
//req.UserAgent = userAgent;
req.ProtocolVersion = HttpVersion.Version10; // new Version("ICE/1.0");
req.Method = "SOURCE";
req.ContentType = "audio/mpeg";
req.Headers.Add("ice-name", settings.Name ?? "no name");
req.Headers.Add("ice-public", "1");
if ((settings.Url ?? "") != "") req.Headers.Add("ice-url", settings.Url);
if ((settings.Genre ?? "") != "") req.Headers.Add("ice-genre", settings.Genre);
if ((settings.Desctiption ?? "") != "") req.Headers.Add("ice-description", settings.Desctiption);
req.Headers.Add("Authorization", string.Format("Basic {0}", Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("source:{0}", settings.Password)))));
req.Timeout = System.Threading.Timeout.Infinite;
req.ReadWriteTimeout = System.Threading.Timeout.Infinite;
//req.ContentLength = 999999999;
req.KeepAlive = false;
req.SendChunked = true;
req.AllowWriteStreamBuffering = false;
req.CachePolicy = new System.Net.Cache.HttpRequestCachePolicy(System.Net.Cache.HttpRequestCacheLevel.BypassCache);
System.Reflection.PropertyInfo pi = typeof(ServicePoint).GetProperty("HttpBehaviour", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
pi.SetValue(req.ServicePoint, pi.PropertyType.GetField("Unknown").GetValue(null), null);
reqStream = req.GetRequestStream();
System.Reflection.FieldInfo fi = reqStream.GetType().GetField("m_HttpWriteMode", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
fi.SetValue(reqStream, fi.FieldType.GetField("Buffer").GetValue(null));
System.Reflection.MethodInfo mi = reqStream.GetType().GetMethod("CallDone", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic, null, new Type[0], null);
mi.Invoke(reqStream, null);
try
{
resp = req.GetResponse() as HttpWebResponse;
if (resp.StatusCode == HttpStatusCode.OK)
{
encoder = new CUETools.Codecs.LAME.LAMEEncoderCBR("", reqStream, AudioPCMConfig.RedBook);
encoder.Options = settings.MP3Options;
}
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
resp = ex.Response as HttpWebResponse;
else
throw ex;
}
}
public void UpdateMetadata(string artist, string title)
{
string song = ((artist ?? "") != "" && (title ?? "") != "") ? artist + " - " + title : (title ?? "");
string metadata = "";
//if (station != "")
// metadata += "&name=" + Uri.EscapeDataString(station);
if (song != "")
metadata += "&song=" + Uri.EscapeDataString(song);
Uri uri = new Uri("http://" + settings.Server + ":" + settings.Port + "/admin/metadata?mode=updinfo&mount=" + settings.Mount + metadata);
HttpWebRequest req2 = (HttpWebRequest)WebRequest.Create(uri);
req2.Method = "GET";
req2.Credentials = new NetworkCredential("source", settings.Password);
//req.Proxy = proxy;
//req.UserAgent = userAgent;
//req2.Headers.Add("Authorization", string.Format("Basic {0}", Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("source:{0}", settings.Password)))));
HttpStatusCode accResult = HttpStatusCode.OK;
try
{
HttpWebResponse resp = (HttpWebResponse)req2.GetResponse();
accResult = resp.StatusCode;
if (accResult == HttpStatusCode.OK)
{
}
resp.Close();
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
accResult = ((HttpWebResponse)ex.Response).StatusCode;
else
accResult = HttpStatusCode.BadRequest;
}
}
public void Close()
{
if (encoder != null)
{
encoder.Close();
encoder = null;
}
if (reqStream != null)
{
reqStream.Close();
reqStream = null;
}
if (resp != null)
{
resp.Close();
resp = null;
}
if (req != null)
{
req.Abort();
req = null;
}
}
public void Delete()
{
if (encoder != null)
{
encoder.Delete();
encoder = null;
}
if (reqStream != null)
{
reqStream.Close();
reqStream = null;
}
if (resp != null)
{
resp.Close();
resp = null;
}
if (req != null)
{
req.Abort();
req = null;
}
}
AudioBuffer tmp;
public void Write(AudioBuffer src)
{
if (encoder == null)
throw new Exception("not connected");
if (tmp == null || tmp.Size < src.Size)
tmp = new AudioBuffer(AudioPCMConfig.RedBook, src.Size);
tmp.Prepare(-1);
Buffer.BlockCopy(src.Float, 0, tmp.Float, 0, src.Length * 8);
tmp.Length = src.Length;
encoder.Write(tmp);
}
public long Position
{
get
{
return _sampleOffset;
}
}
public long BlockSize
{
set { }
}
public long FinalSampleCount
{
set { ; }
}
public int CompressionLevel
{
get { return 0; }
set { }
}
public string Options
{
set
{
if (value == null || value == "") return;
throw new Exception("Unsupported options " + value);
}
}
public AudioPCMConfig PCM
{
get { return pcm; }
}
public string Path { get { return null; } }
#endregion
public long BytesWritten
{
get
{
return encoder == null ? 0 : encoder.BytesWritten;
}
}
}
public class IcecastSettingsData
{
private string server;
private string port = "8000";
private string password;
private string mount;
private string name;
private string description;
private string url;
private string genre;
private string mp3Options = "-m j -b 192";
public string Server { get { return server; } set { server = value; } }
public string Port { get { return port; } set { port = value; } }
public string Password { get { return password; } set { password = value; } }
public string Mount { get { return mount; } set { mount = value; } }
public string Name { get { return name; } set { name = value; } }
public string Desctiption { get { return description; } set { description = value; } }
public string Url { get { return url; } set { url = value; } }
public string Genre { get { return genre; } set { genre = value; } }
public string MP3Options { get { return mp3Options; } set { mp3Options = value; } }
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CUETools.Codecs.Icecast")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("CUETools.Codecs.Icecast")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("913f32e1-64c8-45d3-8f91-5dd1ba733fe9")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]