Consolidate uses of Ebr file functions.#1175
Conversation
…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.
| auto result = [outputStream write:(const unsigned char*)[self bytes] maxLength:numBytes]; | ||
| [outputStream close]; | ||
|
|
||
| if (result != numBytes) { |
There was a problem hiding this comment.
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]; | ||
| } |
There was a problem hiding this comment.
I'm wary of introducing a copy here. #Pending
There was a problem hiding this comment.
At the very least, NSMutableData has mutableBytes, which you can write into up to .capacity.
In reply to: 83926383 [](ancestors = 83926383)
|
|
||
| while ([inputStream hasBytesAvailable]) { | ||
| auto result = [inputStream read:byteBuffer maxLength:_countof(byteBuffer)]; | ||
| [tempData appendBytes:byteBuffer length:result]; |
There was a problem hiding this comment.
[tempData appendBytes:byteBuffer length:result]; [](start = 8, length = 48)
Sorry, two copies. #Pending
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
options parameter not supported [](start = 8, length = 31)
seems like we are supporting a portion of it? #Resolved
There was a problem hiding this comment.
| 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]; |
There was a problem hiding this comment.
100 [](start = 62, length = 3)
I can't recall If I checked this, but does this match the reference platform? #WontFix
There was a problem hiding this comment.
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)
| return NO; | ||
| } | ||
| auto numBytes = [self length]; | ||
| auto result = [outputStream write:(const unsigned char*)[self bytes] maxLength:numBytes]; |
There was a problem hiding this comment.
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
| NSMutableData* tempData = [NSMutableData data]; | ||
|
|
||
| while ([inputStream hasBytesAvailable]) { | ||
| auto result = [inputStream read:byteBuffer maxLength:_countof(byteBuffer)]; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Whoever is looking at 116 2can make those determinations.
In reply to: 83928251 [](ancestors = 83928251)
| NSMutableData* tempData = [NSMutableData data]; | ||
|
|
||
| while ([inputStream hasBytesAvailable]) { | ||
| auto result = [inputStream read:byteBuffer maxLength:_countof(byteBuffer)]; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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] = {}; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
There was a problem hiding this comment.
a cast is needed somewhere so I put it here.
In reply to: 83964371 [](ancestors = 83964371,83959944)
| (id)kCGImagePropertyDPIWidth : [NSNumber numberWithDouble:1000], | ||
| (id)kCGImagePropertyDPIHeight : [NSNumber numberWithDouble:200], | ||
| (id) kCGImagePropertyOrientation : encodeOrientation, (id) | ||
| kCGImagePropertyGIFDictionary : gifOptions, (id) |
There was a problem hiding this comment.
nit: plenty of silly clang format changes in this file. #Resolved
| return self; | ||
| } | ||
|
|
||
| - (id)startLoading { |
There was a problem hiding this comment.
startLoading [](start = 6, length = 12)
This could potentially break something (anyone using this externally). #WontFix
There was a problem hiding this comment.
| */ | ||
|
|
||
| return theAnswer; | ||
| return; |
There was a problem hiding this comment.
return [](start = 4, length = 6)
nit: not needed. #WontFix
| } | ||
|
|
||
| Byte* CAFDecoder::GetBytes(EbrFile* fpIn, int len) { | ||
| Byte* CAFDecoder::GetBytes(NSInputStream* stream, int len) { |
There was a problem hiding this comment.
Changes to this file don't have much collateral, please be sure to validate internal apps. #Resolved
There was a problem hiding this comment.
|
|
|
@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? |
|
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. In reply to: 254903901 [](ancestors = 254903901) |
|
|
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.