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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <vector>
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/time/time.h"
10 #include "media/base/stream_parser_buffer.h"
11 #include "media/base/video_decoder_config.h"
12 #include "media/formats/mp2t/es_adapter_video.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace media {
16 namespace mp2t {
17
18 namespace {
19
20 VideoDecoderConfig CreateFakeVideoConfig() {
21 gfx::Size coded_size(320, 240);
22 gfx::Rect visible_rect(0, 0, 320, 240);
23 gfx::Size natural_size(320, 240);
24 return VideoDecoderConfig(
25 kCodecH264,
26 H264PROFILE_MAIN,
27 VideoFrame::I420,
28 coded_size,
29 visible_rect,
30 natural_size,
31 NULL, 0, false);
32 }
33
34 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.
35 GenerateFakeBuffers(const std::vector<base::TimeDelta>& frame_pts) {
36 uint8 dummy_buffer[] = {0, 0, 0, 0};
37
38 std::vector<scoped_refptr<StreamParserBuffer> > buffers(frame_pts.size());
39 for (size_t k = 0; k < frame_pts.size(); k++) {
40 buffers[k] = StreamParserBuffer::CopyFrom(
41 dummy_buffer, arraysize(dummy_buffer), true, DemuxerStream::VIDEO, 0);
42 buffers[k]->set_timestamp(frame_pts[k]);
43 }
44 return buffers;
45 }
46
47 std::vector<base::TimeDelta> ConvertToTimeDelta(
48 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.
49 std::vector<base::TimeDelta> timestamp(size);
50 for (size_t k = 0; k < size; k++)
51 timestamp[k] = base::TimeDelta::FromMilliseconds(timestamp_in_ms[k]);
52 return timestamp;
53 }
54
55 }
56
57 class EsAdapterVideoTest : public testing::Test {
58 public:
59 EsAdapterVideoTest();
60 virtual ~EsAdapterVideoTest() {}
61
62 protected:
63 // Given a set of input pts |pts_ms|, make sure
64 // the ES adapter computes the expected durations |duration_ms|.
65 void RunDurationTest(const int* pts_ms,
66 const int* duration_ms,
67 size_t size);
68
69 private:
70 void OnNewConfig(const VideoDecoderConfig& video_config);
71 void OnNewBuffer(scoped_refptr<StreamParserBuffer> buffer);
72
73 EsAdapterVideo es_adapter_;
74
75 size_t buffer_count_;
76 std::vector<base::TimeDelta> expected_frame_duration_;
77
78 DISALLOW_COPY_AND_ASSIGN(EsAdapterVideoTest);
79 };
80
81 EsAdapterVideoTest::EsAdapterVideoTest()
82 : es_adapter_(base::Bind(&EsAdapterVideoTest::OnNewConfig,
83 base::Unretained(this)),
84 base::Bind(&EsAdapterVideoTest::OnNewBuffer,
85 base::Unretained(this))),
86 buffer_count_(0) {
87 }
88
89 void EsAdapterVideoTest::OnNewConfig(const VideoDecoderConfig& video_config) {
90 }
91
92 void EsAdapterVideoTest::OnNewBuffer(
93 scoped_refptr<StreamParserBuffer> buffer) {
94 ASSERT_LT(buffer_count_, expected_frame_duration_.size());
95 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
96 buffer_count_++;
97 }
98
wolenetz 2014/07/10 23:28:13 Thanks for adding test coverage - I would like to
damienv1 2014/07/11 00:44:42 Done.
99 void EsAdapterVideoTest::RunDurationTest(
100 const int* pts_ms,
101 const int* duration_ms,
102 size_t size) {
103 std::vector<base::TimeDelta> frame_pts(ConvertToTimeDelta(pts_ms, size));
104 expected_frame_duration_ = ConvertToTimeDelta(duration_ms, size);
105
106 // Generate fake buffers with the given PTS.
107 std::vector<scoped_refptr<StreamParserBuffer> > fake_buffers(
108 GenerateFakeBuffers(frame_pts));
109
110 es_adapter_.OnConfigChanged(CreateFakeVideoConfig());
111 for (size_t k = 0; k < fake_buffers.size(); k++)
112 es_adapter_.OnNewBuffer(fake_buffers[k]);
113 es_adapter_.Flush();
114 }
115
116 TEST_F(EsAdapterVideoTest, FrameDurationSimpleGop) {
117 // PTS for a GOP without B frames - strictly increasing.
118 int pts_ms[] = {30, 31, 33, 36, 40, 45, 51, 58};
119 int duration_ms[] = {1, 2, 3, 4, 5, 6, 7, 7};
120
121 RunDurationTest(pts_ms, duration_ms, arraysize(pts_ms));
122 }
123
124 TEST_F(EsAdapterVideoTest, FrameDurationComplexGop) {
125 // PTS for a GOP with B frames.
126 int pts_ms[] = {30, 120, 60, 90, 210, 150, 180, 300, 240, 270};
127 int duration_ms[] = {30, 30, 30, 30, 30, 30, 30, 30, 30, 30};
128
129 RunDurationTest(pts_ms, duration_ms, arraysize(pts_ms));
130 }
131
132 } // namespace mp2t
133 } // namespace media
OLDNEW
« 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