@@ -48,95 +48,110 @@ public bool ConfigureAndOpen(Action<DecoderContext> config, IDictionary<string,
48
48
49
49
public void Decode ( AvPacketWrapper packet , ref AvFrameWrapper frame )
50
50
{
51
- int decodeResult ;
52
-
53
- // 尝试发送
54
- logger . LogDebug ( "Try send packet to decoder." ) ;
55
-
56
- var sendResult = ctx . TrySendPacket ( packet ) ;
57
- if ( sendResult == ffmpeg . AVERROR ( ffmpeg . EAGAIN ) )
58
- {
59
- // reference:
60
- // * tree/release/6.1/fftools/ffmpeg_dec.c:567
61
- // 理论上不会出现 EAGAIN
62
-
63
- logger . LogWarning (
64
- "Receive {error} after sent, this could be cause by ffmpeg bug or some reason, ignored this message." ,
65
- nameof ( ffmpeg . EAGAIN ) ) ;
66
- sendResult = 0 ;
67
- }
68
-
69
- if ( sendResult == 0 || sendResult == ffmpeg . AVERROR_EOF )
70
- {
71
- // 发送成功
72
- logger . LogDebug ( "PacketBuffer sent success, try get decoded frame." ) ;
73
- // 获取解码结果
74
- decodeResult = ctx . TryReceivedFrame ( ref frame ) ;
75
- }
76
- else
77
- {
78
- var error = new ApplicationException ( FfMpegExtension . av_strerror ( sendResult ) ) ;
79
-
80
- // 无法处理的发送失败
81
- logger . LogError ( error , "Send packet to decoder failed.\n " ) ;
82
-
83
- throw error ;
84
- }
85
-
86
- if ( decodeResult < 0 )
51
+ using ( logger . BeginScope ( "{name}.{function}" ,
52
+ Context . ToString ( ) , nameof ( Decode ) ) )
87
53
{
88
- // 错误处理
89
- ApplicationException error ;
90
- var message = FfMpegExtension . av_strerror ( decodeResult ) ;
54
+ int decodeResult ;
55
+ // 尝试发送
91
56
92
- if ( decodeResult == ffmpeg . AVERROR_EOF )
93
- {
94
- // reference:
95
- // * https://ffmpeg.org/doxygen/6.1/group__lavc__decoding.html#ga11e6542c4e66d3028668788a1a74217c
96
- // > the codec has been fully flushed, and there will be no more output frames
97
- // 理论上不会出现 EOF
98
- message =
99
- "the codec has been fully flushed, and there will be no more output frames." ;
57
+ var scope = logger . BeginScope ( packet . ToString ( ) ) ;
100
58
101
- error = new ( message ) ;
59
+ logger . LogDebug ( "Try send packet to decoder." ) ;
102
60
103
- logger . LogError ( error , "Received EOF from decoder.\n " ) ;
104
- }
105
- else if ( decodeResult == ffmpeg . AVERROR ( ffmpeg . EAGAIN ) )
61
+ var sendResult = ctx . TrySendPacket ( packet ) ;
62
+ if ( sendResult == ffmpeg . AVERROR ( ffmpeg . EAGAIN ) )
106
63
{
107
64
// reference:
108
- // * tree/release/6.1/fftools/ffmpeg_dec.c:596
109
- // * https://ffmpeg.org/doxygen/6.1/group__lavc__decoding.html#ga11e6542c4e66d3028668788a1a74217c
110
- // > output is not available in this state - user must try to send new input
65
+ // * tree/release/6.1/fftools/ffmpeg_dec.c:567
111
66
// 理论上不会出现 EAGAIN
112
- message =
113
- "output is not available in this state - user must try to send new input" ;
114
67
115
- //if (_streamOption.KeyFrameOnly)
116
- //{
117
- // // 抛出异常,仅关键帧模式中,该错误不可能通过发送更多需要的包来解决
118
- // error = new(message);
68
+ logger . LogWarning (
69
+ "Receive {error} after sent, this could be cause by ffmpeg bug or some reason, ignored this message." ,
70
+ nameof ( ffmpeg . EAGAIN ) ) ;
71
+ sendResult = 0 ;
72
+ }
119
73
120
- // _logger.LogError(error, "Received EAGAIN from decoder.\n");
121
- // throw error;
122
- //}
74
+ if ( sendResult == 0 || sendResult == ffmpeg . AVERROR_EOF )
75
+ {
76
+ // 发送成功
77
+ logger . LogDebug ( "PacketBuffer sent success, try get decoded frame." ) ;
123
78
124
- // 忽略错误,发送下一个包进行编码,可能足够的包进入解码器可以解决
125
- logger . LogWarning ( "Receive EAGAIN from decoder, retry." ) ;
126
- // continue;
79
+ scope ? . Dispose ( ) ;
80
+ // 获取解码结果
81
+ decodeResult = ctx . TryReceivedFrame ( ref frame ) ;
82
+ scope = logger . BeginScope ( frame . ToString ( ) ) ;
127
83
}
128
84
else
129
85
{
130
- error = new ( message ) ;
131
- logger . LogError ( error , "Uncaught error occured during decoding.\n " ) ;
86
+ var error = new ApplicationException ( FfMpegExtension . av_strerror ( sendResult ) ) ;
87
+
88
+ // 无法处理的发送失败
89
+ logger . LogError ( error , "Send packet to decoder failed.\n " ) ;
90
+
91
+ scope ? . Dispose ( ) ;
132
92
throw error ;
133
93
}
134
- }
135
94
136
- // 解码正常
137
- logger . LogInformation ( "Decode frame success. type {type}, pts {pts}." ,
138
- frame . PictureType . ToString ( ) ,
139
- frame . GetPresentationTimeSpan ( ctx . TimeBase ) . ToString ( "c" ) ) ;
95
+ if ( decodeResult < 0 )
96
+ {
97
+ // 错误处理
98
+ ApplicationException error ;
99
+ var message = FfMpegExtension . av_strerror ( decodeResult ) ;
100
+
101
+ if ( decodeResult == ffmpeg . AVERROR_EOF )
102
+ {
103
+ // reference:
104
+ // * https://ffmpeg.org/doxygen/6.1/group__lavc__decoding.html#ga11e6542c4e66d3028668788a1a74217c
105
+ // > the codec has been fully flushed, and there will be no more output frames
106
+ // 理论上不会出现 EOF
107
+ message =
108
+ "the codec has been fully flushed, and there will be no more output frames." ;
109
+
110
+ error = new ( message ) ;
111
+
112
+ logger . LogError ( error , "Received EOF from decoder.\n " ) ;
113
+ }
114
+ else if ( decodeResult == ffmpeg . AVERROR ( ffmpeg . EAGAIN ) )
115
+ {
116
+ // reference:
117
+ // * tree/release/6.1/fftools/ffmpeg_dec.c:596
118
+ // * https://ffmpeg.org/doxygen/6.1/group__lavc__decoding.html#ga11e6542c4e66d3028668788a1a74217c
119
+ // > output is not available in this state - user must try to send new input
120
+ // 理论上不会出现 EAGAIN
121
+ message =
122
+ "output is not available in this state - user must try to send new input" ;
123
+
124
+ //if (_streamOption.KeyFrameOnly)
125
+ //{
126
+ // // 抛出异常,仅关键帧模式中,该错误不可能通过发送更多需要的包来解决
127
+ // error = new(message);
128
+
129
+ // _logger.LogError(error, "Received EAGAIN from decoder.\n");
130
+ // throw error;
131
+ //}
132
+
133
+ // 忽略错误,发送下一个包进行编码,可能足够的包进入解码器可以解决
134
+ logger . LogWarning ( "Receive EAGAIN from decoder, retry." ) ;
135
+ // continue;
136
+ }
137
+ else
138
+ {
139
+ error = new ( message ) ;
140
+ logger . LogError ( error , "Uncaught error occured during decoding.\n " ) ;
141
+
142
+ scope ? . Dispose ( ) ;
143
+
144
+ throw error ;
145
+ }
146
+ }
147
+
148
+ // 解码正常
149
+ logger . LogInformation ( "Decode frame success. type {type}, pts {pts}." ,
150
+ frame . PictureType . ToString ( ) ,
151
+ frame . GetPresentationTimeSpan ( ctx . TimeBase ) . ToString ( "c" ) ) ;
152
+
153
+ scope ? . Dispose ( ) ;
154
+ }
140
155
}
141
156
142
157
public void Dispose ( )
0 commit comments