Beispiel #1
0
AMControl* AMControlSet::controlNamed(const QString& controlName) {
	int index = indexOfKey(controlName);
	if(index < 0)
		return 0;

	return at(index);
}
status_t AudioPolicyMixCollection::getInputMixForAttr(audio_attributes_t attr, AudioMix **policyMix)
{
    if (strncmp(attr.tags, "addr=", strlen("addr=")) != 0) {
        return BAD_VALUE;
    }
    String8 address(attr.tags + strlen("addr="));

#ifdef LOG_NDEBUG
    ALOGV("getInputMixForAttr looking for address %s\n  mixes available:", address.string());
    for (size_t i = 0; i < size(); i++) {
            sp<AudioPolicyMix> policyMix = valueAt(i);
            AudioMix *mix = policyMix->getMix();
            ALOGV("\tmix %zu address=%s", i, mix->mDeviceAddress.string());
    }
#endif

    ssize_t index = indexOfKey(address);
    if (index < 0) {
        ALOGW("getInputMixForAttr() no policy for address %s", address.string());
        return BAD_VALUE;
    }
    sp<AudioPolicyMix> audioPolicyMix = valueAt(index);
    AudioMix *mix = audioPolicyMix->getMix();

    if (mix->mMixType != MIX_TYPE_PLAYERS) {
        ALOGW("getInputMixForAttr() bad policy mix type for address %s", address.string());
        return BAD_VALUE;
    }
    *policyMix = mix;
    return NO_ERROR;
}
Beispiel #3
0
void IndexNode::shiftAndInsert(int key){
   
    int index = indexOfKey(key);
    TreeNode::shiftAndInsert(key);
    
    for (int i = getCount() - 1; i > index; i--){
        m_children[i + 1] = m_children[i];
    }
    
}
status_t SoundTriggerSessionCollection::releaseSession(audio_session_t session)
{
    ssize_t index = indexOfKey(session);
    if (index < 0) {
        ALOGW("acquireSoundTriggerSession() session %d not registered", session);
        return BAD_VALUE;
    }

    removeItem(session);
    return NO_ERROR;
}
status_t AudioPolicyMixCollection::unregisterMix(const String8& address)
{
    ssize_t index = indexOfKey(address);
    if (index < 0) {
        ALOGE("unregisterPolicyMixes(): mix for address %s not registered", address.string());
        return BAD_VALUE;
    }

    removeItemsAt(index);
    return NO_ERROR;
}
status_t AudioPolicyMixCollection::getAudioPolicyMix(const String8& address,
                                                     sp<AudioPolicyMix> &policyMix) const
{
    ssize_t index = indexOfKey(address);
    if (index < 0) {
        ALOGE("unregisterPolicyMixes(): mix for address %s not registered", address.string());
        return BAD_VALUE;
    }
    policyMix = valueAt(index);
    return NO_ERROR;
}
Beispiel #7
0
IndexNode * IndexNode::split(int key, TreeNode *left, TreeNode *right, int &middle){
    assert(getCount() == getMax());
    
    //merge keys and children together
    int order = getMax();
    int *merged = new int[order + 1];
    int index = indexOfKey(key);
    int * keys = getKeys();
    TreeNode **mergedNodes = new TreeNode*[order + 2];
    for (int i = 0 ; i < index; i ++){
        merged[i] = keys[i];
        mergedNodes[i] = m_children[i];
    }
    merged[index] = key;
    mergedNodes[index] = left;
    mergedNodes[index+1] = right;
    for (int i = index + 1; i < order + 1; i ++){
        merged[i] = keys[i-1];
        mergedNodes[i+1] = m_children[i];
    }
    int half = (order + 1) / 2;
    //half is returned to be pushed up
    middle = merged[half];
    
    //split keys and children for left node
    for (int i = 0; i < half; i++){
        keys[i] = merged[i];
        m_children[i] = mergedNodes[i];
    }
    m_children[half] = mergedNodes[half];

    for (int i = half + 1; i < order+1; i++){
        m_children[i] = nullptr;
    }
    
    setCount(half);
    
    //split keys and children for second node
    IndexNode * sibling = new IndexNode(getOrder());
    int * s_keys = sibling->getKeys();
    TreeNode **s_children = sibling->m_children;
    for (int i = half + 1; i < order + 1; i++){
        s_keys[i - (half + 1)] = merged[i];
        s_children[i - (half + 1)] = mergedNodes[i];
        s_children[i - (half + 1)]->setParent(sibling);
        sibling->increment();
    }
    s_children[order + 1 - (half + 1)] = mergedNodes[order+1];
    s_children[order + 1 - (half + 1)]->setParent(sibling);
    delete[] merged;
    delete mergedNodes;
    return sibling;
}
Beispiel #8
0
 /**
  * Removes the mapping for a key from this map if it is present
  * (optional operation).
  *
  * @param key the key to be removed.
  * @throws NullPointerException if the key is null.
  */
 virtual V remove(K const& key) {
     Type::int32 i = indexOfKey(key);
     V oldValue = valueArray[i];
     if (keyArray[i] != Type::Null) { // Entry exist.
         keyArray[i] = Type::Null; // Remove key.
         valueArray[i] = Type::Null;  // And value.
         // Since we have made a hole, adjacent keys might have to shift.
         for (;;) {
             i = (i + 1) & (keyArray.length - 1); // We use a step of 1 (improve caching through memory locality).
             if (keyArray[i] == Type::Null) break; // Done.
             Type::int32 correctIndex = indexOfKey(keyArray[i]);
             if (correctIndex != i) { // Misplaced.
                 keyArray[correctIndex] = keyArray[i];
                 valueArray[correctIndex] = valueArray[i];
                 keyArray[i] = Type::Null;
                 valueArray[i] = Type::Null;
             }
         }
         // Check if we need to resize.
         if (((--count << (EMPTINESS_LEVEL+1)) <= keyArray.length) && (keyArray.length > INITIAL_CAPACITY)) {
             resize(keyArray.length >> 1);
         }
Beispiel #9
0
 /**
  * Associates the specified value with the specified key in this map
  * (optional operation).  If the map previously contained a mapping for
  * the key, the old value is replaced by the specified value.
  *
  * @param key the key to be added.
  * @param value the associated value.
  * @throws NullPointerException if the key is null.
  */
 virtual V put(K const& key, V const& value) {
     Type::int32 i = indexOfKey(key);
     V oldValue = valueArray[i];
     valueArray[i] = value;
     if (keyArray[i] == Type::Null) { // New entry.
         keyArray[i] = key;
         // Check if we need to resize.
         if ((++count << EMPTINESS_LEVEL) > keyArray.length) {
             resize(keyArray.length << 1);
         }
     }
     return oldValue;
 }
Beispiel #10
0
void IndexNode::insert(int key, TreeNode *leftNode, TreeNode *rightNode){
    if (getCount() < getMax()){
        int index = indexOfKey(key);
        shiftAndInsert(key);
        m_children[index] = leftNode;
        m_children[index+1]=rightNode;
    } else {
        int mid;
        IndexNode *s_node = split(key, leftNode, rightNode, mid);
        TreeNode *p = getParent();
        if (p == nullptr){
            p = new IndexNode(getOrder());
            setParent(p);
        }
        s_node->setParent(p);
        p->insert(mid, this, s_node);
    }
}
status_t AudioPolicyMixCollection::registerMix(const String8& address, AudioMix mix,
                                               sp<SwAudioOutputDescriptor> desc)
{
    ssize_t index = indexOfKey(address);
    if (index >= 0) {
        ALOGE("registerPolicyMixes(): mix for address %s already registered", address.string());
        return BAD_VALUE;
    }
    sp<AudioPolicyMix> policyMix = new AudioPolicyMix();
    policyMix->setMix(mix);
    add(address, policyMix);

    if (desc != 0) {
        desc->mPolicyMix = policyMix->getMix();
        policyMix->setOutput(desc);
    }
    return NO_ERROR;
}
Beispiel #12
0
int AMControlSet::indexOf(const QString& controlName) {
	return indexOfKey(controlName);
}
Beispiel #13
0
 /**
  * Returns the value to which the specified key is mapped,
  * or <code>Type::Null</code> if this map contains no mapping for the key.
  *
  * @param key the key for which the value is returned.
  * @throws NullPointerException if the key is null.
  */
 virtual V const& get(K const& key) const {
     return valueArray[indexOfKey(key)];
 }
Beispiel #14
0
TreeNode * IndexNode::search(int key){
    int index = indexOfKey(key);
    return m_children[index]->search(key);
}
Beispiel #15
0
const AMOldDetectorInfo* AMOldDetectorInfoSet::detectorInfoNamed(const QString &detectorName) const{
	int index = indexOfKey(detectorName);
	if(index < 0)
		return 0; // NULL
	return at(index).first;
}
Beispiel #16
0
int AMOldDetectorInfoSet::indexOf(const QString& detectorName) const{
	return indexOfKey(detectorName);
}
Beispiel #17
0
AMDetector* AMDetectorSet::detectorNamed(const QString &detectorName){
	int index = indexOfKey(detectorName);
	if(index < 0)
		return 0;
	return at(index);
}