Exemple #1
0
void CCoreAudioHardware::ResetAudioDevices()
{
  // Reset any devices with an AC3 stream back to a Linear PCM
  // so that they can become a default output device
  UInt32 size;
  AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, NULL);
  AudioDeviceID *devices = (AudioDeviceID*)malloc(size);
  if (!devices)
  {
    CLog::Log(LOGERROR, "CCoreAudioHardware::ResetAudioDevices: ResetAudioDevices - out of memory?");
    return;
  }
  int numDevices = size / sizeof(AudioDeviceID);
  AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &size, devices);

  for (int i = 0; i < numDevices; i++)
  {
    AudioStreamID *streams;

    streams = StreamsList(devices[i]);
    for (int j = 0; streams[j] != kAudioHardwareBadStreamError; j++)
      ResetStream(streams[j]);

    free(streams);
  }
  free(devices);
}
Exemple #2
0
	void OggWrapper::DecompressAll(std::vector<char>& decompressBuffer)
	{
		char bufferArray[OGG_BUFFER_SIZE];
		memcpy(bufferArray, bufferArray_, sizeof (char) * OGG_BUFFER_SIZE);

		size_t pos = getCurrentStreamPos();
		ResetStream();

		decompressBuffer.clear();

		int endian = 0;
		int bitstream;
		int bytes;

		do
		{
			bytes = ov_read(ovFile_, bufferArray_, OGG_BUFFER_SIZE, endian, 2, 1, &bitstream);

			if (bytes < 0)
			{
				std::cout << "ov_read error. returned " << bytes << std::endl;
				continue;
			}

			decompressBuffer.insert(decompressBuffer.end(), bufferArray_, bufferArray_ + bytes);

		} while (bytes > 0);

		Seek(pos, START);

		memcpy(bufferArray_, bufferArray, sizeof(char) * OGG_BUFFER_SIZE);
	}
Exemple #3
0
	void OggWrapper::Seek(size_t pos, SeekPos start)
	{
		if (seekable_ == false)
		{
			return;
		}

		if (start == START)
		{
			ResetStream();
		}

		int error = ov_raw_seek(ovFile_, pos);
		if (error != 0)
		{
			std::cout << "ov_raw_seek error : " << error << std::endl;
		}
	}
Exemple #4
0
void CCoreAudioHardware::ResetAudioDevices()
{
  // Reset any devices with an AC3 stream back to a Linear PCM
  // so that they can become a default output device
  AudioObjectPropertyAddress propertyAddress; 
  propertyAddress.mScope    = kAudioObjectPropertyScopeGlobal; 
  propertyAddress.mElement  = kAudioObjectPropertyElementMaster;
  propertyAddress.mSelector = kAudioHardwarePropertyDevices; 

  UInt32 size;
  OSStatus ret = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size); 
  if (ret != noErr)
  {
    CLog::Log(LOGERROR, "CCoreAudioHardware::ResetAudioDevices: ResetAudioDevices - unknown size");
    return;
  }

  AudioDeviceID *devices = (AudioDeviceID*)malloc(size);
  if (!devices)
  {
    CLog::Log(LOGERROR, "CCoreAudioHardware::ResetAudioDevices: ResetAudioDevices - out of memory?");
    return;
  }
  int numDevices = size / sizeof(AudioDeviceID);
  ret = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &size, devices); 
  if (ret != noErr)
  {
    CLog::Log(LOGERROR, "CCoreAudioHardware::ResetAudioDevices: ResetAudioDevices - cannot get device list");
    return;
  }

  for (int i = 0; i < numDevices; i++)
  {
    AudioStreamID *streams = StreamsList(devices[i]);
    if (streams)
    {
      for (int j = 0; streams[j] != kAudioHardwareBadStreamError; j++)
        ResetStream(streams[j]);
      free(streams);
    }
  }
  free(devices);
}
Exemple #5
0
	void OggWrapper::DecompressStream(std::vector<char>& decompressBuffer, bool inLoop)
	{
		decompressBuffer.clear();

		int endian = 0;
		int bitstream;
		int bytes;

		do
		{
			do
			{

				bytes = ov_read(ovFile_, bufferArray_, OGG_BUFFER_SIZE, endian, 2, 1, &bitstream);

				if (bytes < 0)
				{
					std::cout << "ov_read error. returned " << bytes << std::endl;
					continue;
				}

				decompressBuffer.insert(decompressBuffer.end(), bufferArray_, bufferArray_ + bytes);

				if (static_cast<int>(decompressBuffer.size()) >= minDecompressLengthAtOnce_)
				{
					return;
				}

			} while (bytes > 0);

			if (inLoop)
			{
				ResetStream();
			}

			if (minDecompressLengthAtOnce_ == INT_MAX)
			{
				return;
			}

		} while (inLoop);
	}
Exemple #6
0
void CCoreAudioHardware::ResetAudioDevices()
{
  CLog::Log(LOGDEBUG, "CCoreAudioHardware::ResetAudioDevices resetting our devices to LPCM");
  CoreAudioDeviceList list;
  if (GetOutputDevices(&list))
  {
    for (CoreAudioDeviceList::iterator it = list.begin(); it != list.end(); ++it)
    {
      CCoreAudioDevice device(*it);

      AudioStreamIdList streams;
      if (device.GetStreams(&streams))
      {
        CLog::Log(LOGDEBUG, "CCoreAudioHardware::ResetAudioDevices %lu streams for device %s", streams.size(), device.GetName().c_str());
        for (AudioStreamIdList::iterator ait = streams.begin(); ait != streams.end(); ++ait)
          ResetStream(*ait);
      }
    }
  }
}
Exemple #7
0
void freePlay()
{
    AllLED(VERT);
	AUDIO_PlayFile(VOIX_FREE);
	LCD_ClearAndPrint("Je t'ecoute!\n");
	LCD_ClearAndPrint("Appuie sur un des trois boutons pour revenir au menu.\n");
	THREAD_MSleep(3000);

	PianoStream stream;

	stream.size = PIANO_SIZE;
	stream.streamID = -1;
	stream.currentNote = -1;

	Note notes[PIANO_SIZE] = {{false, true, VAL_DO1},
							  {false, true, VAL_RE},
							  {false, true, VAL_MI},
							  {false, true, VAL_FA},
							  {false, true, VAL_SOL},
							  {false, true, VAL_LA},
							  {false, true, VAL_SI},
							  {false, true, VAL_DO2}};
	stream.notes = notes;

	AUDIO_SetVolume(50);

	//Infinite loop until the buttons call break
	while(1)
	{
		CheckPressedKeys(&stream);
		PlayAndStopNotes(&stream);

		THREAD_MSleep(10);
		if(ButtonStatus(1) == 1 || ButtonStatus(2) == 1 || ButtonStatus(3) == 1)
			break;
	}

	//Assure the piano has stopped playing sounds
	ResetStream(&stream);
	PlayAndStopNotes(&stream);
}
Exemple #8
0
void repeat(const char * path)
{
	PianoStream stream;

	stream.size = PIANO_SIZE;
	stream.streamID = -1;
	stream.currentNote = -1;

	Note notes[PIANO_SIZE] = {{false, true, VAL_DO1},
							  {false, true, VAL_RE},
							  {false, true, VAL_MI},
							  {false, true, VAL_FA},
							  {false, true, VAL_SOL},
							  {false, true, VAL_LA},
							  {false, true, VAL_SI},
							  {false, true, VAL_DO2}};
	stream.notes = notes;

	AUDIO_SetVolume(50);

	SongSequenceData song = readSongFile(path);		//Song which is a representation of the song to play

	char readValue;				//Mux read value for the piano notes
	float noteStartTime;		//Represents the start of the note to keep up with time

	for(int i = 0; i < song.size; i++)
	{
		OpenLEDForNotes(song.noteSequences[i].note);
		noteStartTime = SYSTEM_ReadTimerMSeconds();

		while(noteStartTime + song.noteSequences[i].delay > SYSTEM_ReadTimerMSeconds())
		{
			CheckPressedKeys(&stream);
			PlayAndStopNotes(&stream);
		}
	}

	ResetStream(&stream);
	PlayAndStopNotes(&stream);
}
int RTPEndpoint::StartReceiving()
{
	//Check if inited
	if (!inited)
		//Exit
		return Error("Not initied");
	
        //Check
        if (receiving)
                //Exit
                return Error("Alredy receiving");

        //Inited
        receiving = true;

        //Create thread
	createPriorityThread(&thread,run,this,1);

	//Sedn on reset
	ResetStream();

	//Return listening port
	return 1;
}
Exemple #10
0
void TokenStream::SetTokenStream( char *data )
{
    ResetStream( );
    data_ = data;
}
Exemple #11
0
TokenStream::TokenStream( )
{
    ResetStream( );
}
void OmxDecTestReposition::Run()
{
    switch (iState)
    {
        case StateUnLoaded:
        {
            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateUnLoaded IN"));
            OMX_ERRORTYPE Err;
            OMX_BOOL Status;

            //Run this test case only for Audio component currently, exit if video comes
            if (0 == oscl_strcmp(iFormat, "H264") || 0 == oscl_strcmp(iFormat, "M4V")
                    || 0 == oscl_strcmp(iFormat, "WMV") || 0 == oscl_strcmp(iFormat, "H263") || 0 == oscl_strcmp(iFormat, "RV"))
            {
                PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestReposition::Run() - ERROR, This test can't be run for Video component"));
#ifdef PRINT_RESULT
                fprintf(iConsOutFile, "Cannot run this test case for Video Components, Exit\n");
#endif

                iState = StateUnLoaded;
                OsclExecScheduler* sched = OsclExecScheduler::Current();
                sched->StopScheduler();
                break;
            }

            if (!iCallbacks->initCallbacks())
            {
                PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestReposition::Run() - ERROR initCallbacks failed, OUT"));
                StopOnError();
                break;
            }

            ipAppPriv = (AppPrivateType*) oscl_malloc(sizeof(AppPrivateType));
            CHECK_MEM(ipAppPriv, "Component_Handle");
            ipAppPriv->Handle = NULL;

            //Allocate bitstream buffer for AVC component
            if (0 == oscl_strcmp(iFormat, "H264"))
            {
                ipAVCBSO = OSCL_NEW(AVCBitstreamObject, (ipInputFile));
                CHECK_MEM(ipAVCBSO, "Bitstream_Buffer");
            }

            //Allocate bitstream buffer for MPEG4/H263 component
            if (0 == oscl_strcmp(iFormat, "M4V") || 0 == oscl_strcmp(iFormat, "H263"))
            {
                ipBitstreamBuffer = (OMX_U8*) oscl_malloc(BIT_BUFF_SIZE);
                CHECK_MEM(ipBitstreamBuffer, "Bitstream_Buffer")
                ipBitstreamBufferPointer = ipBitstreamBuffer;
            }

            //Allocate bitstream buffer for MP3 component
            if (0 == oscl_strcmp(iFormat, "MP3"))
            {
                ipMp3Bitstream = OSCL_NEW(Mp3BitstreamObject, (ipInputFile));
                CHECK_MEM(ipMp3Bitstream, "Bitstream_Buffer");
            }

            //This should be the first call to the component to load it.
            Err = OMX_MasterInit();
            CHECK_ERROR(Err, "OMX_MasterInit");
            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestReposition::Run() - OMX_MasterInit done"));

            Status = PrepareComponent();

            if (OMX_FALSE == Status)
            {
                PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestReposition::Run() Error while loading component OUT"));
                iState = StateError;

                if (iInputParameters.inPtr)
                {
                    oscl_free(iInputParameters.inPtr);
                    iInputParameters.inPtr = NULL;
                }

                RunIfNotReady();
                break;
            }


#if PROXY_INTERFACE
            ipThreadSafeHandlerEventHandler = OSCL_NEW(OmxEventHandlerThreadSafeCallbackAO, (this, EVENT_HANDLER_QUEUE_DEPTH, "EventHandlerAO"));
            ipThreadSafeHandlerEmptyBufferDone = OSCL_NEW(OmxEmptyBufferDoneThreadSafeCallbackAO, (this, iInBufferCount, "EmptyBufferDoneAO"));
            ipThreadSafeHandlerFillBufferDone = OSCL_NEW(OmxFillBufferDoneThreadSafeCallbackAO, (this, iOutBufferCount, "FillBufferDoneAO"));

            if ((NULL == ipThreadSafeHandlerEventHandler) ||
                    (NULL == ipThreadSafeHandlerEmptyBufferDone) ||
                    (NULL == ipThreadSafeHandlerFillBufferDone))
            {
                PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR,
                                (0, "OmxDecTestReposition::Run() - Error, ThreadSafe Callback Handler initialization failed, OUT"));

                iState = StateUnLoaded;
                OsclExecScheduler* sched = OsclExecScheduler::Current();
                sched->StopScheduler();
            }
#endif

            if (StateError != iState)
            {
                iState = StateLoaded;
                PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateUnLoaded OUT, moving to next state"));
            }

            RunIfNotReady();
        }
        break;

        case StateLoaded:
        {
            OMX_ERRORTYPE Err;
            OMX_U32 ii;

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateLoaded IN"));
            // allocate memory for ipInBuffer
            ipInBuffer = (OMX_BUFFERHEADERTYPE**) oscl_malloc(sizeof(OMX_BUFFERHEADERTYPE*) * iInBufferCount);
            CHECK_MEM(ipInBuffer, "InputBufferHeader");

            ipInputAvail = (OMX_BOOL*) oscl_malloc(sizeof(OMX_BOOL) * iInBufferCount);
            CHECK_MEM(ipInputAvail, "InputBufferFlag");

            /* Initialize all the buffers to NULL */
            for (ii = 0; ii < iInBufferCount; ii++)
            {
                ipInBuffer[ii] = NULL;
            }

            //allocate memory for output buffer
            ipOutBuffer = (OMX_BUFFERHEADERTYPE**) oscl_malloc(sizeof(OMX_BUFFERHEADERTYPE*) * iOutBufferCount);
            CHECK_MEM(ipOutBuffer, "OutputBuffer");

            ipOutReleased = (OMX_BOOL*) oscl_malloc(sizeof(OMX_BOOL) * iOutBufferCount);
            CHECK_MEM(ipOutReleased, "OutputBufferFlag");

            /* Initialize all the buffers to NULL */
            for (ii = 0; ii < iOutBufferCount; ii++)
            {
                ipOutBuffer[ii] = NULL;
            }

            Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
            CHECK_ERROR(Err, "SendCommand Loaded->Idle");

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                            (0, "OmxDecTestReposition::Run() - Sent State Transition Command from Loaded->Idle"));
            iPendingCommands = 1;

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                            (0, "OmxDecTestReposition::Run() - Allocating %d input and %d output buffers", iInBufferCount, iOutBufferCount));
            //These calls are required because the control of in & out buffer should be with the testapp.
            for (ii = 0; ii < iInBufferCount; ii++)
            {
                Err = OMX_AllocateBuffer(ipAppPriv->Handle, &ipInBuffer[ii], iInputPortIndex, NULL, iInBufferSize);
                CHECK_ERROR(Err, "AllocateBuffer_Input");

                PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                (0, "OmxDecTestReposition::Run() - Called AllocateBuffer for buffer index %d on port %d", ii, iInputPortIndex));
                ipInputAvail[ii] = OMX_TRUE;
                ipInBuffer[ii]->nInputPortIndex = iInputPortIndex;
            }

            if (StateError == iState)
            {
                PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR,
                                (0, "OmxDecTestReposition::Run() - AllocateBuffer Error, StateLoaded OUT"));
                RunIfNotReady();
                break;
            }

            for (ii = 0; ii < iOutBufferCount; ii++)
            {
                Err = OMX_AllocateBuffer(ipAppPriv->Handle, &ipOutBuffer[ii], iOutputPortIndex, NULL, iOutBufferSize);
                CHECK_ERROR(Err, "AllocateBuffer_Output");

                PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                (0, "OmxDecTestReposition::Run() - Called AllocateBuffer for buffer index %d on port %d", ii, iOutputPortIndex));
                ipOutReleased[ii] = OMX_TRUE;

                ipOutBuffer[ii]->nOutputPortIndex = iOutputPortIndex;
                ipOutBuffer[ii]->nInputPortIndex = 0;
            }
            if (StateError == iState)
            {
                PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR,
                                (0, "OmxDecTestReposition::Run() - AllocateBuffer Error, StateLoaded OUT"));
                RunIfNotReady();
                break;
            }
            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateLoaded OUT, Moving to next state"));
        }
        break;

        case StateIdle:
        {
            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateIdle IN"));
            OMX_ERRORTYPE Err = OMX_ErrorNone;

            Err = OMX_FillThisBuffer(ipAppPriv->Handle, ipOutBuffer[0]);
            CHECK_ERROR(Err, "FillThisBuffer");

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                            (0, "OmxDecTestReposition::Run() - FillThisBuffer command called for initiating dynamic port reconfiguration"));

            ipOutReleased[0] = OMX_FALSE;

            Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
            CHECK_ERROR(Err, "SendCommand Idle->Executing");

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                            (0, "OmxDecTestReposition::Run() - Sent State Transition Command from Idle->Executing"));
            iPendingCommands = 1;

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateIdle OUT"));
        }
        break;

        case StateDecodeHeader:
        {
            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE,
                            (0, "OmxDecTestReposition::Run() - StateDecodeHeader IN, Sending configuration input buffers to the component to start dynamic port reconfiguration"));

            if (!iFlagDecodeHeader)
            {
                (*this.*pGetInputFrame)();
                //For AAC component , send one more frame apart from the config frame, so that we can receive the callback
                if (0 == oscl_strcmp(iFormat, "AAC") || 0 == oscl_strcmp(iFormat, "AMR"))
                {
                    (*this.*pGetInputFrame)();
                }
                iFlagDecodeHeader = OMX_TRUE;
                iFrameCount++;

                //Proceed to executing state and if Port settings changed callback comes,
                //then do the dynamic port reconfiguration
                iState = StateExecuting;

                RunIfNotReady();
            }
            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateDecodeHeader OUT"));
        }
        break;

        case StateDisablePort:
        {
            OMX_ERRORTYPE Err = OMX_ErrorNone;
            OMX_U32 ii;

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateDisablePort IN"));

            if (!iDisableRun)
            {
                if (!iFlagDisablePort)
                {
                    Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandPortDisable, iOutputPortIndex, NULL);
                    CHECK_ERROR(Err, "SendCommand_PortDisable");

                    PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                    (0, "OmxDecTestReposition::Run() - Sent Command for OMX_CommandPortDisable on port %d as a part of dynamic port reconfiguration", iOutputPortIndex));

                    iPendingCommands = 1;
                    iFlagDisablePort = OMX_TRUE;
                    RunIfNotReady();
                }
                else
                {
                    //Wait for all the buffers to be returned on output port before freeing them
                    //This wait is required because of the queueing delay in all the Callbacks
                    for (ii = 0; ii < iOutBufferCount; ii++)
                    {
                        if (OMX_FALSE == ipOutReleased[ii])
                        {
                            break;
                        }
                    }

                    if (ii != iOutBufferCount)
                    {
                        PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                        (0, "OmxDecTestReposition::Run() - Not all the output buffers returned by component yet, wait for it"));
                        RunIfNotReady();
                        break;
                    }

                    for (ii = 0; ii < iOutBufferCount; ii++)
                    {
                        if (ipOutBuffer[ii])
                        {
                            Err = OMX_FreeBuffer(ipAppPriv->Handle, iOutputPortIndex, ipOutBuffer[ii]);
                            CHECK_ERROR(Err, "FreeBuffer_Output_DynamicReconfig");
                            ipOutBuffer[ii] = NULL;

                            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                            (0, "OmxDecTestReposition::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iOutputPortIndex));
                        }
                    }

                    if (ipOutBuffer)
                    {
                        oscl_free(ipOutBuffer);
                        ipOutBuffer = NULL;
                    }

                    if (ipOutReleased)
                    {
                        oscl_free(ipOutReleased);
                        ipOutReleased = NULL;
                    }

                    if (StateError == iState)
                    {
                        PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR,
                                        (0, "OmxDecTestReposition::Run() - Error occured in this state, StateDisablePort OUT"));
                        RunIfNotReady();
                        break;
                    }
                    iDisableRun = OMX_TRUE;
                }
            }

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateDisablePort OUT"));
        }
        break;

        case StateDynamicReconfig:
        {
            OMX_BOOL Status = OMX_TRUE;

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateDynamicReconfig IN"));

            Status = HandlePortReEnable();
            if (OMX_FALSE == Status)
            {
                PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR,
                                (0, "OmxDecTestReposition::Run() - Error occured in this state, StateDynamicReconfig OUT"));
                iState = StateError;
                RunIfNotReady();
                break;
            }

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateDynamicReconfig OUT"));
        }
        break;

        case StateExecuting:
        {
            OMX_U32 Index;
            OMX_BOOL MoreOutput;
            OMX_ERRORTYPE Err = OMX_ErrorNone;

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateExecuting IN"));

            //After Processing N number of buffers, send the flush command on both the ports
            if ((iFrameCount > TEST_NUM_BUFFERS_TO_PROCESS) && (OMX_FALSE == iRepositionCommandSent))
            {
                OMX_ERRORTYPE Err = OMX_ErrorNone;
                Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
                CHECK_ERROR(Err, "SendCommand Executing->Idle");

                PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                (0, "OmxDecTestReposition::Run() - State transition command send from Executing ->Idle to indicate repositioning of the clip"));

                iPendingCommands = 1;
                iRepositionCommandSent = OMX_TRUE;
            }
            else
            {
                MoreOutput = OMX_TRUE;
                while (MoreOutput)
                {
                    Index = 0;
                    while (OMX_FALSE == ipOutReleased[Index] && Index < iOutBufferCount)
                    {
                        Index++;
                    }

                    if (Index != iOutBufferCount)
                    {
                        //This call is being made only once per frame
                        Err = OMX_FillThisBuffer(ipAppPriv->Handle, ipOutBuffer[Index]);
                        CHECK_ERROR(Err, "FillThisBuffer");
                        //Reset this till u receive the callback for output buffer free
                        ipOutReleased[Index] = OMX_FALSE;

                        PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                        (0, "OmxDecTestReposition::Run() - FillThisBuffer command called for output buffer index %d", Index));
                    }
                    else
                    {
                        MoreOutput = OMX_FALSE;
                    }
                } //while (MoreOutput) loop end here


                if (!iStopProcessingInput || (OMX_ErrorInsufficientResources == iStatusExecuting))
                {
                    // find available input buffer
                    Index = 0;
                    while (OMX_FALSE == ipInputAvail[Index] && Index < iInBufferCount)
                    {
                        Index++;
                    }

                    if (Index != iInBufferCount)
                    {
                        iStatusExecuting = (*this.*pGetInputFrame)();
                        iFrameCount++;
                    }
                }
                else if (OMX_FALSE == iEosFlagExecuting)
                {
                    //Only send one successful dummy buffer with flag set to signal EOS
                    Index = 0;
                    while (OMX_FALSE == ipInputAvail[Index] && Index < iInBufferCount)
                    {
                        Index++;
                    }

                    if (Index != iInBufferCount)
                    {
                        ipInBuffer[Index]->nFlags |= OMX_BUFFERFLAG_EOS;
                        ipInBuffer[Index]->nFilledLen = 0;
                        Err = OMX_EmptyThisBuffer(ipAppPriv->Handle, ipInBuffer[Index]);

                        CHECK_ERROR(Err, "EmptyThisBuffer_EOS");

                        ipInputAvail[Index] = OMX_FALSE; // mark unavailable
                        iEosFlagExecuting = OMX_TRUE;

                        PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                        (0, "OmxDecTestReposition::Run() - Input buffer sent to the component with OMX_BUFFERFLAG_EOS flag set"));
                    }
                }
                else
                {
                    //nothing to do here
                }

                RunIfNotReady();
            }
            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateExecuting OUT"));

        }
        break;

        case StateIntermediate:
        {
            OMX_ERRORTYPE Err = OMX_ErrorNone;
            OMX_BOOL Status;

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestReposition::Run() - Repositioning the stream to the start"));

            Status = ResetStream();

            if (OMX_FALSE == Status)
            {
                iState = StateError;
                RunIfNotReady();
                break;
            }

            //Now resume processing by changing state to Executing again
            Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
            CHECK_ERROR(Err, "SendCommand Idle->Executing");

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG, (0, "OmxDecTestReposition::Run() - Resume processing by state transition command from Idle->Executing"));

            iPendingCommands = 1;
        }
        break;


        case StateStopping:
        {
            OMX_ERRORTYPE Err = OMX_ErrorNone;

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateStopping IN"));

            //stop execution by state transition to Idle state.
            if (!iFlagStopping)
            {
                Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
                CHECK_ERROR(Err, "SendCommand Executing->Idle");

                PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                (0, "OmxDecTestReposition::Run() - Sent State Transition Command from Executing->Idle"));

                iPendingCommands = 1;
                iFlagStopping = OMX_TRUE;
            }

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateStopping OUT"));
        }
        break;

        case StateCleanUp:
        {
            OMX_U32 ii;
            OMX_ERRORTYPE Err = OMX_ErrorNone;

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateCleanUp IN"));


            if (!iFlagCleanUp)
            {
                //Added a check here to verify whether all the ip/op buffers are returned back by the component or not
                //in case of Executing->Idle state transition

                if (OMX_FALSE == VerifyAllBuffersReturned())
                {
                    // not all buffers have been returned yet, reschedule
                    RunIfNotReady();
                    break;
                }

                //Destroy the component by state transition to Loaded state
                Err = OMX_SendCommand(ipAppPriv->Handle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
                CHECK_ERROR(Err, "SendCommand Idle->Loaded");

                PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                (0, "OmxDecTestReposition::Run() - Sent State Transition Command from Idle->Loaded"));

                iPendingCommands = 1;

                if (ipInBuffer)
                {
                    for (ii = 0; ii < iInBufferCount; ii++)
                    {
                        if (ipInBuffer[ii])
                        {
                            Err = OMX_FreeBuffer(ipAppPriv->Handle, iInputPortIndex, ipInBuffer[ii]);
                            CHECK_ERROR(Err, "FreeBuffer_Input");
                            ipInBuffer[ii] = NULL;

                            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                            (0, "OmxDecTestReposition::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iInputPortIndex));
                        }
                    }

                    oscl_free(ipInBuffer);
                    ipInBuffer = NULL;
                }

                if (ipInputAvail)
                {
                    oscl_free(ipInputAvail);
                    ipInputAvail = NULL;
                }


                if (ipOutBuffer)
                {
                    for (ii = 0; ii < iOutBufferCount; ii++)
                    {
                        if (ipOutBuffer[ii])
                        {
                            Err = OMX_FreeBuffer(ipAppPriv->Handle, iOutputPortIndex, ipOutBuffer[ii]);
                            CHECK_ERROR(Err, "FreeBuffer_Output");
                            ipOutBuffer[ii] = NULL;

                            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                            (0, "OmxDecTestReposition::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iOutputPortIndex));
                        }
                    }
                    oscl_free(ipOutBuffer);
                    ipOutBuffer = NULL;
                }

                if (ipOutReleased)
                {
                    oscl_free(ipOutReleased);
                    ipOutReleased = NULL;
                }

                iFlagCleanUp = OMX_TRUE;
            }

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateCleanUp OUT"));

        }
        break;


        /********* FREE THE HANDLE & CLOSE FILES FOR THE COMPONENT ********/
        case StateStop:
        {
            OMX_U8 TestName[] = "REPOSITIONING_TEST";
            OMX_ERRORTYPE Err = OMX_ErrorNone;

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateStop IN"));

            if (ipAppPriv)
            {
                if (ipAppPriv->Handle)
                {
                    PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                    (0, "OmxDecTestReposition::Run() - Free the Component Handle"));

                    Err = OMX_MasterFreeHandle(ipAppPriv->Handle);
                    if (OMX_ErrorNone != Err)
                    {
                        PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestReposition::Run() - FreeHandle Error"));
                        iTestStatus = OMX_FALSE;
                    }
                }
            }

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                            (0, "OmxDecTestReposition::Run() - De-initialize the omx component"));

            Err = OMX_MasterDeinit();
            if (OMX_ErrorNone != Err)
            {
                PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_ERR, (0, "OmxDecTestReposition::Run() - OMX_MasterDeinit Error"));
                iTestStatus = OMX_FALSE;
            }

            if (0 == oscl_strcmp(iFormat, "H264"))
            {
                if (ipAVCBSO)
                {
                    OSCL_DELETE(ipAVCBSO);
                    ipAVCBSO = NULL;
                }
            }

            if (0 == oscl_strcmp(iFormat, "M4V") || 0 == oscl_strcmp(iFormat, "H263"))
            {
                if (ipBitstreamBuffer)
                {
                    oscl_free(ipBitstreamBufferPointer);
                    ipBitstreamBuffer = NULL;
                    ipBitstreamBufferPointer = NULL;
                }
            }

            if (0 == oscl_strcmp(iFormat, "MP3"))
            {
                if (ipMp3Bitstream)
                {
                    OSCL_DELETE(ipMp3Bitstream);
                    ipMp3Bitstream = NULL;
                }
            }

            if (iOutputParameters)
            {
                oscl_free(iOutputParameters);
                iOutputParameters = NULL;
            }

            if (ipAppPriv)
            {
                oscl_free(ipAppPriv);
                ipAppPriv = NULL;
            }

#if PROXY_INTERFACE
            if (ipThreadSafeHandlerEventHandler)
            {
                OSCL_DELETE(ipThreadSafeHandlerEventHandler);
                ipThreadSafeHandlerEventHandler = NULL;
            }

            if (ipThreadSafeHandlerEmptyBufferDone)
            {
                OSCL_DELETE(ipThreadSafeHandlerEmptyBufferDone);
                ipThreadSafeHandlerEmptyBufferDone = NULL;
            }

            if (ipThreadSafeHandlerFillBufferDone)
            {
                OSCL_DELETE(ipThreadSafeHandlerFillBufferDone);
                ipThreadSafeHandlerFillBufferDone = NULL;
            }
#endif

            if (ipOutputFile)
            {
                VerifyOutput(TestName);
            }
            else
            {
                if (OMX_FALSE == iTestStatus)
                {
#ifdef PRINT_RESULT
                    fprintf(iConsOutFile, "%s: Fail \n", TestName);
                    OMX_DEC_TEST(false);
                    iTestCase->TestCompleted();
#endif
                    PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_INFO,
                                    (0, "OmxDecTestReposition::Run() - %s : Fail", TestName));
                }
                else
                {
#ifdef PRINT_RESULT
                    fprintf(iConsOutFile, "%s: Success {Output file not available} \n", TestName);
                    OMX_DEC_TEST(true);
                    iTestCase->TestCompleted();
#endif
                    PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_INFO,
                                    (0, "OmxDecTestReposition::Run() - %s : Success {Output file not available}", TestName));
                }
            }

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateStop OUT"));

            iState = StateUnLoaded;
            OsclExecScheduler* sched = OsclExecScheduler::Current();
            sched->StopScheduler();
        }
        break;

        case StateError:
        {
            //Do all the cleanup's and exit from here
            OMX_U32 ii;

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateError IN"));

            iTestStatus = OMX_FALSE;

            if (ipInBuffer)
            {
                for (ii = 0; ii < iInBufferCount; ii++)
                {
                    if (ipInBuffer[ii])
                    {
                        OMX_FreeBuffer(ipAppPriv->Handle, iInputPortIndex, ipInBuffer[ii]);
                        ipInBuffer[ii] = NULL;

                        PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                        (0, "OmxDecTestReposition::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iInputPortIndex));
                    }
                }
                oscl_free(ipInBuffer);
                ipInBuffer = NULL;
            }

            if (ipInputAvail)
            {
                oscl_free(ipInputAvail);
                ipInputAvail = NULL;
            }

            if (ipOutBuffer)
            {
                for (ii = 0; ii < iOutBufferCount; ii++)
                {
                    if (ipOutBuffer[ii])
                    {
                        OMX_FreeBuffer(ipAppPriv->Handle, iOutputPortIndex, ipOutBuffer[ii]);
                        ipOutBuffer[ii] = NULL;

                        PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_DEBUG,
                                        (0, "OmxDecTestReposition::Run() - Called FreeBuffer for buffer index %d on port %d", ii, iOutputPortIndex));
                    }
                }
                oscl_free(ipOutBuffer);
                ipOutBuffer = NULL;
            }

            if (ipOutReleased)
            {
                oscl_free(ipOutReleased);
                ipOutReleased = NULL;
            }

            iState = StateStop;
            RunIfNotReady();

            PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "OmxDecTestReposition::Run() - StateError OUT"));

        }
        break;

        default:
        {
            break;
        }
    }
    return ;
}
Exemple #13
0
BOOL SpdyFramesHandler::TryToParseHeader()
{
	const UINT32 maxHeaderLength = 18;// the longest spdy frame header is 18 bytes long
	char header[maxHeaderLength]; /* ARRAY OK 2012-04-29 kswitalski */
	size_t header_len = MIN(buffer.Length(), maxHeaderLength);
	if (header_len < 4)
		return FALSE;

	buffer.CopyInto(header, header_len);

	if (header_len < SpdyFrameHeader::GetSize())
		return FALSE;
	else
	{
		if (reinterpret_cast<SpdyFrameHeader *>(header)->IsControl())
		{
			if (header_len < ControlFrameHeader::GetSize())
				return FALSE;
			
			ControlFrameHeader *controlFrame = reinterpret_cast<ControlFrameHeader *>(header);
			if (controlFrame->GetVersion() != version)
			{
				listener->OnProtocolError();
				return FALSE;
			}

			switch (controlFrame->GetType())
			{
			case SCT_SYN_STREAM:
				if (header_len >= SynStreamFrameHeader::GetSize())
				{
					// we don't have support for push/hint yet
					SynStreamFrameHeader *synStreamFrame = reinterpret_cast<SynStreamFrameHeader *>(header);
					CALL_ON_SELFTESTLISTENER(OnReceivedSynStream, (synStreamFrame->GetStreamId()));
					if (synStreamFrame->GetStreamId() % 2 == nextStreamId % 2)
					{
						listener->OnProtocolError();
						return FALSE;
					}
					decompressingConsumer.SetAmountOfDataToConsume(synStreamFrame->GetHeadersBlockSize());
					activeDataConsumer = &decompressingConsumer;
					buffer.Consume(SynStreamFrameHeader::GetSize());
					ResetStream(synStreamFrame->GetStreamId(), SRS_REFUSED_STREAM);
					return TRUE;
				}
				break;
			case SCT_SYN_REPLY:
				if (header_len >= SynReplyFrameHeader::GetSize(version))
				{
					SynReplyFrameHeader *synReplyFrame = reinterpret_cast<SynReplyFrameHeader *>(header);
					CALL_ON_SELFTESTLISTENER(OnReceivedSynReply, (synReplyFrame->GetStreamId()));
					SpdyStreamHandler *stream = FindStream(synReplyFrame->GetStreamId());
					
					if (stream && stream->AcceptsNewFrames() && !stream->ReceivedSynReply())
					{
						stream->SynReplyFrameLoaded(synReplyFrame);
						activeDataConsumer = stream;
					}
					else
					{
						if (stream && stream->ReceivedSynReply())
							stream->Reset(SRS_PROTOCOL_ERROR);
						decompressingConsumer.SetAmountOfDataToConsume(synReplyFrame->GetHeadersBlockSize(version));
						activeDataConsumer = &decompressingConsumer;
					}
					
					buffer.Consume(SynReplyFrameHeader::GetSize(version));
					return TRUE;
				}
				break;
			case SCT_SETTINGS:
				if (header_len >= SettingsFrameHeader::GetSize())
				{
					SettingsFrameHeader *settingsFrame = reinterpret_cast<SettingsFrameHeader *>(header);
					settingsController.SettingsFrameLoaded(settingsFrame);
					buffer.Consume(SettingsFrameHeader::GetSize());
					activeDataConsumer = &settingsController;
					return TRUE;
				}
				break;
			case SCT_RST_STREAM:
				if (header_len >= ResetStreamFrameHeader::GetSize())
				{
					ResetStreamFrameHeader *resetFrame = reinterpret_cast<ResetStreamFrameHeader *>(header);
					CALL_ON_SELFTESTLISTENER(OnReceivedReset, (resetFrame->GetStreamId(), resetFrame->GetStatusCode()));
					SpdyStreamHandler *stream = FindStream(resetFrame->GetStreamId());
					if (stream && stream->AcceptsNewFrames())
						stream->ResetFrameLoaded(resetFrame);
					buffer.Consume(ResetStreamFrameHeader::GetSize());
					return TRUE;
				}
				break;
			case SCT_NOOP:
				buffer.Consume(NoopFrameHeader::GetSize());
				return TRUE;
			case SCT_PING:
				if (header_len >= PingFrameHeader::GetSize())
				{
					PingFrameHeader *pingFrame = reinterpret_cast<PingFrameHeader *>(header);
					pingController.PingFrameLoaded(pingFrame);
					buffer.Consume(PingFrameHeader::GetSize());
					return TRUE;
				}
				break;
			case SCT_GOAWAY:
				if (header_len >= GoawayFrameHeader::GetSize(version))
				{
					GoawayFrameHeader *goawayFrame = reinterpret_cast<GoawayFrameHeader *>(header);
					CALL_ON_SELFTESTLISTENER(OnReceivedGoAway, ());
					buffer.Consume(GoawayFrameHeader::GetSize(version));
					noMoreStreams = TRUE;
					listener->OnGoAway();
					CancelStreamsWithHigherId(goawayFrame->GetLastGoodStreamId());
					return TRUE;
				}
				break;
			case SCT_HEADERS:
				if (header_len >= HeadersFrameHeader::GetSize(version))
				{
					HeadersFrameHeader *headersFrame = reinterpret_cast<HeadersFrameHeader *>(header);
					SpdyStreamHandler *stream = FindStream(headersFrame->GetStreamId());
					if (stream && stream->AcceptsNewFrames())
					{
						stream->HeadersFrameLoaded(headersFrame);
						activeDataConsumer = stream;
					}
					else
					{
						decompressingConsumer.SetAmountOfDataToConsume(headersFrame->GetHeadersBlockSize(version));
						activeDataConsumer = &decompressingConsumer;
					}
					buffer.Consume(HeadersFrameHeader::GetSize(version));
					return TRUE;
				}
			case SCT_WINDOW_UPDATE:
				if (header_len >= WindowUpdateFrameHeader::GetSize())
				{
					WindowUpdateFrameHeader *windowUpdateFrame = reinterpret_cast<WindowUpdateFrameHeader *>(header);
					SpdyStreamHandler *stream = FindStream(windowUpdateFrame->GetStreamId());
					if (stream && stream->AcceptsNewFrames())
						stream->WindowUpdateFrameLoaded(windowUpdateFrame);
					buffer.Consume(WindowUpdateFrameHeader::GetSize());
					return TRUE;
				}
			default:
				listener->OnProtocolError();
			}
		}
		else
		{
			if (header_len < DataFrameHeader::GetSize())