Skip to content

Commit

Permalink
feat: media服务支持自定义参数和过滤器 #2768
Browse files Browse the repository at this point in the history
  • Loading branch information
felixncheng committed Nov 19, 2024
1 parent 8527c4f commit 0138ab0
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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<PluginDelegateFilter> {
val registrationBean = FilterRegistrationBean<PluginDelegateFilter>()
registrationBean.filter = PluginDelegateFilter()
return registrationBean
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class StreamService(
type = RepositoryType.MEDIA,
category = RepositoryCategory.LOCAL,
public = false,
display = display
display = display,
)
repositoryService.createRepo(createRepoRequest)
val nodeCreateRequest = NodeCreateRequest(
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -106,6 +106,7 @@ class TranscodeService(
audioCodec = audioCodec,
inputFileName = artifactInfo.getResponseName(),
outputFileName = outputArtifactInfo.getResponseName(),
extraParams = transcodeConfig.extraParams.orEmpty(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
}
}

Expand Down Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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, // 额外参数
)
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 0138ab0

Please sign in to comment.