1 /*****************************************************************************
2 * VLCStreamOutput.m: VLCKit.framework VLCStreamOutput 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 "VLCStreamOutput.h"
26 #import "VLCLibVLCBridging.h"
28 @implementation VLCStreamOutput
29 - (id)initWithOptionDictionary:(NSDictionary *)dictionary
31 if( self = [super init] )
33 options = [[NSMutableDictionary dictionaryWithDictionary:dictionary] retain];
37 - (NSString *)description
39 return [self representedLibVLCOptions];
41 + (id)streamOutputWithOptionDictionary:(NSDictionary *)dictionary
43 return [[[self alloc] initWithOptionDictionary:dictionary] autorelease];
45 + (id)rtpBroadcastStreamOutputWithSAPAnnounce:(NSString *)announceName
47 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
48 [NSDictionary dictionaryWithObjectsAndKeys:
52 [announceName copy], @"name",
53 @"239.255.1.1", @"destination", nil
60 + (id)rtpBroadcastStreamOutput
62 return [self rtpBroadcastStreamOutputWithSAPAnnounce:@"Helloworld!"];
65 + (id)ipodStreamOutputWithFilePath:(NSString *)filePath
67 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
68 [NSDictionary dictionaryWithObjectsAndKeys:
69 @"mp4v", @"videoCodec",
70 @"1024", @"videoBitrate",
71 @"mp4a", @"audioCodec",
72 @"192", @"audioBitrate",
75 @"240", @"canvasHeight",
76 @"Yes", @"audio-sync",
78 ], @"transcodingOptions",
79 [NSDictionary dictionaryWithObjectsAndKeys:
82 [filePath copy], @"destination", nil
89 + (id)mpeg4StreamOutputWithFilePath:(NSString *)filePath
91 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
92 [NSDictionary dictionaryWithObjectsAndKeys:
93 @"mp4v", @"videoCodec",
94 @"1024", @"videoBitrate",
95 @"mp4a", @"audioCodec",
96 @"192", @"audioBitrate",
98 ], @"transcodingOptions",
99 [NSDictionary dictionaryWithObjectsAndKeys:
102 [filePath copy], @"destination", nil
109 + (id)streamOutputWithFilePath:(NSString *)filePath
111 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
112 [NSDictionary dictionaryWithObjectsAndKeys:
115 [filePath copy], @"destination", nil
122 + (id)mpeg2StreamOutputWithFilePath:(NSString *)filePath;
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",
132 ], @"transcodingOptions",
133 [NSDictionary dictionaryWithObjectsAndKeys:
136 [filePath copy], @"destination", nil
144 @implementation VLCStreamOutput (LibVLCBridge)
145 - (NSString *)representedLibVLCOptions
147 NSString * representedOptions;
148 NSMutableArray * subOptions = [NSMutableArray array];
149 NSMutableArray * optionsAsArray = [NSMutableArray array];
150 NSDictionary * transcodingOptions = [options objectForKey:@"transcodingOptions"];
151 if( transcodingOptions )
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];
177 NSDictionary * outputOptions = [options objectForKey:@"outputOptions"];
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];
192 NSDictionary * rtpOptions = [options objectForKey:@"rtpOptions"];
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];
206 representedOptions = [optionsAsArray componentsJoinedByString:@":"];
207 return representedOptions;