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 NSString *name = [announceName copy];
48 id output = [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
49 [NSDictionary dictionaryWithObjectsAndKeys:
54 @"239.255.1.1", @"destination", nil
63 + (id)rtpBroadcastStreamOutput
65 return [self rtpBroadcastStreamOutputWithSAPAnnounce:@"Helloworld!"];
68 + (id)ipodStreamOutputWithFilePath:(NSString *)filePath
70 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
71 [NSDictionary dictionaryWithObjectsAndKeys:
72 @"mp4v", @"videoCodec",
73 @"1024", @"videoBitrate",
74 @"mp4a", @"audioCodec",
75 @"192", @"audioBitrate",
78 @"240", @"canvasHeight",
79 @"Yes", @"audio-sync",
81 ], @"transcodingOptions",
82 [NSDictionary dictionaryWithObjectsAndKeys:
85 [filePath copy], @"destination", nil
92 + (id)mpeg4StreamOutputWithFilePath:(NSString *)filePath
94 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
95 [NSDictionary dictionaryWithObjectsAndKeys:
96 @"mp4v", @"videoCodec",
97 @"1024", @"videoBitrate",
98 @"mp4a", @"audioCodec",
99 @"192", @"audioBitrate",
101 ], @"transcodingOptions",
102 [NSDictionary dictionaryWithObjectsAndKeys:
105 [filePath copy], @"destination", nil
112 + (id)streamOutputWithFilePath:(NSString *)filePath
114 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
115 [NSDictionary dictionaryWithObjectsAndKeys:
118 [filePath copy], @"destination", nil
125 + (id)mpeg2StreamOutputWithFilePath:(NSString *)filePath;
127 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
128 [NSDictionary dictionaryWithObjectsAndKeys:
129 @"mp2v", @"videoCodec",
130 @"1024", @"videoBitrate",
131 @"mp2a", @"audioCodec",
132 @"128", @"audioBitrate",
133 @"Yes", @"audio-sync",
135 ], @"transcodingOptions",
136 [NSDictionary dictionaryWithObjectsAndKeys:
139 [filePath copy], @"destination", nil
147 @implementation VLCStreamOutput (LibVLCBridge)
148 - (NSString *)representedLibVLCOptions
150 NSString * representedOptions;
151 NSMutableArray * subOptions = [NSMutableArray array];
152 NSMutableArray * optionsAsArray = [NSMutableArray array];
153 NSDictionary * transcodingOptions = [options objectForKey:@"transcodingOptions"];
154 if( transcodingOptions )
156 NSString * videoCodec = [transcodingOptions objectForKey:@"videoCodec"];
157 NSString * audioCodec = [transcodingOptions objectForKey:@"audioCodec"];
158 NSString * videoBitrate = [transcodingOptions objectForKey:@"videoBitrate"];
159 NSString * audioBitrate = [transcodingOptions objectForKey:@"audioBitrate"];
160 NSString * channels = [transcodingOptions objectForKey:@"channels"];
161 NSString * height = [transcodingOptions objectForKey:@"height"];
162 NSString * canvasHeight = [transcodingOptions objectForKey:@"canvasHeight"];
163 NSString * width = [transcodingOptions objectForKey:@"width"];
164 NSString * audioSync = [transcodingOptions objectForKey:@"audioSync"];
165 NSString * videoEncoder = [transcodingOptions objectForKey:@"videoEncoder"];
166 if( videoEncoder ) [subOptions addObject:[NSString stringWithFormat:@"venc=%@", videoEncoder]];
167 if( videoCodec ) [subOptions addObject:[NSString stringWithFormat:@"vcodec=%@", videoCodec]];
168 if( videoBitrate ) [subOptions addObject:[NSString stringWithFormat:@"vb=%@", videoBitrate]];
169 if( width ) [subOptions addObject:[NSString stringWithFormat:@"width=%@", width]];
170 if( height ) [subOptions addObject:[NSString stringWithFormat:@"height=%@", height]];
171 if( canvasHeight ) [subOptions addObject:[NSString stringWithFormat:@"canvas-height=%@", canvasHeight]];
172 if( audioCodec ) [subOptions addObject:[NSString stringWithFormat:@"acodec=%@", audioCodec]];
173 if( audioBitrate ) [subOptions addObject:[NSString stringWithFormat:@"ab=%@", audioBitrate]];
174 if( channels ) [subOptions addObject:[NSString stringWithFormat:@"channels=%@", channels]];
175 if( audioSync ) [subOptions addObject:[NSString stringWithFormat:@"audioSync", width]];
176 [optionsAsArray addObject: [NSString stringWithFormat:@"transcode{%@}", [subOptions componentsJoinedByString:@","]]];
177 [subOptions removeAllObjects];
180 NSDictionary * outputOptions = [options objectForKey:@"outputOptions"];
183 NSString * muxer = [outputOptions objectForKey:@"muxer"];
184 NSString * destination = [outputOptions objectForKey:@"destination"];
185 NSString * url = [outputOptions objectForKey:@"url"];
186 NSString * access = [outputOptions objectForKey:@"access"];
187 if( muxer ) [subOptions addObject:[NSString stringWithFormat:@"mux=%@", muxer]];
188 if( destination ) [subOptions addObject:[NSString stringWithFormat:@"dst=\"%@\"", [destination stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]];
189 if( url ) [subOptions addObject:[NSString stringWithFormat:@"url=\"%@\"", [url stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]];
190 if( access ) [subOptions addObject:[NSString stringWithFormat:@"access=%@", access]];
191 [optionsAsArray addObject:[NSString stringWithFormat:@"std{%@}", [subOptions componentsJoinedByString:@","]]];
192 [subOptions removeAllObjects];
195 NSDictionary * rtpOptions = [options objectForKey:@"rtpOptions"];
198 NSString * muxer = [rtpOptions objectForKey:@"muxer"];
199 NSString * destination = [rtpOptions objectForKey:@"destination"];
200 NSString * sdp = [rtpOptions objectForKey:@"sdp"];
201 NSString * name = [rtpOptions objectForKey:@"name"];
202 if( muxer ) [subOptions addObject:[NSString stringWithFormat:@"muxer=%@", muxer]];
203 if( destination ) [subOptions addObject:[NSString stringWithFormat:@"dst=%@", destination]];
204 if( sdp ) [subOptions addObject:[NSString stringWithFormat:@"sdp=%@", sdp]];
205 if( name ) [subOptions addObject:[NSString stringWithFormat:@"name=\"%@\"", name]];
206 [optionsAsArray addObject:[NSString stringWithFormat:@"rtp{%@}", [subOptions componentsJoinedByString:@","]]];
207 [subOptions removeAllObjects];
209 representedOptions = [optionsAsArray componentsJoinedByString:@":"];
210 return representedOptions;