BOOL _PLMTPC_Seek(PlayListManager manager, int trackNumber) { PlayListManager_PC state = (PlayListManager_PC)manager->InternalState; BOOL result = FALSE; if(trackNumber >= state->StartingTrackNumber && trackNumber <= (state->StartingTrackNumber + state->Count - 1)) { int index = trackNumber - state->StartingTrackNumber; if(manager->TrackMetaData != NULL) { CDS_ObjRef_Release(manager->TrackMetaData); manager->TrackMetaData = NULL; } String_Destroy(manager->TrackURI); manager->TrackURI = NULL; manager->TrackMetaData = state->Objects[index]; CDS_ObjRef_Add(manager->TrackMetaData); manager->TrackNumber = trackNumber; manager->TrackURI = String_Create(manager->TrackMetaData->Res->Value); result = TRUE; } else { if(Browse(state, trackNumber) == TRUE) { if(manager->TrackMetaData != NULL) { CDS_ObjRef_Release(manager->TrackMetaData); manager->TrackMetaData = NULL; } String_Destroy(manager->TrackURI); manager->TrackURI = NULL; manager->TrackMetaData = state->Objects[0]; CDS_ObjRef_Add(manager->TrackMetaData); manager->TrackNumber = trackNumber; manager->TrackURI = String_Create(manager->TrackMetaData->Res->Value); result = TRUE; } else { if(manager->TrackMetaData != NULL) { CDS_ObjRef_Release(manager->TrackMetaData); manager->TrackMetaData = NULL; } String_Destroy(manager->TrackURI); manager->TrackURI = NULL; result = FALSE; } } return result; }
/* Methods */ void _PLMTPC_Destroy(PlayListManager manager) { PlayListManager_PC state = (PlayListManager_PC)manager->InternalState; if(state != NULL) { sem_wait(&state->LockObject); sem_destroy(&state->LockObject); String_Destroy(state->UDN); String_Destroy(state->ServiceID); String_Destroy(state->ContainerID); String_Destroy(state->FirstItemID); String_Destroy(state->SortArgs); ClearMetadata(state); free(state); } if(manager->TrackURI != NULL) { free(manager->TrackURI); } if(manager->TrackMetaData != NULL) { CDS_ObjRef_Release(manager->TrackMetaData); } sem_destroy(&manager->LockObject); if(manager->ShuffleArray != NULL) { BitArray_Destroy(manager->ShuffleArray); } free(manager); }
/* Methods */ void _PLMTS_Destroy(PlayListManager manager) { PlayListManager_S state = (PlayListManager_S)manager->InternalState; if(state != NULL) { sem_wait(&state->FirstBlockFinished); sem_destroy(&state->FirstBlockFinished); sem_wait(&state->BlocksFinished); sem_destroy(&state->BlocksFinished); CircularBuffer_Destroy(state->_buffer); IndexBlocks_Destroy(state->Blocks); free(state); } if(manager->TrackURI != NULL) { free(manager->TrackURI); } if(manager->TrackMetaData != NULL) { CDS_ObjRef_Release(manager->TrackMetaData); } sem_destroy(&manager->LockObject); if(manager->ShuffleArray != NULL) { BitArray_Destroy(manager->ShuffleArray); } free(manager); }
void ClearMetadata(PlayListManager_PC instance) { int i; for(i = 0; i < instance->Count; i++) { if(instance->Objects[i] != NULL) { CDS_ObjRef_Release(instance->Objects[i]); instance->Objects[i] = NULL; } } instance->Count = 0; }
void _Callback2(struct UPnPService *sender, int ErrorCode, void *user, char* Result, unsigned int NumberReturned, unsigned int TotalMatches, unsigned int UpdateID) { PlayListManager_PC state = (PlayListManager_PC)user; struct ILibXMLNode* root = NULL; int count = (int)NumberReturned; state->Error = -ErrorCode; if(ErrorCode != 0) { sem_post(&state->LockObject); return; } ClearMetadata(state); if((int)TotalMatches != state->Parent->TrackCount) { state->Parent->TrackCount = (int)TotalMatches; BitArray_ChangeSize(state->Parent->ShuffleArray, state->Parent->TrackCount); if(state->Parent->OnTrackCountChanged != NULL) { state->Parent->OnTrackCountChanged(state->Parent); } } root = ILibParseXML(Result, 0, (int)strlen(Result)); if(root != NULL) { BOOL failure = FALSE; if(ILibProcessXMLNodeList(root) == 0) { int i = 0; struct ILibXMLNode* item = root->Next; ILibXML_BuildNamespaceLookupTable(root); while(item != NULL && i < count) { struct ILibXMLAttribute* attrs = ILibGetXMLAttributes(item); if(attrs != NULL) { state->Objects[i] = CDS_DeserializeDidlToObject(item, attrs, 1, Result, Result + strlen(Result)); ILibDestructXMLAttributeList(attrs); } else { failure = TRUE; state->Objects[i] = NULL; } i++; item = item->Peer; } } ILibDestructXMLNodeList(root); if(failure == TRUE) { int i; state->Count = 0; for(i = 0; i < count; i++) { if(state->Objects[i] != NULL) { CDS_ObjRef_Release(state->Objects[i]); state->Objects[i] = NULL; } } state->Error = 1; } state->Count = count; } else { state->Error = 2; } sem_post(&state->LockObject); }
BOOL _PLMTS_Seek(PlayListManager manager, int trackNumber) { char* format = "<DIDL-Lite xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\" xmlns:dlna=\"urn:schemas-dlna-org:metadata-1-0/\">%s</DIDL-Lite>"; char* fragment = NULL; char* xml = NULL; BOOL result = FALSE; char* metadata = NULL; int offset = 0; int length = 0; PlayListManager_S state = (PlayListManager_S)manager->InternalState; metadata = _GetTrackMetadata(state, trackNumber - 1, &offset, &length); if(metadata == NULL) { return FALSE; } fragment = ILibString_Copy(metadata + offset, length); xml = (char*)malloc(strlen(fragment) + strlen(format)); sprintf(xml, format, fragment); free(fragment); free(metadata); if(xml != NULL) { struct ILibXMLNode* root = ILibParseXML(xml, 0, (int)strlen(xml)); if(root != NULL) { if(ILibProcessXMLNodeList(root) == 0) { ILibXML_BuildNamespaceLookupTable(root); if(root->Next != NULL) { struct ILibXMLNode* item = root->Next; struct ILibXMLAttribute* attrs = ILibGetXMLAttributes(item); if(attrs != NULL) { struct CdsObject* cdsItem = CDS_DeserializeDidlToObject(item, attrs, 1, metadata + offset, metadata + offset + length); if(cdsItem != NULL) { if(state->Parent->TrackMetaData != NULL) { CDS_ObjRef_Release(state->Parent->TrackMetaData); state->Parent->TrackMetaData = NULL; } if(state->Parent->TrackURI != NULL) { free(state->Parent->TrackURI); state->Parent->TrackURI = NULL; } state->Parent->TrackNumber = trackNumber; state->Parent->TrackMetaData = cdsItem; state->Parent->TrackNumber = trackNumber; result = TRUE; } ILibDestructXMLAttributeList(attrs); } } } ILibDestructXMLNodeList(root); } free(xml); } return result; }