Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. -(void)appendToPool:(NSString *)packetID
  2. packetBody:(const void*)packetBody
  3. numberBytes:(UInt32)numberBytes
  4. packetNumber:(UInt32)packetNumber
  5. {
  6. AudioItem * item = [audioPool.pool objectForKey:packetID];
  7. if (!item)
  8. {
  9. NSLog(@"we are creating a new item, not fetching it");
  10. item = [audioPool createItemAndAddToPool:packetID];
  11. }
  12.  
  13. [item.data dataWithBytes:packetBody];
  14.  
  15. if (currentSong && ![currentSong isEqual:packetID]) {
  16. NSLog(@"ooh! song has changed, current song is %@ and packetId is %@", currentSong, packetID);
  17. isSongChanged = true;
  18. currentSong = packetID;
  19. return;
  20. }
  21.  
  22.  
  23. pthread_mutex_lock(&queueBuffersMutex);
  24.  
  25. currentSong = packetID;
  26. NSLog(@"we have just assigned current song and it is %@",currentSong);
  27.  
  28. pthread_cond_signal(&queueBufferReadyCondition);
  29. pthread_mutex_unlock(&queueBuffersMutex);
  30.  
  31. }
  32.  
  33. -(void)startReader
  34. {
  35. // initialize a mutex and condition so that we can block on buffers in use.
  36. pthread_mutex_init(&queueBuffersMutex, NULL);
  37. pthread_cond_init(&queueBufferReadyCondition, NULL);
  38.  
  39. pthread_mutex_lock(&queueBuffersMutex);
  40. while (!currentSong) {
  41. //wait
  42. pthread_cond_wait(&queueBufferReadyCondition, &queueBuffersMutex);
  43. NSLog(@"we are currently waiting for current songto show up");
  44. }
  45. pthread_mutex_unlock(&queueBuffersMutex);
  46.  
  47. @synchronized(self)
  48. {
  49. NSLog(@"we're done waiting! now we wil read item withcurrent song %@", currentSong);
  50. AudioItem * item = [audioPool.pool objectForKey:currentSong];
  51.  
  52. NSLog(@"we have fetched item");
  53. if (!item)
  54. {
  55. NSLog(@"cannot find song in container");
  56. return;
  57. }
  58.  
  59. while ([item.data length] > 0) {
  60. NSLog(@"we are looping as long as there is length in item.data");
  61. [self doRead:item];
  62. if (isSongChanged) {
  63. NSLog(@"song has changed! time to change item");
  64. item = [audioPool.pool objectForKey:currentSong];
  65. }
  66. }
  67. }
  68.  
  69. }
  70.  
  71. ooh! song has changed, current song is (
  72. kCFRunLoopCommonModes
  73. ) and packetId is ax Rialtz ndant
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement