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

Unified Diff: media/mp2t/mp2t_stream_parser_unittest.cc

Issue 23566013: Mpeg2 TS stream parser for media source. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup - address comments from patch set #8 Created 7 years, 3 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
Index: media/mp2t/mp2t_stream_parser_unittest.cc
diff --git a/media/mp2t/mp2t_stream_parser_unittest.cc b/media/mp2t/mp2t_stream_parser_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8aa41122b6e9658e72288d534c1cc6335b736556
--- /dev/null
+++ b/media/mp2t/mp2t_stream_parser_unittest.cc
@@ -0,0 +1,180 @@
+// Copyright (c) 2013 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 <algorithm>
+#include <string>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "base/time/time.h"
+#include "media/base/audio_decoder_config.h"
+#include "media/base/decoder_buffer.h"
+#include "media/base/stream_parser_buffer.h"
+#include "media/base/test_data_util.h"
+#include "media/base/video_decoder_config.h"
+#include "media/mp2t/mp2t_stream_parser.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+namespace mp2t {
+
+class Mp2tStreamParserTest : public testing::Test {
+ public:
+ Mp2tStreamParserTest()
+ : configs_received_(false),
+ audio_frame_count_(0),
+ video_frame_count_(0),
+ video_min_dts_(kNoTimestamp()),
+ video_max_dts_(kNoTimestamp()) {
+ parser_.reset(new Mpeg2TsStreamParser());
+ }
+
+ protected:
+ scoped_ptr<Mpeg2TsStreamParser> parser_;
+ bool configs_received_;
+ int audio_frame_count_;
+ int video_frame_count_;
+ base::TimeDelta video_min_dts_;
+ base::TimeDelta video_max_dts_;
+
+ bool AppendData(const uint8* data, size_t length) {
+ return parser_->Parse(data, length);
+ }
+
+ bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) {
+ const uint8* start = data;
+ const uint8* end = data + length;
+ while (start < end) {
+ size_t append_size = std::min(piece_size,
+ static_cast<size_t>(end - start));
+ if (!AppendData(start, append_size))
+ return false;
+ start += append_size;
+ }
+ return true;
+ }
+
+ void InitF(bool init_ok, base::TimeDelta duration) {
+ DVLOG(1) << "InitF: ok=" << init_ok
+ << ", dur=" << duration.InMilliseconds();
+ }
+
+ bool NewConfigF(const AudioDecoderConfig& ac, const VideoDecoderConfig& vc) {
+ DVLOG(1) << "NewConfigF: audio=" << ac.IsValidConfig()
+ << ", video=" << vc.IsValidConfig();
+ 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.
+ return true;
+ }
+
+
+ void DumpBuffers(const std::string& label,
+ const StreamParser::BufferQueue& buffers) {
+ DVLOG(2) << "DumpBuffers: " << label << " size " << buffers.size();
+ for (StreamParser::BufferQueue::const_iterator buf = buffers.begin();
+ buf != buffers.end(); buf++) {
+ DVLOG(3) << " n=" << buf - buffers.begin()
+ << ", size=" << (*buf)->data_size()
+ << ", dur=" << (*buf)->duration().InMilliseconds();
+ }
+ }
+
+ bool NewBuffersF(const StreamParser::BufferQueue& audio_buffers,
+ const StreamParser::BufferQueue& video_buffers) {
+ DumpBuffers("audio_buffers", audio_buffers);
+ DumpBuffers("video_buffers", video_buffers);
+ audio_frame_count_ += audio_buffers.size();
+ video_frame_count_ += video_buffers.size();
+ for (StreamParser::BufferQueue::const_iterator it = video_buffers.begin();
+ it != video_buffers.end(); ++it) {
+ base::TimeDelta dts = (*it)->GetDecodeTimestamp();
+ if (video_min_dts_ == kNoTimestamp() ||
+ 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.
+ video_min_dts_ = dts;
+ if (video_max_dts_ == kNoTimestamp() ||
acolwell GONE FROM CHROMIUM 2013/09/16 06:19:30 ditto
damienv1 2013/09/17 02:58:22 Done.
+ dts > video_max_dts_)
+ video_max_dts_ = dts;
+ }
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.
+ return true;
+ }
+
+ bool NewTextBuffersF(TextTrack* text_track,
+ const StreamParser::BufferQueue& buffers) {
+ return true;
+ }
+
+ void KeyNeededF(const std::string& type,
+ scoped_ptr<uint8[]> init_data, int init_data_size) {
+ DVLOG(1) << "KeyNeededF: " << init_data_size;
+ }
+
+ scoped_ptr<TextTrack> AddTextTrackF(
+ TextKind kind,
+ const std::string& label,
+ const std::string& language) {
+ return scoped_ptr<TextTrack>();
+ }
+
+ void NewSegmentF() {
+ DVLOG(1) << "NewSegmentF";
+ }
+
+ void EndOfSegmentF() {
+ DVLOG(1) << "EndOfSegmentF()";
+ }
+
+ void InitializeParser() {
+ parser_->Init(
+ base::Bind(&Mp2tStreamParserTest::InitF,
+ base::Unretained(this)),
+ base::Bind(&Mp2tStreamParserTest::NewConfigF,
+ base::Unretained(this)),
+ base::Bind(&Mp2tStreamParserTest::NewBuffersF,
+ base::Unretained(this)),
+ base::Bind(&Mp2tStreamParserTest::NewTextBuffersF,
+ base::Unretained(this)),
+ base::Bind(&Mp2tStreamParserTest::KeyNeededF,
+ base::Unretained(this)),
+ base::Bind(&Mp2tStreamParserTest::AddTextTrackF,
+ base::Unretained(this)),
+ base::Bind(&Mp2tStreamParserTest::NewSegmentF,
+ base::Unretained(this)),
+ base::Bind(&Mp2tStreamParserTest::EndOfSegmentF,
+ base::Unretained(this)),
+ LogCB());
+ }
+
+ bool ParseMpeg2TsFile(const std::string& filename, int append_bytes) {
+ InitializeParser();
+
+ scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename);
+ EXPECT_TRUE(AppendDataInPieces(buffer->data(),
+ buffer->data_size(),
+ append_bytes));
+ return true;
+ }
+};
+
+TEST_F(Mp2tStreamParserTest, UnalignedAppend) {
+ // Test small, non-segment-aligned appends.
+ ParseMpeg2TsFile("bear-1280x720.ts", 512);
+ EXPECT_EQ(video_frame_count_, 81);
+ parser_->Flush();
+ EXPECT_EQ(video_frame_count_, 82);
+}
+
+TEST_F(Mp2tStreamParserTest, TimestampWrapAround) {
+ // "bear-1280x720_ptswraparound.ts" has been transcoded
+ // from bear-1280x720.mp4 by applying a time offset of 95442s
+ // (close to 2^33 / 90000) which results in timestamps wrap around
+ // in the Mpeg2 TS stream.
+ ParseMpeg2TsFile("bear-1280x720_ptswraparound.ts", 512);
+ EXPECT_EQ(video_frame_count_, 81);
+ EXPECT_GE(video_min_dts_, base::TimeDelta::FromSeconds(95443 - 10));
+ EXPECT_LE(video_max_dts_, base::TimeDelta::FromSeconds(95443 + 10));
+}
+
+} // namespace mp2t
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698