Unit test for WVM clear input.
Change-Id: I7261e927238682ac73bb564366c5e7a731b439d7
This commit is contained in:
parent
e4e2dafa52
commit
972ec11bea
|
@ -24,24 +24,23 @@
|
|||
],
|
||||
'dependencies': [
|
||||
'../../base/media_base.gyp:base',
|
||||
'../../filters/filters.gyp:filters',
|
||||
'../../formats/mp2t/mp2t.gyp:mp2t',
|
||||
'../mpeg/mpeg.gyp:mpeg',
|
||||
],
|
||||
},
|
||||
# {
|
||||
# 'target_name': 'wvm_unittest',
|
||||
# 'type': '<(gtest_target_type)',
|
||||
# 'sources': [
|
||||
# 'adts_header_unittest.cc',
|
||||
# 'es_parser_h264_unittest.cc',
|
||||
# 'wvm_media_parser_unittest.cc',
|
||||
# ],
|
||||
# 'dependencies': [
|
||||
# '../../../testing/gtest.gyp:gtest',
|
||||
# '../../../testing/gmock.gyp:gmock',
|
||||
# '../../filters/filters.gyp:filters',
|
||||
# '../../test/media_test.gyp:media_test_support',
|
||||
# '../mpeg/mpeg.gyp:mpeg',
|
||||
# 'wvm',
|
||||
# ]
|
||||
# },
|
||||
{
|
||||
'target_name': 'wvm_unittest',
|
||||
'type': '<(gtest_target_type)',
|
||||
'sources': [
|
||||
'wvm_media_parser_unittest.cc',
|
||||
],
|
||||
'dependencies': [
|
||||
'../../../testing/gtest.gyp:gtest',
|
||||
'../../../testing/gmock.gyp:gmock',
|
||||
'../../test/media_test.gyp:media_test_support',
|
||||
'wvm',
|
||||
]
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#define MEDIA_FORMATS_WVM_WVM_MEDIA_PARSER_H_
|
||||
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
// Copyright 2014 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.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/bind_helpers.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "media/base/media_sample.h"
|
||||
#include "media/base/stream_info.h"
|
||||
#include "media/base/timestamp.h"
|
||||
#include "media/base/video_stream_info.h"
|
||||
#include "media/formats/wvm/wvm_media_parser.h"
|
||||
#include "media/test/test_data_util.h"
|
||||
|
||||
namespace {
|
||||
const char kClearWvmFile[] = "hb2_4stream_clear.wvm";
|
||||
// Constants associated with kClearWvmFile follows.
|
||||
const uint32 kExpectedStreams = 4;
|
||||
const int kExpectedVideoFrameCount = 6665;
|
||||
const int kExpectedAudioFrameCount = 11964;
|
||||
}
|
||||
|
||||
namespace media {
|
||||
namespace wvm {
|
||||
|
||||
class WvmMediaParserTest : public testing::Test {
|
||||
public:
|
||||
WvmMediaParserTest()
|
||||
: audio_frame_count_(0),
|
||||
video_frame_count_(0),
|
||||
video_max_dts_(kNoTimestamp),
|
||||
current_track_id_(-1) {
|
||||
parser_.reset(new WvmMediaParser());
|
||||
}
|
||||
|
||||
protected:
|
||||
typedef std::map<int, scoped_refptr<StreamInfo> > StreamMap;
|
||||
|
||||
scoped_ptr<WvmMediaParser> parser_;
|
||||
StreamMap stream_map_;
|
||||
int audio_frame_count_;
|
||||
int video_frame_count_;
|
||||
int64 video_max_dts_;
|
||||
uint32 current_track_id_;
|
||||
|
||||
void OnInit(const std::vector<scoped_refptr<StreamInfo> >& stream_infos) {
|
||||
DVLOG(1) << "OnInit: " << stream_infos.size() << " streams.";
|
||||
for (std::vector<scoped_refptr<StreamInfo> >::const_iterator iter =
|
||||
stream_infos.begin(); iter != stream_infos.end(); ++iter) {
|
||||
DVLOG(1) << (*iter)->ToString();
|
||||
stream_map_[(*iter)->track_id()] = *iter;
|
||||
}
|
||||
}
|
||||
|
||||
bool OnNewSample(uint32 track_id, const scoped_refptr<MediaSample>& sample) {
|
||||
std::string stream_type;
|
||||
if (track_id != current_track_id_) {
|
||||
// onto next track.
|
||||
video_max_dts_ = kNoTimestamp;
|
||||
current_track_id_ = track_id;
|
||||
}
|
||||
StreamMap::const_iterator stream = stream_map_.find(track_id);
|
||||
if (stream != stream_map_.end()) {
|
||||
if (stream->second->stream_type() == kStreamAudio) {
|
||||
++audio_frame_count_;
|
||||
stream_type = "audio";
|
||||
} else if (stream->second->stream_type() == kStreamVideo) {
|
||||
++video_frame_count_;
|
||||
stream_type = "video";
|
||||
// Verify timestamps are increasing.
|
||||
if (video_max_dts_ == kNoTimestamp) {
|
||||
video_max_dts_ = sample->dts();
|
||||
} else if (video_max_dts_ >= sample->dts()) {
|
||||
LOG(ERROR) << "Video DTS not strictly increasing for track = "
|
||||
<< track_id << ", video max dts = "
|
||||
<< video_max_dts_ << ", sample dts = "
|
||||
<< sample->dts();
|
||||
return false;
|
||||
}
|
||||
video_max_dts_ = sample->dts();
|
||||
} else {
|
||||
LOG(ERROR) << "Missing StreamInfo for track ID " << track_id;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InitializeParser() {
|
||||
parser_->Init(
|
||||
base::Bind(&WvmMediaParserTest::OnInit,
|
||||
base::Unretained(this)),
|
||||
base::Bind(&WvmMediaParserTest::OnNewSample,
|
||||
base::Unretained(this)),
|
||||
NULL);
|
||||
}
|
||||
|
||||
void Parse(const std::string& filename) {
|
||||
InitializeParser();
|
||||
|
||||
std::vector<uint8> buffer = ReadTestDataFile(filename);
|
||||
EXPECT_TRUE(parser_->Parse(buffer.data(), buffer.size()));
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(WvmMediaParserTest, ParseClear) {
|
||||
Parse(kClearWvmFile);
|
||||
}
|
||||
|
||||
TEST_F(WvmMediaParserTest, StreamCount) {
|
||||
Parse(kClearWvmFile);
|
||||
EXPECT_EQ(kExpectedStreams, stream_map_.size());
|
||||
}
|
||||
|
||||
TEST_F(WvmMediaParserTest, VideoFrameCount) {
|
||||
Parse(kClearWvmFile);
|
||||
EXPECT_EQ(kExpectedVideoFrameCount, video_frame_count_);
|
||||
}
|
||||
|
||||
TEST_F(WvmMediaParserTest, AudioFrameCount) {
|
||||
Parse(kClearWvmFile);
|
||||
EXPECT_EQ(kExpectedAudioFrameCount, audio_frame_count_);
|
||||
}
|
||||
|
||||
} // namespace wvm
|
||||
} // namespace media
|
Binary file not shown.
Loading…
Reference in New Issue