def _generate_widevine_data(key_ids, content_id, provider, protection_scheme): """Generate widevine pssh data.""" wv = widevine_pssh_data_pb2.WidevinePsshData() wv.key_id.extend(key_ids) wv.provider = provider or '' wv.content_id = content_id # 'cenc' is the default, so omitted to save bytes. if protection_scheme and protection_scheme != 'cenc': wv.protection_scheme = struct.unpack('>L', protection_scheme)[0] return wv.SerializeToString()
def _parse_widevine_data(data): """Parses Widevine PSSH box from the given binary string.""" wv = widevine_pssh_data_pb2.WidevinePsshData() wv.ParseFromString(data) ret = [] if wv.key_id: ret.append('Key IDs (%d):' % len(wv.key_id)) ret.extend([' ' + _create_uuid(x) for x in wv.key_id]) if wv.HasField('provider'): ret.append('Provider: ' + wv.provider) if wv.HasField('content_id'): ret.append('Content ID: ' + base64.b16encode(wv.content_id)) if wv.HasField('policy'): ret.append('Policy: ' + wv.policy) if wv.HasField('crypto_period_index'): ret.append('Crypto Period Index: %d' % wv.crypto_period_index) return ret
def _generate_widevine_data(key_ids, content_id, provider): wv = widevine_pssh_data_pb2.WidevinePsshData() wv.key_id.extend(key_ids) wv.provider = provider or '' wv.content_id = content_id return wv.SerializeToString()