Skip to content

Commit

Permalink
Clean up -_startChannelPipelinesWithError:
Browse files Browse the repository at this point in the history
  • Loading branch information
hmelder committed Oct 27, 2024
1 parent 191a604 commit b170142
Showing 1 changed file with 41 additions and 59 deletions.
100 changes: 41 additions & 59 deletions Daemons/vmpserverd/src/VMPRTSPServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,17 @@ - (BOOL)_startChannelPipelinesWithError:(NSError **)error {
for (VMPConfigChannelModel *channel in channels) {
NSString *type, *name;
NSDictionary<NSString *, id> *properties;
VMPPipelineManager *manager;
NSDictionary *vars = nil;
NSString *pipeline;

type = [channel type];
name = [channel name];
properties = [channel properties];

if ([type isEqualToString:VMPConfigChannelTypeV4L2]) {
VMPInfo(@"Starting channel %@ of type %@", name, type);
NSString *device, *pipeline;
NSDictionary *vars;
VMPPipelineManager *manager;
NSString *device;

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

vars = @{@"V4L2DEV" : device, @"VIDEOCHANNEL.0" : name};
VMPDebug(@"Substitution dictionary for v4l2 pipeline: %@", vars);

pipeline = [_currentProfile pipelineForChannelType:type variables:vars error:error];
if (!pipeline) {
return NO;
}

manager = [VMPPipelineManager managerWithLaunchArgs:pipeline
channel:name
delegate:self];
if (![manager start]) {
CONFIG_ERROR(error, @"Failed to start V4L2 pipeline")
return NO;
}

[_managedPipelines addObject:manager];

VMPInfo(@"V4L2 pipeline for channel %@ started successfully", name);
} else if ([type isEqualToString:VMPConfigChannelTypeVideoTest]) {
NSNumber *width, *height;
NSString *pipeline;
NSDictionary *vars;
VMPPipelineManager *manager;

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

// Substitute variables in pipeline template
pipeline = [_currentProfile pipelineForChannelType:type variables:vars error:error];
if (!pipeline) {
return NO;
}
// Skip pipeline creation if type is unknown
if (nil == vars) {
continue;
}

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

manager = [VMPPipelineManager managerWithLaunchArgs:pipeline
channel:name
delegate:self];
if (![manager start]) {
CONFIG_ERROR(error, @"Failed to start video test pipeline")
return NO;
}
[_managedPipelines addObject:manager];
pipeline = [_currentProfile pipelineForChannelType:type variables:vars error:error];
if (!pipeline) {
return NO;
}

VMPInfo(@"Video test pipeline for channel %@ started successfully", name);
manager = [VMPPipelineManager managerWithLaunchArgs:pipeline channel:name delegate:self];
if (![manager start]) {
CONFIG_ERROR(error, @"Failed to start pipeline")
return NO;
}

[_managedPipelines addObject:manager];

VMPInfo(@"pipeline '%@' for channel %@ started successfully", manager, name);
}

VMPDebug(@"Finished starting channel pipelines");
Expand Down Expand Up @@ -666,11 +647,11 @@ - (void)stop {

- (VMPRecordingManager *)defaultRecordingWithOptions:(NSDictionary *)options
path:(NSURL *)path
deadline: (NSDate *)date
error: (NSError **) error {
deadline:(NSDate *)date
error:(NSError **)error {
NSString *videoChannel = nil;
NSString *audioChannel = nil;
NSString *pulseDevice = nil;
NSString *pulseDevice = nil;
NSNumber *videoBitrate = nil;
NSNumber *audioBitrate = nil;
NSNumber *width = nil;
Expand All @@ -695,11 +676,12 @@ - (VMPRecordingManager *)defaultRecordingWithOptions:(NSDictionary *)options
}

if (!video || !audio) {
CONFIG_ERROR(error, @"'videoChannel' or 'audioChannel' key missing in options dictionary and not defined in channel config");
CONFIG_ERROR(error, @"'videoChannel' or 'audioChannel' key missing in options dictionary "
@"and not defined in channel config");
return nil;
}

if (![[audio type] isEqualToString: VMPConfigChannelTypePulseAudio]) {
if (![[audio type] isEqualToString:VMPConfigChannelTypePulseAudio]) {
CONFIG_ERROR(error, @"Currently, only audio channels of type 'pulse' are supported");
return nil;
}
Expand Down Expand Up @@ -748,17 +730,17 @@ - (VMPRecordingManager *)defaultRecordingWithOptions:(NSDictionary *)options
// Substitution dictionary for video pipeline
vars = @{
@"VIDEOCHANNEL" : videoChannel,
@"WIDTH": [width stringValue],
@"HEIGHT": [height stringValue],
@"BITRATE": [videoBitrate stringValue]
@"WIDTH" : [width stringValue],
@"HEIGHT" : [height stringValue],
@"BITRATE" : [videoBitrate stringValue]
};
template = [template stringBySubstitutingVariables: vars error: error];
template = [template stringBySubstitutingVariables:vars error:error];
if (!template) {
return nil;
}

pipeline = [template mutableCopy];
[pipeline appendFormat: @" ! matroskamux name=mux ! filesink location=%@ ", [path path]];
[pipeline appendFormat:@" ! matroskamux name=mux ! filesink location=%@ ", [path path]];

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

// Substitution directory for audio pipeline
vars = @{
@"PULSEDEV": pulseDevice,
@"BITRATE": [audioBitrate stringValue]
};
template = [template stringBySubstitutingVariables: vars error: error];
vars = @{@"PULSEDEV" : pulseDevice, @"BITRATE" : [audioBitrate stringValue]};
template = [template stringBySubstitutingVariables:vars error:error];
if (!template) {
return nil;
}

[pipeline appendString: template];
[pipeline appendString: @" ! mux."];
[pipeline appendString:template];
[pipeline appendString:@" ! mux."];

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

return [VMPRecordingManager recorderWithLaunchArgs: pipeline path: path recordUntil: date delegate: self];
return [VMPRecordingManager recorderWithLaunchArgs:pipeline
path:path
recordUntil:date
delegate:self];
}

/*
Expand Down

0 comments on commit b170142

Please sign in to comment.