MacOSX/Framework: Add VLCStreamSession, VLCStreamOutput to allow streaming/exporting.
[vlc.git] / extras / MacOSX / Framework / Sources / VLCStreamSession.m
1 //
2 //  VLCStreamSession.m
3 //  VLCKit
4 //
5 //  Created by Pierre d'Herbemont on 1/12/08.
6 //  Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "VLCStreamSession.h"
10 #import "VLCLibVLCBridging.h"
11
12 @implementation VLCStreamSession
13 @synthesize media=originalMedia;
14 @synthesize streamOutput;
15
16 + (id)streamSession
17 {
18     return [[[self alloc] init] autorelease];
19 }
20
21
22 - (void)startStreaming;
23 {
24     [self play];
25 }
26
27 - (void)play;
28 {
29     NSString * libvlcArgs;
30     if( self.drawable )
31     {
32         libvlcArgs = [NSString stringWithFormat:@"duplicate{dst=display,dst=\"%@\"}",[streamOutput representedLibVLCOptions]];
33     }
34     else
35     {
36         libvlcArgs = [streamOutput representedLibVLCOptions];
37     }
38     [super setMedia: [VLCMedia mediaWithMedia:originalMedia andLibVLCOptions:
39                             [NSDictionary dictionaryWithObject: libvlcArgs
40                                                         forKey: @"sout"]]];
41     [super play];
42 }
43
44 + (NSSet *)keyPathsForValuesAffectingDescription
45 {
46     return [NSSet setWithObjects:@"isCompleted", @"state", nil];
47 }
48
49 - (NSString *)description
50 {
51     if([self isComplete])
52         return @"Done.";
53     else if([self state] == VLCMediaPlayerStateError)
54         return @"Error while Converting. Open Console.app to diagnose.";
55     else
56         return @"Converting...";
57 }
58
59 + (NSSet *)keyPathsForValuesAffectingIsComplete
60 {
61     return [NSSet setWithObjects:@"playing", @"state", @"position", nil];
62 }
63
64 - (BOOL)isComplete
65 {
66     return ([self position] == 1.0 || [self state] == VLCMediaPlayerStateEnded || ([self state] == VLCMediaPlayerStateStopped && self.media));
67 }
68 @end