Skip to content

Commit

Permalink
samples/videoplayer: migrate from libavresample to libswresample (Jet…
Browse files Browse the repository at this point in the history
  • Loading branch information
msink authored and olonho committed May 3, 2018
1 parent cafc30c commit f5090b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion samples/videoplayer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions samples/videoplayer/src/main/c_interop/ffmpeg.def
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -21,7 +21,7 @@ static void avformat_free_context2(AVFormatContext* ref) {
avformat_free_context(&copy);
}

static void avresample_free2(AVAudioResampleContext* ref) {
AVAudioResampleContext* copy = ref;
avresample_free(&copy);
static void swr_free2(SwrContext* ref) {
SwrContext* copy = ref;
swr_free(&copy);
}
8 changes: 4 additions & 4 deletions samples/videoplayer/src/main/kotlin/DecoderWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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) =
Expand Down Expand Up @@ -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)!!
Expand Down

0 comments on commit f5090b1

Please sign in to comment.