KsProperty () returns"The data area passed to a system call is too small" ERROR_INSUFFICIENT_BUFFER while setting camera Zoom value - directshow

HRESULT hr = S_OK;
KSPROPERTY ksprop;
ZeroMemory(&ksprop, sizeof(ksprop));
PVOID pData = NULL;
ULONG valueSize = 0;
ULONG dataLength = 0;
KSPROPERTY_CAMERACONTROL_S cameraControl;
ZeroMemory(&cameraControl, sizeof(cameraControl));
ksprop.Set = PROPSETID_VIDCAP_CAMERACONTROL;
ksprop.Id = KSPROPERTY_CAMERACONTROL_ZOOM;
ksprop.Flags = KSPROPERTY_TYPE_SET;
cameraControl.Property = ksprop;
cameraControl.Flags = KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
cameraControl.Capabilities = KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
cameraControl.Value = 50;
pData = &cameraControl;
dataLength = sizeof(cameraControl);
hr = m_pKsControl->KsProperty(
&ksprop, sizeof(ksprop),
pData, dataLength, &valueSize);
here hr "The data area passed to a system call is too small. "
I am compiling on vs 2010 on windows 7 machine.

You are likely to provide a buffer which is too small in fourth parameter.
It's easy to check this out, see IKsControl::KsProperty docs:
To determine the buffer size that is required for a specific property
request, you can call this method with PropertyData set to NULL and
DataLength equal to zero. The method returns
HRESULT_FROM_WIN32(ERROR_MORE_DATA), and BytesReturned contains the
size of the required buffer.

In this KsProperty use case, you should pass KSPROPERTY_CAMERACONTROL_S structure variable to make this work.
For example
KSPROPERTY_CAMERACONTROL_S kspIn = { 0 };
KSPROPERTY_CAMERACONTROL_S kspOut = { 0 };
ULONG valueSize = 0;
kspIn.Property.Set = PROPSETID_VIDCAP_CAMERACONTROL;
kspIn.Property.Id = KSPROPERTY_CAMERACONTROL_ZOOM;
kspIn.Property.Flags = KSPROPERTY_TYPE_SET;
kspOut.Property.Set = PROPSETID_VIDCAP_CAMERACONTROL;
kspOut.Property.Id = KSPROPERTY_CAMERACONTROL_ZOOM;
kspOut.Property.Flags = KSPROPERTY_TYPE_SET;
kspOut.Flags = KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
kspOut.Capabilities = KSPROPERTY_CAMERACONTROL_FLAGS_MANUAL;
kspOut.Value = 50;
hr = m_pKsControl->KsProperty(
(PKSPROPERTY)&kspIn, sizeof(kspIn),
&kspOut, sizeof(kspOut), &valueSize);
Should work

Related

Retrieving Signature from Point-Array

I'm trying to retrieve the Points of a SignaturePad to redisplay the signature.
public static void GetPoints(string airid, SignaturePadView padView)
{
List<Strokes> DBStrokes = SqLiteHelper.conn.Query<Strokes>("select * from Strokes where airid = ? order by PointSequence", airid);
List<Point> points = new List<Point>();
foreach (Strokes stroke in DBStrokes)
points.Add(new Point { X = stroke.pointx, Y = stroke.pointy });
padView.Points = points.AsEnumerable();
}
The array points is filled correctly, but the padView.Points shows as result
{Xamarin.Forms.Point[0]}.
I've found the Problem. It seems that it is only possible to set the Points property when the Signaturepad is visible. so my new code looks like this:
List<Strokes> DBStrokes = SqLiteHelper.conn.Query<Strokes>("select * from Strokes where airid = ? order by PointSequence", formField.pictFile);
Xamarin.Forms.Point[] points = new Point[DBStrokes.Count];
for (int i = 0; i < DBStrokes.Count; i++)
points[i] = new Point(DBStrokes[i].pointx, DBStrokes[i].pointy);
var originalPoints = JsonConvert.SerializeObject(points);
Xamarin.Forms.Point[] points4View = JsonConvert.DeserializeObject<Xamarin.Forms.Point[]>(originalPoints);
signatureView.Points = points4View;
Now i'm using the Handle_MeasureInvalidated - Event to run this code.

ios 8.1 calling AudioConvertFillComplexBuffer make a infinite loop with cpuload 100%

I'm converting audio by using the AudioToolBox.AudioConverter library.
AudioStreamBasicDescription inDescription;
inDescription.mSampleRate = 44100;
inDescription.mFormatID = kAudioFormatMPEGLayer3;
inDescription.mFormatFlags = 0;
inDescription.mBytesPerPacket = 0;
inDescription.mFramesPerPacket = 1152;
inDescription.mBytesPerFrame = 0;
inDescription.mChannelsPerFrame = 2;
inDescription.mBitsPerChannel = 0;
inDescription.mReserved = 0;
AudioStreamBasicDescription outDescription;
audioDescription.mFormatID = kAudioFormatLinearPCM
audioDescription.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian;
audioDescription.mChannelsPerFrame = 2;
audioDescription.mBytesPerPacket = sizeof(SInt16)*audioDescription.mChannelsPerFrame;
audioDescription.mFramesPerPacket = 1;
audioDescription.mBytesPerFrame = sizeof(SInt16)*audioDescription.mChannelsPerFrame;
audioDescription.mBitsPerChannel = 8 * sizeof(SInt16);
audioDescription.mSampleRate = 44100.0;
This is the conversion part with mp3AudioData...
AudioBufferList *mp3Audio = (AudioBufferList *)malloc(sizeof(AudioBufferList) + sizeof(AudioBuffer));
mp3Audio->mNumberBuffers = 1;
mp3Audio->mBuffers[0].mNumberChannels = 2;
mp3Audio->mBuffers[0].mDataByteSize = chunkLen;
mp3Audio->mBuffers[0].mData = calloc(chunkLen, sizeof(uint8_t));
memcpy(mp3Audio->mBuffers[0].mData, chunkData, chunkLen);
AudioStreamPacketDescription *packetDescription =
(AudioStreamPacketDescription*)malloc(sizeof(AudioStreamPacketDescription) * frames);
packetDescription->mDataByteSize = chunkLen;
packetDescription->mStartOffset = 0;
packetDescription->mVariableFramesInPacket = 1;
OSStatus result = AudioConverterFillComplexBuffer(audioConverter,
fillComplexBufferInputProc,
&(struct fillComplexBufferInputProc_t) { .bufferList =mp3Audio, .frames = frames, .packetDescriptions = packetDescription },
&frames,
pcmAudio,
NULL);
free(mp3Audio->mBuffers[0].mData);
free(mp3Audio);
free(packetDescription);
The first running of AudioConverterFillComplexBuffer is OK but when I run that function a second time, the infinite loop happens with cpuload 100%.
This code is OK on an IOS 7 device, but when I run it on an IOS 8 device, the infinite loop happens.
Could anyone tell me why this happens on IOS 8?
fillComplexBufferInputProc function:
static OSStatus fillComplexBufferInputProc(AudioConverterRef inAudioConverter,
UInt32 *ioNumberDataPackets,
AudioBufferList *ioData,
AudioStreamPacketDescription **outDataPacketDescription,
void *inUserData) {
struct fillComplexBufferInputProc_t *arg = inUserData;
for (int i = 0; i < ioData->mNumberBuffers; i++) {
ioData->mBuffers[i].mData = arg->bufferList->mBuffers[i].mData;
ioData->mBuffers[i].mDataByteSize = arg->bufferList->mBuffers[i].mDataByteSize;
}
if (NULL == *outDataPacketDescription) {
*outDataPacketDescription = arg->packetDescriptions;
}
*ioNumberDataPackets = arg->frames;
return noErr;
}
Because it seems no possible infinite loop in your code (except for-loop in fillComplexBufferInputProc function), I suggest you use Instruments (Time Profiler) to see what method is using the majority of CPU time. Check the stack trace for more information, so maybe we can help. Here is a tutorial for time profiler.

Swift: Cannot Store Unsafe Pointers in Array

I created a small struct to hold version numbers.
Now I searched a compact way to parse the numbers directly into the variables of the struct. I tried to implement it this way:
struct Version {
var major: Int = 0
var minor: Int = 0
var revision: Int = 0
init(string: String) {
let components = string.componentsSeparatedByString(".")
if 1...3 ~= components.count {
var targets = [&major, &minor, &revision]
for index in 0...2 {
var scanner = NSScanner(string: components[index])
if (!scanner.scanInteger(target[index])) {
major = 0
minor = 0
revision = 0
return
}
}
}
}
}
But I get this error message:
Type '[inout Int]' of variable is not materializable
I do not understand this error. Is there a way to implement it in this way, using a sort of pointers to the member variables?
Update
In the end I did not use unsafe pointers. This was my final implementation:
init(string: String) {
let components = string.componentsSeparatedByString(".")
if 1...3 ~= components.count {
var values = [0, 0, 0]
for index in 0..<components.count {
var scanner = NSScanner(string: components[index])
if (!scanner.scanInteger(&values[index])) {
return
}
}
major = values[0]
minor = values[1]
revision = values[2]
}
}
The problem is how to get a pointer to the variables at all. It is possible
using withUnsafeMutablePointers():
init(string: String) {
let components = string.componentsSeparatedByString(".")
if 1...3 ~= components.count {
withUnsafeMutablePointers(&major, &minor, &revision) {
(p1, p2, p3) -> Void in
let targets = [p1, p2, p3]
for index in 0...2 {
var scanner = NSScanner(string: components[index])
if (!scanner.scanInteger(targets[index])) {
self.major = 0
self.minor = 0
self.revision = 0
break
}
}
}
}
}
but the code would probably better readable with three separate cases instead
of a pointer array.
in-out is not UnsafePointer nor UnsafeMutablePointer, only if the function accepts Unsafe???Pointer<T> family arguments, in-out expression will be passed as corresponding pointer types. see: the docs
try this:
var targets:[Int] = [0,0,0];
for index in 0...2 {
var scanner = NSScanner(string: components[index])
if (!scanner.scanInteger(&targets[index])) {
major = 0
minor = 0
revision = 0
return
}
}
major = targets[0]
minor = targets[1]
revision = targets[2]
OR
var targets:[UnsafeMutablePointer<Int>] = []
targets.append(&major)
targets.append(&minor)
targets.append(&revision)
for index in 0...2 {
var scanner = NSScanner(string: components[index])
if (!scanner.scanInteger(targets[index])) {
major = 0
minor = 0
revision = 0
return
}
}

Using NAudio to achieve fade out and fade in for a series of 44 kHz 16-bit two-channel wave files

I have a series of 44 kHz 16-bit two-channel uncompressed wave files (read from resources) and want to apply the fade out and fade in effect to create a stream from the sequence of all the WAV files.
The resource reading, and getting the 16-bit wavestream happens correctly. The target format is also shown correct, but I keep getting acmnotpossible as the exception in the waveformat coversion step below. What am I doing wrong?
String ResToPlay2 = NameSpaceString + ".Resources." + inWave2 + ".wav";
Stream _audioStream2;
int wavdur2 = 0;
Double fadeDurDbl2 = 0;
int fadeDur2 = 0;
if (!resA.GetManifestResourceStream (ResToPlay2).Equals (Stream.Null))
{
_audioStream2 = resA.GetManifestResourceStream (ResToPlay2);
WaveStream wavePCMStream2 = WaveFormatConversionStream.CreatePcmStream (new WaveFileReader (_audioStream2));
WaveFormat targetFmt2 = new WaveFormat (44100, 32, 2);
WaveStream waveStream2 = new WaveFormatConversionStream(targetFmt2,wavePCMStream2);
using (waveStream2)
{
wavdur2 = (int) waveStream2.TotalTime.Milliseconds;
var fader2 = new FadeInOutSampleProvider(new WaveToSampleProvider(waveStream2));
fadeDurDbl2 = (wavdur2*OverlapPCT) / 100;
fadeDur2 = (int) Math.Round(fadeDurDbl2, 0);
fader2.BeginFadeIn (fadeDur2);
var stwp2 = new NAudio.Wave.SampleProviders.SampleToWaveProvider (fader2);
WaveFileWriter.CreateWaveFile (Application.StartupPath + "\\" + "fadedIn_?.wav", stwp2);
}
}
I'm not sure why you are using WaveFormatConversionStream since you are starting in PCM. First get to a sample provider, then you can use FadeInOutSampleProvider
var reader = new WaveFileReader (_audioStream2)
var sampleProvider = SampleProviderConverters.ConvertWaveProviderIntoSampleProvider(reader);
var fader = new FadeInOutSampleProvider (sampleProvider);

Conditional Line Graph using Open Flash Charts

I am using Open Flash Charts v2. I have been trying to make Conditional line graph. But I couldn't find any straight forward way, example or any class for producing Conditional charts.
Example of Conditional Graph
So I thought to use some techniques to emulate conditional graph ,I made separate Line object for values above limit range and then this line is used to overlap the plotted line.
This techniques works some what ok ,but there are problems with it,
How to color or place the conditional colored line exactly above the limit.
Remove tooltip and dot from limit line.
Tooltip of conditional line(red) and plotted line(green) are both shown ,I only need tooltip of green line.
Conditional Line Graph Problem illustrated
Source Code: // C#
var chart = new OpenFlashChart.OpenFlashChart();
var data1 = new List<double?> { 1, 3, 4, 5, 2, 1, 6, 7 };//>4=
var overlap = new List<double?> { null, null, 4, 5, null, null, null, null };
var overlap2 = new List<double?> { null, null, null, null, null, null, 6, 7 };
var limitData = new List<double?> { 4, 4, 4, 4, 4, 4, 4, 4 };
var line1 = new Line();
line1.Values = data1;
//line1.HaloSize = 0;
line1.Width = 2;
line1.DotSize = 5;
line1.DotStyleType.Tip = "#x_label#<br>#val#";
line1.Colour = "#37c855";
line1.Tooltip = "#val#";
var overLine = new Line();
overLine.Values = overlap;
//overLine.HaloSize = 0;
overLine.Width = 2;
overLine.DotSize = 5;
overLine.DotStyleType.Tip = "#x_label#<br>#val#";
overLine.Colour = "#d81417";
overLine.Tooltip = "#val#";
var overLine2 = new Line();
overLine2.Values = overlap2;
//overLine2.HaloSize = 0;
overLine2.Width = 2;
overLine2.DotSize = 5;
//overLine2.DotStyleType.Tip = "#x_label#<br>#val#";
//overLine2.DotStyleType.Type = DotType.DOT;
overLine2.Colour = "#d81417";
overLine2.Tooltip = "#val#";
var limit = new Line();
limit.Values = limitData;
limit.Width = 2;
limit.Colour = "#ff0000";
limit.HaloSize = -1;
limit.DotSize = -1;
// limit.DotStyleType.Tip = "";
limit.DotStyleType.Type = null;
//limit.Tooltip = "";
chart.AddElement(line1);
chart.AddElement(overLine);
chart.AddElement(overLine2);
chart.AddElement(limit);
chart.Y_Legend = new Legend("Experiment");
chart.Title = new Title("Conditional Line Graph");
chart.Y_Axis.SetRange(0, 10);
chart.X_Axis.Labels.Color = "#e43456";
chart.X_Axis.Steps = 4;
chart.Tooltip = new ToolTip("#val#");
chart.Tooltip.Shadow = true;
chart.Tooltip.Colour = "#e43456";
chart.Tooltip.MouseStyle = ToolTipStyle.CLOSEST;
Response.Clear();
Response.CacheControl = "no-cache";
Response.Write(chart.ToPrettyString());
Response.End();
Note:
I have already downloaded the OFC (Open Flash Charts) source ,If I modify the OFC Line.as source than how would I be able to generate json for the changed graph ? ,b/c I'm currently using .Net library for the json generation for OFC charts,please do let me know this also.
Update:
I have modified the source code on the advice of David Mears I'm using FlashDevelop for ActionScript.
P.S: I'm open for ideas if another library can do this job.
If you don't mind a little rebuilding, you can get the source of OFC here and modify the Line.solid_line() method in open-flash-chart/charts/Line.as to do this fairly easily.
In order to set the extra chart details through JSON using the .NET library, you'll also have to modify OpenFlashChart/LineBase.cs to add alternative colour and boundary properties. I'm not hugely familiar with .NET, but based on the existing properties you might add something like this:
private double boundary;
private string altcolour;
[JsonProperty("boundary")]
public virtual double Boundary
{
set { this.boundary = value; }
get { return this.boundary; }
}
[JsonProperty("alt-colour")]
public virtual string AltColour
{
set { this.altcolour = value; }
get { return this.altcolour; }
}
Then I believe the following should work in Line.as:
public function solid_line(): void {
var first:Boolean = true;
var i:Number;
var tmp:Sprite;
var x:Number;
var y:Number;
var last_e:Element;
var ratio:Number;
for ( i=0; i < this.numChildren; i++ ) {
// Step through every child object.
tmp = this.getChildAt(i) as Sprite;
// Only include data Elements, ignoring extra children such as line masks.
if( tmp is Element )
{
var e:Element = tmp as Element;
if( first )
{
if (this.props.get('alt-colour') != Number.NEGATIVE_INFINITY) {
if (e._y >= this.props.get_colour('boundary'))
{
// Line starts below boundary, set alt line colour.
this.graphics.lineStyle( this.props.get_colour('width'), this.props.get_colour('alt-colour') );
}
else
{
// Line starts above boundary, set normal line colour.
this.graphics.lineStyle( this.props.get_colour('width'), this.props.get_colour('colour') );
}
}
// Move to the first point.
this.graphics.moveTo(e.x, e.y);
x = e.x;
y = e.y;
first = false;
}
else
{
if (this.props.get('alt-colour') != Number.NEGATIVE_INFINITY) {
if (last_e._y < this.props.get_colour('boundary') && e._y >= this.props.get_colour('boundary'))
{
// Line passes below boundary. Draw first section and switch to alt colour.
ratio = (this.props.get_colour('boundary') - last_e._y) / (e._y - last_e._y);
this.graphics.lineTo(last_e.x + (e.x - last_e.x) * ratio, last_e.y + (e.y - last_e.y) * ratio);
this.graphics.lineStyle( this.props.get_colour('width'), this.props.get_colour('alt-colour') );
}
else if (last_e._y >= this.props.get_colour('boundary') && e._y < this.props.get_colour('boundary'))
{
// Line passes above boundary. Draw first section and switch to normal colour.
ratio = (this.props.get_colour('boundary') - last_e._y) / (e._y - last_e._y);
this.graphics.lineTo(last_e.x + (e.x - last_e.x) * ratio, last_e.y + (e.y - last_e.y) * ratio);
this.graphics.lineStyle( this.props.get_colour('width'), this.props.get_colour('colour') );
}
}
// Draw a line to the next point.
this.graphics.lineTo(e.x, e.y);
}
last_e = e;
}
}
if ( this.props.get('loop') ) {
// close the line loop (radar charts)
this.graphics.lineTo(x, y);
}
}
With the new open-flash-chart.swf, you should be able to just set your new properties on line1:
line1.Boundary = 4;
line1.AltColour = "#d81417";

Resources