@@ -20,19 +20,17 @@ use crate::profiles::*;
20
20
use crate :: session:: Session ;
21
21
22
22
use std:: collections:: HashMap ;
23
+ use std:: fmt;
23
24
use std:: time:: Duration ;
24
25
use std:: time:: Instant ;
25
- use std:: fmt;
26
26
27
27
use async_trait:: async_trait;
28
+ use tracing:: debug;
29
+ use tracing:: info;
30
+ use tracing:: warn;
28
31
use xtra_proc:: actor;
29
32
use xtra_proc:: handler;
30
33
31
- use slog:: debug;
32
- use slog:: error;
33
- use slog:: info;
34
- use slog:: warn;
35
-
36
34
pub use tokio:: process:: ChildStdout ;
37
35
38
36
pub struct StreamStat {
@@ -61,8 +59,6 @@ pub struct StateManager {
61
59
pub stream_stats : HashMap < String , StreamStat > ,
62
60
/// Contains the exit status of dead sessions
63
61
pub exit_statuses : HashMap < String , String > ,
64
- /// Logger
65
- pub logger : slog:: Logger ,
66
62
}
67
63
68
64
impl fmt:: Debug for __ActorStateManager:: StateManager {
@@ -78,18 +74,16 @@ impl fmt::Debug for __ActorStateManager::StateManager {
78
74
79
75
impl fmt:: Debug for StateManager {
80
76
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
81
- f. debug_struct ( "StateManagerActor" )
82
- . finish ( )
77
+ f. debug_struct ( "StateManagerActor" ) . finish ( )
83
78
}
84
79
}
85
80
86
81
#[ actor]
87
82
impl StateManager {
88
- pub fn new ( outdir : String , ffmpeg : String , logger : slog :: Logger ) -> Self {
83
+ pub fn new ( outdir : String , ffmpeg : String ) -> Self {
89
84
Self {
90
85
outdir,
91
86
ffmpeg,
92
- logger,
93
87
sessions : HashMap :: new ( ) ,
94
88
stream_stats : HashMap :: new ( ) ,
95
89
exit_statuses : HashMap :: new ( ) ,
@@ -107,7 +101,11 @@ impl StateManager {
107
101
let first_tag = if let Some ( x) = profile_chain. first ( ) {
108
102
x. tag ( )
109
103
} else {
110
- error ! ( self . logger, "Supplied profile chain is empty" ; "profile" => format!( "{:?}" , profile_args) ) ;
104
+ tracing:: error!(
105
+ "Supplied profile chain is empty {}" ,
106
+ profile = format!( "{:?}" , profile_args)
107
+ ) ;
108
+
111
109
return Err ( NightfallError :: ProfileChainExhausted ) ;
112
110
} ;
113
111
@@ -137,8 +135,8 @@ impl StateManager {
137
135
} ;
138
136
139
137
info ! (
140
- self . logger ,
141
- "New session {} map {} -> {}" , & session_id, profile_args. input_ctx. stream, tag
138
+ "New session {} map {} -> {}" ,
139
+ & session_id, profile_args. input_ctx. stream, tag
142
140
) ;
143
141
144
142
profile_args. output_ctx . outdir = format ! ( "{}/{}" , & self . outdir, session_id) ;
@@ -150,7 +148,12 @@ impl StateManager {
150
148
. unwrap_or ( false )
151
149
&& profile_chain. len ( ) == 1 ;
152
150
153
- info ! ( self . logger, "Session {} chain {}" , & session_id, chain; "direct_play" => is_direct_play) ;
151
+ info ! (
152
+ "Session {} chain {} {}" ,
153
+ & session_id,
154
+ chain,
155
+ direct_play = is_direct_play
156
+ ) ;
154
157
155
158
let new_session = Session :: new (
156
159
session_id. clone ( ) ,
@@ -176,10 +179,7 @@ impl StateManager {
176
179
if let Some ( status) = session. exit_status . take ( ) {
177
180
if !status. success ( ) {
178
181
if let Some ( x) = session. next_profile ( ) {
179
- info ! (
180
- self . logger,
181
- "Session {} chunk={} trying profile {}" , & id, chunk, x
182
- ) ;
182
+ info ! ( "Session {} chunk={} trying profile {}" , & id, chunk, x) ;
183
183
session. reset_to ( session. start_num ( ) ) ;
184
184
} else {
185
185
return Err ( NightfallError :: ProfileChainExhausted ) ;
@@ -253,16 +253,12 @@ impl StateManager {
253
253
stats. last_hard_seek = Instant :: now ( ) ;
254
254
stats. hard_seeked_at = chunk;
255
255
256
- debug ! (
257
- self . logger,
258
- "Resetting {} to chunk {} because user seeked." , & id, chunk
259
- ) ;
256
+ debug ! ( "Resetting {} to chunk {} because user seeked." , & id, chunk) ;
260
257
}
261
258
262
259
Err ( NightfallError :: ChunkNotDone )
263
260
} else {
264
261
let chunk_path = session. chunk_to_path ( chunk) ;
265
- let log = self . logger . clone ( ) ;
266
262
let path = chunk_path. clone ( ) ;
267
263
let real_segment = session. real_segment ;
268
264
@@ -272,31 +268,33 @@ impl StateManager {
272
268
}
273
269
274
270
if !session. is_direct_play {
275
- match patch_segment ( log , path, real_segment) . await {
271
+ match patch_segment ( path, real_segment) . await {
276
272
Ok ( seq) => session. real_segment = seq,
277
273
// Sometimes we get partial chunks, when playback goes linearly (no hard seeks have
278
274
// occured) we can ignore this, but when the user seeks, the player doesnt query
279
275
// `init.mp4` again, so we have to move the video data from `init.mp4` into
280
276
// `N.m4s`.
281
277
Err ( NightfallError :: PartialSegment ( _) ) => {
282
278
if session. chunks_since_init >= 1 {
283
- debug ! ( self . logger, "Got a partial segment, patching because the user has most likely seeked." ) ;
279
+ debug ! ( "Got a partial segment, patching because the user has most likely seeked." ) ;
280
+
284
281
match patch_init_segment (
285
- self . logger . clone ( ) ,
286
282
session. init_seg ( ) ,
287
283
chunk_path. clone ( ) ,
288
284
real_segment,
289
285
)
290
- . await
291
- {
292
- Ok ( seq) => session. real_segment = seq,
293
- Err ( e) => {
294
- warn ! ( self . logger, "Failed to patch init segment." ; "error" => e. to_string( ) )
295
- }
286
+ . await
287
+ {
288
+ Ok ( seq) => session. real_segment = seq,
289
+ Err ( e) => {
290
+ warn ! ( "Failed to patch init segment. {}" , error = e. to_string( ) )
296
291
}
292
+ }
297
293
}
298
294
}
299
- Err ( e) => warn ! ( self . logger, "Failed to patch segment." ; "error" => e. to_string( ) ) ,
295
+ Err ( e) => {
296
+ warn ! ( "Failed to patch segment. {}" , error = e. to_string( ) )
297
+ }
300
298
}
301
299
}
302
300
@@ -325,7 +323,7 @@ impl StateManager {
325
323
326
324
let stats = self . stream_stats . entry ( id) . or_default ( ) ;
327
325
328
- if !session. has_started ( ) || session. is_direct_play {
326
+ if !session. has_started ( ) || session. is_direct_play {
329
327
return Ok ( false ) ;
330
328
}
331
329
// if we are seeking backwards we always want to restart the stream
@@ -356,7 +354,7 @@ impl StateManager {
356
354
. sessions
357
355
. get_mut ( & id)
358
356
. ok_or ( NightfallError :: SessionDoesntExist ) ?;
359
- info ! ( self . logger , "Killing session {}" , id) ;
357
+ info ! ( "Killing session {}" , id) ;
360
358
session. join ( ) . await ;
361
359
session. set_timeout ( ) ;
362
360
@@ -369,7 +367,7 @@ impl StateManager {
369
367
. sessions
370
368
. get_mut ( & id)
371
369
. ok_or ( NightfallError :: SessionDoesntExist ) ?;
372
- info ! ( self . logger , "Killing session {}" , id) ;
370
+ info ! ( "Killing session {}" , id) ;
373
371
session. join ( ) . await ;
374
372
375
373
Ok ( ( ) )
@@ -427,7 +425,7 @@ impl StateManager {
427
425
} ;
428
426
429
427
if !to_reap. is_empty ( ) {
430
- info ! ( self . logger , "Reaping {} streams" , to_reap. len( ) ) ;
428
+ info ! ( "Reaping {} streams" , to_reap. len( ) ) ;
431
429
}
432
430
433
431
for ( k, v) in to_reap. iter_mut ( ) {
@@ -446,7 +444,7 @@ impl StateManager {
446
444
}
447
445
448
446
if cnt != 0 {
449
- info ! ( self . logger , "Paused {} streams" , cnt) ;
447
+ info ! ( "Paused {} streams" , cnt) ;
450
448
}
451
449
452
450
Ok ( ( ) )
0 commit comments