1 /*****************************************************************************
2 * output.m: MacOS X Output Dialog
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: output.m,v 1.2 2003/05/10 10:32:29 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];
61 - (void)setTranscode:(NSString *)o_transcode_string
63 [o_transcode autorelease];
64 o_transcode = [o_transcode_string copy];
69 intf_thread_t * p_intf = [NSApp getIntf];
70 char * psz_sout = config_GetPsz( p_intf, "sout" );
72 if ( psz_sout != NULL && *psz_sout )
74 [o_output_ckbox setState: YES];
78 [o_output_ckbox setState: NO];
84 [[NSNotificationCenter defaultCenter] addObserver: self
85 selector: @selector(outputInfoChanged:)
86 name: NSControlTextDidChangeNotification
87 object: o_file_field];
88 [[NSNotificationCenter defaultCenter] addObserver: self
89 selector: @selector(outputInfoChanged:)
90 name: NSControlTextDidChangeNotification
91 object: o_stream_address];
92 [[NSNotificationCenter defaultCenter] addObserver: self
93 selector: @selector(outputInfoChanged:)
94 name: NSControlTextDidChangeNotification
95 object: o_stream_port];
96 [[NSNotificationCenter defaultCenter] addObserver: self
97 selector: @selector(TTLChanged:)
98 name: NSControlTextDidChangeNotification
99 object: o_stream_ttl];
100 [[NSNotificationCenter defaultCenter] addObserver: self
101 selector: @selector(transcodeInfoChanged:)
102 name: NSControlTextDidChangeNotification
103 object: o_transcode_video_bitrate];
104 [[NSNotificationCenter defaultCenter] addObserver: self
105 selector: @selector(transcodeInfoChanged:)
106 name: NSControlTextDidChangeNotification
107 object: o_transcode_audio_bitrate];
109 [o_mux_selector setAutoenablesItems: NO];
110 [self transcodeChanged:nil];
115 [o_output_ckbox setTitle: _NS("Advanced output:")];
116 [o_output_settings setTitle: _NS("Settings...")];
117 [o_btn_ok setTitle: _NS("OK")];
119 [o_options_lbl setTitle: _NS("Output Options")];
120 [o_display setTitle: _NS("Screen")];
121 [[o_method cellAtRow:0 column:0] setTitle: _NS("File")];
122 [[o_method cellAtRow:1 column:0] setTitle: _NS("Stream")];
123 [o_btn_browse setTitle: _NS("Browse...")];
124 [o_stream_address_lbl setStringValue: _NS("Address")];
125 [o_stream_port_lbl setStringValue: _NS("Port")];
126 [o_stream_ttl_lbl setStringValue: _NS("TTL")];
127 [[o_stream_type itemAtIndex: 0] setTitle: _NS("HTTP")];
128 [[o_stream_type itemAtIndex: 1] setTitle: _NS("UDP")];
129 [[o_stream_type itemAtIndex: 2] setTitle: _NS("RTP")];
130 [o_stream_type_lbl setStringValue: _NS("Type")];
132 [o_mux_lbl setStringValue: _NS("Encapsulation Method")];
133 [[o_mux_selector itemAtIndex: 0] setTitle: _NS("MPEG TS")];
134 [[o_mux_selector itemAtIndex: 1] setTitle: _NS("MPEG PS")];
135 [[o_mux_selector itemAtIndex: 2] setTitle: _NS("AVI")];
136 [[o_mux_selector itemAtIndex: 3] setTitle: _NS("Ogg")];
137 [[o_mux_selector itemAtIndex: 4] setTitle: _NS("mp4")];
139 [o_transcode_lbl setTitle: _NS("Transcode options")];
140 [o_transcode_video_chkbox setTitle: _NS("Video")];
141 [[o_transcode_video_selector itemAtIndex: 0] setTitle: @"mpgv"];
142 [[o_transcode_video_selector itemAtIndex: 1] setTitle: @"mp4v"];
143 [[o_transcode_video_selector itemAtIndex: 2] setTitle: @"DIV1"];
144 [[o_transcode_video_selector itemAtIndex: 3] setTitle: @"DIV2"];
145 [[o_transcode_video_selector itemAtIndex: 4] setTitle: @"DIV3"];
146 [[o_transcode_video_selector itemAtIndex: 5] setTitle: @"H263"];
147 [[o_transcode_video_selector itemAtIndex: 6] setTitle: @"I263"];
148 [[o_transcode_video_selector itemAtIndex: 7] setTitle: @"WMV1"];
149 [o_transcode_video_bitrate_lbl setStringValue: _NS("Bitrate (bps)")];
150 [o_transcode_audio_chkbox setTitle: _NS("Audio")];
151 [[o_transcode_audio_selector itemAtIndex: 0] setTitle: _NS("mpga")];
152 [[o_transcode_audio_selector itemAtIndex: 1] setTitle: _NS("a52 ")];
153 [o_transcode_audio_bitrate_lbl setStringValue: _NS("Bitrate (bps)")];
156 - (IBAction)outputChanged:(id)sender;
158 if ([o_output_ckbox state] == NSOnState)
160 [o_output_settings setEnabled:YES];
164 intf_thread_t * p_intf = [NSApp getIntf];
165 config_PutPsz( p_intf, "sout", NULL );
166 [o_output_settings setEnabled:NO];
170 - (IBAction)outputSettings:(id)sender
172 [NSApp beginSheet: o_output_sheet
173 modalForWindow: o_open_panel
179 - (IBAction)outputCloseSheet:(id)sender
181 intf_thread_t * p_intf = [NSApp getIntf];
182 config_PutPsz( p_intf, "sout", [o_mrl lossyCString] );
184 [o_output_sheet orderOut:sender];
185 [NSApp endSheet: o_output_sheet];
188 - (void)outputMethodChanged:(NSNotification *)o_notification
192 o_mode = [[o_method selectedCell] title];
194 if( [o_mode isEqualToString: _NS("File")] )
196 [o_file_field setEnabled: YES];
197 [o_btn_browse setEnabled: YES];
198 [o_stream_address setEnabled: NO];
199 [o_stream_port setEnabled: NO];
200 [o_stream_ttl setEnabled: NO];
201 [o_stream_port_stp setEnabled: NO];
202 [o_stream_ttl_stp setEnabled: NO];
203 [o_stream_type setEnabled: NO];
204 [o_mux_selector setEnabled: YES];
205 [[o_mux_selector itemAtIndex: 1] setEnabled: YES];
206 [[o_mux_selector itemAtIndex: 2] setEnabled: YES];
207 [[o_mux_selector itemAtIndex: 3] setEnabled: YES];
208 [[o_mux_selector itemAtIndex: 4] setEnabled: YES];
210 else if( [o_mode isEqualToString: _NS("Stream")] )
212 [o_file_field setEnabled: NO];
213 [o_btn_browse setEnabled: NO];
214 [o_stream_port setEnabled: YES];
215 [o_stream_port_stp setEnabled: YES];
216 [o_stream_type setEnabled: YES];
217 [o_mux_selector setEnabled: YES];
219 o_mode = [o_stream_type titleOfSelectedItem];
221 if( [o_mode isEqualToString: _NS("HTTP")] )
223 [o_stream_address setEnabled: YES];
224 [o_stream_ttl setEnabled: NO];
225 [o_stream_ttl_stp setEnabled: NO];
226 [[o_mux_selector itemAtIndex: 1] setEnabled: YES];
227 [[o_mux_selector itemAtIndex: 2] setEnabled: NO];
228 [[o_mux_selector itemAtIndex: 3] setEnabled: YES];
229 [[o_mux_selector itemAtIndex: 4] setEnabled: NO];
231 else if( [o_mode isEqualToString: _NS("UDP")] )
233 [o_stream_address setEnabled: YES];
234 [o_stream_ttl setEnabled: YES];
235 [o_stream_ttl_stp setEnabled: YES];
236 [[o_mux_selector itemAtIndex: 1] setEnabled: NO];
237 [[o_mux_selector itemAtIndex: 2] setEnabled: NO];
238 [[o_mux_selector itemAtIndex: 3] setEnabled: NO];
239 [[o_mux_selector itemAtIndex: 4] setEnabled: NO];
241 else if( [o_mode isEqualToString: _NS("RTP")] )
243 [o_stream_address setEnabled: YES];
244 [o_stream_ttl setEnabled: NO];
245 [o_stream_ttl_stp setEnabled: NO];
246 [[o_mux_selector itemAtIndex: 1] setEnabled: NO];
247 [[o_mux_selector itemAtIndex: 2] setEnabled: NO];
248 [[o_mux_selector itemAtIndex: 3] setEnabled: NO];
249 [[o_mux_selector itemAtIndex: 4] setEnabled: NO];
252 if( ![[o_mux_selector selectedItem] isEnabled] )
254 [o_mux_selector selectItemAtIndex: 0];
256 [self outputInfoChanged: nil];
259 - (void)outputInfoChanged:(NSNotification *)o_notification
261 NSString *o_mode, *o_mux, *o_mux_string;
262 NSMutableString *o_mrl_string = [NSMutableString stringWithString:@"#"];
264 if( [o_display state] == NSOnState )
266 [o_mrl_string appendString: @"display:"];
268 [o_mrl_string appendString: o_transcode];
270 o_mode = [[o_method selectedCell] title];
271 o_mux = [o_mux_selector titleOfSelectedItem];
273 if ( [o_mux isEqualToString: _NS("AVI")] ) o_mux_string = @"avi";
274 else if ( [o_mux isEqualToString: _NS("Ogg")] ) o_mux_string = @"ogg";
275 else if ( [o_mux isEqualToString: _NS("MPEG PS")] ) o_mux_string = @"ps";
276 else if ( [o_mux isEqualToString: _NS("mp4")] ) o_mux_string = @"mp4";
277 else o_mux_string = @"ts";
279 if( [o_mode isEqualToString: _NS("File")] )
281 [o_mrl_string appendFormat:
282 @"dst=std{access=file,mux=%@,url=\"%@\"},",
283 o_mux_string, [o_file_field stringValue]];
285 else if( [o_mode isEqualToString: _NS("Stream")] )
287 o_mode = [o_stream_type titleOfSelectedItem];
289 if ( [o_mode isEqualToString: _NS("HTTP")] ) o_mode = @"http";
290 else if ( [o_mode isEqualToString: _NS("UDP")] )
292 else if ( [o_mode isEqualToString: _NS("RTP")] )
295 [o_mrl_string appendFormat:
296 @"dst=std{access=%@,mux=%@,url=\"%@:%@\"},",
297 o_mode, o_mux_string, [o_stream_address stringValue],
298 [o_stream_port stringValue]];
300 [o_mrl_string appendString: @"}:"];
301 [self setMRL:o_mrl_string];
304 - (void)TTLChanged:(NSNotification *)o_notification
306 intf_thread_t * p_intf = [NSApp getIntf];
307 config_PutInt( p_intf, "ttl", [o_stream_ttl intValue] );
310 - (IBAction)outputFileBrowse:(id)sender
312 NSSavePanel *o_save_panel = [NSSavePanel savePanel];
313 NSString *o_mux_string;
314 if ( [[o_mux_selector titleOfSelectedItem] isEqualToString: _NS("MPEG PS")] )
315 o_mux_string = @"vob";
316 else if ( [[o_mux_selector titleOfSelectedItem] isEqualToString: _NS("AVI")] )
317 o_mux_string = @"avi";
318 else if ( [[o_mux_selector titleOfSelectedItem] isEqualToString: _NS("Ogg")] )
319 o_mux_string = @"ogm";
320 else if ( [[o_mux_selector titleOfSelectedItem] isEqualToString: _NS("mp4")] )
321 o_mux_string = @"mp4";
323 o_mux_string = @"ts";
325 NSString * o_name = [NSString stringWithFormat: @"vlc-output.%@",
328 [o_save_panel setTitle: _NS("Save File")];
329 [o_save_panel setPrompt: _NS("Save")];
331 if( [o_save_panel runModalForDirectory: nil
332 file: o_name] == NSOKButton )
334 NSString *o_filename = [o_save_panel filename];
335 [o_file_field setStringValue: o_filename];
336 [self outputInfoChanged: nil];
340 - (IBAction)streamPortStepperChanged:(id)sender
342 [o_stream_port setIntValue: [o_stream_port_stp intValue]];
343 [self outputInfoChanged: nil];
346 - (IBAction)streamTTLStepperChanged:(id)sender
348 [o_stream_ttl setIntValue: [o_stream_ttl_stp intValue]];
349 [self TTLChanged:nil];
352 - (void)transcodeChanged:(NSNotification *)o_notification
354 if( [o_transcode_video_chkbox state] == NSOnState )
356 [o_transcode_video_selector setEnabled: YES];
357 [o_transcode_video_bitrate setEnabled: YES];
361 [o_transcode_video_selector setEnabled: NO];
362 [o_transcode_video_bitrate setEnabled: NO];
364 if( [o_transcode_audio_chkbox state] == NSOnState )
366 [o_transcode_audio_selector setEnabled: YES];
367 [o_transcode_audio_bitrate setEnabled: YES];
371 [o_transcode_audio_selector setEnabled: NO];
372 [o_transcode_audio_bitrate setEnabled: NO];
375 [self transcodeInfoChanged:nil];
378 - (void)transcodeInfoChanged:(NSNotification *)o_notification
380 NSMutableString *o_transcode_string;
382 if( [o_transcode_video_chkbox state] == NSOnState ||
383 [o_transcode_audio_chkbox state] == NSOnState )
385 o_transcode_string = [NSMutableString stringWithString:@"transcode{"];
386 if ( [o_transcode_video_chkbox state] == NSOnState )
388 [o_transcode_string appendFormat: @"vcodec=\"%@\",vb=\"%@\",",
389 [o_transcode_video_selector titleOfSelectedItem],
390 [o_transcode_video_bitrate stringValue]];
392 if ( [o_transcode_audio_chkbox state] == NSOnState )
394 [o_transcode_string appendFormat: @"acodec=\"%@\",ab=\"%@\",",
395 [o_transcode_audio_selector titleOfSelectedItem],
396 [o_transcode_audio_bitrate stringValue]];
401 o_transcode_string = [NSString stringWithString:@"duplicate{"];
403 [self setTranscode: o_transcode_string];
404 [self outputInfoChanged:nil];