redribben

BMHttpAudioStreamManager.h

Aug 27th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  BMHttpAudioStreamManager.h
  3. //  Радио СВЕТ
  4. //
  5. //  Created by Bogdan Michalchuk on 8/21/14.
  6. //  Copyright (c) 2014 Радио CBET. All rights reserved.
  7. //
  8.  
  9.  
  10. #import <Foundation/Foundation.h>
  11. #import <stdio.h>
  12. #import <string.h>
  13. #import <netdb.h>
  14. #import <netinet/in.h>
  15. #import <unistd.h>
  16. #import <pthread.h>
  17. #import <AudioToolbox/AudioToolbox.h>
  18. #import <CFNetwork/CFHTTPMessage.h>
  19. #import <AVFoundation/AVFoundation.h>
  20. #import <MediaPlayer/MediaPlayer.h>
  21.  
  22.  
  23. #define kNumAQBufs 3                        // number of audio queue buffers we allocate
  24. #define kAQBufSize  128*1024                // number of bytes in each audio queue buffer
  25. #define kAQMaxPacketDescs 512               // number of packet descriptions in our array
  26.  
  27. typedef struct {
  28.  
  29.     AudioFileStreamID audioFileStream;      // the audio file stream parser
  30.    
  31.     AudioQueueRef audioQueue;                               // the audio queue
  32.     AudioQueueBufferRef audioQueueBuffer[kNumAQBufs];       // audio queue buffers
  33.    
  34.     AudioStreamPacketDescription packetDescs[kAQMaxPacketDescs];    // packet descriptions for enqueuing audio
  35.    
  36.     unsigned int fillBufferIndex;           // the index of the audioQueueBuffer that is being filled
  37.     unsigned int bytesFilled;               // how many bytes have been filled
  38.     unsigned int packetsFilled;             // how many packets have been filled
  39.    
  40.     bool inuse[kNumAQBufs];                 // flags to indicate that a buffer is still in use
  41.     bool started;                           // flag to indicate that the queue has been started
  42.     bool failed;                            // flag to indicate an error occurred
  43.    
  44.     pthread_mutex_t mutex;                  // a mutex to protect the inuse flags
  45.     pthread_cond_t cond;                    // a condition varable for handling the inuse flags
  46.     pthread_cond_t done;                    // a condition varable for handling the inuse flags
  47. } AudioData;
  48.  
  49.  
  50. @interface BMHttpAudioStreamManager : NSObject
  51.  
  52. -(void) connectionStart;
  53. -(void) stopRadio;
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. //void MyPacketsProc(void *                         inClientData,
  64. //                 UInt32                           inNumberBytes,
  65. //                 UInt32                           inNumberPackets,
  66. //                 const void *                 inInputData,
  67. //                 AudioStreamPacketDescription *inPacketDescriptions);
  68. + (void) myPacketsProcWithData:(AudioData *) audioData
  69.                 forNumberBytes:(UInt32) inNumberBytes
  70.               forNumberPackets:(inNumberPackets) inNumberPackets
  71.                   forInputData:(const void *) inInputData
  72.          withPacketDescription:(AudioStreamPacketDescription *) inPacketDescription;
  73.  
  74.  
  75. //int MyFindQueueBuffer(AudioData* audioData, AudioQueueBufferRef inBuffer);
  76.  - (int) myFindQueueBufferWithAudioData:(AudioData *) audioData
  77.                              withBuffer:(AudioQueueBufferRef) inBuffer;
  78.  
  79.  
  80. //void MyPropertyListenerProc(void *                        inClientData,
  81. //                          AudioFileStreamID               inAudioFileStream,
  82. //                          AudioFileStreamPropertyID       inPropertyID,
  83. //                          UInt32 *                        ioFlags);
  84. + (void) myPropertyListerProcForData:(AudioData *) audioData //note this parameter
  85.                          forStreamID:(AudioFileStreamID) inAudioFileStream
  86.                        forPropertyID:(AudioFileStreamPropertyID) inPropertyID
  87.                           forIOFlags:(UInt32) ioFlags;
  88.  
  89.  
  90.  
  91. //void MyAudioQueueIsRunningCallback(void*                  inClientData,
  92. //                                 AudioQueueRef            inAQ,
  93. //                                 AudioQueuePropertyID     inID);
  94. + (void) myAudioQueueIsRunningCallbackWithData:(AudioData *) audioData
  95.                                        withRef:(AudioQueueRef) inAQ
  96.                                 withPropertyID:(AudioQueuePropertyID) inID;
  97.  
  98.  
  99. //OSStatus MyEnqueueBuffer(AudioData* audioData);
  100.  
  101. //void WaitForFreeBuffer(AudioData* audioData);
  102. + (void) waitForFreeBufferForData:(AudioData *) audioData;
  103.  
  104. //void MyAudioQueueOutputCallback(void*                 inClientData,
  105. //                              AudioQueueRef           inAQ,
  106. //                              AudioQueueBufferRef     inBuffer);
  107. + (void) myAudioQueueOutputCallbackWithData:(BMHttpAudioStreamManager *) inClientData
  108.                                   WithQueue:(AudioQueueRef) inAQ
  109.                                  withBuffer:(AudioQueueBufferRef) inBuffer;
  110.  
  111.  
  112.  
  113. //OSStatus StartQueueIfNeeded(AudioData* audioData);
  114. + (OSStatus) startQueueifNeededWithData:(AudioData *) audioData;
  115.  
  116. + (void) readStreamClientCallBackWithData:(CFReadStreamRef) stream
  117.                                  withType:(CFStreamEventType) type
  118.                    withClientCallBackInfo:(void *) clientCallBackInfo;
  119.  
  120.  
  121.  
  122.  
  123. @end
Add Comment
Please, Sign In to add comment