public AVTransportLastChange(CpAVTransport cpAV, string Ident, int ID, AVTransportLastChange.ReadyHandler ReadyCallback) { //OpenSource.Utilities.InstanceTracker.Add(this); this.OnReady += ReadyCallback; InstanceID = ID.ToString(); Identifier = Ident; _cp = cpAV; _cp.OnStateVariable_LastChange += new CpAVTransport.StateVariableModifiedHandler_LastChange(LastChangeSink); _cp._subscribe(500); lock(this) { if(_cp.HasAction_GetPositionInfo) { ++StateCounter; //PollerTimeoutHandler = new LifeTimeMonitor.LifeTimeHandler(PollerTimeoutSink); //PollerTimeout.AddWeakEvent_OnExpired(PollerTimeoutHandler); _cp.GetPositionInfo((UInt32)ID,null,new CpAVTransport.Delegate_OnResult_GetPositionInfo(PositionInfoSink)); } if(_cp.HasAction_GetMediaInfo) { ++StateCounter; _cp.GetMediaInfo((UInt32)ID,null,new CpAVTransport.Delegate_OnResult_GetMediaInfo(MediaInfoSink)); } if(_cp.HasAction_GetTransportInfo) { ++StateCounter; _cp.GetTransportInfo((UInt32)ID,null,new CpAVTransport.Delegate_OnResult_GetTransportInfo(GetTransportInfoSink)); } if(_cp.HasAction_GetTransportSettings) { ++StateCounter; _cp.GetTransportSettings((UInt32)ID,null,new CpAVTransport.Delegate_OnResult_GetTransportSettings(GetTransportSettingsSink)); } } }
private void GetTransportSettingsSink(CpAVTransport sender, System.UInt32 InstanceID, CpAVTransport.Enum_CurrentPlayMode PlayMode, CpAVTransport.Enum_CurrentRecordQualityMode RecQualityMode, UPnPInvokeException e, object _Tag) { if(e==null) { _CurrentPlayMode = _cp.Enum_CurrentPlayMode_ToString(PlayMode); if(this.OnCurrentPlayModeChanged!=null) OnCurrentPlayModeChanged(this); } lock(this) { --StateCounter; if(StateCounter==0) { if(OnReady!=null)OnReady(this); } } }
protected void PositionInfoSink(CpAVTransport sender, UInt32 InstanceID, UInt32 Track, string TrackDuration, string TrackMetaData, string TrackURI, string RelTime, string AbsTime, int RelCount, int AbsCount, UPnPInvokeException e, object Handle) { DText p = new DText(); p.ATTRMARK = ":"; try { p[0] = TrackDuration; _CurrentDuration = new TimeSpan(int.Parse(p[1]),int.Parse(p[2]),int.Parse(p[3])); } catch(Exception) { } try { p[0]= RelTime; _CurrentPosition = new TimeSpan(int.Parse(p[1]),int.Parse(p[2]),int.Parse(p[3])); } catch(Exception) { } if(OnCurrentPositionChanged!=null) OnCurrentPositionChanged(this); _CurrentTrack = Track; this._TrackURI = HTTPMessage.UnEscapeString(TrackURI); if(this.OnTrackURIChanged!=null) OnTrackURIChanged(this); if(OnCurrentTrackChanged!=null) OnCurrentTrackChanged(this); lock(this) { --StateCounter; if(StateCounter==0) { if(OnReady!=null)OnReady(this); } } }
protected void MediaInfoSink(CpAVTransport sender, System.UInt32 InstanceID, System.UInt32 NrTracks, System.String MediaDuration, System.String CurrentURI, System.String CurrentURIMetaData, System.String NextURI, System.String NextURIMetaData, CpAVTransport.Enum_PlaybackStorageMedium PlayMedium, CpAVTransport.Enum_RecordStorageMedium RecordMedium, CpAVTransport.Enum_RecordMediumWriteStatus WriteStatus, UPnPInvokeException e, object Handle) { _AVTransportURI = CurrentURI; _AVTransportMetaData = CurrentURIMetaData; if(this.OnAVTransportURIChanged!=null) OnAVTransportURIChanged(this); _NextAVTransportURI = NextURI; _NextAVTransportMetaData = NextURIMetaData; if(this.OnNextAVTransportURIChanged!=null) OnNextAVTransportURIChanged(this); _NumberOfTracks = NrTracks; this._AVTransportMetaData = CurrentURIMetaData; if(this.OnCurrentURIMetaDataChanged!=null) OnCurrentURIMetaDataChanged(this); if(OnNumberOfTracksChanged!=null) OnNumberOfTracksChanged(this); lock(this) { --StateCounter; if(StateCounter==0) { if(OnReady!=null)OnReady(this); } } }
protected void PollSink(CpAVTransport sender, UInt32 InstanceID, UInt32 Track, string TrackDuration, string TrackMetaData, string TrackURI, string RelTime, string AbsTime, int RelCount, int AbsCount, UPnPInvokeException e, object Handle) { DText p = new DText(); p.ATTRMARK = ":"; TimeSpan ts; try { p[0]= RelTime; _CurrentPosition = new TimeSpan(int.Parse(p[1]),int.Parse(p[2]),int.Parse(p[3])); if (this._CurrentTrack != Track) { this._CurrentTrack = Track; if (this.OnCurrentTrackChanged != null) { this.OnCurrentTrackChanged(this); } } p[0] = TrackDuration; ts = new TimeSpan(int.Parse(p[1]), int.Parse(p[2]), int.Parse(p[3])); if (this._CurrentDuration != ts) { this._CurrentDuration = ts; } if (this._TrackURI.CompareTo(TrackURI) != 0) { this._TrackURI = TrackURI; if (this.OnCurrentTrackChanged != null) { this.OnCurrentTrackChanged(this); } } if (this._AVTransportMetaData.CompareTo(TrackMetaData) != 0) { this._AVTransportMetaData = TrackMetaData; if (this.OnCurrentURIMetaDataChanged != null) { this.OnCurrentURIMetaDataChanged(this); } } } catch(Exception) { } if(OnCurrentPositionChanged!=null) OnCurrentPositionChanged(this); }
protected void GetTransportInfoSink(CpAVTransport sender, System.UInt32 InstanceID, CpAVTransport.Enum_TransportState CurrentTransportState, CpAVTransport.Enum_TransportStatus CurrentTransportStatus, CpAVTransport.Enum_TransportPlaySpeed CurrentSpeed, UPnPInvokeException e, object Handle) { if(e!=null) return; _TransportStatus = _cp.Enum_TransportStatus_ToString(CurrentTransportStatus); switch(CurrentTransportState) { case CpAVTransport.Enum_TransportState.PLAYING: this._PlayState = "PLAYING"; break; case CpAVTransport.Enum_TransportState.STOPPED: this._PlayState = "STOPPED"; break; case CpAVTransport.Enum_TransportState.PAUSED_PLAYBACK: this._PlayState = "PAUSED_PLAYBACK"; break; case CpAVTransport.Enum_TransportState.PAUSED_RECORDING: this._PlayState = "PAUSED_RECORDING"; break; case CpAVTransport.Enum_TransportState.RECORDING: this._PlayState = "RECORDING"; break; case CpAVTransport.Enum_TransportState.TRANSITIONING: this._PlayState = "TRANSITIONING"; break; } if(this.OnPlayStateChanged!=null) OnPlayStateChanged(this); if(this.OnTransportStatusChanged!=null) OnTransportStatusChanged(this); lock(this) { --StateCounter; if(StateCounter==0) { if(OnReady!=null)OnReady(this); } } }
protected void LastChangeSink(CpAVTransport sender, string LC) { if(LC=="")return; //LC = UPnPStringFormatter.UnEscapeString(LC); if(LC.Substring(0,1)!="<") LC = UPnPStringFormatter.UnEscapeString(LC); if(LC.Substring(0,1)!="<") LC = UPnPStringFormatter.UnEscapeString(LC); StringReader MyString = new StringReader(LC); XmlTextReader XMLDoc = new XmlTextReader(MyString); Hashtable T = new Hashtable(); int ID = -1; string VarName = ""; string VarValue = ""; string AttrName = ""; string AttrValue = ""; XMLDoc.Read(); XMLDoc.MoveToContent(); XMLDoc.Read(); XMLDoc.MoveToContent(); while((XMLDoc.LocalName!="Event")&&(XMLDoc.EOF==false)) { // At Start, should be InstanceID if(XMLDoc.LocalName=="InstanceID") { XMLDoc.MoveToAttribute("val"); ID = int.Parse(XMLDoc.GetAttribute("val")); if(T.ContainsKey(ID)==false) T[ID] = new Hashtable(); XMLDoc.MoveToContent(); XMLDoc.Read(); XMLDoc.MoveToContent(); while(XMLDoc.LocalName!="InstanceID") { if(XMLDoc.IsStartElement()==true) { VarName = XMLDoc.LocalName; VarValue = ""; AttrName = ""; AttrValue = ""; for(int a_idx=0;a_idx<XMLDoc.AttributeCount;++a_idx) { XMLDoc.MoveToAttribute(a_idx); if(XMLDoc.LocalName=="val") { VarValue = UPnPStringFormatter.UnEscapeString(XMLDoc.GetAttribute(a_idx)); } else { AttrName = XMLDoc.LocalName; AttrValue = XMLDoc.GetAttribute(a_idx); } } XMLDoc.MoveToContent(); if(AttrName=="") { ((Hashtable)T[ID])[VarName] = VarValue; } else { if(((Hashtable)T[ID]).ContainsKey(VarName)==false) { ((Hashtable)T[ID])[VarName] = new Hashtable(); } if(((Hashtable)((Hashtable)T[ID])[VarName]).ContainsKey(AttrName)==false) { ((Hashtable)((Hashtable)T[ID])[VarName])[AttrName] = new Hashtable(); } ((Hashtable)((Hashtable)((Hashtable)T[ID])[VarName])[AttrName])[AttrValue] = VarValue; } } XMLDoc.Read(); XMLDoc.MoveToContent(); } } else { XMLDoc.Skip(); } XMLDoc.Read(); XMLDoc.MoveToContent(); } XMLDoc.Close(); IDictionaryEnumerator inEn = T.GetEnumerator(); IDictionaryEnumerator EvEn; Hashtable TT; string TempString; DText TempParser = new DText(); while(inEn.MoveNext()) { if(inEn.Key.ToString() == InstanceID) { TT = (Hashtable)inEn.Value; EvEn = TT.GetEnumerator(); while(EvEn.MoveNext()) { switch((string)EvEn.Key) { case "AVTransportURI": _AVTransportURI = (string)EvEn.Value; if(OnAVTransportURIChanged!=null) OnAVTransportURIChanged(this); break; case "TransportState": _PlayState = (string)EvEn.Value; if(OnPlayStateChanged!=null) OnPlayStateChanged(this); break; case "CurrentTrackDuration": TempString = (string)EvEn.Value; TempParser.ATTRMARK = ":"; TempParser[0] = TempString; try { this._CurrentDuration = new TimeSpan(int.Parse(TempParser[1]),int.Parse(TempParser[2]),int.Parse(TempParser[3])); } catch(Exception) {} if(this.OnCurrentPositionChanged!=null) this.OnCurrentPositionChanged(this); break; case "RelativeTimePosition": TempString = (string)EvEn.Value; TempParser.ATTRMARK = ":"; TempParser[0] = TempString; this._CurrentPosition = new TimeSpan(int.Parse(TempParser[1]),int.Parse(TempParser[2]),int.Parse(TempParser[3])); if(this.OnCurrentPositionChanged!=null) this.OnCurrentPositionChanged(this); break; case "NumberOfTracks": try { _NumberOfTracks = UInt32.Parse((string)EvEn.Value); if(OnNumberOfTracksChanged!=null) OnNumberOfTracksChanged(this); } catch(Exception) {} break; case "CurrentTrack": try { _CurrentTrack = UInt32.Parse((string)EvEn.Value); if(OnCurrentTrackChanged!=null) OnCurrentTrackChanged(this); } catch(Exception) {} break; case "CurrentTrackURI": _TrackURI = (string)EvEn.Value; if(OnTrackURIChanged!=null) OnTrackURIChanged(this); break; case "TransportStatus": _TransportStatus = (string)EvEn.Value; if(OnTransportStatusChanged!=null) OnTransportStatusChanged(this); break; case "AVTransportURIMetaData": _AVTransportMetaData = (string)EvEn.Value; if(this.OnCurrentURIMetaDataChanged!=null) OnCurrentURIMetaDataChanged(this); break; case "CurrentPlayMode": _CurrentPlayMode = (string)EvEn.Value; if(this.OnCurrentPlayModeChanged!=null) OnCurrentPlayModeChanged(this); break; } } } } }
/// <summary> /// This construct is only called by the AVRenderer object. /// </summary> /// <param name="device"></param> /// <param name="AVTransportID"></param> /// <param name="RenderingControlID"></param> /// <param name="ConnectionID"></param> /// <param name="ReadyCallback"></param> /// <param name="StateObject"></param> internal AVConnection(UPnPDevice device, int AVTransportID, int RenderingControlID, Int32 ConnectionID, AVConnection.OnReadyHandler ReadyCallback, object StateObject) { OpenSource.Utilities.InstanceTracker.Add(this); this.Tag = StateObject; this.OnReady += ReadyCallback; FriendlyName = device.FriendlyName; Identifier = device.UniqueDeviceName + ":" + ConnectionID.ToString(); AVTid = AVTransportID; RCid = RenderingControlID; CMid = ConnectionID; AVTransport = new CpAVTransport(device.GetServices(CpAVTransport.SERVICE_NAME)[0]); RenderingControl = new CpRenderingControl(device.GetServices(CpRenderingControl.SERVICE_NAME)[0]); ConnectionManager = new CpConnectionManager(device.GetServices(CpConnectionManager.SERVICE_NAME)[0]); if(RenderingControl.HasStateVariable_Volume) { // If the renderer has defined ranges, use those if(RenderingControl.HasMaximum_Volume) { MaxVolume = (UInt16)RenderingControl.Maximum_Volume; } else { MaxVolume = UInt16.MaxValue; } if(RenderingControl.HasMinimum_Volume) { MinVolume = (UInt16)RenderingControl.Minimum_Volume; } else { MinVolume = UInt16.MinValue; } } lock(this) { if(AVTransport.HasStateVariable_LastChange) { // Hook up to the LastChange event of AVTransport ++this.StateCounter; AV_LastChange = new AVTransportLastChange(AVTransport,device.UniqueDeviceName, AVTid, new AVTransportLastChange.ReadyHandler(AVTLC)); AV_LastChange.OnCurrentPositionChanged += new AVTransportLastChange.VariableChangeHandler(PositionSink); AV_LastChange.OnPlayStateChanged += new AVTransportLastChange.VariableChangeHandler(PlayStateSink); AV_LastChange.OnAVTransportURIChanged += new AVTransportLastChange.VariableChangeHandler(AVTransportURISink); AV_LastChange.OnCurrentTrackChanged += new AVTransportLastChange.VariableChangeHandler(TrackChangedSink); AV_LastChange.OnNumberOfTracksChanged += new AVTransportLastChange.VariableChangeHandler(NumberOfTracksChangedSink); AV_LastChange.OnTrackURIChanged += new AVTransportLastChange.VariableChangeHandler(TrackURIChangedSink); AV_LastChange.OnCurrentURIMetaDataChanged += new AVTransportLastChange.VariableChangeHandler(URIMetaDataChangedSink); AV_LastChange.OnCurrentPlayModeChanged += new AVTransportLastChange.VariableChangeHandler(CurrentPlayModeChangedSink); AV_LastChange.OnTransportStatusChanged += new AVTransportLastChange.VariableChangeHandler(TransportStatusChangedSink); } if(RenderingControl.HasStateVariable_LastChange) { // Hook up to the LastChange event of RenderingControl ++this.StateCounter; RC_LastChange = new RenderingControlLastChange(RenderingControl,device.UniqueDeviceName, RCid, new RenderingControlLastChange.OnReadyHandler(RCLC)); RC_LastChange.OnMuteChanged += new RenderingControlLastChange.VariableChangeHandler(MuteSink); RC_LastChange.OnVolumeChanged += new RenderingControlLastChange.VariableChangeHandler(VolumeSink); } /* Get ProtocolInfo Value of current connection */ ++this.StateCounter; ConnectionManager.GetCurrentConnectionInfo(ConnectionID,this.GetHashCode(),new CpConnectionManager.Delegate_OnResult_GetCurrentConnectionInfo(InitialState_GetCurrentConnectionInfoSink)); } RenderingControl._subscribe(500); AVTransport._subscribe(500); }
protected void SetAVTransportURISink(CpAVTransport sender, System.UInt32 InstanceID, System.String CurrentURI, System.String CurrentURIMetaData, UPnPInvokeException e, object Tag) { if(e!=null) return; OnSetAVTransportURIEvent.Fire(this,Tag); }
internal void SetAVTransportURI(string NewUri, string MetaData, object Tag, CpAVTransport.Delegate_OnResult_SetAVTransportURI Callback) { AVTransport.SetAVTransportURI((UInt32)AVTid,NewUri,MetaData,Tag, Callback); //AVTransport.Sync_SetAVTransportURI((UInt32)AVTid, NewUri); }
public override void Start(UPnPDevice device) { UPnPTestStates Master = UPnPTestStates.Pass; TestDevice = device; UPnPDevice d = device; UPnPService[] services = d.GetServices(CpConnectionManager.SERVICE_NAME); if (services == null || services.Length == 0) { enabled = false; return; } CM = new CpConnectionManager(services[0]); string SOURCE=""; string SINK=""; DText parser = new DText(); StartCountDown(0,90); try { CM.Sync_GetProtocolInfo(out SOURCE,out SINK); } catch(UPnPInvokeException) { Results.Add("Connection Handler Test was aborted because GetProtocolInfo FAILED"); SetState("Connection Handling",UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } AbortCountDown(); parser.ATTRMARK = ","; parser.MULTMARK = ":"; bool OK = true; if(ConnectionManagerEventsTest()==false) { Results.Add("Connection Handler Test was aborted because of invalid/missing events"); SetState("Connection Handling",UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } if(SINK!="") { parser[0] = SINK; TotalTime = parser.DCOUNT()*120; CurrentTime = 0; for(int i=1;i<=parser.DCOUNT();++i) { if(parser.DCOUNT(i)!=4) { // Invalid Format OK = false; AddEvent(LogImportance.Critical,"Connection Handling"," Protocol Info String [" + parser[i] + "] is not in a valid format"); } } if(OK) { AddEvent(LogImportance.Remark,"Connection Handling"," Protocol Info Strings are in the correct format"); } else { Results.Add("Connection Handler Test was aborted because of invalid Protocol Info Strings"); SetState("Connection Handling",UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } if(CM.HasAction_PrepareForConnection) { for(int i=1;i<=parser.DCOUNT();++i) { if(PrepareForConnectionTest_SINK(parser[i])==false) { OK = false; } } } } if(OK) { Results.Add("Connection Handler Test PASSED"); SetState("Connection Handling",UPnPTestStates.Pass); } else { Results.Add("Connection Handler Test FAILED"); SetState("Connection Handling",UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } OK = true; UPnPService[] _AVT = d.GetServices(CpAVTransport.SERVICE_NAME); if(_AVT.Length!=0) { // AVT Tests AVT = new CpAVTransport(_AVT[0]); if(!Test_AVTransport_LastChange()) OK = false; } if(OK) { Results.Add("Event Formatting PASSED"); SetState("Event Formatting",UPnPTestStates.Pass); } else { Results.Add("Event Formatting FAILED"); SetState("Event Formatting",UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } OK = true; _AVT = d.GetServices(CpAVTransport.SERVICE_NAME); if(_AVT.Length!=0) { // AVT Tests AVT = new CpAVTransport(_AVT[0]); if(!Test_AVTransport_StateVariables()) OK = false; } if (OK) { Results.Add("StateVariable Values NOT TESTED (Not implemented)"); SetState("StateVariable Values",UPnPTestStates.Pass); } else { Results.Add("StateVariable Values FAILED"); SetState("StateVariable Values",UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } // this.HTTP_ScenarioTest(); state = Master; }
private void AVT_LastChangeSink(CpAVTransport sender, string Val) { Ev.Set(); }