좋아, 그래서 너무 비슷하기 전에 문제가 발생했습니다,하지만 WPF와, 그래서 소금 한 스푼 다음과 같은 (매우 해키) 제안을.
는
다음 방법은 기본적으로 DirectShow를 명령을 실행하기 위해 완전히 별도의 응용 프로그램 스레드를 생성하지만 형태가 WPF 응용 프로그램에서 호스팅 제어하는 윈도우의 핸들을 사용하는 직접 쇼를 알려줍니다.
그래서 먼저 우리는 더미 윈폼은 우리가 전화를 호출하는 데 사용할 수있는 양식이 필요하지만, 그것은 결코 렌더링 얻을 것 없다 :
/// <summary>
/// Just a dummy invisible form.
/// </summary>
private class DummyForm : Form
{
protected override void SetVisibleCore(bool value)
{
//just override here, make sure that the form will never become visible
if (!IsHandleCreated)
{
CreateHandle();
}
value = false;
base.SetVisibleCore(value);
}
}
다음 단계는 우리가 넣을 수 있습니다 스레드를 만드는 것입니다 메시지 루프에 : 더미 형태 (및 스레드)가 생성 된 후
//this will need to be a class level variable, since all the directshow
//calls will get invoked on this form
DummyForm dumbForm;
Thread separateThread;
private void CreateDummyForm()
{
ManualResetEvent reset = new ManualResetEvent(false);
//create our thread
separateThread = new Thread((ThreadStart)
delegate
{
//we need a dummy form to invoke on
dumbForm = new DummyForm();
//signal the calling method that it can continue
reset.Set();
//now kick off the message loop
Application.Run(dumbForm);
});
//set the apartment state of this new thread to MTA
separateThread.SetApartmentState(ApartmentState.MTA);
separateThread.IsBackground = true;
separateThread.Start();
//we need to wait for the windowing thread to have initialised before we can
//say that initialisation is finished
reset.WaitOne();
//wait for the form handle to be created, since this won't happen until the form
//loads inside Application.Run
while (!dumbForm.IsHandleCreated)
{
Thread.Sleep(0);
}
}
그래서, 당신이 그렇게 같은 MTA 응용 프로그램 스레드에서 호출을 호출 할 수 있습니다
당신은 모든 DirectShow에서 물건 완료 그런
, 그래서 같은 종료 별도의 응용 프로그램 스레드 :이 방법의
//to end the separate thread and application loop,
//just close your invisible form
dumbForm.Close();
장점은 깔끔하게 별도의 스레드로 DirectShow를 샌드 박스이다. 단점은 Invoke 호출의 컨텍스트 전환과 다른 응용 프로그램 스레드가있는 오버 헤드입니다. 이 아키텍처를 현재 아키텍처에 약간 재미있게 사용할 수도 있지만 도움이 될 것입니다.
당신이 어떻게 시작하는지 알려주세요. 나는 이것이 얼마나 잘 작동하는지에 흥미를 느끼고 있습니다.
코드를 게시하거나 코드 설명을 게시 하시겠습니까? 나는 첫 번째와 함께 갈 것입니다. –
왜 DirectShow를 사용하고 있습니까? WPF는 미디어를 재생할 수 있습니다. –
@Emo - 아마도 파일이나 일반적인 비디오 스트림이 아닌 비디오 소스를 가지고있을 것입니까? 그는 어떤 종류의 커스텀 소스 필터를 가지고 있을지도 모른다. – Kazar