2018-03-15 23:04:01 +00:00
|
|
|
// Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
#include "packager/media/chunking/chunking_handler.h"
|
|
|
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "packager/media/base/media_handler_test_base.h"
|
|
|
|
#include "packager/media/chunking/cue_alignment_handler.h"
|
|
|
|
#include "packager/media/public/ad_cue_generator_params.h"
|
2018-05-01 21:40:01 +00:00
|
|
|
#include "packager/status_macros.h"
|
2018-03-15 23:04:01 +00:00
|
|
|
#include "packager/status_test_util.h"
|
|
|
|
|
2018-05-25 17:41:02 +00:00
|
|
|
using ::testing::_;
|
2018-03-15 23:04:01 +00:00
|
|
|
using ::testing::ElementsAre;
|
|
|
|
using ::testing::IsEmpty;
|
|
|
|
|
|
|
|
namespace shaka {
|
|
|
|
namespace media {
|
|
|
|
namespace {
|
|
|
|
const size_t kOneInput = 1;
|
|
|
|
const size_t kOneOutput = 1;
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
const size_t kThreeInputs = 3;
|
|
|
|
const size_t kThreeOutputs = 3;
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
const bool kKeyFrame = true;
|
|
|
|
|
2021-08-04 18:56:44 +00:00
|
|
|
const int32_t kMsTimeScale = 1000;
|
2018-03-15 23:04:01 +00:00
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
const size_t kStreamIndex = 0;
|
2018-03-15 23:04:01 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-05-01 21:40:01 +00:00
|
|
|
class CueAlignmentHandlerTest : public MediaHandlerTestBase {
|
|
|
|
protected:
|
2018-06-19 20:23:39 +00:00
|
|
|
std::unique_ptr<SyncPointQueue> CreateSyncPoints(
|
|
|
|
std::initializer_list<double> cues) {
|
|
|
|
AdCueGeneratorParams params;
|
|
|
|
|
|
|
|
for (double cue_time : cues) {
|
|
|
|
Cuepoint cue;
|
|
|
|
cue.start_time_in_seconds = cue_time;
|
|
|
|
|
|
|
|
params.cue_points.push_back(cue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::unique_ptr<SyncPointQueue>(new SyncPointQueue(params));
|
2018-05-01 21:40:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
Status DispatchAudioInfo(size_t input_index) {
|
|
|
|
auto info = GetAudioStreamInfo(kMsTimeScale);
|
|
|
|
auto data = StreamData::FromStreamInfo(kStreamIndex, std::move(info));
|
|
|
|
|
|
|
|
return Input(input_index)->Dispatch(std::move(data));
|
2018-05-01 21:40:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
Status DispatchTextInfo(size_t input_index) {
|
|
|
|
auto info = GetTextStreamInfo(kMsTimeScale);
|
|
|
|
auto data = StreamData::FromStreamInfo(kStreamIndex, std::move(info));
|
|
|
|
|
|
|
|
return Input(input_index)->Dispatch(std::move(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DispatchVideoInfo(size_t input_index) {
|
|
|
|
auto info = GetVideoStreamInfo(kMsTimeScale);
|
|
|
|
auto data = StreamData::FromStreamInfo(kStreamIndex, std::move(info));
|
|
|
|
|
|
|
|
return Input(input_index)->Dispatch(std::move(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DispatchMediaSample(size_t input_index,
|
|
|
|
int64_t start_time,
|
|
|
|
int64_t duration,
|
|
|
|
bool keyframe) {
|
|
|
|
auto sample = GetMediaSample(start_time, duration, keyframe);
|
|
|
|
auto data = StreamData::FromMediaSample(kStreamIndex, std::move(sample));
|
|
|
|
|
|
|
|
return Input(input_index)->Dispatch(std::move(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
Status DispatchTextSample(size_t input_index,
|
|
|
|
int64_t start_time,
|
|
|
|
int64_t end_time) {
|
|
|
|
const char* kNoId = "";
|
|
|
|
const char* kNoPayload = "";
|
|
|
|
|
|
|
|
auto sample = GetTextSample(kNoId, start_time, end_time, kNoPayload);
|
|
|
|
auto data = StreamData::FromTextSample(kStreamIndex, std::move(sample));
|
|
|
|
|
|
|
|
return Input(input_index)->Dispatch(std::move(data));
|
2018-05-01 21:40:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Status FlushAll(std::initializer_list<size_t> inputs) {
|
|
|
|
for (auto& input : inputs) {
|
|
|
|
RETURN_IF_ERROR(Input(input)->FlushAllDownstreams());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status::OK;
|
|
|
|
}
|
|
|
|
};
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
TEST_F(CueAlignmentHandlerTest, VideoInputWithNoCues) {
|
|
|
|
const size_t kVideoStream = 0;
|
|
|
|
|
|
|
|
const int64_t kSampleDuration = 1000;
|
|
|
|
const int64_t kSample0Start = 0;
|
|
|
|
const int64_t kSample1Start = kSample0Start + kSampleDuration;
|
|
|
|
const int64_t kSample2Start = kSample1Start + kSampleDuration;
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
auto sync_points = CreateSyncPoints({});
|
|
|
|
auto handler = std::make_shared<CueAlignmentHandler>(sync_points.get());
|
2018-05-22 21:24:50 +00:00
|
|
|
ASSERT_OK(SetUpAndInitializeGraph(handler, kOneInput, kOneOutput));
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kVideoStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample0Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample1Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample2Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(*Output(kVideoStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchVideoInfo(kVideoStream));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample0Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample1Start, kSampleDuration,
|
|
|
|
!kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample2Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
ASSERT_OK(FlushAll({kVideoStream}));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CueAlignmentHandlerTest, AudioInputWithNoCues) {
|
|
|
|
const size_t kAudioStream = 0;
|
|
|
|
|
|
|
|
const int64_t kSampleDuration = 1000;
|
|
|
|
const int64_t kSample0Start = 0;
|
|
|
|
const int64_t kSample1Start = kSample0Start + kSampleDuration;
|
|
|
|
const int64_t kSample2Start = kSample1Start + kSampleDuration;
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
auto sync_points = CreateSyncPoints({});
|
|
|
|
auto handler = std::make_shared<CueAlignmentHandler>(sync_points.get());
|
2018-05-22 21:24:50 +00:00
|
|
|
ASSERT_OK(SetUpAndInitializeGraph(handler, kOneInput, kOneOutput));
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kAudioStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample0Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample1Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample2Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(*Output(kAudioStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchAudioInfo(kAudioStream));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample0Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample1Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample2Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
ASSERT_OK(FlushAll({kAudioStream}));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CueAlignmentHandlerTest, TextInputWithNoCues) {
|
|
|
|
const size_t kTextStream = 0;
|
|
|
|
|
|
|
|
const int64_t kSampleDuration = 1000;
|
|
|
|
|
2018-03-26 18:04:09 +00:00
|
|
|
const int64_t kSample0Start = 0;
|
|
|
|
const int64_t kSample0End = kSample0Start + kSampleDuration;
|
|
|
|
const int64_t kSample1Start = kSample0End;
|
|
|
|
const int64_t kSample1End = kSample1Start + kSampleDuration;
|
|
|
|
const int64_t kSample2Start = kSample1End;
|
|
|
|
const int64_t kSample2End = kSample2Start + kSampleDuration;
|
2018-03-15 23:04:01 +00:00
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
auto sync_points = CreateSyncPoints({});
|
|
|
|
auto handler = std::make_shared<CueAlignmentHandler>(sync_points.get());
|
2018-05-22 21:24:50 +00:00
|
|
|
ASSERT_OK(SetUpAndInitializeGraph(handler, kOneInput, kOneOutput));
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
2020-08-24 22:23:15 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample0Start, kSample0End)));
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample1Start, kSample1End)));
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample2Start, kSample2End)));
|
2018-06-19 17:35:00 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchTextInfo(kTextStream));
|
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample0Start, kSample0End));
|
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample1Start, kSample1End));
|
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample2Start, kSample2End));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
ASSERT_OK(FlushAll({kTextStream}));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CueAlignmentHandlerTest, TextAudioVideoInputWithNoCues) {
|
|
|
|
const size_t kTextStream = 0;
|
|
|
|
const size_t kAudioStream = 1;
|
|
|
|
const size_t kVideoStream = 2;
|
|
|
|
|
2018-03-26 18:04:09 +00:00
|
|
|
const int64_t kSampleDuration = 1000;
|
2018-03-15 23:04:01 +00:00
|
|
|
|
2018-03-26 18:04:09 +00:00
|
|
|
const int64_t kSample0Start = 0;
|
|
|
|
const int64_t kSample0End = kSample0Start + kSampleDuration;
|
|
|
|
const int64_t kSample1Start = kSample0Start + kSampleDuration;
|
|
|
|
const int64_t kSample1End = kSample1Start + kSampleDuration;
|
|
|
|
const int64_t kSample2Start = kSample1Start + kSampleDuration;
|
|
|
|
const int64_t kSample2End = kSample2Start + kSampleDuration;
|
2018-03-15 23:04:01 +00:00
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
auto sync_points = CreateSyncPoints({});
|
|
|
|
auto handler = std::make_shared<CueAlignmentHandler>(sync_points.get());
|
|
|
|
ASSERT_OK(SetUpAndInitializeGraph(handler, kThreeInputs, kThreeOutputs));
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
2020-08-24 22:23:15 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample0Start, kSample0End)));
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample1Start, kSample1End)));
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample2Start, kSample2End)));
|
2018-06-19 17:35:00 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kAudioStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample0Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample1Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample2Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(*Output(kAudioStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kVideoStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample0Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample1Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample2Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(*Output(kVideoStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-01 21:40:01 +00:00
|
|
|
// Dispatch Stream Info
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchTextInfo(kTextStream));
|
|
|
|
ASSERT_OK(DispatchAudioInfo(kAudioStream));
|
|
|
|
ASSERT_OK(DispatchVideoInfo(kVideoStream));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
// Dispatch Sample 0
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample0Start, kSample0End));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample0Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample0Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
// Dispatch Sample 1
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample1Start, kSample1End));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample1Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample1Start, kSampleDuration,
|
|
|
|
!kKeyFrame));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
// Dispatch Sample 2
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample2Start, kSample2End));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample2Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample2Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
ASSERT_OK(FlushAll({kTextStream, kAudioStream, kVideoStream}));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CueAlignmentHandlerTest, VideoInputWithCues) {
|
|
|
|
const size_t kVideoStream = 0;
|
|
|
|
|
|
|
|
const int64_t kSampleDuration = 1000;
|
|
|
|
const int64_t kSample0Start = 0;
|
|
|
|
const int64_t kSample1Start = kSample0Start + kSampleDuration;
|
|
|
|
const int64_t kSample2Start = kSample1Start + kSampleDuration;
|
|
|
|
|
|
|
|
const double kSample2StartInSeconds =
|
|
|
|
static_cast<double>(kSample2Start) / kMsTimeScale;
|
|
|
|
|
|
|
|
// Put the cue between two key frames.
|
2018-06-19 20:23:39 +00:00
|
|
|
auto sync_points =
|
|
|
|
CreateSyncPoints({static_cast<double>(kSample1Start) / kMsTimeScale});
|
|
|
|
auto handler = std::make_shared<CueAlignmentHandler>(sync_points.get());
|
2018-05-22 21:24:50 +00:00
|
|
|
ASSERT_OK(SetUpAndInitializeGraph(handler, kOneInput, kOneOutput));
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kVideoStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample0Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample1Start, kSampleDuration, _, _)));
|
2018-03-15 23:04:01 +00:00
|
|
|
EXPECT_CALL(*Output(kVideoStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsCueEvent(_, kSample2StartInSeconds)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample2Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(*Output(kVideoStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchVideoInfo(kVideoStream));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample0Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample1Start, kSampleDuration,
|
|
|
|
!kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample2Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
ASSERT_OK(FlushAll({kVideoStream}));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CueAlignmentHandlerTest, AudioInputWithCues) {
|
|
|
|
const size_t kAudioStream = 0;
|
|
|
|
|
|
|
|
const int64_t kSampleDuration = 1000;
|
|
|
|
const int64_t kSample0Start = 0;
|
|
|
|
const int64_t kSample1Start = kSample0Start + kSampleDuration;
|
|
|
|
const int64_t kSample2Start = kSample1Start + kSampleDuration;
|
|
|
|
|
|
|
|
const double kSample1StartInSeconds =
|
|
|
|
static_cast<double>(kSample1Start) / kMsTimeScale;
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
auto sync_points =
|
|
|
|
CreateSyncPoints({static_cast<double>(kSample1Start) / kMsTimeScale});
|
|
|
|
auto handler = std::make_shared<CueAlignmentHandler>(sync_points.get());
|
2018-05-22 21:24:50 +00:00
|
|
|
ASSERT_OK(SetUpAndInitializeGraph(handler, kOneInput, kOneOutput));
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kAudioStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample0Start, kSampleDuration, _, _)));
|
2018-03-15 23:04:01 +00:00
|
|
|
EXPECT_CALL(*Output(kAudioStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsCueEvent(_, kSample1StartInSeconds)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample1Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample2Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(*Output(kAudioStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchAudioInfo(kAudioStream));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample0Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample1Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample2Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
ASSERT_OK(FlushAll({kAudioStream}));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CueAlignmentHandlerTest, TextInputWithCues) {
|
|
|
|
const size_t kTextStream = 0;
|
|
|
|
|
|
|
|
const int64_t kSampleDuration = 1000;
|
|
|
|
|
2018-03-26 18:04:09 +00:00
|
|
|
const int64_t kSample0Start = 0;
|
|
|
|
const int64_t kSample0End = kSample0Start + kSampleDuration;
|
|
|
|
const int64_t kSample1Start = kSample0End;
|
|
|
|
const int64_t kSample1End = kSample1Start + kSampleDuration;
|
|
|
|
const int64_t kSample2Start = kSample1End;
|
|
|
|
const int64_t kSample2End = kSample2Start + kSampleDuration;
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
const double kSample1StartInSeconds =
|
|
|
|
static_cast<double>(kSample1Start) / kMsTimeScale;
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
auto sync_points =
|
|
|
|
CreateSyncPoints({static_cast<double>(kSample1Start) / kMsTimeScale});
|
|
|
|
auto handler = std::make_shared<CueAlignmentHandler>(sync_points.get());
|
2018-05-22 21:24:50 +00:00
|
|
|
ASSERT_OK(SetUpAndInitializeGraph(handler, kOneInput, kOneOutput));
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
2020-08-24 22:23:15 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample0Start, kSample0End)));
|
2018-03-15 23:04:01 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsCueEvent(_, kSample1StartInSeconds)));
|
2020-08-24 22:23:15 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample1Start, kSample1End)));
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample2Start, kSample2End)));
|
2018-06-19 17:35:00 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchTextInfo(kTextStream));
|
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample0Start, kSample0End));
|
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample1Start, kSample1End));
|
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample2Start, kSample2End));
|
2018-05-14 20:46:03 +00:00
|
|
|
|
|
|
|
ASSERT_OK(FlushAll({kTextStream}));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CueAlignmentHandlerTest, TextInputWithCueAfterLastStart) {
|
|
|
|
const size_t kTextStream = 0;
|
|
|
|
|
|
|
|
const int64_t kSampleDuration = 1000;
|
|
|
|
|
|
|
|
const int64_t kSample0Start = 0;
|
|
|
|
const int64_t kSample0End = kSample0Start + kSampleDuration;
|
|
|
|
const int64_t kSample1Start = kSample0End;
|
|
|
|
const int64_t kSample1End = kSample1Start + kSampleDuration;
|
|
|
|
const int64_t kSample2Start = kSample1End;
|
|
|
|
const int64_t kSample2End = kSample2Start + kSampleDuration;
|
|
|
|
|
2018-07-20 17:31:26 +00:00
|
|
|
// Put the cue 1 between the start and end of the last sample.
|
|
|
|
const double kCue1TimeInSeconds =
|
|
|
|
static_cast<double>(kSample2Start + kSample2End) / 2 / kMsTimeScale;
|
2018-05-14 20:46:03 +00:00
|
|
|
|
2018-07-20 17:31:26 +00:00
|
|
|
// Put the cue 2 after the end of the last sample.
|
|
|
|
const double kCue2TimeInSeconds =
|
|
|
|
static_cast<double>(kSample2End) / kMsTimeScale;
|
|
|
|
|
|
|
|
auto sync_points = CreateSyncPoints({kCue1TimeInSeconds, kCue2TimeInSeconds});
|
2018-06-19 20:23:39 +00:00
|
|
|
auto handler = std::make_shared<CueAlignmentHandler>(sync_points.get());
|
2018-05-22 21:24:50 +00:00
|
|
|
ASSERT_OK(SetUpAndInitializeGraph(handler, kOneInput, kOneOutput));
|
2018-05-14 20:46:03 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
2020-08-24 22:23:15 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample0Start, kSample0End)));
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample1Start, kSample1End)));
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample2Start, kSample2End)));
|
2018-07-20 17:31:26 +00:00
|
|
|
// Cue before the sample end is processed.
|
2018-05-14 20:46:03 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
2018-07-20 17:31:26 +00:00
|
|
|
OnProcess(IsCueEvent(_, kCue1TimeInSeconds)));
|
|
|
|
// Cue after the samples is ignored.
|
2018-06-19 17:35:00 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream), OnFlush(_));
|
2018-05-14 20:46:03 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchTextInfo(kTextStream));
|
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample0Start, kSample0End));
|
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample1Start, kSample1End));
|
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample2Start, kSample2End));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
ASSERT_OK(FlushAll({kTextStream}));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CueAlignmentHandlerTest, TextAudioVideoInputWithCues) {
|
|
|
|
const size_t kTextStream = 0;
|
|
|
|
const size_t kAudioStream = 1;
|
|
|
|
const size_t kVideoStream = 2;
|
|
|
|
|
|
|
|
const int64_t kSampleDuration = 1000;
|
|
|
|
|
|
|
|
const int64_t kSample0Start = 0;
|
2018-03-26 18:04:09 +00:00
|
|
|
const int64_t kSample0End = kSample0Start + kSampleDuration;
|
|
|
|
const int64_t kSample1Start = kSample0End;
|
|
|
|
const int64_t kSample1End = kSample1Start + kSampleDuration;
|
|
|
|
const int64_t kSample2Start = kSample1End;
|
|
|
|
const int64_t kSample2End = kSample2Start + kSampleDuration;
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
const double kSample2StartInSeconds =
|
|
|
|
static_cast<double>(kSample2Start) / kMsTimeScale;
|
|
|
|
|
|
|
|
// Put the cue between two key frames.
|
2018-06-19 20:23:39 +00:00
|
|
|
auto sync_points =
|
|
|
|
CreateSyncPoints({static_cast<double>(kSample1Start) / kMsTimeScale});
|
|
|
|
auto handler = std::make_shared<CueAlignmentHandler>(sync_points.get());
|
|
|
|
ASSERT_OK(SetUpAndInitializeGraph(handler, kThreeInputs, kThreeOutputs));
|
2018-03-15 23:04:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
2020-08-24 22:23:15 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample0Start, kSample0End)));
|
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample1Start, kSample1End)));
|
2018-03-15 23:04:01 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsCueEvent(_, kSample2StartInSeconds)));
|
2020-08-24 22:23:15 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream),
|
|
|
|
OnProcess(IsTextSample(_, _, kSample2Start, kSample2End)));
|
2018-06-19 17:35:00 +00:00
|
|
|
EXPECT_CALL(*Output(kTextStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kAudioStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample0Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample1Start, kSampleDuration, _, _)));
|
2018-03-15 23:04:01 +00:00
|
|
|
EXPECT_CALL(*Output(kAudioStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsCueEvent(_, kSample2StartInSeconds)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kAudioStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample2Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(*Output(kAudioStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
testing::InSequence s;
|
|
|
|
|
|
|
|
EXPECT_CALL(*Output(kVideoStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsStreamInfo(_, kMsTimeScale, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample0Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample1Start, kSampleDuration, _, _)));
|
2018-03-15 23:04:01 +00:00
|
|
|
EXPECT_CALL(*Output(kVideoStream),
|
2018-06-19 17:35:00 +00:00
|
|
|
OnProcess(IsCueEvent(_, kSample2StartInSeconds)));
|
|
|
|
EXPECT_CALL(
|
|
|
|
*Output(kVideoStream),
|
|
|
|
OnProcess(IsMediaSample(_, kSample2Start, kSampleDuration, _, _)));
|
|
|
|
EXPECT_CALL(*Output(kVideoStream), OnFlush(_));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-01 21:40:01 +00:00
|
|
|
// Dispatch Stream Info
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchTextInfo(kTextStream));
|
|
|
|
ASSERT_OK(DispatchAudioInfo(kAudioStream));
|
|
|
|
ASSERT_OK(DispatchVideoInfo(kVideoStream));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
// Dispatch Sample 0
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample0Start, kSample0End));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample0Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample0Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
// Dispatch Sample 1
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample1Start, kSample1End));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample1Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample1Start, kSampleDuration,
|
|
|
|
!kKeyFrame));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
// Dispatch Sample 2
|
2018-06-19 20:23:39 +00:00
|
|
|
ASSERT_OK(DispatchTextSample(kTextStream, kSample2Start, kSample2End));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kAudioStream, kSample2Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
|
|
|
ASSERT_OK(DispatchMediaSample(kVideoStream, kSample2Start, kSampleDuration,
|
|
|
|
kKeyFrame));
|
2018-05-01 21:40:01 +00:00
|
|
|
|
|
|
|
ASSERT_OK(FlushAll({kTextStream, kAudioStream, kVideoStream}));
|
2018-03-15 23:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(kqyang): Add more tests, in particular, multi-thread tests.
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
} // namespace shaka
|