diff --git a/libavformat/mov.c b/libavformat/mov.c index 5678948491..1ea5c07a49 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7410,7 +7410,7 @@ static int cenc_filter(MOVContext *mov, AVStream* st, MOVStreamContext *sc, AVPa size_t size; #ifdef OHOS_DRM AV_DrmCencInfo *side_data = NULL; - side_data = av_encryption_info_add_side_data_ex(encrypted_sample, &size, side_data); + side_data = av_encryption_info_add_side_data_ex(encrypted_sample, &size, side_data, pkt->size); #else uint8_t *side_data = av_encryption_info_add_side_data(encrypted_sample, &size); #endif diff --git a/libavutil/encryption_info.c b/libavutil/encryption_info.c index b081a1a606..b9553b7aec 100644 --- a/libavutil/encryption_info.c +++ b/libavutil/encryption_info.c @@ -187,7 +187,7 @@ static void av_encryption_info_set_drm_algo(uint32_t algo, AV_DrmCencInfo *cenc_ } AV_DrmCencInfo *av_encryption_info_add_side_data_ex(const AVEncryptionInfo *info, size_t *side_data_size, - AV_DrmCencInfo *cenc_info) + AV_DrmCencInfo *cenc_info, int pkt_data_size) { uint32_t i; if ((info == NULL) || (info->key_id_size != AV_DRM_KEY_ID_SIZE) || (info->iv_size > AV_DRM_IV_SIZE) || @@ -216,6 +216,17 @@ AV_DrmCencInfo *av_encryption_info_add_side_data_ex(const AVEncryptionInfo *info cenc_info->sub_samples[i].clear_header_len = info->subsamples[i].bytes_of_clear_data; cenc_info->sub_samples[i].pay_load_len = info->subsamples[i].bytes_of_protected_data; } + if ((info->subsample_count == 0) && (info->crypt_byte_block == 0) && (info->skip_byte_block == 0) && + ((info->scheme == MKBETAG('c','e','n','s')) || (info->scheme == MKBETAG('s','m','4','r')))) { + cenc_info->sub_sample_num = 1; // 1: sub_sample num + cenc_info->sub_samples[0].clear_header_len = 0; + cenc_info->sub_samples[0].pay_load_len = (pkt_data_size / 16) * 16; // 16: block size + if ((pkt_data_size % 16) != 0) { // 16: block size + cenc_info->sub_sample_num = 2; // 2: sub_sample num + cenc_info->sub_samples[1].clear_header_len = pkt_data_size % 16; // 16: block size + cenc_info->sub_samples[1].pay_load_len = 0; + } + } return cenc_info; } #endif diff --git a/libavutil/encryption_info.h b/libavutil/encryption_info.h index 61470c529c..87e9f0a0a1 100644 --- a/libavutil/encryption_info.h +++ b/libavutil/encryption_info.h @@ -222,7 +222,7 @@ uint8_t *av_encryption_info_add_side_data( #ifdef OHOS_DRM AV_DrmCencInfo *av_encryption_info_add_side_data_ex( - const AVEncryptionInfo *info, size_t *side_data_size, AV_DrmCencInfo *cenc_info); + const AVEncryptionInfo *info, size_t *side_data_size, AV_DrmCencInfo *cenc_info, int pkt_data_size); #endif /**