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:
Aaron Vaage 2017-09-14 09:23:29 -07:00
parent df6878ee6d
commit 31bf6dab59
6 changed files with 53 additions and 46 deletions

View File

@ -68,7 +68,8 @@ Status FakeInputMediaHandler::InitializeInternal() {
}
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() {
@ -103,10 +104,6 @@ bool FakeMediaHandler::ValidateOutputStreamIndex(size_t stream_index) const {
return true;
}
MediaHandlerTestBase::MediaHandlerTestBase()
: next_handler_(new FakeMediaHandler),
some_handler_(new FakeMediaHandler) {}
bool MediaHandlerTestBase::IsVideoCodec(Codec codec) const {
return codec >= kCodecVideo && codec < kCodecVideoMaxPlusOne;
}
@ -189,7 +186,11 @@ std::unique_ptr<SegmentInfo> MediaHandlerTestBase::GetSegmentInfo(
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,
std::shared_ptr<MediaHandler> handler) {
// 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>>&
MediaHandlerTestBase::GetOutputStreamDataVector() const {
MediaHandlerGraphTestBase::GetOutputStreamDataVector() const {
return next_handler_->stream_data_vector();
}
void MediaHandlerTestBase::ClearOutputStreamDataVector() {
void MediaHandlerGraphTestBase::ClearOutputStreamDataVector() {
next_handler_->clear_stream_data_vector();
}

View File

@ -97,7 +97,8 @@ class MockOutputMediaHandler : public MediaHandler {
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 {
public:
const std::vector<std::unique_ptr<StreamData>>& stream_data_vector() const {
@ -116,49 +117,54 @@ class FakeMediaHandler : public MediaHandler {
class MediaHandlerTestBase : public ::testing::Test {
public:
MediaHandlerTestBase();
MediaHandlerTestBase() = default;
protected:
bool IsVideoCodec(Codec codec) const;
std::unique_ptr<StreamInfo> GetVideoStreamInfo(
uint32_t time_scale) const;
std::unique_ptr<StreamInfo> GetVideoStreamInfo(uint32_t time_scale) const;
std::unique_ptr<StreamInfo> GetVideoStreamInfo(
uint32_t time_scale, uint32_t width, uint64_t height) const;
std::unique_ptr<StreamInfo> GetVideoStreamInfo(uint32_t time_scale,
uint32_t width,
uint64_t height) const;
std::unique_ptr<StreamInfo> GetVideoStreamInfo(
uint32_t time_scale, Codec codec) const;
std::unique_ptr<StreamInfo> GetVideoStreamInfo(uint32_t time_scale,
Codec codec) const;
std::unique_ptr<StreamInfo> GetVideoStreamInfo(
uint32_t time_scale,
Codec codec,
uint32_t width,
uint64_t height) const;
std::unique_ptr<StreamInfo> GetVideoStreamInfo(uint32_t time_scale,
Codec codec,
uint32_t width,
uint64_t height) const;
std::unique_ptr<StreamInfo> GetAudioStreamInfo(
uint32_t time_scale) const;
std::unique_ptr<StreamInfo> GetAudioStreamInfo(uint32_t time_scale) const;
std::unique_ptr<StreamInfo> GetAudioStreamInfo(
uint32_t time_scale,
Codec codec) const;
std::unique_ptr<StreamInfo> GetAudioStreamInfo(uint32_t time_scale,
Codec codec) const;
std::unique_ptr<MediaSample> GetMediaSample(
int64_t timestamp,
int64_t duration,
bool is_keyframe) const;
std::unique_ptr<MediaSample> GetMediaSample(int64_t timestamp,
int64_t duration,
bool is_keyframe) const;
std::unique_ptr<MediaSample> GetMediaSample(
int64_t timestamp,
int64_t duration,
bool is_keyframe,
const uint8_t* data,
size_t data_length) const;
std::unique_ptr<MediaSample> GetMediaSample(int64_t timestamp,
int64_t duration,
bool is_keyframe,
const uint8_t* data,
size_t data_length) const;
std::unique_ptr<SegmentInfo> GetSegmentInfo(
int64_t start_timestamp,
int64_t duration,
bool is_subsegment) const;
std::unique_ptr<SegmentInfo> GetSegmentInfo(int64_t start_timestamp,
int64_t duration,
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|.
void SetUpGraph(size_t num_inputs,
size_t num_outputs,
@ -178,8 +184,8 @@ class MediaHandlerTestBase : public ::testing::Test {
std::shared_ptr<FakeMediaHandler> next_handler() { return next_handler_; }
private:
MediaHandlerTestBase(const MediaHandlerTestBase&) = delete;
MediaHandlerTestBase& operator=(const MediaHandlerTestBase&) = delete;
MediaHandlerGraphTestBase(const MediaHandlerTestBase&) = delete;
MediaHandlerGraphTestBase& operator=(const MediaHandlerTestBase&) = delete;
// Downstream handler used in testing graph.
std::shared_ptr<FakeMediaHandler> next_handler_;

View File

@ -30,7 +30,7 @@ const bool kEncrypted = true;
} // namespace
class ChunkingHandlerTest : public MediaHandlerTestBase {
class ChunkingHandlerTest : public MediaHandlerGraphTestBase {
public:
void SetUpChunkingHandler(int num_inputs,
const ChunkingParams& chunking_params) {

View File

@ -81,7 +81,7 @@ class MockVideoSliceHeaderParser : public VideoSliceHeaderParser {
} // namespace
class EncryptionHandlerTest : public MediaHandlerTestBase {
class EncryptionHandlerTest : public MediaHandlerGraphTestBase {
public:
void SetUp() override { SetUpEncryptionHandler(EncryptionParams()); }

View File

@ -29,7 +29,7 @@ class MockKeySource : public FixedKeySource {
};
} // namespace
class DemuxerTest : public MediaHandlerTestBase {
class DemuxerTest : public MediaHandlerGraphTestBase {
protected:
EncryptionKey GetMockEncryptionKey() {
const uint8_t kKeyId[]{

View File

@ -55,7 +55,7 @@ MATCHER_P3(IsKeyFrameMediaSample, stream_index, timestamp, duration, "") {
arg->media_sample->is_key_frame() == true;
}
class TrickPlayHandlerTest : public MediaHandlerTestBase {
class TrickPlayHandlerTest : public MediaHandlerGraphTestBase {
public:
void SetUpTrickPlayHandler(const std::vector<uint32_t>& trick_play_factors) {
trick_play_handler_.reset(new TrickPlayHandler());