Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: media/formats/mp2t/es_adapter_video_unittest.cc

Issue 364823008: Mpeg2TS - estimate duration for video frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add an video ES adapter unit test. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/formats/mp2t/es_adapter_video.cc ('k') | media/formats/mp2t/es_parser_h264.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/formats/mp2t/es_adapter_video_unittest.cc
diff --git a/media/formats/mp2t/es_adapter_video_unittest.cc b/media/formats/mp2t/es_adapter_video_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cfa0a9d81a45c8f5e69f6a55ec46248b115bddd0
--- /dev/null
+++ b/media/formats/mp2t/es_adapter_video_unittest.cc
@@ -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 <vector>
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/time/time.h"
+#include "media/base/stream_parser_buffer.h"
+#include "media/base/video_decoder_config.h"
+#include "media/formats/mp2t/es_adapter_video.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+namespace mp2t {
+
+namespace {
+
+VideoDecoderConfig CreateFakeVideoConfig() {
+ gfx::Size coded_size(320, 240);
+ gfx::Rect visible_rect(0, 0, 320, 240);
+ gfx::Size natural_size(320, 240);
+ return VideoDecoderConfig(
+ kCodecH264,
+ H264PROFILE_MAIN,
+ VideoFrame::I420,
+ coded_size,
+ visible_rect,
+ natural_size,
+ NULL, 0, false);
+}
+
+std::vector<scoped_refptr<StreamParserBuffer> >
wolenetz 2014/07/10 23:28:14 nit: use StreamParserBuffer::BufferQueue (a deque)
damienv1 2014/07/11 00:44:41 Done.
+GenerateFakeBuffers(const std::vector<base::TimeDelta>& frame_pts) {
+ uint8 dummy_buffer[] = {0, 0, 0, 0};
+
+ std::vector<scoped_refptr<StreamParserBuffer> > buffers(frame_pts.size());
+ for (size_t k = 0; k < frame_pts.size(); k++) {
+ buffers[k] = StreamParserBuffer::CopyFrom(
+ dummy_buffer, arraysize(dummy_buffer), true, DemuxerStream::VIDEO, 0);
+ buffers[k]->set_timestamp(frame_pts[k]);
+ }
+ return buffers;
+}
+
+std::vector<base::TimeDelta> ConvertToTimeDelta(
+ const int* timestamp_in_ms, size_t size) {
wolenetz 2014/07/10 23:28:13 nit: |size| could be misinterpreted as # of bytes
wolenetz 2014/07/10 23:28:14 nit: move to previous line and wrap after 1st para
damienv1 2014/07/11 00:44:42 Done.
damienv1 2014/07/11 00:44:42 Done.
+ std::vector<base::TimeDelta> timestamp(size);
+ for (size_t k = 0; k < size; k++)
+ timestamp[k] = base::TimeDelta::FromMilliseconds(timestamp_in_ms[k]);
+ return timestamp;
+}
+
+}
+
+class EsAdapterVideoTest : public testing::Test {
+ public:
+ EsAdapterVideoTest();
+ virtual ~EsAdapterVideoTest() {}
+
+ protected:
+ // Given a set of input pts |pts_ms|, make sure
+ // the ES adapter computes the expected durations |duration_ms|.
+ void RunDurationTest(const int* pts_ms,
+ const int* duration_ms,
+ size_t size);
+
+ private:
+ void OnNewConfig(const VideoDecoderConfig& video_config);
+ void OnNewBuffer(scoped_refptr<StreamParserBuffer> buffer);
+
+ EsAdapterVideo es_adapter_;
+
+ size_t buffer_count_;
+ std::vector<base::TimeDelta> expected_frame_duration_;
+
+ DISALLOW_COPY_AND_ASSIGN(EsAdapterVideoTest);
+};
+
+EsAdapterVideoTest::EsAdapterVideoTest()
+ : es_adapter_(base::Bind(&EsAdapterVideoTest::OnNewConfig,
+ base::Unretained(this)),
+ base::Bind(&EsAdapterVideoTest::OnNewBuffer,
+ base::Unretained(this))),
+ buffer_count_(0) {
+}
+
+void EsAdapterVideoTest::OnNewConfig(const VideoDecoderConfig& video_config) {
+}
+
+void EsAdapterVideoTest::OnNewBuffer(
+ scoped_refptr<StreamParserBuffer> buffer) {
+ ASSERT_LT(buffer_count_, expected_frame_duration_.size());
+ EXPECT_EQ(expected_frame_duration_[buffer_count_], buffer->duration());
scherkus (not reviewing) 2014/07/10 23:13:58 suggestion for improving the maintainability of th
damienv1 2014/07/11 00:44:42 Pretty convenient indeed. Thanks for the suggestio
+ buffer_count_++;
+}
+
wolenetz 2014/07/10 23:28:13 Thanks for adding test coverage - I would like to
damienv1 2014/07/11 00:44:42 Done.
+void EsAdapterVideoTest::RunDurationTest(
+ const int* pts_ms,
+ const int* duration_ms,
+ size_t size) {
+ std::vector<base::TimeDelta> frame_pts(ConvertToTimeDelta(pts_ms, size));
+ expected_frame_duration_ = ConvertToTimeDelta(duration_ms, size);
+
+ // Generate fake buffers with the given PTS.
+ std::vector<scoped_refptr<StreamParserBuffer> > fake_buffers(
+ GenerateFakeBuffers(frame_pts));
+
+ es_adapter_.OnConfigChanged(CreateFakeVideoConfig());
+ for (size_t k = 0; k < fake_buffers.size(); k++)
+ es_adapter_.OnNewBuffer(fake_buffers[k]);
+ es_adapter_.Flush();
+}
+
+TEST_F(EsAdapterVideoTest, FrameDurationSimpleGop) {
+ // PTS for a GOP without B frames - strictly increasing.
+ int pts_ms[] = {30, 31, 33, 36, 40, 45, 51, 58};
+ int duration_ms[] = {1, 2, 3, 4, 5, 6, 7, 7};
+
+ RunDurationTest(pts_ms, duration_ms, arraysize(pts_ms));
+}
+
+TEST_F(EsAdapterVideoTest, FrameDurationComplexGop) {
+ // PTS for a GOP with B frames.
+ int pts_ms[] = {30, 120, 60, 90, 210, 150, 180, 300, 240, 270};
+ int duration_ms[] = {30, 30, 30, 30, 30, 30, 30, 30, 30, 30};
+
+ RunDurationTest(pts_ms, duration_ms, arraysize(pts_ms));
+}
+
+} // namespace mp2t
+} // namespace media
« no previous file with comments | « media/formats/mp2t/es_adapter_video.cc ('k') | media/formats/mp2t/es_parser_h264.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698