samples/videoplayer: migrate from libavresample to libswresample (#1551)
This commit is contained in:
committed by
Nikolay Igotti
parent
cafc30cf76
commit
f5090b1317
@@ -7,7 +7,7 @@ ffmpeg and SDL2 is needed for that to work, i.e.
|
||||
port install ffmpeg-devel
|
||||
brew install ffmpeg sdl2
|
||||
apt install libavcodec-dev libavformat-dev libavutil-dev libswscale-dev \
|
||||
libavresample-dev
|
||||
libswresample-dev
|
||||
apt install libsdl2-dev
|
||||
pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-ffmpeg
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package = ffmpeg
|
||||
headers = libavcodec/avcodec.h libavformat/avformat.h libavutil/pixfmt.h libavutil/opt.h \
|
||||
libswscale/swscale.h libavresample/avresample.h
|
||||
libswscale/swscale.h libswresample/swresample.h
|
||||
headerFilter = libavcodec/** libavformat/** libavutil/** \
|
||||
libswscale/** libavresample/**
|
||||
linkerOpts = -lavutil -lavformat -lavcodec -lswscale -lavresample
|
||||
libswscale/** libswresample/**
|
||||
linkerOpts = -lavutil -lavformat -lavcodec -lswscale -lswresample
|
||||
---
|
||||
|
||||
static void av_buffer_unref2(AVBufferRef* ref) {
|
||||
@@ -21,7 +21,7 @@ static void avformat_free_context2(AVFormatContext* ref) {
|
||||
avformat_free_context(©);
|
||||
}
|
||||
|
||||
static void avresample_free2(AVAudioResampleContext* ref) {
|
||||
AVAudioResampleContext* copy = ref;
|
||||
avresample_free(©);
|
||||
static void swr_free2(SwrContext* ref) {
|
||||
SwrContext* copy = ref;
|
||||
swr_free(©);
|
||||
}
|
||||
|
||||
@@ -190,8 +190,8 @@ private class AudioDecoder(
|
||||
disposable(create = ::av_frame_alloc, dispose = ::av_frame_unref).pointed
|
||||
private val resampledAudioFrame: AVFrame =
|
||||
disposable(create = ::av_frame_alloc, dispose = ::av_frame_unref).pointed
|
||||
private val resampleContext: CPointer<AVAudioResampleContext> =
|
||||
disposable(create = ::avresample_alloc_context, dispose = ::avresample_free2)
|
||||
private val resampleContext: CPointer<SwrContext> =
|
||||
disposable(create = ::swr_alloc, dispose = ::swr_free2)
|
||||
|
||||
private val audioQueue = Queue<AudioFrame>(100)
|
||||
|
||||
@@ -214,7 +214,7 @@ private class AudioDecoder(
|
||||
setResampleOpt("in_sample_fmt", sample_fmt)
|
||||
setResampleOpt("out_sample_fmt", output.sampleFormat)
|
||||
}
|
||||
avresample_open(resampleContext)
|
||||
swr_init(resampleContext)
|
||||
}
|
||||
|
||||
private fun setResampleOpt(name: String, value: Int) =
|
||||
@@ -248,7 +248,7 @@ private class AudioDecoder(
|
||||
val size = avcodec_decode_audio4(audioCodecContext.ptr, audioFrame.ptr, frameFinished.ptr, packet.ptr)
|
||||
if (frameFinished.value != 0) {
|
||||
// Put audio frame to decoder's queue.
|
||||
avresample_convert_frame(resampleContext, resampledAudioFrame.ptr, audioFrame.ptr).checkAVError()
|
||||
swr_convert_frame(resampleContext, resampledAudioFrame.ptr, audioFrame.ptr).checkAVError()
|
||||
with (resampledAudioFrame) {
|
||||
val audioFrameSize = av_samples_get_buffer_size(null, channels, nb_samples, format, 1)
|
||||
val buffer = av_buffer_alloc(audioFrameSize)!!
|
||||
|
||||
Reference in New Issue
Block a user