File tree Expand file tree Collapse file tree 2 files changed +25
-11
lines changed Expand file tree Collapse file tree 2 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,23 @@ FfmpegAudioCursor::
210
210
*/
211
211
void FfmpegAudioCursor::
212
212
cleanup () {
213
+ if (_audio_ctx && _audio_ctx->codec ) {
214
+ #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 100)
215
+ // We need to drain the codec to prevent a memory leak.
216
+ avcodec_send_packet (_audio_ctx, nullptr );
217
+ while (avcodec_receive_frame (_audio_ctx, _frame) == 0 ) {}
218
+ avcodec_flush_buffers (_audio_ctx);
219
+ #endif
220
+
221
+ avcodec_close (_audio_ctx);
222
+ #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 52, 0)
223
+ avcodec_free_context (&_audio_ctx);
224
+ #else
225
+ delete _audio_ctx;
226
+ #endif
227
+ }
228
+ _audio_ctx = nullptr ;
229
+
213
230
if (_frame) {
214
231
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 45, 101)
215
232
av_frame_free (&_frame);
@@ -237,16 +254,6 @@ cleanup() {
237
254
_buffer = nullptr ;
238
255
}
239
256
240
- if ((_audio_ctx)&&(_audio_ctx->codec )) {
241
- avcodec_close (_audio_ctx);
242
- #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 52, 0)
243
- avcodec_free_context (&_audio_ctx);
244
- #else
245
- delete _audio_ctx;
246
- #endif
247
- }
248
- _audio_ctx = nullptr ;
249
-
250
257
if (_format_ctx) {
251
258
_ffvfile.close ();
252
259
_format_ctx = nullptr ;
Original file line number Diff line number Diff line change @@ -595,7 +595,14 @@ close_stream() {
595
595
// Hold the global lock while we free avcodec objects.
596
596
ReMutexHolder av_holder (_av_lock);
597
597
598
- if ((_video_ctx)&&(_video_ctx->codec )) {
598
+ if (_video_ctx && _video_ctx->codec ) {
599
+ #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 100)
600
+ // We need to drain the codec to prevent a memory leak.
601
+ avcodec_send_packet (_video_ctx, nullptr );
602
+ while (avcodec_receive_frame (_video_ctx, _frame) == 0 ) {}
603
+ avcodec_flush_buffers (_video_ctx);
604
+ #endif
605
+
599
606
avcodec_close (_video_ctx);
600
607
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 52, 0)
601
608
avcodec_free_context (&_video_ctx);
You can’t perform that action at this time.
0 commit comments