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

Side by Side Diff: media/formats/mp2t/mp2t_stream_parser_unittest.cc

Issue 447963003: Introduce DecodeTimestamp class to make it easier to distiguish presentation and decode timestamps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 19 matching lines...) Expand all
30 30
31 StreamParser::BufferQueue::const_iterator it1 = buffers.begin(); 31 StreamParser::BufferQueue::const_iterator it1 = buffers.begin();
32 StreamParser::BufferQueue::const_iterator it2 = ++it1; 32 StreamParser::BufferQueue::const_iterator it2 = ++it1;
33 for ( ; it2 != buffers.end(); ++it1, ++it2) { 33 for ( ; it2 != buffers.end(); ++it1, ++it2) {
34 if ((*it2)->GetDecodeTimestamp() < (*it1)->GetDecodeTimestamp()) 34 if ((*it2)->GetDecodeTimestamp() < (*it1)->GetDecodeTimestamp())
35 return false; 35 return false;
36 } 36 }
37 return true; 37 return true;
38 } 38 }
39 39
40 bool IsAlmostEqual(base::TimeDelta t0, base::TimeDelta t1) { 40 bool IsAlmostEqual(DecodeTimestamp t0, DecodeTimestamp t1) {
41 base::TimeDelta kMaxDeviation = base::TimeDelta::FromMilliseconds(5); 41 base::TimeDelta kMaxDeviation = base::TimeDelta::FromMilliseconds(5);
42 base::TimeDelta diff = t1 - t0; 42 base::TimeDelta diff = t1 - t0;
43 return (diff >= -kMaxDeviation && diff <= kMaxDeviation); 43 return (diff >= -kMaxDeviation && diff <= kMaxDeviation);
44 } 44 }
45 45
46 } // namespace 46 } // namespace
47 47
48 class Mp2tStreamParserTest : public testing::Test { 48 class Mp2tStreamParserTest : public testing::Test {
49 public: 49 public:
50 Mp2tStreamParserTest() 50 Mp2tStreamParserTest()
51 : segment_count_(0), 51 : segment_count_(0),
52 config_count_(0), 52 config_count_(0),
53 audio_frame_count_(0), 53 audio_frame_count_(0),
54 video_frame_count_(0), 54 video_frame_count_(0),
55 audio_min_dts_(kNoTimestamp()), 55 audio_min_dts_(kNoDecodeTimestamp()),
56 audio_max_dts_(kNoTimestamp()), 56 audio_max_dts_(kNoDecodeTimestamp()),
57 video_min_dts_(kNoTimestamp()), 57 video_min_dts_(kNoDecodeTimestamp()),
58 video_max_dts_(kNoTimestamp()) { 58 video_max_dts_(kNoDecodeTimestamp()) {
59 bool has_sbr = false; 59 bool has_sbr = false;
60 parser_.reset(new Mp2tStreamParser(has_sbr)); 60 parser_.reset(new Mp2tStreamParser(has_sbr));
61 } 61 }
62 62
63 protected: 63 protected:
64 scoped_ptr<Mp2tStreamParser> parser_; 64 scoped_ptr<Mp2tStreamParser> parser_;
65 int segment_count_; 65 int segment_count_;
66 int config_count_; 66 int config_count_;
67 int audio_frame_count_; 67 int audio_frame_count_;
68 int video_frame_count_; 68 int video_frame_count_;
69 base::TimeDelta audio_min_dts_; 69 DecodeTimestamp audio_min_dts_;
70 base::TimeDelta audio_max_dts_; 70 DecodeTimestamp audio_max_dts_;
71 base::TimeDelta video_min_dts_; 71 DecodeTimestamp video_min_dts_;
72 base::TimeDelta video_max_dts_; 72 DecodeTimestamp video_max_dts_;
73 73
74 void ResetStats() { 74 void ResetStats() {
75 segment_count_ = 0; 75 segment_count_ = 0;
76 config_count_ = 0; 76 config_count_ = 0;
77 audio_frame_count_ = 0; 77 audio_frame_count_ = 0;
78 video_frame_count_ = 0; 78 video_frame_count_ = 0;
79 audio_min_dts_ = kNoTimestamp(); 79 audio_min_dts_ = kNoDecodeTimestamp();
80 audio_max_dts_ = kNoTimestamp(); 80 audio_max_dts_ = kNoDecodeTimestamp();
81 video_min_dts_ = kNoTimestamp(); 81 video_min_dts_ = kNoDecodeTimestamp();
82 video_max_dts_ = kNoTimestamp(); 82 video_max_dts_ = kNoDecodeTimestamp();
83 } 83 }
84 84
85 bool AppendData(const uint8* data, size_t length) { 85 bool AppendData(const uint8* data, size_t length) {
86 return parser_->Parse(data, length); 86 return parser_->Parse(data, length);
87 } 87 }
88 88
89 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { 89 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) {
90 const uint8* start = data; 90 const uint8* start = data;
91 const uint8* end = data + length; 91 const uint8* end = data + length;
92 while (start < end) { 92 while (start < end) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if (!text_map.empty()) 142 if (!text_map.empty())
143 return false; 143 return false;
144 144
145 // Verify monotonicity. 145 // Verify monotonicity.
146 if (!IsMonotonic(video_buffers)) 146 if (!IsMonotonic(video_buffers))
147 return false; 147 return false;
148 if (!IsMonotonic(audio_buffers)) 148 if (!IsMonotonic(audio_buffers))
149 return false; 149 return false;
150 150
151 if (!video_buffers.empty()) { 151 if (!video_buffers.empty()) {
152 base::TimeDelta first_dts = video_buffers.front()->GetDecodeTimestamp(); 152 DecodeTimestamp first_dts = video_buffers.front()->GetDecodeTimestamp();
153 base::TimeDelta last_dts = video_buffers.back()->GetDecodeTimestamp(); 153 DecodeTimestamp last_dts = video_buffers.back()->GetDecodeTimestamp();
154 if (video_max_dts_ != kNoTimestamp() && first_dts < video_max_dts_) 154 if (video_max_dts_ != kNoDecodeTimestamp() && first_dts < video_max_dts_)
155 return false; 155 return false;
156 if (video_min_dts_ == kNoTimestamp()) 156 if (video_min_dts_ == kNoDecodeTimestamp())
157 video_min_dts_ = first_dts; 157 video_min_dts_ = first_dts;
158 video_max_dts_ = last_dts; 158 video_max_dts_ = last_dts;
159 } 159 }
160 if (!audio_buffers.empty()) { 160 if (!audio_buffers.empty()) {
161 base::TimeDelta first_dts = audio_buffers.front()->GetDecodeTimestamp(); 161 DecodeTimestamp first_dts = audio_buffers.front()->GetDecodeTimestamp();
162 base::TimeDelta last_dts = audio_buffers.back()->GetDecodeTimestamp(); 162 DecodeTimestamp last_dts = audio_buffers.back()->GetDecodeTimestamp();
163 if (audio_max_dts_ != kNoTimestamp() && first_dts < audio_max_dts_) 163 if (audio_max_dts_ != kNoDecodeTimestamp() && first_dts < audio_max_dts_)
164 return false; 164 return false;
165 if (audio_min_dts_ == kNoTimestamp()) 165 if (audio_min_dts_ == kNoDecodeTimestamp())
166 audio_min_dts_ = first_dts; 166 audio_min_dts_ = first_dts;
167 audio_max_dts_ = last_dts; 167 audio_max_dts_ = last_dts;
168 } 168 }
169 169
170 audio_frame_count_ += audio_buffers.size(); 170 audio_frame_count_ += audio_buffers.size();
171 video_frame_count_ += video_buffers.size(); 171 video_frame_count_ += video_buffers.size();
172 return true; 172 return true;
173 } 173 }
174 174
175 void OnKeyNeeded(const std::string& type, 175 void OnKeyNeeded(const std::string& type,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // "bear-1280x720_ptswraparound.ts" has been transcoded 255 // "bear-1280x720_ptswraparound.ts" has been transcoded
256 // from bear-1280x720.mp4 by applying a time offset of 95442s 256 // from bear-1280x720.mp4 by applying a time offset of 95442s
257 // (close to 2^33 / 90000) which results in timestamps wrap around 257 // (close to 2^33 / 90000) which results in timestamps wrap around
258 // in the Mpeg2 TS stream. 258 // in the Mpeg2 TS stream.
259 InitializeParser(); 259 InitializeParser();
260 ParseMpeg2TsFile("bear-1280x720_ptswraparound.ts", 512); 260 ParseMpeg2TsFile("bear-1280x720_ptswraparound.ts", 512);
261 parser_->Flush(); 261 parser_->Flush();
262 EXPECT_EQ(video_frame_count_, 82); 262 EXPECT_EQ(video_frame_count_, 82);
263 263
264 EXPECT_TRUE(IsAlmostEqual(video_min_dts_, 264 EXPECT_TRUE(IsAlmostEqual(video_min_dts_,
265 base::TimeDelta::FromSecondsD(95443.376))); 265 DecodeTimestamp::FromSecondsD(95443.376)));
266 EXPECT_TRUE(IsAlmostEqual(video_max_dts_, 266 EXPECT_TRUE(IsAlmostEqual(video_max_dts_,
267 base::TimeDelta::FromSecondsD(95446.079))); 267 DecodeTimestamp::FromSecondsD(95446.079)));
268 268
269 // Note: for audio, AdtsStreamParser considers only the PTS (which is then 269 // Note: for audio, AdtsStreamParser considers only the PTS (which is then
270 // used as the DTS). 270 // used as the DTS).
271 // TODO(damienv): most of the time, audio streams just have PTS. Here, only 271 // TODO(damienv): most of the time, audio streams just have PTS. Here, only
272 // the first PES packet has a DTS, all the other PES packets have PTS only. 272 // the first PES packet has a DTS, all the other PES packets have PTS only.
273 // Reconsider the expected value for |audio_min_dts_| if DTS are used as part 273 // Reconsider the expected value for |audio_min_dts_| if DTS are used as part
274 // of the ADTS stream parser. 274 // of the ADTS stream parser.
275 // 275 //
276 // Note: the last pts for audio is 95445.931 but this PES packet includes 276 // Note: the last pts for audio is 95445.931 but this PES packet includes
277 // 9 ADTS frames with 1 AAC frame in each ADTS frame. 277 // 9 ADTS frames with 1 AAC frame in each ADTS frame.
278 // So the PTS of the last AAC frame is: 278 // So the PTS of the last AAC frame is:
279 // 95445.931 + 8 * (1024 / 44100) = 95446.117 279 // 95445.931 + 8 * (1024 / 44100) = 95446.117
280 EXPECT_TRUE(IsAlmostEqual(audio_min_dts_, 280 EXPECT_TRUE(IsAlmostEqual(audio_min_dts_,
281 base::TimeDelta::FromSecondsD(95443.400))); 281 DecodeTimestamp::FromSecondsD(95443.400)));
282 EXPECT_TRUE(IsAlmostEqual(audio_max_dts_, 282 EXPECT_TRUE(IsAlmostEqual(audio_max_dts_,
283 base::TimeDelta::FromSecondsD(95446.117))); 283 DecodeTimestamp::FromSecondsD(95446.117)));
284 } 284 }
285 285
286 } // namespace mp2t 286 } // namespace mp2t
287 } // namespace media 287 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698