1 /*****************************************************************************
2 * output.m: MacOS X Output Dialog
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: output.m,v 1.15 2003/09/22 03:40:05 hartman Exp $
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * Derk-Jan Hartman <thedj@users.sourceforge.net>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <stdlib.h> /* malloc(), free() */
35 /*****************************************************************************
36 * VLCOutput implementation
37 *****************************************************************************/
38 @implementation VLCOutput
43 o_mrl = [[NSString alloc] init];
44 o_transcode = [[NSString alloc] init];
51 [o_transcode release];
55 - (void)setMRL:(NSString *)o_mrl_string
58 o_mrl = [o_mrl_string copy];
66 - (void)setTranscode:(NSString *)o_transcode_string
68 [o_transcode autorelease];
69 o_transcode = [o_transcode_string copy];
76 [[NSNotificationCenter defaultCenter] addObserver: self
77 selector: @selector(outputInfoChanged:)
78 name: NSControlTextDidChangeNotification
79 object: o_file_field];
80 [[NSNotificationCenter defaultCenter] addObserver: self
81 selector: @selector(outputInfoChanged:)
82 name: NSControlTextDidChangeNotification
83 object: o_stream_address];
84 [[NSNotificationCenter defaultCenter] addObserver: self
85 selector: @selector(outputInfoChanged:)
86 name: NSControlTextDidChangeNotification
87 object: o_stream_port];
88 [[NSNotificationCenter defaultCenter] addObserver: self
89 selector: @selector(TTLChanged:)
90 name: NSControlTextDidChangeNotification
91 object: o_stream_ttl];
92 [[NSNotificationCenter defaultCenter] addObserver: self
93 selector: @selector(transcodeInfoChanged:)
94 name: NSControlTextDidChangeNotification
95 object: o_transcode_video_bitrate];
96 [[NSNotificationCenter defaultCenter] addObserver: self
97 selector: @selector(transcodeInfoChanged:)
98 name: NSControlTextDidChangeNotification
99 object: o_transcode_audio_bitrate];
100 [[NSNotificationCenter defaultCenter] addObserver: self
101 selector: @selector(transcodeInfoChanged:)
102 name: NSControlTextDidChangeNotification
103 object: o_transcode_audio_channels];
104 [[NSNotificationCenter defaultCenter] addObserver: self
105 selector: @selector(transcodeInfoChanged:)
106 name: NSControlTextDidChangeNotification
109 [o_mux_selector setAutoenablesItems: NO];
110 [self transcodeChanged:nil];
115 NSArray *o_muxers = [NSArray arrayWithObjects: @"MPEG TS", @"MPEG PS", @"MPEG 1",
116 @"Ogg", @"AVI", @"ASF", @"MPEG 4", @"Quicktime", nil];
117 NSArray *o_a_channels = [NSArray arrayWithObjects: @"1", @"2", @"4", @"6", nil];
118 NSArray *o_a_bitrates = [NSArray arrayWithObjects: @"96", @"128", @"192", @"256", @"512", nil];
119 NSArray *o_v_bitrates = [NSArray arrayWithObjects:
120 @"100", @"150", @"200", @"400", @"500", @"750", @"1000", @"2000", @"3000", nil];
121 NSArray *o_a_codecs = [NSArray arrayWithObjects:
122 @"mpga", @"mp3 ", @"a52 ", @"vorb", nil];
123 NSArray *o_v_codecs = [NSArray arrayWithObjects:
124 @"mp1v", @"mp2v", @"mp4v", @"DIV1", @"DIV2", @"DIV3", @"H263", @"I263", @"WMV1", @"WMV2", @"MJPG", nil];
126 [o_output_ckbox setTitle: _NS("Advanced output:")];
127 [o_output_settings setTitle: _NS("Settings...")];
128 [o_btn_ok setTitle: _NS("OK")];
130 [o_options_lbl setTitle: _NS("Output Options")];
131 [o_display setTitle: _NS("Screen")];
132 [[o_method cellAtRow:0 column:0] setTitle: _NS("File")];
133 [[o_method cellAtRow:1 column:0] setTitle: _NS("Stream")];
134 [o_btn_browse setTitle: _NS("Browse...")];
135 [o_stream_address_lbl setStringValue: _NS("Address")];
136 [o_stream_port_lbl setStringValue: _NS("Port")];
137 [o_stream_ttl_lbl setStringValue: _NS("TTL")];
138 [[o_stream_type itemAtIndex: 0] setTitle: _NS("HTTP")];
139 [[o_stream_type itemAtIndex: 1] setTitle: _NS("MMSH")];
140 [[o_stream_type itemAtIndex: 2] setTitle: _NS("UDP")];
141 [[o_stream_type itemAtIndex: 3] setTitle: _NS("RTP")];
142 [o_stream_type_lbl setStringValue: _NS("Type")];
144 [o_mux_lbl setStringValue: _NS("Encapsulation Method")];
145 [o_mux_selector removeAllItems];
146 [o_mux_selector addItemsWithTitles: o_muxers];
148 [o_transcode_lbl setTitle: _NS("Transcode options")];
149 [o_transcode_video_chkbox setTitle: _NS("Video")];
150 [o_transcode_video_selector removeAllItems];
151 [o_transcode_video_selector addItemsWithTitles: o_v_codecs];
152 [o_transcode_video_bitrate_lbl setStringValue: _NS("Bitrate (kb/s)")];
153 [o_transcode_video_bitrate removeAllItems];
154 [o_transcode_video_bitrate addItemsWithObjectValues: o_v_bitrates];
155 [o_transcode_audio_chkbox setTitle: _NS("Audio")];
156 [o_transcode_audio_selector removeAllItems];
157 [o_transcode_audio_selector addItemsWithTitles: o_a_codecs];
158 [o_transcode_audio_bitrate_lbl setStringValue: _NS("Bitrate (kb/s)")];
159 [o_transcode_audio_bitrate removeAllItems];
160 [o_transcode_audio_bitrate addItemsWithObjectValues: o_a_bitrates];
161 [o_transcode_audio_channels_lbl setStringValue: _NS("Channels")];
162 [o_transcode_audio_channels removeAllItems];
163 [o_transcode_audio_channels addItemsWithObjectValues: o_a_channels];
165 [o_misc_lbl setTitle: _NS("Miscellaneous Options")];
166 [o_sap_chkbox setTitle: _NS("Announce streams via SAP Channel:")];
169 - (IBAction)outputChanged:(id)sender;
171 if ([o_output_ckbox state] == NSOnState)
173 [o_output_settings setEnabled:YES];
177 [o_output_settings setEnabled:NO];
181 - (IBAction)outputSettings:(id)sender
183 [NSApp beginSheet: o_output_sheet
184 modalForWindow: o_open_panel
190 - (IBAction)outputCloseSheet:(id)sender
192 [o_output_sheet orderOut:sender];
193 [NSApp endSheet: o_output_sheet];
196 - (void)outputMethodChanged:(NSNotification *)o_notification
199 o_mode = [[o_method selectedCell] title];
201 [o_sap_chkbox setEnabled: NO];
202 [o_sap_name setEnabled: NO];
203 [[o_mux_selector itemAtIndex: 0] setEnabled: YES];
205 if( [o_mode isEqualToString: _NS("File")] )
207 [o_file_field setEnabled: YES];
208 [o_btn_browse setEnabled: YES];
209 [o_stream_address setEnabled: NO];
210 [o_stream_port setEnabled: NO];
211 [o_stream_ttl setEnabled: NO];
212 [o_stream_port_stp setEnabled: NO];
213 [o_stream_ttl_stp setEnabled: NO];
214 [o_stream_type setEnabled: NO];
215 [o_mux_selector setEnabled: YES];
216 [[o_mux_selector itemAtIndex: 1] setEnabled: YES]; // MPEG PS
217 [[o_mux_selector itemAtIndex: 2] setEnabled: YES]; // MPEG 1
218 [[o_mux_selector itemAtIndex: 3] setEnabled: YES]; // Ogg
219 [[o_mux_selector itemAtIndex: 4] setEnabled: YES]; // AVI
220 [[o_mux_selector itemAtIndex: 5] setEnabled: YES]; // ASF
221 [[o_mux_selector itemAtIndex: 6] setEnabled: YES]; // MPEG 4
222 [[o_mux_selector itemAtIndex: 7] setEnabled: YES]; // QuickTime
224 else if( [o_mode isEqualToString: _NS("Stream")] )
226 [o_file_field setEnabled: NO];
227 [o_btn_browse setEnabled: NO];
228 [o_stream_port setEnabled: YES];
229 [o_stream_port_stp setEnabled: YES];
230 [o_stream_type setEnabled: YES];
231 [o_mux_selector setEnabled: YES];
233 o_mode = [o_stream_type titleOfSelectedItem];
235 if( [o_mode isEqualToString: _NS("HTTP")] )
237 [o_stream_address setEnabled: YES];
238 [o_stream_ttl setEnabled: NO];
239 [o_stream_ttl_stp setEnabled: NO];
240 [[o_mux_selector itemAtIndex: 1] setEnabled: YES];
241 [[o_mux_selector itemAtIndex: 2] setEnabled: YES];
242 [[o_mux_selector itemAtIndex: 3] setEnabled: YES];
243 [[o_mux_selector itemAtIndex: 4] setEnabled: NO];
244 [[o_mux_selector itemAtIndex: 5] setEnabled: NO];
245 [[o_mux_selector itemAtIndex: 6] setEnabled: NO];
246 [[o_mux_selector itemAtIndex: 7] setEnabled: NO];
248 else if( [o_mode isEqualToString: _NS("MMSH")] )
250 [o_stream_address setEnabled: YES];
251 [o_stream_ttl setEnabled: NO];
252 [o_stream_ttl_stp setEnabled: NO];
253 [[o_mux_selector itemAtIndex: 0] setEnabled: NO];
254 [[o_mux_selector itemAtIndex: 1] setEnabled: NO];
255 [[o_mux_selector itemAtIndex: 2] setEnabled: NO];
256 [[o_mux_selector itemAtIndex: 3] setEnabled: NO];
257 [[o_mux_selector itemAtIndex: 4] setEnabled: NO];
258 [[o_mux_selector itemAtIndex: 5] setEnabled: YES];
259 [[o_mux_selector itemAtIndex: 6] setEnabled: NO];
260 [[o_mux_selector itemAtIndex: 7] setEnabled: NO];
262 else if( [o_mode isEqualToString: _NS("UDP")] )
264 [o_stream_address setEnabled: YES];
265 [o_stream_ttl setEnabled: YES];
266 [o_stream_ttl_stp setEnabled: YES];
267 [[o_mux_selector itemAtIndex: 1] setEnabled: NO];
268 [[o_mux_selector itemAtIndex: 2] setEnabled: NO];
269 [[o_mux_selector itemAtIndex: 3] setEnabled: NO];
270 [[o_mux_selector itemAtIndex: 4] setEnabled: NO];
271 [[o_mux_selector itemAtIndex: 5] setEnabled: NO];
272 [[o_mux_selector itemAtIndex: 6] setEnabled: NO];
273 [[o_mux_selector itemAtIndex: 7] setEnabled: NO];
274 [o_sap_chkbox setEnabled: YES];
275 [o_sap_name setEnabled: YES];
277 else if( [o_mode isEqualToString: _NS("RTP")] )
279 [o_stream_address setEnabled: YES];
280 [o_stream_ttl setEnabled: YES];
281 [o_stream_ttl_stp setEnabled: YES];
282 [[o_mux_selector itemAtIndex: 1] setEnabled: NO];
283 [[o_mux_selector itemAtIndex: 2] setEnabled: NO];
284 [[o_mux_selector itemAtIndex: 3] setEnabled: NO];
285 [[o_mux_selector itemAtIndex: 4] setEnabled: NO];
286 [[o_mux_selector itemAtIndex: 5] setEnabled: NO];
287 [[o_mux_selector itemAtIndex: 6] setEnabled: NO];
288 [[o_mux_selector itemAtIndex: 7] setEnabled: NO];
291 if( ![[o_mux_selector selectedItem] isEnabled] )
293 [o_mux_selector selectItemAtIndex: 0];
295 [self outputInfoChanged: nil];
298 - (void)outputInfoChanged:(NSNotification *)o_notification
300 NSString *o_mode, *o_mux, *o_mux_string, *o_sap;
301 NSMutableString *o_mrl_string = [NSMutableString stringWithString:@"#"];
303 [o_mrl_string appendString: o_transcode];
304 if( [o_display state] == NSOnState )
306 [o_mrl_string appendString: @"duplicate{dst=display,dst="];
309 o_mode = [[o_method selectedCell] title];
310 o_mux = [o_mux_selector titleOfSelectedItem];
312 if ( [o_mux isEqualToString: _NS("AVI")] ) o_mux_string = @"avi";
313 else if ( [o_mux isEqualToString: _NS("Ogg")] ) o_mux_string = @"ogg";
314 else if ( [o_mux isEqualToString: _NS("MPEG PS")] ) o_mux_string = @"ps";
315 else if ( [o_mux isEqualToString: _NS("MPEG 4")] ) o_mux_string = @"mp4";
316 else if ( [o_mux isEqualToString: _NS("MPEG 1")] ) o_mux_string = @"mpeg1";
317 else if ( [o_mux isEqualToString: _NS("Quicktime")] ) o_mux_string = @"mov";
318 else if ( [o_mux isEqualToString: _NS("ASF")] ) o_mux_string = @"asf";
319 else o_mux_string = @"ts";
321 if( [o_mode isEqualToString: _NS("File")] )
323 [o_mrl_string appendFormat:
324 @"std{access=file,mux=%@,url=\"%@\"}",
325 o_mux_string, [o_file_field stringValue]];
327 else if( [o_mode isEqualToString: _NS("Stream")] )
329 o_mode = [o_stream_type titleOfSelectedItem];
332 if ( [o_mode isEqualToString: _NS("HTTP")] )
334 else if ( [o_mode isEqualToString: _NS("MMSH")] )
336 if ( [o_mux isEqualToString: _NS("ASF")] ) o_mux_string = @"asfh";
339 else if ( [o_mode isEqualToString: _NS("UDP")] )
342 if( [o_sap_chkbox state] == NSOnState )
345 if ( ![[o_sap_name stringValue] isEqualToString: @""] )
346 o_sap = [NSString stringWithFormat:@",sap=%@", [o_sap_name stringValue]];
349 else if ( [o_mode isEqualToString: _NS("RTP")] )
352 [o_mrl_string appendFormat:
353 @"std{access=%@,mux=%@,url=\"%@:%@\"%@}",
354 o_mode, o_mux_string, [o_stream_address stringValue],
355 [o_stream_port stringValue], o_sap];
357 if( [o_display state] == NSOnState )
359 [o_mrl_string appendString: @"}"];
361 [self setMRL:o_mrl_string];
364 - (void)TTLChanged:(NSNotification *)o_notification
366 intf_thread_t * p_intf = [NSApp getIntf];
367 config_PutInt( p_intf, "ttl", [o_stream_ttl intValue] );
370 - (IBAction)outputFileBrowse:(id)sender
372 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
373 NSString *o_mux_string;
374 if ( [[o_mux_selector titleOfSelectedItem] isEqualToString: _NS("MPEG PS")] )
375 o_mux_string = @"vob";
376 else if ( [[o_mux_selector titleOfSelectedItem] isEqualToString: _NS("MPEG 1")] )
377 o_mux_string = @"mpg";
378 else if ( [[o_mux_selector titleOfSelectedItem] isEqualToString: _NS("AVI")] )
379 o_mux_string = @"avi";
380 else if ( [[o_mux_selector titleOfSelectedItem] isEqualToString: _NS("ASF")] )
381 o_mux_string = @"asf";
382 else if ( [[o_mux_selector titleOfSelectedItem] isEqualToString: _NS("Ogg")] )
383 o_mux_string = @"ogm";
384 else if ( [[o_mux_selector titleOfSelectedItem] isEqualToString: _NS("MPEG 4")] )
385 o_mux_string = @"mp4";
386 else if ( [[o_mux_selector titleOfSelectedItem] isEqualToString: _NS("Quicktime")] )
387 o_mux_string = @"mov";
389 o_mux_string = @"ts";
391 NSString * o_name = [NSString stringWithFormat: @"vlc-output.%@",
394 [o_save_panel setTitle: _NS("Save File")];
395 [o_save_panel setPrompt: _NS("Save")];
397 if( [o_save_panel runModalForDirectory: nil
398 file: o_name] == NSOKButton )
400 NSString *o_filename = [o_save_panel filename];
401 [o_file_field setStringValue: o_filename];
402 [self outputInfoChanged: nil];
406 - (IBAction)streamPortStepperChanged:(id)sender
408 [o_stream_port setIntValue: [o_stream_port_stp intValue]];
409 [self outputInfoChanged: nil];
412 - (IBAction)streamTTLStepperChanged:(id)sender
414 [o_stream_ttl setIntValue: [o_stream_ttl_stp intValue]];
415 [self TTLChanged:nil];
418 - (void)transcodeChanged:(NSNotification *)o_notification
420 if( [o_transcode_video_chkbox state] == NSOnState )
422 [o_transcode_video_selector setEnabled: YES];
423 [o_transcode_video_bitrate setEnabled: YES];
427 [o_transcode_video_selector setEnabled: NO];
428 [o_transcode_video_bitrate setEnabled: NO];
430 if( [o_transcode_audio_chkbox state] == NSOnState )
432 [o_transcode_audio_selector setEnabled: YES];
433 [o_transcode_audio_bitrate setEnabled: YES];
434 [o_transcode_audio_channels setEnabled: YES];
438 [o_transcode_audio_selector setEnabled: NO];
439 [o_transcode_audio_bitrate setEnabled: NO];
440 [o_transcode_audio_channels setEnabled: NO];
443 [self transcodeInfoChanged:nil];
446 - (void)transcodeInfoChanged:(NSNotification *)o_notification
448 NSMutableString *o_transcode_string;
450 if( [o_transcode_video_chkbox state] == NSOnState ||
451 [o_transcode_audio_chkbox state] == NSOnState )
453 o_transcode_string = [NSMutableString stringWithString:@"transcode{"];
454 if ( [o_transcode_video_chkbox state] == NSOnState )
456 [o_transcode_string appendFormat: @"vcodec=\"%@\",vb=\"%@\"",
457 [o_transcode_video_selector titleOfSelectedItem],
458 [o_transcode_video_bitrate stringValue]];
459 if ( [o_transcode_audio_chkbox state] == NSOnState )
461 [o_transcode_string appendString: @","];
464 if ( [o_transcode_audio_chkbox state] == NSOnState )
466 [o_transcode_string appendFormat: @"acodec=\"%@\",ab=\"%@\"",
467 [o_transcode_audio_selector titleOfSelectedItem],
468 [o_transcode_audio_bitrate stringValue]];
470 [o_transcode_string appendString:@"}:"];
474 o_transcode_string = [NSString stringWithString:@""];
476 [self setTranscode: o_transcode_string];
477 [self outputInfoChanged:nil];
480 - (IBAction)sapChanged:(id)sender
482 [o_sap_name setEnabled: [o_sap_chkbox state]];
483 [self outputInfoChanged: nil];