+- (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 ([[self.currentProfile objectAtIndex:1] intValue]) {
+ // video is enabled
+ [composedOptions appendFormat:@"vcodec=%@", [self.currentProfile objectAtIndex:4]];
+ if (![[self.currentProfile objectAtIndex:4] isEqualToString:@"none"]) {
+ 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]];
+ }
+ }
+ if ([[self.currentProfile objectAtIndex:2] intValue]) {
+ // audio is enabled
+
+ // add another comma in case video is enabled
+ if ([[self.currentProfile objectAtIndex:1] intValue])
+ [composedOptions appendString:@","];
+
+ [composedOptions appendFormat:@"acodec=%@", [self.currentProfile objectAtIndex:10]];
+ if (![[self.currentProfile objectAtIndex:10] isEqualToString:@"none"]) {
+ [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
+ }
+ }
+ if ([self.currentProfile objectAtIndex:3]) {
+ // subtitles enabled
+ [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 objectAtIndex:0]];
+
+ // add output destination
+ [composedOptions appendFormat:@",dst=%@,access=file}", _outputDestination];
+ } else {
+ /* streaming */
+ if ([[[_stream_type_pop selectedItem] title] isEqualToString:@"RTP"])
+ [composedOptions appendFormat:@":rtp{mux=ts,dst=%@,port=%@", _outputDestination, [_stream_port_fld stringValue]];
+ else if ([[[_stream_type_pop selectedItem] title] isEqualToString:@"UDP"])
+ [composedOptions appendFormat:@":standard{mux=ts,dst=%@,port=%@,access=udp", _outputDestination, [_stream_port_fld stringValue]];
+ 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 objectAtIndex:0], [_stream_port_fld stringValue], _outputDestination];
+
+ if ([_stream_sap_ckb state])
+ [composedOptions appendFormat:@",sap,name=\"%@\"", [_stream_channel_fld stringValue]];
+ if ([_stream_sdp_matrix selectedCell] != [_stream_sdp_matrix cellWithTag:0]) {
+ NSInteger tag = [[_stream_sdp_matrix selectedCell] tag];
+ switch (tag) {
+ case 1:
+ [composedOptions appendFormat:@",sdp=\"http://%@\"", [_stream_sdp_fld stringValue]];
+ break;
+ case 2:
+ [composedOptions appendFormat:@",sdp=\"rtsp://%@\"", [_stream_sdp_fld stringValue]];
+ break;
+ case 3:
+ [composedOptions appendFormat:@",sdp=\"file://%s\"", vlc_path2uri([[_stream_sdp_fld stringValue] UTF8String], NULL)];
+ default:
+ break;
+ }
+ }
+
+ [composedOptions appendString:@"} :sout-keep"];
+ }
+
+ NSString * returnString = [NSString stringWithString:composedOptions];
+ [composedOptions release];
+
+ return returnString;
+}
+
+- (void)updateCurrentProfile
+{
+ [self.currentProfile removeAllObjects];
+
+ NSInteger i;
+ [self.currentProfile addObject: [self currentEncapsulationFormatAsFileExtension:NO]];
+ [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 objectAtIndex:1] objectAtIndex:i]];
+ else
+ [self.currentProfile addObject: @"none"];
+ [self.currentProfile addObject: [NSString stringWithFormat:@"%i", [_customize_vid_bitrate_fld intValue]]];
+ [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", [_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 objectAtIndex:1] objectAtIndex: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]]];
+ [self.currentProfile addObject: [[_customize_aud_samplerate_pop selectedItem] title]];
+ i = [_customize_subs_pop indexOfSelectedItem];
+ if (i >= 0)
+ [self.currentProfile addObject: [[_subsCodecs objectAtIndex:1] objectAtIndex:i]];
+ else
+ [self.currentProfile addObject: @"none"];
+ [self.currentProfile addObject: [NSString stringWithFormat:@"%li", [_customize_subs_overlay_ckb state]]];
+}
+
+- (void)storeProfilesOnDisk
+{
+ NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
+ [defaults setObject:_profileNames forKey:@"CASProfileNames"];
+ [defaults setObject:_profileValueList forKey:@"CASProfiles"];
+ [defaults synchronize];
+}
+
+- (void)recreateProfilePopup
+{
+ [_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:)];
+}
+