1) Do not use gflags in the example binary code.
2) Also surface wv_cas_key_fetcher_example to partner. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=229965302
This commit is contained in:
@@ -13,17 +13,15 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "gflags/gflags.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
|
||||
DEFINE_int32(content_iv_size, 8, "Content IV size");
|
||||
DEFINE_bool(key_rotation, true, "Whether key rotation is enabled");
|
||||
DEFINE_string(crypto_mode, "CSA2", "Only CBC, CTR, or CSA2 is allowed");
|
||||
DEFINE_int32(ecm_pid, 149, "PID for the ECM packet");
|
||||
DEFINE_string(output_file, "",
|
||||
"If specified, generated ECM TS packet will be written to the "
|
||||
"specified output file path");
|
||||
const size_t kContentIvSize = 8;
|
||||
const bool kKeyRotation = false; // whether key rotation is enabled
|
||||
const char kCryptoMode[] = "CTR"; // CBC, CTR, or CSA2
|
||||
const int kEcmPid = 149; // PID for the ECM packet
|
||||
const char kOutputFile[] =
|
||||
"/tmp/ecm.ts"; // ECM TS packet will be output to here
|
||||
|
||||
const char kCsaEvenKey[] = "even_key"; // 8 bytes
|
||||
const char kEvenContentIv8Bytes[] = "even_iv."; // 8 bytes
|
||||
@@ -35,31 +33,31 @@ const char kOddContentIv8Bytes[] = "odd_iv.."; // 8 bytes
|
||||
const char kOddEntitlementKeyId[] = "fake_key_id2...."; // 16 bytes
|
||||
const char kOddEntitlementKey[] =
|
||||
"fakefakefakefakefakefakefake2..."; // 32 bytes
|
||||
const uint8_t kTableId = 0x80;
|
||||
const size_t kTsPacketSize = 188;
|
||||
|
||||
widevine::cas::CryptoMode GetCryptoMode() {
|
||||
if (FLAGS_crypto_mode.compare("CBC") == 0) {
|
||||
widevine::cas::CryptoMode GetCryptoMode(const std::string& crypto_mode) {
|
||||
if (crypto_mode.compare("CBC") == 0) {
|
||||
return widevine::cas::CryptoMode::kAesCbc;
|
||||
}
|
||||
if (FLAGS_crypto_mode.compare("CTR") == 0) {
|
||||
if (crypto_mode.compare("CTR") == 0) {
|
||||
return widevine::cas::CryptoMode::kAesCtr;
|
||||
}
|
||||
return widevine::cas::CryptoMode::kDvbCsa2;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
int main(int argc, char** argv) {
|
||||
// Generate ECM.
|
||||
widevine::cas::WvCasEcm wv_cas_ecm;
|
||||
widevine::cas::WvCasStatus status = wv_cas_ecm.Initialize(
|
||||
FLAGS_content_iv_size, FLAGS_key_rotation, GetCryptoMode());
|
||||
kContentIvSize, kKeyRotation, GetCryptoMode(kCryptoMode));
|
||||
if (status != widevine::cas::OK) {
|
||||
std::cerr << "Failed to initialize WV CAS ECM, error: "
|
||||
<< widevine::cas::GetWvCasStatusMessage(status)
|
||||
<< std::endl;
|
||||
}
|
||||
std::string ecm;
|
||||
if (FLAGS_key_rotation) {
|
||||
if (kKeyRotation) {
|
||||
status = wv_cas_ecm.GenerateEcm(
|
||||
kCsaEvenKey, kEvenContentIv8Bytes, kEvenEntitlementKeyId,
|
||||
kEvenEntitlementKey, kCsaOddKey, kOddContentIv8Bytes,
|
||||
@@ -85,8 +83,7 @@ int main(int argc, char **argv) {
|
||||
// Generate ECM TS Packet.
|
||||
uint8_t packet[kTsPacketSize];
|
||||
uint8_t continuity_counter; // not used.
|
||||
status = wv_cas_ecm.GenerateTsPacket(ecm, FLAGS_ecm_pid,
|
||||
/* table_id= */ 0x80,
|
||||
status = wv_cas_ecm.GenerateTsPacket(ecm, kEcmPid, kTableId,
|
||||
&continuity_counter, packet);
|
||||
if (status != widevine::cas::OK) {
|
||||
std::cerr << "Failed to create ECM TS packet" << std::endl;
|
||||
@@ -99,13 +96,11 @@ int main(int argc, char **argv) {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
// Write ECM TS Packet to a file.
|
||||
if (!FLAGS_output_file.empty()) {
|
||||
std::ofstream file;
|
||||
file.open(FLAGS_output_file.c_str(), std::ios_base::binary);
|
||||
file.open(kOutputFile, std::ios_base::binary);
|
||||
assert(file.is_open());
|
||||
file.write(reinterpret_cast<char *>(packet), kTsPacketSize);
|
||||
file.close();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user