]> git.sesse.net Git - vlc/blob - projects/macosx/framework/Sources/VLCStreamOutput.m
Replace libvlc_exception_get_message with libvlc_errmsg
[vlc] / projects / macosx / framework / Sources / VLCStreamOutput.m
1 /*****************************************************************************
2  * VLCStreamOutput.m: VLCKit.framework VLCStreamOutput implementation
3  *****************************************************************************
4  * Copyright (C) 2008 Pierre d'Herbemont
5  * Copyright (C) 2008 the VideoLAN team
6  * $Id$
7  *
8  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #import "VLCStreamOutput.h"
26 #import "VLCLibVLCBridging.h"
27
28 @implementation VLCStreamOutput
29 - (id)initWithOptionDictionary:(NSDictionary *)dictionary
30 {
31     if( self = [super init] )
32     {
33         options = [[NSMutableDictionary dictionaryWithDictionary:dictionary] retain];
34     }
35     return self;
36 }
37 - (NSString *)description
38 {
39     return [self representedLibVLCOptions];
40 }
41 + (id)streamOutputWithOptionDictionary:(NSDictionary *)dictionary
42 {
43     return [[[self alloc] initWithOptionDictionary:dictionary] autorelease];
44 }
45 + (id)rtpBroadcastStreamOutputWithSAPAnnounce:(NSString *)announceName
46 {
47     return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
48                                             [NSDictionary dictionaryWithObjectsAndKeys:
49                                                 @"ts", @"muxer",
50                                                 @"file", @"access",
51                                                 @"sap", @"sdp",
52                                                 [announceName copy], @"name",
53                                                 @"239.255.1.1", @"destination", nil
54                                             ], @"rtpOptions",
55                                             nil
56                                             ]
57                                         ];
58 }
59
60 + (id)rtpBroadcastStreamOutput
61 {
62     return [self rtpBroadcastStreamOutputWithSAPAnnounce:@"Helloworld!"];
63 }
64
65 + (id)ipodStreamOutputWithFilePath:(NSString *)filePath
66 {
67     return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
68                                             [NSDictionary dictionaryWithObjectsAndKeys:
69                                                 @"mp4v", @"videoCodec",
70                                                 @"1024",  @"videoBitrate",
71                                                 @"mp4a", @"audioCodec",
72                                                 @"192", @"audioBitrate",
73                                                 @"2",   @"channels",
74                                                 @"320", @"width",
75                                                 @"240", @"canvasHeight",
76                                                 @"Yes", @"audio-sync",
77                                                 nil
78                                             ], @"transcodingOptions",
79                                             [NSDictionary dictionaryWithObjectsAndKeys:
80                                                 @"mp4", @"muxer",
81                                                 @"file", @"access",
82                                                 [filePath copy], @"destination", nil
83                                             ], @"outputOptions",
84                                             nil
85                                             ]
86                                         ];
87 }
88
89 + (id)mpeg4StreamOutputWithFilePath:(NSString *)filePath
90 {
91     return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
92                                             [NSDictionary dictionaryWithObjectsAndKeys:
93                                                 @"mp4v", @"videoCodec",
94                                                 @"1024",  @"videoBitrate",
95                                                 @"mp4a", @"audioCodec",
96                                                 @"192", @"audioBitrate",
97                                                 nil
98                                             ], @"transcodingOptions",
99                                             [NSDictionary dictionaryWithObjectsAndKeys:
100                                                 @"mp4", @"muxer",
101                                                 @"file", @"access",
102                                                 [filePath copy], @"destination", nil
103                                             ], @"outputOptions",
104                                             nil
105                                             ]
106                                         ];
107 }
108
109 + (id)streamOutputWithFilePath:(NSString *)filePath
110 {
111     return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
112                                             [NSDictionary dictionaryWithObjectsAndKeys:
113                                                 @"ps", @"muxer",
114                                                 @"file", @"access",
115                                                 [filePath copy], @"destination", nil
116                                             ], @"outputOptions",
117                                             nil
118                                             ]
119                                         ];
120 }
121
122 + (id)mpeg2StreamOutputWithFilePath:(NSString *)filePath;
123 {
124     return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
125                                             [NSDictionary dictionaryWithObjectsAndKeys:
126                                                 @"mp2v", @"videoCodec",
127                                                 @"1024", @"videoBitrate",
128                                                 @"mp2a",   @"audioCodec",
129                                                 @"128",   @"audioBitrate",
130                                                 @"Yes",   @"audio-sync",
131                                                 nil
132                                             ], @"transcodingOptions",
133                                             [NSDictionary dictionaryWithObjectsAndKeys:
134                                                 @"mpeg", @"muxer",
135                                                 @"file", @"access",
136                                                 [filePath copy], @"destination", nil
137                                             ], @"outputOptions",
138                                             nil
139                                             ]
140                                         ];
141 }
142 @end
143
144 @implementation VLCStreamOutput (LibVLCBridge)
145 - (NSString *)representedLibVLCOptions
146 {
147     NSString * representedOptions;
148     NSMutableArray * subOptions = [NSMutableArray array];
149     NSMutableArray * optionsAsArray = [NSMutableArray array];
150     NSDictionary * transcodingOptions = [options objectForKey:@"transcodingOptions"];
151     if( transcodingOptions )
152     {
153         NSString * videoCodec = [transcodingOptions objectForKey:@"videoCodec"];
154         NSString * audioCodec = [transcodingOptions objectForKey:@"audioCodec"];
155         NSString * videoBitrate = [transcodingOptions objectForKey:@"videoBitrate"];
156         NSString * audioBitrate = [transcodingOptions objectForKey:@"audioBitrate"];
157         NSString * channels = [transcodingOptions objectForKey:@"channels"];
158         NSString * height = [transcodingOptions objectForKey:@"height"];
159         NSString * canvasHeight = [transcodingOptions objectForKey:@"canvasHeight"];
160         NSString * width = [transcodingOptions objectForKey:@"width"];
161         NSString * audioSync = [transcodingOptions objectForKey:@"audioSync"];
162         NSString * videoEncoder = [transcodingOptions objectForKey:@"videoEncoder"];
163         if( videoEncoder )   [subOptions addObject:[NSString stringWithFormat:@"venc=%@", videoEncoder]];
164         if( videoCodec )   [subOptions addObject:[NSString stringWithFormat:@"vcodec=%@", videoCodec]];
165         if( videoBitrate ) [subOptions addObject:[NSString stringWithFormat:@"vb=%@", videoBitrate]];
166         if( width ) [subOptions addObject:[NSString stringWithFormat:@"width=%@", width]];
167         if( height ) [subOptions addObject:[NSString stringWithFormat:@"height=%@", height]];
168         if( canvasHeight ) [subOptions addObject:[NSString stringWithFormat:@"canvas-height=%@", canvasHeight]];
169         if( audioCodec )   [subOptions addObject:[NSString stringWithFormat:@"acodec=%@", audioCodec]];
170         if( audioBitrate ) [subOptions addObject:[NSString stringWithFormat:@"ab=%@", audioBitrate]];
171         if( channels ) [subOptions addObject:[NSString stringWithFormat:@"channels=%@", channels]];
172         if( audioSync ) [subOptions addObject:[NSString stringWithFormat:@"audioSync", width]];
173         [optionsAsArray addObject: [NSString stringWithFormat:@"transcode{%@}", [subOptions componentsJoinedByString:@","]]];
174         [subOptions removeAllObjects];
175     }
176     
177     NSDictionary * outputOptions = [options objectForKey:@"outputOptions"];
178     if( outputOptions )
179     {
180         NSString * muxer = [outputOptions objectForKey:@"muxer"];
181         NSString * destination = [outputOptions objectForKey:@"destination"];
182         NSString * url = [outputOptions objectForKey:@"url"];
183         NSString * access = [outputOptions objectForKey:@"access"];
184         if( muxer )       [subOptions addObject:[NSString stringWithFormat:@"mux=%@", muxer]];
185         if( destination ) [subOptions addObject:[NSString stringWithFormat:@"dst=\"%@\"", [destination stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]];
186         if( url ) [subOptions addObject:[NSString stringWithFormat:@"url=\"%@\"", [url stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]];
187         if( access )      [subOptions addObject:[NSString stringWithFormat:@"access=%@", access]];
188         [optionsAsArray addObject:[NSString stringWithFormat:@"std{%@}", [subOptions componentsJoinedByString:@","]]];
189         [subOptions removeAllObjects];
190     }
191
192     NSDictionary * rtpOptions = [options objectForKey:@"rtpOptions"];
193     if( rtpOptions )
194     {
195         NSString * muxer = [rtpOptions objectForKey:@"muxer"];
196         NSString * destination = [rtpOptions objectForKey:@"destination"];
197         NSString * sdp = [rtpOptions objectForKey:@"sdp"];
198         NSString * name = [rtpOptions objectForKey:@"name"];
199         if( muxer )       [subOptions addObject:[NSString stringWithFormat:@"muxer=%@", muxer]];
200         if( destination ) [subOptions addObject:[NSString stringWithFormat:@"dst=%@", destination]];
201         if( sdp )      [subOptions addObject:[NSString stringWithFormat:@"sdp=%@", sdp]];
202         if( name )      [subOptions addObject:[NSString stringWithFormat:@"name=\"%@\"", name]];
203         [optionsAsArray addObject:[NSString stringWithFormat:@"rtp{%@}", [subOptions componentsJoinedByString:@","]]];
204         [subOptions removeAllObjects];
205     }
206     representedOptions = [optionsAsArray componentsJoinedByString:@":"];
207     return representedOptions;
208 }
209 @end