Separate MediaHandlerTestBase From FakeMediaHandler
To allow more tests to use the MediaHandlerTestBase and get access to the helpful creation methods, this change moves the use of FakeMediaHandler and setting up the graph to a sub class. Change-Id: I90dd151e3c96d8fbe4bd02a1d6b11e66a279d95b
This commit is contained in:
parent
df6878ee6d
commit
31bf6dab59
|
@ -68,7 +68,8 @@ Status FakeInputMediaHandler::InitializeInternal() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Status FakeInputMediaHandler::Process(std::unique_ptr<StreamData> stream_data) {
|
Status FakeInputMediaHandler::Process(std::unique_ptr<StreamData> stream_data) {
|
||||||
return Status::OK;
|
return Status(error::INTERNAL_ERROR,
|
||||||
|
"FakeInputMediaHandler should never be a downstream handler.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Status MockOutputMediaHandler::InitializeInternal() {
|
Status MockOutputMediaHandler::InitializeInternal() {
|
||||||
|
@ -103,10 +104,6 @@ bool FakeMediaHandler::ValidateOutputStreamIndex(size_t stream_index) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaHandlerTestBase::MediaHandlerTestBase()
|
|
||||||
: next_handler_(new FakeMediaHandler),
|
|
||||||
some_handler_(new FakeMediaHandler) {}
|
|
||||||
|
|
||||||
bool MediaHandlerTestBase::IsVideoCodec(Codec codec) const {
|
bool MediaHandlerTestBase::IsVideoCodec(Codec codec) const {
|
||||||
return codec >= kCodecVideo && codec < kCodecVideoMaxPlusOne;
|
return codec >= kCodecVideo && codec < kCodecVideoMaxPlusOne;
|
||||||
}
|
}
|
||||||
|
@ -189,7 +186,11 @@ std::unique_ptr<SegmentInfo> MediaHandlerTestBase::GetSegmentInfo(
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaHandlerTestBase::SetUpGraph(size_t num_inputs,
|
MediaHandlerGraphTestBase::MediaHandlerGraphTestBase()
|
||||||
|
: next_handler_(new FakeMediaHandler),
|
||||||
|
some_handler_(new FakeMediaHandler) {}
|
||||||
|
|
||||||
|
void MediaHandlerGraphTestBase::SetUpGraph(size_t num_inputs,
|
||||||
size_t num_outputs,
|
size_t num_outputs,
|
||||||
std::shared_ptr<MediaHandler> handler) {
|
std::shared_ptr<MediaHandler> handler) {
|
||||||
// Input handler is not really used anywhere but just to satisfy one input
|
// Input handler is not really used anywhere but just to satisfy one input
|
||||||
|
@ -203,11 +204,11 @@ void MediaHandlerTestBase::SetUpGraph(size_t num_inputs,
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::unique_ptr<StreamData>>&
|
const std::vector<std::unique_ptr<StreamData>>&
|
||||||
MediaHandlerTestBase::GetOutputStreamDataVector() const {
|
MediaHandlerGraphTestBase::GetOutputStreamDataVector() const {
|
||||||
return next_handler_->stream_data_vector();
|
return next_handler_->stream_data_vector();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaHandlerTestBase::ClearOutputStreamDataVector() {
|
void MediaHandlerGraphTestBase::ClearOutputStreamDataVector() {
|
||||||
next_handler_->clear_stream_data_vector();
|
next_handler_->clear_stream_data_vector();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,8 @@ class MockOutputMediaHandler : public MediaHandler {
|
||||||
Status OnFlushRequest(size_t index) override;
|
Status OnFlushRequest(size_t index) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// A fake media handler definition used for testing.
|
// TODO(vaage) : Remove this test handler and convert other tests to use
|
||||||
|
// FakeInputMediaHandler and MockOutputMediaHandler.
|
||||||
class FakeMediaHandler : public MediaHandler {
|
class FakeMediaHandler : public MediaHandler {
|
||||||
public:
|
public:
|
||||||
const std::vector<std::unique_ptr<StreamData>>& stream_data_vector() const {
|
const std::vector<std::unique_ptr<StreamData>>& stream_data_vector() const {
|
||||||
|
@ -116,49 +117,54 @@ class FakeMediaHandler : public MediaHandler {
|
||||||
|
|
||||||
class MediaHandlerTestBase : public ::testing::Test {
|
class MediaHandlerTestBase : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
MediaHandlerTestBase();
|
MediaHandlerTestBase() = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
bool IsVideoCodec(Codec codec) const;
|
bool IsVideoCodec(Codec codec) const;
|
||||||
|
|
||||||
std::unique_ptr<StreamInfo> GetVideoStreamInfo(
|
std::unique_ptr<StreamInfo> GetVideoStreamInfo(uint32_t time_scale) const;
|
||||||
uint32_t time_scale) const;
|
|
||||||
|
|
||||||
std::unique_ptr<StreamInfo> GetVideoStreamInfo(
|
std::unique_ptr<StreamInfo> GetVideoStreamInfo(uint32_t time_scale,
|
||||||
uint32_t time_scale, uint32_t width, uint64_t height) const;
|
uint32_t width,
|
||||||
|
uint64_t height) const;
|
||||||
|
|
||||||
std::unique_ptr<StreamInfo> GetVideoStreamInfo(
|
std::unique_ptr<StreamInfo> GetVideoStreamInfo(uint32_t time_scale,
|
||||||
uint32_t time_scale, Codec codec) const;
|
Codec codec) const;
|
||||||
|
|
||||||
std::unique_ptr<StreamInfo> GetVideoStreamInfo(
|
std::unique_ptr<StreamInfo> GetVideoStreamInfo(uint32_t time_scale,
|
||||||
uint32_t time_scale,
|
|
||||||
Codec codec,
|
Codec codec,
|
||||||
uint32_t width,
|
uint32_t width,
|
||||||
uint64_t height) const;
|
uint64_t height) const;
|
||||||
|
|
||||||
std::unique_ptr<StreamInfo> GetAudioStreamInfo(
|
std::unique_ptr<StreamInfo> GetAudioStreamInfo(uint32_t time_scale) const;
|
||||||
uint32_t time_scale) const;
|
|
||||||
|
|
||||||
std::unique_ptr<StreamInfo> GetAudioStreamInfo(
|
std::unique_ptr<StreamInfo> GetAudioStreamInfo(uint32_t time_scale,
|
||||||
uint32_t time_scale,
|
|
||||||
Codec codec) const;
|
Codec codec) const;
|
||||||
|
|
||||||
std::unique_ptr<MediaSample> GetMediaSample(
|
std::unique_ptr<MediaSample> GetMediaSample(int64_t timestamp,
|
||||||
int64_t timestamp,
|
|
||||||
int64_t duration,
|
int64_t duration,
|
||||||
bool is_keyframe) const;
|
bool is_keyframe) const;
|
||||||
|
|
||||||
std::unique_ptr<MediaSample> GetMediaSample(
|
std::unique_ptr<MediaSample> GetMediaSample(int64_t timestamp,
|
||||||
int64_t timestamp,
|
|
||||||
int64_t duration,
|
int64_t duration,
|
||||||
bool is_keyframe,
|
bool is_keyframe,
|
||||||
const uint8_t* data,
|
const uint8_t* data,
|
||||||
size_t data_length) const;
|
size_t data_length) const;
|
||||||
|
|
||||||
std::unique_ptr<SegmentInfo> GetSegmentInfo(
|
std::unique_ptr<SegmentInfo> GetSegmentInfo(int64_t start_timestamp,
|
||||||
int64_t start_timestamp,
|
|
||||||
int64_t duration,
|
int64_t duration,
|
||||||
bool is_subsegment) const;
|
bool is_subsegment) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
MediaHandlerTestBase(const MediaHandlerTestBase&) = delete;
|
||||||
|
MediaHandlerTestBase& operator=(const MediaHandlerTestBase&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MediaHandlerGraphTestBase : public MediaHandlerTestBase {
|
||||||
|
public:
|
||||||
|
MediaHandlerGraphTestBase();
|
||||||
|
|
||||||
|
protected:
|
||||||
/// Setup a graph using |handler| with |num_inputs| and |num_outputs|.
|
/// Setup a graph using |handler| with |num_inputs| and |num_outputs|.
|
||||||
void SetUpGraph(size_t num_inputs,
|
void SetUpGraph(size_t num_inputs,
|
||||||
size_t num_outputs,
|
size_t num_outputs,
|
||||||
|
@ -178,8 +184,8 @@ class MediaHandlerTestBase : public ::testing::Test {
|
||||||
std::shared_ptr<FakeMediaHandler> next_handler() { return next_handler_; }
|
std::shared_ptr<FakeMediaHandler> next_handler() { return next_handler_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MediaHandlerTestBase(const MediaHandlerTestBase&) = delete;
|
MediaHandlerGraphTestBase(const MediaHandlerTestBase&) = delete;
|
||||||
MediaHandlerTestBase& operator=(const MediaHandlerTestBase&) = delete;
|
MediaHandlerGraphTestBase& operator=(const MediaHandlerTestBase&) = delete;
|
||||||
|
|
||||||
// Downstream handler used in testing graph.
|
// Downstream handler used in testing graph.
|
||||||
std::shared_ptr<FakeMediaHandler> next_handler_;
|
std::shared_ptr<FakeMediaHandler> next_handler_;
|
||||||
|
|
|
@ -30,7 +30,7 @@ const bool kEncrypted = true;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class ChunkingHandlerTest : public MediaHandlerTestBase {
|
class ChunkingHandlerTest : public MediaHandlerGraphTestBase {
|
||||||
public:
|
public:
|
||||||
void SetUpChunkingHandler(int num_inputs,
|
void SetUpChunkingHandler(int num_inputs,
|
||||||
const ChunkingParams& chunking_params) {
|
const ChunkingParams& chunking_params) {
|
||||||
|
|
|
@ -81,7 +81,7 @@ class MockVideoSliceHeaderParser : public VideoSliceHeaderParser {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class EncryptionHandlerTest : public MediaHandlerTestBase {
|
class EncryptionHandlerTest : public MediaHandlerGraphTestBase {
|
||||||
public:
|
public:
|
||||||
void SetUp() override { SetUpEncryptionHandler(EncryptionParams()); }
|
void SetUp() override { SetUpEncryptionHandler(EncryptionParams()); }
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ class MockKeySource : public FixedKeySource {
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class DemuxerTest : public MediaHandlerTestBase {
|
class DemuxerTest : public MediaHandlerGraphTestBase {
|
||||||
protected:
|
protected:
|
||||||
EncryptionKey GetMockEncryptionKey() {
|
EncryptionKey GetMockEncryptionKey() {
|
||||||
const uint8_t kKeyId[]{
|
const uint8_t kKeyId[]{
|
||||||
|
|
|
@ -55,7 +55,7 @@ MATCHER_P3(IsKeyFrameMediaSample, stream_index, timestamp, duration, "") {
|
||||||
arg->media_sample->is_key_frame() == true;
|
arg->media_sample->is_key_frame() == true;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TrickPlayHandlerTest : public MediaHandlerTestBase {
|
class TrickPlayHandlerTest : public MediaHandlerGraphTestBase {
|
||||||
public:
|
public:
|
||||||
void SetUpTrickPlayHandler(const std::vector<uint32_t>& trick_play_factors) {
|
void SetUpTrickPlayHandler(const std::vector<uint32_t>& trick_play_factors) {
|
||||||
trick_play_handler_.reset(new TrickPlayHandler());
|
trick_play_handler_.reset(new TrickPlayHandler());
|
||||||
|
|
Loading…
Reference in New Issue