[Windows Mobile] Changing still image resolution or DirectShow.NETCF part IV
Posted on June 17th, 2009 by admin
Most of us who was trying to use DirectShowNETCF found that resolution of stilled image smaller that it could be, for example my device (Samsung i710) got default resolution on still pin 320×240, but i know that it supports resolutions up to 2Mpx. So that should be fixed
What do we need to change resolution?
1. We need Enum supported:
- Find STILL pin
- using IEnumMediatypes enumerate supported mediatypes
2. Using IAMStreamConfig set required mediatype to required pin (STILL pin in our case)
here is interfaces:
[ComVisible(true), ComImport,
Guid("89C31040-846B-11CE-97D3-00AA0055595A"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IEnumMediaTypes
{
[PreserveSig]
int Next(
[In] int cMediaTypes,
[Out] out IntPtr ppMediaTypes,
[Out] out int pcFetched
);
[PreserveSig]
int Skip([In] int cMediaTypes);
[PreserveSig]
int Reset();
[PreserveSig]
int Clone([Out] out IEnumMediaTypes ppEnum);
}
[ComVisible(true), ComImport,
Guid("C6E13340-30AC-11D0-A18C-00A0C9118956"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IAMStreamConfig
{
[PreserveSig]
int SetFormat([In, MarshalAs(UnmanagedType.LPStruct)] AMMediaType pmt);
[PreserveSig]
int GetFormat([Out] out IntPtr pmt);
[PreserveSig]
int GetNumberOfCapabilities(
[Out] out int piCount,
[Out] out int piSize);
[PreserveSig]
int GetStreamCaps(
[In] int iIndex,
[Out] out IntPtr ppmt,
[In] IntPtr pSCC
);
}
Also was created useful class CEnumMediatypes (as in DSPack)
public class CEnumMediaTypes
{
private List<AMMediaType> FList;
private IEnumMediaTypes EnumMediaTypes;
private IntPtr Mt;
public void Free()
{
Clear();
}
public CEnumMediaTypes()
{
FList = new List<AMMediaType>();
}
private void Clear()
{
for (int i = 0; i < FList.Count; i++)
{
DirectShowEx.FreeMediaType(FList[i]);
FList[0] = null;
FList.RemoveAt(0);
}
FList.Clear();
}
public int Count
{
get
{
return FList.Count;
}
}
public void Assign(ICaptureGraphBuilder2 capGraph, IBaseFilter filter, Guid category)
{
Clear();
IPin pin_ = null;
CGuid guid = new CGuid(category);
CGuid guid2 = new CGuid(CLSID_.MEDIATYPE_Video);
int res = capGraph.FindPin(filter, PinDirection.Output, guid, guid2, true, 0, out pin_);
if (res > -1)
{
pin_.EnumMediaTypes(out EnumMediaTypes);
if (EnumMediaTypes == null)
{
return;
}
int fetched = 0;
int hr = EnumMediaTypes.Next(1, out Mt, out fetched);
while (hr == 0)
{
fetched = 0;
hr = EnumMediaTypes.Next(1, out Mt, out fetced);
AMMediaType mt = (AMMediaType)Marshal.PtrToStructure(Mt, typeof(AMMediaType));
FList.Add(mt);
}
Marshal.ReleaseComObject(EnumMediaTypes);
Marshal.ReleaseComObject(pin_);
}
}
private string getFourCC(int value)
{
IntPtr ptr = Marshal.AllocHGlobal(4);
Marshal.WriteInt32(ptr, value);
byte[] bt = new byte[4];
Marshal.Copy(ptr, bt, 0, 4);
Marshal.FreeHGlobal(ptr);
char[] ch = new char[4];
for (int i = 0; i < 4; i++)
{
ch[i] = (char)bt[i];
}
bt = null;
return new string(ch);
}
public string GetMediaDescription(int index)
{
string result = "";
AMMediaType tempType = FList[index];
if (tempType.formatType == CLSID_.VideoInfo)
{
result += ((VideoInfoHeader)Marshal.PtrToStructure(tempType.formatPtr, typeof(VideoInfoHeader))).BmiHeader.Width.ToString();
result += 'X';
result += ((VideoInfoHeader)Marshal.PtrToStructure(tempType.formatPtr, typeof(VideoInfoHeader))).BmiHeader.Height.ToString();
}
else
{
if (tempType.formatType == CLSID_.VideoInfo2)
{
result += ((VideoInfoHeader2)Marshal.PtrToStructure(tempType.formatPtr, typeof(VideoInfoHeader2))).BmiHeader.Width.ToString();
result += 'X';
result += ((VideoInfoHeader2)Marshal.PtrToStructure(tempType.formatPtr, typeof(VideoInfoHeader2))).BmiHeader.Height.ToString();
}
}
tempType = null;
return result;
}
public AMMediaType this[int index]
{
get
{
return FList[index];
}
}
}
Exaple how to set/change resolution is here
Filed under: Programming
March 6th, 2010 at 9:59 am
this is directshow driver problem and its impossible to resolve it using directshow
March 6th, 2010 at 8:01 am
Hi Alex, did you manage to find a solution for HTC devices? mine only gives 320 X 240 resolution, even though it has a 3.2MP camera
December 12th, 2009 at 10:10 pm
2robo, you are not right. in Camera class i do enumerating of still pin and it returns resolutions up to max supported on most devices, but HTC does not.
in AMCamera and AMCameraEx use video pin to grab frames.
P.S. lib you can find here:
http://alexmogurenko.com/blog/directshownetcf/