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:
55 @"239.255.1.1", @"destination", nil
64 + (id)rtpBroadcastStreamOutput
66 return [self rtpBroadcastStreamOutputWithSAPAnnounce:@"Helloworld!"];
69 + (id)ipodStreamOutputWithFilePath:(NSString *)filePath
71 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
72 [NSDictionary dictionaryWithObjectsAndKeys:
73 @"h264", @"videoCodec",
74 @"1024", @"videoBitrate", // max by Apple: 1.5 mbps
75 @"mp4a", @"audioCodec",
76 @"128", @"audioBitrate", // max by Apple: 160 kbps
78 @"640", @"width", // max by Apple: do.
79 @"480", @"canvasHeight", // max by Apple: do.
80 @"Yes", @"audio-sync",
82 ], @"transcodingOptions",
83 [NSDictionary dictionaryWithObjectsAndKeys:
86 [[filePath copy] autorelease], @"destination",
94 + (id)mpeg4StreamOutputWithFilePath:(NSString *)filePath
96 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
97 [NSDictionary dictionaryWithObjectsAndKeys:
98 @"mp4v", @"videoCodec",
99 @"1024", @"videoBitrate",
100 @"mp4a", @"audioCodec",
101 @"192", @"audioBitrate",
103 ], @"transcodingOptions",
104 [NSDictionary dictionaryWithObjectsAndKeys:
107 [[filePath copy] autorelease], @"destination", nil
114 + (id)streamOutputWithFilePath:(NSString *)filePath
116 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
117 [NSDictionary dictionaryWithObjectsAndKeys:
120 [[filePath copy] autorelease], @"destination", nil
127 + (id)mpeg2StreamOutputWithFilePath:(NSString *)filePath;
129 return [self streamOutputWithOptionDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
130 [NSDictionary dictionaryWithObjectsAndKeys:
131 @"mp2v", @"videoCodec",
132 @"1024", @"videoBitrate",
133 @"mpga", @"audioCodec",
134 @"128", @"audioBitrate",
135 @"Yes", @"audio-sync",
137 ], @"transcodingOptions",
138 [NSDictionary dictionaryWithObjectsAndKeys:
141 [[filePath copy] autorelease], @"destination", nil
149 @implementation VLCStreamOutput (LibVLCBridge)
150 - (NSString *)representedLibVLCOptions
152 NSString * representedOptions;
153 NSMutableArray * subOptions = [NSMutableArray array];
154 NSMutableArray * optionsAsArray = [NSMutableArray array];
155 NSDictionary * transcodingOptions = [options objectForKey:@"transcodingOptions"];
156 if( transcodingOptions )
158 NSString * videoCodec = [transcodingOptions objectForKey:@"videoCodec"];
159 NSString * audioCodec = [transcodingOptions objectForKey:@"audioCodec"];
160 NSString * videoBitrate = [transcodingOptions objectForKey:@"videoBitrate"];
161 NSString * audioBitrate = [transcodingOptions objectForKey:@"audioBitrate"];
162 NSString * channels = [transcodingOptions objectForKey:@"channels"];
163 NSString * height = [transcodingOptions objectForKey:@"height"];
164 NSString * canvasHeight = [transcodingOptions objectForKey:@"canvasHeight"];
165 NSString * width = [transcodingOptions objectForKey:@"width"];
166 NSString * audioSync = [transcodingOptions objectForKey:@"audioSync"];
167 NSString * videoEncoder = [transcodingOptions objectForKey:@"videoEncoder"];
168 if( videoEncoder ) [subOptions addObject:[NSString stringWithFormat:@"venc=%@", videoEncoder]];
169 if( videoCodec ) [subOptions addObject:[NSString stringWithFormat:@"vcodec=%@", videoCodec]];
170 if( videoBitrate ) [subOptions addObject:[NSString stringWithFormat:@"vb=%@", videoBitrate]];
171 if( width ) [subOptions addObject:[NSString stringWithFormat:@"width=%@", width]];
172 if( height ) [subOptions addObject:[NSString stringWithFormat:@"height=%@", height]];
173 if( canvasHeight ) [subOptions addObject:[NSString stringWithFormat:@"canvas-height=%@", canvasHeight]];
174 if( audioCodec ) [subOptions addObject:[NSString stringWithFormat:@"acodec=%@", audioCodec]];
175 if( audioBitrate ) [subOptions addObject:[NSString stringWithFormat:@"ab=%@", audioBitrate]];
176 if( channels ) [subOptions addObject:[NSString stringWithFormat:@"channels=%@", channels]];
177 if( audioSync ) [subOptions addObject:[NSString stringWithFormat:@"audioSync", width]];
178 [optionsAsArray addObject: [NSString stringWithFormat:@"transcode{%@}", [subOptions componentsJoinedByString:@","]]];
179 [subOptions removeAllObjects];
182 NSDictionary * outputOptions = [options objectForKey:@"outputOptions"];
185 NSString * muxer = [outputOptions objectForKey:@"muxer"];
186 NSString * destination = [outputOptions objectForKey:@"destination"];
187 NSString * url = [outputOptions objectForKey:@"url"];
188 NSString * access = [outputOptions objectForKey:@"access"];
189 if( muxer ) [subOptions addObject:[NSString stringWithFormat:@"mux=%@", muxer]];
190 if( destination ) [subOptions addObject:[NSString stringWithFormat:@"dst=\"%@\"", [destination stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]];
191 if( url ) [subOptions addObject:[NSString stringWithFormat:@"url=\"%@\"", [url stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]]];
192 if( access ) [subOptions addObject:[NSString stringWithFormat:@"access=%@", access]];
193 [optionsAsArray addObject:[NSString stringWithFormat:@"std{%@}", [subOptions componentsJoinedByString:@","]]];
194 [subOptions removeAllObjects];
197 NSDictionary * rtpOptions = [options objectForKey:@"rtpOptions"];
200 NSString * muxer = [rtpOptions objectForKey:@"muxer"];
201 NSString * destination = [rtpOptions objectForKey:@"destination"];
202 NSString * sdp = [rtpOptions objectForKey:@"sdp"];
203 NSString * name = [rtpOptions objectForKey:@"name"];
204 NSString * sap = [rtpOptions objectForKey:@"sap"];
205 if( muxer ) [subOptions addObject:[NSString stringWithFormat:@"muxer=%@", muxer]];
206 if( destination ) [subOptions addObject:[NSString stringWithFormat:@"dst=%@", destination]];
207 if( sdp ) [subOptions addObject:[NSString stringWithFormat:@"sdp=%@", sdp]];
208 if( sap ) [subOptions addObject:@"sap"];
209 if( name ) [subOptions addObject:[NSString stringWithFormat:@"name=\"%@\"", name]];
210 [optionsAsArray addObject:[NSString stringWithFormat:@"rtp{%@}", [subOptions componentsJoinedByString:@","]]];
211 [subOptions removeAllObjects];
213 representedOptions = [optionsAsArray componentsJoinedByString:@":"];
214 return representedOptions;