From 0138ab0221a3148a0e1395278c4574aa99db090a Mon Sep 17 00:00:00 2001 From: felixncheng Date: Tue, 19 Nov 2024 16:29:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20media=E6=9C=8D=E5=8A=A1=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8F=82=E6=95=B0=E5=92=8C?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E5=99=A8=20#2768?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/bkrepo/media/config/WebConfig.kt | 16 +++++++++++++++ .../bkrepo/media/service/StreamService.kt | 7 +++++-- .../bkrepo/media/service/TokenService.kt | 2 +- .../bkrepo/media/service/TranscodeService.kt | 3 ++- .../media/stream/MediaArtifactFileConsumer.kt | 2 -- .../bkrepo/media/stream/TranscodeConfig.kt | 3 ++- .../bkrepo/media/stream/TranscodeParam.kt | 3 ++- .../bkrepo/media/web/PluginDelegateFilter.kt | 20 +++++++++++++++++++ 8 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/config/WebConfig.kt create mode 100644 src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/web/PluginDelegateFilter.kt diff --git a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/config/WebConfig.kt b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/config/WebConfig.kt new file mode 100644 index 0000000000..d3d6717aa0 --- /dev/null +++ b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/config/WebConfig.kt @@ -0,0 +1,16 @@ +package com.tencent.bkrepo.media.config + +import com.tencent.bkrepo.media.web.PluginDelegateFilter +import org.springframework.boot.web.servlet.FilterRegistrationBean +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class WebConfig { + @Bean + fun pluginDelegateFilter(): FilterRegistrationBean { + val registrationBean = FilterRegistrationBean() + registrationBean.filter = PluginDelegateFilter() + return registrationBean + } +} diff --git a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/StreamService.kt b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/StreamService.kt index 1833726fe9..74425c05f7 100644 --- a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/StreamService.kt +++ b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/StreamService.kt @@ -59,7 +59,7 @@ class StreamService( type = RepositoryType.MEDIA, category = RepositoryCategory.LOCAL, public = false, - display = display + display = display, ) repositoryService.createRepo(createRepoRequest) val nodeCreateRequest = NodeCreateRequest( @@ -100,17 +100,20 @@ class StreamService( userId: String, remux: Boolean = false, saveType: MediaType = MediaType.RAW, + transcodeExtraParams: String? = null, ): ClientStream { val repoId = RepositoryId(projectId, repoName) val repo = ArtifactContextHolder.getRepoDetail(repoId) val credentials = repo.storageCredentials ?: storageProperties.defaultStorageCredentials() + val transcodeConfig = getTranscodeConfig(projectId) + transcodeConfig?.let { it.extraParams = transcodeExtraParams } val fileConsumer = MediaArtifactFileConsumer( storageManager, transcodeService, repo, userId, STREAM_PATH, - getTranscodeConfig(projectId), + transcodeConfig, ) val recordingListener = if (remux) { RemuxRecordingListener(credentials.upload.location, scheduler, saveType, fileConsumer) diff --git a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/TokenService.kt b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/TokenService.kt index a35226c8d6..304915854d 100644 --- a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/TokenService.kt +++ b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/TokenService.kt @@ -150,7 +150,7 @@ class TokenService( /** * 检查token并返回token信息 */ - private fun checkToken(token: String): TemporaryTokenInfo { + fun checkToken(token: String): TemporaryTokenInfo { if (token.isBlank()) { throw ErrorCodeException(ArtifactMessageCode.TEMPORARY_TOKEN_INVALID, token) } diff --git a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/TranscodeService.kt b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/TranscodeService.kt index 15734405a3..8e2719f016 100644 --- a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/TranscodeService.kt +++ b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/service/TranscodeService.kt @@ -76,7 +76,7 @@ class TranscodeService( projectId = projectId, repoName = repoName, fullPath = newArtifactInfo.getArtifactFullPath(), - metadata = originMetadata + metadata = originMetadata, ) metadataService.saveMetadata(copyRequest) val removeContext = ArtifactRemoveContext(repo, originArtifactInfo) @@ -106,6 +106,7 @@ class TranscodeService( audioCodec = audioCodec, inputFileName = artifactInfo.getResponseName(), outputFileName = outputArtifactInfo.getResponseName(), + extraParams = transcodeConfig.extraParams.orEmpty(), ) } } diff --git a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/MediaArtifactFileConsumer.kt b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/MediaArtifactFileConsumer.kt index 6d7ed3f1e7..92e6d902eb 100644 --- a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/MediaArtifactFileConsumer.kt +++ b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/MediaArtifactFileConsumer.kt @@ -39,7 +39,6 @@ class MediaArtifactFileConsumer( storageManager.storeArtifactFile(nodeCreateRequest, file, repo.storageCredentials) if (transcodeConfig != null) { transcodeService.transcode(artifactInfo, transcodeConfig, userId) - logger.info("Add transcode task for artifact[$artifactInfo]") } } @@ -68,7 +67,6 @@ class MediaArtifactFileConsumer( } companion object { - private val logger = LoggerFactory.getLogger(MediaArtifactFileConsumer::class.java) private const val METADATA_KEY_MEDIA_START_TIME = "media.startTime" private const val METADATA_KEY_MEDIA_STOP_TIME = "media.stopTime" } diff --git a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/TranscodeConfig.kt b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/TranscodeConfig.kt index bc785920ce..774f962809 100644 --- a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/TranscodeConfig.kt +++ b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/TranscodeConfig.kt @@ -4,5 +4,6 @@ data class TranscodeConfig( var scale: String = "", // 分辨率,比如1280x720 var videoCodec: String = "", // 视频编码 var audioCodec: String = "", // 音频编码 - var jobId: String = "", // 转码任务id + var jobId: String = "", // 转码任务id, + var extraParams: String? = null, ) diff --git a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/TranscodeParam.kt b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/TranscodeParam.kt index fdf6c9ce85..ddd85e9554 100644 --- a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/TranscodeParam.kt +++ b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/stream/TranscodeParam.kt @@ -7,5 +7,6 @@ data class TranscodeParam( val videoCodec: String? = null, // 视频编码 val audioCodec: String? = null, // 音频编码 var inputFileName: String, // 源文件名 - var outputFileName: String, // 输出文件名 + var outputFileName: String, // 输出文件名, + var extraParams: String, // 额外参数 ) diff --git a/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/web/PluginDelegateFilter.kt b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/web/PluginDelegateFilter.kt new file mode 100644 index 0000000000..2b67713438 --- /dev/null +++ b/src/backend/media/biz-media/src/main/kotlin/com/tencent/bkrepo/media/web/PluginDelegateFilter.kt @@ -0,0 +1,20 @@ +package com.tencent.bkrepo.media.web + +import javax.servlet.Filter +import javax.servlet.FilterChain +import javax.servlet.ServletRequest +import javax.servlet.ServletResponse + +class PluginDelegateFilter : Filter { + override fun doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain) { + if (delegate != null) { + delegate!!.doFilter(request, response, chain) + } else { + chain.doFilter(request, response) + } + } + + companion object { + var delegate: Filter? = null + } +}