Debugging: Implement buffer chain logging code
This optional code, disabled at compile time by default, allows finding weird issues with the sample decoding chain. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
b631cf803e
commit
001f3e53ea
4 changed files with 98 additions and 0 deletions
|
@ -67,6 +67,10 @@ static void *kConverterNodeContext = &kConverterNodeContext;
|
||||||
extrapolateBufferSize = 0;
|
extrapolateBufferSize = 0;
|
||||||
|
|
||||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.volumeScaling" options:0 context:kConverterNodeContext];
|
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.volumeScaling" options:0 context:kConverterNodeContext];
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
[self initLogFiles];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
|
@ -38,6 +38,10 @@
|
||||||
inMerge = NO;
|
inMerge = NO;
|
||||||
|
|
||||||
[self setPreviousNode:p];
|
[self setPreviousNode:p];
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
[self initLogFiles];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#define BUFFER_SIZE 1024 * 1024
|
#define BUFFER_SIZE 1024 * 1024
|
||||||
#define CHUNK_SIZE 16 * 1024
|
#define CHUNK_SIZE 16 * 1024
|
||||||
|
|
||||||
|
//#define LOG_CHAINS 1
|
||||||
|
|
||||||
@interface Node : NSObject {
|
@interface Node : NSObject {
|
||||||
ChunkList *buffer;
|
ChunkList *buffer;
|
||||||
Semaphore *writeSemaphore;
|
Semaphore *writeSemaphore;
|
||||||
|
@ -41,9 +43,18 @@
|
||||||
BOOL nodeLossless;
|
BOOL nodeLossless;
|
||||||
|
|
||||||
double durationPrebuffer;
|
double durationPrebuffer;
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
NSFileHandle *logFileOut;
|
||||||
|
NSFileHandle *logFileIn;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
- (id _Nullable)initWithController:(id _Nonnull)c previous:(id _Nullable)p;
|
- (id _Nullable)initWithController:(id _Nonnull)c previous:(id _Nullable)p;
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
- (void)initLogFiles;
|
||||||
|
#endif
|
||||||
|
|
||||||
- (void)cleanUp;
|
- (void)cleanUp;
|
||||||
|
|
||||||
- (BOOL)paused;
|
- (BOOL)paused;
|
||||||
|
|
|
@ -17,8 +17,33 @@
|
||||||
|
|
||||||
#import <mach/mach_time.h>
|
#import <mach/mach_time.h>
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
#import "NSFileHandle+CreateFile.h"
|
||||||
|
|
||||||
|
static NSLock * _Node_lock = nil;
|
||||||
|
static uint64_t _Node_serial;
|
||||||
|
#endif
|
||||||
|
|
||||||
@implementation Node
|
@implementation Node
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
+ (void)initialize {
|
||||||
|
@synchronized (_Node_lock) {
|
||||||
|
if(!_Node_lock) {
|
||||||
|
_Node_lock = [[NSLock alloc] init];
|
||||||
|
_Node_serial = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)initLogFiles {
|
||||||
|
[_Node_lock lock];
|
||||||
|
logFileOut = [NSFileHandle fileHandleForWritingAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_output_%08lld.raw", [self className], _Node_serial++]] createFile:YES];
|
||||||
|
logFileIn = [NSFileHandle fileHandleForWritingAtPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_input_%08lld.raw", [self className], _Node_serial++]] createFile:YES];
|
||||||
|
[_Node_lock unlock];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
- (id)initWithController:(id)c previous:(id)p {
|
- (id)initWithController:(id)c previous:(id)p {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if(self) {
|
if(self) {
|
||||||
|
@ -45,6 +70,10 @@
|
||||||
inMerge = NO;
|
inMerge = NO;
|
||||||
|
|
||||||
[self setPreviousNode:p];
|
[self setPreviousNode:p];
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
[self initLogFiles];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -94,6 +123,12 @@
|
||||||
[chunk setLossless:nodeLossless];
|
[chunk setLossless:nodeLossless];
|
||||||
[chunk assignSamples:ptr frameCount:amount / nodeFormat.mBytesPerPacket];
|
[chunk assignSamples:ptr frameCount:amount / nodeFormat.mBytesPerPacket];
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
if(logFileOut) {
|
||||||
|
[logFileOut writeData:[NSData dataWithBytes:ptr length:amount]];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
double durationList = [buffer listDuration];
|
double durationList = [buffer listDuration];
|
||||||
double durationLeft = [buffer maxDuration] - durationList;
|
double durationLeft = [buffer maxDuration] - durationList;
|
||||||
|
|
||||||
|
@ -167,6 +202,14 @@
|
||||||
|
|
||||||
BOOL doSignal = NO;
|
BOOL doSignal = NO;
|
||||||
if([chunk frameCount]) {
|
if([chunk frameCount]) {
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
if(logFileOut) {
|
||||||
|
AudioChunk *chunkCopy = [chunk copy];
|
||||||
|
size_t frameCount = [chunkCopy frameCount];
|
||||||
|
NSData *chunkData = [chunkCopy removeSamples:frameCount];
|
||||||
|
[logFileOut writeData:chunkData];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
[buffer addChunk:chunk];
|
[buffer addChunk:chunk];
|
||||||
doSignal = YES;
|
doSignal = YES;
|
||||||
}
|
}
|
||||||
|
@ -324,6 +367,15 @@
|
||||||
[[previousNode writeSemaphore] signal];
|
[[previousNode writeSemaphore] signal];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
if(logFileIn) {
|
||||||
|
AudioChunk *chunkCopy = [ret copy];
|
||||||
|
size_t frameCount = [chunkCopy frameCount];
|
||||||
|
NSData *chunkData = [chunkCopy removeSamples:frameCount];
|
||||||
|
[logFileIn writeData:chunkData];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
inRead = NO;
|
inRead = NO;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -385,6 +437,15 @@
|
||||||
[[previousNode writeSemaphore] signal];
|
[[previousNode writeSemaphore] signal];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
if(logFileIn) {
|
||||||
|
AudioChunk *chunkCopy = [ret copy];
|
||||||
|
size_t frameCount = [chunkCopy frameCount];
|
||||||
|
NSData *chunkData = [chunkCopy removeSamples:frameCount];
|
||||||
|
[logFileIn writeData:chunkData];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
inRead = NO;
|
inRead = NO;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -432,6 +493,15 @@
|
||||||
|
|
||||||
if([ret frameCount]) {
|
if([ret frameCount]) {
|
||||||
[[previousNode writeSemaphore] signal];
|
[[previousNode writeSemaphore] signal];
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
if(logFileIn) {
|
||||||
|
AudioChunk *chunkCopy = [ret copy];
|
||||||
|
size_t frameCount = [chunkCopy frameCount];
|
||||||
|
NSData *chunkData = [chunkCopy removeSamples:frameCount];
|
||||||
|
[logFileIn writeData:chunkData];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inMerge = NO;
|
inMerge = NO;
|
||||||
|
@ -481,6 +551,15 @@
|
||||||
|
|
||||||
if([ret frameCount]) {
|
if([ret frameCount]) {
|
||||||
[[previousNode writeSemaphore] signal];
|
[[previousNode writeSemaphore] signal];
|
||||||
|
|
||||||
|
#ifdef LOG_CHAINS
|
||||||
|
if(logFileIn) {
|
||||||
|
AudioChunk *chunkCopy = [ret copy];
|
||||||
|
size_t frameCount = [chunkCopy frameCount];
|
||||||
|
NSData *chunkData = [chunkCopy removeSamples:frameCount];
|
||||||
|
[logFileIn writeData:chunkData];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inMerge = NO;
|
inMerge = NO;
|
||||||
|
|
Loading…
Reference in a new issue