OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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 <algorithm> | |
6 #include <string> | |
7 | |
8 #include "base/bind.h" | |
9 #include "base/bind_helpers.h" | |
10 #include "base/logging.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/time/time.h" | |
13 #include "media/base/audio_decoder_config.h" | |
14 #include "media/base/decoder_buffer.h" | |
15 #include "media/base/stream_parser_buffer.h" | |
16 #include "media/base/test_data_util.h" | |
17 #include "media/base/video_decoder_config.h" | |
18 #include "media/mp2t/mp2t_stream_parser.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | |
20 | |
21 namespace media { | |
22 namespace mp2t { | |
23 | |
24 class Mp2tStreamParserTest : public testing::Test { | |
25 public: | |
26 Mp2tStreamParserTest() | |
27 : configs_received_(false), | |
28 audio_frame_count_(0), | |
29 video_frame_count_(0), | |
30 video_min_dts_(kNoTimestamp()), | |
31 video_max_dts_(kNoTimestamp()) { | |
32 parser_.reset(new Mpeg2TsStreamParser()); | |
33 } | |
34 | |
35 protected: | |
36 scoped_ptr<Mpeg2TsStreamParser> parser_; | |
37 bool configs_received_; | |
38 int audio_frame_count_; | |
39 int video_frame_count_; | |
40 base::TimeDelta video_min_dts_; | |
41 base::TimeDelta video_max_dts_; | |
42 | |
43 bool AppendData(const uint8* data, size_t length) { | |
44 return parser_->Parse(data, length); | |
45 } | |
46 | |
47 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { | |
48 const uint8* start = data; | |
49 const uint8* end = data + length; | |
50 while (start < end) { | |
51 size_t append_size = std::min(piece_size, | |
52 static_cast<size_t>(end - start)); | |
53 if (!AppendData(start, append_size)) | |
54 return false; | |
55 start += append_size; | |
56 } | |
57 return true; | |
58 } | |
59 | |
60 void InitF(bool init_ok, base::TimeDelta duration) { | |
61 DVLOG(1) << "InitF: ok=" << init_ok | |
62 << ", dur=" << duration.InMilliseconds(); | |
63 } | |
64 | |
65 bool NewConfigF(const AudioDecoderConfig& ac, const VideoDecoderConfig& vc) { | |
66 DVLOG(1) << "NewConfigF: audio=" << ac.IsValidConfig() | |
67 << ", video=" << vc.IsValidConfig(); | |
68 configs_received_ = true; | |
acolwell GONE FROM CHROMIUM
2013/09/16 06:19:30
nit: You don't appear to check the value of this a
damienv1
2013/09/17 02:58:22
Removed.
| |
69 return true; | |
70 } | |
71 | |
72 | |
73 void DumpBuffers(const std::string& label, | |
74 const StreamParser::BufferQueue& buffers) { | |
75 DVLOG(2) << "DumpBuffers: " << label << " size " << buffers.size(); | |
76 for (StreamParser::BufferQueue::const_iterator buf = buffers.begin(); | |
77 buf != buffers.end(); buf++) { | |
78 DVLOG(3) << " n=" << buf - buffers.begin() | |
79 << ", size=" << (*buf)->data_size() | |
80 << ", dur=" << (*buf)->duration().InMilliseconds(); | |
81 } | |
82 } | |
83 | |
84 bool NewBuffersF(const StreamParser::BufferQueue& audio_buffers, | |
85 const StreamParser::BufferQueue& video_buffers) { | |
86 DumpBuffers("audio_buffers", audio_buffers); | |
87 DumpBuffers("video_buffers", video_buffers); | |
88 audio_frame_count_ += audio_buffers.size(); | |
89 video_frame_count_ += video_buffers.size(); | |
90 for (StreamParser::BufferQueue::const_iterator it = video_buffers.begin(); | |
91 it != video_buffers.end(); ++it) { | |
92 base::TimeDelta dts = (*it)->GetDecodeTimestamp(); | |
93 if (video_min_dts_ == kNoTimestamp() || | |
94 dts < video_min_dts_) | |
acolwell GONE FROM CHROMIUM
2013/09/16 06:19:30
nit: Add {} or move second condition to the line a
damienv1
2013/09/17 02:58:22
Done.
| |
95 video_min_dts_ = dts; | |
96 if (video_max_dts_ == kNoTimestamp() || | |
acolwell GONE FROM CHROMIUM
2013/09/16 06:19:30
ditto
damienv1
2013/09/17 02:58:22
Done.
| |
97 dts > video_max_dts_) | |
98 video_max_dts_ = dts; | |
99 } | |
acolwell GONE FROM CHROMIUM
2013/09/16 06:19:30
Shouldn't video_min_dts_ == video_buffers.front()-
damienv1
2013/09/17 02:58:22
Correct.
I modified the code.
| |
100 return true; | |
101 } | |
102 | |
103 bool NewTextBuffersF(TextTrack* text_track, | |
104 const StreamParser::BufferQueue& buffers) { | |
105 return true; | |
106 } | |
107 | |
108 void KeyNeededF(const std::string& type, | |
109 scoped_ptr<uint8[]> init_data, int init_data_size) { | |
110 DVLOG(1) << "KeyNeededF: " << init_data_size; | |
111 } | |
112 | |
113 scoped_ptr<TextTrack> AddTextTrackF( | |
114 TextKind kind, | |
115 const std::string& label, | |
116 const std::string& language) { | |
117 return scoped_ptr<TextTrack>(); | |
118 } | |
119 | |
120 void NewSegmentF() { | |
121 DVLOG(1) << "NewSegmentF"; | |
122 } | |
123 | |
124 void EndOfSegmentF() { | |
125 DVLOG(1) << "EndOfSegmentF()"; | |
126 } | |
127 | |
128 void InitializeParser() { | |
129 parser_->Init( | |
130 base::Bind(&Mp2tStreamParserTest::InitF, | |
131 base::Unretained(this)), | |
132 base::Bind(&Mp2tStreamParserTest::NewConfigF, | |
133 base::Unretained(this)), | |
134 base::Bind(&Mp2tStreamParserTest::NewBuffersF, | |
135 base::Unretained(this)), | |
136 base::Bind(&Mp2tStreamParserTest::NewTextBuffersF, | |
137 base::Unretained(this)), | |
138 base::Bind(&Mp2tStreamParserTest::KeyNeededF, | |
139 base::Unretained(this)), | |
140 base::Bind(&Mp2tStreamParserTest::AddTextTrackF, | |
141 base::Unretained(this)), | |
142 base::Bind(&Mp2tStreamParserTest::NewSegmentF, | |
143 base::Unretained(this)), | |
144 base::Bind(&Mp2tStreamParserTest::EndOfSegmentF, | |
145 base::Unretained(this)), | |
146 LogCB()); | |
147 } | |
148 | |
149 bool ParseMpeg2TsFile(const std::string& filename, int append_bytes) { | |
150 InitializeParser(); | |
151 | |
152 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); | |
153 EXPECT_TRUE(AppendDataInPieces(buffer->data(), | |
154 buffer->data_size(), | |
155 append_bytes)); | |
156 return true; | |
157 } | |
158 }; | |
159 | |
160 TEST_F(Mp2tStreamParserTest, UnalignedAppend) { | |
161 // Test small, non-segment-aligned appends. | |
162 ParseMpeg2TsFile("bear-1280x720.ts", 512); | |
163 EXPECT_EQ(video_frame_count_, 81); | |
164 parser_->Flush(); | |
165 EXPECT_EQ(video_frame_count_, 82); | |
166 } | |
167 | |
168 TEST_F(Mp2tStreamParserTest, TimestampWrapAround) { | |
169 // "bear-1280x720_ptswraparound.ts" has been transcoded | |
170 // from bear-1280x720.mp4 by applying a time offset of 95442s | |
171 // (close to 2^33 / 90000) which results in timestamps wrap around | |
172 // in the Mpeg2 TS stream. | |
173 ParseMpeg2TsFile("bear-1280x720_ptswraparound.ts", 512); | |
174 EXPECT_EQ(video_frame_count_, 81); | |
175 EXPECT_GE(video_min_dts_, base::TimeDelta::FromSeconds(95443 - 10)); | |
176 EXPECT_LE(video_max_dts_, base::TimeDelta::FromSeconds(95443 + 10)); | |
177 } | |
178 | |
179 } // namespace mp2t | |
180 } // namespace media | |
OLD | NEW |