66import jakarta .validation .Valid ;
77import lombok .extern .log4j .Log4j2 ;
88import org .springframework .beans .factory .annotation .Autowired ;
9+ import org .springframework .beans .factory .annotation .Value ;
910import org .springframework .data .domain .Pageable ;
1011import org .springframework .http .ResponseEntity ;
1112import org .springframework .security .access .prepost .PreAuthorize ;
2223import uk .gov .hmcts .reform .preapi .controllers .params .SearchRecordings ;
2324import uk .gov .hmcts .reform .preapi .dto .CaptureSessionDTO ;
2425import uk .gov .hmcts .reform .preapi .dto .CreateRecordingDTO ;
26+ import uk .gov .hmcts .reform .preapi .dto .EncodeJobDTO ;
2527import uk .gov .hmcts .reform .preapi .dto .media .AssetDTO ;
2628import uk .gov .hmcts .reform .preapi .dto .media .GenerateAssetDTO ;
2729import uk .gov .hmcts .reform .preapi .dto .media .GenerateAssetResponseDTO ;
2830import uk .gov .hmcts .reform .preapi .dto .media .LiveEventDTO ;
2931import uk .gov .hmcts .reform .preapi .dto .media .PlaybackDTO ;
3032import uk .gov .hmcts .reform .preapi .enums .CaseState ;
33+ import uk .gov .hmcts .reform .preapi .enums .EncodeTransform ;
3134import uk .gov .hmcts .reform .preapi .enums .RecordingStatus ;
3235import uk .gov .hmcts .reform .preapi .exception .AssetFilesNotFoundException ;
3336import uk .gov .hmcts .reform .preapi .exception .ConflictException ;
4043import uk .gov .hmcts .reform .preapi .media .storage .AzureIngestStorageService ;
4144import uk .gov .hmcts .reform .preapi .security .authentication .UserAuthentication ;
4245import uk .gov .hmcts .reform .preapi .services .CaptureSessionService ;
46+ import uk .gov .hmcts .reform .preapi .services .EncodeJobService ;
4347import uk .gov .hmcts .reform .preapi .services .RecordingService ;
4448
4549import java .util .List ;
@@ -56,19 +60,27 @@ public class MediaServiceController extends PreApiController {
5660 private final AzureFinalStorageService azureFinalStorageService ;
5761 private final AzureIngestStorageService azureIngestStorageService ;
5862 private final RecordingService recordingService ;
63+ private final EncodeJobService encodeJobService ;
64+
65+ private final boolean enableEnhancedProcessing ;
5966
6067 @ Autowired
6168 public MediaServiceController (MediaServiceBroker mediaServiceBroker ,
6269 CaptureSessionService captureSessionService ,
6370 RecordingService recordingService ,
6471 AzureFinalStorageService azureFinalStorageService ,
65- AzureIngestStorageService azureIngestStorageService ) {
72+ AzureIngestStorageService azureIngestStorageService ,
73+ EncodeJobService encodeJobService ,
74+ @ Value ("${feature-flags.enable-enhanced-processing:}" )
75+ Boolean enableEnhancedProcessing ) {
6676 super ();
6777 this .mediaServiceBroker = mediaServiceBroker ;
6878 this .captureSessionService = captureSessionService ;
6979 this .recordingService = recordingService ;
7080 this .azureFinalStorageService = azureFinalStorageService ;
7181 this .azureIngestStorageService = azureIngestStorageService ;
82+ this .encodeJobService = encodeJobService ;
83+ this .enableEnhancedProcessing = enableEnhancedProcessing ;
7284 }
7385
7486 @ GetMapping ("/health" )
@@ -188,19 +200,48 @@ public ResponseEntity<CaptureSessionDTO> stopLiveEvent(
188200 }
189201
190202 var recordingId = UUID .randomUUID ();
191- dto = captureSessionService .stopCaptureSession (captureSessionId , RecordingStatus .PROCESSING , recordingId );
203+ if (!enableEnhancedProcessing ) {
204+ // todo code to removed once feature fully enabled (deprecated)
205+ dto = captureSessionService .stopCaptureSession (captureSessionId , RecordingStatus .PROCESSING , recordingId );
206+ }
192207
193208 var mediaService = mediaServiceBroker .getEnabledMediaService ();
194209 try {
195- var status = mediaService .stopLiveEvent (dto , recordingId );
196- if (status == RecordingStatus .FAILURE ) {
197- throw new UnknownServerException ("Encountered an error during encoding process for CaptureSession("
198- + captureSessionId
199- + ")" );
210+ if (!enableEnhancedProcessing ) {
211+ // todo code to removed once feature fully enabled (deprecated)
212+ var status = mediaService .stopLiveEventAndProcess (dto , recordingId );
213+ if (status == RecordingStatus .FAILURE ) {
214+ throw new UnknownServerException ("Encountered an error during encoding process for CaptureSession("
215+ + captureSessionId
216+ + ")" );
217+ }
218+ dto = captureSessionService .stopCaptureSession (captureSessionId , status , recordingId );
219+ } else {
220+ mediaService .stopLiveEvent (dto , recordingId );
221+ var jobName = mediaService .triggerProcessingStep1 (
222+ dto ,
223+ dto .getId ().toString ().replace ("-" , "" ),
224+ recordingId
225+ );
226+ if (jobName == null ) {
227+ dto =
228+ captureSessionService .stopCaptureSession (captureSessionId , RecordingStatus .NO_RECORDING , null );
229+ } else {
230+ var encodeJob = new EncodeJobDTO ();
231+ encodeJob .setCaptureSessionId (captureSessionId );
232+ encodeJob .setJobName (jobName );
233+ encodeJob .setRecordingId (recordingId );
234+ encodeJob .setTransform (EncodeTransform .ENCODE_FROM_INGEST );
235+ encodeJobService .upsert (encodeJob );
236+ dto = captureSessionService .stopCaptureSession (
237+ captureSessionId ,
238+ RecordingStatus .PROCESSING ,
239+ recordingId
240+ );
241+ }
200242 }
201- dto = captureSessionService .stopCaptureSession (captureSessionId , status , recordingId );
202243 } catch (Exception e ) {
203- captureSessionService .stopCaptureSession (captureSessionId , RecordingStatus .FAILURE , recordingId );
244+ captureSessionService .stopCaptureSession (captureSessionId , RecordingStatus .FAILURE , null );
204245 throw e ;
205246 }
206247
0 commit comments