Пример #1
0
HRESULT CKCamStream::CheckMediaType(const CMediaType *pMediaType)
{
	// The CheckMediaType method determines if the pin accepts a specific media type. 
	// MSDN says to "Only accept the preferred media type (See SetFormat for more information)"
	//	but there applications that call CheckMediaType with a different media type than they call SetFormat (e.g. Flash in Chrome)
	//	=> we just check some crucial parameters of the requested media type match with something we offer
	DbgLog((LOG_TRACE, 1, "CheckMediaType"));

	if (!m_device)
		return E_FAIL;

    DECLARE_PTR(VIDEOINFOHEADER, f_pvi, pMediaType->pbFormat);
	DbgLog((LOG_TRACE, 1, "... CheckMediaType (%dx%dx%d)", f_pvi->bmiHeader.biWidth, f_pvi->bmiHeader.biHeight, f_pvi->bmiHeader.biBitCount));

	CAutoLock f_lock(m_pFilter->pStateLock());	// XXX not needed anymore ?
	bool f_ok = false;

	for (int f_idx = 0; !f_ok && f_idx < m_device->video_resolution_count(); ++f_idx)
	{
		auto f_res = m_device->video_resolution(f_idx);

		f_ok = (f_res.m_width == f_pvi->bmiHeader.biWidth &&
			    f_res.m_height == abs(f_pvi->bmiHeader.biHeight) &&
			    f_res.m_bits_per_pixel == f_pvi->bmiHeader.biBitCount &&
				CompressionFromPixelFormat(f_res.m_pixel_format) == f_pvi->bmiHeader.biCompression);
	}

	DbgLog((LOG_TRACE, 1, "... CheckMediaType (%s)", (f_ok) ? "OK" : "NOK"));
	return (f_ok) ? S_OK : E_INVALIDARG;
}
Пример #2
0
		virtual void OnDisable() override
		{
			if (f != nullptr) {
				std::lock_guard<std::mutex> f_lock(m_file);
				
				fflush(f);
				fclose(f);
				f = nullptr;
			}
		}
Пример #3
0
		virtual void OnEnable() override
		{
			if (f == nullptr) {
				std::lock_guard<std::mutex> f_lock(m_file);
				
				f = fopen("soundmem.log", "w");
				if (f == nullptr) {
					Warning("Failed to open soundmem.log: errno = %d:\n%s\n", errno, strerror(errno));
				} else {
					Msg("Opened soundmem.log\n");
				}
			}
		}
Пример #4
0
 /// Lockt #mtx und #file_mtx und löscht dann den Inhalt von #file
 void reset() {
     lock_guard lock ( mtx );
     file_mtx_lock f_lock ( file_mtx );
     alle_nutzer.clear();
     file.remove();
 }
Пример #5
0
 /// Lockt #mtx und #file_mtx, ruft einlesen() auf und gibt dann *this zurück
 NutzerVerwaltung& aktualisieren() {
     lock_guard lock ( mtx );
     sharable_file_mtx_lock f_lock ( file_mtx );
     einlesen();
     return *this;
 }
Пример #6
0
int LargeTableBase::RefreshNearest(int colid, int value, bool top)
{
    SQLiteValuePair constrain;
    set<string> results;
    SQLiteValuePair returnResults;
    int currentTable;
    int save_currentTable = -1;
    int save_currentIndex = -1;
    bool found = false;
    int left, right;
    int leftindex, rightindex, saveleft, saveright;

    if(colid >= m_colnum)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest invalid colid.");
        return -1;
    }
    
    const SQLiteColumn &col = m_col[colid];
    if(col.GetType() != ENUM_SQLite_COLUMN_INTEGER)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest col must be integer.");
        return -1;
    }
    
    results.clear();

    file_lock f_lock(m_file_lock.c_str());
    scoped_lock<file_lock> e_lock(f_lock);

    if(m_schemaColNum < m_maxrownum)
    {
        if(m_maxrownum - m_schemaColNum < LARGE_TABLE_OVERHEAD)
        {
            int tmpIndex = LARGE_TABLE_OVERHEAD - (m_maxrownum - m_schemaColNum);
            leftindex = tmpIndex % m_unitrownum;
            left = tmpIndex / m_unitrownum;
        }
        else
        {
            left = 0;
            leftindex = 0;
        }
        right = m_schemaCurrentTable;
        rightindex = m_schemaCurrentIndex;
    }
    else
    {
        left = m_schemaCurrentTable;
        leftindex = m_schemaCurrentIndex;

        leftindex += LARGE_TABLE_OVERHEAD;
        left += (leftindex / m_unitrownum);
        leftindex %= m_unitrownum;
        if(left >= m_tablenum)
        {
            left -= m_tablenum;
        }

        right = m_schemaCurrentTable;
        rightindex = m_schemaCurrentIndex;
    }

    saveleft = left;
    saveright = right;
    m_values.clear();
    
    while(!found)
    {
        if(left <= right)
        {
            currentTable = (left + right) / 2;
        }
        else
        {
            int distance = m_tablenum - (left - right);
            currentTable = right - (distance / 2);
            if(currentTable < 0)
            {
                currentTable += m_tablenum;
            }
        }

        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest left %d, right %d, current %d.", left, right, currentTable);
        SQLiteTable table(GetExactDbFullName(currentTable), m_tableName + numToString<int>(currentTable), m_unitrownum);
        SetTable(table);
        if(table.Open() < 0)
        {
            LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest open table failed.");
            return -1;
        }
        constrain.clear();
        constrain.insert(SQLiteValuePair::value_type(col.GetHead(), value));
        if(m_schemaColNum >= m_maxrownum)
        {
            if((top) && (currentTable == saveright))
            {
                constrain.insert(SQLiteValuePair::value_type(LARGE_TABLE_COL_INDEX, rightindex));
            }
            else if((!top) && (currentTable == saveleft))
            {
                constrain.insert(SQLiteValuePair::value_type(LARGE_TABLE_COL_INDEX, leftindex));
            }
        }
        int ret = table.QueryNearest(LARGE_TABLE_COL_INDEX, constrain, results, returnResults, top);
        table.Close();
        if(ret < 0)
        {
            if(top)
            {
                if(left == currentTable)
                {
                    if(m_values.size())
                    {
                        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest value found 1.");
                        found =  true;
                        break;
                    }
                    else
                    {
                        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest reach left and no value found.");
                        break;
                    }
                }
                right = currentTable - 1;
                if(right < 0)
                {
                    right = m_tablenum - 1;
                }
            }
            else
            {
                if(right == currentTable)
                {
                    if(m_values.size())
                    {
                        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest value found 2.");
                        found =  true;
                        break;
                    }
                    else
                    {
                        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest reach right and no value found.");
                        break;
                    }
                }
                left = currentTable + 1;
                if(left >= m_tablenum)
                {
                    left = 0;
                }
            }
        }
        else
        {
            int index =  GetSQLiteValueInt(returnResults[LARGE_TABLE_COL_INDEX]);
            m_values = returnResults;
            save_currentTable = currentTable;
            save_currentIndex = index;
            if(top)
            {
                if(index >= (m_unitrownum - 1))
                {
                    if(right == currentTable)
                    {
                        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest value found 3.");
                        found =  true;
                        break;
                    }
                    left = currentTable + 1;
                    if(left >= m_tablenum)
                    {
                        left = 0;
                    }
                }
                else
                {
                    LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest value found 4.");
                    found = true;
                    break;
                }
            }
            else
            {
                if(index <= 0)
                {
                    if(left == currentTable)
                    {
                        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest value found 5.");
                        found =  true;
                        break;
                    }
                    right = currentTable - 1;
                    if(right < 0)
                    {
                        right = m_tablenum - 1;
                    }
                }
                else
                {
                    LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest value found 6.");
                    found = true;
                    break;
                }
            }
        }
    }

    if(!found)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest find nothing.");
        return -1;
    }
    
    if(top)
    {
        if((saveleft == save_currentTable) && (save_currentIndex < leftindex))
        {
            LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest left side beyond the overhead.");
            return -1;
        }
        if((saveright == save_currentTable) && (save_currentIndex > rightindex))
        {
            LogUtility::Log(LOG_LEVEL_INFO, "LargeTableBase::RefreshNearest align the right index.");
            save_currentIndex = rightindex;
        }
        if(m_schemaColNum < m_maxrownum)
        {
            if(m_maxrownum - m_schemaColNum < LARGE_TABLE_OVERHEAD)
            {
                int tmpIndex = LARGE_TABLE_OVERHEAD - (m_maxrownum - m_schemaColNum);
                m_queryCurrentIndex = tmpIndex % m_unitrownum;
                m_queryCurrentTable = tmpIndex / m_unitrownum;
            }
            else
            {
                m_queryCurrentIndex = 0;
                m_queryCurrentTable = 0;
            }
        }
        else
        {
            m_queryCurrentTable = m_schemaCurrentTable;
            m_queryCurrentIndex = m_schemaCurrentIndex;
            m_queryCurrentIndex += LARGE_TABLE_OVERHEAD;
            m_queryCurrentTable += (m_queryCurrentIndex / m_unitrownum);
            m_queryCurrentIndex %= m_unitrownum;
            if(m_queryCurrentTable >= m_tablenum)
            {
                m_queryCurrentTable -= m_tablenum;
            }
        }
    }
    else
    {
        if((saveleft == save_currentTable) && (save_currentIndex < leftindex))
        {
            LogUtility::Log(LOG_LEVEL_INFO, "LargeTableBase::RefreshNearest align the left index.");
            save_currentIndex = leftindex;
        }
        if((saveright == save_currentTable) && (save_currentIndex > rightindex))
        {
            LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshNearest right side beyond the overhead.");
            return -1;
        }

        m_queryCurrentTable = m_schemaCurrentTable;
        m_queryCurrentIndex = m_schemaCurrentIndex;
    }
    
    return save_currentTable * m_unitrownum + save_currentIndex;
}
Пример #7
0
int LargeTableBase::RefreshPrevious(int nowIndex, int topIndex)
{
    set<string> results;
    int currentTable;
    int currentIndex;
    int min, max;
    bool invalid_flag = false;

    file_lock f_lock(m_file_lock.c_str());
    scoped_lock<file_lock> e_lock(f_lock);

    if(m_schemaColNum < m_maxrownum)
    {
        if(topIndex > nowIndex)
        {
            invalid_flag = true;
        }
    }
    else
    {
        if((topIndex > nowIndex) && (topIndex < m_schemaCurrentTable * m_unitrownum + m_schemaCurrentIndex))
        {
            invalid_flag = true;
        }
        else if((topIndex < m_schemaCurrentTable * m_unitrownum + m_schemaCurrentIndex) && (nowIndex > m_schemaCurrentTable * m_unitrownum + m_schemaCurrentIndex))
        {
            invalid_flag = true;
        }
    }

    if(invalid_flag)
    {
        LogUtility::Log(LOG_LEVEL_INFO, "LargeTableBase::RefreshPrevious invalid topindex(%d, %d, %d, %d).", topIndex, nowIndex, m_schemaCurrentTable, m_schemaCurrentIndex);
        return -1;
    }
    
    currentTable = nowIndex / m_unitrownum;
    currentIndex = nowIndex % m_unitrownum;
    if((currentTable == m_queryCurrentTable) && (currentIndex == m_queryCurrentIndex))
    {
        LogUtility::Log(LOG_LEVEL_INFO, "LargeTableBase::RefreshPrevious query results end(%d, %d, %d, %d).", currentTable, currentIndex, m_queryCurrentTable, m_queryCurrentIndex);
        return -1;
    }

    if(currentIndex > 0)
    {
        currentIndex --;
    }
    else
    {
        currentIndex = m_unitrownum - 1;

        if(currentTable > 0)
        {
            currentTable --;
        }
        else
        {
            currentTable = m_tablenum - 1;
        }
    }

    if(m_schemaColNum < m_maxrownum)
    {
        if((currentTable * m_unitrownum + currentIndex) > (m_schemaCurrentTable * m_unitrownum + m_schemaCurrentIndex))
        {
            LogUtility::Log(LOG_LEVEL_INFO, "LargeTableBase::RefreshPrevious index beyond table end(%d, %d, %d, %d).", currentTable, currentIndex, m_schemaCurrentTable, m_schemaCurrentIndex);
            return -1;
        }
    }

    max = currentIndex;
    if(topIndex >= currentTable * m_unitrownum)
    {
        min = topIndex - currentTable * m_unitrownum;
    }
    else
    {
        min = 0;
    }
    
    if(min >= m_unitrownum)
    {
        min = 0;
    }
    else if(min > max)
    {
        LogUtility::Log(LOG_LEVEL_INFO, "LargeTableBase::RefreshPrevious min exceed max(%d, %d).", min, max);
        return -1;
    }
    
    SQLiteTable table(GetExactDbFullName(currentTable), m_tableName + numToString<int>(currentTable), m_unitrownum);
    SetTable(table);
    if(table.Open() < 0)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshPrevious open table failed.");
        return -1;
    }
    m_values.clear();
    results.clear();
    m_returnResults.clear();
    
    if(table.QueryBetween(LARGE_TABLE_COL_INDEX, min, max, results, m_returnResults, false))
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshPrevious query failed.");
        table.Close();
        return -1;
    }

    table.Close();
    
    if(m_returnResults.size() <= 0)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshPrevious query results invalid.");
        return -1;
    }
    
    return currentTable * m_unitrownum + min;
}
Пример #8
0
int LargeTableBase::RefreshPrevious(int nowIndex)
{
    SQLiteValuePair constrain;
    set<string> results;
    set<SQLiteValuePair> returnResults;
    int currentTable;
    int currentIndex;

    file_lock f_lock(m_file_lock.c_str());
    scoped_lock<file_lock> e_lock(f_lock);

    currentTable = nowIndex / m_unitrownum;
    currentIndex = nowIndex % m_unitrownum;
    if((currentTable == m_queryCurrentTable) && (currentIndex == m_queryCurrentIndex))
    {
        LogUtility::Log(LOG_LEVEL_INFO, "LargeTableBase::RefreshPrevious query results end(%d, %d, %d, %d).", currentTable, currentIndex, m_queryCurrentTable, m_queryCurrentIndex);
        return -1;
    }

    if(currentIndex > 0)
    {
        currentIndex --;
    }
    else
    {
        currentIndex = m_unitrownum - 1;

        if(currentTable > 0)
        {
            currentTable --;
        }
        else
        {
            currentTable = m_tablenum - 1;
        }
    }

    if(m_schemaColNum < m_maxrownum)
    {
        if((currentTable * m_unitrownum + currentIndex) > (m_schemaCurrentTable * m_unitrownum + m_schemaCurrentIndex))
        {
            LogUtility::Log(LOG_LEVEL_INFO, "LargeTableBase::RefreshPrevious index beyond table end(%d, %d, %d, %d).", currentTable, currentIndex, m_schemaCurrentTable, m_schemaCurrentIndex);
            return -1;
        }
    }

    SQLiteTable table(GetExactDbFullName(currentTable), m_tableName + numToString<int>(currentTable), m_unitrownum);
    SetTable(table);
    if(table.Open() < 0)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshPrevious open table failed.");
        return -1;
    }
    m_values.clear();
    results.clear();
    constrain[LARGE_TABLE_COL_INDEX] = SQLiteValue(currentIndex);

    if(table.Query(constrain, results, returnResults) < 0)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshPrevious query failed.");
        table.Close();
        return -1;
    }

    table.Close();
    
    if(returnResults.size() != 1)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshPrevious query results invalid.");
        return -1;
    }
    
    m_values = *(returnResults.begin());
    
    return currentTable * m_unitrownum + currentIndex;
}
Пример #9
0
int LargeTableBase::RefreshBottom(int count)
{
    SQLiteValuePair constrain;
    set<string> results;
    int currentTable;
    int currentIndex;
    int min, max;

    file_lock f_lock(m_file_lock.c_str());
    scoped_lock<file_lock> e_lock(f_lock);
    
    if(count > m_schemaColNum)
    {
        count = m_schemaColNum;
    }
    currentTable = m_schemaCurrentTable;
    currentIndex = m_schemaCurrentIndex;
    m_returnResults.clear();

    while((int)m_returnResults.size() < count)
    {
        int countleft = count - m_returnResults.size();
        SQLiteTable table(GetExactDbFullName(currentTable), m_tableName + numToString<int>(currentTable), m_unitrownum);
        SetTable(table);
        if(table.Open() < 0)
        {
            LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshBottom open table failed.");
            return -1;
        }
        
        max = currentIndex;
        min = 0;
        
        if(currentIndex > countleft)
        {
            min = currentIndex - countleft + 1;
        }
        results.clear();

        if(table.QueryBetween(LARGE_TABLE_COL_INDEX, min, max, results, m_returnResults, false))
        {
            LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshBottom query failed.");
            table.Close();
            return -1;
        }

        table.Close();
        if(m_schemaColNum < m_maxrownum)
        {
            if(currentTable <= 0)
            {
                LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshBottom reach top.");
                break;
            }
            currentIndex = m_unitrownum - 1;
            currentTable --;
        }
        else
        {
            currentIndex = m_unitrownum - 1;
            currentTable --;
            if(currentTable < 0)
            {
                currentTable = m_tablenum - 1;
            }
        }
    }
    
    return 0;
}
Пример #10
0
int LargeTableBase::RefreshBottom()
{
    SQLiteValuePair constrain;
    set<string> results;
    set<SQLiteValuePair> returnResults;
    int currentTable;
    int currentIndex;

    file_lock f_lock(m_file_lock.c_str());
    scoped_lock<file_lock> e_lock(f_lock);
    
    currentTable = m_schemaCurrentTable;
    currentIndex = m_schemaCurrentIndex;

    SQLiteTable table(GetExactDbFullName(currentTable), m_tableName + numToString<int>(currentTable), m_unitrownum);
    SetTable(table);
    if(table.Open() < 0)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshBottom open table failed.");
        return -1;
    }
    m_values.clear();
    results.clear();
    constrain[LARGE_TABLE_COL_INDEX] = SQLiteValue(currentIndex);

    if(table.Query(constrain, results, returnResults))
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshBottom query failed.");
        table.Close();
        return -1;
    }

    table.Close();
    
    if(returnResults.size() != 1)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::RefreshBottom query results invalid.");
        return -1;
    }
    
    m_values = *(returnResults.begin());

    if(m_schemaColNum < m_maxrownum)
    {
        if(m_maxrownum - m_schemaColNum < LARGE_TABLE_OVERHEAD)
        {
            int tmpIndex = LARGE_TABLE_OVERHEAD - (m_maxrownum - m_schemaColNum);
            m_queryCurrentIndex = tmpIndex % m_unitrownum;
            m_queryCurrentTable = tmpIndex / m_unitrownum;
        }
        else
        {
            m_queryCurrentIndex = 0;
            m_queryCurrentTable = 0;
        }
    }
    else
    {
        m_queryCurrentTable = m_schemaCurrentTable;
        m_queryCurrentIndex = m_schemaCurrentIndex;
        m_queryCurrentIndex += LARGE_TABLE_OVERHEAD;
        m_queryCurrentTable += (m_queryCurrentIndex / m_unitrownum);
        m_queryCurrentIndex %= m_unitrownum;
        if(m_queryCurrentTable >= m_tablenum)
        {
            m_queryCurrentTable -= m_tablenum;
        }
    }
    
    return currentTable * m_unitrownum + currentIndex;
}
Пример #11
0
int LargeTableBase::Add()
{
    SQLiteValuePair constrain;
    SQLiteValuePair pairs;
    set<string> results;
    set<SQLiteValuePair> returnResults;
    bool needAdd = false;
    int currentTable;
    int currentIndex;

    file_lock f_lock(m_file_lock.c_str());
    scoped_lock<file_lock> e_lock(f_lock);
    
    if(m_schemaColNum <= 0)
    {
        currentTable = 0;
        currentIndex = 0;
    }
    else
    {
        currentTable = m_schemaCurrentTable;
        currentIndex = m_schemaCurrentIndex;
        currentIndex ++;
        if(currentIndex >= m_unitrownum)
        {
            currentIndex = 0;
            currentTable ++;
        }
        if(currentTable >= m_tablenum)
        {
            currentTable = 0;
        }
    }
    
    SQLiteTable table(GetExactDbFullName(currentTable), m_tableName + numToString<int>(currentTable), m_unitrownum);
    SetTable(table);
    if(m_schemaColNum < m_maxrownum)
    {
        needAdd = true;
    }
    
    if(table.Open() < 0)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::Add open table failed.");
        return -1;
    }
    
    constrain.clear();
    results.clear();
    returnResults.clear();
    pairs.clear();
    
    for(int i = 0; i < m_colnum; i ++)
    {
        if(m_dirty[i] == false)
        {
            continue;
        }
        
        const SQLiteColumn col = m_col[i];
        pairs[col.GetHead()] = m_values[col.GetHead()];
    }
    
    if(needAdd)
    {
        pairs[LARGE_TABLE_COL_INDEX] = SQLiteValue(currentIndex); 
        if(table.Add(pairs) < 0)
        {
            LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::Add failed to add.");
            needAdd = false;
        }
    }
    
    if(!needAdd)
    {
        constrain[LARGE_TABLE_COL_INDEX] = SQLiteValue(currentIndex); 
        if(table.Modify(constrain, pairs) < 0)
        {
            LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::Add failed to modify.");
            table.Close();
            return -1;
        }
    }
    
    for(int i = 0; i < m_colnum; i ++)
    {
        m_dirty[i] = false;
    }
    
    table.Close();
    
    m_schemaCurrentTable = currentTable;
    m_schemaCurrentIndex = currentIndex;
    if(m_schemaColNum < m_maxrownum)
    {
        m_schemaColNum ++;
    }

    if(UpdateSchema() < 0)
    {
        LogUtility::Log(LOG_LEVEL_ERROR, "LargeTableBase::Add failed to update schema.");
        return -1;
    }
    
    return 0;
}