Skip to content

Commit b170142

Browse files
committed
Clean up -_startChannelPipelinesWithError:
1 parent 191a604 commit b170142

File tree

1 file changed

+41
-59
lines changed

1 file changed

+41
-59
lines changed

Daemons/vmpserverd/src/VMPRTSPServer.m

+41-59
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,17 @@ - (BOOL)_startChannelPipelinesWithError:(NSError **)error {
324324
for (VMPConfigChannelModel *channel in channels) {
325325
NSString *type, *name;
326326
NSDictionary<NSString *, id> *properties;
327+
VMPPipelineManager *manager;
328+
NSDictionary *vars = nil;
329+
NSString *pipeline;
327330

328331
type = [channel type];
329332
name = [channel name];
330333
properties = [channel properties];
331334

332335
if ([type isEqualToString:VMPConfigChannelTypeV4L2]) {
333336
VMPInfo(@"Starting channel %@ of type %@", name, type);
334-
NSString *device, *pipeline;
335-
NSDictionary *vars;
336-
VMPPipelineManager *manager;
337+
NSString *device;
337338

338339
device = properties[@"device"];
339340
if (!device) {
@@ -342,29 +343,8 @@ - (BOOL)_startChannelPipelinesWithError:(NSError **)error {
342343
}
343344

344345
vars = @{@"V4L2DEV" : device, @"VIDEOCHANNEL.0" : name};
345-
VMPDebug(@"Substitution dictionary for v4l2 pipeline: %@", vars);
346-
347-
pipeline = [_currentProfile pipelineForChannelType:type variables:vars error:error];
348-
if (!pipeline) {
349-
return NO;
350-
}
351-
352-
manager = [VMPPipelineManager managerWithLaunchArgs:pipeline
353-
channel:name
354-
delegate:self];
355-
if (![manager start]) {
356-
CONFIG_ERROR(error, @"Failed to start V4L2 pipeline")
357-
return NO;
358-
}
359-
360-
[_managedPipelines addObject:manager];
361-
362-
VMPInfo(@"V4L2 pipeline for channel %@ started successfully", name);
363346
} else if ([type isEqualToString:VMPConfigChannelTypeVideoTest]) {
364347
NSNumber *width, *height;
365-
NSString *pipeline;
366-
NSDictionary *vars;
367-
VMPPipelineManager *manager;
368348

369349
VMPInfo(@"Starting channel %@ of type %@", name, type);
370350
width = properties[@"width"];
@@ -380,28 +360,29 @@ - (BOOL)_startChannelPipelinesWithError:(NSError **)error {
380360
@"WIDTH" : [width stringValue],
381361
@"HEIGHT" : [height stringValue]
382362
};
383-
VMPDebug(@"Substitution dictionary for video test pipeline: %@", vars);
363+
}
384364

385-
// Substitute variables in pipeline template
386-
pipeline = [_currentProfile pipelineForChannelType:type variables:vars error:error];
387-
if (!pipeline) {
388-
return NO;
389-
}
365+
// Skip pipeline creation if type is unknown
366+
if (nil == vars) {
367+
continue;
368+
}
390369

391-
VMPInfo(@"Creating video test pipeline manager with width %@ and height %@", width,
392-
height);
370+
VMPDebug(@"Substitution dictionary for pipeline with name '%@': %@", name, vars);
393371

394-
manager = [VMPPipelineManager managerWithLaunchArgs:pipeline
395-
channel:name
396-
delegate:self];
397-
if (![manager start]) {
398-
CONFIG_ERROR(error, @"Failed to start video test pipeline")
399-
return NO;
400-
}
401-
[_managedPipelines addObject:manager];
372+
pipeline = [_currentProfile pipelineForChannelType:type variables:vars error:error];
373+
if (!pipeline) {
374+
return NO;
375+
}
402376

403-
VMPInfo(@"Video test pipeline for channel %@ started successfully", name);
377+
manager = [VMPPipelineManager managerWithLaunchArgs:pipeline channel:name delegate:self];
378+
if (![manager start]) {
379+
CONFIG_ERROR(error, @"Failed to start pipeline")
380+
return NO;
404381
}
382+
383+
[_managedPipelines addObject:manager];
384+
385+
VMPInfo(@"pipeline '%@' for channel %@ started successfully", manager, name);
405386
}
406387

407388
VMPDebug(@"Finished starting channel pipelines");
@@ -666,11 +647,11 @@ - (void)stop {
666647

667648
- (VMPRecordingManager *)defaultRecordingWithOptions:(NSDictionary *)options
668649
path:(NSURL *)path
669-
deadline: (NSDate *)date
670-
error: (NSError **) error {
650+
deadline:(NSDate *)date
651+
error:(NSError **)error {
671652
NSString *videoChannel = nil;
672653
NSString *audioChannel = nil;
673-
NSString *pulseDevice = nil;
654+
NSString *pulseDevice = nil;
674655
NSNumber *videoBitrate = nil;
675656
NSNumber *audioBitrate = nil;
676657
NSNumber *width = nil;
@@ -695,11 +676,12 @@ - (VMPRecordingManager *)defaultRecordingWithOptions:(NSDictionary *)options
695676
}
696677

697678
if (!video || !audio) {
698-
CONFIG_ERROR(error, @"'videoChannel' or 'audioChannel' key missing in options dictionary and not defined in channel config");
679+
CONFIG_ERROR(error, @"'videoChannel' or 'audioChannel' key missing in options dictionary "
680+
@"and not defined in channel config");
699681
return nil;
700682
}
701683

702-
if (![[audio type] isEqualToString: VMPConfigChannelTypePulseAudio]) {
684+
if (![[audio type] isEqualToString:VMPConfigChannelTypePulseAudio]) {
703685
CONFIG_ERROR(error, @"Currently, only audio channels of type 'pulse' are supported");
704686
return nil;
705687
}
@@ -748,17 +730,17 @@ - (VMPRecordingManager *)defaultRecordingWithOptions:(NSDictionary *)options
748730
// Substitution dictionary for video pipeline
749731
vars = @{
750732
@"VIDEOCHANNEL" : videoChannel,
751-
@"WIDTH": [width stringValue],
752-
@"HEIGHT": [height stringValue],
753-
@"BITRATE": [videoBitrate stringValue]
733+
@"WIDTH" : [width stringValue],
734+
@"HEIGHT" : [height stringValue],
735+
@"BITRATE" : [videoBitrate stringValue]
754736
};
755-
template = [template stringBySubstitutingVariables: vars error: error];
737+
template = [template stringBySubstitutingVariables:vars error:error];
756738
if (!template) {
757739
return nil;
758740
}
759741

760742
pipeline = [template mutableCopy];
761-
[pipeline appendFormat: @" ! matroskamux name=mux ! filesink location=%@ ", [path path]];
743+
[pipeline appendFormat:@" ! matroskamux name=mux ! filesink location=%@ ", [path path]];
762744

763745
template = [_currentProfile recordings][@"pulse"];
764746
if (!template) {
@@ -767,17 +749,14 @@ - (VMPRecordingManager *)defaultRecordingWithOptions:(NSDictionary *)options
767749
}
768750

769751
// Substitution directory for audio pipeline
770-
vars = @{
771-
@"PULSEDEV": pulseDevice,
772-
@"BITRATE": [audioBitrate stringValue]
773-
};
774-
template = [template stringBySubstitutingVariables: vars error: error];
752+
vars = @{@"PULSEDEV" : pulseDevice, @"BITRATE" : [audioBitrate stringValue]};
753+
template = [template stringBySubstitutingVariables:vars error:error];
775754
if (!template) {
776755
return nil;
777756
}
778757

779-
[pipeline appendString: template];
780-
[pipeline appendString: @" ! mux."];
758+
[pipeline appendString:template];
759+
[pipeline appendString:@" ! mux."];
781760

782761
/* pipeline now contains a full GStreamer pipeline for encoding
783762
and writing out a matroska file to path.
@@ -786,7 +765,10 @@ - (VMPRecordingManager *)defaultRecordingWithOptions:(NSDictionary *)options
786765
filesink location=<PATH> <AUDIO_PIPELINE> ! mux. -e
787766
*/
788767

789-
return [VMPRecordingManager recorderWithLaunchArgs: pipeline path: path recordUntil: date delegate: self];
768+
return [VMPRecordingManager recorderWithLaunchArgs:pipeline
769+
path:path
770+
recordUntil:date
771+
delegate:self];
790772
}
791773

792774
/*

0 commit comments

Comments
 (0)