1 /*****************************************************************************
2 * VLCStreamSession.m: VLCKit.framework VLCStreamSession implementation
3 *****************************************************************************
4 * Copyright (C) 2008 Pierre d'Herbemont
5 * Copyright (C) 2008 the VideoLAN team
8 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #import "VLCStreamSession.h"
26 #import "VLCLibVLCBridging.h"
28 @interface VLCStreamSession ()
29 @property (readwrite) BOOL isComplete;
32 @implementation VLCStreamSession
33 @synthesize media=originalMedia;
34 @synthesize streamOutput;
35 @synthesize isComplete;
39 if( self = [super init] )
41 reattemptedConnections = 0;
42 [self addObserver:self forKeyPath:@"state" options:NSKeyValueObservingOptionNew context:nil];
50 [self removeObserver:self forKeyPath:@"state"];
56 return [[[self alloc] init] autorelease];
60 - (void)startStreaming
68 self.isComplete = YES;
74 NSString * libvlcArgs;
76 libvlcArgs = [NSString stringWithFormat:@"#duplicate{dst=display,dst=\"%@\"}",[streamOutput representedLibVLCOptions]];
78 libvlcArgs = [streamOutput representedLibVLCOptions];
81 [super setMedia: [VLCMedia mediaWithMedia:originalMedia andLibVLCOptions:
82 [NSDictionary dictionaryWithObject: libvlcArgs forKey: @"sout"]]];
86 [super setMedia: self.media];
92 + (NSSet *)keyPathsForValuesAffectingDescription
94 return [NSSet setWithObjects:@"isCompleted", @"state", nil];
97 - (NSString *)description
101 else if([self state] == VLCMediaPlayerStateError)
102 return @"Error while Converting. Open Console.app to diagnose.";
104 return @"Converting...";
107 + (NSSet *)keyPathsForValuesAffectingEncounteredError
109 return [NSSet setWithObjects:@"state", nil];
112 - (BOOL)encounteredError;
114 return ([self state] == VLCMediaPlayerStateError);
117 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
119 if([keyPath isEqualToString:@"state"])
121 if( (([self position] == 1.0 || [self state] == VLCMediaPlayerStateEnded || ([self state] == VLCMediaPlayerStateStopped && self.media)) ||
122 [self encounteredError] ) && ![super.media subitems] )
124 self.isComplete = YES;
127 if( reattemptedConnections > 4 )
130 /* Our media has in fact gained subitems, let's change our playing media */
131 if( [[super.media subitems] count] > 0 )
134 self.media = [[super.media subitems] mediaAtIndex:0];
136 reattemptedConnections++;
140 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];