Lines Matching refs:cstr

123 static GF_Err isma_enc_configure(GF_CENCEncCtx *ctx, GF_CENCStream *cstr, Bool is_isma, const char …  in isma_enc_configure()  argument
128 p = gf_filter_pid_get_property(cstr->ipid, GF_PROP_PID_DECODER_CONFIG); in isma_enc_configure()
129 if (!p) p = gf_filter_pid_get_property(cstr->ipid, GF_PROP_PID_DECODER_CONFIG_ENHANCEMENT); in isma_enc_configure()
131 switch (cstr->codec_id) { in isma_enc_configure()
137 cstr->nalu_size_length = avcc ? avcc->nal_unit_size : 0; in isma_enc_configure()
140 if (!cstr->nalu_size_length) { in isma_enc_configure()
141 cstr->nalu_size_length = 4; in isma_enc_configure()
148 …GF_HEVCConfig *hvcc = gf_odf_hevc_cfg_read(p->value.data.ptr, p->value.data.size, (cstr->codec_id=… in isma_enc_configure()
149 cstr->nalu_size_length = hvcc ? hvcc->nal_unit_size : 0; in isma_enc_configure()
152 if (!cstr->nalu_size_length) { in isma_enc_configure()
153 cstr->nalu_size_length = 4; in isma_enc_configure()
161 …if (cstr->tci && ((cstr->tci->sel_enc_type==GF_CRYPT_SELENC_RAND) || (cstr->tci->sel_enc_type==GF_… in isma_enc_configure()
165 cstr->isma_IV_size = 0; in isma_enc_configure()
168 cstr->isma_IV_size = 16; in isma_enc_configure()
170 p = gf_filter_pid_get_property(cstr->ipid, GF_PROP_PID_CENC_IV_SIZE); in isma_enc_configure()
172 cstr->isma_IV_size = p->value.uint; in isma_enc_configure()
174 p = gf_filter_pid_get_property(cstr->ipid, GF_PROP_PID_MEDIA_DATA_SIZE); in isma_enc_configure()
178 if (BSO<0xFFFF) cstr->isma_IV_size = 2; in isma_enc_configure()
179 else if (BSO<0xFFFFFFFF) cstr->isma_IV_size = 4; in isma_enc_configure()
180 else cstr->isma_IV_size = 8; in isma_enc_configure()
183 if (!cstr->isma_IV_size || (cstr->isma_IV_size > 8)) cstr->isma_IV_size = 8; in isma_enc_configure()
186 if (!cstr->tci || !cstr->tci->KID_count) { in isma_enc_configure()
193 memcpy(IV, cstr->tci->first_IV, sizeof(char)*8); in isma_enc_configure()
194 if (cstr->crypt) gf_crypt_close(cstr->crypt); in isma_enc_configure()
195 cstr->crypt = gf_crypt_open(GF_AES_128, GF_CTR); in isma_enc_configure()
196 if (!cstr->crypt) { in isma_enc_configure()
201 e = gf_crypt_init(cstr->crypt, cstr->tci->keys[0], IV); in isma_enc_configure()
207 …crypting stream %s - KMS: %s%s\n", gf_filter_pid_get_name(cstr->ipid), cstr->tci->KMS_URI, cstr->t… in isma_enc_configure()
212 memcpy(Data, cstr->tci->keys[0], sizeof(char)*16); in isma_enc_configure()
213 memcpy(Data+16, cstr->tci->first_IV, sizeof(char)*8); in isma_enc_configure()
216 cstr->tci->KMS_URI = gf_realloc(cstr->tci->KMS_URI, size_b64+6); in isma_enc_configure()
217 strcpy(cstr->tci->KMS_URI, "(key)"); in isma_enc_configure()
218 strcat(cstr->tci->KMS_URI, d64); in isma_enc_configure()
219 kms_uri = cstr->tci->KMS_URI; in isma_enc_configure()
223 gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_PROTECTION_SCHEME_VERSION, &PROP_UINT(1) ); in isma_enc_configure()
224 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_PROTECTION_KMS_URI, kms_uri ? &PROP_STRING(kms_… in isma_enc_configure()
225 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_ISMA_SELECTIVE_ENC, &PROP_BOOL( (cstr->tci->sel… in isma_enc_configure()
226 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_ISMA_IV_LENGTH, &PROP_UINT(cstr->isma_IV_size) … in isma_enc_configure()
229 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_PROTECTION_SCHEME_URI, scheme_uri ? &PROP_STRIN… in isma_enc_configure()
231 if ((cstr->tci->sel_enc_type==GF_CRYPT_SELENC_PREVIEW) && cstr->tci->sel_enc_range) { in isma_enc_configure()
236 sprintf(szSTR, "PreviewRange:%d", cstr->tci->sel_enc_range); in isma_enc_configure()
237 …len = (u32) strlen(szSTR) + ( cstr->tci->TextualHeaders ? (u32) strlen(cstr->tci->TextualHeaders) … in isma_enc_configure()
239 strcpy(szPreview, cstr->tci->TextualHeaders ? cstr->tci->TextualHeaders : ""); in isma_enc_configure()
242 gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_OMA_TXT_HDR, &PROP_STRING_NO_COPY(szPreview)); in isma_enc_configure()
244 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_OMA_TXT_HDR, cstr->tci->TextualHeaders ? &PROP_… in isma_enc_configure()
247 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_OMA_CID, scheme_uri ? &PROP_STRING(scheme_uri) … in isma_enc_configure()
249 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_OMA_CRYPT_TYPE, &PROP_UINT(cstr->tci->encryptio… in isma_enc_configure()
250 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_OMA_CLEAR_LEN, &PROP_LONGUINT(cstr->tci->sel_en… in isma_enc_configure()
251 gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_ISMA_KI_LENGTH, &PROP_UINT(0) ); in isma_enc_configure()
254 cstr->range_end = 0; in isma_enc_configure()
255 if (cstr->tci->sel_enc_type==GF_CRYPT_SELENC_PREVIEW) { in isma_enc_configure()
256 p = gf_filter_pid_get_property(cstr->ipid, GF_PROP_PID_TIMESCALE); in isma_enc_configure()
258 cstr->range_end = p->value.uint *cstr->tci->sel_enc_range; in isma_enc_configure()
261 cstr->isma_oma = GF_TRUE; in isma_enc_configure()
262 cstr->prev_pck_encryped = GF_TRUE; in isma_enc_configure()
263 cstr->has_crypted_pck = GF_FALSE; in isma_enc_configure()
342 static GF_Err adobe_enc_configure(GF_CENCEncCtx *ctx, GF_CENCStream *cstr) in adobe_enc_configure() argument
344 if (cstr->crypt) gf_crypt_close(cstr->crypt); in adobe_enc_configure()
345 cstr->crypt = gf_crypt_open(GF_AES_128, GF_CBC); in adobe_enc_configure()
346 if (!cstr->crypt) { in adobe_enc_configure()
352 memcpy(cstr->key, cstr->tci->keys[0], 16); in adobe_enc_configure()
354 if (cstr->tci->metadata) in adobe_enc_configure()
355 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_ADOBE_CRYPT_META, &PROP_DATA(cstr->tci->metadat… in adobe_enc_configure()
357 cstr->is_adobe = GF_TRUE; in adobe_enc_configure()
362 static GF_Err cenc_parse_pssh(GF_CENCEncCtx *ctx, GF_CENCStream *cstr, const char *cfile_name) in cenc_parse_pssh() argument
509 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_CENC_PSSH, &PROP_DATA_NO_COPY(pssh, pssh_size)); in cenc_parse_pssh()
517 static GF_Err cenc_enc_configure(GF_CENCEncCtx *ctx, GF_CENCStream *cstr, const char *cfile_name) in cenc_enc_configure() argument
528 p = gf_filter_pid_get_property(cstr->ipid, GF_PROP_PID_DECODER_CONFIG); in cenc_enc_configure()
529 if (!p) p = gf_filter_pid_get_property(cstr->ipid, GF_PROP_PID_DECODER_CONFIG_ENHANCEMENT); in cenc_enc_configure()
534 if (dsi_crc != cstr->dsi_crc) in cenc_enc_configure()
536 else if (!dsi_crc && !cstr->crypt) in cenc_enc_configure()
539 cstr->dsi_crc = dsi_crc; in cenc_enc_configure()
543 cstr->nalu_size_length = 0; in cenc_enc_configure()
544 switch (cstr->codec_id) { in cenc_enc_configure()
552 if (avccfg) cstr->nalu_size_length = avccfg->nal_unit_size; in cenc_enc_configure()
554 cstr->cenc_codec = CENC_AVC; in cenc_enc_configure()
556 p2 = gf_filter_pid_get_property(cstr->ipid, GF_PROP_PID_ISOM_SUBTYPE); in cenc_enc_configure()
558 if (!cstr->tci->allow_encrypted_slice_header) { in cenc_enc_configure()
559 cstr->slice_header_clear = GF_TRUE; in cenc_enc_configure()
560 } else if (cstr->tci->scheme_type==GF_CRYPT_TYPE_CBCS) { in cenc_enc_configure()
561 cstr->slice_header_clear = GF_TRUE; in cenc_enc_configure()
564 cstr->slice_header_clear = GF_TRUE; in cenc_enc_configure()
570 gf_media_avc_read_sps(slc->data, slc->size, &cstr->avc, 0, NULL); in cenc_enc_configure()
574 gf_media_avc_read_pps(slc->data, slc->size, &cstr->avc); in cenc_enc_configure()
582 cstr->bytes_in_nal_hdr = 1; in cenc_enc_configure()
584 if (!cstr->slice_header_clear && cstr->tci->clear_bytes) in cenc_enc_configure()
585 cstr->bytes_in_nal_hdr = cstr->tci->clear_bytes; in cenc_enc_configure()
587 if (!cstr->nalu_size_length) { in cenc_enc_configure()
588 cstr->nalu_size_length = 4; in cenc_enc_configure()
597 …hevccfg = gf_odf_hevc_cfg_read(p->value.data.ptr, p->value.data.size, (cstr->codec_id==GF_CODECID_… in cenc_enc_configure()
598 if (hevccfg) cstr->nalu_size_length = hevccfg->nal_unit_size; in cenc_enc_configure()
601 gf_media_hevc_parse_ps(hevccfg, &cstr->hevc, GF_HEVC_NALU_VID_PARAM); in cenc_enc_configure()
602 gf_media_hevc_parse_ps(hevccfg, &cstr->hevc, GF_HEVC_NALU_SEQ_PARAM); in cenc_enc_configure()
603 gf_media_hevc_parse_ps(hevccfg, &cstr->hevc, GF_HEVC_NALU_PIC_PARAM); in cenc_enc_configure()
607 cstr->slice_header_clear = GF_TRUE; in cenc_enc_configure()
609 cstr->cenc_codec = CENC_HEVC; in cenc_enc_configure()
612 cstr->bytes_in_nal_hdr = 2; in cenc_enc_configure()
614 if (!cstr->nalu_size_length) { in cenc_enc_configure()
615 cstr->nalu_size_length = 4; in cenc_enc_configure()
624 cstr->av1.config = gf_odf_av1_cfg_read(p->value.data.ptr, p->value.data.size); in cenc_enc_configure()
625 cstr->cenc_codec = CENC_AV1; in cenc_enc_configure()
626 cstr->bytes_in_nal_hdr = 2; in cenc_enc_configure()
629 cstr->slice_header_clear = GF_TRUE; in cenc_enc_configure()
634 cstr->cenc_codec = CENC_VPX; in cenc_enc_configure()
635 cstr->bytes_in_nal_hdr = 2; in cenc_enc_configure()
641 … (((cstr->tci->scheme_type == GF_CRYPT_TYPE_CENS) || (cstr->tci->scheme_type == GF_CRYPT_TYPE_CBCS… in cenc_enc_configure()
643 if (!cstr->tci->crypt_byte_block || !cstr->tci->skip_byte_block) { in cenc_enc_configure()
644 if (cstr->tci->crypt_byte_block || cstr->tci->skip_byte_block) { in cenc_enc_configure()
647 cstr->tci->crypt_byte_block = 1; in cenc_enc_configure()
648 cstr->tci->skip_byte_block = 9; in cenc_enc_configure()
652 if ( (cstr->cenc_codec==CENC_VPX) && (cstr->tci->scheme_type != GF_CRYPT_TYPE_CENC) ) { in cenc_enc_configure()
653 …ion mode %s is not supported with VP8/VP9, only cenc is\n", gf_4cc_to_str(cstr->tci->scheme_type) … in cenc_enc_configure()
658 cstr->use_subsamples = GF_FALSE; in cenc_enc_configure()
659 if (cstr->cenc_codec != CENC_FULL_SAMPLE) cstr->use_subsamples = GF_TRUE; in cenc_enc_configure()
661 else if (cstr->tci->scheme_type == GF_CRYPT_TYPE_CBCS) { in cenc_enc_configure()
662 if (cstr->tci->skip_byte_block) { in cenc_enc_configure()
663 cstr->use_subsamples = GF_TRUE; in cenc_enc_configure()
666 cstr->bytes_in_nal_hdr = cstr->tci->clear_bytes; in cenc_enc_configure()
672 else if (!cstr->tci->crypt_byte_block) { in cenc_enc_configure()
673 cstr->tci->crypt_byte_block = 1; in cenc_enc_configure()
677 cstr->tci->crypt_byte_block = 0; in cenc_enc_configure()
681 else if ((cstr->tci->scheme_type == GF_CRYPT_TYPE_CENS) && cstr->tci->skip_byte_block) { in cenc_enc_configure()
683 cstr->tci->skip_byte_block = 0; in cenc_enc_configure()
684 if (!cstr->tci->crypt_byte_block) { in cenc_enc_configure()
685 cstr->tci->crypt_byte_block = 1; in cenc_enc_configure()
690 if (cstr->crypt) gf_crypt_close(cstr->crypt); in cenc_enc_configure()
691 if (cstr->ctr_mode) { in cenc_enc_configure()
692 cstr->crypt = gf_crypt_open(GF_AES_128, GF_CTR); in cenc_enc_configure()
695 cstr->crypt = gf_crypt_open(GF_AES_128, GF_CBC); in cenc_enc_configure()
698 if (!cstr->crypt) { in cenc_enc_configure()
699 …GF_LOG(GF_LOG_ERROR, GF_LOG_AUTHOR, ("[CENC] Cannot open AES-128 %s\n", cstr->ctr_mode ? "CTR" : "… in cenc_enc_configure()
704 if (!cstr->tci->keys) { in cenc_enc_configure()
708 if (cstr->tci->defaultKeyIdx && (cstr->tci->defaultKeyIdx < cstr->tci->KID_count)) { in cenc_enc_configure()
709 memcpy(cstr->key, cstr->tci->keys[cstr->tci->defaultKeyIdx], 16); in cenc_enc_configure()
710 memcpy(cstr->default_KID, cstr->tci->KIDs[cstr->tci->defaultKeyIdx], 16); in cenc_enc_configure()
711 cstr->kidx = cstr->tci->defaultKeyIdx; in cenc_enc_configure()
713 memcpy(cstr->key, cstr->tci->keys[0], 16); in cenc_enc_configure()
714 memcpy(cstr->default_KID, cstr->tci->KIDs[0], 16); in cenc_enc_configure()
715 cstr->kidx = 0; in cenc_enc_configure()
717 cstr->prev_pck_encryped = cstr->tci->IsEncrypted; in cenc_enc_configure()
722 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_PROTECTION_SCHEME_VERSION, &PROP_UINT(0x0001000… in cenc_enc_configure()
723 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_ENCRYPTED, &PROP_BOOL(cstr->tci->IsEncrypted ? … in cenc_enc_configure()
725 if (cstr->tci->IV_size) { in cenc_enc_configure()
726 gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_CENC_IV_SIZE, &PROP_UINT(cstr->tci->IV_size) ); in cenc_enc_configure()
728 gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_CENC_IV_SIZE, NULL); in cenc_enc_configure()
730 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_KID, &PROP_DATA(cstr->default_KID, sizeof(bin12… in cenc_enc_configure()
732 if (cstr->tci->skip_byte_block || cstr->tci->crypt_byte_block) { in cenc_enc_configure()
733 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_CENC_PATTERN, &PROP_FRAC_INT(cstr->tci->skip_by… in cenc_enc_configure()
735 gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_CENC_PATTERN, NULL); in cenc_enc_configure()
737 if (cstr->tci->constant_IV_size) { in cenc_enc_configure()
738 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_CENC_IV_CONST, &PROP_DATA(cstr->tci->constant_I… in cenc_enc_configure()
740 gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_CENC_IV_CONST, NULL ); in cenc_enc_configure()
743 if (!cstr->tci->constant_IV_size || cstr->use_subsamples) { in cenc_enc_configure()
744 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_CENC_STORE, &PROP_UINT(cstr->tci->sai_saved_box… in cenc_enc_configure()
748 return cenc_parse_pssh(ctx, cstr, cfile_name); in cenc_enc_configure()
760 GF_CENCStream *cstr; in cenc_enc_configure_pid() local
768 cstr = gf_filter_pid_get_udta(pid); in cenc_enc_configure_pid()
769 if (cstr) { in cenc_enc_configure_pid()
770 gf_list_del_item(ctx->streams, cstr); in cenc_enc_configure_pid()
771 gf_filter_pid_remove(cstr->opid); in cenc_enc_configure_pid()
772 if (cstr->crypt) gf_crypt_close(cstr->crypt); in cenc_enc_configure_pid()
773 if (cstr->cinfo) gf_crypt_info_del(cstr->cinfo); in cenc_enc_configure_pid()
774 gf_free(cstr); in cenc_enc_configure_pid()
834 cstr = gf_filter_pid_get_udta(pid); in cenc_enc_configure_pid()
835 if (!cstr) { in cenc_enc_configure_pid()
836 GF_SAFEALLOC(cstr, GF_CENCStream); in cenc_enc_configure_pid()
837 if (!cstr) return GF_OUT_OF_MEM; in cenc_enc_configure_pid()
838 cstr->ipid = pid; in cenc_enc_configure_pid()
839 cstr->opid = gf_filter_pid_new(filter); in cenc_enc_configure_pid()
840 cstr->tci = tci; in cenc_enc_configure_pid()
841 gf_list_add(ctx->streams, cstr); in cenc_enc_configure_pid()
842 gf_filter_pid_set_udta(pid, cstr); in cenc_enc_configure_pid()
844 if (cstr->cinfo) gf_crypt_info_del(cstr->cinfo); in cenc_enc_configure_pid()
845 cstr->cinfo = (cinfo != ctx->cinfo) ? cinfo : NULL; in cenc_enc_configure_pid()
846 cstr->tci = tci; in cenc_enc_configure_pid()
847 cstr->passthrough = tci ? GF_FALSE : GF_TRUE; in cenc_enc_configure_pid()
850 gf_filter_pid_copy_properties(cstr->opid, pid); in cenc_enc_configure_pid()
853 if (prop) cstr->codec_id = prop->value.uint; in cenc_enc_configure_pid()
855 if (cstr->tci) { in cenc_enc_configure_pid()
856 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_PROTECTION_SCHEME_TYPE, &PROP_UINT(scheme_type)… in cenc_enc_configure_pid()
867 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_ORIG_STREAM_TYPE, & PROP_UINT(prop->value.uint)… in cenc_enc_configure_pid()
871 cstr->passthrough = GF_TRUE; in cenc_enc_configure_pid()
875 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_CENC_STSD_MODE, &PROP_UINT(tci->force_clear_sts… in cenc_enc_configure_pid()
878 if (cstr->passthrough) return GF_OK; in cenc_enc_configure_pid()
880 gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_STREAM_TYPE, &PROP_UINT(GF_STREAM_ENCRYPTED) ); in cenc_enc_configure_pid()
882 scheme_uri = cstr->tci->Scheme_URI; in cenc_enc_configure_pid()
883 kms_uri = cstr->tci->KMS_URI; in cenc_enc_configure_pid()
890 cstr->ctr_mode = GF_FALSE; in cenc_enc_configure_pid()
894 cstr->ctr_mode = GF_TRUE; in cenc_enc_configure_pid()
895 return isma_enc_configure(ctx, cstr, GF_TRUE, scheme_uri, kms_uri); in cenc_enc_configure_pid()
897 return isma_enc_configure(ctx, cstr, GF_FALSE, scheme_uri, kms_uri); in cenc_enc_configure_pid()
899 return adobe_enc_configure(ctx, cstr); in cenc_enc_configure_pid()
903 cstr->ctr_mode = GF_TRUE; in cenc_enc_configure_pid()
906 return cenc_enc_configure(ctx, cstr, cfile_name); in cenc_enc_configure_pid()
915 static GF_Err isma_process(GF_CENCEncCtx *ctx, GF_CENCStream *cstr, GF_FilterPacket *pck) in isma_process() argument
928 switch (cstr->tci->sel_enc_type) { in isma_process()
942 if (! (cstr->nb_pck % cstr->tci->sel_enc_range) ) cstr->has_crypted_pck = 0; in isma_process()
943 if (! cstr->has_crypted_pck) { in isma_process()
945 if (!(rand % cstr->tci->sel_enc_range)) flags |= GF_ISOM_ISMA_IS_ENCRYPTED; in isma_process()
947 if (!(flags & GF_ISOM_ISMA_IS_ENCRYPTED) && !( (1+cstr->nb_pck) % cstr->tci->sel_enc_range)) { in isma_process()
950 cstr->has_crypted_pck = (flags & GF_ISOM_ISMA_IS_ENCRYPTED); in isma_process()
955 if (!(cstr->nb_pck % cstr->tci->sel_enc_type)) flags |= GF_ISOM_ISMA_IS_ENCRYPTED; in isma_process()
958 if (cts >= cstr->range_end) in isma_process()
968 if (cstr->tci->sel_enc_type) flags |= GF_ISOM_ISMA_USE_SEL_ENC; in isma_process()
971 if (flags & GF_ISOM_ISMA_IS_ENCRYPTED) isma_hdr_size += cstr->isma_IV_size + cstr->KI_length; in isma_process()
978 dst_pck = gf_filter_pck_new_alloc(cstr->opid, size+isma_hdr_size, &output); in isma_process()
984 if (cstr->nalu_size_length) { in isma_process()
999 if (!cstr->prev_pck_encryped) { in isma_process()
1004 count = cstr->BSO / 16; in isma_process()
1005 remain = (u32) (cstr->BSO % 16); in isma_process()
1010 gf_bs_write_data(bs, cstr->tci->first_IV, 8); in isma_process()
1013 gf_crypt_set_IV(cstr->crypt, IV, GF_AES_128_KEYSIZE+1); in isma_process()
1018 gf_crypt_decrypt(cstr->crypt, dummy, remain); in isma_process()
1021 gf_crypt_encrypt(cstr->crypt, output+isma_hdr_size, size); in isma_process()
1022 cstr->prev_pck_encryped = GF_TRUE; in isma_process()
1024 cstr->prev_pck_encryped = GF_FALSE; in isma_process()
1036 if (cstr->isma_IV_size) gf_bs_write_long_int(ctx->bs_w, (s64) cstr->BSO, 8*cstr->isma_IV_size); in isma_process()
1041 cstr->BSO += size; in isma_process()
1047 static GF_Err adobe_process(GF_CENCEncCtx *ctx, GF_CENCStream *cstr, GF_FilterPacket *pck) in adobe_process() argument
1059 switch (cstr->tci->sel_enc_type) { in adobe_process()
1084 dst_pck = gf_filter_pck_new_alloc(cstr->opid, len + adobe_hdr_size, &output); in adobe_process()
1090 if (!cstr->prev_pck_encryped) { in adobe_process()
1091 memcpy(IV, cstr->tci->first_IV, sizeof(char)*16); in adobe_process()
1092 e = gf_crypt_init(cstr->crypt, cstr->key, IV); in adobe_process()
1093 cstr->prev_pck_encryped = GF_TRUE; in adobe_process()
1095 cstr->isma_IV_size = 16; in adobe_process()
1096 e = gf_crypt_get_IV(cstr->crypt, IV, &cstr->isma_IV_size); in adobe_process()
1107 gf_crypt_encrypt(cstr->crypt, output+adobe_hdr_size, len); in adobe_process()
1181 static u32 cenc_get_clear_bytes(GF_CENCStream *cstr, GF_BitStream *plaintext_bs, char *samp_data, u… in cenc_get_clear_bytes() argument
1184 if (cstr->slice_header_clear) { in cenc_get_clear_bytes()
1186 if (cstr->cenc_codec==CENC_AVC) { in cenc_get_clear_bytes()
1188 gf_media_avc_parse_nalu(plaintext_bs, &cstr->avc); in cenc_get_clear_bytes()
1189 ntype = cstr->avc.last_nal_type_parsed; in cenc_get_clear_bytes()
1208 cstr->hevc.full_slice_header_parse = GF_TRUE; in cenc_get_clear_bytes()
1209 gf_media_hevc_parse_nalu (samp_data + nal_start, nal_size, &cstr->hevc, &ntype, &ntid, &nlid); in cenc_get_clear_bytes()
1211 clear_bytes = cstr->hevc.s_info.payload_start_offset; in cenc_get_clear_bytes()
1226 static GF_Err cenc_encrypt_packet(GF_CENCEncCtx *ctx, GF_CENCStream *cstr, GF_FilterPacket *pck) in cenc_encrypt_packet() argument
1235 u32 sai_size = cstr->tci->IV_size; in cenc_encrypt_packet()
1239 if (!cstr->ctr_mode && cstr->tci->IV_size) { in cenc_encrypt_packet()
1241 gf_crypt_get_IV(cstr->crypt, cstr->IV, &IV_size); in cenc_encrypt_packet()
1248 dst_pck = gf_filter_pck_new_clone(cstr->opid, pck, &output); in cenc_encrypt_packet()
1251 gf_filter_pid_drop_packet(cstr->ipid); in cenc_encrypt_packet()
1263 gf_bs_write_data(sai_bs, cstr->IV, cstr->tci->IV_size); in cenc_encrypt_packet()
1268 if (cstr->use_subsamples) { in cenc_encrypt_packet()
1292 switch (cstr->cenc_codec) { in cenc_encrypt_packet()
1295 nalu_size = gf_bs_read_int(ctx->bs_r, 8*cstr->nalu_size_length); in cenc_encrypt_packet()
1299 …clear_bytes = cenc_get_clear_bytes(cstr, ctx->bs_r, (char *) data, nalu_size, cstr->bytes_in_nal_h… in cenc_encrypt_packet()
1304 e = gf_media_aom_av1_parse_obu(ctx->bs_r, &obut, &obu_size, &hdr_size, &cstr->av1); in cenc_encrypt_packet()
1316 if (!cstr->av1.frame_state.nb_tiles_in_obu) { in cenc_encrypt_packet()
1319 nb_ranges = cstr->av1.frame_state.nb_tiles_in_obu; in cenc_encrypt_packet()
1321 ranges[0].clear = cstr->av1.frame_state.tiles[0].obu_start_offset; in cenc_encrypt_packet()
1322 ranges[0].encrypted = cstr->av1.frame_state.tiles[0].size; in cenc_encrypt_packet()
1324 …ranges[i].clear = cstr->av1.frame_state.tiles[i].obu_start_offset - (cstr->av1.frame_state.tiles[i… in cenc_encrypt_packet()
1325 ranges[i].encrypted = cstr->av1.frame_state.tiles[i].size; in cenc_encrypt_packet()
1353 if (cstr->tci->block_align != 2) { in cenc_encrypt_packet()
1355 cstr->tci->block_align = 2; in cenc_encrypt_packet()
1424 if (cstr->ctr_mode) { in cenc_encrypt_packet()
1430 if (cstr->cenc_codec==CENC_AV1) { in cenc_encrypt_packet()
1434 …else if ((cstr->tci->scheme_type == GF_CRYPT_TYPE_CENC) || (cstr->tci->scheme_type == GF_CRYPT_TYP… in cenc_encrypt_packet()
1436 if (cstr->tci->block_align != 1) { in cenc_encrypt_packet()
1438 if (cstr->tci->block_align==2) { in cenc_encrypt_packet()
1453 if ((cstr->cenc_codec != CENC_VPX) && (cstr->tci->scheme_type == GF_CRYPT_TYPE_CBCS)) { in cenc_encrypt_packet()
1478 if (!cstr->ctr_mode && !cstr->tci->IV_size) in cenc_encrypt_packet()
1479 gf_crypt_set_IV(cstr->crypt, cstr->IV, 16); in cenc_encrypt_packet()
1482 if (cstr->tci->crypt_byte_block && cstr->tci->skip_byte_block) { in cenc_encrypt_packet()
1488 …e = gf_crypt_encrypt(cstr->crypt, output+pos, res >= (u32) (16*cstr->tci->crypt_byte_block) ? 16*c… in cenc_encrypt_packet()
1489 if (res >= (u32) (16 * (cstr->tci->crypt_byte_block + cstr->tci->skip_byte_block))) { in cenc_encrypt_packet()
1490 pos += 16 * (cstr->tci->crypt_byte_block + cstr->tci->skip_byte_block); in cenc_encrypt_packet()
1491 res -= 16 * (cstr->tci->crypt_byte_block + cstr->tci->skip_byte_block); in cenc_encrypt_packet()
1499 e = gf_crypt_encrypt(cstr->crypt, output+cur_pos, nalu_size - clear_bytes); in cenc_encrypt_packet()
1506 prev_entry_bytes_clear += cstr->nalu_size_length + clear_bytes; in cenc_encrypt_packet()
1516 prev_entry_bytes_clear = cstr->nalu_size_length + clear_bytes; in cenc_encrypt_packet()
1541 switch (cstr->cenc_codec) { in cenc_encrypt_packet()
1560 } else if (cstr->ctr_mode) { in cenc_encrypt_packet()
1562 e = gf_crypt_encrypt(cstr->crypt, output, pck_size); in cenc_encrypt_packet()
1569 if (!cstr->tci->IV_size) in cenc_encrypt_packet()
1570 gf_crypt_set_IV(cstr->crypt, cstr->IV, 16); in cenc_encrypt_packet()
1573 gf_crypt_encrypt(cstr->crypt, output, pck_size - clear_trailing); in cenc_encrypt_packet()
1591 if (cstr->ctr_mode) in cenc_encrypt_packet()
1592 cenc_resync_IV(cstr->crypt, cstr->IV, cstr->tci->IV_size); in cenc_encrypt_packet()
1597 gf_bs_seek(sai_bs, cstr->tci->IV_size); in cenc_encrypt_packet()
1611 static GF_Err cenc_process(GF_CENCEncCtx *ctx, GF_CENCStream *cstr, GF_FilterPacket *pck) in cenc_process() argument
1630 switch (cstr->tci->sel_enc_type) { in cenc_process()
1647 if (cstr->tci->sel_enc_range && (cstr->nb_pck+1 >= cstr->tci->sel_enc_range)) { in cenc_process()
1648 cstr->tci->sel_enc_type = GF_CRYPT_SELENC_NONE; in cenc_process()
1660 dst_pck = gf_filter_pck_new_ref(cstr->opid, NULL, 0, pck); in cenc_process()
1663 if (force_clear && !cstr->tci->force_clear_stsd_idx) in cenc_process()
1666 if (cstr->use_subsamples && signal_sai) { in cenc_process()
1678 memcpy(NULL_IV, (char *) &cstr->nb_pck, 4); in cenc_process()
1679 gf_bs_write_data(bs, NULL_IV, cstr->tci->IV_size); in cenc_process()
1704 if (!cstr->cenc_init) { in cenc_process()
1705 memset(cstr->IV, 0, sizeof(char)*16); in cenc_process()
1706 if (cstr->tci->IV_size == 8) { in cenc_process()
1707 memcpy(cstr->IV, cstr->tci->first_IV, sizeof(char)*8); in cenc_process()
1708 memset(cstr->IV+8, 0, sizeof(char)*8); in cenc_process()
1710 else if (cstr->tci->IV_size == 16) { in cenc_process()
1711 memcpy(cstr->IV, cstr->tci->first_IV, sizeof(char)*16); in cenc_process()
1713 else if (!cstr->tci->IV_size) { in cenc_process()
1714 if (cstr->tci->constant_IV_size == 8) { in cenc_process()
1715 memcpy(cstr->IV, cstr->tci->constant_IV, sizeof(char)*8); in cenc_process()
1716 memset(cstr->IV+8, 0, sizeof(char)*8); in cenc_process()
1718 else if (cstr->tci->constant_IV_size == 16) { in cenc_process()
1719 memcpy(cstr->IV, cstr->tci->constant_IV, sizeof(char)*16); in cenc_process()
1727 e = gf_crypt_init(cstr->crypt, cstr->key, cstr->IV); in cenc_process()
1729 …GF_LOG(GF_LOG_ERROR, GF_LOG_AUTHOR, ("[CENC] Cannot initialize AES-128 %s (%s)\n", cstr->ctr_mode … in cenc_process()
1732 cstr->cenc_init = GF_TRUE; in cenc_process()
1734 if (cstr->tci->keyRoll) { in cenc_process()
1735 u32 new_idx = (cstr->nb_pck_encrypted / cstr->tci->keyRoll) % cstr->tci->KID_count; in cenc_process()
1736 if (cstr->kidx != new_idx) { in cenc_process()
1737 cstr->kidx = new_idx; in cenc_process()
1738 memcpy(cstr->key, cstr->tci->keys[cstr->kidx], 16); in cenc_process()
1740 e = gf_crypt_set_key(cstr->crypt, cstr->key); in cenc_process()
1742 …GF_LOG(GF_LOG_ERROR, GF_LOG_AUTHOR, ("[CENC] Cannot set key AES-128 %s (%s)\n", cstr->ctr_mode ? "… in cenc_process()
1750 …gf_filter_pid_set_property(cstr->opid, GF_PROP_PID_KID, &PROP_DATA( cstr->tci->KIDs[cstr->kidx], s… in cenc_process()
1755 e = cenc_encrypt_packet(ctx, cstr, pck); in cenc_process()
1757 …, ("[CENC] Error encrypting packet %d in PID %s: %s\n", cstr->nb_pck, gf_filter_pid_get_name(cstr-… in cenc_process()
1761 cstr->nb_pck_encrypted++; in cenc_process()
1773 GF_CENCStream *cstr = gf_list_get(ctx->streams, i); in cenc_enc_process() local
1774 GF_FilterPacket *pck = gf_filter_pid_get_packet(cstr->ipid); in cenc_enc_process()
1776 if (gf_filter_pid_is_eos(cstr->ipid)) { in cenc_enc_process()
1777 gf_filter_pid_set_eos(cstr->opid); in cenc_enc_process()
1783 if (cstr->passthrough) { in cenc_enc_process()
1784 gf_filter_pck_forward(pck, cstr->opid); in cenc_enc_process()
1786 else if (cstr->isma_oma) { in cenc_enc_process()
1787 e = isma_process(ctx, cstr, pck); in cenc_enc_process()
1788 } else if (cstr->is_adobe) { in cenc_enc_process()
1789 e = adobe_process(ctx, cstr, pck); in cenc_enc_process()
1791 e = cenc_process(ctx, cstr, pck); in cenc_enc_process()
1793 gf_filter_pid_drop_packet(cstr->ipid); in cenc_enc_process()
1794 cstr->nb_pck++; in cenc_enc_process()