@@ -9,9 +9,10 @@ use crate::{
9
9
decoder:: VideoDecoderOptions ,
10
10
encoder:: { AudioEncoder , AudioEncoderThread , VideoEncoder , VideoEncoderThread } ,
11
11
layout:: Layout ,
12
- media:: { MediaStreamId , MediaStreamIdGenerator } ,
12
+ media:: { MediaSample , MediaStreamId , MediaStreamIdGenerator } ,
13
13
mixer_audio:: AudioMixerThread ,
14
14
mixer_video:: VideoMixerThread ,
15
+ processor:: { MediaProcessor , MediaProcessorInput , MediaProcessorOutput } ,
15
16
source:: { AudioSourceThread , VideoSourceThread } ,
16
17
stats:: { ProcessorStats , Seconds , SharedStats } ,
17
18
types:: CodecName ,
@@ -70,12 +71,12 @@ impl Composer {
70
71
) ;
71
72
72
73
// 映像ミキサーとエンコーダーを準備
73
- let encoded_video_rx = self
74
+ let mut encoded_video_rx = self
74
75
. create_video_mixer_and_encoder ( error_flag. clone ( ) , stats. clone ( ) , video_source_rxs)
75
76
. or_fail ( ) ?;
76
77
77
78
// 音声ミキサーとエンコーダーを準備
78
- let encoded_audio_rx = self
79
+ let mut encoded_audio_rx = self
79
80
. create_audio_mixer_and_encoder ( error_flag. clone ( ) , stats. clone ( ) , audio_source_rxs)
80
81
. or_fail ( ) ?;
81
82
@@ -95,7 +96,29 @@ impl Composer {
95
96
)
96
97
. or_fail ( ) ?;
97
98
98
- while let Some ( timestamp) = mp4_writer. poll ( ) . or_fail ( ) ? {
99
+ loop {
100
+ match mp4_writer. process_output ( ) . or_fail ( ) ? {
101
+ MediaProcessorOutput :: Finished => break ,
102
+ MediaProcessorOutput :: Pending { awaiting_stream_id }
103
+ if awaiting_stream_id == writer_input_audio_stream_id =>
104
+ {
105
+ let input = MediaProcessorInput {
106
+ stream_id : awaiting_stream_id,
107
+ sample : encoded_audio_rx. recv ( ) . map ( MediaSample :: audio_data) ,
108
+ } ;
109
+ mp4_writer. process_input ( input) . or_fail ( ) ?;
110
+ }
111
+ MediaProcessorOutput :: Pending { awaiting_stream_id } => {
112
+ let input = MediaProcessorInput {
113
+ stream_id : awaiting_stream_id,
114
+ sample : encoded_video_rx. recv ( ) . map ( MediaSample :: video_frame) ,
115
+ } ;
116
+ mp4_writer. process_input ( input) . or_fail ( ) ?;
117
+ }
118
+ MediaProcessorOutput :: Processed { .. } => unreachable ! ( ) ,
119
+ }
120
+
121
+ let timestamp = mp4_writer. current_duration ( ) ;
99
122
progress_bar. set_position ( timestamp. as_secs ( ) ) ;
100
123
if error_flag. get ( ) {
101
124
// ファイル読み込み、デコード、合成、エンコード、のいずれかで失敗したものがあるとここに来る
0 commit comments