コード例 #1
0
  NS_IMETHOD
  Run()
  {
    NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");

    uint32_t audioCount, videoCount, i;
    MediaManager* manager = MediaManager::Get();

    nsTArray<nsRefPtr<MediaEngineVideoSource> > videoSources;
    manager->GetBackend()->EnumerateVideoDevices(&videoSources);
    videoCount = videoSources.Length();

    nsTArray<nsRefPtr<MediaEngineAudioSource> > audioSources;
    manager->GetBackend()->EnumerateAudioDevices(&audioSources);
    audioCount = audioSources.Length();

    nsTArray<nsCOMPtr<nsIMediaDevice> > *devices =
      new nsTArray<nsCOMPtr<nsIMediaDevice> >;

    for (i = 0; i < videoCount; i++) {
      devices->AppendElement(new MediaDevice(videoSources[i]));
    }
    for (i = 0; i < audioCount; i++) {
      devices->AppendElement(new MediaDevice(audioSources[i]));
    }

    NS_DispatchToMainThread(new DeviceSuccessCallbackRunnable(
      mSuccess, mError, *devices
    ));
    return NS_OK;
  }
コード例 #2
0
ファイル: SpeechRecognition.cpp プロジェクト: seinlin/gecko
void
SpeechRecognition::Start(ErrorResult& aRv)
{
  if (!mCurrentState == STATE_IDLE) {
    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
    return;
  }

  nsAutoCString speechRecognitionServiceCID;
  GetRecognitionServiceCID(speechRecognitionServiceCID);

  nsresult rv;
  mRecognitionService = do_GetService(speechRecognitionServiceCID.get(), &rv);
  NS_ENSURE_SUCCESS_VOID(rv);

  rv = mRecognitionService->Initialize(this->asWeakPtr());
  NS_ENSURE_SUCCESS_VOID(rv);

  AutoSafeJSContext cx;
  MediaStreamConstraints constraints;
  constraints.mAudio.SetAsBoolean() = true;

  if (!mTestConfig.mFakeFSMEvents) {
    MediaManager* manager = MediaManager::Get();
    manager->GetUserMedia(cx,
                          false,
                          GetOwner(),
                          constraints,
                          new GetUserMediaSuccessCallback(this),
                          new GetUserMediaErrorCallback(this));
  }

  nsRefPtr<SpeechEvent> event = new SpeechEvent(this, EVENT_START);
  NS_DispatchToMainThread(event);
}
コード例 #3
0
void
SpeechRecognition::Start(const Optional<NonNull<DOMMediaStream>>& aStream, ErrorResult& aRv)
{
    if (mCurrentState != STATE_IDLE) {
        aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
        return;
    }

    nsAutoCString speechRecognitionServiceCID;
    GetRecognitionServiceCID(speechRecognitionServiceCID);

    nsresult rv;
    mRecognitionService = do_GetService(speechRecognitionServiceCID.get(), &rv);
    NS_ENSURE_SUCCESS_VOID(rv);

    rv = mRecognitionService->Initialize(this);
    NS_ENSURE_SUCCESS_VOID(rv);

    MediaStreamConstraints constraints;
    constraints.mAudio.SetAsBoolean() = true;

    if (aStream.WasPassed()) {
        StartRecording(&aStream.Value());
    } else {
        MediaManager* manager = MediaManager::Get();
        manager->GetUserMedia(false,
                              GetOwner(),
                              constraints,
                              new GetUserMediaSuccessCallback(this),
                              new GetUserMediaErrorCallback(this));
    }

    nsRefPtr<SpeechEvent> event = new SpeechEvent(this, EVENT_START);
    NS_DispatchToMainThread(event);
}
コード例 #4
0
ファイル: manager.cpp プロジェクト: rickcaudill/Pyro
/** Provides access to the MediaManager class.
 * \par Description:
 *  Creates a new media manager if it does not exist. Otherwise return a pointer
 * to the current one.
 * \par Note:
 * Make sure you call Put() afterwards. If the creation fails, an exception will
 * be thrown.
 * \sa Put()
 * \author	Arno Klenke ([email protected])
 *****************************************************************************/
MediaManager* MediaManager::Get()
{
	MediaManager* pcManager = s_pcInstance;
	if( pcManager == NULL ) {
		pcManager = new MediaManager();
	} else
		pcManager->AddRef();
	return( pcManager );
}
コード例 #5
0
ファイル: stage.cpp プロジェクト: rickcaudill/Pyro
/** Creates a output stage for the default video output.
 * \par Description:
 * Creates a output stage for the default video output.
 * \author	Arno Klenke
 ******************************************************************************/
MediaOutputStage* MediaOutputStage::CreateDefaultVideoOutputStage( os::String zParameters )
{
    MediaManager* pcManager = MediaManager::Get();
    if( pcManager == NULL )
        return( NULL );
    MediaOutput* pcOutput = pcManager->GetDefaultVideoOutput();
    pcManager->Put();
    if( pcOutput == NULL || pcOutput->Open( zParameters ) != 0 )
        return( NULL );

    MediaOutputStage* pcStage = new MediaOutputStage();
    pcStage->SetOutput( pcOutput );
    pcOutput->Release();
    return( pcStage );
}
コード例 #6
0
  NS_IMETHOD
  Run()
  {
    NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");

    uint32_t audioCount, videoCount, i;
    MediaManager* manager = MediaManager::Get();

    nsTArray<nsRefPtr<MediaEngineVideoSource> > videoSources;
    manager->GetBackend()->EnumerateVideoDevices(&videoSources);
    videoCount = videoSources.Length();

    nsTArray<nsRefPtr<MediaEngineAudioSource> > audioSources;
    manager->GetBackend()->EnumerateAudioDevices(&audioSources);
    audioCount = audioSources.Length();

    nsTArray<nsCOMPtr<nsIMediaDevice> > *devices =
      new nsTArray<nsCOMPtr<nsIMediaDevice> >;

    /**
     * We only display available devices in the UI for now. We can easily
     * change this later, when we implement a more sophisticated UI that
     * lets the user revoke a device currently held by another tab (or
     * we decide to provide a stream from a device already allocated).
     */
    for (i = 0; i < videoCount; i++) {
      nsRefPtr<MediaEngineVideoSource> vSource = videoSources[i];
      if (vSource->IsAvailable()) {
        devices->AppendElement(new MediaDevice(vSource));
      }
    }
    for (i = 0; i < audioCount; i++) {
      nsRefPtr<MediaEngineAudioSource> aSource = audioSources[i];
      if (aSource->IsAvailable()) {
        devices->AppendElement(new MediaDevice(aSource));
      }
    }

    NS_DispatchToMainThread(new DeviceSuccessCallbackRunnable(
      mSuccess, mError, *devices
    ));
    return NS_OK;
  }
コード例 #7
0
void
SpeechRecognition::Start(const Optional<NonNull<DOMMediaStream>>& aStream,
                         CallerType aCallerType,
                         ErrorResult& aRv)
{
  if (mCurrentState != STATE_IDLE) {
    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
    return;
  }

  if (!SetRecognitionService(aRv)) {
    return;
  }

  if (!ValidateAndSetGrammarList(aRv)) {
    return;
  }

  nsresult rv;
  rv = mRecognitionService->Initialize(this);
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return;
  }

  MediaStreamConstraints constraints;
  constraints.mAudio.SetAsBoolean() = true;

  if (aStream.WasPassed()) {
    StartRecording(&aStream.Value());
  } else {
    AutoNoJSAPI();
    MediaManager* manager = MediaManager::Get();
    manager->GetUserMedia(GetOwner(),
                          constraints,
                          new GetUserMediaSuccessCallback(this),
                          new GetUserMediaErrorCallback(this),
                          aCallerType);
  }

  RefPtr<SpeechEvent> event = new SpeechEvent(this, EVENT_START);
  NS_DispatchToMainThread(event);
}
コード例 #8
0
ファイル: stage.cpp プロジェクト: rickcaudill/Pyro
/** Creates a stage object for a file.
 * \par Description:
 * Creates a stage object for a file.
 * \param zFileName - The filename.
 * \author	Arno Klenke
 ******************************************************************************/
MediaInputStage* MediaInputStage::CreateStageForFile( String zFileName )
{
    MediaManager* pcManager = MediaManager::Get();
    if( pcManager == NULL )
        return( NULL );
    MediaInput* pcInput = pcManager->GetBestInput( zFileName );
    pcManager->Put();
    if( pcInput == NULL || pcInput->Open( zFileName ) != 0 )
        return( NULL );
    if( !pcInput->PacketBased() )
    {
        pcInput->Release();
        return( NULL );
    }

    pcInput->SelectTrack( 0 );
    MediaInputStage* pcStage = new MediaInputStage();
    pcStage->SetInput( pcInput );
    pcInput->Release();
    return( pcStage );
}
コード例 #9
0
ファイル: stage.cpp プロジェクト: rickcaudill/Pyro
status_t MediaDecoderStage::Initialize()
{
    printf( "Looking for best codec...\n" );
    if( m_pcCodec == NULL )
    {
        MediaStage* pcNext;
        MediaStage* pcPrev;
        uint32 nNextInput;
        uint32 nPrevOutput;
        GetNextStage( 0, &pcNext, &nNextInput );
        if( pcNext == NULL )
            return( -EINVAL );

        GetPrevStage( 0, &pcPrev, &nPrevOutput );
        if( pcPrev == NULL )
            return( -EINVAL );
        MediaManager* pcManager = MediaManager::Get();
        if( pcManager == NULL )
            return( -EINVAL );
        MediaCodec* pcCodec = NULL;
        uint j;
        for( j = 0; j < pcNext->GetInputFormatCount( nNextInput ); j++ )
        {
            pcCodec = pcManager->GetBestCodec( pcPrev->GetOutputFormat( nPrevOutput ), pcNext->GetInputFormat( nNextInput, j ), false );
            if( pcCodec != NULL )
            {
                printf( "Found matching codec for %s ( %s ) -> %s ( %s )\n", pcPrev->GetIdentifier().c_str(), pcPrev->GetOutputFormat( nPrevOutput ).zName.c_str(),
                        pcNext->GetIdentifier().c_str(), pcNext->GetInputFormat( nNextInput, j ).zName.c_str() );
                break;
            }
        }
        if( pcCodec == NULL )
        {
            printf( "Could not find codec!" );
            return( -EINVAL );
        }


        pcCodec->Open( pcPrev->GetOutputFormat( nPrevOutput ), pcNext->GetInputFormat( nNextInput, j ), false );
        if( pcCodec->GetExternalFormat().nType == MEDIA_TYPE_AUDIO )
        {
            printf( "Creating audio output packet!\n" );
            if( pcCodec->CreateAudioOutputPacket( &m_sPacket ) != 0 )
            {
                pcCodec->Release();
                return( -EINVAL );
            }
            m_bAudio = true;
        }
        else if( pcCodec->GetExternalFormat().nType == MEDIA_TYPE_VIDEO )
        {
            printf( "Creating video output packet!\n" );
            if( pcCodec->CreateVideoOutputPacket( &m_sPacket ) != 0 )
            {
                pcCodec->Release();
                return( -EINVAL );
            }
            m_bVideo = true;
        }
        m_pcCodec = pcCodec;
        printf( "Found codec %s\n", pcCodec->GetIdentifier().c_str() );
        printf( "*****Input format*****\n" );
        DumpFormat( pcCodec->GetInternalFormat() );
        printf( "*****Output format******\n" );
        DumpFormat( pcCodec->GetExternalFormat() );
        pcManager->Put();
    }
    return( 0 );
}