Пример #1
0
		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.Settings as CUETools.Codecs.LAME.LAMEEncoderCBRSettings).StereoMode = settings.JointStereo ? 
						CUETools.Codecs.LAME.Interop.MpegMode.JOINT_STEREO : CUETools.Codecs.LAME.Interop.MpegMode.STEREO;
					(encoder.Settings as CUETools.Codecs.LAME.LAMEEncoderCBRSettings).CustomBitrate = settings.Bitrate;
				}
			}
			catch (WebException ex)
			{
				if (ex.Status == WebExceptionStatus.ProtocolError)
					resp = ex.Response as HttpWebResponse;
				else
					throw ex;
			}
		}
Пример #2
0
		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;
			}
		}