Пример #1
0
Файл: ctf.c Проект: DataIX/src
/*
 * Create the compression buffer, and fill it with the CTF and string
 * table data.  We flush the compression state between the two so the
 * dictionary used for the string tables won't be polluted with values
 * that made sense for the CTF data.
 */
static caddr_t
write_compressed_buffer(ctf_header_t *h, ctf_buf_t *buf, size_t *resszp)
{
	resbuf_t resbuf;
	resbuf.rb_size = RES_BUF_CHUNK_SIZE;
	resbuf.rb_base = xmalloc(resbuf.rb_size);
	bcopy(h, resbuf.rb_base, sizeof (ctf_header_t));
	resbuf.rb_ptr = resbuf.rb_base + sizeof (ctf_header_t);

	compress_start(&resbuf);
	(void) compress_buffer(buf->ctb_base, buf->ctb_ptr - buf->ctb_base,
	    &resbuf);
	compress_flush(&resbuf, Z_FULL_FLUSH);
	(void) strtab_write(&buf->ctb_strtab, compress_buffer, &resbuf);
	compress_end(&resbuf);

	*resszp = (resbuf.rb_ptr - resbuf.rb_base);
	return (resbuf.rb_base);
}
int AudioALSAPlaybackHandlerOffload::process_write()
{
    while(1)
    {
        int32_t consumed;
        
        if(mDecBsbufRemain < mDecHandler->BsbufferSize() && mDecPcmbufRemain < mWritebytes)
            return OFFLOAD_WRITE_EMPTY; 

        if(mDecPcmbufRemain >= mWritebytes)
        {
            memcpy(offload_stream.tmpBuffer, mDecPcmbuf, mWritebytes);
            mDecPcmbufRemain -= mWritebytes;
            memmove(mDecPcmbuf, mDecPcmbuf+mWritebytes, mDecPcmbufRemain);
	          
            // stereo to mono for speaker
            if (mStreamAttributeSource->audio_format == AUDIO_FORMAT_PCM_16_BIT) // AudioMixer will perform stereo to mono when 32-bit
            {
                doStereoToMonoConversionIfNeed(offload_stream.tmpBuffer, mWritebytes);
            }
		     
            // post processing (can handle both Q1P16 and Q1P31 by audio_format_t)
            void *pBufferAfterPostProcessing = NULL;
            uint32_t bytesAfterPostProcessing = 0;
            doPostProcessing(offload_stream.tmpBuffer, mWritebytes, &pBufferAfterPostProcessing, &bytesAfterPostProcessing);
	      
            // SRC
            void *pBufferAfterBliSrc = NULL;
            uint32_t bytesAfterBliSrc = 0;
            doBliSrc(pBufferAfterPostProcessing, bytesAfterPostProcessing, &pBufferAfterBliSrc, &bytesAfterBliSrc);
		     
            // bit conversion
            void *pBufferAfterBitConvertion = NULL;
            uint32_t bytesAfterBitConvertion = 0;
            doBitConversion(pBufferAfterBliSrc, bytesAfterBliSrc, &pBufferAfterBitConvertion, &bytesAfterBitConvertion);
		    int *ptr32;
			int ptr32_temp, ptr32_cnt;
			ptr32 = (int*)pBufferAfterBitConvertion;
	#if 0
			for(ptr32_cnt = 0; ptr32_cnt<(bytesAfterBitConvertion>>2); ptr32_cnt++)
			{
			    ptr32_temp = *ptr32;
			    *ptr32 = ptr32_temp<<8;
				*ptr32++;
			}
	#endif
            // data pending
            void *pBufferAfterPending = NULL;
            uint32_t bytesAfterpending = 0;
            dodataPending(pBufferAfterBitConvertion, bytesAfterBitConvertion, &pBufferAfterPending, &bytesAfterpending);
		     
            // pcm dump
            WritePcmDumpData(pBufferAfterPending, bytesAfterpending);
		     
            //int retval = compress_write(mComprStream, offload_stream.tmpBuffer, mWritebytes);
            int retval = compress_write(mComprStream, pBufferAfterPending, bytesAfterpending);
            
            if (retval < 0)
            {
                ALOGE("%s(), compress_write() error, retval = %d, %s", __FUNCTION__, retval, compress_get_error(mComprStream));
            }
            else
            {
                if(!mReady)
                {
                    mReady = true;
                    if( offload_stream.offload_state == OFFLOAD_STATE_IDLE)
                        offload_stream.offload_state = OFFLOAD_STATE_PLAYING;
                    compress_nonblock(mComprStream, 1);
                    compress_start(mComprStream);
                }
            }
        #if 0
            if( compress_blockwrite(mComprStream) != 0)
                ALOGE("%s(), compress_blockwrite() error= %s", __FUNCTION__, compress_get_error(mComprStream));
        #endif

			
            return OFFLOAD_WRITE_REMAIN;
        }

        ALOGV("%s(),Decode+ %x, %x ", __FUNCTION__, mDecBsbufRemain, mDecPcmbufRemain);
        if(mDecBsbufRemain >= mDecHandler->BsbufferSize())
            consumed = mDecHandler->DecodeAudio( mDecBsbuf, mDecPcmbuf+mDecPcmbufRemain, mDecBsbufRemain);

        if(consumed < 0)
        {
            ALOGD("%s(), Decoder return error:%x", __FUNCTION__, consumed);
        }
        else
        {
            mDecBsbufRemain -= consumed;
            memmove(mDecBsbuf, mDecBsbuf + consumed, mDecBsbufRemain);
            mDecPcmbufRemain += mDecHandler->PcmbufferSize();
        }
        ALOGD("%s(),Decode- %x, %x", __FUNCTION__, mDecBsbufRemain, mDecPcmbufRemain);
    }