Replacement for deprecated NXOpenEventStatus? - objective-c

I need to get the tracking speed of the mouse on OSX 10.13. I found this code on the internet but NXOpenEventStatus is deprecated (as is IOHIDGetAccelerationWithKey), is there an alternative way?
#include <stdio.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/hidsystem/IOHIDLib.h>
#include <IOKit/hidsystem/IOHIDParameter.h>
#include <IOKit/hidsystem/event_status_driver.h>
int main()
{
kern_return_t kr;
double trackpadAcceleration, mouseAcceleration;
NXEventHandle h = 0;
h = NXOpenEventStatus();
if (h == nil)
return -1;
kr = IOHIDGetAccelerationWithKey( h, CFSTR(kIOHIDMouseAccelerationType), &mouseAcceleration);
return 0;
}

Since NXOpenEventStatus and IOHIDGetAccelerationWithKey are both part of the open-source IOKit distribution, you can look at how they're implemented. It turns out we can do what those functions do, using only non-deprecated functions.
To boil it down to the bare minimum, you can get a dictionary of the HID system's properties like this:
#import <Foundation/Foundation.h>
#import <IOKit/hidsystem/IOHIDLib.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
io_service_t service = IORegistryEntryFromPath(kIOMasterPortDefault, kIOServicePlane ":/IOResources/IOHIDSystem");
CFDictionaryRef parameters = IORegistryEntryCreateCFProperty(service, CFSTR(kIOHIDParametersKey), kCFAllocatorDefault, kNilOptions);
NSLog(#"%#", parameters);
IOObjectRelease(service);
}
return 0;
}
Output (for me on macOS 10.13.4):
2018-04-05 17:06:55.560590-0500 accel[11924:131983] {
ActuateDetents = 1;
Clicking = 0;
DragLock = 0;
Dragging = 0;
EjectDelay = 0;
FirstClickThreshold = 1;
ForceSuppressed = 0;
HIDClickSpace = (
5,
5
);
HIDClickTime = 500000000;
HIDDefaultParameters = 1;
HIDF12EjectDelay = 250;
HIDFKeyMode = 1;
HIDInitialKeyRepeat = 250000000;
HIDKeyRepeat = 33333333;
HIDKeyboardModifierMappingPairs = (
);
HIDMouseAcceleration = 98304;
HIDMouseKeysOptionToggles = 0;
HIDPointerAcceleration = 45056;
HIDPointerButtonMode = 2;
HIDScrollAcceleration = 20480;
HIDScrollZoomModifierMask = 262144;
HIDSlowKeysDelay = 0;
HIDStickyKeysDisabled = 0;
HIDStickyKeysOn = 0;
HIDStickyKeysShiftToggles = 0;
HIDTrackpadAcceleration = 57344;
HIDWaitCursorFrameInterval = 16666667;
JitterNoClick = 1;
JitterNoMove = 1;
MouseButtonDivision = 55;
MouseButtonMode = TwoButton;
MouseHorizontalScroll = 1;
MouseMomentumScroll = 1;
MouseOneFingerDoubleTapGesture = 0;
MouseTwoFingerDoubleTapGesture = 0;
MouseTwoFingerHorizSwipeGesture = 0;
MouseVerticalScroll = 1;
"OutsidezoneNoAction When Typing" = 1;
"PalmNoAction Permanent" = 1;
"PalmNoAction When Typing" = 1;
SecondClickThreshold = 1;
"Trackpad Jitter Milliseconds" = 192;
TrackpadCornerSecondaryClick = 0;
TrackpadFiveFingerPinchGesture = 0;
TrackpadFourFingerHorizSwipeGesture = 2;
TrackpadFourFingerPinchGesture = 0;
TrackpadFourFingerVertSwipeGesture = 0;
TrackpadHandResting = 1;
TrackpadHorizScroll = 1;
TrackpadMomentumScroll = 1;
TrackpadPinch = 1;
TrackpadRightClick = 1;
TrackpadRotate = 1;
TrackpadScroll = 1;
TrackpadThreeFingerDrag = 0;
TrackpadThreeFingerHorizSwipeGesture = 2;
TrackpadThreeFingerTapGesture = 0;
TrackpadThreeFingerVertSwipeGesture = 0;
TrackpadThreeFingersRightClick = 0;
TrackpadTwoFingerDoubleTapGesture = 1;
TrackpadTwoFingerFromRightEdgeSwipeGesture = 0;
TwofingerNoAction = 1;
USBMouseStopsTrackpad = 0;
"Use Panther Settings for W" = 0;
UserPreferences = 1;
version = 1;
}
Program ended with exit code: 0
The kIOHIDMouseAccelerationType constant has value HIDMouseAcceleration. I also see HIDPointerAcceleration and HIDTrackpadAcceleration in there. There are kIOHID... constants for those too.
Note also that IOHIDGetAccelerationWithKey divides the registry value by 65536 before returning it. IOHIDSetAccelerationWithKey performs the opposite transformation.

Related

Vulkan: Loading floating point cubemap textures distorted

I am using vulkan-tutorial codes and i made modify for cubemap.
when i use VK_FORMAT_R8G8B8A8_UNORM is working with this code:
unsigned char* pixelsArray[6];
for (int i = 0; i < 6; ++i)
{
pixelsArray[i] = stbi_load(imageFileArray[i].c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
}
VkDeviceSize allSize = texWidth * texHeight * 4 * 6;
VkDeviceSize size = texWidth * texHeight * 4 ;
VkBufferCreateInfo bufferInfo{};
...
bufferInfo.size = allSize ;
vkMapMemory(device, stagingBufferMemory, 0, AllSize, 0, &data);
for(int i = 0; i < 6; ++i)
{
memcpy( (char*) data + (size*i) , pixelsArray[i], static_cast<size_t>(size));
}
vkUnmapMemory(device, stagingBufferMemory);
VkImageCreateInfo imageInfo{};
...
imageInfo.arrayLayers = 6;
imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
imageInfo.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
VkImageViewCreateInfo viewInfo{};
...
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_CUBE;
viewInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
viewInfo.subresourceRange.layerCount = 6;
but when i try VK_FORMAT_R16G16B16A16_SFLOAT is giving distorted display and no validation error with this code:
float* pixelsArray[6];
for (int i = 0; i < 6; ++i)
{
pixelsArray[i] = stbi_loadf(imageFileArray[i].c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha);
}
VkDeviceSize allSize = texWidth * texHeight * 4 * 6 * 2;// I added *2
VkDeviceSize size = texWidth * texHeight * 4 * 2;// I added *2
VkBufferCreateInfo bufferInfo{};
...
bufferInfo.size = allSize ;
vkMapMemory(device, stagingBufferMemory, 0, AllSize, 0, &data);
for(int i = 0; i < 6; ++i)
{
memcpy( (char*) data + (size*i) , pixelsArray[i], static_cast<size_t>(size));
}
vkUnmapMemory(device, stagingBufferMemory);
VkImageCreateInfo imageInfo{};
...
imageInfo.arrayLayers = 6;
imageInfo.format = VK_FORMAT_R16G16B16A16_SFLOAT;
imageInfo.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
VkImageViewCreateInfo viewInfo{};
...
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_CUBE;
viewInfo.format = VK_FORMAT_R16G16B16A16_SFLOAT;
viewInfo.subresourceRange.layerCount = 6;
when VK_FORMAT_R8G8B8A8_UNORM :
when VK_FORMAT_R16G16B16A16_SFLOAT :
i fixed the problem. problem was that i want to use half float but i was sending float to memcpy function.i searched how can i use half float and i found a solution without using extra library.
what i did add helper functions :
typedef unsigned int uint;
typedef unsigned short ushort;
uint as_uint(const float x)
{
return *(uint*)&x;
}
ushort float_to_half(const float x)
{
// IEEE-754 16-bit floating-point format (without infinity): 1-5-10, exp-15, +-131008.0, +-6.1035156E-5, +-5.9604645E-8, 3.311 digits
const uint b = as_uint(x)+0x00001000; // round-to-nearest-even: add last bit after truncated mantissa
const uint e = (b&0x7F800000)>>23; // exponent
const uint m = b&0x007FFFFF; // mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 = decimal indicator flag - initial rounding
return (b&0x80000000)>>16 | (e>112)*((((e-112)<<10)&0x7C00)|m>>13) | ((e<113)&(e>101))*((((0x007FF000+m)>>(125-e))+1)>>1) | (e>143)*0x7FFF; // sign : normalized : denormalized : saturate
}
and fix problem with this helper functions :
VkDeviceSize size_2 = texWidth * texHeight * 4;// different from the above variables in question : allSize or size
//create half float for cubemap
void* half_pixelsArray[6];
half_pixelsArray[0] = new ushort[size_2];
half_pixelsArray[1] = new ushort[size_2];
half_pixelsArray[2] = new ushort[size_2];
half_pixelsArray[3] = new ushort[size_2];
half_pixelsArray[4] = new ushort[size_2];
half_pixelsArray[5] = new ushort[size_2];
//copy from float to half float
for (int i = 0; i < 6; ++i)
{
for (int j = 0; j < size_2; ++j)
{
((ushort*)half_pixelsArray[i])[j] = float_to_half( pixelsArray[i][j] );
}
}
// and change float to half flaot in memcpy
memcpy( (char*) data + (layerSize*i) , half_pixelsArray[i], static_cast<size_t>(layerSize));

compare images using systemC

I wrote in this forum asking for help to solve this problem that took ame a lot of my time,i write my first program using systemC, I will expain my aim as much as I can , I stored 2 matrix of pixel value of image in two different text files, I write a systemC code that load two matrix and apply somme of absolute difference, if number of different superior of a Threshold the code displays message (motion).
My code composed of two modules, the first module check if there a number stored in a text file, if yes this Module will automates the other module to load the two matrix and compare them, I really need this code for my project graduation any help or suggestion.
#include "systemC.h"
#include "string.h"
#include "stdio.h"
#include"stdlib.h"
#include <time.h>
#include <math.h> /* fabs */
#include <fstream>
#include <iostream>
#include <fstream>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
_CRT_SECURE_NO_WARNINGS
double elapsed;
int H = 0;
int D = 0;
int a, b;
int in = false;
int L = 0;
char *mode1 = "r";
char *mode2 = "w";
int i, j, k;
int rows1, cols1, rows2, cols2;
bool fileFound = false;
FILE *SwitchContext;
FILE *image1;
FILE *image2;
FILE *image3;
int sum = 0;
clock_t start = clock();
SC_MODULE(synchronization)
{
sc_in<bool>sig ;
SC_CTOR(synchronization)
{
SC_METHOD(synchroprocess)
}
void synchroprocess()
{
cout << "\n Running Automation";
SwitchContext = fopen("F:/SWITCH CONTEXT.txt", mode2);
fscanf(SwitchContext, "%d", &L);
while (L != 0)
{
cout << "waiting...";
}
sig == true;
}
};
SC_MODULE(imageProcess)
{
sc_in<bool>sig;
SC_CTOR(imageProcess)
{
SC_METHOD(MotionDetector)
sensitive(sig);
}
void MotionDetector()
{
image3 = fopen("F:/image3.txt", mode2);
do
{
char *mode1 = "r";
char *mode2 = "w";
image1 = fopen("F:/image1.txt", mode1);
if (!image1)
{
printf("File Not Found!!\n");
fileFound = true;
}
else
fileFound = false;
}
while (fileFound);
do
{
image2 = fopen("F:/image2.txt", mode1);
if (!image2)
{
printf("File Not Found!!\n");
fileFound = true;
}
else
fileFound = false;
}
while (fileFound);
rows1 = rows2 = 384;
cols1 = cols2 = 512;
int **mat1 = (int **)malloc(rows1 * sizeof(int*));
for (i = 0; i < rows1; i++)
mat1[i] = (int *)malloc(cols1 * sizeof(int));
i = 0;
int **mat2 = (int **)malloc(rows2 * sizeof(int*));
for (i = 0; i < rows2; i++)
mat2[i] = (int *)malloc(cols2 * sizeof(int));
i = 0;
while (!feof(image1))
{
for (i = 0; i < rows1; i++)
{
for (j = 0; j < cols1; j++)
fscanf(image1, "%d%", &mat1[i][j]);
}
}
i = 0;
j = 0;
while (!feof(image2))
{
for (i = 0; i < rows2; i++)
{
for (j = 0; j < cols2; j++)
fscanf(image2, "%d%", &mat2[i][j]);
}
}
i = 0;
j = 0;
printf("\n\n");
for (i = 0; i < rows1; i++)
{
for (j = 0; j < cols1; j++) {
a = abs(mat1[i][j] = mat2[i][j]);
b = b + a;
}
}
i = j = 0;
D = b / 196608;
if (D > 0.9)
{
printf("%d,&K");
printf("MOTION...DETECTED");
getchar();
sc_pause;
for (i = 0; i < rows1; i++) {
for (j = 0; j < cols1; j++)
{
fprintf(image3, "%d ", mat2[i][j]);
}
fprintf(image3, "\n");
}
printf("\n Image Saved....");
std::ofstream mon_fichier("F:\toto.txt");
mon_fichier << elapsed << '\n';
}
fclose(image1);
fclose(image2);
fclose(image3);
clock_t end = clock();
elapsed = ((double)end - start) / CLOCKS_PER_SEC;
printf("time is %f", elapsed);
}
};
int sc_main(int argc, char* argv[])
{
imageProcess master("EE2");
master.MotionDetector();
sc_start();
return(0);
}
What you did is basically wrong.
You copy pasted code to SC_MODULE, this code is simple C code
(Do not mix C and C++ files)
This is not how you use clock
What you should do:
You need to check if your algorithm works, for this you do not need SystemC at all
Then you can replace data types with HW one and check if it still works
Then you have to find which data interface is used in HW and how to use this interface
Then you have to tweak your alg. to work with this interface (There you can use SC_MODULE, sc ports etc...)
Also take look at SC_CTHREAD, you will need it.
Without any informations about target platform I can not provide any other help.

Code cleanup data structure

How to clean up/remove Verific data structures
int x = 15;
for (int i = 0; i < x; i++) {
mySequence[i] = 0;
}
mySequence[0] = -127;
delete[] mySequence;

How to view complete contents of NSUserDefaults [duplicate]

This question already has answers here:
See NSUserDefaults file content
(4 answers)
Closed 8 years ago.
I have an app where I store all of the user preferences in NSUserDefaults. I would like to be able to see (for debugging purposes) the complete contents of the NSUserDefaults file.
Can it be done without providing each of the keys?
Can it be done without providing each of the keys?
You can use dictionaryRepresentation of NSUserDefaults like that below example:-
NSUserDefaults *def=[NSUserDefaults standardUserDefaults];
[def setObject:#"test1" forKey:#"test1"];
[def setObject:#"test2" forKey:#"test2"];
NSLog(#"%#",[[NSUserDefaults standardUserDefaults]dictionaryRepresentation]);
EDIT:-
When use dictionaryRepresentation it will print the complete information of user default, including extra value which is added in the defaults.
Below is the output of above code. Also you can see the value in the last which is extra included in the user defaults :-
AppleAntiAliasingThreshold = 4;
AppleGCIdleTimeInterval = "1.0";
AppleLanguages = (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
es,
it,
nl,
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
ar,
th,
cs,
hu,
ca,
hr,
el,
he,
ro,
sk,
uk,
id,
ms,
vi
);
AppleLocale = "en_US";
AppleMeasurementUnits = Inches;
AppleMetricUnits = 0;
AppleMiniaturizeOnDoubleClick = 0;
AppleShowScrollBars = Always;
AppleTextDirection = 0;
AppleUserLanguages = 1;
Country = US;
MultipleSessionEnabled = 1;
NSBoldSystemFont = ".LucidaGrandeUI-Bold";
NSButtonDelay = "0.4";
NSButtonPeriod = "0.075";
NSDocumentRevisionsDebugMode = YES;
NSDragAutoscrollAreaWidth = "5.0";
NSDragCancelLimit = "100000.0";
NSDraggingAutoscrollDelay = "0.4";
NSEnableAutoCollapseOutlineDuringDragsDefault = NO;
NSEnableAutoExpandOutlineDuringDragsDefault = YES;
NSFixedPitchFont = "Menlo-Regular";
NSFixedPitchFontSize = 11;
NSFont = Helvetica;
NSFontSize = 12;
NSInputServerLaunchTimeout = 60;
NSInterfaceStyle = macintosh;
NSLanguages = (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
es,
it,
nl,
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
ar,
th,
cs,
hu,
ca,
hr,
el,
he,
ro,
sk,
uk,
id,
ms,
vi
);
NSMargins = "72 72 90 90";
NSMenuFlashCount = 3;
NSMenuScrollingOffset = 3;
NSMenuScrollingSpeed = 5;
NSNavPanelFileLastListModeForOpenModeKey = 1;
NSNavPanelFileListModeForOpenMode2 = 1;
NSNavPanelSidebarKeyForOpen = (
);
NSNavPanelSidebarKeyForSave = (
);
NSNavRecentPlaces = (
"~/Documents",
"~/Documents/sample Project/learning_iOS",
"~/Desktop/firstPage",
"~/Desktop/SoftwareDepotIssue",
"~/Desktop"
);
NSPreferredSpellServerVendors = {
English = "NeXT-OpenStep";
};
NSPreferredWebServices = {
NSWebServicesProviderWebSearch = {
NSDefaultDisplayName = Google;
NSProviderIdentifier = "com.google.www";
};
};
NSQuotedKeystrokeBinding = "^q";
NSRequireAutoCollapseOutlineAfterDropsDefault = NO;
NSResetIncrementalSearchOnFailure = YES;
NSScrollAnimationEnabled = YES;
NSScrollerButtonAcceleration = 8;
NSScrollerButtonDelay = "0.5";
NSScrollerButtonPeriod = "0.05";
NSScrollerHasSeparateArrows = YES;
NSScrollerKnobCount = 2;
NSScrollerKnobDelay = "0.001";
NSSmartCMYKColorConversion = YES;
NSSystemFont = ".LucidaGrandeUI";
NSSystemFontSize = 13;
NSUIHeartBeatCycle = "0.03";
NSUseCocoaInputServers = YES;
NSUserDictionaryReplacementItems = (
);
NSWindowResizeTime = ".20";
NavPanelFileListModeForOpenMode = 1;
SGTRecentFileSearches = (
{
attributes = (
kMDItemDisplayName
);
enforceStrictMatch = 0;
exactMatch = 0;
name = istsu;
scope = 4;
type = "com.apple.finder";
values = (
istsu
);
}
);
WebKitAVFoundationEnabled = 1;
WebKitAccelerated2dCanvasEnabled = 0;
WebKitAcceleratedCompositingEnabled = 1;
WebKitAcceleratedDrawingEnabled = 0;
WebKitAllowAnimatedImageLoopingPreferenceKey = 1;
WebKitAllowAnimatedImagesPreferenceKey = 1;
WebKitAllowFileAccessFromFileURLs = 1;
WebKitAllowUniversalAccessFromFileURLs = 1;
WebKitApplicationCacheDefaultOriginQuota = 9223372036854775807;
WebKitApplicationCacheTotalQuota = 9223372036854775807;
WebKitApplicationChromeModeEnabledPreferenceKey = 0;
WebKitAsynchronousSpellCheckingEnabled = 0;
WebKitAuthorAndUserStylesEnabledPreferenceKey = 1;
WebKitBackForwardCacheExpirationIntervalKey = 1800;
WebKitBackspaceKeyNavigationEnabled = 1;
WebKitCSSCompositingEnabled = 1;
WebKitCSSCustomFilterEnabled = 1;
WebKitCSSGridLayoutEnabled = 0;
WebKitCSSRegionsEnabled = 1;
WebKitCacheModelPreferenceKey = 0;
WebKitCanvasUsesAcceleratedDrawing = 0;
WebKitCursiveFont = "Apple Chancery";
WebKitDNSPrefetchingEnabled = 0;
WebKitDOMPasteAllowedPreferenceKey = 0;
WebKitDatabasesEnabledPreferenceKey = 1;
WebKitDefaultFixedFontSize = 13;
WebKitDefaultFontSize = 16;
WebKitDefaultTextEncodingName = "ISO-8859-1";
WebKitDeveloperExtrasEnabledPreferenceKey = 0;
WebKitDiagnosticLoggingEnabled = 0;
WebKitDisplayImagesKey = 1;
WebKitEditableLinkBehavior = 0;
WebKitEnableInheritURIQueryComponent = 0;
WebKitExperimentalNotificationsEnabledPreferenceKey = 0;
WebKitFantasyFont = Papyrus;
WebKitFixedFont = Courier;
WebKitFrameFlatteningEnabled = 0;
WebKitFullScreenEnabled = 0;
WebKitHiddenPageCSSAnimationSuspensionEnabled = 0;
WebKitHiddenPageDOMTimerThrottlingEnabled = 0;
WebKitHyperlinkAuditingEnabled = 1;
WebKitJavaEnabled = 1;
WebKitJavaScriptCanAccessClipboard = 0;
WebKitJavaScriptCanOpenWindowsAutomatically = 1;
WebKitJavaScriptEnabled = 1;
WebKitJavaScriptExperimentsEnabledPreferenceKey = 0;
WebKitKerningAndLigaturesEnabledByDefault = 1;
WebKitLoadSiteIconsKey = 0;
WebKitLocalFileContentSniffingEnabledPreferenceKey = 0;
WebKitLocalStorageEnabledPreferenceKey = 1;
WebKitLowPowerVideoAudioBufferSizeEnabled = 0;
WebKitMediaPlaybackAllowsInline = 1;
WebKitMediaPlaybackRequiresUserGesture = 0;
WebKitMinimumFontSize = 0;
WebKitMinimumLogicalFontSize = 9;
WebKitNotificationsEnabled = 1;
WebKitOfflineWebApplicationCacheEnabled = 0;
WebKitPDFDisplayMode = 1;
WebKitPDFScaleFactor = 0;
WebKitPageCacheSupportsPluginsPreferenceKey = 1;
WebKitPictographFont = "Apple Color Emoji";
WebKitPlugInSnapshottingEnabled = 0;
WebKitPluginsEnabled = 1;
WebKitPrivateBrowsingEnabled = 0;
WebKitQTKitEnabled = 1;
WebKitRegionBasedColumnsEnabled = 0;
WebKitRequestAnimationFrameEnabled = 1;
WebKitRespectStandardStyleKeyEquivalents = 0;
WebKitSansSerifFont = Helvetica;
WebKitScreenFontSubstitutionEnabled = 0;
WebKitSerifFont = Times;
WebKitShouldDisplayCaptions = 0;
WebKitShouldDisplaySubtitles = 0;
WebKitShouldDisplayTextDescriptions = 0;
WebKitShouldPrintBackgroundsPreferenceKey = 0;
WebKitShouldRespectImageOrientation = 0;
WebKitShowDebugBorders = 0;
WebKitShowRepaintCounter = 0;
WebKitShowsToolTipOverTruncatedText = 0;
WebKitShowsURLsInToolTips = 0;
WebKitShrinksStandaloneImagesToFit = 0;
WebKitSpatialNavigationEnabled = 0;
WebKitStandardFont = Times;
WebKitStorageBlockingPolicy = 0;
WebKitSuppressesIncrementalRendering = 0;
WebKitTabToLinksPreferenceKey = 0;
WebKitTextAreasAreResizable = 0;
WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey = 1;
WebKitUseLegacyTextAlignPositionedElementBehavior = 0;
WebKitUsePreHTML5ParserQuirks = 0;
WebKitUseSiteSpecificSpoofing = 0;
WebKitUserStyleSheetEnabledPreferenceKey = 0;
WebKitUserStyleSheetLocationPreferenceKey = "";
WebKitUsesEncodingDetector = 0;
WebKitUsesPageCachePreferenceKey = 1;
WebKitWantsBalancedSetDefersLoadingBehavior = 0;
WebKitWebArchiveDebugModeEnabledPreferenceKey = 0;
WebKitWebAudioEnabled = 0;
WebKitWebGLEnabled = 0;
WebKitWebSecurityEnabled = 1;
WebKitXSSAuditorEnabled = 1;
WebKitZoomsTextOnly = 1;
"com.apple.AppleModemSettingTool.LastCountryCode" = US;
"com.apple.ColorSync.Devices" = {
"Device.cmra.00000000-0000-0000-0000-000000533630" = {
DeviceDescriptions = {
"en_US" = "NO NAME";
};
FactoryProfiles = {
555810816 = {
DeviceModeDescriptions = {
"en_US" = Default;
};
DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
};
DeviceDefaultProfileID = 555810816;
};
};
"Device.cmra.30303441-3030-3930-4637-393830304637" = {
DeviceDescriptions = {
"en_US" = "Lumia 520";
};
FactoryProfiles = {
555810816 = {
DeviceModeDescriptions = {
"en_US" = Default;
};
DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
};
DeviceDefaultProfileID = 555810816;
};
};
"Device.cmra.37616133-3566-6339-6362-303662336639" = {
DeviceDescriptions = {
"en_US" = iPhone;
};
FactoryProfiles = {
555810816 = {
DeviceModeDescriptions = {
"en_US" = Default;
};
DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
};
DeviceDefaultProfileID = 555810816;
};
};
};
"com.apple.TimeZonePref.Last_Selected_City" = (
"37.36883",
"-122.0363",
0,
"America/Los_Angeles",
US,
Sunnyvale,
"U.S.A.",
Sunnyvale,
"U.S.A.",
"DEPRECATED IN 10.6"
);
"com.apple.preferences.timezone.selected_city" = {
CountryCode = US;
GeonameID = 5400075;
Latitude = "37.36883";
LocalizedNames = {
ar = "\U0633\U0627\U0646\U064a\U0641\U064a\U0644";
ca = Sunnyvale;
cs = Sunnyvale;
da = Sunnyvale;
de = Sunnyvale;
el = Sunnyvale;
en = Sunnyvale;
es = Sunnyvale;
fi = Sunnyvale;
fr = Sunnyvale;
he = "\U05e1\U05d0\U05e0\U05d9\U05d5\U05d5\U05dc";
hr = Sunnyvale;
hu = Sunnyvale;
id = Sunnyvale;
it = Sunnyvale;
ja = "\U30b5\U30cb\U30fc\U30d9\U30fc\U30eb";
ko = "\Uc11c\Ub2c8\Ubca0\Uc77c";
ms = Sunnyvale;
nb = Sunnyvale;
nl = Sunnyvale;
pl = Sunnyvale;
pt = Sunnyvale;
"pt-PT" = Sunnyvale;
ro = Sunnyvale;
ru = "\U0421\U0430\U043d\U043d\U0438\U0432\U0435\U0439\U043b";
sk = Sunnyvale;
sv = Sunnyvale;
th = Sunnyvale;
tr = Sunnyvale;
uk = "\U0421\U0430\U043d\U043d\U0456\U0432\U0435\U0439\U043b";
vi = Sunnyvale;
"zh-Hans" = "\U6851\U5c3c\U7ef4\U5c14";
"zh-Hant" = "\U6851\U5c3c\U7dad\U723e";
};
Longitude = "-122.0363";
Name = Sunnyvale;
Population = 140081;
RegionalCode = CA;
TimeZoneName = "America/Los_Angeles";
Version = 1;
};
"com.apple.springing.delay" = "0.5";
"com.apple.springing.enabled" = 1;
"com.apple.trackpad.enableSecondaryClick" = 1;
"com.apple.trackpad.fiveFingerPinchSwipeGesture" = 2;
"com.apple.trackpad.fourFingerHorizSwipeGesture" = 2;
"com.apple.trackpad.fourFingerPinchSwipeGesture" = 2;
"com.apple.trackpad.fourFingerVertSwipeGesture" = 2;
"com.apple.trackpad.momentumScroll" = 1;
"com.apple.trackpad.pinchGesture" = 1;
"com.apple.trackpad.rotateGesture" = 1;
"com.apple.trackpad.scrollBehavior" = 2;
"com.apple.trackpad.threeFingerDragGesture" = 0;
"com.apple.trackpad.threeFingerHorizSwipeGesture" = 2;
"com.apple.trackpad.threeFingerTapGesture" = 2;
"com.apple.trackpad.threeFingerVertSwipeGesture" = 2;
"com.apple.trackpad.twoFingerDoubleTapGesture" = 1;
"com.apple.trackpad.twoFingerFromRightEdgeSwipeGesture" = 3;
"com.apple.trackpad.version" = 5;
"com.apple.updatesettings_did_disable_ftp" = 1;
test1 = test1;
test2 = test2;

using X264 and librtmp to send live camera frame, but the flash can't show

I am using X264 and librtmp to send my live camera frame, all the things seems right. but my web test flash can't show the correct video. Sometimes it seems correct, but when I re-click play button, it doesn't show any picture on the flash.
Here is my X264 config code
x264_param_default_preset(&x264param, "ultrafast", "zerolatency");
x264param.i_threads = 2;
x264param.i_width = width;
x264param.i_height = height;
x264param.i_log_level = X264_LOG_DEBUG;
x264param.i_fps_num = x264param.i_timebase_num= fps;
x264param.i_fps_den = x264param.i_timebase_den=1;
x264param.i_frame_total = 0;
x264param.i_frame_reference =1;
//x264param.i_frame_reference = 2;
x264param.i_keyint_min = 25;
x264param.i_keyint_max = fps*3;
x264param.i_scenecut_threshold = 40;
x264param.b_deblocking_filter = 1;
x264param.b_cabac = 0;
x264param.analyse.i_trellis = 0;
x264param.analyse.b_chroma_me = 1;
x264param.vui.i_sar_width = 0;
x264param.vui.i_sar_height = 0;
x264param.i_bframe_bias = 0;
x264param.b_interlaced= 0;
x264param.analyse.i_subpel_refine = 6; /* 0..5 -> 1..6 */
x264param.analyse.i_me_method = X264_ME_DIA;//X264_ME_HEX?X264_ME_DIA
x264param.analyse.i_me_range = 16;
x264param.analyse.i_direct_mv_pred = X264_DIRECT_PRED_AUTO;
x264param.i_deblocking_filter_alphac0 = 0;
x264param.i_deblocking_filter_beta = 0;
//x264param.analyse.intra = X264_ANALYSE_I4x4;
x264param.analyse.intra = X264_ANALYSE_I4x4;// | X264_ANALYSE_PSUB16x16 | X264_ANALYSE_BSUB16x16;
x264param.analyse.inter = X264_ANALYSE_I4x4 | X264_ANALYSE_PSUB16x16 | X264_ANALYSE_BSUB16x16;
//edit 2014-7-28
x264param.analyse.b_transform_8x8 = 1;
//x264param.analyse.b_transform_8x8 = 0;
x264param.analyse.b_fast_pskip = 1;
x264param.i_bframe = 0;
//x264param.b_intra_refresh
x264param.analyse.b_weighted_bipred = 0;
//// Intra refres:
x264param.i_keyint_max = 250;
x264param.b_intra_refresh = 0;
////Rate control:
//x264param.rc.i_rc_method = X264_RC_CRF;
//Rate Control
x264param.rc.f_ip_factor = 1.4f;
x264param.rc.f_pb_factor = 1.3f;
x264param.rc.f_qcompress = 1.0;
x264param.rc.i_qp_min = 20;//20;
x264param.rc.i_qp_max = 32;
x264param.rc.i_qp_step = 1;
switch (0)
{
case 0: /* 1 PASS ABR */
x264param.rc.i_rc_method = X264_RC_ABR;
x264param.rc.i_bitrate = 300; // max = 5000
x264param.rc.b_mb_tree = 0;
break;
case 1: /* 1 PASS CQ */
x264param.rc.i_rc_method = X264_RC_CQP;
x264param.rc.i_qp_constant = 26;//10 - 51
break;
}
//For streaming:
x264param.b_repeat_headers = 1;
x264param.b_annexb = 1;
x264_param_apply_profile(&x264param, "baseline");
encoder = x264_encoder_open(&x264param);
x264_picture_init( &pic_in );
x264_picture_alloc(&pic_in, X264_CSP_I420, width, height);
pic_in.img.i_csp = X264_CSP_I420|X264_CSP_VFLIP;
pic_in.img.i_plane = 3;
pic_in.i_type = X264_TYPE_AUTO;
Sending To RTMP:
sws_scale(convertCtx,&a,&scribe,0,height, pic_in.img.plane, pic_in.img.i_stride);
int i_nal;
int i_frame_size = x264_encoder_encode( encoder, &nal, &i_nal, &pic_in, &pic_out );
if(i_frame_size <= 0){
printf("\t!!!FAILED encode frame \n");
}else{
for (int i = 0,last=0; i < i_nal;i++)
{
fwrite(nal[i].p_payload, 1, i_frame_size-last, fpw1);
if (nal[i].i_type == NAL_SPS) {
sps_len = nal[i].i_payload-4;
sps = new unsigned char[sps_len];
memcpy(sps,nal[i].p_payload+4,sps_len);
} else if (nal[i].i_type == NAL_PPS) {
pps_len = nal[i].i_payload-4;
pps = new unsigned char[sps_len];
memcpy(pps,nal[i].p_payload+4,pps_len);
send_video_sps_pps();
free(sps);
free(pps);
} else {
send_rtmp_video(nal[i].p_payload,i_frame_size-last);
break;
}
last += nal[i].i_payload;
}
}
Send PPS and SPS
void send_video_sps_pps(){
if(rtmp!= NULL){
RTMPPacket * packet;
unsigned char * body;
int i;
packet = (RTMPPacket *)malloc(RTMP_HEAD_SIZE+1024);
memset(packet,0,RTMP_HEAD_SIZE);
packet->m_body = (char *)packet + RTMP_HEAD_SIZE;
body = (unsigned char *)packet->m_body;
i = 0;
body[i++] = 0x17;
body[i++] = 0x00;
body[i++] = 0x00;
body[i++] = 0x00;
body[i++] = 0x00;
/*AVCDecoderConfigurationRecord*/
body[i++] = 0x01;
body[i++] = sps[1];
body[i++] = sps[2];
body[i++] = sps[3];
body[i++] = 0xff;
/*sps*/
body[i++] = 0xe1;
body[i++] = (sps_len >> 8) & 0xff;
body[i++] = sps_len & 0xff;
memcpy(&body[i],sps,sps_len);
i += sps_len;
/*pps*/
body[i++] = 0x01;
body[i++] = (pps_len >> 8) & 0xff;
body[i++] = (pps_len) & 0xff;
memcpy(&body[i],pps,pps_len);
i += pps_len;
packet->m_packetType = RTMP_PACKET_TYPE_VIDEO;
packet->m_nBodySize = i;
packet->m_nChannel = 0x04;
packet->m_nTimeStamp = 0;
packet->m_hasAbsTimestamp = 0;
packet->m_headerType = RTMP_PACKET_SIZE_MEDIUM;
packet->m_nInfoField2 = rtmp->m_stream_id;
RTMP_SendPacket(rtmp,packet,TRUE);
free(packet);
rtmp_start_time = GetTickCount();
}else{
std::cout<<"RTMP is not ready"<<std::endl;
}
}
Send video Frame
void send_rtmp_video(unsigned char * buf,int len){
RTMPPacket * packet;
long timeoffset = GetTickCount() - rtmp_start_time;
int type = buf[0]&0x1f;
packet = (RTMPPacket *)malloc(RTMP_HEAD_SIZE+len+9);
memset(packet,0,RTMP_HEAD_SIZE);
packet->m_body = (char *)packet + RTMP_HEAD_SIZE;
packet->m_nBodySize = len + 9;
/*send video packet*/
unsigned char *body = (unsigned char *)packet->m_body;
memset(body,0,len+9);
/*key frame*/
body[0] = 0x27;
if (type == NAL_SLICE_IDR) {
body[0] = 0x17;
}
body[1] = 0x01; /*nal unit*/
body[2] = 0x00;
body[3] = 0x00;
body[4] = 0x00;
body[5] = (len >> 24) & 0xff;
body[6] = (len >> 16) & 0xff;
body[7] = (len >> 8) & 0xff;
body[8] = (len ) & 0xff;
/*copy data*/
memcpy(&body[9],buf,len);
packet->m_hasAbsTimestamp = 0;
packet->m_packetType = RTMP_PACKET_TYPE_VIDEO;
if(rtmp != NULL){
packet->m_nInfoField2 = rtmp->m_stream_id;
}
packet->m_nChannel = 0x04;
packet->m_headerType = RTMP_PACKET_SIZE_LARGE;
packet->m_nTimeStamp = timeoffset;
if(rtmp != NULL){
RTMP_SendPacket(rtmp,packet,TRUE);
}
free(packet);
}
Try changing:
pps = new unsigned char[sps_len];
to:
pps = new unsigned char[pps_len];