]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/ConvertAndSave.m
macosx: CAS: remove duplicated code
[vlc] / modules / gui / macosx / ConvertAndSave.m
index 3356ae446e8f4c09aa9d00e56a27bcd904c98590..cc735fd83dbaca0c1412259ba76d5297c3cb129b 100644 (file)
 
 @synthesize MRL=_MRL, outputDestination=_outputDestination, profileNames=_profileNames, profileValueList=_profileValueList, currentProfile=_currentProfile;
 
+@synthesize vidBitrate, vidFramerate, audBitrate, audChannels;
+
 static VLCConvertAndSave *_o_sharedInstance = nil;
 
 #pragma mark -
 #pragma mark Initialization
 
-+ (void)initialize{
++ (void)initialize
+{
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 
     /* We are using the same format as the Qt4 intf here:
@@ -84,11 +87,11 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
                                  @"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];
+                                 @"ogg;0;1;0;none;800;1;0;0;0;vorb;128;2;44100;none;0",
+                                 @"raw;0;1;0;none;800;1;0;0;0;mp3;128;2;44100;none;0",
+                                 @"mp4;0;1;0;none;800;1;0;0;0;mpga;128;2;44100;none;0",
+                                 @"raw;0;1;0;none;800;1;0;0;0;flac;128;2;44100;none;0",
+                                 @"wav;0;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)",
@@ -217,12 +220,18 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
     [self setProfileNames: [defaults arrayForKey:@"CASProfileNames"]];
     [self recreateProfilePopup];
 
-    _videoCodecs = @[@[@"MPEG-1", @"MPEG-2", @"MPEG-4", @"DIVX 1", @"DIVX 2", @"DIVX 3", @"H.263", @"H.264", @"VP8", @"WMV1", @"WMV2", @"M-JPEG", @"Theora", @"Dirac"],
-  @[@"mpgv", @"mp2v", @"mp4v", @"DIV1", @"DIV2", @"DIV3", @"H263", @"h264", @"VP80", @"WMV1", @"WMV2", @"MJPG", @"theo", @"drac"]];
-    _audioCodecs = @[@[@"MPEG Audio", @"MP3", @"MPEG 4 Audio (AAC)", @"A52/AC-3", @"Vorbis", @"Flac", @"Speex", @"WAV", @"WMA2"],
-                    @[@"mpga", @"mp3", @"mp4a", @"a52", @"vorb", @"flac", @"spx", @"s16l", @"wma2"]];
-    _subsCodecs = @[@[@"DVB subtitle", @"T.140"],
-                   @[@"dvbs", @"t140"]];
+    _videoCodecs = [[NSArray alloc] initWithObjects:
+                    @[@"MPEG-1", @"MPEG-2", @"MPEG-4", @"DIVX 1", @"DIVX 2", @"DIVX 3", @"H.263", @"H.264", @"VP8", @"WMV1", @"WMV2", @"M-JPEG", @"Theora", @"Dirac"],
+                    @[@"mpgv", @"mp2v", @"mp4v", @"DIV1", @"DIV2", @"DIV3", @"H263", @"h264", @"VP80", @"WMV1", @"WMV2", @"MJPG", @"theo", @"drac"],
+                    nil];
+    _audioCodecs = [[NSArray alloc] initWithObjects:
+                    @[@"MPEG Audio", @"MP3", @"MPEG 4 Audio (AAC)", @"A52/AC-3", @"Vorbis", @"Flac", @"Speex", @"WAV", @"WMA2"],
+                    @[@"mpga", @"mp3", @"mp4a", @"a52", @"vorb", @"flac", @"spx", @"s16l", @"wma2"],
+                    nil];
+    _subsCodecs = [[NSArray alloc] initWithObjects:
+                   @[@"DVB subtitle", @"T.140"],
+                   @[@"dvbs", @"t140"],
+                    nil];
 
     [_customize_vid_codec_pop removeAllItems];
     [_customize_vid_scale_pop removeAllItems];
@@ -230,9 +239,9 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
     [_customize_aud_samplerate_pop removeAllItems];
     [_customize_subs_pop removeAllItems];
 
-    [_customize_vid_codec_pop addItemsWithTitles:_videoCodecs[0]];
-    [_customize_aud_codec_pop addItemsWithTitles:_audioCodecs[0]];
-    [_customize_subs_pop addItemsWithTitles:_subsCodecs[0]];
+    [_customize_vid_codec_pop addItemsWithTitles:[_videoCodecs objectAtIndex:0]];
+    [_customize_aud_codec_pop addItemsWithTitles:[_audioCodecs objectAtIndex:0]];
+    [_customize_subs_pop addItemsWithTitles:[_subsCodecs objectAtIndex:0]];
 
     [_customize_aud_samplerate_pop addItemWithTitle:@"8000"];
     [_customize_aud_samplerate_pop addItemWithTitle:@"11025"];
@@ -251,7 +260,7 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
 
     [_ok_btn setEnabled: NO];
 
-    [self resetCustomizationSheetBasedOnProfile:self.profileValueList[0]];
+    [self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:0]];
 }
 
 # pragma mark -
@@ -269,7 +278,7 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
 {
     if (b_streaming) {
         if ([[[_stream_type_pop selectedItem] title] isEqualToString:@"HTTP"]) {
-            NSString *muxformat = self.currentProfile[0];
+            NSString *muxformat = [self.currentProfile objectAtIndex:0];
             if ([muxformat isEqualToString:@"wav"] || [muxformat isEqualToString:@"mov"] || [muxformat isEqualToString:@"mp4"] || [muxformat isEqualToString:@"mkv"]) {
                 NSBeginInformationalAlertSheet(_NS("Invalid container format for HTTP streaming"), _NS("OK"), @"", @"", _window,
                                                nil, nil, nil, nil,
@@ -330,8 +339,9 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
 - (IBAction)switchProfile:(id)sender
 {
     NSUInteger index = [_profile_pop indexOfSelectedItem];
-    if (index < ([self.profileValueList count] - 1))
-        [self resetCustomizationSheetBasedOnProfile:self.profileValueList[index]];
+    // last index is "custom"
+    if (index <= ([self.profileValueList count] - 1))
+        [self resetCustomizationSheetBasedOnProfile:[self.profileValueList objectAtIndex:index]];
 }
 
 - (IBAction)customizeProfile:(id)sender
@@ -543,7 +553,7 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
             NSArray *values = [[paste propertyListForType: NSFilenamesPboardType] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
 
             if ([values count] > 0) {
-                [self setMRL: @(vlc_path2uri([values[0] UTF8String], NULL))];
+                [self setMRL: @(vlc_path2uri([[values objectAtIndex:0] UTF8String], NULL))];
                 [self updateOKButton];
                 [self updateDropView];
                 return YES;
@@ -558,7 +568,7 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
                 PL_LOCK;
                 /* let's look for the first proper input item */
                 for (NSUInteger x = 0; x < count; x++) {
-                    p_item = [array[x] pointerValue];
+                    p_item = [[array objectAtIndex:x] pointerValue];
                     if (p_item) {
                         if (p_item->p_input) {
                             if (p_item->p_input->psz_uri != nil) {
@@ -592,8 +602,9 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
             [workArray addObject:text];
             [self setProfileNames:[[[NSArray alloc] initWithArray:workArray] autorelease]];
             [workArray release];
+
             workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
-            [workArray addObject:[[[NSArray alloc] initWithArray:self.currentProfile] autorelease]];
+            [workArray addObject:[self.currentProfile componentsJoinedByString:@";"]];
             [self setProfileValueList:[[[NSArray alloc] initWithArray:workArray] autorelease]];
             [workArray release];
 
@@ -622,13 +633,7 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
         [workArray release];
 
         /* update UI */
-        [_profile_pop removeAllItems];
-        [_profile_pop addItemsWithTitles:self.profileNames];
-        [_profile_pop addItemWithTitle:_NS("Custom")];
-        [[_profile_pop menu] addItem:[NSMenuItem separatorItem]];
-        [_profile_pop addItemWithTitle:_NS("Organize Profiles...")];
-        [[_profile_pop lastItem] setTarget: self];
-        [[_profile_pop lastItem] setAction: @selector(deleteProfileAction:)];
+        [self recreateProfilePopup];
 
         /* update internals */
         [self switchProfile:self];
@@ -684,57 +689,61 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
         return;
     }
 
-    [self selectCellByEncapsulationFormat:components[0]];
-    [_customize_vid_ckb setState:[components[1] intValue]];
-    [_customize_aud_ckb setState:[components[2] intValue]];
-    [_customize_subs_ckb setState:[components[3] intValue]];
-    [_customize_vid_bitrate_fld setStringValue:components[5]];
-    [_customize_vid_scale_pop selectItemWithTitle:components[6]];
-    [_customize_vid_framerate_fld setStringValue:components[7]];
-    [_customize_vid_width_fld setStringValue:components[8]];
-    [_customize_vid_height_fld setStringValue:components[9]];
-    [_customize_aud_bitrate_fld setStringValue:components[11]];
-    [_customize_aud_channels_fld setStringValue:components[12]];
-    [_customize_aud_samplerate_pop selectItemWithTitle:components[13]];
-    [_customize_subs_overlay_ckb setState:[components[15] intValue]];
+    [self selectCellByEncapsulationFormat:[components objectAtIndex:0]];
+    [_customize_vid_ckb setState:[[components objectAtIndex:1] intValue]];
+    [_customize_aud_ckb setState:[[components objectAtIndex:2] intValue]];
+    [_customize_subs_ckb setState:[[components objectAtIndex:3] intValue]];
+    [self setVidBitrate:[[components objectAtIndex:5] intValue]];
+    [_customize_vid_scale_pop selectItemWithTitle:[components objectAtIndex:6]];
+    [self setVidFramerate:[[components objectAtIndex:7] intValue]];
+    [_customize_vid_width_fld setStringValue:[components objectAtIndex:8]];
+    [_customize_vid_height_fld setStringValue:[components objectAtIndex:9]];
+    [self setAudBitrate:[[components objectAtIndex:11] intValue]];
+    [self setAudChannels:[[components objectAtIndex:12] intValue]];
+    [_customize_aud_samplerate_pop selectItemWithTitle:[components objectAtIndex:13]];
+    [_customize_subs_overlay_ckb setState:[[components objectAtIndex:15] intValue]];
 
     /* since there is no proper lookup mechanism in arrays, we need to implement a string specific one ourselves */
-    NSArray * tempArray = _videoCodecs[1];
+    NSArray * tempArray = [_videoCodecs objectAtIndex:1];
     NSUInteger count = [tempArray count];
-    NSString * searchString = components[4];
-    if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"]) {
+    NSString * searchString = [components objectAtIndex:4];
+    int videoKeep = [searchString isEqualToString:@"copy"];
+    [_customize_vid_keep_ckb setState:videoKeep];
+    if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"] || videoKeep) {
         [_customize_vid_codec_pop selectItemAtIndex:-1];
     } else {
         for (NSUInteger x = 0; x < count; x++) {
-            if ([tempArray[x] isEqualToString: searchString]) {
+            if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
                 [_customize_vid_codec_pop selectItemAtIndex:x];
                 break;
             }
         }
     }
 
-    tempArray = _audioCodecs[1];
+    tempArray = [_audioCodecs objectAtIndex:1];
     count = [tempArray count];
-    searchString = components[10];
-    if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"]) {
+    searchString = [components objectAtIndex:10];
+    int audioKeep = [searchString isEqualToString:@"copy"];
+    [_customize_aud_keep_ckb setState:audioKeep];
+    if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"] || audioKeep) {
         [_customize_aud_codec_pop selectItemAtIndex:-1];
     } else {
         for (NSUInteger x = 0; x < count; x++) {
-            if ([tempArray[x] isEqualToString: searchString]) {
+            if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
                 [_customize_aud_codec_pop selectItemAtIndex:x];
                 break;
             }
         }
     }
 
-    tempArray = _subsCodecs[1];
+    tempArray = [_subsCodecs objectAtIndex:1];
     count = [tempArray count];
-    searchString = components[14];
+    searchString = [components objectAtIndex:14];
     if ([searchString isEqualToString:@"none"] || [searchString isEqualToString:@"0"]) {
         [_customize_subs_pop selectItemAtIndex:-1];
     } else {
         for (NSUInteger x = 0; x < count; x++) {
-            if ([tempArray[x] isEqualToString: searchString]) {
+            if ([[tempArray objectAtIndex:x] isEqualToString: searchString]) {
                 [_customize_subs_pop selectItemAtIndex:x];
                 break;
             }
@@ -853,47 +862,63 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
 - (NSString *)composedOptions
 {
     NSMutableString *composedOptions = [[NSMutableString alloc] initWithString:@":sout=#transcode{"];
-    if ([self.currentProfile[1] intValue]) {
+    BOOL haveVideo = YES;
+    if ([[self.currentProfile objectAtIndex:1] intValue]) {
         // video is enabled
-        [composedOptions appendFormat:@"vcodec=%@", self.currentProfile[4]];
-        if (![self.currentProfile[4] isEqualToString:@"none"]) {
-            if ([self.currentProfile[5] intValue] > 0) // bitrate
-                [composedOptions appendFormat:@",vb=%@", self.currentProfile[5]];
-            if ([self.currentProfile[6] floatValue] > 0.) // scale
-                [composedOptions appendFormat:@",scale=%@", self.currentProfile[6]];
-            if ([self.currentProfile[7] floatValue] > 0.) // fps
-                [composedOptions appendFormat:@",fps=%@", self.currentProfile[7]];
-            if ([self.currentProfile[8] intValue] > 0) // width
-                [composedOptions appendFormat:@",width=%@", self.currentProfile[8]];
-            if ([self.currentProfile[9] intValue] > 0) // height
-                [composedOptions appendFormat:@",height=%@", self.currentProfile[9]];
+        if (![[self.currentProfile objectAtIndex:4] isEqualToString:@"copy"]) {
+        [composedOptions appendFormat:@"vcodec=%@", [self.currentProfile objectAtIndex:4]];
+            if ([[self.currentProfile objectAtIndex:5] intValue] > 0) // bitrate
+                [composedOptions appendFormat:@",vb=%@", [self.currentProfile objectAtIndex:5]];
+            if ([[self.currentProfile objectAtIndex:6] floatValue] > 0.) // scale
+                [composedOptions appendFormat:@",scale=%@", [self.currentProfile objectAtIndex:6]];
+            if ([[self.currentProfile objectAtIndex:7] floatValue] > 0.) // fps
+                [composedOptions appendFormat:@",fps=%@", [self.currentProfile objectAtIndex:7]];
+            if ([[self.currentProfile objectAtIndex:8] intValue] > 0) // width
+                [composedOptions appendFormat:@",width=%@", [self.currentProfile objectAtIndex:8]];
+            if ([[self.currentProfile objectAtIndex:9] intValue] > 0) // height
+                [composedOptions appendFormat:@",height=%@", [self.currentProfile objectAtIndex:9]];
+        } else {
+            haveVideo = NO;
         }
+    } else {
+        [composedOptions appendString:@"vcodec=none"];
     }
-    if ([self.currentProfile[2] intValue]) {
+
+    BOOL haveAudio = YES;
+    if ([[self.currentProfile objectAtIndex:2] intValue]) {
         // audio is enabled
+        if (![[self.currentProfile objectAtIndex:10] isEqualToString:@"copy"]) {
+            if(haveVideo)
+                [composedOptions appendString:@","];
+            [composedOptions appendFormat:@"acodec=%@", [self.currentProfile objectAtIndex:10]];
 
-        // add another comma in case video is enabled
-        if ([self.currentProfile[1] intValue])
-            [composedOptions appendString:@","];
 
-        [composedOptions appendFormat:@"acodec=%@", self.currentProfile[10]];
-        if (![self.currentProfile[10] isEqualToString:@"none"]) {
-            [composedOptions appendFormat:@",ab=%@", self.currentProfile[11]]; // bitrate
-            [composedOptions appendFormat:@",channels=%@", self.currentProfile[12]]; // channel number
-            [composedOptions appendFormat:@",samplerate=%@", self.currentProfile[13]]; // sample rate
+            [composedOptions appendFormat:@"acodec=%@", [self.currentProfile objectAtIndex:10]];
+            [composedOptions appendFormat:@",ab=%@", [self.currentProfile objectAtIndex:11]]; // bitrate
+            [composedOptions appendFormat:@",channels=%@", [self.currentProfile objectAtIndex:12]]; // channel number
+            [composedOptions appendFormat:@",samplerate=%@", [self.currentProfile objectAtIndex:13]]; // sample rate
+        } else {
+            haveAudio = NO;
         }
+    } else {
+        if(haveVideo)
+            [composedOptions appendString:@","];
+
+        [composedOptions appendString:@"acodec=none"];
     }
-    if (self.currentProfile[3]) {
+    if ([self.currentProfile objectAtIndex:3]) {
+        if(haveVideo || haveAudio)
+            [composedOptions appendString:@","];
         // subtitles enabled
-        [composedOptions appendFormat:@",scodec=%@", self.currentProfile[14]];
-        if ([self.currentProfile[15] intValue])
+        [composedOptions appendFormat:@"scodec=%@", [self.currentProfile objectAtIndex:14]];
+        if ([[self.currentProfile objectAtIndex:15] intValue])
             [composedOptions appendFormat:@",soverlay"];
     }
 
     if (!b_streaming) {
         /* file transcoding */
         // add muxer
-        [composedOptions appendFormat:@"}:standard{mux=%@", self.currentProfile[0]];
+        [composedOptions appendFormat:@"}:standard{mux=%@", [self.currentProfile objectAtIndex:0]];
 
         // add output destination
         [composedOptions appendFormat:@",access=file{no-overwrite},dst=%@}", _outputDestination];
@@ -906,7 +931,7 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
         else if ([[[_stream_type_pop selectedItem] title] isEqualToString:@"MMSH"])
             [composedOptions appendFormat:@":standard{mux=asfh,dst=%@,port=%@,access=mmsh", _outputDestination, [_stream_port_fld stringValue]];
         else
-            [composedOptions appendFormat:@":standard{mux=%@,dst=%@,port=%@,access=http", self.currentProfile[0], [_stream_port_fld stringValue], _outputDestination];
+            [composedOptions appendFormat:@":standard{mux=%@,dst=%@,port=%@,access=http", [self.currentProfile objectAtIndex:0], [_stream_port_fld stringValue], _outputDestination];
 
         if ([_stream_sap_ckb state])
             [composedOptions appendFormat:@",sap,name=\"%@\"", [_stream_channel_fld stringValue]];
@@ -944,27 +969,43 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_vid_ckb state]]];
     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_aud_ckb state]]];
     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_subs_ckb state]]];
-    i = [_customize_vid_codec_pop indexOfSelectedItem];
-    if (i >= 0)
-        [self.currentProfile addObject: _videoCodecs[1][i]];
-    else
-        [self.currentProfile addObject: @"none"];
-    [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_vid_bitrate_fld intValue]]];
+    
+    NSString *videoCodec;
+    if([_customize_vid_keep_ckb state] == NSOnState)
+        videoCodec = @"copy";
+    else {
+        i = [_customize_vid_codec_pop indexOfSelectedItem];
+        if (i >= 0)
+            videoCodec = [[_videoCodecs objectAtIndex:1] objectAtIndex:i];
+        else
+            videoCodec = @"none";
+    }
+    [self.currentProfile addObject: videoCodec];
+
+    [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self vidBitrate]]];
     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [[[_customize_vid_scale_pop selectedItem] title] intValue]]];
-    [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_vid_framerate_fld intValue]]];
+    [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self vidFramerate]]];
     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_vid_width_fld intValue]]];
     [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_vid_height_fld intValue]]];
-    i = [_customize_aud_codec_pop indexOfSelectedItem];
-    if (i >= 0)
-        [self.currentProfile addObject: _audioCodecs[1][i]];
-    else
-        [self.currentProfile addObject: @"none"];
-    [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_aud_bitrate_fld intValue]]];
-    [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_aud_channels_fld intValue]]];
+
+    NSString *audioCodec;
+    if([_customize_aud_keep_ckb state] == NSOnState)
+        audioCodec = @"copy";
+    else {
+        i = [_customize_aud_codec_pop indexOfSelectedItem];
+        if (i >= 0)
+            audioCodec = [[_audioCodecs objectAtIndex:1] objectAtIndex:i];
+        else
+            audioCodec = @"none";
+    }
+    [self.currentProfile addObject: audioCodec];
+    
+    [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self audBitrate]]];
+    [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [self audChannels]]];
     [self.currentProfile addObject: [[_customize_aud_samplerate_pop selectedItem] title]];
     i = [_customize_subs_pop indexOfSelectedItem];
     if (i >= 0)
-        [self.currentProfile addObject: _subsCodecs[1][i]];
+        [self.currentProfile addObject: [[_subsCodecs objectAtIndex:1] objectAtIndex:i]];
     else
         [self.currentProfile addObject: @"none"];
     [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_subs_overlay_ckb state]]];