예제 #1
0
//
// CFilePlayer::GetColorKeyInternal(): Private method to query the color key
// value from teh first input pin of the OverlayMixer.
//
HRESULT CFilePlayer::GetColorKeyInternal(IBaseFilter *pOvM)
{
    DbgLog((LOG_TRACE, 5, TEXT("CFilePlayer::GetColorKeyInternal() entered"))) ;

    if (NULL == pOvM)
        return E_INVALIDARG ;

    IEnumPins  *pEnumPins ;
    IPin       *pPin ;
    ULONG       ul ;
    PIN_DIRECTION  pd ;
    DWORD       dwColorKey ;
    IMixerPinConfig  *pMPC ;
    HRESULT  hr = pOvM->EnumPins(&pEnumPins) ;
    ASSERT(pEnumPins) ;
    while (S_OK == pEnumPins->Next(1, &pPin, &ul)  &&  1 == ul)  // try all pins
    {
        pPin->QueryDirection(&pd) ;
        if (PINDIR_INPUT == pd)  // only the 1st in pin
        {
            hr = pPin->QueryInterface(IID_IMixerPinConfig, (LPVOID *) &pMPC) ;
            ASSERT(SUCCEEDED(hr) && pMPC) ;
            hr = pMPC->GetColorKey(NULL, &dwColorKey) ;  // just get the physical color
            SetColorKey(dwColorKey) ;

            //  Set mode to stretch - that way we don't fight the overlay
            //  mixer about the exact way to fix the aspect ratio
            pMPC->SetAspectRatioMode(AM_ARMODE_STRETCHED);
            ASSERT(SUCCEEDED(hr)) ;
            pMPC->Release() ;
            pPin->Release() ; // exiting early; release pin
            break ;   // we are done
        }
        pPin->Release() ;
    }
    pEnumPins->Release() ;  // done with pin enum

    return S_OK ;
}
예제 #2
0
/*
 * Class:     sage_DShowMediaPlayer
 * Method:    getColorKey0
 * Signature: (J)Ljava/awt/Color;
 */
JNIEXPORT jobject JNICALL Java_sage_DShowMediaPlayer_getColorKey0
  (JNIEnv *env, jobject jo, jlong dataPtr)
{
	if (!dataPtr) return 0;
	CPlayerData* playData = (CPlayerData*) dataPtr;
	IGraphBuilder* pGraph = playData->GetGraph();
	if (!pGraph) return 0;
	BOOL forceColorKey = FALSE;
	HRESULT hr;
	DWORD holder;
	HKEY myKey;
	DWORD readType;
	DWORD hsize = sizeof(holder);
	DWORD keyedColor = RGB(1,1,1);
	if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Frey Technologies\\Common\\DirectShow", 0, 0,
		REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &myKey, 0) == ERROR_SUCCESS)
	{
		if (RegQueryValueEx(myKey, "TransparentColorKey", 0, &readType, (LPBYTE) &holder, &hsize) == ERROR_SUCCESS)
		{
			keyedColor = holder;
			forceColorKey = TRUE;
		}
		RegCloseKey(myKey);
	}
	COLORKEY overlayKey;
	overlayKey.KeyType = CK_RGB;
	overlayKey.PaletteIndex = 0;
	overlayKey.LowColorValue = keyedColor;
	overlayKey.HighColorValue = keyedColor;

	COLORKEY defaultKey;

	BOOL overlayIsUsed = FALSE;
	IEnumFilters *pEnum = NULL;
	if (!forceColorKey)
	{
		// Find the default color key
		hr = pGraph->EnumFilters(&pEnum);
		if (SUCCEEDED(hr))
		{
			IBaseFilter *currFilt = NULL;
			while (pEnum->Next(1, &currFilt, NULL) == S_OK)
			{
				IPin *overlayPin = NULL;
				IEnumPins* pPinEnum = NULL;
				hr = currFilt->EnumPins(&pPinEnum);
				if (hr == NO_ERROR)
				{
					IPin *pPin = NULL;
					hr = E_FAIL;
					while(S_OK == pPinEnum->Next(1, &pPin, NULL))
					{
						IOverlay *pOverlayPin = NULL;
						hr = pPin->QueryInterface(IID_IOverlay, (void**)&pOverlayPin);
						if (SUCCEEDED(hr))
						{
							hr = pOverlayPin->GetDefaultColorKey(&defaultKey);
							if (!forceColorKey && SUCCEEDED(hr))
							{
								keyedColor = defaultKey.LowColorValue;
								slog((env, "Got the default color key 0x%x\r\n", keyedColor));
								//forceColorKey = TRUE;
							}
							SAFE_RELEASE(pOverlayPin);
						}
						SAFE_RELEASE(pPin);
					}
					SAFE_RELEASE(pPinEnum);
				}
				SAFE_RELEASE(currFilt);
			}
			SAFE_RELEASE(pEnum);
		}
	}
	pEnum = NULL;

	// Set the color key value
	hr = pGraph->EnumFilters(&pEnum);
	if (SUCCEEDED(hr))
	{
		IBaseFilter *currFilt = NULL;
		while (pEnum->Next(1, &currFilt, NULL) == S_OK)
		{
			IPin *overlayPin = NULL;
			IEnumPins* pPinEnum = NULL;
			currFilt->EnumPins(&pPinEnum);
			while (pPinEnum->Next(1, &overlayPin, NULL) == S_OK)
			{
				// let's see if it's overlay
				IMixerPinConfig *pOverlayMix = NULL;
				hr = overlayPin->QueryInterface(IID_IMixerPinConfig, (void**)&pOverlayMix);
				if (SUCCEEDED(hr))
				{
					if (!forceColorKey)
						keyedColor = overlayKey.LowColorValue;
					else
						overlayKey.LowColorValue = overlayKey.HighColorValue = keyedColor;
					IPin* testPin = NULL;
					overlayPin->ConnectedTo(&testPin);
					BOOL currPinUsed = FALSE;
					if (testPin)
					{
						currPinUsed = TRUE;
						SAFE_RELEASE(testPin);
					}
					if (currPinUsed)
					{
						if (forceColorKey)
						{
							slog((env, "Setting the color key to 0x%x\r\n", keyedColor));
							hr = pOverlayMix->SetColorKey(&overlayKey);
						}
						else
						{
							hr = pOverlayMix->GetColorKey(&defaultKey, &keyedColor);
							slog((env, "Got the default overlay color key of 0x%x\r\n", keyedColor));
						}
//						HTESTPRINT(hr);
						if (!overlayIsUsed)
						{
							// Force the color key on all connected mixer pins to match
							overlayIsUsed = TRUE;
							forceColorKey = TRUE;
						}
					}
					SAFE_RELEASE(pOverlayMix);
				}
				SAFE_RELEASE(overlayPin);
			}
			SAFE_RELEASE(pPinEnum);
			SAFE_RELEASE(currFilt);
		}
		SAFE_RELEASE(pEnum);
	}
	static jclass colorClass = (jclass) env->NewGlobalRef(env->FindClass("java/awt/Color"));
	static jmethodID constMeth = env->GetMethodID(colorClass, "<init>", "(I)V");
	// Set the alpha to be 255 for the color.
	keyedColor = keyedColor | 0xFF000000;
	slog((env, "Returning the color key as 0x%x\r\n", keyedColor));
	return env->NewObject(colorClass, constMeth, keyedColor);
}