bool VideoCaptureDeviceImpl::setCurrentVideoFormat(
    const RGBVideoFormat& videoFormat) {
  if (!isInitialized()) {
    return false;
  }

  if (!videoFormat) {
    return false;
  }

  if (!stopCapturing()) {
    return false;
  }

  const Uuid videoFormatUuid(videoFormat.uuid());
  if (videoFormatUuid.is_nil()) {
    return false;
  }

  VideoFormatConstIterator iterator(
      m_videoFormatsByUuid.find(videoFormatUuid));
  if (iterator == m_videoFormatsByUuid.end()) {
    return false;
  }

  const UuidVideoFormatPair uuidVideoFormatPair(*iterator);
  const VideoFormatSharedPtr pVideoFormat(uuidVideoFormatPair.second);
  if (!pVideoFormat) {
    return false;
  }

  m_currentVideoFormatUuid = uuidVideoFormatPair.first;

  if (!pVideoFormat->setMediaTypeOfStream(m_pStreamConfig)) {
    return false;
  }

  return true;
}