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:
@@ -18,8 +18,10 @@ filegroup(
|
|||||||
srcs = [
|
srcs = [
|
||||||
"test_ecmg_messages.h",
|
"test_ecmg_messages.h",
|
||||||
"wv_cas_ecm_example.cc",
|
"wv_cas_ecm_example.cc",
|
||||||
|
"wv_cas_key_fetcher_example.cc",
|
||||||
"wv_cas_types_example.cc",
|
"wv_cas_types_example.cc",
|
||||||
":wv_cas_ecm_example",
|
":wv_cas_ecm_example",
|
||||||
|
":wv_cas_key_fetcher_example",
|
||||||
":wv_cas_types_example",
|
":wv_cas_types_example",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,17 +13,15 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "gflags/gflags.h"
|
|
||||||
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
|
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
|
||||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||||
|
|
||||||
DEFINE_int32(content_iv_size, 8, "Content IV size");
|
const size_t kContentIvSize = 8;
|
||||||
DEFINE_bool(key_rotation, true, "Whether key rotation is enabled");
|
const bool kKeyRotation = false; // whether key rotation is enabled
|
||||||
DEFINE_string(crypto_mode, "CSA2", "Only CBC, CTR, or CSA2 is allowed");
|
const char kCryptoMode[] = "CTR"; // CBC, CTR, or CSA2
|
||||||
DEFINE_int32(ecm_pid, 149, "PID for the ECM packet");
|
const int kEcmPid = 149; // PID for the ECM packet
|
||||||
DEFINE_string(output_file, "",
|
const char kOutputFile[] =
|
||||||
"If specified, generated ECM TS packet will be written to the "
|
"/tmp/ecm.ts"; // ECM TS packet will be output to here
|
||||||
"specified output file path");
|
|
||||||
|
|
||||||
const char kCsaEvenKey[] = "even_key"; // 8 bytes
|
const char kCsaEvenKey[] = "even_key"; // 8 bytes
|
||||||
const char kEvenContentIv8Bytes[] = "even_iv."; // 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 kOddEntitlementKeyId[] = "fake_key_id2...."; // 16 bytes
|
||||||
const char kOddEntitlementKey[] =
|
const char kOddEntitlementKey[] =
|
||||||
"fakefakefakefakefakefakefake2..."; // 32 bytes
|
"fakefakefakefakefakefakefake2..."; // 32 bytes
|
||||||
|
const uint8_t kTableId = 0x80;
|
||||||
const size_t kTsPacketSize = 188;
|
const size_t kTsPacketSize = 188;
|
||||||
|
|
||||||
widevine::cas::CryptoMode GetCryptoMode() {
|
widevine::cas::CryptoMode GetCryptoMode(const std::string& crypto_mode) {
|
||||||
if (FLAGS_crypto_mode.compare("CBC") == 0) {
|
if (crypto_mode.compare("CBC") == 0) {
|
||||||
return widevine::cas::CryptoMode::kAesCbc;
|
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::kAesCtr;
|
||||||
}
|
}
|
||||||
return widevine::cas::CryptoMode::kDvbCsa2;
|
return widevine::cas::CryptoMode::kDvbCsa2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char** argv) {
|
||||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
||||||
// Generate ECM.
|
// Generate ECM.
|
||||||
widevine::cas::WvCasEcm wv_cas_ecm;
|
widevine::cas::WvCasEcm wv_cas_ecm;
|
||||||
widevine::cas::WvCasStatus status = wv_cas_ecm.Initialize(
|
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) {
|
if (status != widevine::cas::OK) {
|
||||||
std::cerr << "Failed to initialize WV CAS ECM, error: "
|
std::cerr << "Failed to initialize WV CAS ECM, error: "
|
||||||
<< widevine::cas::GetWvCasStatusMessage(status)
|
<< widevine::cas::GetWvCasStatusMessage(status)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
std::string ecm;
|
std::string ecm;
|
||||||
if (FLAGS_key_rotation) {
|
if (kKeyRotation) {
|
||||||
status = wv_cas_ecm.GenerateEcm(
|
status = wv_cas_ecm.GenerateEcm(
|
||||||
kCsaEvenKey, kEvenContentIv8Bytes, kEvenEntitlementKeyId,
|
kCsaEvenKey, kEvenContentIv8Bytes, kEvenEntitlementKeyId,
|
||||||
kEvenEntitlementKey, kCsaOddKey, kOddContentIv8Bytes,
|
kEvenEntitlementKey, kCsaOddKey, kOddContentIv8Bytes,
|
||||||
@@ -85,8 +83,7 @@ int main(int argc, char **argv) {
|
|||||||
// Generate ECM TS Packet.
|
// Generate ECM TS Packet.
|
||||||
uint8_t packet[kTsPacketSize];
|
uint8_t packet[kTsPacketSize];
|
||||||
uint8_t continuity_counter; // not used.
|
uint8_t continuity_counter; // not used.
|
||||||
status = wv_cas_ecm.GenerateTsPacket(ecm, FLAGS_ecm_pid,
|
status = wv_cas_ecm.GenerateTsPacket(ecm, kEcmPid, kTableId,
|
||||||
/* table_id= */ 0x80,
|
|
||||||
&continuity_counter, packet);
|
&continuity_counter, packet);
|
||||||
if (status != widevine::cas::OK) {
|
if (status != widevine::cas::OK) {
|
||||||
std::cerr << "Failed to create ECM TS packet" << std::endl;
|
std::cerr << "Failed to create ECM TS packet" << std::endl;
|
||||||
@@ -99,13 +96,11 @@ int main(int argc, char **argv) {
|
|||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
// Write ECM TS Packet to a file.
|
// Write ECM TS Packet to a file.
|
||||||
if (!FLAGS_output_file.empty()) {
|
|
||||||
std::ofstream file;
|
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());
|
assert(file.is_open());
|
||||||
file.write(reinterpret_cast<char *>(packet), kTsPacketSize);
|
file.write(reinterpret_cast<char *>(packet), kTsPacketSize);
|
||||||
file.close();
|
file.close();
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,9 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "gflags/gflags.h"
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||||
|
|
||||||
DEFINE_string(function_to_call, "CreateWvCasEncryptionRequestJson",
|
|
||||||
"Function in wv_cas_types to exercise");
|
|
||||||
|
|
||||||
void CallCreateWvCasEncryptionRequestJson() {
|
void CallCreateWvCasEncryptionRequestJson() {
|
||||||
widevine::cas::WvCasEncryptionRequest request;
|
widevine::cas::WvCasEncryptionRequest request;
|
||||||
request.content_id = "cont_id cont_id ";
|
request.content_id = "cont_id cont_id ";
|
||||||
@@ -25,13 +21,10 @@ void CallCreateWvCasEncryptionRequestJson() {
|
|||||||
request.key_rotation = true;
|
request.key_rotation = true;
|
||||||
std::string request_json;
|
std::string request_json;
|
||||||
widevine::cas::CreateWvCasEncryptionRequestJson(request, &request_json);
|
widevine::cas::CreateWvCasEncryptionRequestJson(request, &request_json);
|
||||||
LOG(INFO) << FLAGS_function_to_call << " returns " << request_json;
|
LOG(INFO) << "CreateWvCasEncryptionRequestJson returns " << request_json;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
||||||
if (FLAGS_function_to_call.compare("CreateWvCasEncryptionRequestJson") == 0) {
|
|
||||||
CallCreateWvCasEncryptionRequestJson();
|
CallCreateWvCasEncryptionRequestJson();
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user