Skip to content
This repository has been archived by the owner on Aug 7, 2019. It is now read-only.

Adds HTTPHeaders for playing from http source #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Xcode
.DS_Store
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
profile
*.moved-aside
DerivedData
.idea/

Pods/

*.xccheckout
Podfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions OrigamiEngine/ORGMCommonProtocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ typedef enum : NSInteger {
*/
- (BOOL)open:(NSURL *)url;

/**
Opens source file for `read`.

@param url A source file url.
@param httpHeaders A dictionary representing HTTP header fields and values

@return `YES` if success, otherwise `NO`.
*/
- (BOOL)open:(NSURL *)url
httpHeaders:(NSDictionary *)httpHeaders;

/**
Determines if source is seekable.

Expand Down
19 changes: 19 additions & 0 deletions OrigamiEngine/ORGMEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ typedef enum : NSInteger {
*/
- (void)playUrl:(NSURL *)url;

/**
Starts new playback process from corresponding source.

@param url The url object to be used as a source path during playback.
@param httpHeaders A dictionary representing HTTP header fields and values

*/
- (void)playUrl:(NSURL *)url httpHeaders:(NSDictionary *)httpHeaders;

/**
Starts new playback process from corresponding source.

@param url The url object to be used as a source path during playback.
@param httpHeaders A dictionary representing HTTP header fields and values
@param outputUnitClass Class that will be used during output unit initialisation. Must be subclass of ORGMOutputUnit.

*/
- (void)playUrl:(NSURL *)url httpHeaders:(NSDictionary *)httpHeaders withOutputUnitClass:(Class)outputUnitClass;

/**
Pauses the playback.

Expand Down
21 changes: 16 additions & 5 deletions OrigamiEngine/ORGMEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ - (void)dealloc {

#pragma mark - public

- (void)playUrl:(NSURL *)url withOutputUnitClass:(Class)outputUnitClass {
- (void)playUrl:(NSURL *)url httpHeaders:(NSDictionary *)httpHeaders withOutputUnitClass:(Class)outputUnitClass
{
if (!outputUnitClass || ![outputUnitClass isSubclassOfClass:[ORGMOutputUnit class]]) {

@throw [NSException exceptionWithName:NSInternalInconsistencyException
Expand All @@ -77,7 +78,7 @@ - (void)playUrl:(NSURL *)url withOutputUnitClass:(Class)outputUnitClass {
self.input = input;
[input release];

if (![_input openWithUrl:url]) {
if (![_input openWithUrl:url httpHeaders:httpHeaders]) {
self.currentState = ORGMEngineStateError;
self.currentError = [NSError errorWithDomain:kErrorDomain
code:ORGMEngineErrorCodesSourceFailed
Expand Down Expand Up @@ -113,9 +114,19 @@ - (void)playUrl:(NSURL *)url withOutputUnitClass:(Class)outputUnitClass {
});
}

- (void)playUrl:(NSURL *)url {
- (void)playUrl:(NSURL *)url withOutputUnitClass:(Class)outputUnitClass
{
[self playUrl:url httpHeaders:nil withOutputUnitClass:outputUnitClass];
}

- (void)playUrl:(NSURL *)url httpHeaders:(NSDictionary *)httpHeaders
{
[self playUrl:url httpHeaders:httpHeaders withOutputUnitClass:[ORGMOutputUnit class]];
}

[self playUrl:url withOutputUnitClass:[ORGMOutputUnit class]];
- (void)playUrl:(NSURL *)url
{
[self playUrl:url httpHeaders:nil];
}

- (void)pause {
Expand Down Expand Up @@ -171,7 +182,7 @@ - (void)setNextUrl:(NSURL *)url withDataFlush:(BOOL)flush {
[self stop];
} else {
dispatch_async([ORGMQueues processing_queue], ^{
if (![_input openWithUrl:url]) {
if (![_input openWithUrl:url httpHeaders:nil]) {
[self stop];
}
[_converter reinitWithNewInput:_input withDataFlush:flush];
Expand Down
19 changes: 15 additions & 4 deletions OrigamiEngine/ORGMInputUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,25 @@
@property (assign, nonatomic, readonly) BOOL endOfInput;

/**
Open input source and initializes necessary resources.
Open input source and initializes necessary resources.

@param url A url object to be used as a source path during playback.
@param url A url object to be used as a source path during playback.

@return `YES` if success, otherwise `NO`.
*/
@return `YES` if success, otherwise `NO`.
*/
- (BOOL)openWithUrl:(NSURL *)url;

/**
Open input source and initializes necessary resources.

@param url A url object to be used as a source path during playback.
@param httpHeaders A dictionary representing HTTP header fields and values

@return `YES` if success, otherwise `NO`.
*/
- (BOOL)openWithUrl:(NSURL *)url
httpHeaders:(NSDictionary *)httpHeaders;

/**
Closes input unit and corresponding decoder, deallocates unnecessary resources.
*/
Expand Down
10 changes: 8 additions & 2 deletions OrigamiEngine/ORGMInputUnit.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ - (void)dealloc {

#pragma mark - public

- (BOOL)openWithUrl:(NSURL *)url {
- (BOOL)openWithUrl:(NSURL *)url httpHeaders:(NSDictionary *)httpHeaders
{
self.source = [[ORGMPluginManager sharedManager] sourceForURL:url error:nil];
if (!_source || ![_source open:url]) return NO;
if (!_source || ![_source open:url httpHeaders:httpHeaders]) return NO;
self.decoder = [[ORGMPluginManager sharedManager] decoderForSource:_source error:nil];
if (!_decoder || ![_decoder open:_source]) return NO;

Expand All @@ -75,6 +76,11 @@ - (BOOL)openWithUrl:(NSURL *)url {
return YES;
}

- (BOOL)openWithUrl:(NSURL *)url
{
return [self openWithUrl:url httpHeaders:nil];
}

- (void)close {
[_decoder close];
}
Expand Down
2 changes: 1 addition & 1 deletion OrigamiEngine/Plugins/CueSheetDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ - (BOOL)open:(id<ORGMSource>)s {
if ([track.track isEqualToString:[url fragment]]) {
self.source = [pluginManager sourceForURL:track.url error:nil];

if (![_source open:track.url]) {
if (![_source open:track.url httpHeaders:nil]) {
return NO;
}

Expand Down
10 changes: 9 additions & 1 deletion OrigamiEngine/Plugins/FileSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,20 @@ - (long)size {
return size;
}

- (BOOL)open:(NSURL *)url {
- (BOOL)open:(NSURL *)url
httpHeaders:(NSDictionary *)httpHeaders
{
[self setUrl:url];
_fd = fopen([[url path] UTF8String], "r");
return (_fd != NULL);
}

- (BOOL)open:(NSURL *)url
{
return [self open:url httpHeaders:nil];
}


- (BOOL)seekable {
return YES;
}
Expand Down
17 changes: 16 additions & 1 deletion OrigamiEngine/Plugins/HTTPSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,20 @@ - (long)size {
return (long)_bytesExpected;
}

- (BOOL)open:(NSURL *)url {
- (BOOL)open:(NSURL *)url httpHeaders:(NSDictionary *)httpHeaders
{
self.request = [NSMutableURLRequest requestWithURL:url];
[self.request addValue:@"identity" forHTTPHeaderField:@"Accept-Encoding"];

if(httpHeaders)
{
for (id headerField in httpHeaders)
{
[_request addValue:httpHeaders[headerField]
forHTTPHeaderField:headerField];
}
}

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:_request
delegate:self
startImmediately:NO];
Expand Down Expand Up @@ -97,6 +107,11 @@ - (BOOL)open:(NSURL *)url {
return YES;
}

- (BOOL)open:(NSURL *)url
{
return [self open:url httpHeaders:nil];
}

- (BOOL)seekable {
return YES;
}
Expand Down