Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Consolidate uses of Ebr file functions.#1175

Merged
bbowman merged 9 commits into
microsoft:developfrom
bbowman:bbowman/NSStreamConsolidation
Oct 19, 2016
Merged

Consolidate uses of Ebr file functions.#1175
bbowman merged 9 commits into
microsoft:developfrom
bbowman:bbowman/NSStreamConsolidation

Conversation

@bbowman

@bbowman bbowman commented Oct 18, 2016

Copy link
Copy Markdown
Member

Consolidate uses of Ebr file functions to only where absolutely needed. This helps abstract any weird semantics we have to only a few locations and uses well defined APIs for foundation constructs like NSData and NSStream where possible.

…d. This helps

abstract any weird semantics we have to only a few locations and uses well defined
APIs for foundation constructs like NSData and NSStream where possible.
Comment thread Frameworks/Foundation/NSData.mm Outdated
auto result = [outputStream write:(const unsigned char*)[self bytes] maxLength:numBytes];
[outputStream close];

if (result != numBytes) {

@DHowett-MSFT DHowett-MSFT Oct 18, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numBytes [](start = 18, length = 8)

Only -1 is an error. 0 < numBytes <= maxBytes is legal and should be retried to consume the rest of the buffer. #Resolved

}

return [self initWithData:tempData];
}

@DHowett-MSFT DHowett-MSFT Oct 18, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wary of introducing a copy here. #Pending

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the very least, NSMutableData has mutableBytes, which you can write into up to .capacity.


In reply to: 83926383 [](ancestors = 83926383)

Comment thread Frameworks/Foundation/NSData.mm Outdated

while ([inputStream hasBytesAvailable]) {
auto result = [inputStream read:byteBuffer maxLength:_countof(byteBuffer)];
[tempData appendBytes:byteBuffer length:result];

@DHowett-MSFT DHowett-MSFT Oct 18, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[tempData appendBytes:byteBuffer length:result]; [](start = 8, length = 48)

Sorry, two copies. #Pending

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my other response to JJ. Its not quite as bad as you make it out to be and any other solution is potientially more error prone. I will keep looking at other solutions though.


In reply to: 83926449 [](ancestors = 83926449)


/**
@Status Caveat
@Notes options parameter not supported

@msft-Jeyaram msft-Jeyaram Oct 18, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options parameter not supported [](start = 8, length = 31)

seems like we are supporting a portion of it? #Resolved

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update the comment but its still caveat.


In reply to: 83927091 [](ancestors = 83927091)

TraceVerbose(TAG, L"-[NSData::writeToURL]: Only file: URLs are supported. (%hs)", [[url absoluteString] UTF8String]);
if (!url) {
if (errorp) {
*errorp = [NSError errorWithDomain:@"NSData" code:100 userInfo:nil];

@msft-Jeyaram msft-Jeyaram Oct 18, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 [](start = 62, length = 3)

I can't recall If I checked this, but does this match the reference platform? #WontFix

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from the file one now that file forwards to URL. Not the purpose of this pr to validate our error codes.


In reply to: 83927171 [](ancestors = 83927171)

Comment thread Frameworks/Foundation/NSData.mm Outdated
return NO;
}
auto numBytes = [self length];
auto result = [outputStream write:(const unsigned char*)[self bytes] maxLength:numBytes];

@msft-Jeyaram msft-Jeyaram Oct 18, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result = [outputStream write:(const unsigned char*)[self bytes] maxLength:numBytes]; [](start = 8, length = 85)

we might not write the whole buffer, we need to check if we have any left over and write the rest?
I recall similar code existing already. #Resolved

Comment thread Frameworks/Foundation/NSData.mm Outdated
NSMutableData* tempData = [NSMutableData data];

while ([inputStream hasBytesAvailable]) {
auto result = [inputStream read:byteBuffer maxLength:_countof(byteBuffer)];

@msft-Jeyaram msft-Jeyaram Oct 18, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result [](start = 13, length = 6)

check for failure condition (-1)? #Pending

TraceVerbose(TAG, L"Opened %hs", pFilePath);
}
// TODO 1162: An NSInputStream should be initialized here and run loop events should be used to schedule
// the file operations.

@DHowett-MSFT DHowett-MSFT Oct 18, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I certainly hope NSURLConnection is up to the task. As well, I wonder if the reference platform short-circuits file URL handling.

It is fully possible to load a file from a file URL without spinning a run loop inbetween. #WontFix

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoever is looking at 116 2can make those determinations.


In reply to: 83928251 [](ancestors = 83928251)

Comment thread Frameworks/Foundation/NSData.mm Outdated
NSMutableData* tempData = [NSMutableData data];

while ([inputStream hasBytesAvailable]) {
auto result = [inputStream read:byteBuffer maxLength:_countof(byteBuffer)];

@msft-Jeyaram msft-Jeyaram Oct 18, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byteBuffer [](start = 40, length = 10)

you can just get the mutableBytes of the NSMutableData and read into it directly (would help you avoid the copy)
If you need to grow the capacity, you can do it via increaseLength #Pending

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

increaseLength isn't really desirable here. Ideally I'd be able to read the chunks directly in and return the same data. If the length is wrong I can't return that data and need to manually reconstruct it with the right length that I keep track of. appendBytes is morally equivalent of what you are suggesting but it adjusts the capacity instead of length at the expense of the temp buffer (which is only allocated once and is stack space so its "cheap" in the grand scheme of things). Basically this is letting the NSData append impl be smart about growth etc which seems better than me trying to be smart (since I'm not very). I'll look for other ways to avoid extra copies though.


In reply to: 83929862 [](ancestors = 83929862)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, in this context, append is appropriate (but just thought I would surface that).


In reply to: 83930789 [](ancestors = 83930789,83929862)

getSizeFunc:getSizeFunc
setSizeFunc:setSizeFunc];
[in open];
char header[4] = {};

@rajsesh rajsesh Oct 18, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char [](start = 4, length = 4)

nit: this could be uint8_t to avoid casts. It is unsigned char, so the other apis should work? #Closed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hilariously no because of the use of strncmp


In reply to: 83959944 [](ancestors = 83959944)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a cast is needed somewhere so I put it here.


In reply to: 83964371 [](ancestors = 83964371,83959944)

Comment thread tests/unittests/ImageIO/ImageIOTest.mm Outdated
(id)kCGImagePropertyDPIWidth : [NSNumber numberWithDouble:1000],
(id)kCGImagePropertyDPIHeight : [NSNumber numberWithDouble:200],
(id) kCGImagePropertyOrientation : encodeOrientation, (id)
kCGImagePropertyGIFDictionary : gifOptions, (id)

@rajsesh rajsesh Oct 18, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: plenty of silly clang format changes in this file. #Resolved

return self;
}

- (id)startLoading {

@rajsesh rajsesh Oct 18, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

startLoading [](start = 6, length = 12)

This could potentially break something (anyone using this externally). #WontFix

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no functional change.


In reply to: 83974374 [](ancestors = 83974374)

*/

return theAnswer;
return;

@rajsesh rajsesh Oct 18, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return [](start = 4, length = 6)

nit: not needed. #WontFix

}

Byte* CAFDecoder::GetBytes(EbrFile* fpIn, int len) {
Byte* CAFDecoder::GetBytes(NSInputStream* stream, int len) {

@rajsesh rajsesh Oct 18, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to this file don't have much collateral, please be sure to validate internal apps. #Resolved

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validated.


In reply to: 83975337 [](ancestors = 83975337)

@rajsesh

rajsesh commented Oct 18, 2016

Copy link
Copy Markdown
Contributor

:shipit:

@bbowman

bbowman commented Oct 19, 2016

Copy link
Copy Markdown
Member Author

@DHowett-MSFT @msft-Jeyaram My full build passed and it seems like CAF audio is not broken. huzzah. Any other comments before I go go?

@DHowett-MSFT

Copy link
Copy Markdown

I'm not 100% stoked about the foundation dep in AudioToolbox, but I understand that we already had one (IIRC) and it's fairly harmless to replace if we do decide to set up a boundary.
LGTM!


In reply to: 254903901 [](ancestors = 254903901)

@DHowett-MSFT

Copy link
Copy Markdown

:shipit:

@bbowman bbowman merged commit be78bef into microsoft:develop Oct 19, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants