Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor local file playback to allow different audio decoders. Add e…

…mpty FLACDecoderWorker.
  • Loading branch information...
commit 183a7b8ec3dd73d805cd3e01ab970d858b472e87 1 parent 3566f94
@iKenndac authored
View
32 Viva.xcodeproj/project.pbxproj
@@ -188,12 +188,13 @@
50E3F772133FD32A00FF4618 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50E3F771133FD32A00FF4618 /* MainWindow.xib */; };
50E3F779133FD95200FF4618 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50E3F778133FD95200FF4618 /* Security.framework */; };
50E819CF133926A3000CE44D /* SPBackgroundColorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 50E819CE133926A3000CE44D /* SPBackgroundColorView.m */; };
+ 50EC2B6814DC0175009C5C69 /* VivaFLACDecoderWorker.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EC2B6714DC0175009C5C69 /* VivaFLACDecoderWorker.m */; };
50FC8A891473CD6200FA43DD /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50FC8A881473CD6200FA43DD /* CoreMedia.framework */; };
50FC8A951473D5A000FA43DD /* LocalFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 50FC8A941473D5A000FA43DD /* LocalFile.m */; };
50FC8A981473D5A000FA43DD /* LocalFileSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 50FC8A971473D5A000FA43DD /* LocalFileSource.m */; };
50FC8A9B1474009A00FA43DD /* VivaLocalFileDecoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 50FC8A9A1474009A00FA43DD /* VivaLocalFileDecoder.m */; };
50FC8A9D1474030800FA43DD /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50FC8A9C1474030800FA43DD /* AudioToolbox.framework */; };
- 50FC8AA014742CB100FA43DD /* VivaLocalFileDecoderWorker.m in Sources */ = {isa = PBXBuildFile; fileRef = 50FC8A9F14742CB100FA43DD /* VivaLocalFileDecoderWorker.m */; };
+ 50FC8AA014742CB100FA43DD /* VivaAVAssetDecoderWorker.m in Sources */ = {isa = PBXBuildFile; fileRef = 50FC8A9F14742CB100FA43DD /* VivaAVAssetDecoderWorker.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -558,6 +559,9 @@
50E3F778133FD95200FF4618 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
50E819CD133926A3000CE44D /* SPBackgroundColorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPBackgroundColorView.h; path = "Custom Controls/SPBackgroundColorView.h"; sourceTree = "<group>"; };
50E819CE133926A3000CE44D /* SPBackgroundColorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SPBackgroundColorView.m; path = "Custom Controls/SPBackgroundColorView.m"; sourceTree = "<group>"; };
+ 50EC2B6614DC0175009C5C69 /* VivaFLACDecoderWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VivaFLACDecoderWorker.h; sourceTree = "<group>"; };
+ 50EC2B6714DC0175009C5C69 /* VivaFLACDecoderWorker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VivaFLACDecoderWorker.m; sourceTree = "<group>"; };
+ 50EC2B8714DC0320009C5C69 /* VivaLocalFileDecoderWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VivaLocalFileDecoderWorker.h; sourceTree = "<group>"; };
50FC8A881473CD6200FA43DD /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; };
50FC8A931473D5A000FA43DD /* LocalFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalFile.h; sourceTree = "<group>"; };
50FC8A941473D5A000FA43DD /* LocalFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalFile.m; sourceTree = "<group>"; };
@@ -566,8 +570,8 @@
50FC8A991474009A00FA43DD /* VivaLocalFileDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VivaLocalFileDecoder.h; sourceTree = "<group>"; };
50FC8A9A1474009A00FA43DD /* VivaLocalFileDecoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VivaLocalFileDecoder.m; sourceTree = "<group>"; };
50FC8A9C1474030800FA43DD /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
- 50FC8A9E14742CB000FA43DD /* VivaLocalFileDecoderWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VivaLocalFileDecoderWorker.h; sourceTree = "<group>"; };
- 50FC8A9F14742CB100FA43DD /* VivaLocalFileDecoderWorker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VivaLocalFileDecoderWorker.m; sourceTree = "<group>"; };
+ 50FC8A9E14742CB000FA43DD /* VivaAVAssetDecoderWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VivaAVAssetDecoderWorker.h; sourceTree = "<group>"; };
+ 50FC8A9F14742CB100FA43DD /* VivaAVAssetDecoderWorker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VivaAVAssetDecoderWorker.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -621,10 +625,7 @@
506F347713438755002BA308 /* VivaPlaybackManager.m */,
50B4774C1462C8B300B04A51 /* SPCircularBuffer.h */,
50B4774D1462C8B300B04A51 /* SPCircularBuffer.m */,
- 50FC8A991474009A00FA43DD /* VivaLocalFileDecoder.h */,
- 50FC8A9A1474009A00FA43DD /* VivaLocalFileDecoder.m */,
- 50FC8A9E14742CB000FA43DD /* VivaLocalFileDecoderWorker.h */,
- 50FC8A9F14742CB100FA43DD /* VivaLocalFileDecoderWorker.m */,
+ 50EC2B8814DC04A7009C5C69 /* Local Files */,
);
name = Playback;
sourceTree = "<group>";
@@ -1278,6 +1279,20 @@
name = "Login Window";
sourceTree = "<group>";
};
+ 50EC2B8814DC04A7009C5C69 /* Local Files */ = {
+ isa = PBXGroup;
+ children = (
+ 50FC8A991474009A00FA43DD /* VivaLocalFileDecoder.h */,
+ 50FC8A9A1474009A00FA43DD /* VivaLocalFileDecoder.m */,
+ 50EC2B8714DC0320009C5C69 /* VivaLocalFileDecoderWorker.h */,
+ 50FC8A9E14742CB000FA43DD /* VivaAVAssetDecoderWorker.h */,
+ 50FC8A9F14742CB100FA43DD /* VivaAVAssetDecoderWorker.m */,
+ 50EC2B6614DC0175009C5C69 /* VivaFLACDecoderWorker.h */,
+ 50EC2B6714DC0175009C5C69 /* VivaFLACDecoderWorker.m */,
+ );
+ name = "Local Files";
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -1641,7 +1656,7 @@
50FC8A951473D5A000FA43DD /* LocalFile.m in Sources */,
50FC8A981473D5A000FA43DD /* LocalFileSource.m in Sources */,
50FC8A9B1474009A00FA43DD /* VivaLocalFileDecoder.m in Sources */,
- 50FC8AA014742CB100FA43DD /* VivaLocalFileDecoderWorker.m in Sources */,
+ 50FC8AA014742CB100FA43DD /* VivaAVAssetDecoderWorker.m in Sources */,
50DC12ED1487ABD300F030FC /* SPNowPlayingCoverView.m in Sources */,
50439AD8148B847D0059B578 /* LibraryViewController.m in Sources */,
50439AEA148B99A20059B578 /* VivaAlbumIKImageViewProxy.m in Sources */,
@@ -1653,6 +1668,7 @@
50A241E514C5AC1000949DB7 /* SPArrayExtensions.m in Sources */,
50A241E814C5AC1E00949DB7 /* NSObject+Spotify.mm in Sources */,
50A241EB14C5AC3900949DB7 /* SPMediaKeyTap.m in Sources */,
+ 50EC2B6814DC0175009C5C69 /* VivaFLACDecoderWorker.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
14 Viva/VivaAVAssetDecoderWorker.h
@@ -0,0 +1,14 @@
+//
+// VivaLocalFileDecoderWorker.h
+// Viva
+//
+// Created by Daniel Kennett on 16/11/2011.
+// For license information, see LICENSE.markdown
+//
+
+#import <Foundation/Foundation.h>
+#import "VivaLocalFileDecoderWorker.h"
+
+@interface VivaAVAssetDecoderWorker : NSObject <VivaLocalFileDecoderWorker>
+
+@end
View
9 Viva/VivaLocalFileDecoderWorker.m → Viva/VivaAVAssetDecoderWorker.m
@@ -6,15 +6,18 @@
// For license information, see LICENSE.markdown
//
-#import "VivaLocalFileDecoderWorker.h"
+#import "VivaAVAssetDecoderWorker.h"
+#import <AVFoundation/AVFoundation.h>
-@implementation VivaLocalFileDecoderWorker
+@implementation VivaAVAssetDecoderWorker
@synthesize delegate;
@synthesize cancelled;
@synthesize playing;
--(void)decodeAsset:(AVAsset *)asset fromPosition:(NSTimeInterval)startTime {
+-(void)decodeLocalFile:(LocalFile *)file fromPosition:(NSTimeInterval)startTime {
+
+ AVAsset *asset = [AVAsset assetWithURL:[NSURL fileURLWithPath:file.path]];
[self performSelectorInBackground:@selector(decodeAssetOnThreadWithProperties:)
withObject:[NSDictionary dictionaryWithObjectsAndKeys:
View
13 Viva/VivaFLACDecoderWorker.h
@@ -0,0 +1,13 @@
+//
+// VivaFLACDecoder.h
+// Viva
+//
+// Created by Daniel Kennett on 03/02/2012.
+// For license information, see LICENSE.markdown
+//
+
+#import <Foundation/Foundation.h>
+
+@interface VivaFLACDecoderWorker : NSObject
+
+@end
View
13 Viva/VivaFLACDecoderWorker.m
@@ -0,0 +1,13 @@
+//
+// VivaFLACDecoder.m
+// Viva
+//
+// Created by Daniel Kennett on 03/02/2012.
+// For license information, see LICENSE.markdown
+//
+
+#import "VivaFLACDecoderWorker.h"
+
+@implementation VivaFLACDecoderWorker
+
+@end
View
2  Viva/VivaLocalFileDecoder.h
@@ -12,7 +12,7 @@
#import <Foundation/Foundation.h>
#import <CocoaLibSpotify/CocoaLibSpotify.h>
-#import "VivaLocalFileDecoderWorker.h"
+#import "VivaAVAssetDecoderWorker.h"
@interface VivaLocalFileDecoder : NSObject <VivaLocalFileDecoderWorkerDelegate, SPSessionPlaybackProvider>
View
21 Viva/VivaLocalFileDecoder.m
@@ -10,13 +10,14 @@
#import <AVFoundation/AVFoundation.h>
#import "LocalFilesController.h"
#import "VivaTrackExtensions.h"
+#import "VivaAVAssetDecoderWorker.h"
@interface VivaLocalFileDecoder ()
@property (readwrite) BOOL cancelled;
-@property (readwrite, strong) VivaLocalFileDecoderWorker *currentWorker;
-@property (readwrite, strong) AVAsset *currentAsset;
+@property (readwrite, strong) id <VivaLocalFileDecoderWorker> currentWorker;
+@property (readwrite, strong) LocalFile *currentFile;
@end
@@ -48,7 +49,7 @@ -(void)dealloc {
@synthesize playbackDelegate;
@synthesize cancelled;
@synthesize currentWorker;
-@synthesize currentAsset;
+@synthesize currentFile;
@synthesize playing;
-(BOOL)preloadTrackForPlayback:(SPTrack *)aTrack error:(NSError **)error {
@@ -68,10 +69,10 @@ -(BOOL)playTrack:(SPTrack *)aTrack error:(NSError **)error {
[self unloadPlayback];
- self.currentAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:localFile.path]];
- self.currentWorker = [[VivaLocalFileDecoderWorker alloc] init];
+ self.currentFile = localFile;
+ self.currentWorker = [[VivaAVAssetDecoderWorker alloc] init];
self.currentWorker.delegate = self;
- [self.currentWorker decodeAsset:self.currentAsset fromPosition:0.0];
+ [self.currentWorker decodeLocalFile:self.currentFile fromPosition:0.0];
self.currentWorker.playing = self.isPlaying;
return YES;
@@ -80,13 +81,13 @@ -(BOOL)playTrack:(SPTrack *)aTrack error:(NSError **)error {
-(void)seekPlaybackToOffset:(NSTimeInterval)offset {
[self unloadPlayback];
- self.currentWorker = [[VivaLocalFileDecoderWorker alloc] init];
+ self.currentWorker = [[VivaAVAssetDecoderWorker alloc] init];
self.currentWorker.delegate = self;
// Fake audio delivery to get player to clear buffers.
[self.playbackDelegate session:self shouldDeliverAudioFrames:NULL ofCount:0 format:NULL];
- [self.currentWorker decodeAsset:self.currentAsset fromPosition:offset];
+ [self.currentWorker decodeLocalFile:self.currentFile fromPosition:offset];
self.currentWorker.playing = self.isPlaying;
}
@@ -101,7 +102,7 @@ -(void)unloadPlayback {
#pragma mark -
#pragma mark Delegates
--(NSUInteger)worker:(VivaLocalFileDecoderWorker *)worker shouldDeliverAudioFrames:(const void *)audioFrames ofCount:(NSInteger)frameCount format:(const sp_audioformat *)audioFormat {
+-(NSUInteger)worker:(VivaAVAssetDecoderWorker *)worker shouldDeliverAudioFrames:(const void *)audioFrames ofCount:(NSInteger)frameCount format:(const sp_audioformat *)audioFormat {
if (worker == self.currentWorker) {
return [self.playbackDelegate session:nil
shouldDeliverAudioFrames:audioFrames
@@ -111,7 +112,7 @@ -(NSUInteger)worker:(VivaLocalFileDecoderWorker *)worker shouldDeliverAudioFrame
return 0;
}
--(void)workerDidCompleteAudioPlayback:(VivaLocalFileDecoderWorker *)worker {
+-(void)workerDidCompleteAudioPlayback:(VivaAVAssetDecoderWorker *)worker {
if (worker == self.currentWorker) {
[self unloadPlayback];
[self.playbackDelegate sessionDidEndPlayback:self];
View
16 Viva/VivaLocalFileDecoderWorker.h
@@ -2,30 +2,30 @@
// VivaLocalFileDecoderWorker.h
// Viva
//
-// Created by Daniel Kennett on 16/11/2011.
+// Created by Daniel Kennett on 03/02/2012.
// For license information, see LICENSE.markdown
//
#import <Foundation/Foundation.h>
-#import <AVFoundation/AVFoundation.h>
#import <CocoaLibSpotify/CocoaLibSpotify.h>
+#import "LocalFile.h"
-@class VivaLocalFileDecoderWorker;
+@protocol VivaLocalFileDecoderWorker;
@protocol VivaLocalFileDecoderWorkerDelegate <NSObject>
--(NSUInteger)worker:(VivaLocalFileDecoderWorker *)worker shouldDeliverAudioFrames:(const void *)audioFrames ofCount:(NSInteger)frameCount format:(const sp_audioformat *)audioFormat;
--(void)workerDidCompleteAudioPlayback:(VivaLocalFileDecoderWorker *)worker;
+-(NSUInteger)worker:(id <VivaLocalFileDecoderWorker>)worker shouldDeliverAudioFrames:(const void *)audioFrames ofCount:(NSInteger)frameCount format:(const sp_audioformat *)audioFormat;
+-(void)workerDidCompleteAudioPlayback:(id <VivaLocalFileDecoderWorker>)worker;
@end
-@interface VivaLocalFileDecoderWorker : NSObject
+@protocol VivaLocalFileDecoderWorker <NSObject>
@property (nonatomic) __weak id <VivaLocalFileDecoderWorkerDelegate> delegate;
@property (readwrite) BOOL cancelled;
@property (readwrite, getter = isPlaying) BOOL playing;
-
--(void)decodeAsset:(AVAsset *)asset fromPosition:(NSTimeInterval)startTime;
+-(void)decodeLocalFile:(LocalFile *)file fromPosition:(NSTimeInterval)startTime;
@end
+
Please sign in to comment.
Something went wrong with that request. Please try again.