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

Unified Diff: media/mp4/mp4_stream_parser_unittest.cc

Issue 10536014: Implement ISO BMFF support in Media Source. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: A thorough sign-ification Created 8 years, 6 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/mp4/mp4_stream_parser_unittest.cc
diff --git a/media/mp4/mp4_stream_parser_unittest.cc b/media/mp4/mp4_stream_parser_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..278f6bf59df16d9545b1a561109d23a521d2874a
--- /dev/null
+++ b/media/mp4/mp4_stream_parser_unittest.cc
@@ -0,0 +1,138 @@
+// Copyright (c) 2012 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/memory/ref_counted.h"
+#include "base/move.h"
+#include "base/time.h"
+#include "base/logging.h"
acolwell GONE FROM CHROMIUM 2012/06/08 16:10:38 lint nit: alphabetical order.
strobe_ 2012/06/11 18:44:21 Done.
+#include "media/base/audio_decoder_config.h"
+#include "media/base/decoder_buffer.h"
+#include "media/base/stream_parser_buffer.h"
+#include "media/base/video_decoder_config.h"
+#include "media/base/test_data_util.h"
acolwell GONE FROM CHROMIUM 2012/06/08 16:10:38 lint nit: alphabetical order.
strobe_ 2012/06/11 18:44:21 Done.
+#include "media/mp4/mp4_stream_parser.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using base::TimeDelta;
+
+namespace media {
+namespace mp4 {
+
+class MP4StreamParserTest : public testing::Test {
+ public:
+ MP4StreamParserTest() : parser_(new MP4StreamParser) {}
+
+ protected:
+ scoped_ptr<MP4StreamParser> parser_;
+
+ bool AppendData(const uint8* data, size_t length) {
+ parser_->Parse(data, length);
+ return true;
+ }
+
+ bool AppendDataInPieces(const uint8* data, size_t length) {
+ return AppendDataInPieces(data, length, 7);
+ }
+
+ 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();
+ return true;
+ }
+
+ bool NewBuffersF(const StreamParser::BufferQueue& bufs) {
+ DVLOG(2) << "NewBuffersF: " << bufs.size() << " buffers";
+ for (auto buf = bufs.begin(); buf != bufs.end(); buf++) {
+ DVLOG(3) << " n=" << buf - bufs.begin()
+ << ", size=" << (*buf)->GetDataSize()
+ << ", dur=" << (*buf)->GetDuration().InMilliseconds();
+ }
+ return true;
+ }
+
+ bool KeyNeededF(scoped_array<uint8> init_data, int init_data_size) {
+ DVLOG(1) << "KeyNeededF: " << init_data_size;
+ return true;
+ }
+
+ void InitializeParser() {
+ parser_->Init(
+ base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this)),
+ base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)),
+ base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)),
+ base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)),
+ base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)));
+ }
+
+ bool ParseMP4File(const std::string& filename,
+ const base::TimeDelta& duration) {
+ InitializeParser();
+
+ scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename);
+ EXPECT_TRUE(AppendDataInPieces(buffer->GetData(),
+ buffer->GetDataSize(),
+ 512));
+ return true;
+ }
+};
+
+TEST_F(MP4StreamParserTest, TestParseVideo) {
+ ParseMP4File("google_track1_dash.mp4",
+ base::TimeDelta::FromMilliseconds(0));
+}
+
+TEST_F(MP4StreamParserTest, TestParseAudio) {
+ ParseMP4File("google_track2_dash.mp4",
+ base::TimeDelta::FromMilliseconds(0));
+}
+
+// Avoid logspam while encryption is known to be broken
+/*
+TEST_F(MP4StreamParserTest, TestParseAudioCENC) {
+ ParseMP4File("dash_audio_cenc_gold.mp4",
+ base::TimeDelta::FromMilliseconds(0));
+}
+
+TEST_F(MP4StreamParserTest, TestParseVideoCENC) {
+ ParseMP4File("dash_video_cenc_gold.mp4",
+ base::TimeDelta::FromMilliseconds(0));
+}
+*/
+
+TEST_F(MP4StreamParserTest, TestParseAudioClear) {
+ ParseMP4File("dash_audio_clear.mp4",
+ base::TimeDelta::FromMilliseconds(0));
+}
+
+TEST_F(MP4StreamParserTest, TestParseVideoClear) {
+ ParseMP4File("dash_video_clear.mp4",
+ base::TimeDelta::FromMilliseconds(0));
+}
+
+} // namespace mp4
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698