Esempio n. 1
0
/**
 * Starts decoding and playing the FLI/FLC file
 */
void FlcPlayer::play(bool skipLastFrame)
{
	_playingState = PLAYING;

	// Vertically center the video
	_dy = (_mainScreen->h - _headerHeight) / 2;

	_offset = _dy * _mainScreen->pitch + _mainScreen->format->BytesPerPixel * _dx;

	// Skip file header
	_videoFrameData = _fileBuf + 128;
	_audioFrameData = _videoFrameData;

	while (!shouldQuit())
	{
		if (_frameCallBack)
			(*_frameCallBack)();
		else // TODO: support both, in the case the callback is not some audio?
			decodeAudio(2);

		if (!shouldQuit())
			decodeVideo(skipLastFrame);

		if(!shouldQuit())
			SDLPolling();
	}
	
}
Esempio n. 2
0
Frame *DataSource::readFrame() {
    AVPacket packet;

    //DPRINT("%d, %d", m_formatCtx->streams[m_videoStream]->time_base.num, m_formatCtx->streams[m_videoStream]->time_base.den);
    while (av_read_frame(m_formatCtx, &packet) >= 0) {
        if (packet.stream_index == m_videoStream) {
            //DPRINT("video packet pts %lld", packet.pts);
            if (packet.pts != AV_NOPTS_VALUE) {
                //DPRINT("video set pts %lld", packet.pts);
                if (packet.pts > m_currentVideoPts) {
                    m_currentVideoPts = packet.pts;
                }
            }

            AVFrame *f = decodeVideo(m_formatCtx->streams[m_videoStream]->codec, &packet);

            if (f != NULL) {
                //DPRINT("video pts: %lf, %lf", videoTimeBase, m_currentPts * videoTimeBase);
                Frame *ret = new VideoFrame(f,
                                            m_currentVideoPts,
                                            Frame::VideoFrame);
                av_free_packet(&packet);
                return ret;
            }
        }
        else if (packet.stream_index == m_audioStream) {
            //DPRINT("audio packet pts %lld", packet.pts);
            if (packet.pts != AV_NOPTS_VALUE) {
                //DPRINT("audio set pts %lld", packet.pts);
                if (packet.pts > m_currentAudioPts) {
                    m_currentAudioPts = packet.pts;
                }
            }
            int size = 0;
            uint8_t *buf = decodeAudio(m_formatCtx->streams[m_audioStream]->codec,
                                       &packet,
                                       &size);

            if (buf != NULL) {
                Frame *ret = new AudioFrame(buf, size, m_currentAudioPts, Frame::AudioFrame);
                return ret;
            }
        }

        av_free_packet(&packet);
    }

    return NULL;
}
Esempio n. 3
0
 int InputProcessor::deliverAudioData_(char* buf, int len) {
   if (audioDecoder && audioUnpackager) {
     ELOG_DEBUG("Decoding audio");
     int unp = unpackageAudio((unsigned char*) buf, len,
         unpackagedAudioBuffer_);
     int a = decodeAudio(unpackagedAudioBuffer_, unp, decodedAudioBuffer_);
     ELOG_DEBUG("DECODED AUDIO a %d", a);
     RawDataPacket p;
     p.data = decodedAudioBuffer_;
     p.type = AUDIO;
     p.length = a;
     rawReceiver_->receiveRawData(p);
     return a;
   }
   return 0;
 }
Esempio n. 4
0
void *pck_process( void *tr ){

	int check_decode=10,local_buffer[10],local_flag=9,temp_count=0,wait=0,j, blk_counter=0,x=0;
	BLOCK temp;
		while(!endOfPackets()){
			pthread_mutex_lock( &mutexip);
			temp_count=recv_pck;
			pthread_mutex_unlock( &mutexip);
			while(temp_count<check_decode){
				pthread_mutex_lock( &mutexip);
				temp_count=recv_pck;
				pthread_mutex_unlock( &mutexip);
				usleep(1000);
						}
						pthread_mutex_lock( &mutexip);
							for(j=0;j<10;j++){
								local_buffer[j]=packets[j+local_flag-9];
								}
						pthread_mutex_unlock( &mutexip);
						check_decode+=10;

						if(isBlockSyncPacket(local_buffer[9])){
						temp=decodeAudio(local_buffer);
						pthread_mutex_lock(&mutexproc);
						block[blk_counter]= temp;
						pthread_mutex_unlock(&mutexproc);

					if(!(temp =="ASBLOCK_ERROR")){
					pthread_mutex_lock(&mutexproc);
					blk_counter++;
					decode_block++;
					pthread_mutex_unlock(&mutexproc);

				}
			}
		local_flag+=10;
		if(local_flag>=max_pck)
			local_flag=9;
		if(blk_counter>=max_blk)
			blk_counter=0;

		}
		pthread_exit(NULL);
	  }
Esempio n. 5
0
void FlcPlayer::waitForNextFrame(Uint32 delay)
{
	static Uint32 oldTick = 0;
	int newTick;
	int currentTick;

	currentTick = SDL_GetTicks();
	if (oldTick == 0)
	{
		oldTick = currentTick;
		newTick = oldTick;
	}
	else
		newTick = oldTick + delay;

	if (_hasAudio)
	{
		while (currentTick < newTick)
		{
			while ((newTick - currentTick) > 10 && !isEndOfFile(_audioFrameData))
			{
				decodeAudio(1);
				currentTick = SDL_GetTicks();
			}
			SDL_Delay(1);
			currentTick = SDL_GetTicks();
		}
	}
	else
	{
		while (currentTick < newTick)
		{
			SDL_Delay(1);
			currentTick = SDL_GetTicks();
		}
	}
	oldTick = SDL_GetTicks();
} 
Esempio n. 6
0
unsigned char* FFMpegDecoder::getReSampledAudioSamples(int dstSize)
{
	if (resampler == NULL)
	{
		errinfo("resampler is NULL!");
		return NULL;
	}
		

	//write enough samples into fifo
	while (fifoResampleResult->getSize() < dstSize)
	{
		
		AVPacket *pkt = readPacket();
		if (pkt == NULL)
		{
			int fifoSize = fifoResampleResult->getSize();
			fifoResampleResult->read(resampleChunk,fifoSize);
			memset(resampleChunk+fifoSize,0,dstSize-fifoSize);
			break;
		}
		
		if (pkt->stream_index != audioStream)
			continue;
		
		//decode,resample,and write to fifo
		SimpleBuf *samples = decodeAudio();
		if (samples == NULL)	//decode error
			continue;

		int nb_resampled = resampler->resample((short*)samples->data,(short*)resampleChunk,samples->dataSize);
		fifoResampleResult->write(resampleChunk,nb_resampled);
	}	
	
	fifoResampleResult->read(resampleChunk,dstSize);
	return  resampleChunk;
}
Esempio n. 7
0
void VideoDecoder::updateAudioBuffer() {
    int sizeLeft = VIDEOPLAYER_AUDIO_BUFFER_SIZE;

    // Try getting enough data, to fill the buffer.
    while(sizeLeft > 0) {
        //If there is no decoded data left, decode new frame
        if(audioDecodedUsed >= audioDecodedSize) {
            audioDecodedUsed = 0;

            int size = decodeAudio(audioDecodingBuffer);
            if(size < 0) {
                logDebug("[VideoPlayer::updateAudioBuffer] Could not decode more frames!\n");

                //Play silence
                audioDecodedSize = 1024;
                memset(audioDecodingBuffer, 0, audioDecodedSize);

                //Set an offset for the video, so that audio won't be behind
                timestampOffset += secPerKbBlock;
            } else {
                audioDecodedSize = size;
            }
        }

        //Copy data into the buffer
        int lengthToCopy = audioDecodedSize - audioDecodedUsed;
        //Make sure we never copy more than the buffer
        if(lengthToCopy > sizeLeft) {
            lengthToCopy = sizeLeft;
        }

        memcpy(audioBuffer + (VIDEOPLAYER_AUDIO_BUFFER_SIZE - sizeLeft), audioDecodingBuffer + audioDecodedUsed, lengthToCopy);
        sizeLeft -= lengthToCopy;
        audioDecodedUsed += lengthToCopy;
    }
}