1
- /* vmp-server - A virtual multimedia processor
1
+ /* vmpserverd - A virtual multimedia processor
2
2
* Copyright (C) 2023 Hugo Melder
3
3
*
4
4
* SPDX-License-Identifier: MIT
13
13
#import " VMPRTSPServer.h"
14
14
#import " VMPServerMain.h"
15
15
16
- #include < graphviz/gvc.h>
17
16
#include < graphviz/cgraph.h>
17
+ #include < graphviz/gvc.h>
18
18
19
19
#include " config.h"
20
20
21
21
// Convert a DOT graph to SVG
22
22
static NSData *convertDOTtoSVG (NSData *dotData, NSError **error) {
23
23
NSData *svgData;
24
- GVC_t *gvc;
24
+ GVC_t *gvc;
25
25
Agraph_t *g;
26
- char *rendered;
27
- unsigned int length;
28
-
26
+ char *rendered;
27
+ unsigned int length;
28
+
29
29
// Initialize Graphviz context
30
30
gvc = gvContext ();
31
31
if (!gvc) {
34
34
}
35
35
36
36
// Create a graph from the DOT data
37
- g = agmemread ((char *)[dotData bytes ]);
37
+ g = agmemread ((char *) [dotData bytes ]);
38
38
if (!g) {
39
39
VMP_FAST_ERROR (error, VMPErrorCodeGraphvizError, @" Failed to create graph from DOT data" );
40
40
gvFreeContext (gvc);
58
58
59
59
svgData = [NSData dataWithBytes: rendered length: length];
60
60
61
- // Clean up
62
- gvFreeRenderData (rendered);
63
- gvFreeLayout (gvc, g);
64
- agclose (g);
65
- gvFreeContext (gvc);
61
+ // Clean up
62
+ gvFreeRenderData (rendered);
63
+ gvFreeLayout (gvc, g);
64
+ agclose (g);
65
+ gvFreeContext (gvc);
66
66
67
67
return svgData;
68
68
}
@@ -433,8 +433,8 @@ - (HKHandlerBlock)_recordingCreateV1 {
433
433
}
434
434
435
435
decodedBody = [NSJSONSerialization JSONObjectWithData: [request HTTPBody ]
436
- options: 0
437
- error: NULL ];
436
+ options: 0
437
+ error: NULL ];
438
438
if (!decodedBody) {
439
439
NSDictionary *response = @{
440
440
@" error" : @" Failed to decode JSON body" ,
@@ -465,7 +465,7 @@ - (HKHandlerBlock)_recordingCreateV1 {
465
465
NSDateFormatter *isoFormatter = [[NSDateFormatter alloc ] init ];
466
466
NSDate *stopAtDate;
467
467
468
- [isoFormatter setDateFormat: @" yyyy-MM-dd'T'HH:mm:ssZ" ];
468
+ [isoFormatter setDateFormat: @" yyyy-MM-dd'T'HH:mm:ssZ" ];
469
469
470
470
stopAtDate = [isoFormatter dateFromString: stopAt];
471
471
if (!stopAtDate) {
@@ -474,7 +474,7 @@ - (HKHandlerBlock)_recordingCreateV1 {
474
474
};
475
475
return [HKHTTPJSONResponse responseWithJSONObject: response status: 400 error: NULL ];
476
476
}
477
-
477
+
478
478
// Check if stop date is reasonable (not more then 8 hours in the future)
479
479
// TODO: Add option to define this in configuration
480
480
if ([stopAtDate timeIntervalSinceNow ] > 8 * 60 * 60 ) {
@@ -483,7 +483,7 @@ - (HKHandlerBlock)_recordingCreateV1 {
483
483
};
484
484
return [HKHTTPJSONResponse responseWithJSONObject: response status: 400 error: NULL ];
485
485
}
486
-
486
+
487
487
// Create a new recording with default options
488
488
// TODO: Allow for user to specify options
489
489
[recordingOptions addEntriesFromDictionary: @{
@@ -500,37 +500,36 @@ - (HKHandlerBlock)_recordingCreateV1 {
500
500
now = [NSDate date ];
501
501
url = [NSURL fileURLWithPathComponents: @[
502
502
[_configuration scratchDirectory ],
503
- [NSString stringWithFormat: @" recording_%@ .mkv" , [isoFormatter stringFromDate: now]]
503
+ [NSString stringWithFormat: @" recording_%@ .mkv" , [isoFormatter stringFromDate: now]]
504
504
]];
505
505
506
506
recording = [_rtspServer defaultRecordingWithOptions: recordingOptions
507
- path: url
508
- deadline: stopAtDate
509
- error: &error];
507
+ path: url
508
+ deadline: stopAtDate
509
+ error: &error];
510
510
if (!recording) {
511
511
NSString *desc;
512
512
513
- desc = [NSString stringWithFormat: @" Failed to create recording: %@ " , [error localizedDescription ]];
514
- NSDictionary *response = @{
515
- @" error" : desc
516
- };
513
+ desc = [NSString
514
+ stringWithFormat: @" Failed to create recording: %@ " , [error localizedDescription ]];
515
+ NSDictionary *response = @{@" error" : desc};
517
516
return [HKHTTPJSONResponse responseWithJSONObject: response status: 500 error: NULL ];
518
517
}
519
518
520
- if (![_rtspServer scheduleRecording: recording]) {
521
- NSDictionary *response = @{
522
- @" error" : @" Failed to schedule recording"
523
- };
519
+ if (![_rtspServer scheduleRecording: recording]) {
520
+ NSDictionary *response = @{@" error" : @" Failed to schedule recording" };
524
521
return [HKHTTPJSONResponse responseWithJSONObject: response status: 500 error: NULL ];
525
522
}
526
523
527
524
return [HKHTTPJSONResponse responseWithJSONObject: @{
528
525
@" status" : @" ok" ,
529
526
@" path" : [url path ],
530
- @" startAt" : [isoFormatter stringFromDate: now],
527
+ @" startAt" : [isoFormatter stringFromDate: now],
531
528
@" stopAt" : [isoFormatter stringFromDate: stopAtDate],
532
- @" numberOfSeconds" : @([stopAtDate timeIntervalSinceDate: now])
533
- } status: 200 error: NULL ];
529
+ @" numberOfSeconds" : @([stopAtDate timeIntervalSinceDate: now])
530
+ }
531
+ status: 200
532
+ error: NULL ];
534
533
};
535
534
}
536
535
@@ -574,9 +573,8 @@ - (void)setupHTTPHandlers {
574
573
handler: [self _mountpointGraphHandlerV1 ]];
575
574
// POST /api/v1/recording/create
576
575
recordingCreateRoute = [HKRoute routeWithPath: @" /api/v1/recording/create"
577
- method: HKHTTPMethodPOST
578
- handler: [self _recordingCreateV1 ]];
579
-
576
+ method: HKHTTPMethodPOST
577
+ handler: [self _recordingCreateV1 ]];
580
578
581
579
[router registerRoute: statusRoute withCORSHandler: CORSHandler];
582
580
[router registerRoute: configRoute withCORSHandler: CORSHandler];
0 commit comments