HRESULT COggSplitter::CreateOutputPins() { CAutoLock lock(&m_csFilter); int i; COggSplitOutputPin *pPin; // Create a pin for the active streams ... for (i=0; i<m_iStreams; i++) if (m_paStream[i]->m_bEnabled) { CMediaType *pmt = &(m_paStream[i]->m_mt); if (*(pmt->Type()) != MEDIATYPE_NULL) { HRESULT hr = NOERROR; wchar_t PinNameL[64]; char PinName[64]; if (*(pmt->Type()) == MEDIATYPE_Video) wsprintf(PinName, "Video %d", m_paStream[i]->m_iStreamID); else if (*(pmt->Type()) == MEDIATYPE_Audio) wsprintf(PinName, "Audio %d", m_paStream[i]->m_iStreamID); else if (*(pmt->Type()) == MEDIATYPE_Text) wsprintf(PinName, "Subtitle %d", m_paStream[i]->m_iStreamID); else wsprintf(PinName, "Stream %d", m_paStream[i]->m_iStreamID); wsprintfW(PinNameL, L"%s", PinName); pPin = new COggSplitOutputPin(PinName, this, &m_csFilter, &hr, PinNameL); if FAILED(hr) return E_OUTOFMEMORY; { // Add the pin the array ... COggSplitOutputPin **paOutput = new COggSplitOutputPin *[m_iOutputs+1]; if (!paOutput) return E_OUTOFMEMORY; // Copy the array if there was one before if (m_paOutput) { CopyMemory((void*)paOutput, (void*)m_paOutput, m_iOutputs * sizeof(m_paOutput[0])); delete [] m_paOutput; } m_paOutput = paOutput; m_paOutput[m_iOutputs] = pPin; m_iOutputs++; m_paStream[i]->m_pPin = pPin; pPin->m_pStream = m_paStream[i]; } }
// // Classify the streams and set the groupID // void COggSplitter::SetGroupID() { int i = 0; while (i<m_iStreams) { CMediaType *pmt = &(m_paStream[i]->m_mt); int iMaxGroupID = -1; m_paStream[i]->m_iGroupID = -1; for (int j=0; j<i; j++) { CMediaType *pmt_cmp = &(m_paStream[j]->m_mt); if (m_paStream[j]->m_iGroupID > iMaxGroupID) iMaxGroupID = m_paStream[j]->m_iGroupID; if (*(pmt->Type()) == *(pmt_cmp->Type()) && *(pmt->Subtype()) == *(pmt_cmp->Subtype())) { m_paStream[i]->m_iGroupID = m_paStream[j]->m_iGroupID; m_paStream[i]->Enable(m_bEnableAll); } } if (m_paStream[i]->m_iGroupID == -1) { // This is the first stream of this type if (*(m_paStream[i]->m_mt.Type()) == MEDIATYPE_Text && !m_bEnableAll) { // We must create dummy stream ... COggStream* pStream; InsertStream(i,&pStream, 65535, true); m_paStream[i]->m_iGroupID = iMaxGroupID + 1; m_paStream[i]->Enable(true); i++; m_paStream[i]->m_iGroupID = iMaxGroupID + 1; m_paStream[i]->Enable(false); } else { m_paStream[i]->m_iGroupID = iMaxGroupID + 1; m_paStream[i]->Enable(TRUE); } } i++; } }
XnVideoStream::Mode XnVideoStream::MediaTypeToMode(const CMediaType& mediaType) { Mode result = {0}; if (*mediaType.Type() != MEDIATYPE_Video) // we only output video { xnLogError(XN_MASK_FILTER, "bad type"); return result; } // Check for the subtypes we support const GUID *SubType = mediaType.Subtype(); if (SubType && *SubType != GUID_NULL) { if (*SubType == MEDIASUBTYPE_RGB24) { result.Format = XN_PIXEL_FORMAT_RGB24; } else if (*SubType == MEDIASUBTYPE_MJPG) { result.Format = XN_PIXEL_FORMAT_MJPEG; } else { xnLogVerbose(XN_MASK_FILTER, "bad subtype"); return result; } } // Get the format area of the media type VIDEOINFO *pvi = (VIDEOINFO*)mediaType.Format(); if (pvi == NULL) { return result; } result.OutputMode.nFPS = (XnUInt32)(10000000ULL / pvi->AvgTimePerFrame); result.OutputMode.nXRes = pvi->bmiHeader.biWidth; result.OutputMode.nYRes = pvi->bmiHeader.biHeight; return result; }
bool mt2spk(CMediaType mt, Speakers &spk) { const GUID type = *mt.Type(); const GUID subtype = *mt.Subtype(); const GUID formattype = *mt.FormatType(); WAVEFORMAT *wf = 0; size_t wf_size = 0; int sample_rate = 0; if ((formattype == FORMAT_WaveFormatEx) && (mt.FormatLength() > sizeof(WAVEFORMAT))) { wf = (WAVEFORMAT *)mt.Format(); wf_size = mt.FormatLength(); sample_rate = wf->nSamplesPerSec; } ///////////////////////////////////////////////////////// // HD LPCM if (type == MEDIATYPE_Audio && subtype == MEDIASUBTYPE_HDMV_LPCM_AUDIO && wf && wf->wFormatTag == 1) { spk = wf2spk(wf, wf_size); switch (spk.format) { case FORMAT_PCM16: spk.format = FORMAT_PCM16_BE; return true; case FORMAT_PCM24: spk.format = FORMAT_PCM24_BE; return true; case FORMAT_PCM32: spk.format = FORMAT_PCM32_BE; return true; default: return false; } } ///////////////////////////////////////////////////////// // Compressed formats if (type == MEDIATYPE_MPEG2_PES || type == MEDIATYPE_MPEG2_PACK || type == MEDIATYPE_DVD_ENCRYPTED_PACK) if (subtype == MEDIASUBTYPE_DOLBY_AC3 || subtype == MEDIASUBTYPE_DTS || subtype == MEDIASUBTYPE_MPEG1AudioPayload || subtype == MEDIASUBTYPE_MPEG2_AUDIO || subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO) { spk = Speakers(FORMAT_PES, 0, sample_rate); return true; } if (subtype == MEDIASUBTYPE_DOLBY_AC3 || subtype == MEDIASUBTYPE_AVI_AC3) { // It may be AC3 or EAC3 spk = Speakers(FORMAT_DOLBY, 0, sample_rate); return true; } if (subtype == MEDIASUBTYPE_DOLBY_DDPLUS) { spk = Speakers(FORMAT_EAC3, 0, sample_rate); return true; } if (subtype == MEDIASUBTYPE_DOLBY_TRUEHD) { spk = Speakers(FORMAT_TRUEHD, 0, sample_rate); return true; } if (subtype == MEDIASUBTYPE_DTS || subtype == MEDIASUBTYPE_DTS_HD || subtype == MEDIASUBTYPE_AVI_DTS) { spk = Speakers(FORMAT_DTS, 0, sample_rate); return true; } if (subtype == MEDIASUBTYPE_MPEG1AudioPayload || subtype == MEDIASUBTYPE_MPEG2_AUDIO) { spk = Speakers(FORMAT_MPA, 0, sample_rate); return true; } if (subtype == MEDIASUBTYPE_DOLBY_AC3_SPDIF) { spk = Speakers(FORMAT_SPDIF, 0, sample_rate); return true; } /* if (subtype == MEDIASUBTYPE_Vorbis && formattype == FORMAT_Vorbis && mt.FormatLength() > sizeof(VORBISFORMAT)) { VORBISFORMAT *format = (VORBISFORMAT *)mt.Format(); spk = Speakers(FORMAT_VORBIS, 0, format->samplesPerSec); spk.set_format_data(mt.Format(), mt.FormatLength()); } */ if (subtype == MEDIASUBTYPE_Vorbis2 && formattype == FORMAT_Vorbis2 && mt.FormatLength() > sizeof(VORBISFORMAT2)) { VORBISFORMAT2 *format = (VORBISFORMAT2 *)mt.Format(); spk = Speakers(FORMAT_VORBIS, 0, format->samplesPerSec); spk.set_format_data(mt.Format(), mt.FormatLength()); return true; } ///////////////////////////////////////////////////////// // LPCM if (subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO) { PCMWAVEFORMAT *pcmwf = wf_cast<PCMWAVEFORMAT>(wf, wf_size); if (!pcmwf) return false; int format, mode; switch (pcmwf->wBitsPerSample) { case 16: format = FORMAT_PCM16_BE; break; case 20: format = FORMAT_LPCM20; break; case 24: format = FORMAT_LPCM24; break; default: return false; } switch (pcmwf->wf.nChannels) { case 1: mode = MODE_MONO; break; case 2: mode = MODE_STEREO; break; default: return false; } spk = Speakers(format, mode, sample_rate); return true; } ///////////////////////////////////////////////////////// // General WAVEFORMAT conversion spk = Speakers(); if (wf) spk = wf2spk(wf, wf_size); return !spk.is_unknown(); }