-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faster Image Capture #2713
Closed
Closed
Faster Image Capture #2713
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
68297b5
Fast capture prototype.
f539dbf
Image capture is functional but needs optimization and cleanup.
57602f6
Improvements to image capture speedup
8c3a757
Cleaned up fast img capture, but it's less faster for some reason.
e899c94
remove comments for PR
205ae5b
Added buffer pool object and used for image capture. Increases speed …
33e73f8
Closer to fixing build issues
82dbb3e
Reinstate commented out DepthNav code
83a6004
Removed remaining build errors.
b245d5c
Replaced non-portable expression _CRT_SIZE_MAX
4a502b0
Restored height, width, and time_stamp data in image responses.
de9cf5b
Removed extraneous std:move() and made a portable bit strober to fix …
142f860
add image_benchmarker script
madratman 1f89018
[formatting] maintain whitespacing consistency with AirSim code
madratman 220ad4b
Rather than assume width is rounded up to power of two, pass the buff…
ironclownfish 03494a5
Get simGetImages working
9b74b56
A memcopy is necessary in RpcLibAdaptorsBase. A swap would send a siz…
0b94b8a
Compilation fixes
rajat2004 6d7f405
Fix camera name in benchmark script
rajat2004 d70f0e0
Merge branch 'master' of https://github.com/microsoft/AirSim into pr/…
rajat2004 6b16976
Fix compile error
rajat2004 4603bf3
Fix image width calculation
rajat2004 e85fee6
[Unreal] Use WriteOnly LockMode to avoid crash on Linux using Vulkan
rajat2004 b5f79e5
Make no. of channles depend on image, allows it to be used on both PR…
rajat2004 92c977c
Revert "[Unreal] Use WriteOnly LockMode to avoid crash on Linux using…
rajat2004 d572411
Updated benchmark script, add save_images option
rajat2004 3de9156
[Unreal] Disable camera after capturing image
rajat2004 41dcd84
[Pythonclient] Add high resolution camera benchmark script
rajat2004 6612ea4
restore BP_FlyingPawn.uasset, fixes to benchmarking script
madratman 0391272
Add image_type option to benchmark script
rajat2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
#include <vector> | ||
#include <map> | ||
#include <memory> | ||
#include <unordered_set> | ||
#include <functional> | ||
#include <limits> | ||
|
||
typedef std::vector<uint8_t> Buffer; | ||
typedef std::function<void(Buffer*)> Deleter; | ||
typedef std::unique_ptr<Buffer, Deleter> BufferPtr; | ||
|
||
class BufferPool | ||
{ | ||
public: | ||
BufferPtr GetBufferExactSize(size_t size); | ||
BufferPtr GetBufferAtLeastSize(size_t size, size_t max_size = std::numeric_limits<size_t>::max()); | ||
|
||
private: | ||
class BufferCollection | ||
{ | ||
public: | ||
BufferCollection(size_t size) : Size(size) {} | ||
BufferPtr DemandBuffer(); | ||
BufferPtr GetBufferIfAvailable(); | ||
|
||
private: | ||
size_t Size; | ||
std::unordered_set<Buffer*> AvailableBuffers; | ||
BufferPtr MakeBufferPtr(Buffer *underlyingBuffer = nullptr); | ||
void ReturnToCollection(Buffer *buffer); | ||
}; | ||
std::map<size_t, BufferCollection> CollectionsBySize; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#include "common/common_utils/BufferPool.h" | ||
|
||
BufferPtr BufferPool::GetBufferExactSize(size_t size) | ||
{ | ||
if (CollectionsBySize.count(size) == 0) | ||
CollectionsBySize.insert(std::pair<size_t, BufferCollection>(size, BufferCollection(size))); | ||
|
||
return CollectionsBySize.at(size).DemandBuffer(); | ||
} | ||
|
||
BufferPtr BufferPool::GetBufferAtLeastSize(size_t size, size_t max_size) | ||
{ | ||
BufferPtr buffer = nullptr; | ||
auto closestOffering = CollectionsBySize.lower_bound(size); | ||
if (closestOffering != CollectionsBySize.end() && closestOffering->first < max_size) | ||
buffer = closestOffering->second.GetBufferIfAvailable(); | ||
|
||
if (buffer != nullptr) | ||
return buffer; | ||
return GetBufferExactSize(size); | ||
} | ||
|
||
BufferPtr BufferPool::BufferCollection::DemandBuffer() | ||
{ | ||
BufferPtr buf = GetBufferIfAvailable(); | ||
if (buf != nullptr) | ||
return buf; | ||
return MakeBufferPtr(); | ||
} | ||
|
||
BufferPtr BufferPool::BufferCollection::GetBufferIfAvailable() | ||
{ | ||
if (AvailableBuffers.size() == 0) | ||
return nullptr; | ||
|
||
Buffer *buffer = *AvailableBuffers.begin(); | ||
AvailableBuffers.erase(buffer); | ||
return MakeBufferPtr(buffer); | ||
} | ||
|
||
BufferPtr BufferPool::BufferCollection::MakeBufferPtr(Buffer *underlyingBuffer) | ||
{ | ||
if (underlyingBuffer == nullptr) | ||
return std::unique_ptr<Buffer, Deleter>(new Buffer(Size), std::bind(&BufferPool::BufferCollection::ReturnToCollection, this, std::placeholders::_1)); | ||
else | ||
return std::unique_ptr<Buffer, Deleter>(underlyingBuffer, std::bind(&BufferPool::BufferCollection::ReturnToCollection, this, std::placeholders::_1)); | ||
} | ||
|
||
void BufferPool::BufferCollection::ReturnToCollection(Buffer *buffer) | ||
{ | ||
AvailableBuffers.insert(buffer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should probably be a destructor defined for this class to avoid memory leaks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very sure about this, will need to think more and check if memory leak is happening
If destructor is defined, then copy constructor, assignment might also be required, atleast from what I understand
Any pointers, suggestions and discussions on this would be great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct me if I'm wrong, but I believe a memory leak will occur since we are allocating Buffers using
new
but the buffers are neverdelete
d. We make unique_ptrs using the allocated buffers, but we use a custom deleter so they aren't deleted. This isn't really a problem at the moment since a single static BufferPool is being used, but it could be an issue in the future if someone uses more BufferPool objects. The destructor should probably delete the pointers in AvailableBuffers so that that memory is freed. I think it would probably make sense to delete the copy constructor and assignment operator, since it doesn't really make sense to copy this kind of object.Thanks again :)