From 7c38963c29f8cf40c8fd6109bab22f9e49e63818 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Tue, 17 Oct 2017 15:47:43 -0700 Subject: [PATCH] [doc] Update raw key tutorial Change-Id: Ife841975c036cf8042c9775583c409e0daa089c7 --- .../source/options/drm_stream_descriptors.rst | 15 +++++ .../options/raw_key_encryption_options.rst | 8 --- docs/source/options/stream_descriptors.rst | 16 +----- docs/source/tutorials/raw_key.rst | 56 +++++++++++++------ docs/source/tutorials/widevine.rst | 8 +-- packager/app/packager_main.cc | 4 ++ packager/media/base/widevine_key_source.cc | 1 + 7 files changed, 64 insertions(+), 44 deletions(-) create mode 100644 docs/source/options/drm_stream_descriptors.rst diff --git a/docs/source/options/drm_stream_descriptors.rst b/docs/source/options/drm_stream_descriptors.rst new file mode 100644 index 0000000000..7201a7f833 --- /dev/null +++ b/docs/source/options/drm_stream_descriptors.rst @@ -0,0 +1,15 @@ +DRM related Stream descriptor fields +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +:skip_encryption=0|1: + + Optional. Defaults to 0 if not specified. If it is set to 1, no encryption + of the stream will be made. + +:drm_label: + + Optional value for custom DRM label, which defines the encryption key + applied to the stream. Typically values include AUDIO, SD, HD, UHD1, UHD2. + For raw key, it should be a label defined in --keys. If not provided, the + DRM label is derived from stream type (video, audio), resolutions, etc. + Note that it is case sensitive. diff --git a/docs/source/options/raw_key_encryption_options.rst b/docs/source/options/raw_key_encryption_options.rst index 31820f2a0f..d31e7ad451 100644 --- a/docs/source/options/raw_key_encryption_options.rst +++ b/docs/source/options/raw_key_encryption_options.rst @@ -23,14 +23,6 @@ Raw key encryption options *key_id* and *key* should be 32-digit hex strings. ---key_id <32-digit hex string> - - The key id in hex string format. Deprecated. Use --keys instead. - ---key <32-digit hex string> - - The key in hex string format. Deprecated. Use --keys instead. - --iv <16-digit or 32-digit hex string> IV in hex string format. If not specified, a random IV will be generated. diff --git a/docs/source/options/stream_descriptors.rst b/docs/source/options/stream_descriptors.rst index ac97e252ff..c91a762cc1 100644 --- a/docs/source/options/stream_descriptors.rst +++ b/docs/source/options/stream_descriptors.rst @@ -4,7 +4,7 @@ Stream descriptors There can be multiple *stream_descriptor* with input from the same "file" or multiple different "files". -Stream is of the form:: +Stream descriptor is of the form:: {field}={value}[,{field}={value}]... @@ -57,23 +57,11 @@ These are the available fields: If not specified, it will be derived from the file extension of the output file. -:skip_encryption=0|1: - - Optional. Defaults to 0 if not specified. If it is set to 1, no encryption - of the stream will be made. - -:drm_label: - - Optional value for custom DRM label, which defines the encryption key - applied to the stream. Typically values include AUDIO, SD, HD, UHD1, UHD2. - For raw key, it should be a label defined in --keys. If not provided, the - DRM label is derived from stream type (video, audio), resolutions, etc. - Note that it is case sensitive. - :trick_play_factor (tpf): Optional value which specifies the trick play, a.k.a. trick mode, stream sampling rate among key frames. If specified, the output is a trick play stream. +.. include:: /options/drm_stream_descriptors.rst .. include:: /options/hls_stream_descriptors.rst diff --git a/docs/source/tutorials/raw_key.rst b/docs/source/tutorials/raw_key.rst index a477d04d58..7890b497fe 100644 --- a/docs/source/tutorials/raw_key.rst +++ b/docs/source/tutorials/raw_key.rst @@ -10,19 +10,24 @@ Synopsis $ packager {stream_descriptor} [stream_descriptor] ... \ --enable_fixed_key_encryption \ - --key_id --key \ + --keys \ [--pssh ] \ [Other options, e.g. DASH options, HLS options] +**key_info_string** is of the form:: + + label={label}:key_id={key_id}:key={key} + Custom PSSH(s) can be provided in *--pssh*. If absent, `v1 common PSSH box `_ is generated. Examples -------- -The examples below uses the H264 streams created in :doc:`encoding`. Here are examples with DASH. It can be applied to HLS in a similar way. +The examples below uses the H264 streams created in :doc:`encoding`. Here are +examples with DASH. It can be applied to HLS in a similar way. -Common PSSH:: +Common PSSH (one key for all streams):: $ packager \ in=h264_baseline_360p_600.mp4,stream=audio,output=audio.mp4 \ @@ -31,21 +36,31 @@ Common PSSH:: in=h264_main_720p_3000.mp4,stream=video,output=h264_720p.mp4 \ in=h264_high_1080p_6000.mp4,stream=video,output=h264_1080p.mp4 \ --enable_fixed_key_encryption \ - --key_id abba271e8bcf552bbd2e86a434a9a5d9 \ - --key 69eaa802a6763af979e8d1940fb88392 \ + --keys label=:key_id=abba271e8bcf552bbd2e86a434a9a5d9:key=69eaa802a6763af979e8d1940fb88392 \ --mpd_output h264.mpd -Widevine PSSH:: +Common PSSH (different keys for different streams):: $ packager \ - in=h264_baseline_360p_600.mp4,stream=audio,output=audio.mp4 \ - in=h264_baseline_360p_600.mp4,stream=video,output=h264_360p.mp4 \ - in=h264_main_480p_1000.mp4,stream=video,output=h264_480p.mp4 \ - in=h264_main_720p_3000.mp4,stream=video,output=h264_720p.mp4 \ - in=h264_high_1080p_6000.mp4,stream=video,output=h264_1080p.mp4 \ + in=h264_baseline_360p_600.mp4,stream=audio,output=audio.mp4,drm_label=AUDIO \ + in=h264_baseline_360p_600.mp4,stream=video,output=h264_360p.mp4,drm_label=SD \ + in=h264_main_480p_1000.mp4,stream=video,output=h264_480p.mp4,drm_label=SD \ + in=h264_main_720p_3000.mp4,stream=video,output=h264_720p.mp4,drm_label=HD \ + in=h264_high_1080p_6000.mp4,stream=video,output=h264_1080p.mp4,drm_label=HD \ --enable_fixed_key_encryption \ - --key_id abba271e8bcf552bbd2e86a434a9a5d9 \ - --key 69eaa802a6763af979e8d1940fb88392 \ + --keys label=AUDIO:key_id=f3c5e0361e6654b28f8049c778b23946:key=a4631a153a443df9eed0593043db7519,label=SD:key_id=abba271e8bcf552bbd2e86a434a9a5d9:key=69eaa802a6763af979e8d1940fb88392,label=HD:key_id=6d76f25cb17f5e16b8eaef6bbf582d8e:key=cb541084c99731aef4fff74500c12ead \ + --mpd_output h264.mpd + +Widevine PSSH (different keys for different streams):: + + $ packager \ + in=h264_baseline_360p_600.mp4,stream=audio,output=audio.mp4,drm_label=AUDIO \ + in=h264_baseline_360p_600.mp4,stream=video,output=h264_360p.mp4,drm_label=SD \ + in=h264_main_480p_1000.mp4,stream=video,output=h264_480p.mp4,drm_label=SD \ + in=h264_main_720p_3000.mp4,stream=video,output=h264_720p.mp4,drm_label=HD \ + in=h264_high_1080p_6000.mp4,stream=video,output=h264_1080p.mp4,drm_label=HD \ + --enable_fixed_key_encryption \ + --keys label=AUDIO:key_id=f3c5e0361e6654b28f8049c778b23946:key=a4631a153a443df9eed0593043db7519,label=SD:key_id=abba271e8bcf552bbd2e86a434a9a5d9:key=69eaa802a6763af979e8d1940fb88392,label=HD:key_id=6d76f25cb17f5e16b8eaef6bbf582d8e:key=cb541084c99731aef4fff74500c12ead \ --pssh 000000407073736800000000edef8ba979d64acea3c827dcd51d21ed000000201a0d7769646576696e655f74657374220f7465737420636f6e74656e74206964 \ --mpd_output h264.mpd @@ -56,19 +71,23 @@ on how to config the DRM in Shaka Player. Test vectors used in this tutorial ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Key ID +:Key ID: - abba271e8bcf552bbd2e86a434a9a5d9 + | SD: abba271e8bcf552bbd2e86a434a9a5d9 + | HD: 6d76f25cb17f5e16b8eaef6bbf582d8e + | AUDIO: f3c5e0361e6654b28f8049c778b23946 Key ID must be 16 bytes or 32 digits in HEX. -Key +:Key: - 69eaa802a6763af979e8d1940fb88392 + | SD: 69eaa802a6763af979e8d1940fb88392 + | HD: cb541084c99731aef4fff74500c12ead + | AUDIO: a4631a153a443df9eed0593043db7519 Key must be 16 bytes or 32 digits in HEX. -Widevine PSSH +:Widevine PSSH: 000000407073736800000000edef8ba979d64acea3c827dcd51d21ed000000201a0d7769646576696e655f74657374220f7465737420636f6e74656e74206964 @@ -78,6 +97,7 @@ Widevine PSSH $ pssh-box.py --widevine-system-id \ --content-id 7465737420636f6e74656e74206964 --provider widevine_test +.. include:: /options/drm_stream_descriptors.rst .. include:: /options/raw_key_encryption_options.rst pssh-box (Utility to generate PSSH boxes) diff --git a/docs/source/tutorials/widevine.rst b/docs/source/tutorials/widevine.rst index e8f2861be1..74e1bb2685 100644 --- a/docs/source/tutorials/widevine.rst +++ b/docs/source/tutorials/widevine.rst @@ -62,19 +62,19 @@ Widevine test credential Here is the test crendential used in this tutorial. -key_server_url +:key_server_url: https://license.uat.widevine.com/cenc/getcontentkey/widevine_test -signer +:signer: widevine_test -aes_signing_key +:aes_signing_key: 1ae8ccd0e7985cc0b6203a55855a1034afc252980e970ca90e5202689f947ab9 -aes_signing_iv +:aes_signing_iv: d58ce954203b7c9a9a9d467f59839249 diff --git a/packager/app/packager_main.cc b/packager/app/packager_main.cc index 040389c7f0..cf39c4a071 100644 --- a/packager/app/packager_main.cc +++ b/packager/app/packager_main.cc @@ -182,10 +182,14 @@ bool ParseKeys(const std::string& keys, RawKeyParams* raw_key) { auto& key_info = raw_key->key_map[drm_label]; if (value_map[kKeyIdLabel].empty() || !base::HexStringToBytes(value_map[kKeyIdLabel], &key_info.key_id)) { + LOG(ERROR) << "Empty key id or invalid hex string for key id: " + << value_map[kKeyIdLabel]; return false; } if (value_map[kKeyLabel].empty() || !base::HexStringToBytes(value_map[kKeyLabel], &key_info.key)) { + LOG(ERROR) << "Empty key or invalid hex string for key: " + << value_map[kKeyLabel]; return false; } } diff --git a/packager/media/base/widevine_key_source.cc b/packager/media/base/widevine_key_source.cc index ef6e1ae34d..57244a4dc8 100644 --- a/packager/media/base/widevine_key_source.cc +++ b/packager/media/base/widevine_key_source.cc @@ -558,6 +558,7 @@ bool WidevineKeySource::ExtractEncryptionKey( std::string stream_label; RCHECK(track_dict->GetString("type", &stream_label)); RCHECK(encryption_key_map.find(stream_label) == encryption_key_map.end()); + VLOG(2) << "drm label:" << stream_label; std::unique_ptr encryption_key(new EncryptionKey());