2015-11-18 21:11:31 +00:00
|
|
|
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/formats/webm/two_pass_single_segment_segmenter.h>
|
2015-11-18 21:11:31 +00:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/formats/webm/segmenter_test_base.h>
|
2016-08-17 17:41:40 +00:00
|
|
|
#include <memory>
|
2015-11-18 21:11:31 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-11-18 21:11:31 +00:00
|
|
|
namespace media {
|
|
|
|
namespace {
|
|
|
|
|
2021-08-04 18:56:44 +00:00
|
|
|
const int32_t kTimeScale = 1000000;
|
|
|
|
const int64_t kDuration = 1000000;
|
2017-02-24 01:17:47 +00:00
|
|
|
const bool kSubsegment = true;
|
2017-03-11 02:49:55 +00:00
|
|
|
const uint8_t kPerSampleIvSize = 8u;
|
|
|
|
const uint8_t kKeyId[] = {
|
|
|
|
0x4c, 0x6f, 0x72, 0x65, 0x6d, 0x20, 0x69, 0x70,
|
|
|
|
0x73, 0x75, 0x6d, 0x20, 0x64, 0x6f, 0x6c, 0x6f,
|
|
|
|
};
|
|
|
|
const uint8_t kIv[] = {
|
|
|
|
0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45,
|
|
|
|
};
|
2022-03-07 19:56:34 +00:00
|
|
|
// clang-format off
|
2015-11-18 21:11:31 +00:00
|
|
|
const uint8_t kBasicSupportData[] = {
|
2016-09-06 22:13:42 +00:00
|
|
|
// ID: EBML Header omitted.
|
2022-03-07 19:56:34 +00:00
|
|
|
// ID: Segment, Payload Size: 439
|
|
|
|
0x18, 0x53, 0x80, 0x67, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xb7,
|
2016-04-04 18:28:08 +00:00
|
|
|
// ID: SeekHead, Payload Size: 58
|
|
|
|
0x11, 0x4d, 0x9b, 0x74, 0xba,
|
|
|
|
// ID: Seek, Payload Size: 11
|
|
|
|
0x4d, 0xbb, 0x8b,
|
|
|
|
// SeekID: binary(4) (Info)
|
|
|
|
0x53, 0xab, 0x84, 0x15, 0x49, 0xa9, 0x66,
|
|
|
|
// SeekPosition: 89
|
|
|
|
0x53, 0xac, 0x81, 0x59,
|
|
|
|
// ID: Seek, Payload Size: 11
|
|
|
|
0x4d, 0xbb, 0x8b,
|
|
|
|
// SeekID: binary(4) (Tracks)
|
|
|
|
0x53, 0xab, 0x84, 0x16, 0x54, 0xae, 0x6b,
|
2022-03-07 19:56:34 +00:00
|
|
|
// SeekPosition: 189
|
|
|
|
0x53, 0xac, 0x81, 0xbd,
|
2015-11-18 21:11:31 +00:00
|
|
|
// ID: Seek, Payload Size: 12
|
|
|
|
0x4d, 0xbb, 0x8c,
|
2016-09-29 00:13:15 +00:00
|
|
|
// SeekID: binary(4) (Cues)
|
|
|
|
0x53, 0xab, 0x84, 0x1c, 0x53, 0xbb, 0x6b,
|
2022-03-07 19:56:34 +00:00
|
|
|
// SeekPosition: 286
|
|
|
|
0x53, 0xac, 0x82, 0x01, 0x1e,
|
2015-11-18 21:11:31 +00:00
|
|
|
// ID: Seek, Payload Size: 12
|
|
|
|
0x4d, 0xbb, 0x8c,
|
2016-09-29 00:13:15 +00:00
|
|
|
// SeekID: binary(4) (Cluster)
|
|
|
|
0x53, 0xab, 0x84, 0x1f, 0x43, 0xb6, 0x75,
|
2022-03-07 19:56:34 +00:00
|
|
|
// SeekPosition: 320
|
|
|
|
0x53, 0xac, 0x82, 0x01, 0x40,
|
2016-04-04 18:28:08 +00:00
|
|
|
// ID: Void, Payload Size: 24
|
|
|
|
0xec, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
2015-11-18 21:11:31 +00:00
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
2016-04-04 18:28:08 +00:00
|
|
|
0x00, 0x00,
|
2022-03-07 19:56:34 +00:00
|
|
|
// ID: Info, Payload Size: 95
|
|
|
|
0x15, 0x49, 0xa9, 0x66, 0xdf,
|
2015-11-18 21:11:31 +00:00
|
|
|
// TimecodeScale: 1000000
|
|
|
|
0x2a, 0xd7, 0xb1, 0x83, 0x0f, 0x42, 0x40,
|
|
|
|
// Duration: float(5000)
|
|
|
|
0x44, 0x89, 0x84, 0x45, 0x9c, 0x40, 0x00,
|
2022-12-17 05:40:00 +00:00
|
|
|
// MuxingApp: 'libwebm-0.3.0.0'
|
2015-11-18 21:11:31 +00:00
|
|
|
0x4d, 0x80, 0x8f, 0x6c, 0x69, 0x62, 0x77, 0x65, 0x62, 0x6d, 0x2d, 0x30,
|
2022-12-17 05:40:00 +00:00
|
|
|
0x2e, 0x33, 0x2e, 0x30, 0x2e, 0x30,
|
2022-03-07 19:56:34 +00:00
|
|
|
// WritingApp: 'https://github.com/shaka-project/shaka-packager version test'
|
|
|
|
0x57, 0x41, 0xbc,
|
2015-11-18 21:11:31 +00:00
|
|
|
0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, 0x68,
|
2022-03-07 19:56:34 +00:00
|
|
|
0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x68, 0x61, 0x6b, 0x61,
|
|
|
|
0x2d, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x73, 0x68, 0x61,
|
|
|
|
0x6b, 0x61, 0x2d, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x72, 0x20,
|
|
|
|
0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x65, 0x73, 0x74,
|
2016-02-17 22:03:43 +00:00
|
|
|
// ID: Tracks, Payload Size: 92
|
|
|
|
0x16, 0x54, 0xae, 0x6b, 0xdc,
|
|
|
|
// ID: Track, Payload Size: 90
|
|
|
|
0xae, 0xda,
|
2015-11-18 21:11:31 +00:00
|
|
|
// TrackNumber: 1
|
|
|
|
0xd7, 0x81, 0x01,
|
|
|
|
// TrackUID: 1
|
|
|
|
0x73, 0xc5, 0x81, 0x01,
|
|
|
|
// TrackType: 1
|
|
|
|
0x83, 0x81, 0x01,
|
|
|
|
// CodecID: 'V_VP8'
|
|
|
|
0x86, 0x85, 0x56, 0x5f, 0x56, 0x50, 0x38,
|
|
|
|
// Language: 'en'
|
|
|
|
0x22, 0xb5, 0x9c, 0x82, 0x65, 0x6e,
|
2016-02-17 22:03:43 +00:00
|
|
|
// ID: ContentEncodings, Payload Size: 48
|
|
|
|
0x6d, 0x80, 0xb0,
|
|
|
|
// ID: ContentEncoding, Payload Size: 45
|
|
|
|
0x62, 0x40, 0xad,
|
2015-11-18 21:11:31 +00:00
|
|
|
// ContentEncodingOrder: 0
|
|
|
|
0x50, 0x31, 0x81, 0x00,
|
|
|
|
// ContentEncodingScope: 1
|
|
|
|
0x50, 0x32, 0x81, 0x01,
|
|
|
|
// ContentEncodingType: 1
|
|
|
|
0x50, 0x33, 0x81, 0x01,
|
2016-02-17 22:03:43 +00:00
|
|
|
// ID: ContentEncryption, Payload Size: 30
|
|
|
|
0x50, 0x35, 0x9e,
|
2015-11-18 21:11:31 +00:00
|
|
|
// ContentEncAlgo: 5
|
|
|
|
0x47, 0xe1, 0x81, 0x05,
|
2016-02-17 22:03:43 +00:00
|
|
|
// ContentEncKeyID: binary(16)
|
|
|
|
0x47, 0xe2, 0x90,
|
|
|
|
0x4c, 0x6f, 0x72, 0x65, 0x6d, 0x20, 0x69, 0x70,
|
|
|
|
0x73, 0x75, 0x6d, 0x20, 0x64, 0x6f, 0x6c, 0x6f,
|
2015-11-18 21:11:31 +00:00
|
|
|
// ID: ContentEncAESSettings, Payload Size: 4
|
|
|
|
0x47, 0xe7, 0x84,
|
|
|
|
// AESSettingsCipherMode: 1
|
|
|
|
0x47, 0xe8, 0x81, 0x01,
|
|
|
|
// ID: Video, Payload Size: 14
|
|
|
|
0xe0, 0x8e,
|
|
|
|
// PixelWidth: 100
|
|
|
|
0xb0, 0x81, 0x64,
|
|
|
|
// PixelHeight: 100
|
|
|
|
0xba, 0x81, 0x64,
|
|
|
|
// DisplayWidth: 100
|
|
|
|
0x54, 0xb0, 0x81, 0x64,
|
|
|
|
// DisplayHeight: 100
|
|
|
|
0x54, 0xba, 0x81, 0x64,
|
2016-09-29 00:13:15 +00:00
|
|
|
// ID: Cues, Payload Size: 29
|
|
|
|
0x1c, 0x53, 0xbb, 0x6b, 0x9d,
|
|
|
|
// ID: CuePoint, Payload Size: 12
|
|
|
|
0xbb, 0x8c,
|
|
|
|
// CueTime: 0
|
|
|
|
0xb3, 0x81, 0x00,
|
|
|
|
// ID: CueTrackPositions, Payload Size: 7
|
|
|
|
0xb7, 0x87,
|
|
|
|
// CueTrack: 1
|
|
|
|
0xf7, 0x81, 0x01,
|
2022-03-07 19:56:34 +00:00
|
|
|
// CueClusterPosition: 320
|
|
|
|
0xf1, 0x82, 0x01, 0x40,
|
2016-09-29 00:13:15 +00:00
|
|
|
// ID: CuePoint, Payload Size: 13
|
|
|
|
0xbb, 0x8d,
|
|
|
|
// CueTime: 3000
|
|
|
|
0xb3, 0x82, 0x0b, 0xb8,
|
|
|
|
// ID: CueTrackPositions, Payload Size: 7
|
|
|
|
0xb7, 0x87,
|
|
|
|
// CueTrack: 1
|
|
|
|
0xf7, 0x81, 0x01,
|
2022-03-07 19:56:34 +00:00
|
|
|
// CueClusterPosition: 377
|
|
|
|
0xf1, 0x82, 0x01, 0x79,
|
2016-08-02 23:43:23 +00:00
|
|
|
// ID: Cluster, Payload Size: 45
|
|
|
|
0x1f, 0x43, 0xb6, 0x75, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d,
|
2015-11-18 21:11:31 +00:00
|
|
|
// Timecode: 0
|
|
|
|
0xe7, 0x81, 0x00,
|
|
|
|
// ID: SimpleBlock, Payload Size: 10
|
|
|
|
0xa3, 0x8a, 0x81, 0x00, 0x00, 0x80,
|
|
|
|
// Signal Byte: Clear
|
|
|
|
0x00,
|
|
|
|
// Frame Data:
|
|
|
|
0xde, 0xad, 0xbe, 0xef, 0x00,
|
2016-08-02 23:43:23 +00:00
|
|
|
// ID: SimpleBlock, Payload Size: 10
|
|
|
|
0xa3, 0x8a, 0x81, 0x03, 0xe8, 0x80,
|
|
|
|
// Signal Byte: Clear
|
|
|
|
0x00,
|
|
|
|
// Frame Data:
|
|
|
|
0xde, 0xad, 0xbe, 0xef, 0x00,
|
|
|
|
// ID: BlockGroup, Payload Size: 16
|
|
|
|
0xa0, 0x90,
|
|
|
|
// ID: Block, Payload Size: 10
|
|
|
|
0xa1, 0x8a, 0x81, 0x07, 0xd0, 0x00,
|
|
|
|
// Signal Byte: Clear
|
|
|
|
0x00,
|
|
|
|
// Frame Data:
|
|
|
|
0xde, 0xad, 0xbe, 0xef, 0x00,
|
|
|
|
// BlockDuration: 1000
|
|
|
|
0x9b, 0x82, 0x03, 0xe8,
|
|
|
|
// ID: Cluster, Payload Size: 50
|
|
|
|
0x1f, 0x43, 0xb6, 0x75, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32,
|
|
|
|
// Timecode: 3000
|
|
|
|
0xe7, 0x82, 0x0b, 0xb8,
|
|
|
|
// ID: SimpleBlock: Payload Size: 18
|
|
|
|
0xa3, 0x92, 0x81, 0x00,0x00, 0x80,
|
2015-11-18 21:11:31 +00:00
|
|
|
// Signal Byte: Encrypted
|
|
|
|
0x01,
|
|
|
|
// IV:
|
|
|
|
0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45,
|
|
|
|
// Frame Data:
|
2017-03-11 02:49:55 +00:00
|
|
|
0xde, 0xad, 0xbe, 0xef, 0x00,
|
2016-01-21 23:58:13 +00:00
|
|
|
// ID: BlockGroup, Payload Size: 24
|
|
|
|
0xa0, 0x98,
|
|
|
|
// ID: Block, Payload Size: 18
|
2016-08-02 23:43:23 +00:00
|
|
|
0xa1, 0x92, 0x81, 0x03, 0xe8, 0x00,
|
2016-01-21 23:58:13 +00:00
|
|
|
// Signal Byte: Encrypted
|
|
|
|
0x01,
|
|
|
|
// IV:
|
2017-03-11 02:49:55 +00:00
|
|
|
0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45,
|
2016-01-21 23:58:13 +00:00
|
|
|
// Frame Data:
|
2017-03-11 02:49:55 +00:00
|
|
|
0xde, 0xad, 0xbe, 0xef, 0x00,
|
2016-01-21 23:58:13 +00:00
|
|
|
// BlockDuration: 1000
|
|
|
|
0x9b, 0x82, 0x03, 0xe8,
|
2015-11-18 21:11:31 +00:00
|
|
|
};
|
2022-03-07 19:56:34 +00:00
|
|
|
// clang-format on
|
2015-11-18 21:11:31 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-03-11 02:49:55 +00:00
|
|
|
class EncryptedSegmenterTest : public SegmentTestBase {
|
2015-11-18 21:11:31 +00:00
|
|
|
public:
|
2017-05-13 00:02:12 +00:00
|
|
|
EncryptedSegmenterTest() : info_(CreateVideoStreamInfo(kTimeScale)) {
|
2017-03-11 02:49:55 +00:00
|
|
|
EncryptionConfig encryption_config;
|
|
|
|
encryption_config.per_sample_iv_size = kPerSampleIvSize;
|
|
|
|
encryption_config.key_id.assign(kKeyId, kKeyId + sizeof(kKeyId));
|
|
|
|
info_->set_is_encrypted(true);
|
|
|
|
info_->set_encryption_config(encryption_config);
|
|
|
|
}
|
2015-11-18 21:11:31 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void InitializeSegmenter(const MuxerOptions& options) {
|
|
|
|
ASSERT_NO_FATAL_FAILURE(
|
2016-09-29 00:13:15 +00:00
|
|
|
CreateAndInitializeSegmenter<webm::TwoPassSingleSegmentSegmenter>(
|
2017-09-12 17:24:24 +00:00
|
|
|
options, *info_, &segmenter_));
|
2015-11-18 21:11:31 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 00:55:02 +00:00
|
|
|
std::shared_ptr<StreamInfo> info_;
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<webm::Segmenter> segmenter_;
|
2015-11-18 21:11:31 +00:00
|
|
|
};
|
|
|
|
|
2017-03-11 02:49:55 +00:00
|
|
|
TEST_F(EncryptedSegmenterTest, BasicSupport) {
|
2015-11-18 21:11:31 +00:00
|
|
|
MuxerOptions options = CreateMuxerOptions();
|
|
|
|
ASSERT_NO_FATAL_FAILURE(InitializeSegmenter(options));
|
|
|
|
|
|
|
|
// Write the samples to the Segmenter.
|
2016-08-02 23:43:23 +00:00
|
|
|
// There should be 2 segments with the first segment in clear and the second
|
|
|
|
// segment encrypted.
|
2015-11-18 21:11:31 +00:00
|
|
|
for (int i = 0; i < 5; i++) {
|
2017-12-06 23:08:40 +00:00
|
|
|
if (i == 3) {
|
2017-02-24 01:17:47 +00:00
|
|
|
ASSERT_OK(segmenter_->FinalizeSegment(0, 3 * kDuration, !kSubsegment));
|
2017-12-06 23:08:40 +00:00
|
|
|
}
|
2017-01-24 00:55:02 +00:00
|
|
|
std::shared_ptr<MediaSample> sample =
|
2015-11-18 21:11:31 +00:00
|
|
|
CreateSample(kKeyFrame, kDuration, kNoSideData);
|
2017-03-11 02:49:55 +00:00
|
|
|
if (i >= 3) {
|
|
|
|
sample->set_is_encrypted(true);
|
|
|
|
std::unique_ptr<DecryptConfig> decrypt_config(
|
|
|
|
new DecryptConfig(info_->encryption_config().key_id,
|
|
|
|
std::vector<uint8_t>(kIv, kIv + sizeof(kIv)),
|
|
|
|
std::vector<SubsampleEntry>()));
|
|
|
|
sample->set_decrypt_config(std::move(decrypt_config));
|
|
|
|
}
|
2017-09-12 17:24:24 +00:00
|
|
|
ASSERT_OK(segmenter_->AddSample(*sample));
|
2015-11-18 21:11:31 +00:00
|
|
|
}
|
2017-02-24 01:17:47 +00:00
|
|
|
ASSERT_OK(
|
|
|
|
segmenter_->FinalizeSegment(3 * kDuration, 2 * kDuration, !kSubsegment));
|
2015-11-18 21:11:31 +00:00
|
|
|
ASSERT_OK(segmenter_->Finalize());
|
|
|
|
|
2016-09-06 22:13:42 +00:00
|
|
|
ASSERT_FILE_ENDS_WITH(OutputFileName().c_str(), kBasicSupportData);
|
2015-11-18 21:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|