2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2017 Google LLC. All rights reserved.
|
2017-03-28 19:31:32 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/demuxer/demuxer.h>
|
2017-03-28 19:31:32 +00:00
|
|
|
|
2017-05-31 18:14:11 +00:00
|
|
|
#include <gmock/gmock.h>
|
2017-03-28 19:31:32 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/media/base/media_handler_test_base.h>
|
|
|
|
#include <packager/media/base/raw_key_source.h>
|
|
|
|
#include <packager/media/test/test_data_util.h>
|
|
|
|
#include <packager/status/status_test_util.h>
|
2017-05-31 18:14:11 +00:00
|
|
|
|
2017-03-28 19:31:32 +00:00
|
|
|
namespace shaka {
|
|
|
|
namespace media {
|
2017-05-31 18:14:11 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
using ::testing::_;
|
2023-09-09 00:44:17 +00:00
|
|
|
using ::testing::DoAll;
|
2017-05-31 18:14:11 +00:00
|
|
|
using ::testing::Return;
|
|
|
|
using ::testing::SetArgPointee;
|
|
|
|
|
2017-10-17 23:03:08 +00:00
|
|
|
class MockKeySource : public RawKeySource {
|
2017-05-31 18:14:11 +00:00
|
|
|
public:
|
|
|
|
MOCK_METHOD2(GetKey,
|
|
|
|
Status(const std::vector<uint8_t>& key_id, EncryptionKey* key));
|
|
|
|
};
|
|
|
|
} // namespace
|
2017-03-28 19:31:32 +00:00
|
|
|
|
2017-09-14 16:23:29 +00:00
|
|
|
class DemuxerTest : public MediaHandlerGraphTestBase {
|
2017-05-31 18:14:11 +00:00
|
|
|
protected:
|
|
|
|
EncryptionKey GetMockEncryptionKey() {
|
|
|
|
const uint8_t kKeyId[]{
|
|
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
|
|
|
0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
|
|
|
|
};
|
|
|
|
const uint8_t kKey[]{
|
|
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
|
|
|
0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
|
|
|
|
};
|
|
|
|
EncryptionKey encryption_key;
|
|
|
|
encryption_key.key_id.assign(kKeyId, kKeyId + sizeof(kKeyId));
|
|
|
|
encryption_key.key.assign(kKey, kKey + sizeof(kKey));
|
|
|
|
return encryption_key;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DemuxerTest, FileNotFound) {
|
2017-03-28 19:31:32 +00:00
|
|
|
Demuxer demuxer("file_not_exist.mp4");
|
|
|
|
EXPECT_EQ(error::FILE_FAILURE, demuxer.Run().error_code());
|
|
|
|
}
|
|
|
|
|
2017-05-31 18:14:11 +00:00
|
|
|
TEST_F(DemuxerTest, EncryptedContentWithoutKeySource) {
|
2023-09-09 00:44:17 +00:00
|
|
|
Demuxer demuxer(
|
|
|
|
GetAppTestDataFilePath("encryption/bear-640x360-video.mp4").string());
|
2017-05-31 18:14:11 +00:00
|
|
|
ASSERT_OK(demuxer.SetHandler("video", some_handler()));
|
|
|
|
EXPECT_EQ(error::INVALID_ARGUMENT, demuxer.Run().error_code());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DemuxerTest, EncryptedContentWithKeySource) {
|
|
|
|
std::unique_ptr<MockKeySource> mock_key_source(new MockKeySource);
|
|
|
|
EXPECT_CALL(*mock_key_source, GetKey(_, _))
|
|
|
|
.WillOnce(
|
|
|
|
DoAll(SetArgPointee<1>(GetMockEncryptionKey()), Return(Status::OK)));
|
|
|
|
|
2023-09-09 00:44:17 +00:00
|
|
|
Demuxer demuxer(
|
|
|
|
GetAppTestDataFilePath("encryption/bear-640x360-video.mp4").string());
|
2017-05-31 18:14:11 +00:00
|
|
|
demuxer.SetKeySource(std::move(mock_key_source));
|
|
|
|
ASSERT_OK(demuxer.SetHandler("video", some_handler()));
|
|
|
|
EXPECT_OK(demuxer.Run());
|
|
|
|
}
|
|
|
|
|
2017-03-28 19:31:32 +00:00
|
|
|
// TODO(kqyang): Add more tests.
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
} // namespace shaka
|