Example #1
0
MediaStream::MediaStream(ExecutionContext* context,
                         const MediaStreamTrackVector& audioTracks,
                         const MediaStreamTrackVector& videoTracks)
    : m_scheduledEventTimer(this, &MediaStream::scheduledEventTimerFired),
      m_executionContext(context) {
  MediaStreamComponentVector audioComponents;
  MediaStreamComponentVector videoComponents;

  MediaStreamTrackVector::const_iterator iter;
  for (iter = audioTracks.begin(); iter != audioTracks.end(); ++iter) {
    (*iter)->registerMediaStream(this);
    audioComponents.append((*iter)->component());
  }
  for (iter = videoTracks.begin(); iter != videoTracks.end(); ++iter) {
    (*iter)->registerMediaStream(this);
    videoComponents.append((*iter)->component());
  }

  m_descriptor =
      MediaStreamDescriptor::create(audioComponents, videoComponents);
  m_descriptor->setClient(this);
  MediaStreamCenter::instance().didCreateMediaStream(m_descriptor);

  m_audioTracks = audioTracks;
  m_videoTracks = videoTracks;
  if (emptyOrOnlyEndedTracks()) {
    m_descriptor->setActive(false);
  }
}
Example #2
0
void UserMediaRequest::callSuccessHandler(PassRefPtr<MediaStreamDescriptor> streamDescriptor)
{
    // 4 - Create the MediaStream and pass it to the success callback.
    ASSERT(m_successCallback);

    RefPtr<MediaStream> stream = MediaStream::create(m_scriptExecutionContext, streamDescriptor);

    MediaStreamTrackVector tracks = stream->getAudioTracks();
    for (MediaStreamTrackVector::iterator iter = tracks.begin(); iter != tracks.end(); ++iter)
        (*iter)->source()->setConstraints(m_audioConstraints);

    tracks = stream->getVideoTracks();
    for (MediaStreamTrackVector::iterator iter = tracks.begin(); iter != tracks.end(); ++iter)
        (*iter)->source()->setConstraints(m_videoConstraints);

    m_successCallback->handleEvent(stream.get());
}
void UserMediaRequest::succeed(PassRefPtr<MediaStreamDescriptor> streamDescriptor)
{
    if (!executionContext())
        return;

    RefPtrWillBeRawPtr<MediaStream> stream = MediaStream::create(executionContext(), streamDescriptor);

    MediaStreamTrackVector audioTracks = stream->getAudioTracks();
    for (MediaStreamTrackVector::iterator iter = audioTracks.begin(); iter != audioTracks.end(); ++iter) {
        (*iter)->component()->source()->setConstraints(m_audio);
    }

    MediaStreamTrackVector videoTracks = stream->getVideoTracks();
    for (MediaStreamTrackVector::iterator iter = videoTracks.begin(); iter != videoTracks.end(); ++iter) {
        (*iter)->component()->source()->setConstraints(m_video);
    }

    m_successCallback->handleEvent(stream.get());
}