From 11cbbd86fb5ffb80fdb21c70ee174618407ac393 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Thu, 8 Feb 2018 23:40:46 -0800 Subject: [PATCH] Fix fMP4 'cbcs' playback issue in Safari Looks like Safari does not like v0 tenc box. - Use v1 tenc box for cbcs and cens protection_scheme as required by CENCv3 spec. - Set crypt_byte_block and skip_byte_block to 0 for full sample encryption cbcs and cens. Fixes #326 Change-Id: I5581cd856fffc4ff104d950f3ca19b9337d57a78 --- .../testdata/bear-640x360-a-cbcs-golden.mp4 | Bin 43947 -> 43947 bytes .../testdata/bear-640x360-a-cens-golden.mp4 | Bin 44620 -> 44620 bytes packager/media/formats/mp4/mp4_muxer.cc | 27 ++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/packager/app/test/testdata/bear-640x360-a-cbcs-golden.mp4 b/packager/app/test/testdata/bear-640x360-a-cbcs-golden.mp4 index 2c07174911386c2bfd59a139e737b3cfc1249f75..07afa6a80c44a23a938b731d388dbc083fa1c60b 100644 GIT binary patch delta 21 acmZ2|ooV%TrVR_3*ccf=VDoY&mX!cg*amC> delta 21 acmZ2|ooV%TrVR_3*cd=SVDoY&mX!chEe3l4 diff --git a/packager/app/test/testdata/bear-640x360-a-cens-golden.mp4 b/packager/app/test/testdata/bear-640x360-a-cens-golden.mp4 index 067799fab63dc54968f90808739992b6692bef0c..36c049aa3ab1933d5e2d8c19f49e28be263aa42a 100644 GIT binary patch delta 21 acmX?ehw026rVR_3*ccf=VDoaOrKinfo.track_encryption; track_encryption.default_is_protected = 1; + track_encryption.default_crypt_byte_block = encryption_config.crypt_byte_block; track_encryption.default_skip_byte_block = encryption_config.skip_byte_block; + switch (encryption_config.protection_scheme) { + case FOURCC_cenc: + case FOURCC_cbc1: + DCHECK_EQ(track_encryption.default_crypt_byte_block, 0u); + DCHECK_EQ(track_encryption.default_skip_byte_block, 0u); + // CENCv3 10.1 ‘cenc’ AES-CTR scheme and 10.2 ‘cbc1’ AES-CBC scheme: + // The version of the Track Encryption Box (‘tenc’) SHALL be 0. + track_encryption.version = 0; + break; + case FOURCC_cbcs: + case FOURCC_cens: + if (track_encryption.default_skip_byte_block == 0) { + // Some clients, e.g. Safari v11.0.3 does not like having + // crypt_byte_block as a non-zero value when skip_byte_block is zero. + track_encryption.default_crypt_byte_block = 0; + } + // CENCv3 10.3 ‘cens’ AES-CTR subsample pattern encryption scheme and + // 10.4 ‘cbcs’ AES-CBC subsample pattern encryption scheme: + // The version of the Track Encryption Box (‘tenc’) SHALL be 1. + track_encryption.version = 1; + break; + default: + NOTREACHED() << "Unexpected protection scheme " + << encryption_config.protection_scheme; + } + track_encryption.default_per_sample_iv_size = encryption_config.per_sample_iv_size; track_encryption.default_constant_iv = encryption_config.constant_iv;