DASH MP4 cenc 筆記


術語:

  • Initialization Segment 通常指 moov box,不包含 moof box
  • Movie Fragment 一般指 moof box
  • tenc Track Encryption box
  • sgpd sample group description box
  • sbgp Sample To Group Box
  • senc sample encryption box
  • saio auxiliary information offset box
  • saiz auxiliary information size box
  • pssh protection system specific header box

cenc 定義於 ISO BMFF的ISO/IEC 23001-7。其包括:

  • 對於NAL結構的Video和其他媒體使用AES-128 CTR 模式的Common ENCryption(CENC)方案
  • 單個 Representation 的multi-DRM 系統的解密支持
  • Key Rotation(隔斷時間更換 media keys)
  • MPD 中對默認 KID 屬性和 pssh 元素的XML語法支持

DRM組成:

  1. MPD中的 ContentProtection描述符,其包含了表示使用了通用加密或特殊DRM的URI
  2. tenc box(位於Initialization Segment,通常指的是位於 moov box 的 trak box 中)描述了加密參數和default_KID。位於 sgpd box 的 default_KID 會覆蓋 tenc 中的 default_KID,同樣,關於 "not encrypted" 的參數也會被覆蓋。當樣本可用於解密時,樣本組描述中KID引用的密鑰必須可用,其可能位於 moof box中的 pssh box。default_KID 也可能出現在 MPD中。
  3. senc box 可能存儲了 IV(initialization vectors) 和 subsample 的加密范圍。對於一個加密track而言,其位於 traf box(track fragment box)中。訪問這些存儲的參數需要借助於 sziosaiz box。(參考ISO14496-12 #8.7.8)
  4. pssh用於批准對於以"Protection System Specific"形式的DRM獲取的數據或者keys。pssh 可能存在於moov 或者 moof box。其也可能以cenc:pssh的形式出現在 MPD 中,這種形式支持 faster parsing,earlier access,identification of duplicate license requests,和不修改內容的前提下的附加DRMs。在moov中的pssh形式並不是推薦的,因為在Web瀏覽器中為每個Representation和比特率切換 Initialization Segment 時,它們都會觸發license requests。
  5. Key rotation 主要用於更改連續實時內容的密鑰。其實現需要以下條件:
    • sbgpseig類型的sgpd用於聲明應用於每個sample的 KID,和隔斷時間對於 KIDs的改變,即 Key rotation。 當Segment中的sample可用於解密時,樣本組引用的KID必須具有與這些KID對應的密鑰. Segments 種的 sample group 引用的Keys位於 moof種的 pssh box 中。版本 1"pssh"框可用於列出存儲的 KID 值,以便在文件分段時刪除重復box。
    • 對於不同用戶,Movie Fragment 中存儲的 pssh采用一致的DRM格式,以使得 Movie Fragment 可以被不同用戶共享。用戶特定信息必須"帶外"(out of band)傳遞,如與default_KID關聯的"root"許可證中,該許可證可以針對每個 DRM 客戶端進行個性化設置,並控制對存儲在 Media Segments 中的共享"pssh"信息的訪問,例如,使用特定於用戶的 DRM 根許可證提供的"root key"加密存儲在Segment"pssh"box中的密鑰。cenc指定"pssh"以啟用moov/moof的密鑰存儲;但它不排除滿足 KID 索引和可用性要求的其他密鑰交付方法。

ISO BMFF Support for Common Encryption and DRM

cenc 具有以下結構關系:
• moov/pssh (zero or one per system ID)
• moov/trak/mdia/minf/stbl/stsd/sinf/schm (one, if encrypted)
• moov/trak/mdia/minf/stbl/stsd/sinf/schi/tenc (one, if encrypted)
• moof/traf/saiz (one, if encrypted)
• moof/traf/saio (one, if encrypted)
• moof/traf/senc (one, if encrypted)

Key Rotation 具有以下結構關系:
• moof/traf/sbgp (one per sample group)
• moof/traf/sgpd ‘seig’ (sample group entry) (one per sample group)
• moof/pssh (zero or one per system ID)

senc 與 saio/saio 的關系

senc結構如下:

aligned(8) class SampleEncryptionBox extends FullBox(‘senc’, version=0, flags)
{
  unsigned int(32) sample_count;
  {
    unsigned int(Per_Sample_IV_Size*8) InitializationVector;
    if (flags & 0x000002)
    {
    unsigned int(16) subsample_count;
      {
        unsigned int(16) BytesOfClearData;
        unsigned int(32) BytesOfProtectedData;
      } [ subsample_count ]
    }
  }[ sample_count ]
}

sample auxiliary information 的一個可選存儲位置是senc box (Sample Encryption Box)。senc 包含 sample auxiliary information,和對於每個 sample 的 IV信息,和 partial sample 加密video的 clear 以及 protected 數據的字節范圍(即 “Subsample encryption”)。當track 的sample 或者 track fragment 為加密的時候是有用的。在 traf box(track fragment box) 中存儲 senc box,使得在 moof(movie fragment) 中可以訪問所有包含 sample 的必要 sample auxiliary information,以使每個 track fragment 可以獨立解密。

saiz 的結構如下:

aligned(8) class SampleAuxiliaryInformationSizesBox extends FullBox(‘saiz’, version = 0, flags)
{
  if (flags & 1) {
    unsigned int(32) aux_info_type; // 聲明輔助信息類型,對於 cenc加密,此處是 cenc
    unsigned int(32) aux_info_type_parameter; // 與前者關聯的參數,由aux_info_type決定
  }
  unsigned int(8) default_sample_info_size; // 輔助信息 默認大小
  unsigned int(32) sample_count;  // 有多少sample 輔助信息
  if (default_sample_info_size == 0) {
    unsigned int(8) sample_info_size[ sample_count ];
  }
}

saio 的結構如下:

aligned(8) class SampleAuxiliaryInformationOffsetsBox extends FullBox(‘saio’, version, flags)
{
  if (flags & 1) {
    unsigned int(32) aux_info_type; // 聲明輔助信息類型,對於 cenc加密,此處是 cenc
    unsigned int(32) aux_info_type_parameter; // 與前者關聯的參數,由aux_info_type決定
  }
  unsigned int(32) entry_count; // 一般為1
  if ( version == 0 ) {
    unsigned int(32) offset[ entry_count ]; // 若 saio/saiz 在 stbl 中,此值是絕對的; 在 traf 中,該值是相對的(tfhd box 的flag, 如果該 flag == 0x020000(default-base-is-moof)則表示該相對偏移量是相對於 moof box的開始位置)
  }
  else {
    unsigned int(64) offset[ entry_count ];
  }
}

對於 saio/saiz 與 senc 同時存在與 traf的情況,saio 指向的輔助信息始終是 senc 中的第一個 IV, 因為 輔助信息是連續的,所以輔助信息的大小通常為 saiz.default_sample_info_size * saiz.sample_count. 並且有 senc.sample_count == saiz.sample_count;

總結 Common encryption sample auxiliary information

受保護 track 中的每個受保護 sample 都應具有與其關聯的IV(Initialization Vector)。 IV 和 SubSample 加密信息都可以由等於 sheme 的 aux_info_type 和 等於0 的aux_info_type_parameter的 sample 輔助信息提供。比如:如果track 使用 cenc scheme 加密,那么 ux_info_type == cenc,aux_info_type_parameter == 0;所以這些可選字段應該忽略。對於 cenc 類型的 sample 輔助信息,其具有一下形式:

aligned(8) class CencSampleAuxiliaryDataFormat
{
  unsigned int(Per_Sample_IV_Size*8) InitializationVector;
  if (sample_info_size > Per_Sample_IV_Size )
  {
    unsigned int(16) subsample_count;
    {
      unsigned int(16) BytesOfClearData;
      unsigned int(32) BytesOfProtectedData;
    } [subsample_count ]
  }
}

這個結構就是senc的子結構
如果 SubSample Encrytion 的方案未被使用(即 sample auxiliary information 的size == Per_Sample_IV_Size),此時整個 sample 都是加密的。這種情況下,所有的auxiliary information 都具有相同的size,因此 saiz 中的 default_sample_info_size == Per_Sample_IV_Size(IV)。
如果 Per_Sample_IV_Size 也為0,(因為使用了 constant IVs),那么sample auxiliary information 應該為 0 且被忽略。
注意:即使使用了 Subsample encryption, sample auxiliary information 的 size 對於所有 sample 而言,仍然可能都相同(如果所有的sample 都含有相同數目的subsample),而且,default_sample_info_size 也可能被使用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM