1 /*****************************************************************************
2 * ConvertAndSave.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2012 Felix Paul Kühne
7 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
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.
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.
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 *****************************************************************************/
24 #import "ConvertAndSave.h"
27 #import <vlc_common.h>
31 * the used NSMatrix includes a bunch of cells referenced most easily by tags. There you go: */
45 /* 13-15 are present, but not set */
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;
59 @implementation VLCConvertAndSave
61 @synthesize MRL=_MRL, outputDestination=_outputDestination, profileNames=_profileNames, profileValueList=_profileValueList, currentProfile=_currentProfile;
63 @synthesize vidBitrate, vidFramerate, audBitrate, audChannels;
65 static VLCConvertAndSave *_o_sharedInstance = nil;
68 #pragma mark Initialization
72 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
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];
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)",
108 @"Audio - MP3 (MP4)",
113 NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:defaultProfiles, @"CASProfiles", defaultProfileNames, @"CASProfileNames", nil];
115 [defaults registerDefaults:appDefaults];
116 [defaultProfiles release];
117 [defaultProfileNames release];
120 + (VLCConvertAndSave *)sharedInstance
122 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
127 if (_o_sharedInstance) {
130 _o_sharedInstance = [super init];
133 return _o_sharedInstance;
139 [_currentProfile release];
141 [_profileNames release];
142 [_profileValueList release];
143 [_videoCodecs release];
144 [_audioCodecs release];
145 [_subsCodecs release];
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];
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];
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];
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],
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],
232 _subsCodecs = [[NSArray alloc] initWithObjects:
233 [NSArray arrayWithObjects:@"DVB subtitle", @"T.140", nil],
234 [NSArray arrayWithObjects:@"dvbs", @"t140", nil],
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];
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]];
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"];
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"];
262 [_ok_btn setEnabled: NO];
265 [_drop_box enablePlaylistItems];
266 [_drop_box setDropHandler: self];
268 [self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:0]];
272 # pragma mark Code to Communicate with other objects
276 [_window makeKeyAndOrderFront: nil];
280 # pragma mark User Interaction
282 - (IBAction)finalizePanel:(id)sender
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,
290 _NS("Media encapsulated as %@ cannot be streamed through the HTTP protocol for technical reasons."),
291 [[self currentEncapsulationFormatAsFileExtension:YES] uppercaseString]);
297 playlist_t * p_playlist = pl_Get(VLCIntf);
299 input_item_t *p_input = input_item_New([_MRL UTF8String], [[_dropin_media_lbl stringValue] UTF8String]);
303 input_item_AddOption(p_input, [[self composedOptions] UTF8String], VLC_INPUT_OPTION_TRUSTED);
305 input_item_AddOption(p_input, [[NSString stringWithFormat:@"ttl=%@", [_stream_ttl_fld stringValue]] UTF8String], VLC_INPUT_OPTION_TRUSTED);
308 returnValue = playlist_AddInput(p_playlist, p_input, PLAYLIST_STOP, PLAYLIST_END, true, pl_Unlocked);
310 if (returnValue == VLC_SUCCESS) {
313 playlist_item_t *p_item = playlist_ItemGetByInput(p_playlist, p_input);
314 playlist_Control(p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, NULL,
319 msg_Err(VLCIntf, "CAS: playlist add input failed :(");
321 /* we're done with this input */
322 vlc_gc_decref(p_input);
324 [_window performClose:sender];
327 - (IBAction)openMedia:(id)sender
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)
337 [self setMRL: [NSString stringWithUTF8String:vlc_path2uri([[[openPanel URL] path] UTF8String], NULL)]];
338 [self updateOKButton];
339 [self updateDropView];
344 - (IBAction)switchProfile:(id)sender
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]];
352 - (IBAction)customizeProfile:(id)sender
354 [NSApp beginSheet:_customize_panel modalForWindow:_window modalDelegate:self didEndSelector:NULL contextInfo:nil];
357 - (IBAction)closeCustomizationSheet:(id)sender
359 [_customize_panel orderOut:sender];
360 [NSApp endSheet: _customize_panel];
362 if (sender == _customize_ok_btn)
363 [self updateCurrentProfile];
366 - (IBAction)newProfileAction:(id)sender
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];
376 [panel runModalForWindow:_customize_panel];
379 - (IBAction)deleteProfileAction:(id)sender
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];
390 [panel runModalForWindow:_window];
393 - (IBAction)iWantAFile:(id)sender
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];
405 [_ok_btn setTitle:_NS("Save")];
408 - (IBAction)iWantAStream:(id)sender
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];
420 [_ok_btn setTitle:_NS("Stream")];
423 - (IBAction)cancelDestination:(id)sender
425 if ([_destination_itwantastream_view superview] != nil)
426 [_destination_itwantastream_view removeFromSuperview];
427 if ([_destination_itwantafile_view superview] != nil)
428 [_destination_itwantafile_view removeFromSuperview];
430 [_destination_cancel_btn setHidden:YES];
431 [[_destination_itwantafile_btn animator] setHidden: NO];
432 [[_destination_itwantastream_btn animator] setHidden: NO];
436 - (IBAction)browseFileDestination:(id)sender
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];
450 [self setOutputDestination:@""];
451 [[_destination_filename_lbl animator] setHidden: YES];
452 [[_destination_filename_stub_lbl animator] setHidden: NO];
454 [self updateOKButton];
458 - (IBAction)showStreamPanel:(id)sender
460 [NSApp beginSheet:_stream_panel modalForWindow:_window modalDelegate:self didEndSelector:NULL contextInfo:nil];
463 - (IBAction)closeStreamPanel:(id)sender
465 [_stream_panel orderOut:sender];
466 [NSApp endSheet: _stream_panel];
468 if (sender == _stream_cancel_btn)
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]];
474 if ([_stream_type_pop indexOfSelectedItem] > 1)
475 [labelContent appendFormat:@" (\"%@\")", [_stream_channel_fld stringValue]];
477 [_destination_stream_lbl setStringValue:labelContent];
478 [labelContent release];
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."));
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."));
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."));
502 /* store destination for further reference and update UI */
503 [self setOutputDestination: [_stream_address_fld stringValue]];
504 [self updateOKButton];
507 - (IBAction)streamTypeToggle:(id)sender
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];
521 [_stream_ttl_fld setEnabled:YES];
522 [_stream_ttl_stepper setEnabled:YES];
523 [_stream_sap_ckb setEnabled:YES];
524 [_stream_sdp_matrix setEnabled:NO];
526 [self streamAnnouncementToggle:sender];
529 - (IBAction)streamAnnouncementToggle:(id)sender
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])];
534 if ([[_stream_sdp_matrix selectedCell] tag] == 3)
535 [_stream_sdp_browsefile_btn setEnabled: YES];
537 [_stream_sdp_browsefile_btn setEnabled: NO];
540 - (IBAction)sdpFileLocationSelector:(id)sender
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]];
552 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
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];
560 if ([desired_type isEqualToString:NSFilenamesPboardType]) {
561 NSArray *values = [[paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
563 if ([values count] > 0) {
564 [self setMRL: [NSString stringWithUTF8String:vlc_path2uri([[values objectAtIndex:0] UTF8String], NULL)]];
565 [self updateOKButton];
566 [self updateDropView];
569 } else if ([desired_type isEqualToString:@"VLCPlaylistItemPboardType"]) {
570 NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems];
571 NSUInteger count = [array count];
573 playlist_t * p_playlist = pl_Get(VLCIntf);
574 playlist_item_t * p_item = NULL;
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];
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];
601 - (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
603 if (value == NSOKButton) {
604 if ([text length] > 0) {
605 /* prepare current data */
606 [self updateCurrentProfile];
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]];
614 workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
615 [workArray addObject:[self.currentProfile componentsJoinedByString:@";"]];
616 [self setProfileValueList:[[[NSArray alloc] initWithArray:workArray] autorelease]];
620 [self recreateProfilePopup];
621 [_profile_pop selectItemWithTitle:text];
623 /* update internals */
624 [self switchProfile:self];
625 [self storeProfilesOnDisk];
630 - (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
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]];
638 workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
639 [workArray removeObjectAtIndex:item];
640 [self setProfileValueList:[[[NSArray alloc] initWithArray:workArray] autorelease]];
644 [self recreateProfilePopup];
646 /* update internals */
647 [self switchProfile:self];
648 [self storeProfilesOnDisk];
652 - (IBAction)videoSettingsChanged:(id)sender
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];
659 - (IBAction)audioSettingsChanged:(id)sender
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];
666 - (IBAction)subSettingsChanged:(id)sender
668 bool enableSettings = [_customize_subs_ckb state] == NSOnState;
669 [_customize_subs_overlay_ckb setEnabled:enableSettings];
670 [_customize_subs_pop setEnabled:enableSettings];
674 # pragma mark Private Functionality
675 - (void)updateDropView
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];
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];
694 [_dropin_view removeFromSuperview];
695 [[_drop_image_view animator] setHidden: NO];
699 - (void)updateOKButton
701 if ([_outputDestination length] > 0 && [_MRL length] > 0)
702 [_ok_btn setEnabled: YES];
704 [_ok_btn setEnabled: NO];
707 - (void)resetCustomizationSheetBasedOnProfile:(NSString *)profileString
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) */
715 NSArray * components = [profileString componentsSeparatedByString:@";"];
716 if ([components count] != 16) {
717 msg_Err(VLCIntf, "CAS: the requested profile '%s' is invalid", [profileString UTF8String]);
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]];
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];
744 for (NSUInteger x = 0; x < count; x++) {
745 if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
746 [_customize_vid_codec_pop selectItemAtIndex:x];
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];
760 for (NSUInteger x = 0; x < count; x++) {
761 if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
762 [_customize_aud_codec_pop selectItemAtIndex:x];
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];
774 for (NSUInteger x = 0; x < count; x++) {
775 if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
776 [_customize_subs_pop selectItemAtIndex:x];
782 [self videoSettingsChanged:nil];
783 [self audioSettingsChanged:nil];
784 [self subSettingsChanged:nil];
786 [self setCurrentProfile: [[[NSMutableArray alloc] initWithArray: [profileString componentsSeparatedByString:@";"]] autorelease]];
789 - (void)selectCellByEncapsulationFormat:(NSString *)format
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];
824 msg_Err(VLCIntf, "CAS: unknown encap format requested for customization");
827 - (NSString *)currentEncapsulationFormatAsFileExtension:(BOOL)b_extension
829 NSUInteger cellTag = (NSUInteger) [[_customize_encap_matrix selectedCell] tag];
830 NSString * returnValue;
836 returnValue = @"webm";
839 returnValue = @"ogg";
844 returnValue = @"m4v";
846 returnValue = @"mp4";
852 returnValue = @"mpg";
858 returnValue = @"mjpeg";
861 returnValue = @"wav";
864 returnValue = @"flv";
869 returnValue = @"mpg";
871 returnValue = @"mpeg1";
875 returnValue = @"mkv";
878 returnValue = @"raw";
881 returnValue = @"avi";
884 returnValue = @"asf";
888 returnValue = @"none";
895 - (NSString *)composedOptions
897 NSMutableString *composedOptions = [[NSMutableString alloc] initWithString:@":sout=#transcode{"];
898 BOOL haveVideo = YES;
899 if ([[self.currentProfile objectAtIndex:1] intValue]) {
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]];
917 [composedOptions appendString:@"vcodec=none"];
920 BOOL haveAudio = YES;
921 if ([[self.currentProfile objectAtIndex:2] intValue]) {
923 if (![[self.currentProfile objectAtIndex:10] isEqualToString:@"copy"]) {
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
935 [composedOptions appendString:@","];
937 [composedOptions appendString:@"acodec=none"];
939 if ([self.currentProfile objectAtIndex:3]) {
940 if(haveVideo || haveAudio)
941 [composedOptions appendString:@","];
943 [composedOptions appendFormat:@"scodec=%@", [self.currentProfile objectAtIndex:14]];
944 if ([[self.currentProfile objectAtIndex:15] intValue])
945 [composedOptions appendFormat:@",soverlay"];
949 /* file transcoding */
951 [composedOptions appendFormat:@"}:standard{mux=%@", [self.currentProfile objectAtIndex:0]];
953 // add output destination
954 [composedOptions appendFormat:@",access=file{no-overwrite},dst=%@}", _outputDestination];
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]];
964 [composedOptions appendFormat:@":standard{mux=%@,dst=%@,port=%@,access=http", [self.currentProfile objectAtIndex:0], [_stream_port_fld stringValue], _outputDestination];
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];
972 [composedOptions appendFormat:@",sdp=\"http://%@\"", [_stream_sdp_fld stringValue]];
975 [composedOptions appendFormat:@",sdp=\"rtsp://%@\"", [_stream_sdp_fld stringValue]];
978 [composedOptions appendFormat:@",sdp=\"file://%s\"", vlc_path2uri([[_stream_sdp_fld stringValue] UTF8String], NULL)];
984 [composedOptions appendString:@"} :sout-keep"];
987 NSString * returnString = [NSString stringWithString:composedOptions];
988 [composedOptions release];
993 - (void)updateCurrentProfile
995 [self.currentProfile removeAllObjects];
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]]];
1003 NSString *videoCodec;
1004 if([_customize_vid_keep_ckb state] == NSOnState)
1005 videoCodec = @"copy";
1007 i = [_customize_vid_codec_pop indexOfSelectedItem];
1009 videoCodec = [[_videoCodecs objectAtIndex:1] objectAtIndex:i];
1011 videoCodec = @"none";
1013 [self.currentProfile addObject: videoCodec];
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]]];
1021 NSString *audioCodec;
1022 if([_customize_aud_keep_ckb state] == NSOnState)
1023 audioCodec = @"copy";
1025 i = [_customize_aud_codec_pop indexOfSelectedItem];
1027 audioCodec = [[_audioCodecs objectAtIndex:1] objectAtIndex:i];
1029 audioCodec = @"none";
1031 [self.currentProfile addObject: audioCodec];
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];
1038 [self.currentProfile addObject: [[_subsCodecs objectAtIndex:1] objectAtIndex:i]];
1040 [self.currentProfile addObject: @"none"];
1041 [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_subs_overlay_ckb state]]];
1044 - (void)storeProfilesOnDisk
1046 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
1047 [defaults setObject:_profileNames forKey:@"CASProfileNames"];
1048 [defaults setObject:_profileValueList forKey:@"CASProfiles"];
1049 [defaults synchronize];
1052 - (void)recreateProfilePopup
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:)];