How to Use DirectShow in Windows Mobile 6.0 SDK

Source: Internet
Author: User

How to Use DirectShow in Windows Mobile 6.0 SDK

(16:00:17)

Http://topic.csdn.net/u/20090303/13/20118bcc-d703-490d-b7e2-1ebe2e4f9446.html

Cause of setformat failure:

The problem has been solved. Thanks to the participation of the barbarian, I am confident to continue.
The solution is summarized as follows:
Why can't I set another resolution. Next I saw a sentence in the document:
In video_stream_config_caps, if the setformat pin is not connected, it tries to use the new format when it is connected. If the PIN is already connected, it will be reconnected in the new media format, however, in either case, the downstream filter may reject the new media format.
Because I connected the pin to the output before setting the resolution, an error occurred while resetting the settings.
Finally, I set the resolution before the pin connection.
In short, thank you, especially the barbarian.

Http://topic.csdn.net/u/20080123/14/2AC749B0-EE67-4A56-96F1-FD5C772BDC3F.html

Probably send the code.
1. Initialization
Hresult hR = s_ OK;
HR = coinitializeex (null, coinit_multithreaded );
If (failed (HR ))
{
Outputdebugstring (L "coinitializeex failed! \ R \ n ");
Couninitialize ();
Return false;
}
// Create icapturegraphbuilder2 Interface
HR = cocreateinstance (clsid_capturegraphbuilder, null, clsctx_inproc, iid_icapturegraphbuilder2, (void **) & pcapturegraphbuild );
If (failed (HR ))
{
Outputdebugstring (L "cocreateinstance capturegraphbuilder failed! \ R \ n ");
Return false;
}
// Create the igraphbuilder Interface
HR = cocreateinstance (clsid_filtergraph, null, clsctx_inproc, iid_igraphbuilder, (void **) & pgraphbuilder );
If (failed (HR ))
{
Outputdebugstring (L "cocreateinstance graphbuilder failed! \ R \ n ");
Return false;
}
HR = pcapturegraphbuild-> setfiltergraph (pgraphbuilder );
If (failed (HR ))
{
Outputdebugstring (L "pcapturegraphbuild setfiltergraph graphbuilder failed! \ R \ n ");
Return false;
}
2. Search for camera
Guid guidcamera = {0xcb998a05, 0x122c, 0x4166, 0x84, 0x6a, 0x93, 0x3e, 0x4d, 0x7e, 0x3c, 0x86 };
// Note about the above: the driver material doesn't ship as part of the SDK. This GUID is hardcoded
// Here to be able to enumerate the camera drivers and pass the name of the driver to the video capture filter
Di. dwsize = sizeof (DI );
Handle = findfirstdevice (devicesearchbyguid, & guidcamera, & di );
If (handle = NULL) | (Di. hdevice = NULL ))
{
Outputdebugstring (L "findcameradevice failed! \ R \ n ");
Return false;
}
Findclose (handle );
Varcamname = Di. szlegacyname;
Propbag. Write (_ T ("vcapname"), & varcamname );
HR = cocreateinstance (clsid_videocapture, null, clsctx_inproc, iid_ibasefilter, (void **) & pbasefilter );
If (failed (HR ))
{
Outputdebugstring (L "cocreateinstance pbasefilter failed! \ R \ n ");
Return false;
}
HR = pbasefilter-> QueryInterface (iid_ipersistpropertybag, (void **) & ppropertybag );
If (failed (HR ))
{
Outputdebugstring (L "pbasefilter QueryInterface ppropertybag failed! \ R \ n ");
Return false;
}
Ppropertybag-> load (& propbag, null );
HR = pgraphbuilder-> addfilter (pbasefilter, _ T ("video capture filter "));
If (failed (HR ))
{
Outputdebugstring (L "pgraphbuilder addfilter pbasefilter failed! \ R \ n ");
Return false;
}
HR = pcapturegraphbuild-> renderstream (& pin_category_preview, & mediatype_video, pbasefilter, null, null );
If (failed (HR ))
{
Outputdebugstring (text ("couldn't render the video capture stream. \ r \ n "));
Pbasefilter-> release ();
Return hr;
}
Pbasefilter-> release ();
3. Connection
Hresult hR = s_ OK;
Imediacontrol * pmediacontrol = NULL;
Ivideowindow * pvideowindow = NULL;
// Query the imediacontrol Interface
HR = pgraphbuilder-> QueryInterface (iid_imediacontrol, (void **) & pmediacontrol );
If (failed (HR ))
{
Outputdebugstring (L "pgraphbuilder QueryInterface pmediacontrol failed! \ R \ n ");
Return false;
}
// Query ivideowindow
HR = pgraphbuilder-> QueryInterface (iid_ivideowindow, (void **) & pvideowindow );
If (failed (HR ))
{
Outputdebugstring (L "pgraphbuilder QueryInterface pvideowindow failed! \ R \ n ");
Pmediacontrol-> release ();
Return false;
}
HR = pgraphbuilder-> QueryInterface (iid_imediaeventex, (void **) & pmediaevent );
If (failed (HR ))
{
Outputdebugstring (L "pgraphbuilder QueryInterface pmediaevent failed! \ R \ n ");
Return false;
}
HR = pmediaevent-> setpolicywindow (oahwnd) g_hwnd, wm_graphnotify, 0); // custom message wm_graphnotify, get this message in step 3 wndproc
HR = pvideowindow-> put_owner (oahwnd (g_hwnd ));
If (failed (HR ))
{
Outputdebugstring (L "pvideowindow put_owner failed! \ R \ n ");
Return false;
}
HR = pvideowindow-> put_windowstyle (ws_child | ws_clipchildren );
If (failed (HR ))
{
Outputdebugstring (L "pvideowindow put_windowstyle failed! \ R \ n ");
Return false;
}
HR = pvideowindow-> put_visible (oatrue );
If (failed (HR ))
{
Outputdebugstring (L "pvideowindow put_visible failed! \ R \ n ");
Return false;
}
HR = pvideowindow-> setwindowposition (0, 0, getsystemmetrics (sm_cxscreen), getsystemmetrics (sm_cyscreen ));
If (failed (HR ))
{
Outputdebugstring (L "pvideowindow setwindowposition failed! \ R \ n ");
Return false;
}
HR = pvideowindow-> put_fullscreenmode (oatrue );
HR = pmediacontrol-> Run (); // start video capture
If (failed (HR ))
{
Outputdebugstring (L "pmediacontrol run failed! \ R \ n ");
Return false;
}
4. Play
Case wm_graphpolicy:
Handlegraphevent ();
Hresult handlegraphevent (void)
{
Long evcode, evparam1, evparam2;
Hresult hR = s_ OK;
// Make sure that we don't access the media event Interface
// After it has already been released.
If (! Pmediaevent)
Return s_ OK;
// Process all queued events
While (succeeded (pmediaevent-> getevent (& evcode, (long_ptr *) & evparam1,
(Long_ptr *) & evparam2, 0 )))
{
// Free memory associated with callback, since we're not using it
HR = pmediaevent-> freeeventparams (evcode, evparam1, evparam2 );
// If this is the end of the clip, reset to beginning
If (ec_complete = evcode)
{
Longlong Pos = 0;
// Reset to first frame of movie
HR = pmediaseeking-> setpositions (& Pos, am_seeking_absolutepositioning, null, am_seeking_nopositioning );
If (failed (HR ))
{
// Some M filters (like the Windows ce midi filter)
// May not implement seeking interfaces (imediaseeking)
// To allow seeking to the start. In that case, just stop
// And restart for the same effect. This shoshould not be
// Necessary in most cases.
If (failed (hR = pmediacontrol-> stop ()))
{
// MSG (text ("failed (0x % 08lx) to stop media clip! \ R \ n "), HR );
Break;
}
If (failed (hR = pmediacontrol-> Run ()))
{
// MSG (text ("failed (0x % 08lx) to reset media clip! \ R \ n "), HR );
Break;
}
}
}
}
Return hr;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.