Vulkan resolve attachment is flipped - vulkan

I use pResolveAttachment to implement MSAA with Vulkan on Android, but the result is flipped.
VkSubpassDescription subpassDesc;
subpassDesc.flags = 0;
subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpassDesc.inputAttachmentCount = 0;
subpassDesc.pInputAttachments = nullptr;
subpassDesc.colorAttachmentCount = colorAttachmentCount;
subpassDesc.pColorAttachments = attachmentRefs.data();
subpassDesc.pResolveAttachments = resolveAttachmentCount > 0 ? resolveReferences.data() : nullptr;
subpassDesc.pDepthStencilAttachment = depthStencilAttachment;
subpassDesc.preserveAttachmentCount = 0;
subpassDesc.pPreserveAttachments = nullptr;
// TIPS
resolveReferences[resolveAttachmentCount].attachment = attachmentCount;
resolveReferences[resolveAttachmentCount].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
resolveAttachmentCount++;
....
subpassDesc.pResolveAttachments = resolveAttachmentCount > 0 ? resolveReferences.data() : nullptr;

Related

How to to create a 1D Texture in Vulkan

I have a problem to create a 1D texture and I don't know how to solve it.
The texture is a float pData[256][4].
The code is like this:
VkDeviceSize imageSize = 256 * 4 * 4;
uint32_t texMemSize = ftsize;
VkBuffer stagingBuffer;
VkDeviceMemory stagingMemory;
VkBufferCreateInfo bufferCreateInfo = {};
bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bufferCreateInfo.size = imageSize;
bufferCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
bufferCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
if (vkCreateBuffer(device, &bufferCreateInfo, nullptr, &stagingBuffer) != VK_SUCCESS) {
throw std::runtime_error("failed to create buffer!");
}
VkMemoryAllocateInfo memAllocInfo2 = { };
memAllocInfo2.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
VkMemoryRequirements memReqs2 = {};
vkGetBufferMemoryRequirements(device, stagingBuffer, &memReqs2);
memAllocInfo2.allocationSize = memReqs2.size;
memAllocInfo2.memoryTypeIndex = findMemoryType(memReqs2.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
if (vkAllocateMemory(device, &memAllocInfo2, nullptr, &stagingMemory) != VK_SUCCESS) {
throw std::runtime_error("failed to allocate memory 2!");
}
vkBindBufferMemory(device, stagingBuffer, stagingMemory, 0);
void* data;
vkMapMemory(device, stagingMemory, 0, imageSize, 0, &data);
memcpy(data, pData, static_cast<size_t>(imageSize));
vkUnmapMemory(device, stagingMemory);
delete pData;
//
VkImageCreateInfo imageInfo = {};
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageInfo.imageType = VK_IMAGE_TYPE_1D;
imageInfo.extent.width = static_cast<uint32_t>(256);
imageInfo.extent.depth = 1;
imageInfo.extent.height = 1;
imageInfo.mipLevels = 1;
imageInfo.arrayLayers = 1;
imageInfo.format = VK_FORMAT_R32G32B32A32_UINT;
imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
imageInfo.flags = 0; // Optional
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
if (vkCreateImage(device, &imageInfo, nullptr, &tftextureImage) != VK_SUCCESS) {
throw std::runtime_error("failed to create image!");
}
The code give me always the runtime error "failed to create image", I tried to change some things like the format, the extent, etc but I can't solve it.
I believe that the mistake is only in the imageInfo part because the first one run ok.

Replacement for deprecated NXOpenEventStatus?

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.

Contact Test Bit Mask not working proper

contactTestBitMask works in general but if the graphic is too complex contactTestBitMask freaks out and you have only a small contact area or get weird errors. What can i do there?
This is an image about my area:
class GameScene: SKScene, SKPhysicsContactDelegate {
let WallCategory : UInt32 = 0x1 << 1
let ShipCategory : UInt32 = 0x1 << 2
var counter = 0
var userCanBuild1Building = false
var KameraSichtVar:SKCameraNode = SKCameraNode()
var touched:Bool = false
var startTouch = CGPointMake(0, 0)
//------------------------------
var draufgeklickt:CGPoint = CGPoint()
var draufgeklicktUpdate:CGPoint = CGPoint()
var userWantScroll = false
var userWantBuild = false
let wohnhausBlue = SKSpriteNode(imageNamed:"wohnhausBlue")
let buildMenu = SKSpriteNode(imageNamed:"Buildmenu")
var hitDetected = false
let actualBuilding = SKSpriteNode()
var userWantUpgrade : Bool = false
//var theBuildingBefore = SKSpriteNode()
//var houseLvlSave : Int = 0
var uphausSave : String = ""
func didBeginContact(contact: SKPhysicsContact) {
var BuildingObject: SKPhysicsBody
var ClickObject: SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask
{
BuildingObject = contact.bodyA
ClickObject = contact.bodyB
}
else
{
BuildingObject = contact.bodyB
ClickObject = contact.bodyA
}
// upgrade Building
let name = BuildingObject.node!.name
let HouseLvL: Int = Int(name!)!
if HouseLvL > 0 && userCanBuild1Building == true{
userCanBuild1Building = false
let touchedBuilding = SKSpriteNode(imageNamed: BuildingObject.node!.name!)
touchedBuilding.name = BuildingObject.node!.name
let name = BuildingObject.node!.name
var HouseLvL: Int = Int(name!)!
HouseLvL = HouseLvL + 1
let uphaus = String(HouseLvL)
let setSpriteTexture = SKAction.setTexture(SKTexture(imageNamed: uphaus))
let upSize = SKSpriteNode(imageNamed: uphaus)
let resizeHousewidth = SKAction.resizeToWidth(upSize.size.width, duration: 0)
let resizeHouseheight = SKAction.resizeToHeight(upSize.size.height, duration: 0)
touchedBuilding.runAction(resizeHousewidth)
touchedBuilding.runAction(resizeHouseheight)
touchedBuilding.runAction(setSpriteTexture)
touchedBuilding.name = "\(uphaus)"
touchedBuilding.position = BuildingObject.node!.position
touchedBuilding.zPosition = BuildingObject.node!.zPosition
touchedBuilding.userInteractionEnabled = false
let upgradedbuilding = SKSpriteNode(imageNamed: uphaus)
touchedBuilding.size = CGSizeMake(upgradedbuilding.size.width, upgradedbuilding.size.height)
touchedBuilding.physicsBody = SKPhysicsBody(texture: SKTexture(imageNamed:"\(uphaus)"), size: upgradedbuilding.size)
touchedBuilding.physicsBody?.categoryBitMask = WallCategory
touchedBuilding.physicsBody?.affectedByGravity = false
touchedBuilding.physicsBody?.dynamic = true
touchedBuilding.physicsBody?.collisionBitMask = 0
addChild(touchedBuilding)
BuildingObject.node?.removeFromParent()
ClickObject.node?.removeFromParent()
}
if HouseLvL == 0
{
ClickObject.node?.removeFromParent()
}
}`override func didMoveToView(view: SKView) {
/* Setup your scene here */
if let KameraSicht:SKCameraNode = self.childNodeWithName("Kamera") as? SKCameraNode{
KameraSichtVar = KameraSicht
self.camera = KameraSichtVar
}
physicsWorld.contactDelegate = self
self.physicsWorld.gravity = CGVectorMake(0, 0)
func addBG(){
let background = SKSpriteNode(imageNamed: "0")
background.name = "0"
background.anchorPoint = CGPointMake(0.5, 0.5)
background.zPosition = 2
background.position = CGPointMake(CGRectGetMinX(self.frame)+self.frame.width/4, CGRectGetMaxY(self.frame)-self.frame.height/4)
background.physicsBody = SKPhysicsBody(texture: SKTexture(imageNamed: "0"), size: background.size)
//background.physicsBody = SKPhysicsBody(rectangleOfSize: background.size)
background.physicsBody?.categoryBitMask = WallCategory
background.physicsBody?.affectedByGravity = false
background.physicsBody?.dynamic = true
background.physicsBody?.collisionBitMask = 0
self.addChild(background)
}
addBG()
let wall = SKSpriteNode(imageNamed:"1" )
wall.name = "1"
wall.zPosition = 10
//wall.xScale = 3
//wall.yScale = 3
wall.size = CGSizeMake(100, 100)
wall.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
wall.physicsBody = SKPhysicsBody(texture: SKTexture(imageNamed: wall.name!), size: wall.size)
//wall.physicsBody = SKPhysicsBody(rectangleOfSize: wall.size)
wall.physicsBody?.affectedByGravity = false
wall.physicsBody?.dynamic = false
wall.physicsBody!.categoryBitMask = WallCategory
wall.physicsBody?.collisionBitMask = 0
self.addChild(wall)
}
`
ok i found the solution. the problem was the weird behavior of the contactTestBitMask when you use this graphic.(it only detected a contact in a small area of the graphic). the reason for that is that the graphic have separated shapes (like the half ring and some other small stuff).
i connected all shape so that its only one shape and now everything works perfectly fine. also tried it with some other graphics and the behavior of contactTestBitMask is: if you have separated shapes in your graphic, contactTestBitMask take exactly one of the shapes and make it the contact area ...but the other shapes in your graphic will not detect a contact then...

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];