Changeset 6d95c7823c9f661571671f149185e2c6f5994b21

Show
Ignore:
Timestamp:
13/01/08 18:17:33 (11 months ago)
Author:
Pierre d'Herbemont <pdherbemont@videolan.org>
git-committer:
Pierre d'Herbemont <pdherbemont@videolan.org> 1200244653 +0000
git-parent:

[d372e0d833d9167304d706a27c2716e34234c6c0]

git-author:
Pierre d'Herbemont <pdherbemont@videolan.org> 1200244653 +0000
Message:

MacOSX/Framework: Support streamin media list.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • extras/MacOSX/Framework/Sources/VLCLibrary.m

    r3d83d9c r6d95c78  
    7979        const char * lib_vlc_params[] = {  
    8080            "-I", "dummy", "--vout=opengllayer",  
    81             "--no-video-title-show", "--no-sout-keep", "-vvv", "--encoder=ffmpeg" 
     81            "--no-video-title-show", "--no-sout-keep", "-vvv" 
    8282            //, "--control=motion", "--motion-use-rotate", "--video-filter=rotate" 
    8383        }; 
  • extras/MacOSX/Framework/Sources/VLCMediaPlayer.m

    r90f36ed r6d95c78  
    9191    else if( event->type == libvlc_MediaInstanceReachedEnd ) 
    9292        newState = VLCMediaPlayerStateStopped; 
     93    else if( event->type == libvlc_MediaInstanceEncounteredError ) 
     94        newState = VLCMediaPlayerStateError; 
    9395    else 
    9496    { 
     
    417419- (void)setMedia:(VLCMedia *)value 
    418420{ 
    419     // We only know how to play media files...not media resources with subitems 
    420     if (media != value && [media subitems] == nil) 
     421    if (media != value) 
    421422    { 
    422423        if (media && [media compare:value] == NSOrderedSame) 
     
    481482- (void)stop 
    482483{ 
    483     if( [NSThread isMainThread] ) 
     484    if( 0 && [NSThread isMainThread] ) 
    484485    { 
    485486        /* Hack because we create a dead lock here, when the vout is stopped 
     
    493494    // Return if there is no media available or if the system is not in play status  
    494495    // or pause status. 
    495     if (!media || (![self isPlaying] && [self state] != VLCMediaPlayerStatePaused)
     496    if (!media
    496497        return; 
    497498     
    498     // The following is not implemented in the core, should I fix it or just 
    499     // compensate? 
    500     //    libvlc_exception_t ex; 
    501     //    libvlc_exception_init( &ex ); 
    502     //    libvlc_media_instance_stop((libvlc_media_instance_t *)instance, &ex); 
    503     //    catch_exception( &ex ); 
    504      
    505     // Pause and reposition to the begining of the stream. 
    506     [self pause]; 
    507     [self setTime:0]; 
    508     // TODO: Should we pause this or destroy the media instance so that it appears as being "stopped"? 
     499    libvlc_exception_t ex; 
     500    libvlc_exception_init( &ex ); 
     501    libvlc_media_instance_stop((libvlc_media_instance_t *)instance, &ex); 
     502    catch_exception( &ex ); 
    509503} 
    510504 
  • extras/MacOSX/Framework/Sources/VLCStreamOutput.m

    r3d83d9c r6d95c78  
    1616    if( self = [super init] ) 
    1717    { 
    18         options = [NSMutableDictionary dictionaryWithDictionary:dictionary]; 
     18        options = [[NSMutableDictionary dictionaryWithDictionary:dictionary] retain]; 
    1919    } 
    2020    return self; 
     
    5252    return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys: 
    5353                                            [NSDictionary dictionaryWithObjectsAndKeys: 
    54                                                 @"x264", @"videoCodec", 
    55                                                 @"768",  @"videoBitrate", 
     54                                                @"mp4v", @"videoCodec", 
     55                                                @"1024",  @"videoBitrate", 
    5656                                                @"mp4a", @"audioCodec", 
    57                                                 @"128", @"audioBitrate", 
     57                                                @"192", @"audioBitrate", 
    5858                                                @"2",   @"channels", 
    5959                                                @"320", @"width", 
     
    6464                                            [NSDictionary dictionaryWithObjectsAndKeys: 
    6565                                                @"mp4", @"muxer", 
     66                                                @"file", @"access", 
     67                                                [filePath copy], @"destination", nil 
     68                                            ], @"outputOptions", 
     69                                            nil 
     70                                            ] 
     71                                        ]; 
     72} 
     73 
     74+ (id)mpeg4StreamOutputWithFilePath:(NSString *)filePath 
     75{ 
     76    return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys: 
     77                                            [NSDictionary dictionaryWithObjectsAndKeys: 
     78                                                @"mp4v", @"videoCodec", 
     79                                                @"1024",  @"videoBitrate", 
     80                                                @"mp4a", @"audioCodec", 
     81                                                @"192", @"audioBitrate", 
     82                                                nil 
     83                                            ], @"transcodingOptions", 
     84                                            [NSDictionary dictionaryWithObjectsAndKeys: 
     85                                                @"mp4", @"muxer", 
     86                                                @"file", @"access", 
     87                                                [filePath copy], @"destination", nil 
     88                                            ], @"outputOptions", 
     89                                            nil 
     90                                            ] 
     91                                        ]; 
     92} 
     93 
     94+ (id)streamOutputWithFilePath:(NSString *)filePath 
     95{ 
     96    return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys: 
     97                                            [NSDictionary dictionaryWithObjectsAndKeys: 
     98                                                @"ps", @"muxer", 
     99                                                @"file", @"access", 
     100                                                [filePath copy], @"destination", nil 
     101                                            ], @"outputOptions", 
     102                                            nil 
     103                                            ] 
     104                                        ]; 
     105} 
     106 
     107+ (id)mpeg2StreamOutputWithFilePath:(NSString *)filePath; 
     108{ 
     109    return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys: 
     110                                            [NSDictionary dictionaryWithObjectsAndKeys: 
     111                                                @"mp2v", @"videoCodec", 
     112                                                @"1024", @"videoBitrate", 
     113                                                @"mp2a",   @"audioCodec", 
     114                                                @"128",   @"audioBitrate", 
     115                                                @"Yes",   @"audio-sync", 
     116                                                nil 
     117                                            ], @"transcodingOptions", 
     118                                            [NSDictionary dictionaryWithObjectsAndKeys: 
     119                                                @"mpeg", @"muxer", 
    66120                                                @"file", @"access", 
    67121                                                [filePath copy], @"destination", nil 
     
    91145        NSString * width = [transcodingOptions objectForKey:@"width"]; 
    92146        NSString * audioSync = [transcodingOptions objectForKey:@"audioSync"]; 
     147        NSString * videoEncoder = [transcodingOptions objectForKey:@"videoEncoder"]; 
     148        if( videoEncoder )   [subOptions addObject:[NSString stringWithFormat:@"venc=%@", videoEncoder]]; 
    93149        if( videoCodec )   [subOptions addObject:[NSString stringWithFormat:@"vcodec=%@", videoCodec]]; 
    94150        if( videoBitrate ) [subOptions addObject:[NSString stringWithFormat:@"vb=%@", videoBitrate]]; 
     
    111167        NSString * url = [outputOptions objectForKey:@"url"]; 
    112168        NSString * access = [outputOptions objectForKey:@"access"]; 
    113         if( muxer )       [subOptions addObject:[NSString stringWithFormat:@"muxer=%@", muxer]]; 
     169        if( muxer )       [subOptions addObject:[NSString stringWithFormat:@"mux=%@", muxer]]; 
    114170        if( destination ) [subOptions addObject:[NSString stringWithFormat:@"dst=\"%@\"", [destination stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]]; 
    115171        if( url ) [subOptions addObject:[NSString stringWithFormat:@"url=\"%@\"", [url stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]]; 
  • extras/MacOSX/Framework/Sources/VLCStreamSession.m

    r3d83d9c r6d95c78  
    1010#import "VLCLibVLCBridging.h" 
    1111 
     12@interface VLCStreamSession () 
     13@property (readwrite) BOOL isComplete; 
     14@end 
     15 
    1216@implementation VLCStreamSession 
    1317@synthesize media=originalMedia; 
    1418@synthesize streamOutput; 
     19@synthesize isComplete; 
     20 
     21- (id)init 
     22{ 
     23    if( self = [super init] ) 
     24    { 
     25        reattemptedConnections = 0; 
     26        [self addObserver:self forKeyPath:@"state" options:NSKeyValueObservingOptionNew context:nil]; 
     27        self.isComplete = NO; 
     28    } 
     29    return self; 
     30} 
     31 
     32- (void)dealloc 
     33{ 
     34    [self removeObserver:self forKeyPath:@"state"]; 
     35    [super dealloc]; 
     36} 
    1537 
    1638+ (id)streamSession 
     
    2244- (void)startStreaming; 
    2345{ 
     46    self.isComplete = NO; 
    2447    [self play]; 
    2548} 
     
    2952    NSString * libvlcArgs; 
    3053    if( self.drawable ) 
     54        libvlcArgs = [NSString stringWithFormat:@"duplicate{dst=display,dst=\"%@\"}",[streamOutput representedLibVLCOptions]]; 
     55    else 
     56        libvlcArgs = [streamOutput representedLibVLCOptions]; 
     57 
     58    if( libvlcArgs ) 
    3159    { 
    32         libvlcArgs = [NSString stringWithFormat:@"duplicate{dst=display,dst=\"%@\"}",[streamOutput representedLibVLCOptions]]; 
     60        [super setMedia: [VLCMedia mediaWithMedia:originalMedia andLibVLCOptions: 
     61                                [NSDictionary dictionaryWithObject: libvlcArgs forKey: @"sout"]]]; 
    3362    } 
    3463    else 
    3564    { 
    36         libvlcArgs = [streamOutput representedLibVLCOptions]; 
     65        [super setMedia: self.media]; 
    3766    } 
    38     [super setMedia: [VLCMedia mediaWithMedia:originalMedia andLibVLCOptions: 
    39                             [NSDictionary dictionaryWithObject: libvlcArgs 
    40                                                         forKey: @"sout"]]]; 
    4167    [super play]; 
    4268} 
     
    5783} 
    5884 
    59 + (NSSet *)keyPathsForValuesAffectingIsComplete 
     85+ (NSSet *)keyPathsForValuesAffectingEncounteredError 
    6086{ 
    61     return [NSSet setWithObjects:@"playing", @"state", @"position", nil]; 
     87    return [NSSet setWithObjects:@"state", nil]; 
    6288} 
    6389 
    64 - (BOOL)isComplete 
     90- (BOOL)encounteredError; 
    6591{ 
    66     return ([self position] == 1.0 || [self state] == VLCMediaPlayerStateEnded || ([self state] == VLCMediaPlayerStateStopped && self.media)); 
     92    return ([self state] == VLCMediaPlayerStateError); 
    6793} 
     94 
     95- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 
     96{ 
     97    if([keyPath isEqualToString:@"state"]) 
     98    { 
     99        if( (([self position] == 1.0 || [self state] == VLCMediaPlayerStateEnded || ([self state] == VLCMediaPlayerStateStopped && self.media)) || 
     100            [self encounteredError] ) && ![super.media subitems] ) 
     101        { 
     102            self.isComplete = YES; 
     103            return; 
     104        } 
     105        if( reattemptedConnections > 4 ) 
     106            return; 
     107 
     108        /* Our media has in fact gained subitems, let's change our playing media */ 
     109        if( [[super.media subitems] count] > 0 ) 
     110        { 
     111            [self stop]; 
     112            self.media = [[super.media subitems] mediaAtIndex:0]; 
     113            [self play]; 
     114            reattemptedConnections++; 
     115        } 
     116        return; 
     117    } 
     118    [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; 
     119} 
     120 
    68121@end