]> git.sesse.net Git - vlc/blob - modules/gui/macosx/ConvertAndSave.m
macosx: robustify media key trap handling
[vlc] / modules / gui / macosx / ConvertAndSave.m
1 /*****************************************************************************
2  * ConvertAndSave.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2012 Felix Paul Kühne
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #import "ConvertAndSave.h"
25 #import "intf.h"
26 #import "playlist.h"
27 #import <vlc_common.h>
28 #import <vlc_url.h>
29
30 /* mini doc:
31  * the used NSMatrix includes a bunch of cells referenced most easily by tags. There you go: */
32 #define MPEGTS 0
33 #define WEBM 1
34 #define OGG 2
35 #define MP4 3
36 #define MPEGPS 4
37 #define MJPEG 5
38 #define WAV 6
39 #define FLV 7
40 #define MPEG1 8
41 #define MKV 9
42 #define RAW 10
43 #define AVI 11
44 #define ASF 12
45 /* 13-15 are present, but not set */
46
47 @interface VLCConvertAndSave (Internal)
48 - (void)updateDropView;
49 - (void)updateOKButton;
50 - (void)resetCustomizationSheetBasedOnProfile:(NSString *)profileString;
51 - (void)selectCellByEncapsulationFormat:(NSString *)format;
52 - (NSString *)currentEncapsulationFormatAsFileExtension:(BOOL)b_extension;
53 - (NSString *)composedOptions;
54 - (void)updateCurrentProfile;
55 - (void)storeProfilesOnDisk;
56 - (void)recreateProfilePopup;
57 @end
58
59 @implementation VLCConvertAndSave
60
61 @synthesize MRL=_MRL, outputDestination=_outputDestination, profileNames=_profileNames, profileValueList=_profileValueList, currentProfile=_currentProfile;
62
63 @synthesize vidBitrate, vidFramerate, audBitrate, audChannels;
64
65 static VLCConvertAndSave *_o_sharedInstance = nil;
66
67 #pragma mark -
68 #pragma mark Initialization
69
70 + (void)initialize
71 {
72     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
73
74     /* We are using the same format as the Qt4 intf here:
75      * Container(string), transcode video(bool), transcode audio(bool),
76      * use subtitles(bool), video codec(string), video bitrate(integer),
77      * scale(float), fps(float), width(integer, height(integer),
78      * audio codec(string), audio bitrate(integer), channels(integer),
79      * samplerate(integer), subtitle codec(string), subtitle overlay(bool) */
80     NSArray * defaultProfiles = [[NSArray alloc] initWithObjects:
81                                  @"mp4;1;1;0;h264;0;0;0;0;0;mpga;128;2;44100;0;1",
82                                  @"webm;1;1;0;VP80;2000;0;0;0;0;vorb;128;2;44100;0;1",
83                                  @"ts;1;1;0;h264;800;1;0;0;0;mpga;128;2;44100;0;0",
84                                  @"ts;1;1;0;drac;800;1;0;0;0;mpga;128;2;44100;0;0",
85                                  @"ogg;1;1;0;theo;800;1;0;0;0;vorb;128;2;44100;0;0",
86                                  @"ogg;1;1;0;theo;800;1;0;0;0;flac;128;2;44100;0;0",
87                                  @"ts;1;1;0;mp2v;800;1;0;0;0;mpga;128;2;44100;0;0",
88                                  @"asf;1;1;0;WMV2;800;1;0;0;0;wma2;128;2;44100;0;0",
89                                  @"asf;1;1;0;DIV3;800;1;0;0;0;mp3;128;2;44100;0;0",
90                                  @"ogg;0;1;0;none;800;1;0;0;0;vorb;128;2;44100;none;0",
91                                  @"raw;0;1;0;none;800;1;0;0;0;mp3;128;2;44100;none;0",
92                                  @"mp4;0;1;0;none;800;1;0;0;0;mpga;128;2;44100;none;0",
93                                  @"raw;0;1;0;none;800;1;0;0;0;flac;128;2;44100;none;0",
94                                  @"wav;0;1;0;none;800;1;0;0;0;s16l;128;2;44100;none;0", nil];
95
96     NSArray * defaultProfileNames = [[NSArray alloc] initWithObjects:
97                                      @"Video - H.264 + MP3 (MP4)",
98                                      @"Video - VP80 + Vorbis (Webm)",
99                                      @"Video - H.264 + MP3 (TS)",
100                                      @"Video - Dirac + MP3 (TS)",
101                                      @"Video - Theora + Vorbis (OGG)",
102                                      @"Video - Theora + Flac (OGG)",
103                                      @"Video - MPEG-2 + MPGA (TS)",
104                                      @"Video - WMV + WMA (ASF)",
105                                      @"Video - DIV3 + MP3 (ASF)",
106                                      @"Audio - Vorbis (OGG)",
107                                      @"Audio - MP3",
108                                      @"Audio - MP3 (MP4)",
109                                      @"Audio - FLAC",
110                                      @"Audio - CD",
111                                      nil];
112
113     NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:defaultProfiles, @"CASProfiles", defaultProfileNames, @"CASProfileNames", nil];
114
115     [defaults registerDefaults:appDefaults];
116     [defaultProfiles release];
117     [defaultProfileNames release];
118 }
119
120 + (VLCConvertAndSave *)sharedInstance
121 {
122     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
123 }
124
125 - (id)init
126 {
127     if (_o_sharedInstance) {
128         [self dealloc];
129     } else {
130         _o_sharedInstance = [super init];
131     }
132
133     return _o_sharedInstance;
134 }
135
136 - (void)dealloc
137 {
138     if (_currentProfile)
139         [_currentProfile release];
140
141     [_profileNames release];
142     [_profileValueList release];
143     [_videoCodecs release];
144     [_audioCodecs release];
145     [_subsCodecs release];
146
147     [super dealloc];
148 }
149
150 - (void)awakeFromNib
151 {
152     [_window setTitle: _NS("Convert & Stream")];
153     [_ok_btn setTitle: _NS("Go!")];
154     [_drop_lbl setStringValue: _NS("Drop media here")];
155     [_drop_btn setTitle: _NS("Open media...")];
156     [_profile_lbl setStringValue: _NS("Choose Profile")];
157     [_profile_btn setTitle: _NS("Customize...")];
158     [_destination_lbl setStringValue: _NS("Choose Destination")];
159     [_destination_filename_stub_lbl setStringValue: _NS("Choose an output location")];
160     [_destination_filename_lbl setHidden: YES];
161     [_destination_browse_btn setTitle:_NS("Browse...")];
162     [_destination_stream_btn setTitle:_NS("Setup Streaming...")];
163     [_destination_stream_lbl setStringValue:@"Select Streaming Method"];
164     [_destination_itwantafile_btn setTitle:_NS("Save as File")];
165     [_destination_itwantastream_btn setTitle:_NS("Stream")];
166     [_destination_cancel_btn setHidden:YES];
167     [_customize_ok_btn setTitle: _NS("Apply")];
168     [_customize_cancel_btn setTitle: _NS("Cancel")];
169     [_customize_newProfile_btn setTitle: _NS("Save as new Profile...")];
170     [[_customize_tabview tabViewItemAtIndex:0] setLabel: _NS("Encapsulation")];
171     [[_customize_tabview tabViewItemAtIndex:1] setLabel: _NS("Video codec")];
172     [[_customize_tabview tabViewItemAtIndex:2] setLabel: _NS("Audio codec")];
173     [[_customize_tabview tabViewItemAtIndex:3] setLabel: _NS("Subtitles")];
174     [_customize_tabview selectTabViewItemAtIndex: 0];
175     [_customize_vid_ckb setTitle: _NS("Video")];
176     [_customize_vid_keep_ckb setTitle: _NS("Keep original video track")];
177     [_customize_vid_codec_lbl setStringValue: _NS("Codec")];
178     [_customize_vid_bitrate_lbl setStringValue: _NS("Bitrate")];
179     [_customize_vid_framerate_lbl setStringValue: _NS("Frame rate")];
180     [_customize_vid_res_box setTitle: _NS("Resolution")];
181     [_customize_vid_res_lbl setStringValue: _NS("You just need to fill one of the three following parameters, VLC will autodetect the other using the original aspect ratio")];
182     [_customize_vid_width_lbl setStringValue: _NS("Width")];
183     [_customize_vid_height_lbl setStringValue: _NS("Height")];
184     [_customize_vid_scale_lbl setStringValue: _NS("Scale")];
185     [_customize_aud_ckb setTitle: _NS("Audio")];
186     [_customize_aud_keep_ckb setTitle: _NS("Keep original audio track")];
187     [_customize_aud_codec_lbl setStringValue: _NS("Codec")];
188     [_customize_aud_bitrate_lbl setStringValue: _NS("Bitrate")];
189     [_customize_aud_channels_lbl setStringValue: _NS("Channels")];
190     [_customize_aud_samplerate_lbl setStringValue: _NS("Samplerate")];
191     [_customize_subs_ckb setTitle: _NS("Subtitles")];
192     [_customize_subs_overlay_ckb setTitle: _NS("Overlay subtitles on the video")];
193     [_stream_ok_btn setTitle: _NS("Apply")];
194     [_stream_cancel_btn setTitle: _NS("Cancel")];
195     [_stream_destination_lbl setStringValue:_NS("Stream Destination")];
196     [_stream_announcement_lbl setStringValue:_NS("Stream Announcement")];
197     [_stream_type_lbl setStringValue:_NS("Type")];
198     [_stream_address_lbl setStringValue:_NS("Address")];
199     [_stream_ttl_lbl setStringValue:_NS("TTL")];
200     [_stream_ttl_fld setEnabled:NO];
201     [_stream_ttl_stepper setEnabled:NO];
202     [_stream_port_lbl setStringValue:_NS("Port")];
203     [_stream_sap_ckb setStringValue:_NS("SAP Announcement")];
204     [[_stream_sdp_matrix cellWithTag:0] setTitle:_NS("None")];
205     [[_stream_sdp_matrix cellWithTag:1] setTitle:_NS("HTTP Announcement")];
206     [[_stream_sdp_matrix cellWithTag:2] setTitle:_NS("RTSP Announcement")];
207     [[_stream_sdp_matrix cellWithTag:3] setTitle:_NS("Export SDP as file")];
208     [_stream_sap_ckb setState:NSOffState];
209     [_stream_sdp_matrix setEnabled:NO];
210
211     /* there is no way to hide single cells, so replace the existing ones with empty cells.. */
212     id blankCell = [[[NSCell alloc] init] autorelease];
213     [blankCell setEnabled:NO];
214     [_customize_encap_matrix putCell:blankCell atRow:3 column:1];
215     [_customize_encap_matrix putCell:blankCell atRow:3 column:2];
216     [_customize_encap_matrix putCell:blankCell atRow:3 column:3];
217
218     /* fetch profiles from defaults */
219     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
220     [self setProfileValueList: [defaults arrayForKey:@"CASProfiles"]];
221     [self setProfileNames: [defaults arrayForKey:@"CASProfileNames"]];
222     [self recreateProfilePopup];
223
224     _videoCodecs = [[NSArray alloc] initWithObjects:
225                     [NSArray arrayWithObjects:@"MPEG-1", @"MPEG-2", @"MPEG-4", @"DIVX 1", @"DIVX 2", @"DIVX 3", @"H.263", @"H.264", @"VP8", @"WMV1", @"WMV2", @"M-JPEG", @"Theora", @"Dirac", nil],
226                     [NSArray arrayWithObjects:@"mpgv", @"mp2v", @"mp4v", @"DIV1", @"DIV2", @"DIV3", @"H263", @"h264", @"VP80", @"WMV1", @"WMV2", @"MJPG", @"theo", @"drac", nil],
227                     nil];
228     _audioCodecs = [[NSArray alloc] initWithObjects:
229                     [NSArray arrayWithObjects:@"MPEG Audio", @"MP3", @"MPEG 4 Audio (AAC)", @"A52/AC-3", @"Vorbis", @"Flac", @"Speex", @"WAV", @"WMA2", nil],
230                     [NSArray arrayWithObjects:@"mpga", @"mp3", @"mp4a", @"a52", @"vorb", @"flac", @"spx", @"s16l", @"wma2", nil],
231                     nil];
232     _subsCodecs = [[NSArray alloc] initWithObjects:
233                    [NSArray arrayWithObjects:@"DVB subtitle", @"T.140", nil],
234                    [NSArray arrayWithObjects:@"dvbs", @"t140", nil],
235                     nil];
236
237     [_customize_vid_codec_pop removeAllItems];
238     [_customize_vid_scale_pop removeAllItems];
239     [_customize_aud_codec_pop removeAllItems];
240     [_customize_aud_samplerate_pop removeAllItems];
241     [_customize_subs_pop removeAllItems];
242
243     [_customize_vid_codec_pop addItemsWithTitles:[_videoCodecs objectAtIndex:0]];
244     [_customize_aud_codec_pop addItemsWithTitles:[_audioCodecs objectAtIndex:0]];
245     [_customize_subs_pop addItemsWithTitles:[_subsCodecs objectAtIndex:0]];
246
247     [_customize_aud_samplerate_pop addItemWithTitle:@"8000"];
248     [_customize_aud_samplerate_pop addItemWithTitle:@"11025"];
249     [_customize_aud_samplerate_pop addItemWithTitle:@"22050"];
250     [_customize_aud_samplerate_pop addItemWithTitle:@"44100"];
251     [_customize_aud_samplerate_pop addItemWithTitle:@"48000"];
252
253     [_customize_vid_scale_pop addItemWithTitle:@"1"];
254     [_customize_vid_scale_pop addItemWithTitle:@"0.25"];
255     [_customize_vid_scale_pop addItemWithTitle:@"0.5"];
256     [_customize_vid_scale_pop addItemWithTitle:@"0.75"];
257     [_customize_vid_scale_pop addItemWithTitle:@"1.25"];
258     [_customize_vid_scale_pop addItemWithTitle:@"1.5"];
259     [_customize_vid_scale_pop addItemWithTitle:@"1.75"];
260     [_customize_vid_scale_pop addItemWithTitle:@"2"];
261
262     [_ok_btn setEnabled: NO];
263
264     // setup drop view
265     [_drop_box enablePlaylistItems];
266     [_drop_box setDropHandler: self];
267
268     [self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:0]];
269 }
270
271 # pragma mark -
272 # pragma mark Code to Communicate with other objects
273
274 - (void)toggleWindow
275 {
276     [_window makeKeyAndOrderFront: nil];
277 }
278
279 # pragma mark -
280 # pragma mark User Interaction
281
282 - (IBAction)finalizePanel:(id)sender
283 {
284     if (b_streaming) {
285         if ([[[_stream_type_pop selectedItem] title] isEqualToString:@"HTTP"]) {
286             NSString *muxformat = [self.currentProfile objectAtIndex:0];
287             if ([muxformat isEqualToString:@"wav"] || [muxformat isEqualToString:@"mov"] || [muxformat isEqualToString:@"mp4"] || [muxformat isEqualToString:@"mkv"]) {
288                 NSBeginInformationalAlertSheet(_NS("Invalid container format for HTTP streaming"), _NS("OK"), @"", @"", _window,
289                                                nil, nil, nil, nil,
290                                                _NS("Media encapsulated as %@ cannot be streamed through the HTTP protocol for technical reasons."),
291                                                [[self currentEncapsulationFormatAsFileExtension:YES] uppercaseString]);
292                 return;
293             }
294         }
295     }
296
297     playlist_t * p_playlist = pl_Get(VLCIntf);
298
299     input_item_t *p_input = input_item_New([_MRL UTF8String], [[_dropin_media_lbl stringValue] UTF8String]);
300     if (!p_input)
301         return;
302
303     input_item_AddOption(p_input, [[self composedOptions] UTF8String], VLC_INPUT_OPTION_TRUSTED);
304     if (b_streaming)
305         input_item_AddOption(p_input, [[NSString stringWithFormat:@"ttl=%@", [_stream_ttl_fld stringValue]] UTF8String], VLC_INPUT_OPTION_TRUSTED);
306
307     int returnValue;
308     returnValue = playlist_AddInput(p_playlist, p_input, PLAYLIST_STOP, PLAYLIST_END, true, pl_Unlocked);
309
310     if (returnValue == VLC_SUCCESS) {
311         /* let's "play" */
312         PL_LOCK;
313         playlist_item_t *p_item = playlist_ItemGetByInput(p_playlist, p_input);
314         playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, NULL,
315                          p_item);
316         PL_UNLOCK;
317     }
318     else
319         msg_Err(VLCIntf, "CAS: playlist add input failed :(");
320
321     /* we're done with this input */
322     vlc_gc_decref(p_input);
323
324     [_window performClose:sender];
325 }
326
327 - (IBAction)openMedia:(id)sender
328 {
329     /* preliminary implementation until the open panel is cleaned up */
330     NSOpenPanel * openPanel = [NSOpenPanel openPanel];
331     [openPanel setCanChooseDirectories:NO];
332     [openPanel setResolvesAliases:YES];
333     [openPanel setAllowsMultipleSelection:NO];
334     [openPanel beginSheetModalForWindow:_window completionHandler:^(NSInteger returnCode) {
335         if (returnCode == NSOKButton)
336         {
337             [self setMRL: [NSString stringWithUTF8String:vlc_path2uri([[[openPanel URL] path] UTF8String], NULL)]];
338             [self updateOKButton];
339             [self updateDropView];
340         }
341     }];
342 }
343
344 - (IBAction)switchProfile:(id)sender
345 {
346     NSUInteger index = [_profile_pop indexOfSelectedItem];
347     // last index is "custom"
348     if (index <= ([self.profileValueList count] - 1))
349         [self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:index]];
350 }
351
352 - (IBAction)customizeProfile:(id)sender
353 {
354     [NSApp beginSheet:_customize_panel modalForWindow:_window modalDelegate:self didEndSelector:NULL contextInfo:nil];
355 }
356
357 - (IBAction)closeCustomizationSheet:(id)sender
358 {
359     [_customize_panel orderOut:sender];
360     [NSApp endSheet: _customize_panel];
361
362     if (sender == _customize_ok_btn)
363         [self updateCurrentProfile];
364 }
365
366 - (IBAction)newProfileAction:(id)sender
367 {
368     /* show panel */
369     VLCEnterTextPanel * panel = [VLCEnterTextPanel sharedInstance];
370     [panel setTitle: _NS("Save as new profile")];
371     [panel setSubTitle: _NS("Enter a name for the new profile:")];
372     [panel setCancelButtonLabel: _NS("Cancel")];
373     [panel setOKButtonLabel: _NS("Save")];
374     [panel setTarget:self];
375
376     [panel runModalForWindow:_customize_panel];
377 }
378
379 - (IBAction)deleteProfileAction:(id)sender
380 {
381     /* show panel */
382     VLCSelectItemInPopupPanel * panel = [VLCSelectItemInPopupPanel sharedInstance];
383     [panel setTitle:_NS("Remove a profile")];
384     [panel setSubTitle:_NS("Select the profile you would like to remove:")];
385     [panel setOKButtonLabel:_NS("Remove")];
386     [panel setCancelButtonLabel:_NS("Cancel")];
387     [panel setPopupButtonContent:self.profileNames];
388     [panel setTarget:self];
389
390     [panel runModalForWindow:_window];
391 }
392
393 - (IBAction)iWantAFile:(id)sender
394 {
395     NSRect boxFrame = [_destination_box frame];
396     NSRect subViewFrame = [_destination_itwantafile_view frame];
397     subViewFrame.origin.x = (boxFrame.size.width - subViewFrame.size.width) / 2;
398     subViewFrame.origin.y = ((boxFrame.size.height - subViewFrame.size.height) / 2) - 15.;
399     [_destination_itwantafile_view setFrame: subViewFrame];
400     [[_destination_itwantafile_btn animator] setHidden: YES];
401     [[_destination_itwantastream_btn animator] setHidden: YES];
402     [_destination_box performSelector:@selector(addSubview:) withObject:_destination_itwantafile_view afterDelay:0.2];
403     [[_destination_cancel_btn animator] setHidden:NO];
404     b_streaming = NO;
405     [_ok_btn setTitle:_NS("Save")];
406 }
407
408 - (IBAction)iWantAStream:(id)sender
409 {
410     NSRect boxFrame = [_destination_box frame];
411     NSRect subViewFrame = [_destination_itwantastream_view frame];
412     subViewFrame.origin.x = (boxFrame.size.width - subViewFrame.size.width) / 2;
413     subViewFrame.origin.y = ((boxFrame.size.height - subViewFrame.size.height) / 2) - 15.;
414     [_destination_itwantastream_view setFrame: subViewFrame];
415     [[_destination_itwantafile_btn animator] setHidden: YES];
416     [[_destination_itwantastream_btn animator] setHidden: YES];
417     [_destination_box performSelector:@selector(addSubview:) withObject:_destination_itwantastream_view afterDelay:0.2];
418     [[_destination_cancel_btn animator] setHidden:NO];
419     b_streaming = YES;
420     [_ok_btn setTitle:_NS("Stream")];
421 }
422
423 - (IBAction)cancelDestination:(id)sender
424 {
425     if ([_destination_itwantastream_view superview] != nil)
426         [_destination_itwantastream_view removeFromSuperview];
427     if ([_destination_itwantafile_view superview] != nil)
428         [_destination_itwantafile_view removeFromSuperview];
429
430     [_destination_cancel_btn setHidden:YES];
431     [[_destination_itwantafile_btn animator] setHidden: NO];
432     [[_destination_itwantastream_btn animator] setHidden: NO];
433     b_streaming = NO;
434 }
435
436 - (IBAction)browseFileDestination:(id)sender
437 {
438     NSSavePanel * saveFilePanel = [NSSavePanel savePanel];
439     [saveFilePanel setCanSelectHiddenExtension: YES];
440     [saveFilePanel setCanCreateDirectories: YES];
441     if ([[_customize_encap_matrix selectedCell] tag] != RAW) // there is no clever guess for this
442         [saveFilePanel setAllowedFileTypes:[NSArray arrayWithObject:[self currentEncapsulationFormatAsFileExtension:YES]]];
443     [saveFilePanel beginSheetModalForWindow:_window completionHandler:^(NSInteger returnCode) {
444         if (returnCode == NSOKButton) {
445             [self setOutputDestination:[[saveFilePanel URL] path]];
446             [_destination_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:_outputDestination]];
447             [[_destination_filename_stub_lbl animator] setHidden: YES];
448             [[_destination_filename_lbl animator] setHidden: NO];
449         } else {
450             [self setOutputDestination:@""];
451             [[_destination_filename_lbl animator] setHidden: YES];
452             [[_destination_filename_stub_lbl animator] setHidden: NO];
453         }
454         [self updateOKButton];
455     }];
456 }
457
458 - (IBAction)showStreamPanel:(id)sender
459 {
460     [NSApp beginSheet:_stream_panel modalForWindow:_window modalDelegate:self didEndSelector:NULL contextInfo:nil];
461 }
462
463 - (IBAction)closeStreamPanel:(id)sender
464 {
465     [_stream_panel orderOut:sender];
466     [NSApp endSheet: _stream_panel];
467
468     if (sender == _stream_cancel_btn)
469         return;
470
471     /* provide a summary of the user selections */
472     NSMutableString * labelContent = [[NSMutableString alloc] initWithFormat:_NS("%@ stream to %@:%@"), [_stream_type_pop titleOfSelectedItem], [_stream_address_fld stringValue], [_stream_port_fld stringValue]];
473
474     if ([_stream_type_pop indexOfSelectedItem] > 1)
475         [labelContent appendFormat:@" (\"%@\")", [_stream_channel_fld stringValue]];
476
477     [_destination_stream_lbl setStringValue:labelContent];
478     [labelContent release];
479
480     /* catch obvious errors */
481     if (![[_stream_address_fld stringValue] length] > 0) {
482         NSBeginInformationalAlertSheet(_NS("No Address given"),
483                                        _NS("OK"), @"", @"", _stream_panel, nil, nil, nil, nil,
484                                        @"%@", _NS("In order to stream, a valid destination address is required."));
485         return;
486     }
487
488     if ([_stream_sap_ckb state] && ![[_stream_channel_fld stringValue] length] > 0) {
489         NSBeginInformationalAlertSheet(_NS("No Channel Name given"),
490                                        _NS("OK"), @"", @"", _stream_panel, nil, nil, nil, nil,
491                                        @"%@", _NS("SAP stream announcement is enabled. However, no channel name is provided."));
492         return;
493     }
494
495     if ([_stream_sdp_matrix isEnabled] && [_stream_sdp_matrix selectedCell] != [_stream_sdp_matrix cellWithTag:0] && ![[_stream_sdp_fld stringValue] length] > 0) {
496         NSBeginInformationalAlertSheet(_NS("No SDP URL given"),
497                                        _NS("OK"), @"", @"", _stream_panel, nil, nil, nil, nil,
498                                        @"%@", _NS("A SDP export is requested, but no URL is provided."));
499         return;
500     }
501
502     /* store destination for further reference and update UI */
503     [self setOutputDestination: [_stream_address_fld stringValue]];
504     [self updateOKButton];
505 }
506
507 - (IBAction)streamTypeToggle:(id)sender
508 {
509     NSUInteger index = [_stream_type_pop indexOfSelectedItem];
510     if (index <= 1) { // HTTP, MMSH
511         [_stream_ttl_fld setEnabled:NO];
512         [_stream_ttl_stepper setEnabled:NO];
513         [_stream_sap_ckb setEnabled:NO];
514         [_stream_sdp_matrix setEnabled:NO];
515     } else if (index == 2) { // RTP
516         [_stream_ttl_fld setEnabled:YES];
517         [_stream_ttl_stepper setEnabled:YES];
518         [_stream_sap_ckb setEnabled:YES];
519         [_stream_sdp_matrix setEnabled:YES];
520     } else { // UDP
521         [_stream_ttl_fld setEnabled:YES];
522         [_stream_ttl_stepper setEnabled:YES];
523         [_stream_sap_ckb setEnabled:YES];
524         [_stream_sdp_matrix setEnabled:NO];
525     }
526     [self streamAnnouncementToggle:sender];
527 }
528
529 - (IBAction)streamAnnouncementToggle:(id)sender
530 {
531     [_stream_channel_fld setEnabled:[_stream_sap_ckb state] && [_stream_sap_ckb isEnabled]];
532     [_stream_sdp_fld setEnabled:[_stream_sdp_matrix isEnabled] && ([_stream_sdp_matrix selectedCell] != [_stream_sdp_matrix cellWithTag:0])];
533
534     if ([[_stream_sdp_matrix selectedCell] tag] == 3)
535         [_stream_sdp_browsefile_btn setEnabled: YES];
536     else
537         [_stream_sdp_browsefile_btn setEnabled: NO];
538 }
539
540 - (IBAction)sdpFileLocationSelector:(id)sender
541 {
542     NSSavePanel * saveFilePanel = [NSSavePanel savePanel];
543     [saveFilePanel setCanSelectHiddenExtension: YES];
544     [saveFilePanel setCanCreateDirectories: YES];
545     [saveFilePanel setAllowedFileTypes:[NSArray arrayWithObject:@"sdp"]];
546     [saveFilePanel beginSheetModalForWindow:_stream_panel completionHandler:^(NSInteger returnCode) {
547         if (returnCode == NSOKButton)
548             [_stream_sdp_fld setStringValue:[[saveFilePanel URL] path]];
549     }];
550 }
551
552 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
553 {
554     NSPasteboard *paste = [sender draggingPasteboard];
555     NSArray *types = [NSArray arrayWithObjects:NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil];
556     NSString *desired_type = [paste availableTypeFromArray: types];
557     NSData *carried_data = [paste dataForType: desired_type];
558
559     if (carried_data) {
560         if ([desired_type isEqualToString:NSFilenamesPboardType]) {
561             NSArray *values = [[paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
562
563             if ([values count] > 0) {
564                 [self setMRL: [NSString stringWithUTF8String:vlc_path2uri([[values objectAtIndex:0] UTF8String], NULL)]];
565                 [self updateOKButton];
566                 [self updateDropView];
567                 return YES;
568             }
569         } else if ([desired_type isEqualToString:@"VLCPlaylistItemPboardType"]) {
570             NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems];
571             NSUInteger count = [array count];
572             if (count > 0) {
573                 playlist_t * p_playlist = pl_Get(VLCIntf);
574                 playlist_item_t * p_item = NULL;
575
576                 PL_LOCK;
577                 /* let's look for the first proper input item */
578                 for (NSUInteger x = 0; x < count; x++) {
579                     p_item = [[array objectAtIndex:x] pointerValue];
580                     if (p_item) {
581                         if (p_item->p_input) {
582                             if (p_item->p_input->psz_uri != nil) {
583                                 [self setMRL: toNSStr(p_item->p_input->psz_uri)];
584                                 [self updateDropView];
585                                 [self updateOKButton];
586
587                                 PL_UNLOCK;
588
589                                 return YES;
590                             }
591                         }
592                     }
593                 }
594                 PL_UNLOCK;
595             }
596         }
597     }
598     return NO;
599 }
600
601 - (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
602 {
603     if (value == NSOKButton) {
604         if ([text length] > 0) {
605             /* prepare current data */
606             [self updateCurrentProfile];
607
608             /* add profile to arrays */
609             NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:self.profileNames];
610             [workArray addObject:text];
611             [self setProfileNames:[[[NSArray alloc] initWithArray:workArray] autorelease]];
612             [workArray release];
613
614             workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
615             [workArray addObject:[self.currentProfile componentsJoinedByString:@";"]];
616             [self setProfileValueList:[[[NSArray alloc] initWithArray:workArray] autorelease]];
617             [workArray release];
618
619             /* update UI */
620             [self recreateProfilePopup];
621             [_profile_pop selectItemWithTitle:text];
622
623             /* update internals */
624             [self switchProfile:self];
625             [self storeProfilesOnDisk];
626         }
627     }
628 }
629
630 - (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
631 {
632     if (value == NSOKButton) {
633         /* remove requested profile from the arrays */
634         NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:self.profileNames];
635         [workArray removeObjectAtIndex:item];
636         [self setProfileNames:[[[NSArray alloc] initWithArray:workArray] autorelease]];
637         [workArray release];
638         workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
639         [workArray removeObjectAtIndex:item];
640         [self setProfileValueList:[[[NSArray alloc] initWithArray:workArray] autorelease]];
641         [workArray release];
642
643         /* update UI */
644         [self recreateProfilePopup];
645
646         /* update internals */
647         [self switchProfile:self];
648         [self storeProfilesOnDisk];
649     }
650 }
651
652 - (IBAction)videoSettingsChanged:(id)sender
653 {
654     bool enableSettings = [_customize_vid_ckb state] == NSOnState && [_customize_vid_keep_ckb state] == NSOffState;
655     [_customize_vid_settings_box enableSubviews:enableSettings];
656     [_customize_vid_keep_ckb setEnabled:[_customize_vid_ckb state] == NSOnState];
657 }
658
659 - (IBAction)audioSettingsChanged:(id)sender
660 {
661     bool enableSettings = [_customize_aud_ckb state] == NSOnState && [_customize_aud_keep_ckb state] == NSOffState;
662     [_customize_aud_settings_box enableSubviews:enableSettings];
663     [_customize_aud_keep_ckb setEnabled:[_customize_aud_ckb state] == NSOnState];
664 }
665
666 - (IBAction)subSettingsChanged:(id)sender
667 {
668     bool enableSettings = [_customize_subs_ckb state] == NSOnState;
669     [_customize_subs_overlay_ckb setEnabled:enableSettings];
670     [_customize_subs_pop setEnabled:enableSettings];
671 }
672
673 # pragma mark -
674 # pragma mark Private Functionality
675 - (void)updateDropView
676 {
677     if ([_MRL length] > 0) {
678         NSString * path = [[NSURL URLWithString:_MRL] path];
679         [_dropin_media_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: path]];
680         NSImage * image = [[NSWorkspace sharedWorkspace] iconForFile: path];
681         [image setSize:NSMakeSize(128,128)];
682         [_dropin_icon_view setImage: image];
683
684         if (![_dropin_view superview]) {
685             NSRect boxFrame = [_drop_box frame];
686             NSRect subViewFrame = [_dropin_view frame];
687             subViewFrame.origin.x = (boxFrame.size.width - subViewFrame.size.width) / 2;
688             subViewFrame.origin.y = (boxFrame.size.height - subViewFrame.size.height) / 2;
689             [_dropin_view setFrame: subViewFrame];
690             [[_drop_image_view animator] setHidden: YES];
691             [_drop_box performSelector:@selector(addSubview:) withObject:_dropin_view afterDelay:0.6];
692         }
693     } else {
694         [_dropin_view removeFromSuperview];
695         [[_drop_image_view animator] setHidden: NO];
696     }
697 }
698
699 - (void)updateOKButton
700 {
701     if ([_outputDestination length] > 0 && [_MRL length] > 0)
702         [_ok_btn setEnabled: YES];
703     else
704         [_ok_btn setEnabled: NO];
705 }
706
707 - (void)resetCustomizationSheetBasedOnProfile:(NSString *)profileString
708 {
709     /* Container(string), transcode video(bool), transcode audio(bool),
710     * use subtitles(bool), video codec(string), video bitrate(integer),
711     * scale(float), fps(float), width(integer, height(integer),
712     * audio codec(string), audio bitrate(integer), channels(integer),
713     * samplerate(integer), subtitle codec(string), subtitle overlay(bool) */
714
715     NSArray * components = [profileString componentsSeparatedByString:@";"];
716     if ([components count] != 16) {
717         msg_Err(VLCIntf, "CAS: the requested profile '%s' is invalid", [profileString UTF8String]);
718         return;
719     }
720
721     [self selectCellByEncapsulationFormat:[components objectAtIndex:0]];
722     [_customize_vid_ckb setState:[[components objectAtIndex:1] intValue]];
723     [_customize_aud_ckb setState:[[components objectAtIndex:2] intValue]];
724     [_customize_subs_ckb setState:[[components objectAtIndex:3] intValue]];
725     [self setVidBitrate:[[components objectAtIndex:5] intValue]];
726     [_customize_vid_scale_pop selectItemWithTitle:[components objectAtIndex:6]];
727     [self setVidFramerate:[[components objectAtIndex:7] intValue]];
728     [_customize_vid_width_fld setStringValue:[components objectAtIndex:8]];
729     [_customize_vid_height_fld setStringValue:[components objectAtIndex:9]];
730     [self setAudBitrate:[[components objectAtIndex:11] intValue]];
731     [self setAudChannels:[[components objectAtIndex:12] intValue]];
732     [_customize_aud_samplerate_pop selectItemWithTitle:[components objectAtIndex:13]];
733     [_customize_subs_overlay_ckb setState:[[components objectAtIndex:15] intValue]];
734
735     /* since there is no proper lookup mechanism in arrays, we need to implement a string specific one ourselves */
736     NSArray * tempArray = [_videoCodecs objectAtIndex:1];
737     NSUInteger count = [tempArray count];
738     NSString * searchString = [components objectAtIndex:4];
739     int videoKeep = [searchString isEqualToString:@"copy"];
740     [_customize_vid_keep_ckb setState:videoKeep];
741     if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"] || videoKeep) {
742         [_customize_vid_codec_pop selectItemAtIndex:-1];
743     } else {
744         for (NSUInteger x = 0; x < count; x++) {
745             if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
746                 [_customize_vid_codec_pop selectItemAtIndex:x];
747                 break;
748             }
749         }
750     }
751
752     tempArray = [_audioCodecs objectAtIndex:1];
753     count = [tempArray count];
754     searchString = [components objectAtIndex:10];
755     int audioKeep = [searchString isEqualToString:@"copy"];
756     [_customize_aud_keep_ckb setState:audioKeep];
757     if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"] || audioKeep) {
758         [_customize_aud_codec_pop selectItemAtIndex:-1];
759     } else {
760         for (NSUInteger x = 0; x < count; x++) {
761             if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
762                 [_customize_aud_codec_pop selectItemAtIndex:x];
763                 break;
764             }
765         }
766     }
767
768     tempArray = [_subsCodecs objectAtIndex:1];
769     count = [tempArray count];
770     searchString = [components objectAtIndex:14];
771     if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"]) {
772         [_customize_subs_pop selectItemAtIndex:-1];
773     } else {
774         for (NSUInteger x = 0; x < count; x++) {
775             if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
776                 [_customize_subs_pop selectItemAtIndex:x];
777                 break;
778             }
779         }
780     }
781
782     [self videoSettingsChanged:nil];
783     [self audioSettingsChanged:nil];
784     [self subSettingsChanged:nil];
785
786     [self setCurrentProfile: [[[NSMutableArray alloc] initWithArray: [profileString componentsSeparatedByString:@";"]] autorelease]];
787 }
788
789 - (void)selectCellByEncapsulationFormat:(NSString *)format
790 {
791     if ([format isEqualToString:@"ts"])
792         [_customize_encap_matrix selectCellWithTag:MPEGTS];
793     else if ([format isEqualToString:@"webm"])
794         [_customize_encap_matrix selectCellWithTag:WEBM];
795     else if ([format isEqualToString:@"ogg"])
796         [_customize_encap_matrix selectCellWithTag:OGG];
797     else if ([format isEqualToString:@"ogm"])
798         [_customize_encap_matrix selectCellWithTag:OGG];
799     else if ([format isEqualToString:@"mp4"])
800         [_customize_encap_matrix selectCellWithTag:MP4];
801     else if ([format isEqualToString:@"mov"])
802         [_customize_encap_matrix selectCellWithTag:MP4];
803     else if ([format isEqualToString:@"ps"])
804         [_customize_encap_matrix selectCellWithTag:MPEGPS];
805     else if ([format isEqualToString:@"mpjpeg"])
806         [_customize_encap_matrix selectCellWithTag:MJPEG];
807     else if ([format isEqualToString:@"wav"])
808         [_customize_encap_matrix selectCellWithTag:WAV];
809     else if ([format isEqualToString:@"flv"])
810         [_customize_encap_matrix selectCellWithTag:FLV];
811     else if ([format isEqualToString:@"mpeg1"])
812         [_customize_encap_matrix selectCellWithTag:MPEG1];
813     else if ([format isEqualToString:@"mkv"])
814         [_customize_encap_matrix selectCellWithTag:MKV];
815     else if ([format isEqualToString:@"raw"])
816         [_customize_encap_matrix selectCellWithTag:RAW];
817     else if ([format isEqualToString:@"avi"])
818         [_customize_encap_matrix selectCellWithTag:AVI];
819     else if ([format isEqualToString:@"asf"])
820         [_customize_encap_matrix selectCellWithTag:ASF];
821     else if ([format isEqualToString:@"wmv"])
822         [_customize_encap_matrix selectCellWithTag:ASF];
823     else
824         msg_Err(VLCIntf, "CAS: unknown encap format requested for customization");
825 }
826
827 - (NSString *)currentEncapsulationFormatAsFileExtension:(BOOL)b_extension
828 {
829     NSUInteger cellTag = (NSUInteger) [[_customize_encap_matrix selectedCell] tag];
830     NSString * returnValue;
831     switch (cellTag) {
832         case MPEGTS:
833             returnValue = @"ts";
834             break;
835         case WEBM:
836             returnValue = @"webm";
837             break;
838         case OGG:
839             returnValue = @"ogg";
840             break;
841         case MP4:
842         {
843             if (b_extension)
844                 returnValue = @"m4v";
845             else
846                 returnValue = @"mp4";
847             break;
848         }
849         case MPEGPS:
850         {
851             if (b_extension)
852                 returnValue = @"mpg";
853             else
854                 returnValue = @"ps";
855             break;
856         }
857         case MJPEG:
858             returnValue = @"mjpeg";
859             break;
860         case WAV:
861             returnValue = @"wav";
862             break;
863         case FLV:
864             returnValue = @"flv";
865             break;
866         case MPEG1:
867         {
868             if (b_extension)
869                 returnValue = @"mpg";
870             else
871                 returnValue = @"mpeg1";
872             break;
873         }
874         case MKV:
875             returnValue = @"mkv";
876             break;
877         case RAW:
878             returnValue = @"raw";
879             break;
880         case AVI:
881             returnValue = @"avi";
882             break;
883         case ASF:
884             returnValue = @"asf";
885             break;
886
887         default:
888             returnValue = @"none";
889             break;
890     }
891
892     return returnValue;
893 }
894
895 - (NSString *)composedOptions
896 {
897     NSMutableString *composedOptions = [[NSMutableString alloc] initWithString:@":sout=#transcode{"];
898     BOOL haveVideo = YES;
899     if ([[self.currentProfile objectAtIndex:1] intValue]) {
900         // video is enabled
901         if (![[self.currentProfile objectAtIndex:4] isEqualToString:@"copy"]) {
902         [composedOptions appendFormat:@"vcodec=%@", [self.currentProfile objectAtIndex:4]];
903             if ([[self.currentProfile objectAtIndex:5] intValue] > 0) // bitrate
904                 [composedOptions appendFormat:@",vb=%@", [self.currentProfile objectAtIndex:5]];
905             if ([[self.currentProfile objectAtIndex:6] floatValue] > 0.) // scale
906                 [composedOptions appendFormat:@",scale=%@", [self.currentProfile objectAtIndex:6]];
907             if ([[self.currentProfile objectAtIndex:7] floatValue] > 0.) // fps
908                 [composedOptions appendFormat:@",fps=%@", [self.currentProfile objectAtIndex:7]];
909             if ([[self.currentProfile objectAtIndex:8] intValue] > 0) // width
910                 [composedOptions appendFormat:@",width=%@", [self.currentProfile objectAtIndex:8]];
911             if ([[self.currentProfile objectAtIndex:9] intValue] > 0) // height
912                 [composedOptions appendFormat:@",height=%@", [self.currentProfile objectAtIndex:9]];
913         } else {
914             haveVideo = NO;
915         }
916     } else {
917         [composedOptions appendString:@"vcodec=none"];
918     }
919
920     BOOL haveAudio = YES;
921     if ([[self.currentProfile objectAtIndex:2] intValue]) {
922         // audio is enabled
923         if (![[self.currentProfile objectAtIndex:10] isEqualToString:@"copy"]) {
924             if(haveVideo)
925                 [composedOptions appendString:@","];
926             [composedOptions appendFormat:@"acodec=%@", [self.currentProfile objectAtIndex:10]];
927             [composedOptions appendFormat:@",ab=%@", [self.currentProfile objectAtIndex:11]]; // bitrate
928             [composedOptions appendFormat:@",channels=%@", [self.currentProfile objectAtIndex:12]]; // channel number
929             [composedOptions appendFormat:@",samplerate=%@", [self.currentProfile objectAtIndex:13]]; // sample rate
930         } else {
931             haveAudio = NO;
932         }
933     } else {
934         if(haveVideo)
935             [composedOptions appendString:@","];
936
937         [composedOptions appendString:@"acodec=none"];
938     }
939     if ([self.currentProfile objectAtIndex:3]) {
940         if(haveVideo || haveAudio)
941             [composedOptions appendString:@","];
942         // subtitles enabled
943         [composedOptions appendFormat:@"scodec=%@", [self.currentProfile objectAtIndex:14]];
944         if ([[self.currentProfile objectAtIndex:15] intValue])
945             [composedOptions appendFormat:@",soverlay"];
946     }
947
948     if (!b_streaming) {
949         /* file transcoding */
950         // add muxer
951         [composedOptions appendFormat:@"}:standard{mux=%@", [self.currentProfile objectAtIndex:0]];
952
953         // add output destination
954         [composedOptions appendFormat:@",access=file{no-overwrite},dst=%@}", _outputDestination];
955     } else {
956         /* streaming */
957         if ([[[_stream_type_pop selectedItem] title] isEqualToString:@"RTP"])
958             [composedOptions appendFormat:@":rtp{mux=ts,dst=%@,port=%@", _outputDestination, [_stream_port_fld stringValue]];
959         else if ([[[_stream_type_pop selectedItem] title] isEqualToString:@"UDP"])
960             [composedOptions appendFormat:@":standard{mux=ts,dst=%@,port=%@,access=udp", _outputDestination, [_stream_port_fld stringValue]];
961         else if ([[[_stream_type_pop selectedItem] title] isEqualToString:@"MMSH"])
962             [composedOptions appendFormat:@":standard{mux=asfh,dst=%@,port=%@,access=mmsh", _outputDestination, [_stream_port_fld stringValue]];
963         else
964             [composedOptions appendFormat:@":standard{mux=%@,dst=%@,port=%@,access=http", [self.currentProfile objectAtIndex:0], [_stream_port_fld stringValue], _outputDestination];
965
966         if ([_stream_sap_ckb state])
967             [composedOptions appendFormat:@",sap,name=\"%@\"", [_stream_channel_fld stringValue]];
968         if ([_stream_sdp_matrix selectedCell] != [_stream_sdp_matrix cellWithTag:0]) {
969             NSInteger tag = [[_stream_sdp_matrix selectedCell] tag];
970             switch (tag) {
971                 case 1:
972                     [composedOptions appendFormat:@",sdp=\"http://%@\"", [_stream_sdp_fld stringValue]];
973                     break;
974                 case 2:
975                     [composedOptions appendFormat:@",sdp=\"rtsp://%@\"", [_stream_sdp_fld stringValue]];
976                     break;
977                 case 3:
978                     [composedOptions appendFormat:@",sdp=\"file://%s\"", vlc_path2uri([[_stream_sdp_fld stringValue] UTF8String], NULL)];
979                 default:
980                     break;
981             }
982         }
983
984         [composedOptions appendString:@"} :sout-keep"];
985     }
986
987     NSString * returnString = [NSString stringWithString:composedOptions];
988     [composedOptions release];
989
990     return returnString;
991 }
992
993 - (void)updateCurrentProfile
994 {
995     [self.currentProfile removeAllObjects];
996
997     NSInteger i;
998     [self.currentProfile addObject: [self currentEncapsulationFormatAsFileExtension:NO]];
999     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_vid_ckb state]]];
1000     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_aud_ckb state]]];
1001     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_subs_ckb state]]];
1002     
1003     NSString *videoCodec;
1004     if([_customize_vid_keep_ckb state] == NSOnState)
1005         videoCodec = @"copy";
1006     else {
1007         i = [_customize_vid_codec_pop indexOfSelectedItem];
1008         if (i >= 0)
1009             videoCodec = [[_videoCodecs objectAtIndex:1] objectAtIndex:i];
1010         else
1011             videoCodec = @"none";
1012     }
1013     [self.currentProfile addObject: videoCodec];
1014
1015     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self vidBitrate]]];
1016     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [[[_customize_vid_scale_pop selectedItem] title] intValue]]];
1017     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self vidFramerate]]];
1018     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_vid_width_fld intValue]]];
1019     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_vid_height_fld intValue]]];
1020
1021     NSString *audioCodec;
1022     if([_customize_aud_keep_ckb state] == NSOnState)
1023         audioCodec = @"copy";
1024     else {
1025         i = [_customize_aud_codec_pop indexOfSelectedItem];
1026         if (i >= 0)
1027             audioCodec = [[_audioCodecs objectAtIndex:1] objectAtIndex:i];
1028         else
1029             audioCodec = @"none";
1030     }
1031     [self.currentProfile addObject: audioCodec];
1032     
1033     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self audBitrate]]];
1034     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self audChannels]]];
1035     [self.currentProfile addObject: [[_customize_aud_samplerate_pop selectedItem] title]];
1036     i = [_customize_subs_pop indexOfSelectedItem];
1037     if (i >= 0)
1038         [self.currentProfile addObject: [[_subsCodecs objectAtIndex:1] objectAtIndex:i]];
1039     else
1040         [self.currentProfile addObject: @"none"];
1041     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_subs_overlay_ckb state]]];
1042 }
1043
1044 - (void)storeProfilesOnDisk
1045 {
1046     NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
1047     [defaults setObject:_profileNames forKey:@"CASProfileNames"];
1048     [defaults setObject:_profileValueList forKey:@"CASProfiles"];
1049     [defaults synchronize];
1050 }
1051
1052 - (void)recreateProfilePopup
1053 {
1054     [_profile_pop removeAllItems];
1055     [_profile_pop addItemsWithTitles:self.profileNames];
1056     [_profile_pop addItemWithTitle:_NS("Custom")];
1057     [[_profile_pop menu] addItem:[NSMenuItem separatorItem]];
1058     [_profile_pop addItemWithTitle:_NS("Organize Profiles...")];
1059     [[_profile_pop lastItem] setTarget: self];
1060     [[_profile_pop lastItem] setAction: @selector(deleteProfileAction:)];
1061 }
1062
1063 @end