CStreamSwitcherFilter::CStreamSwitcherFilter(LPUNKNOWN lpunk, HRESULT* phr, const CLSID& clsid) : CBaseFilter(NAME("CStreamSwitcherFilter"), lpunk, &m_csState, clsid) { if(phr) *phr = S_OK; HRESULT hr = S_OK; do { CAutoPtr<CStreamSwitcherInputPin> pInput; CAutoPtr<CStreamSwitcherOutputPin> pOutput; hr = S_OK; pInput.Attach(new CStreamSwitcherInputPin(this, &hr, L"Channel 1")); if(!pInput || FAILED(hr)) break; hr = S_OK; pOutput.Attach(new CStreamSwitcherOutputPin(this, &hr)); if(!pOutput || FAILED(hr)) break; CAutoLock cAutoLock(&m_csPins); m_pInputs.AddHead(m_pInput = pInput.Detach()); m_pOutput = pOutput.Detach(); return; } while(false); if(phr) *phr = E_FAIL; }
void CBaseSplitterFilter::SortOutputPin() { // Sorting output pin - video at the beginning of the list. CAutoPtrList<CBaseSplitterOutputPin> m_pOutputsVideo; CAutoPtrList<CBaseSplitterOutputPin> m_pOutputsOther; POSITION pos = m_pOutputs.GetHeadPosition(); while (pos) { CAutoPtr<CBaseSplitterOutputPin> pin; pin.Attach(m_pOutputs.GetNext(pos).Detach()); CMediaType mt; if (SUCCEEDED(pin->GetMediaType(0, &mt))) { if (mt.majortype == MEDIATYPE_Video) { m_pOutputsVideo.AddTail(pin); } else { m_pOutputsOther.AddTail(pin); } } } m_pOutputs.RemoveAll(); pos = m_pOutputsVideo.GetHeadPosition(); while (pos) { CAutoPtr<CBaseSplitterOutputPin> pin; pin.Attach(m_pOutputsVideo.GetNext(pos).Detach()); m_pOutputs.AddTail(pin); } pos = m_pOutputsOther.GetHeadPosition(); while (pos) { CAutoPtr<CBaseSplitterOutputPin> pin; pin.Attach(m_pOutputsOther.GetNext(pos).Detach()); m_pOutputs.AddTail(pin); } }
bool CDVDSession::SendKey(DVD_KEY_TYPE KeyType, BYTE* pKeyData) { CAutoPtr<DVD_COPY_PROTECT_KEY> key; switch (KeyType) { case DvdChallengeKey: key.Attach((DVD_COPY_PROTECT_KEY*)DEBUG_NEW BYTE[DVD_CHALLENGE_KEY_LENGTH]); key->KeyLength = DVD_CHALLENGE_KEY_LENGTH; Reverse(key->KeyData, pKeyData, 10); break; case DvdBusKey2: key.Attach((DVD_COPY_PROTECT_KEY*)DEBUG_NEW BYTE[DVD_BUS_KEY_LENGTH]); key->KeyLength = DVD_BUS_KEY_LENGTH; Reverse(key->KeyData, pKeyData, 5); break; default: break; } if (!key) { return false; } key->SessionId = m_session; key->KeyType = KeyType; key->KeyFlags = 0; DWORD BytesReturned; return !!DeviceIoControl(m_hDrive, IOCTL_DVD_SEND_KEY, key, key->KeyLength, NULL, 0, &BytesReturned, NULL); }
HRESULT CDVBSub::ParsePage(CGolombBuffer& gb, WORD wSegLength, CAutoPtr<DVB_PAGE>& pPage) { HRESULT hr = S_OK; WORD wEnd = (WORD)gb.GetPos() + wSegLength; int nPos = 0; pPage.Attach (DNew DVB_PAGE()); pPage->PageTimeOut = gb.ReadByte(); pPage->PageVersionNumber = (BYTE)gb.BitRead(4); pPage->PageState = (BYTE)gb.BitRead(2); pPage->RegionCount = 0; gb.BitRead(2); // Reserved while (gb.GetPos() < wEnd) { if (nPos < MAX_REGIONS) { pPage->Regions[nPos].Id = gb.ReadByte(); gb.ReadByte(); // Reserved pPage->Regions[nPos].HorizAddr = gb.ReadShort(); pPage->Regions[nPos].VertAddr = gb.ReadShort(); pPage->RegionCount++; } nPos++; } return S_OK; }
TAG_METHOD_IMPL(CWSDLBindingParser, OnOperation) { TRACE_PARSE_ENTRY(); CWSDLBinding * pCurr = GetBinding(); if (pCurr != NULL) { CAutoPtr<CWSDLPortTypeOperation> spElem; spElem.Attach( new CWSDLPortTypeOperation ); if (spElem != NULL) { SetXMLElementInfo(spElem, pCurr, GetLocator()); CAutoPtr<CWSDLOperationParser> p( new CWSDLOperationParser(GetReader(), this, GetLevel(), spElem) ); if (p) { if (g_ParserList.AddHead(p) != NULL) { if (SUCCEEDED(p.Detach()->GetAttributes(pAttributes))) { if (pCurr->AddOperation(spElem) != NULL) { spElem.Detach(); return S_OK; } } } } } } EmitErrorHr(E_OUTOFMEMORY); return E_FAIL; }
int CEASpliterFilter::eav_get_packet( int size) { AVPacket *pkt = (AVPacket *)m_pkt; //int ret= av_new_packet(pkt, size); //if(ret<0) // return ret; pkt->pos= m_pFile->GetPos();//url_ftell(s); //ret= m_pFile->ByteRead( pkt->data, size); //get_buffer(s, pkt->data, size); //if(ret<=0) // av_free_packet(pkt); //else{ pkt->size= size; CAutoPtr<Packet> p; p.Attach(new Packet()); p->TrackNumber = pkt->stream_index; p->rtStart = pkt->pts; p->rtStop = p->rtStart + pkt->duration; p->bSyncPoint = pkt->flags; p->SetCount(size); m_pFile->ByteRead(p->GetData(), p->GetCount()); HRESULT hr = DeliverPacket(p); //} return (hr == S_OK); }
void COPCItem::getProperties(const CAtlArray<CPropertyDescription> &propsToRead, ATL::CAutoPtrArray<SPropertyValue> &propsRead){ unsigned noProperties = (DWORD)propsToRead.GetCount(); VARIANT *pValues = NULL; HRESULT *pErrors = NULL; DWORD *pPropertyIDs = new DWORD[noProperties]; for (unsigned i = 0; i < noProperties; i++){ pPropertyIDs[i] = propsToRead.GetAt(i).id; } propsRead.RemoveAll(); propsRead.SetCount(noProperties); USES_CONVERSION; HRESULT res = group.getServer().getPropertiesInterface()->GetItemProperties(T2OLE(name), noProperties, pPropertyIDs, &pValues, &pErrors); delete []pPropertyIDs; if (FAILED(res)){ throw OPCException("Failed to restrieve property values", res); } for (unsigned i = 0; i < noProperties; i++){ CAutoPtr<SPropertyValue> v; if (!FAILED(pErrors[i])){ v.Attach(new SPropertyValue(propsToRead[i], pValues[i])); } propsRead[i]=v; } COPCClient::comFree(pErrors); COPCClient::comFreeVariant(pValues, noProperties); }
CSimpleType * CElement::AddSimpleType(CSimpleType * p) { CAutoPtr<CSimpleType> spOut; if (p== NULL) { spOut.Attach( new CSimpleType ); p = spOut; } if (p != NULL) { if (m_elements.AddTail(p) != NULL) { spOut.Detach(); return p; } } return NULL; }
TAG_METHOD_IMPL(CSchemaParser, OnElement) { TRACE_PARSE_ENTRY(); CSchema * pCurr = GetSchema(); if (pCurr != NULL) { CAutoPtr<CElement> spElem; spElem.Attach( new CElement ); if (spElem != NULL) { SetXSDElementInfo(spElem, pCurr, GetLocator()); spElem->SetParentSchema(pCurr); CAutoPtr<CElementParser> p( new CElementParser(GetReader(), this, GetLevel(), spElem) ); if (p != NULL) { if (g_ParserList.AddHead(p) != NULL) { if (SUCCEEDED(p.Detach()->GetAttributes(pAttributes))) { if (spElem->GetName().GetLength() != 0) { if (pCurr->AddElement(spElem) != NULL) { spElem.Detach(); return S_OK; } } EmitNamedElementError("element"); } } } } } EmitErrorHr(E_OUTOFMEMORY); return E_FAIL; }
int sproxy() { unsigned __int64 nFlags; BOOL bHasInvalid; CStringW wszUrl; CStringW wszOut; CStringA szNamespace; wchar_t **argvW = NULL ; int argc = 0 ; argvW = CommandLineToArgvW(GetCommandLineW(),&argc); if(argvW == NULL) { EmitError(IDS_SDL_CMDLINE_FAILURE, GetLastError()); return 1; } PreProcessCommandLine(argc, argvW, wszOut, szNamespace, &nFlags, &bHasInvalid); g_bUseWchar_t = ((nFlags & SPROXYFLAG_NOWCHAR_T) == 0); if ((nFlags & SPROXYFLAG_NOLOGO) == 0) { PrintHeader(); } if (nFlags & SPROXYFLAG_USAGE) { PrintUsage(true); GlobalFree(argvW); return 0; } ParseCommandLine(argc, argvW, wszUrl, bHasInvalid); GlobalFree(argvW); bHasInvalid = FALSE; if (wszUrl.IsEmpty()) { EmitCmdLineError(IDS_SDL_MISSING_OPTION, nFlags & SPROXYFLAG_WSDLINPUT ?"<wsdl_location>":"<discomap_location>"); bHasInvalid = TRUE; } if (bHasInvalid != FALSE) { printf("\r\n"); PrintUsage(); return 1; } if (nFlags & SPROXYFLAG_NOWARN) { SetEmitWarnings(false); } CHeapPtr<char> spSzNamespace; if (szNamespace && *szNamespace) { if (FAILED(CreateSafeCppName(&spSzNamespace, szNamespace))) { EmitErrorHr(E_OUTOFMEMORY); return 1; } } CoInitialize(NULL); HRESULT hr = S_OK; { CAutoPtr<CDiscoMapParser> dmParser; if(!(nFlags & SPROXYFLAG_WSDLINPUT)) { CComPtr<ISAXXMLReader> spDMReader; hr = CoCreateInstance(__uuidof(SAXXMLReader30), NULL, CLSCTX_ALL, __uuidof(ISAXXMLReader), (void **)&spDMReader); if (FAILED(hr)) { ATLTRACE( _T("CoCreateInstance failed!\n") ); return 1; } dmParser.Attach(new CDiscoMapParser(spDMReader, NULL, 0)); if(dmParser == NULL) { ATLTRACE(_T("Failed to create Discomap Parser : out of memory!\n")); return 1; } dmParser->SetDynamicAlloc(FALSE); hr = spDMReader->putContentHandler( dmParser ); if (FAILED(hr)) { ATLTRACE( _T("putContentHandler failed!\n") ); return 1; } CErrorHandler errDM; errDM.SetLocation(wszUrl); hr = spDMReader->putErrorHandler( &errDM); if (FAILED(hr)) { ATLTRACE( _T("putErrorHandler failed!\n") ); return 1; } g_pDMDoc = dmParser->GetDiscoMapDocument(); if (g_pDMDoc == NULL) { ATLTRACE( _T("failed to create document: out of memory!\n") ); return 1; } hr = g_pDMDoc->SetDocumentUri( wszUrl, wszUrl.GetLength()); if (FAILED(hr)) { ATLTRACE( _T("failed to set document uri: out of memory!\n") ); return 1; } g_wszFile = wszUrl; hr = spDMReader->parseURL( wszUrl ); if (FAILED(hr)) { ATLTRACE( _T("parseURL failed!\n") ); if ((hr == E_SAX_LOADFAILED) || (hr == E_SAX_FILENOTFOUND) || (hr == E_SAX_PATHNOTFOUND) || (hr == E_SAX_ACCESSDENIED)) { EmitError(IDS_SDL_FAILED_DM_OPEN, wszUrl); } EmitError(IDS_SDL_PROCESS_DM_FAILURE, wszUrl); return 1; } } if(nFlags & SPROXYFLAG_WSDLINPUT) g_wszFile = wszUrl; else g_wszFile = g_pDMDoc->GetWSDLFile(); CComPtr<ISAXXMLReader> spReader; hr = CoCreateInstance(__uuidof(SAXXMLReader30), NULL, CLSCTX_ALL, __uuidof(ISAXXMLReader), (void **)&spReader); if (FAILED(hr)) { ATLTRACE( _T("CoCreateInstance failed!\n") ); return 1; } CWSDLParser parser(spReader, NULL, 0); parser.SetDynamicAlloc(FALSE); hr = spReader->putContentHandler( &parser ); if (FAILED(hr)) { ATLTRACE( _T("putContentHandler failed!\n") ); return 1; } CErrorHandler err; err.SetLocation(g_wszFile); hr = spReader->putErrorHandler( &err ); if (FAILED(hr)) { ATLTRACE( _T("putErrorHandler failed!\n") ); return 1; } CWSDLDocument * pDoc = parser.GetWSDLDocument(); if (pDoc == NULL) { ATLTRACE( _T("failed to create document: out of memory!\n") ); return 1; } hr = pDoc->SetDocumentUri( g_wszFile, g_wszFile.GetLength()); if (FAILED(hr)) { ATLTRACE( _T("failed to set document uri: out of memory!\n") ); return 1; } wchar_t wszTmp[ATL_URL_MAX_URL_LENGTH]; if(g_wszFile.Find(L"://") != -1 && ((g_wszFile.Left(5)).MakeLower() != L"file:") ) { // The URL needs to be escaped only if it's not a local file if(AtlEscapeUrl(g_wszFile,wszTmp,0,ATL_URL_MAX_URL_LENGTH-1,ATL_URL_BROWSER_MODE) == FALSE) { ATLTRACE( _T("failed to escape uri!\n") ); return 1; } hr = spReader->parseURL( wszTmp ); } else { hr = spReader->parseURL( g_wszFile ); } if (FAILED(hr)) { ATLTRACE( _T("parseURL failed!\n") ); if ((hr == E_SAX_LOADFAILED) || (hr == E_SAX_FILENOTFOUND) || (hr == E_SAX_PATHNOTFOUND) || (hr == E_SAX_ACCESSDENIED)) { EmitError(IDS_SDL_FAILED_WSDL_OPEN, g_wszFile); } EmitError(IDS_SDL_PROCESS_FAILURE, g_wszFile); return 1; } CCodeTypeBuilder builder; CCodeProxy proxy; hr = builder.Initialize(parser.GetWSDLDocument(), &proxy); if (FAILED(hr)) { ATLTRACE( _T("builder.Initialize failed!\n") ); return PrintGenerateFailure(wszOut); } hr = builder.Build(); if (FAILED(hr)) { ATLTRACE( _T("builder.Build failed!\n") ); return PrintGenerateFailure(wszOut); } if (wszOut.IsEmpty()) { wszOut.Preallocate(proxy.GetServiceName().GetLength()+4); wszOut = (LPCSTR)proxy.GetServiceName(); wszOut.Append(L".h", 2); } Emit(IDS_SDL_SUCCESS, wszOut); CComObjectStack<CCppCodeGenerator> gen; hr = gen.Generate(wszOut, &proxy, (nFlags & SPROXYFLAG_NOPRAGMA) ? false : true, (nFlags & SPROXYFLAG_NOCLOBBER) ? true : false, (nFlags & SPROXYFLAG_NONAMESPACE) ? false : true, (nFlags & SPROXYFLAG_NOPROXY) ? false : true, spSzNamespace ? spSzNamespace : (szNamespace.IsEmpty() ? 0 : LPCSTR(szNamespace))); if (FAILED(hr)) { ATLTRACE( _T("gen.Generate failed!\n") ); return PrintGenerateFailure(wszOut); } } CoUninitialize(); return 0; }
__declspec(dllexport) BOOL runApplication(LPCTSTR cmdline, const RunOptions * options) { try { if (options->size != sizeof(RunOptions) || ((options->user != NULL) ^ (options->password != NULL)) || ((options->stdIn != NULL) ^ (options->stdOut != NULL))) { throw WinApiException(_T(""),ERROR_INVALID_PARAMETER); } init(); setRestrictions(job,options); Process process(cmdline); process.setDesktop(getDesktop(options->useDefaultDesktop != FALSE)); if (options->user != NULL && options->password != NULL) process.setCredentials(options->user,options->password); if (options->stdIn != NULL && options->stdOut != NULL) process.redirect(options->stdIn,options->stdOut); process.load(); job->assignMainProcess(process); process.resume(); CAutoPtr<ConsoleWindow> wnd; if (options->showStatusWindow) { ConsoleWindow * pWnd = new ConsoleWindow(CRect(-28,0,-1,5)); wnd.Attach(pWnd); wnd->show(); } while (job->active()) { job->waitForEvent(30); if (options->showStatusWindow) { _stringstream msg; msg << dec << fixed << showpoint << setprecision(1); msg << _T("Time elapsed: ") << setw(6) << job->infoElapsedTime() << _T("\n"); msg << _T("Time used: ") << setw(6) << job->infoCPUTime() << _T("\n"); msg << _T("Memory used: ") << setw(6) << job->infoMemoryUsage()/1024 << _T("Kb\n"); wnd->setMessage(msg.str()); wnd->redraw(); } if (options->callback != NULL ) { RunStatus status; status.elapsedTime = job->infoElapsedTime(); status.cpuTime = job->infoCPUTime(); status.memoryUsed = job->infoMemoryUsage(); status.peakMemoryUsed = job->infoMemoryUsagePeak(); if (!options->callback(&status)) { job->terminate(); } } } if (options->showStatusWindow) wnd->hide(); JobResult jobresult = job->result(); if (jobresult.result() == JobResult::OK) { DWORD code = process.exitCode(); if (code != 0) { jobresult = JobResult(JobResult::RE, RuntimeErrorMessages::getFullMessage(code)); } } job->gatherInfo(); result.resultcode = jobresult.result(); result.exitcode = process.exitCode(); resultMessage = jobresult.info(); result.message = resultMessage.c_str(); result.elapsedTime = job->infoElapsedTime(); result.cpuTime = job->infoCPUTime(); result.memoryUsed = job->infoMemoryUsagePeak(); result.exception = false; } catch (WinApiException e) { result.exception = true; result.exitcode = e.errorCode(); resultMessage = e.message(); result.message = resultMessage.c_str(); } return !result.exception; }
RenderedSubtitle* Renderer::Lookup(const Subtitle* s, const CSize& vs, const CRect& vr) { m_sra.UpdateTarget(vs, vr); if(s->m_text.IsEmpty()) { return NULL; } CRect spdrc = s->m_frame.reference == _T("video") ? vr : CRect(CPoint(0, 0), vs); if(spdrc.IsRectEmpty()) { return NULL; } RenderedSubtitle* rs = NULL; if(m_rsc.Lookup(s->m_name, rs)) { if(!s->m_animated && rs->m_spdrc == spdrc) { return rs; } m_rsc.Invalidate(s->m_name); } const Style& style = s->m_text.GetHead().style; Size scale; scale.cx = (float)spdrc.Width() / s->m_frame.resolution.cx; scale.cy = (float)spdrc.Height() / s->m_frame.resolution.cy; CRect frame; frame.left = (int)(64.0f * (spdrc.left + style.placement.margin.l * scale.cx) + 0.5); frame.top = (int)(64.0f * (spdrc.top + style.placement.margin.t * scale.cy) + 0.5); frame.right = (int)(64.0f * (spdrc.right - style.placement.margin.r * scale.cx) + 0.5); frame.bottom = (int)(64.0f * (spdrc.bottom - style.placement.margin.b * scale.cy) + 0.5); CRect clip; if(style.placement.clip.l == -1) { clip.left = 0; } else { clip.left = (int)(spdrc.left + style.placement.clip.l * scale.cx); } if(style.placement.clip.t == -1) { clip.top = 0; } else { clip.top = (int)(spdrc.top + style.placement.clip.t * scale.cy); } if(style.placement.clip.r == -1) { clip.right = vs.cx; } else { clip.right = (int)(spdrc.left + style.placement.clip.r * scale.cx); } if(style.placement.clip.b == -1) { clip.bottom = vs.cy; } else { clip.bottom = (int)(spdrc.top + style.placement.clip.b * scale.cy); } clip.left = max(clip.left, 0); clip.top = max(clip.top, 0); clip.right = min(clip.right, vs.cx); clip.bottom = min(clip.bottom, vs.cy); scale.cx *= 64; scale.cy *= 64; bool vertical = s->m_direction.primary == _T("down") || s->m_direction.primary == _T("up"); // create glyph paths WCHAR c_prev = 0, c_next; CAutoPtrList<Glyph> glyphs; POSITION pos = s->m_text.GetHeadPosition(); while(pos) { const Text& t = s->m_text.GetNext(pos); LOGFONT lf; memset(&lf, 0, sizeof(lf)); lf.lfCharSet = DEFAULT_CHARSET; _tcscpy_s(lf.lfFaceName, CString(t.style.font.face)); lf.lfHeight = (LONG)(t.style.font.size * scale.cy + 0.5); lf.lfWeight = (LONG)(t.style.font.weight + 0.5); lf.lfItalic = !!t.style.font.italic; lf.lfUnderline = !!t.style.font.underline; lf.lfStrikeOut = !!t.style.font.strikethrough; lf.lfOutPrecision = OUT_TT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = ANTIALIASED_QUALITY; lf.lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE; FontWrapper* font = m_fc.Create(m_hDC, lf); if(!font) { _tcscpy_s(lf.lfFaceName, _T("Arial")); font = m_fc.Create(m_hDC, lf); if(!font) { ASSERT(0); continue; } } HFONT hOldFont = SelectFont(m_hDC, *font); const TEXTMETRIC& tm = font->GetTextMetric(); for(LPCWSTR c = t.str; *c; c++) { CAutoPtr<Glyph> g(DNew Glyph()); g->c = *c; g->style = t.style; g->scale = scale; g->vertical = vertical; g->font = font; c_next = !c[1] && pos ? c_next = s->m_text.GetAt(pos).str[0] : c[1]; Arabic::Replace(g->c, c_prev, c_next); c_prev = c[0]; CSize extent; GetTextExtentPoint32W(m_hDC, &g->c, 1, &extent); ASSERT(extent.cx >= 0 && extent.cy >= 0); if(vertical) { g->spacing = (int)(t.style.font.spacing * scale.cy + 0.5); g->ascent = extent.cx / 2; g->descent = extent.cx - g->ascent; g->width = extent.cy; // TESTME if(g->c == Text::SP) { g->width /= 2; } } else { g->spacing = (int)(t.style.font.spacing * scale.cx + 0.5); g->ascent = tm.tmAscent; g->descent = tm.tmDescent; g->width = extent.cx; } if(g->c == Text::LSEP) { g->spacing = 0; g->width = 0; g->ascent /= 2; g->descent /= 2; } else { GlyphPath* path = m_gpc.Create(m_hDC, font, g->c); if(!path) { ASSERT(0); continue; } g->path = *path; } glyphs.AddTail(g); } SelectFont(m_hDC, hOldFont); } // break glyphs into rows CAutoPtrList<Row> rows; CAutoPtr<Row> row; pos = glyphs.GetHeadPosition(); while(pos) { CAutoPtr<Glyph> g = glyphs.GetNext(pos); if(!row) { row.Attach(DNew Row()); } WCHAR c = g->c; row->AddTail(g); if(c == Text::LSEP || !pos) { rows.AddTail(row); } } // kerning if(s->m_direction.primary == _T("right")) { // || s->m_direction.primary == _T("left") for(POSITION rpos = rows.GetHeadPosition(); rpos; rows.GetNext(rpos)) { Row* r = rows.GetAt(rpos); POSITION gpos = r->GetHeadPosition(); while(gpos) { Glyph* g1 = r->GetNext(gpos); if(!gpos) { break; } Glyph* g2 = r->GetAt(gpos); if(g1->font != g2->font || !g1->style.font.kerning || !g2->style.font.kerning) { continue; } if(int size = g1->font->GetKernAmount(g1->c, g2->c)) { g2->path.MovePoints(CPoint(size, 0)); g2->width += size; } } } } // wrap rows if(s->m_wrap == _T("normal") || s->m_wrap == _T("even")) { int maxwidth = abs((int)(vertical ? frame.Height() : frame.Width())); int minwidth = 0; for(POSITION rpos = rows.GetHeadPosition(); rpos; rows.GetNext(rpos)) { Row* r = rows.GetAt(rpos); POSITION brpos = NULL; if(s->m_wrap == _T("even")) { int fullwidth = 0; for(POSITION gpos = r->GetHeadPosition(); gpos; r->GetNext(gpos)) { const Glyph* g = r->GetAt(gpos); fullwidth += g->width + g->spacing; } fullwidth = abs(fullwidth); if(fullwidth > maxwidth) { maxwidth = fullwidth / ((fullwidth / maxwidth) + 1); minwidth = maxwidth; } } int width = 0; for(POSITION gpos = r->GetHeadPosition(); gpos; r->GetNext(gpos)) { const Glyph* g = r->GetAt(gpos); width += g->width + g->spacing; if(brpos && abs(width) > maxwidth && g->c != Text::SP) { row.Attach(DNew Row()); POSITION next = brpos; r->GetNext(next); do { row->AddHead(r->GetPrev(brpos)); } while(brpos); rows.InsertBefore(rpos, row); while(!r->IsEmpty() && r->GetHeadPosition() != next) { r->RemoveHeadNoReturn(); } g = r->GetAt(gpos = next); width = g->width + g->spacing; } if(abs(width) >= minwidth) { if(g->style.linebreak == _T("char") || g->style.linebreak == _T("word") && g->c == Text::SP) { brpos = gpos; } } } } } // trim rows for(POSITION pos = rows.GetHeadPosition(); pos; rows.GetNext(pos)) { Row* r = rows.GetAt(pos); while(!r->IsEmpty() && r->GetHead()->c == Text::SP) { r->RemoveHead(); } while(!r->IsEmpty() && r->GetTail()->c == Text::SP) { r->RemoveTail(); } } // calc fill width for each glyph CAtlList<Glyph*> glypsh2fill; int fill_id = 0; int fill_width = 0; for(POSITION pos = rows.GetHeadPosition(); pos; rows.GetNext(pos)) { Row* r = rows.GetAt(pos); POSITION gpos = r->GetHeadPosition(); while(gpos) { Glyph* g = r->GetNext(gpos); if(!glypsh2fill.IsEmpty() && fill_id && (g->style.fill.id != fill_id || !pos && !gpos)) { int w = (int)(g->style.fill.width * fill_width + 0.5); while(!glypsh2fill.IsEmpty()) { Glyph* g = glypsh2fill.RemoveTail(); fill_width -= g->width; g->fill = w - fill_width; } ASSERT(glypsh2fill.IsEmpty()); ASSERT(fill_width == 0); glypsh2fill.RemoveAll(); fill_width = 0; } fill_id = g->style.fill.id; if(g->style.fill.id) { glypsh2fill.AddTail(g); fill_width += g->width; } } } // calc row sizes and total subtitle size CSize size(0, 0); if(s->m_direction.secondary == _T("left") || s->m_direction.secondary == _T("up")) { ReverseList(rows); } for(POSITION pos = rows.GetHeadPosition(); pos; rows.GetNext(pos)) { Row* r = rows.GetAt(pos); if(s->m_direction.primary == _T("left") || s->m_direction.primary == _T("up")) { ReverseList(*r); } int w = 0, h = 0; r->width = 0; for(POSITION gpos = r->GetHeadPosition(); gpos; r->GetNext(gpos)) { const Glyph* g = r->GetAt(gpos); w += g->width; if(gpos) { w += g->spacing; } h = max(h, g->ascent + g->descent); r->width += g->width; if(gpos) { r->width += g->spacing; } r->ascent = max(r->ascent, g->ascent); r->descent = max(r->descent, g->descent); r->border = max(r->border, g->GetBackgroundSize()); } for(POSITION gpos = r->GetHeadPosition(); gpos; r->GetNext(gpos)) { Glyph* g = r->GetAt(gpos); g->row_ascent = r->ascent; g->row_descent = r->descent; } if(vertical) { size.cx += h; size.cy = max(size.cy, w); } else { size.cx = max(size.cx, w); size.cy += h; } } // align rows and calc glyph positions rs = DNew RenderedSubtitle(spdrc, clip); CPoint p = GetAlignPoint(style.placement, scale, frame, size); CPoint org = GetAlignPoint(style.placement, scale, frame); // collision detection if(!s->m_animated) { int tlb = !rows.IsEmpty() ? rows.GetHead()->border : 0; int brb = !rows.IsEmpty() ? rows.GetTail()->border : 0; CRect r(p, size); m_sra.GetRect(r, s, style.placement.align, tlb, brb); org += r.TopLeft() - p; p = r.TopLeft(); } CRect subrect(p, size); // continue positioning for(POSITION pos = rows.GetHeadPosition(); pos; rows.GetNext(pos)) { Row* r = rows.GetAt(pos); CSize rsize; rsize.cx = rsize.cy = r->width; if(vertical) { p.y = GetAlignPoint(style.placement, scale, frame, rsize).y; for(POSITION gpos = r->GetHeadPosition(); gpos; r->GetNext(gpos)) { CAutoPtr<Glyph> g = r->GetAt(gpos); g->tl.x = p.x + (int)(g->style.placement.offset.x * scale.cx + 0.5) + r->ascent - g->ascent; g->tl.y = p.y + (int)(g->style.placement.offset.y * scale.cy + 0.5); p.y += g->width + g->spacing; rs->m_glyphs.AddTail(g); } p.x += r->ascent + r->descent; } else { p.x = GetAlignPoint(style.placement, scale, frame, rsize).x; for(POSITION gpos = r->GetHeadPosition(); gpos; r->GetNext(gpos)) { CAutoPtr<Glyph> g = r->GetAt(gpos); g->tl.x = p.x + (int)(g->style.placement.offset.x * scale.cx + 0.5); g->tl.y = p.y + (int)(g->style.placement.offset.y * scale.cy + 0.5) + r->ascent - g->ascent; p.x += g->width + g->spacing; rs->m_glyphs.AddTail(g); } p.y += r->ascent + r->descent; } } // bkg, precalc style.placement.path, transform pos = rs->m_glyphs.GetHeadPosition(); while(pos) { Glyph* g = rs->m_glyphs.GetNext(pos); g->CreateBkg(); g->CreateSplineCoeffs(spdrc); g->Transform(org, subrect); } // merge glyphs (TODO: merge 'fill' too) Glyph* g0 = NULL; pos = rs->m_glyphs.GetHeadPosition(); while(pos) { POSITION cur = pos; Glyph* g = rs->m_glyphs.GetNext(pos); CRect r = g->bbox + g->tl; int size = (int)(g->GetBackgroundSize() + 0.5); int depth = (int)(g->GetShadowDepth() + 0.5); r.InflateRect(size, size); r.InflateRect(depth, depth); r.left >>= 6; r.top >>= 6; r.right = (r.right + 32) >> 6; r.bottom = (r.bottom + 32) >> 6; if((r & clip).IsRectEmpty()) { // clip rs->m_glyphs.RemoveAt(cur); } else if(g0 && g0->style.IsSimilar(g->style)) { // append CPoint o = g->tl - g0->tl; g->path.MovePoints(o); g0->path.types.Append(g->path.types); g0->path.points.Append(g->path.points); g->path_bkg.MovePoints(o); g0->path_bkg.types.Append(g->path_bkg.types); g0->path_bkg.points.Append(g->path_bkg.points); g0->bbox |= g->bbox + o; rs->m_glyphs.RemoveAt(cur); } else { // leave alone g0 = g; } } // rasterize pos = rs->m_glyphs.GetHeadPosition(); while(pos) { rs->m_glyphs.GetNext(pos)->Rasterize(); } // cache m_rsc.Add(s->m_name, rs); m_fc.Flush(); return rs; }
bool CDVDSession::ReadKey(DVD_KEY_TYPE KeyType, BYTE* pKeyData, int lba) { CAutoPtr<DVD_COPY_PROTECT_KEY> key; switch (KeyType) { case DvdChallengeKey: key.Attach((DVD_COPY_PROTECT_KEY*)DEBUG_NEW BYTE[DVD_CHALLENGE_KEY_LENGTH]); key->KeyLength = DVD_CHALLENGE_KEY_LENGTH; key->Parameters.TitleOffset.QuadPart = 0; break; case DvdBusKey1: key.Attach((DVD_COPY_PROTECT_KEY*)DEBUG_NEW BYTE[DVD_BUS_KEY_LENGTH]); key->KeyLength = DVD_BUS_KEY_LENGTH; key->Parameters.TitleOffset.QuadPart = 0; break; case DvdDiskKey: key.Attach((DVD_COPY_PROTECT_KEY*)DEBUG_NEW BYTE[DVD_DISK_KEY_LENGTH]); key->KeyLength = DVD_DISK_KEY_LENGTH; key->Parameters.TitleOffset.QuadPart = 0; break; case DvdTitleKey: key.Attach((DVD_COPY_PROTECT_KEY*)DEBUG_NEW BYTE[DVD_TITLE_KEY_LENGTH]); key->KeyLength = DVD_TITLE_KEY_LENGTH; key->Parameters.TitleOffset.QuadPart = 2048i64 * lba; break; default: break; } if (!key) { return false; } key->SessionId = m_session; key->KeyType = KeyType; key->KeyFlags = 0; DWORD BytesReturned; if (!DeviceIoControl(m_hDrive, IOCTL_DVD_READ_KEY, key, key->KeyLength, key, key->KeyLength, &BytesReturned, NULL)) { DWORD err = GetLastError(); UNREFERENCED_PARAMETER(err); return false; } switch (KeyType) { case DvdChallengeKey: Reverse(pKeyData, key->KeyData, 10); break; case DvdBusKey1: Reverse(pKeyData, key->KeyData, 5); break; case DvdDiskKey: memcpy(pKeyData, key->KeyData, 2048); for (int i = 0; i < 2048 / 5; i++) { pKeyData[i] ^= m_SessionKey[4 - (i % 5)]; } break; case DvdTitleKey: memcpy(pKeyData, key->KeyData, 5); for (int i = 0; i < 5; i++) { pKeyData[i] ^= m_SessionKey[4 - (i % 5)]; } break; default: break; } return true; }
DWORD CBaseSplitterOutputPin::ThreadProc() { SetThreadName(DWORD(-1), "CBaseSplitterOutputPin"); m_hrDeliver = S_OK; m_fFlushing = m_fFlushed = false; m_eEndFlush.Set(); // fix for Microsoft DTV-DVD Video Decoder - video freeze after STOP/PLAY bool iHaaliRenderConnect = false; CComPtr<IPin> pPinTo = this, pTmp; while (pPinTo && SUCCEEDED(pPinTo->ConnectedTo(&pTmp)) && (pPinTo = pTmp)) { pTmp = nullptr; CComPtr<IBaseFilter> pBF = GetFilterFromPin(pPinTo); if (GetCLSID(pBF) == CLSID_DXR) { // Haali Renderer iHaaliRenderConnect = true; break; } pPinTo = GetFirstPin(pBF, PINDIR_OUTPUT); } if (IsConnected() && !iHaaliRenderConnect) { GetConnected()->BeginFlush(); GetConnected()->EndFlush(); } for (;;) { Sleep(1); DWORD cmd; if (CheckRequest(&cmd)) { m_hThread = nullptr; cmd = GetRequest(); Reply(S_OK); ASSERT(cmd == CMD_EXIT); return 0; } int cnt = 0; do { CAutoPtr<Packet> p; { CAutoLock cAutoLock(&m_queue); if ((cnt = m_queue.GetCount()) > 0) { p.Attach(m_queue.Remove().Detach()); } } if (S_OK == m_hrDeliver && cnt > 0) { ASSERT(!m_fFlushing); m_fFlushed = false; // flushing can still start here, to release a blocked deliver call HRESULT hr = p ? DeliverPacket(p) : DeliverEndOfStream(); m_eEndFlush.Wait(); // .. so we have to wait until it is done if (hr != S_OK && !m_fFlushed) { // and only report the error in m_hrDeliver if we didn't flush the stream // CAutoLock cAutoLock(&m_csQueueLock); m_hrDeliver = hr; break; } } } while (--cnt > 0); } }