X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fmacosx%2FConvertAndSave.m;h=a046a5d0ac2e0554a987eb2c7a050c48878185c4;hb=73ef71e7ad12a3319392abfdb8257f4dd9b22eed;hp=e3cafccb1922e7feb3e28396db1062bcec734cbc;hpb=8beb0c93e03ab71d1da014ad74a69e127f6c6412;p=vlc diff --git a/modules/gui/macosx/ConvertAndSave.m b/modules/gui/macosx/ConvertAndSave.m index e3cafccb19..a046a5d0ac 100644 --- a/modules/gui/macosx/ConvertAndSave.m +++ b/modules/gui/macosx/ConvertAndSave.m @@ -23,6 +23,7 @@ #import "ConvertAndSave.h" #import "intf.h" +#import "playlist.h" #import #import @@ -52,6 +53,54 @@ static VLCConvertAndSave *_o_sharedInstance = nil; #pragma mark - #pragma mark Initialization ++ (void)initialize{ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + /* We are using the same format as the Qt4 intf here: + * Container(string), transcode video(bool), transcode audio(bool), + * use subtitles(bool), video codec(string), video bitrate(integer), + * scale(float), fps(float), width(integer, height(integer), + * audio codec(string), audio bitrate(integer), channels(integer), + * samplerate(integer), subtitle codec(string), subtitle overlay(bool) */ + NSArray * defaultProfiles = [[NSArray alloc] initWithObjects: + @"mp4;1;1;0;h264;0;0;0;0;0;mpga;128;2;44100;0;1", + @"webm;1;1;0;VP80;2000;0;0;0;0;vorb;128;2;44100;0;1", + @"ts;1;1;0;h264;800;1;0;0;0;mpga;128;2;44100;0;0", + @"ts;1;1;0;drac;800;1;0;0;0;mpga;128;2;44100;0;0", + @"ogg;1;1;0;theo;800;1;0;0;0;vorb;128;2;44100;0;0", + @"ogg;1;1;0;theo;800;1;0;0;0;flac;128;2;44100;0;0", + @"ts;1;1;0;mp2v;800;1;0;0;0;mpga;128;2;44100;0;0", + @"asf;1;1;0;WMV2;800;1;0;0;0;wma2;128;2;44100;0;0", + @"asf;1;1;0;DIV3;800;1;0;0;0;mp3;128;2;44100;0;0", + @"ogg;1;1;0;none;800;1;0;0;0;vorb;128;2;44100;none;0", + @"raw;1;1;0;none;800;1;0;0;0;mp3;128;2;44100;none;0", + @"mp4;1;1;0;none;800;1;0;0;0;mpga;128;2;44100;none;0", + @"raw;1;1;0;none;800;1;0;0;0;flac;128;2;44100;none;0", + @"wav;1;1;0;none;800;1;0;0;0;s16l;128;2;44100;none;0", nil]; + + NSArray * defaultProfileNames = [[NSArray alloc] initWithObjects: + @"Video - H.264 + MP3 (MP4)", + @"Video - VP80 + Vorbis (Webm)", + @"Video - H.264 + MP3 (TS)", + @"Video - Dirac + MP3 (TS)", + @"Video - Theora + Vorbis (OGG)", + @"Video - Theora + Flac (OGG)", + @"Video - MPEG-2 + MPGA (TS)", + @"Video - WMV + WMA (ASF)", + @"Video - DIV3 + MP3 (ASF)", + @"Audio - Vorbis (OGG)", + @"Audio - MP3", + @"Audio - MP3 (MP4)", + @"Audio - FLAC", + @"Audio - CD", + nil]; + + NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:defaultProfiles, @"CASProfiles", defaultProfileNames, @"CASProfileNames", nil]; + + [defaults registerDefaults:appDefaults]; + [defaultProfiles release]; +} + + (VLCConvertAndSave *)sharedInstance { return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init]; @@ -70,10 +119,6 @@ static VLCConvertAndSave *_o_sharedInstance = nil; - (void)dealloc { - if (_MRL) - [_MRL release]; - if (_outputDestination) - [_outputDestination release]; if (_currentProfile) [_currentProfile release]; @@ -91,13 +136,19 @@ static VLCConvertAndSave *_o_sharedInstance = nil; [_window setTitle: _NS("Convert & Save")]; [_cancel_btn setTitle: _NS("Cancel")]; [_ok_btn setTitle: _NS("Save")]; - [_drop_lbl setStringValue: _NS("Drop Media here")]; - [_drop_btn setTitle: _NS("Open Media...")]; + [_drop_lbl setStringValue: _NS("Drop media here")]; + [_drop_btn setTitle: _NS("Open media...")]; [_profile_lbl setStringValue: _NS("Choose Profile")]; [_profile_btn setTitle: _NS("Customize")]; [_destination_lbl setStringValue: _NS("Choose Destination")]; [_destination_filename_stub_lbl setStringValue: _NS("Choose an output location")]; [_destination_filename_lbl setHidden: YES]; + [_destination_browse_btn setTitle:_NS("Browse...")]; + [_destination_stream_btn setTitle:_NS("Setup Streaming...")]; + [_destination_stream_lbl setStringValue:@""]; + [_destination_itwantafile_btn setTitle:_NS("Save as File")]; + [_destination_itwantastream_btn setTitle:_NS("Stream")]; + [_destination_cancel_btn setHidden:YES]; [_customize_ok_btn setTitle: _NS("Apply")]; [_customize_cancel_btn setTitle: _NS("Cancel")]; [[_customize_tabview tabViewItemAtIndex:0] setLabel: _NS("Encapsulation")]; @@ -123,6 +174,18 @@ static VLCConvertAndSave *_o_sharedInstance = nil; [_customize_aud_samplerate_lbl setStringValue: _NS("Sample Rate")]; [_customize_subs_ckb setTitle: _NS("Subtitles")]; [_customize_subs_overlay_ckb setTitle: _NS("Overlay subtitles on the video")]; + [_stream_ok_btn setTitle:_NS("Set")]; + [_stream_cancel_btn setTitle:_NS("Cancel")]; + [_stream_destination_lbl setStringValue:_NS("Stream Destination")]; + [_stream_announcement_lbl setStringValue:_NS("Stream Announcement")]; + [_stream_type_lbl setStringValue:_NS("Type")]; + [_stream_address_lbl setStringValue:_NS("Address")]; + [_stream_ttl_lbl setStringValue:_NS("TTL")]; + [_stream_port_lbl setStringValue:_NS("Port")]; + [_stream_sap_ckb setStringValue:_NS("SAP Announcement")]; + [_stream_http_ckb setStringValue:_NS("HTTP Announcement")]; + [_stream_rtsp_ckb setStringValue:_NS("RTSP Announcement")]; + [_stream_sdp_ckb setStringValue:_NS("Export SDP as file")]; /* there is no way to hide single cells, so replace the existing ones with empty cells.. */ id blankCell = [[[NSCell alloc] init] autorelease]; @@ -131,48 +194,14 @@ static VLCConvertAndSave *_o_sharedInstance = nil; [_customize_encap_matrix putCell:blankCell atRow:3 column:2]; [_customize_encap_matrix putCell:blankCell atRow:3 column:3]; - _profileNames = [[NSArray alloc] initWithObjects: - @"Video - H.264 + MP3 (MP4)", - @"Video - VP80 + Vorbis (Webm)", - @"Video - H.264 + MP3 (TS)", - @"Video - Dirac + MP3 (TS)", - @"Video - Theora + Vorbis (OGG)", - @"Video - Theora + Flac (OGG)", - @"Video - MPEG-2 + MPGA (TS)", - @"Video - WMV + WMA (ASF)", - @"Video - DIV3 + MP3 (ASF)", - @"Audio - Vorbis (OGG)", - @"Audio - MP3", - @"Audio - MP3 (MP4)", - @"Audio - FLAC", - @"Audio - CD", -// _NS("Custom"), - nil]; - - /* We are using the same format as the Qt4 intf here: - * Container(string), transcode video(bool), transcode audio(bool), - * use subtitles(bool), video codec(string), video bitrate(integer), - * scale(float), fps(float), width(integer, height(integer), - * audio codec(string), audio bitrate(integer), channels(integer), - * samplerate(integer), subtitle codec(string), subtitle overlay(bool) */ - _profileValueList = [[NSArray alloc] initWithObjects: - @"mp4;1;1;0;h264;0;0;0;0;0;mpga;128;2;44100;0;1", - @"webm;1;1;0;VP80;2000;0;0;0;0;vorb;128;2;44100;0;1", - @"ts;1;1;0;h264;800;1;0;0;0;mpga;128;2;44100;0;0", - @"ts;1;1;0;drac;800;1;0;0;0;mpga;128;2;44100;0;0", - @"ogg;1;1;0;theo;800;1;0;0;0;vorb;128;2;44100;0;0", - @"ogg;1;1;0;theo;800;1;0;0;0;flac;128;2;44100;0;0", - @"ts;1;1;0;mp2v;800;1;0;0;0;mpga;128;2;44100;0;0", - @"asf;1;1;0;WMV2;800;1;0;0;0;wma2;128;2;44100;0;0", - @"asf;1;1;0;DIV3;800;1;0;0;0;mp3;128;2;44100;0;0", - @"ogg;1;1;0;none;800;1;0;0;0;vorb;128;2;44100;none;0", - @"raw;1;1;0;none;800;1;0;0;0;mp3;128;2;44100;none;0", - @"mp4;1;1;0;none;800;1;0;0;0;mpga;128;2;44100;none;0", - @"raw;1;1;0;none;800;1;0;0;0;flac;128;2;44100;none;0", - @"wav;1;1;0;none;800;1;0;0;0;s16l;128;2;44100;none;0", nil]; + /* fetch profiles from defaults */ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + _profileValueList = [[defaults arrayForKey:@"CASProfiles"] retain]; + _profileNames = [[defaults arrayForKey:@"CASProfileNames"] retain]; [_profile_pop removeAllItems]; - [_profile_pop addItemsWithTitles: _profileNames]; + [_profile_pop addItemsWithTitles:_profileNames]; + [_profile_pop addItemWithTitle:_NS("Custom")]; _videoCodecs = [[NSArray alloc] initWithObjects: [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], @@ -211,6 +240,10 @@ static VLCConvertAndSave *_o_sharedInstance = nil; [_customize_vid_scale_pop addItemWithTitle:@"1.5"]; [_customize_vid_scale_pop addItemWithTitle:@"1.75"]; [_customize_vid_scale_pop addItemWithTitle:@"2"]; + + [_ok_btn setEnabled: NO]; + + [self resetCustomizationSheetBasedOnProfile:[_profileValueList objectAtIndex:0]]; } # pragma mark - @@ -224,64 +257,191 @@ static VLCConvertAndSave *_o_sharedInstance = nil; # pragma mark - # pragma mark User Interaction -- (IBAction)windowButtonAction:(id)sender +- (IBAction)saveFile:(id)sender { + playlist_t * p_playlist = pl_Get(VLCIntf); + + input_item_t *p_input = input_item_New([_MRL UTF8String], [[_dropin_media_lbl stringValue] UTF8String]); + if (!p_input) + return; + + input_item_AddOption(p_input, [[self composedOptions] UTF8String], VLC_INPUT_OPTION_TRUSTED); + + int returnValue; + returnValue = playlist_AddInput( p_playlist, p_input, PLAYLIST_STOP, PLAYLIST_END, true, pl_Unlocked ); + + if (returnValue == VLC_SUCCESS) { + /* let's "play" */ + PL_LOCK; + playlist_item_t *p_item = playlist_ItemGetByInput( p_playlist, p_input ); + playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked, NULL, + p_item ); + PL_UNLOCK; + } + else + msg_Err( VLCIntf, "CAS: playlist add input failed :("); + + /* we're done with this input */ + vlc_gc_decref( p_input ); + + [_window performClose:sender]; } - (IBAction)openMedia:(id)sender { + /* preliminary implementation until the open panel is cleaned up */ + NSOpenPanel * openPanel = [NSOpenPanel openPanel]; + [openPanel setCanChooseDirectories:NO]; + [openPanel setResolvesAliases:YES]; + [openPanel setAllowsMultipleSelection:NO]; + [openPanel beginSheetForDirectory:nil file:nil types:nil modalForWindow: _window modalDelegate:self didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:nil]; } -- (IBAction)profileSelection:(id)sender +- (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo { - NSInteger index = [sender indexOfSelectedItem]; - if (index != ([sender numberOfItems] - 1)) + if (returnCode == NSOKButton) { - if (_currentProfile) - [_currentProfile release]; - _currentProfile = [[NSMutableArray alloc] initWithArray: [[_profileValueList objectAtIndex:index] componentsSeparatedByString:@";"]]; + [self setMRL: [NSString stringWithUTF8String:make_URI([[[panel URL] path] UTF8String], NULL)]]; + [self updateOKButton]; + [self updateDropView]; } } +- (IBAction)switchProfile:(id)sender +{ + NSUInteger index = [_profile_pop indexOfSelectedItem]; + if (index < ([_profileValueList count] - 1)) + [self resetCustomizationSheetBasedOnProfile:[_profileValueList objectAtIndex:index]]; +} + - (IBAction)customizeProfile:(id)sender { - [self resetCustomizationSheetBasedOnProfile:[_profile_pop indexOfSelectedItem]]; [NSApp beginSheet:_customize_panel modalForWindow:_window modalDelegate:self didEndSelector:NULL contextInfo:nil]; } - (IBAction)closeCustomizationSheet:(id)sender { - // sender == _customize_ok_btn ? [_customize_panel orderOut:sender]; [NSApp endSheet: _customize_panel]; + + /* update current profile based upon the sheet's values */ + /* Container(string), transcode video(bool), transcode audio(bool), + * use subtitles(bool), video codec(string), video bitrate(integer), + * scale(float), fps(float), width(integer, height(integer), + * audio codec(string), audio bitrate(integer), channels(integer), + * samplerate(integer), subtitle codec(string), subtitle overlay(bool) */ + + if (sender == _customize_ok_btn && [_currentProfile count] == 16) { + NSInteger i; + [_currentProfile replaceObjectAtIndex:0 withObject:[self currentEncapsulationFormatAsFileExtension:NO]]; + [_currentProfile replaceObjectAtIndex:1 withObject:[NSString stringWithFormat:@"%li", [_customize_vid_ckb state]]]; + [_currentProfile replaceObjectAtIndex:2 withObject:[NSString stringWithFormat:@"%li", [_customize_aud_ckb state]]]; + [_currentProfile replaceObjectAtIndex:3 withObject:[NSString stringWithFormat:@"%li", [_customize_subs_ckb state]]]; + i = [_customize_vid_codec_pop indexOfSelectedItem]; + if (i >= 0) + [_currentProfile replaceObjectAtIndex:4 withObject:[_videoCodecs objectAtIndex:i]]; + else + [_currentProfile replaceObjectAtIndex:4 withObject:@"none"]; + [_currentProfile replaceObjectAtIndex:5 withObject:[_customize_vid_bitrate_fld stringValue]]; + [_currentProfile replaceObjectAtIndex:6 withObject:[[_customize_vid_scale_pop selectedItem] title]]; + [_currentProfile replaceObjectAtIndex:7 withObject:[_customize_vid_framerate_fld stringValue]]; + [_currentProfile replaceObjectAtIndex:8 withObject:[_customize_vid_width_fld stringValue]]; + [_currentProfile replaceObjectAtIndex:9 withObject:[_customize_vid_height_fld stringValue]]; + i = [_customize_aud_codec_pop indexOfSelectedItem]; + if (i >= 0) + [_currentProfile replaceObjectAtIndex:10 withObject:[_audioCodecs objectAtIndex:i]]; + else + [_currentProfile replaceObjectAtIndex:10 withObject:@"none"]; + [_currentProfile replaceObjectAtIndex:11 withObject:[_customize_aud_bitrate_fld stringValue]]; + [_currentProfile replaceObjectAtIndex:12 withObject:[_customize_aud_channels_fld stringValue]]; + [_currentProfile replaceObjectAtIndex:13 withObject:[[_customize_aud_samplerate_pop selectedItem] title]]; + i = [_customize_subs_pop indexOfSelectedItem]; + if (i >= 0) + [_currentProfile replaceObjectAtIndex:14 withObject:[_subsCodecs objectAtIndex:i]]; + else + [_currentProfile replaceObjectAtIndex:14 withObject:@"none"]; + [_currentProfile replaceObjectAtIndex:15 withObject:[NSString stringWithFormat:@"%li", [_customize_subs_overlay_ckb state]]]; + } +} + +- (IBAction)iWantAFile:(id)sender +{ + NSRect boxFrame = [_destination_box frame]; + NSRect subViewFrame = [_destination_itwantafile_view frame]; + subViewFrame.origin.x = (boxFrame.size.width - subViewFrame.size.width) / 2; + subViewFrame.origin.y = ((boxFrame.size.height - subViewFrame.size.height) / 2) - 15.; + [_destination_itwantafile_view setFrame: subViewFrame]; + [[_destination_itwantafile_btn animator] setHidden: YES]; + [[_destination_itwantastream_btn animator] setHidden: YES]; + [_destination_box performSelector:@selector(addSubview:) withObject:_destination_itwantafile_view afterDelay:0.2]; + [[_destination_cancel_btn animator] setHidden:NO]; +} + +- (IBAction)iWantAStream:(id)sender +{ + NSRect boxFrame = [_destination_box frame]; + NSRect subViewFrame = [_destination_itwantastream_view frame]; + subViewFrame.origin.x = (boxFrame.size.width - subViewFrame.size.width) / 2; + subViewFrame.origin.y = ((boxFrame.size.height - subViewFrame.size.height) / 2) - 15.; + [_destination_itwantastream_view setFrame: subViewFrame]; + [[_destination_itwantafile_btn animator] setHidden: YES]; + [[_destination_itwantastream_btn animator] setHidden: YES]; + [_destination_box performSelector:@selector(addSubview:) withObject:_destination_itwantastream_view afterDelay:0.2]; + [[_destination_cancel_btn animator] setHidden:NO]; +} + +- (IBAction)cancelDestination:(id)sender +{ + if ([_destination_itwantastream_view superview] != nil) + [_destination_itwantastream_view removeFromSuperview]; + if ([_destination_itwantafile_view superview] != nil) + [_destination_itwantafile_view removeFromSuperview]; + + [_destination_cancel_btn setHidden:YES]; + [[_destination_itwantafile_btn animator] setHidden: NO]; + [[_destination_itwantastream_btn animator] setHidden: NO]; } -- (IBAction)chooseDestination:(id)sender +- (IBAction)browseFileDestination:(id)sender { - NSSavePanel * saveFilePanel = [[NSSavePanel alloc] init]; + NSSavePanel * saveFilePanel = [NSSavePanel savePanel]; [saveFilePanel setCanSelectHiddenExtension: YES]; [saveFilePanel setCanCreateDirectories: YES]; + if ([[_customize_encap_matrix selectedCell] tag] != RAW) // there is no clever guess for this + [saveFilePanel setAllowedFileTypes:[NSArray arrayWithObject:[self currentEncapsulationFormatAsFileExtension:YES]]]; [saveFilePanel beginSheetForDirectory:nil file:nil modalForWindow:_window modalDelegate:self didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:) contextInfo:nil]; } - (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo { if (returnCode == NSOKButton) { - _outputDestination = [[sheet URL] path]; + [self setOutputDestination:[[sheet URL] path]]; [_destination_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:_outputDestination]]; [[_destination_filename_stub_lbl animator] setHidden: YES]; [[_destination_filename_lbl animator] setHidden: NO]; } else { - _outputDestination = @""; + [self setOutputDestination:@""]; [[_destination_filename_lbl animator] setHidden: YES]; [[_destination_filename_stub_lbl animator] setHidden: NO]; } + [self updateOKButton]; +} + +- (IBAction)showStreamPanel:(id)sender +{ + [NSApp beginSheet:_stream_panel modalForWindow:_window modalDelegate:self didEndSelector:NULL contextInfo:nil]; +} + +- (IBAction)closeStreamPanel:(id)sender +{ + [_stream_panel orderOut:sender]; + [NSApp endSheet: _stream_panel]; } - (BOOL)performDragOperation:(id )sender { NSPasteboard *paste = [sender draggingPasteboard]; - NSArray *types = [NSArray arrayWithObject: NSFilenamesPboardType]; + NSArray *types = [NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]; NSString *desired_type = [paste availableTypeFromArray: types]; NSData *carried_data = [paste dataForType: desired_type]; @@ -291,9 +451,37 @@ static VLCConvertAndSave *_o_sharedInstance = nil; if ([values count] > 0) { [self setMRL: [NSString stringWithUTF8String:make_URI([[values objectAtIndex:0] UTF8String], NULL)]]; + [self updateOKButton]; [self updateDropView]; return YES; } + } else if( [desired_type isEqualToString:@"VLCPlaylistItemPboardType"] ) { + NSArray * array = [[[VLCMain sharedInstance] playlist] draggedItems]; + NSUInteger count = [array count]; + if (count > 0) { + playlist_t * p_playlist = pl_Get( VLCIntf ); + playlist_item_t * p_item = NULL; + + PL_LOCK; + /* let's look for the first proper input item */ + for (NSUInteger x = 0; x < count; x++) { + p_item = [[array objectAtIndex:x] pointerValue]; + if (p_item) { + if (p_item->p_input) { + if (p_item->p_input->psz_uri != nil) { + [self setMRL: [NSString stringWithFormat:@"%s", p_item->p_input->psz_uri]]; + [self updateDropView]; + [self updateOKButton]; + + PL_UNLOCK; + + return YES; + } + } + } + } + PL_UNLOCK; + } } } return NO; @@ -307,7 +495,7 @@ static VLCConvertAndSave *_o_sharedInstance = nil; NSString * path = [[NSURL URLWithString:_MRL] path]; [_dropin_media_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: path]]; NSImage * image = [[NSWorkspace sharedWorkspace] iconForFile: path]; - [image setSize:NSMakeSize(64,64)]; + [image setSize:NSMakeSize(128,128)]; [_dropin_icon_view setImage: image]; if (![_dropin_view superview]) { @@ -317,7 +505,7 @@ static VLCConvertAndSave *_o_sharedInstance = nil; subViewFrame.origin.y = (boxFrame.size.height - subViewFrame.size.height) / 2; [_dropin_view setFrame: subViewFrame]; [[_drop_image_view animator] setHidden: YES]; - [_drop_box performSelector:@selector(addSubview:) withObject:_dropin_view afterDelay:0.4]; + [_drop_box performSelector:@selector(addSubview:) withObject:_dropin_view afterDelay:0.6]; } } else { [_dropin_view removeFromSuperview]; @@ -325,17 +513,25 @@ static VLCConvertAndSave *_o_sharedInstance = nil; } } -- (void)resetCustomizationSheetBasedOnProfile:(NSInteger)profileNumber +- (void)updateOKButton +{ + if ([_outputDestination length] > 0 && [_MRL length] > 0) + [_ok_btn setEnabled: YES]; + else + [_ok_btn setEnabled: NO]; +} + +- (void)resetCustomizationSheetBasedOnProfile:(NSString *)profileString { /* Container(string), transcode video(bool), transcode audio(bool), * use subtitles(bool), video codec(string), video bitrate(integer), * scale(float), fps(float), width(integer, height(integer), - * audio codec(string), audio bitrate(integer), channels(integer), - * samplerate(integer), subtitle codec(string), subtitle overlay(bool) */ + * audio codec(string), audio bitrate(integer), channels(integer), + * samplerate(integer), subtitle codec(string), subtitle overlay(bool) */ - NSArray * components = [[_profileValueList objectAtIndex:profileNumber] componentsSeparatedByString:@";"]; + NSArray * components = [profileString componentsSeparatedByString:@";"]; if ([components count] != 16) { - msg_Err(VLCIntf, "CAS: the requested profile %li is invalid", profileNumber); + msg_Err(VLCIntf, "CAS: the requested profile '%s' is invalid", [profileString UTF8String]); return; } @@ -395,6 +591,10 @@ static VLCConvertAndSave *_o_sharedInstance = nil; } } } + + if (_currentProfile) + [_currentProfile release]; + _currentProfile = [[NSMutableArray alloc] initWithArray: [profileString componentsSeparatedByString:@";"]]; } - (void)selectCellByEncapsulationFormat:(NSString *)format @@ -413,13 +613,13 @@ static VLCConvertAndSave *_o_sharedInstance = nil; [_customize_encap_matrix selectCellWithTag:MP4]; else if([format isEqualToString:@"ps"]) [_customize_encap_matrix selectCellWithTag:MPEGPS]; - else if([format isEqualToString:@"mjpeg"]) + else if([format isEqualToString:@"mpjpeg"]) [_customize_encap_matrix selectCellWithTag:MJPEG]; else if([format isEqualToString:@"wav"]) [_customize_encap_matrix selectCellWithTag:WAV]; else if([format isEqualToString:@"flv"]) [_customize_encap_matrix selectCellWithTag:FLV]; - else if([format isEqualToString:@"mpg"]) + else if([format isEqualToString:@"mpeg1"]) [_customize_encap_matrix selectCellWithTag:MPEG1]; else if([format isEqualToString:@"mkv"]) [_customize_encap_matrix selectCellWithTag:MKV]; @@ -435,24 +635,181 @@ static VLCConvertAndSave *_o_sharedInstance = nil; msg_Err(VLCIntf, "CAS: unknown encap format requested for customization"); } +- (NSString *)currentEncapsulationFormatAsFileExtension:(BOOL)b_extension +{ + NSUInteger cellTag = [[_customize_encap_matrix selectedCell] tag]; + NSString * returnValue; + switch (cellTag) { + case MPEGTS: + returnValue = @"ts"; + break; + case WEBM: + returnValue = @"webm"; + break; + case OGG: + returnValue = @"ogg"; + break; + case MP4: + { + if (b_extension) + returnValue = @"m4v"; + else + returnValue = @"mp4"; + break; + } + case MPEGPS: + { + if (b_extension) + returnValue = @"mpg"; + else + returnValue = @"ps"; + break; + } + case MJPEG: + returnValue = @"mjpeg"; + break; + case WAV: + returnValue = @"wav"; + break; + case FLV: + returnValue = @"flv"; + break; + case MPEG1: + { + if (b_extension) + returnValue = @"mpg"; + else + returnValue = @"mpeg1"; + break; + } + case MKV: + returnValue = @"mkv"; + break; + case RAW: + returnValue = @"raw"; + break; + case AVI: + returnValue = @"avi"; + break; + case ASF: + returnValue = @"asf"; + break; + + default: + returnValue = @"none"; + break; + } + + return returnValue; +} + +- (NSString *)composedOptions +{ + NSMutableString *composedOptions = [[NSMutableString alloc] initWithString:@":sout=#transcode{"]; + if ([[_currentProfile objectAtIndex:1] intValue]) { + // video is enabled + [composedOptions appendFormat:@"vcodec=%@", [_currentProfile objectAtIndex:4]]; + if (![[_currentProfile objectAtIndex:4] isEqualToString:@"none"]) { + if ([[_currentProfile objectAtIndex:5] intValue] > 0) // bitrate + [composedOptions appendFormat:@",vb=%@", [_currentProfile objectAtIndex:5]]; + if ([[_currentProfile objectAtIndex:6] floatValue] > 0.) // scale + [composedOptions appendFormat:@",scale=%@", [_currentProfile objectAtIndex:6]]; + if ([[_currentProfile objectAtIndex:7] floatValue] > 0.) // fps + [composedOptions appendFormat:@",fps=%@", [_currentProfile objectAtIndex:7]]; + if ([[_currentProfile objectAtIndex:8] intValue] > 0) // width + [composedOptions appendFormat:@",width=%@", [_currentProfile objectAtIndex:8]]; + if ([[_currentProfile objectAtIndex:9] intValue] > 0) // height + [composedOptions appendFormat:@",height=%@", [_currentProfile objectAtIndex:9]]; + } + } + if ([[_currentProfile objectAtIndex:2] intValue]) { + // audio is enabled + + // add another comma in case video is enabled + if ([[_currentProfile objectAtIndex:1] intValue]) + [composedOptions appendString:@","]; + + [composedOptions appendFormat:@"acodec=%@", [_currentProfile objectAtIndex:10]]; + if (![[_currentProfile objectAtIndex:10] isEqualToString:@"none"]) { + [composedOptions appendFormat:@",ab=%@", [_currentProfile objectAtIndex:11]]; // bitrate + [composedOptions appendFormat:@",channels=%@", [_currentProfile objectAtIndex:12]]; // channel number + [composedOptions appendFormat:@",samplerate=%@", [_currentProfile objectAtIndex:13]]; // sample rate + } + } + if ([_currentProfile objectAtIndex:3]) { + // subtitles enabled + [composedOptions appendFormat:@",scodec=%@", [_currentProfile objectAtIndex:14]]; + if ([[_currentProfile objectAtIndex:15] intValue]) + [composedOptions appendFormat:@",soverlay"]; + } + + // add muxer + [composedOptions appendFormat:@"}:standard{mux=%@", [_currentProfile objectAtIndex:0]]; + + // add output destination (file only at this point) + [composedOptions appendFormat:@",dst=%@,access=file}", _outputDestination]; + + NSString * returnString = [NSString stringWithString:composedOptions]; + [composedOptions release]; + + return returnString; +} + @end +# pragma mark - +# pragma mark Drag and drop handling @implementation VLCDropEnabledBox - (void)awakeFromNib { - [self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]]; + [self registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]]; } - (NSDragOperation)draggingEntered:(id )sender { + b_activeDragAndDrop = YES; + [self setNeedsDisplay:YES]; + + if (OSX_SNOW_LEOPARD || OSX_LION) + [[NSCursor dragCopyCursor] set]; + if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) return NSDragOperationGeneric; return NSDragOperationNone; } +- (void)draggingEnded:(id < NSDraggingInfo >)sender +{ + [[NSCursor arrowCursor] set]; + b_activeDragAndDrop = NO; + [self setNeedsDisplay:YES]; +} + +- (void)draggingExited:(id < NSDraggingInfo >)sender +{ + [[NSCursor arrowCursor] set]; + b_activeDragAndDrop = NO; + [self setNeedsDisplay:YES]; +} + +- (void)drawRect:(NSRect)dirtyRect +{ + if (b_activeDragAndDrop) { + [[NSColor colorWithCalibratedRed:(.154/.255) green:(.154/.255) blue:(.154/.255) alpha:1.] setFill]; + NSRect frameRect = [[self contentView] bounds]; + frameRect.origin.x += 10; + frameRect.origin.y += 10; + frameRect.size.width -= 17; + frameRect.size.height -= 17; + NSFrameRectWithWidthUsingOperation(frameRect, 4., NSCompositeHighlight); + } + + [super drawRect:dirtyRect]; +} + - (BOOL)prepareForDragOperation:(id )sender { return YES; @@ -474,15 +831,12 @@ static VLCConvertAndSave *_o_sharedInstance = nil; - (void)awakeFromNib { - [self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]]; + [self registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]]; } - (NSDragOperation)draggingEntered:(id )sender { - if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) - return NSDragOperationGeneric; - - return NSDragOperationNone; + return [[[self superview] superview] draggingEntered:sender]; } - (BOOL)prepareForDragOperation:(id )sender @@ -506,15 +860,12 @@ static VLCConvertAndSave *_o_sharedInstance = nil; - (void)awakeFromNib { - [self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]]; + [self registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, @"VLCPlaylistItemPboardType", nil]]; } - (NSDragOperation)draggingEntered:(id )sender { - if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric) - return NSDragOperationGeneric; - - return NSDragOperationNone; + return [[[self superview] superview] draggingEntered:sender]; } - (BOOL)prepareForDragOperation:(id )sender