From 0fcab4d396aded22f7220a8656a221338d89a1f3 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Mon, 25 Dec 2017 16:38:30 +0300 Subject: [PATCH] Small videoplayer sample fix. --- .../src/main/kotlin/DecoderWorker.kt | 2 -- .../videoplayer/src/main/kotlin/Dimensions.kt | 15 ++++++++++ .../videoplayer/src/main/kotlin/Disposable.kt | 28 +++++++++++++++---- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/samples/videoplayer/src/main/kotlin/DecoderWorker.kt b/samples/videoplayer/src/main/kotlin/DecoderWorker.kt index ed54285a1f0..249001d2d1e 100644 --- a/samples/videoplayer/src/main/kotlin/DecoderWorker.kt +++ b/samples/videoplayer/src/main/kotlin/DecoderWorker.kt @@ -207,8 +207,6 @@ private class AudioDecoder( } with (audioCodecContext) { - var inputChannelLayout = if (channel_layout != 0L) - channel_layout else av_get_default_channel_layout(audioCodecContext.channels) setResampleOpt("in_channel_layout", channel_layout.narrow()) setResampleOpt("out_channel_layout", output.channelLayout) setResampleOpt("in_sample_rate", sample_rate) diff --git a/samples/videoplayer/src/main/kotlin/Dimensions.kt b/samples/videoplayer/src/main/kotlin/Dimensions.kt index fa6dc0be7fd..2c8dbdefc78 100644 --- a/samples/videoplayer/src/main/kotlin/Dimensions.kt +++ b/samples/videoplayer/src/main/kotlin/Dimensions.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ data class Dimensions(val w: Int, val h: Int) { operator fun minus(other: Dimensions) = Dimensions(w - other.w, h - other.h) diff --git a/samples/videoplayer/src/main/kotlin/Disposable.kt b/samples/videoplayer/src/main/kotlin/Disposable.kt index 257ce6f72d7..07c9e495bbb 100644 --- a/samples/videoplayer/src/main/kotlin/Disposable.kt +++ b/samples/videoplayer/src/main/kotlin/Disposable.kt @@ -1,3 +1,18 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import kotlinx.cinterop.* @@ -38,11 +53,10 @@ abstract class DisposableContainer : Disposable { throw e } - // TODO: It shall be inline, but crashes backend - fun disposable( + inline fun disposable( message: String = "disposable", create: () -> T?, - dispose: (T) -> Unit + crossinline dispose: (T) -> Unit ): T = tryConstruct { create()?.also { @@ -50,13 +64,15 @@ abstract class DisposableContainer : Disposable { } ?: throw Error(message) } - // TODO: It shall be inline, but crashes backend - fun disposable(create: () -> T): T = + inline fun disposable(create: () -> T): T = disposable( create = create, dispose = { it.dispose() }) - fun sdlDisposable(message: String, ptr: CPointer?, dispose: (CPointer) -> Unit): CPointer = + inline fun sdlDisposable( + message: String, + ptr: CPointer?, + crossinline dispose: (CPointer) -> Unit): CPointer = disposable( create = { ptr ?: throwSDLError(message) }, dispose = dispose)