Use AudioQueue to play PCM audio stream in ios, First is ok,but no voice after 15mins -



Use AudioQueue to play PCM audio stream in ios, First is ok,but no voice after 15mins -

i sound info rtmppacket, , utilize audioqueue play in ipad. first, voice fine. after 15mins, there no voice. info ok, , queue playing. don't know why. can help me? thanks.

this class used play audio.

audioplayer.h

#import <foundation/foundation.h> #import <coreaudio/coreaudiotypes.h> #import <corefoundation/corefoundation.h> #import <audiotoolbox/audiotoolbox.h> #include <unistd.h> #define knumberbuffers 3 @interface audioplayer : nsobject { audioqueueref mqueue; audioqueuebufferref mbuffers[knumberbuffers]; audiostreambasicdescription mplayformat; int mindex; @public boolean misrunning; boolean misinitialized; int mbufferbytesize; int pip_fd[2]; uint32 mnumpacketstoread; } @property audioqueueref mqueue; -(id)init; -(id)initwithsamplerate:(int)samplerate; -(void)startplaywithbufferbytesize:(int)bufferbytesize; -(void)stopplay; -(void)putaudiodata:(short*)pcmdata; @end

audioplayer.m

#import "audioplayer.h" @implementation audioplayer @synthesize mqueue; void aqbuffercallback(void * inuserdata , audioqueueref inaq, audioqueuebufferref inbuffer) { audioplayer *this = (__bridge audioplayer *)(inuserdata); if(this->misrunning) { inbuffer->mpacketdescriptioncount = this->mbufferbytesize/2; inbuffer->maudiodatabytesize =this->mbufferbytesize; if(read(this->pip_fd[0], inbuffer->maudiodata, this->mbufferbytesize) > 0 ){ audioqueueenqueuebuffer(inaq, inbuffer, 0, null); } } } -(id)init { homecoming [self initwithsamplerate:16000]; } -(id)initwithsamplerate:(int)samplerate { self = [super init]; if(self) { memset(&mplayformat, 0, sizeof(mplayformat)); mplayformat.mformatid = kaudioformatlinearpcm; mplayformat.mformatflags = klinearpcmformatflagissignedinteger | klinearpcmformatflagispacked; mplayformat.mbitsperchannel = 16; mplayformat.mchannelsperframe = 1; mplayformat.mbytesperpacket = mplayformat.mbytesperframe = (mplayformat.mbitsperchannel / 8) * mplayformat.mchannelsperframe; mplayformat.mframesperpacket = 1; mplayformat.msamplerate = samplerate; misrunning = false; misinitialized = false; } homecoming self; } -(void)startplaywithbufferbytesize:(int)bufferbytesize { if (misinitialized) return; mbufferbytesize = bufferbytesize; audioqueuenewoutput(&mplayformat, aqbuffercallback, (__bridge void *)(self), nil, nil, 0, &mqueue); (int i=0; i<knumberbuffers; i++) { audioqueueallocatebuffer(mqueue, mbufferbytesize, &mbuffers[i]); } audioqueuesetparameter(mqueue, kaudioqueueparam_volume, 1.0); misinitialized = true; int ret = pipe(pip_fd); if (ret == -1) { nslog(@"create pipe failed"); } } -(void)stopplay { close(pip_fd[0]); close(pip_fd[1]); audioqueuestop(mqueue, false); if (mqueue){ audioqueuedispose(mqueue, true); mqueue = null; misrunning = false; } misinitialized = false; nslog(@"stop play queue"); } -(void)putaudiodata:(short*)pcmdata { if (!misrunning) { memcpy(mbuffers[mindex]->maudiodata, pcmdata, mbufferbytesize); mbuffers[mindex]->maudiodatabytesize = mbufferbytesize; mbuffers[mindex]->mpacketdescriptioncount = mbufferbytesize/2; audioqueueenqueuebuffer(mqueue, mbuffers[mindex], 0, null); nslog(@"fill sound queue buffer[%d]",mindex); if(mindex == knumberbuffers - 1) { misrunning = true; mindex = 0; audioqueuestart(mqueue, null); }else { mindex++; } }else { if(write(pip_fd[1], pcmdata, mbufferbytesize) < 0){ nslog(@"write pipe failed!"); } } } @end

ios audio audioqueue

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -