Skip to content

Commit

Permalink
fix: fix profile deserialization in native compiled image
Browse files Browse the repository at this point in the history
Signed-off-by: Gustav Grusell <[email protected]>
  • Loading branch information
grusell committed Nov 20, 2023
1 parent 95d5fcd commit fe017d1
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package se.svt.oss.encore

import org.springframework.aot.hint.annotation.RegisterReflectionForBinding
import org.springframework.context.annotation.Configuration
import se.svt.oss.encore.model.profile.AudioEncode
import se.svt.oss.encore.model.profile.AudioEncoder
import se.svt.oss.encore.model.profile.GenericVideoEncode
import se.svt.oss.encore.model.profile.OutputProducer
import se.svt.oss.encore.model.profile.Profile
import se.svt.oss.encore.model.profile.SimpleAudioEncode
import se.svt.oss.encore.model.profile.ThumbnailEncode
import se.svt.oss.encore.model.profile.ThumbnailMapEncode
import se.svt.oss.encore.model.profile.VideoEncode
import se.svt.oss.encore.model.profile.X264Encode
import se.svt.oss.encore.model.profile.X265Encode
import se.svt.oss.encore.model.profile.X26XEncode

@RegisterReflectionForBinding(
AudioEncode::class,
AudioEncoder::class,
GenericVideoEncode::class,
OutputProducer::class,
Profile::class,
SimpleAudioEncode::class,
ThumbnailEncode::class,
ThumbnailMapEncode::class,
VideoEncode::class,
X26XEncode::class,
X264Encode::class,
X265Encode::class
)
@Configuration
class ReflectionConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class GenericVideoEncode(
override val format: String,
override val codec: String,
override val inputLabel: String = DEFAULT_VIDEO_LABEL
) : VideoEncode {
) : VideoEncode() {
override val type: String
get() = this.javaClass.simpleName
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import se.svt.oss.encore.model.output.Output
import se.svt.oss.encore.model.output.VideoStreamEncode
import se.svt.oss.mediaanalyzer.file.toFractionOrNull

interface VideoEncode : OutputProducer {
val width: Int?
val height: Int?
val twoPass: Boolean
val params: Map<String, String>
val filters: List<String>?
val audioEncode: AudioEncoder?
val audioEncodes: List<AudioEncoder>
val suffix: String
val format: String
val codec: String
val inputLabel: String
abstract class VideoEncode : OutputProducer {
abstract val width: Int?
abstract val height: Int?
abstract val twoPass: Boolean
abstract val params: Map<String, String>
abstract val filters: List<String>?
abstract val audioEncode: AudioEncoder?
abstract val audioEncodes: List<AudioEncoder>
abstract val suffix: String
abstract val format: String
abstract val codec: String
abstract val inputLabel: String

override fun getOutput(job: EncoreJob, encodingProperties: EncodingProperties): Output? {
val audioEncodesToUse = audioEncodes.ifEmpty { listOfNotNull(audioEncode) }
Expand Down Expand Up @@ -62,7 +62,7 @@ interface VideoEncode : OutputProducer {
}
}

fun passParams(pass: Int): Map<String, String> =
open fun passParams(pass: Int): Map<String, String> =
mapOf("pass" to pass.toString(), "passlogfile" to "log$suffix")

private fun videoFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package se.svt.oss.encore.model.profile

abstract class X26XEncode : VideoEncode {
abstract class X26XEncode : VideoEncode() {

abstract val ffmpegParams: LinkedHashMap<String, String>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package se.svt.oss.encore.model.profile

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.junit.jupiter.api.Test
import se.svt.oss.encore.model.profile.ProfileAssert.assertThat

class ProfileJsonTest {

private val yamlMapper = YAMLMapper().findAndRegisterModules().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
private val objectMapper = ObjectMapper().findAndRegisterModules().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)

@Test
fun testSerializeProgramToJson() {
serializeDeserializeJson(readProfile("/profile/program.yml"))
}

@Test
fun testSerializeProgramX265ToJson() {
serializeDeserializeJson(readProfile("/profile/program-x265.yml"))
}

@Test
fun testSerializeProgramToYaml() {
serializeDeserializeYaml(readProfile("/profile/program.yml"))
}

@Test
fun testSerializeProgramX265ToYaml() {
serializeDeserializeYaml(readProfile("/profile/program-x265.yml"))
}

private fun serializeDeserializeJson(profile: Profile) {
val pretty = ObjectMapper().findAndRegisterModules().writerWithDefaultPrettyPrinter()
println(pretty.writeValueAsString(profile))
val serialized = objectMapper.writeValueAsString(profile)
val deserialized: Profile = objectMapper.readValue(serialized, Profile::class.java)
assertThat(deserialized)
.isEqualTo(profile)
}

private fun serializeDeserializeYaml(profile: Profile) {
val pretty = YAMLMapper().findAndRegisterModules().writerWithDefaultPrettyPrinter()
println(pretty.writeValueAsString(profile))
val serialized = yamlMapper.writeValueAsString(profile)
val deserialized: Profile = yamlMapper.readValue(serialized, Profile::class.java)
assertThat(deserialized)
.isEqualTo(profile)
}

private fun readProfile(path: String): Profile =
ProfileJsonTest::class.java.getResourceAsStream(path).use {
yamlMapper.readValue(it)
}
}

0 comments on commit fe017d1

Please sign in to comment.