| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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/move.h" |
| 13 #include "base/time.h" |
| 14 #include "media/base/audio_decoder_config.h" |
| 15 #include "media/base/decoder_buffer.h" |
| 16 #include "media/base/stream_parser_buffer.h" |
| 17 #include "media/base/test_data_util.h" |
| 18 #include "media/base/video_decoder_config.h" |
| 19 #include "media/mp4/mp4_stream_parser.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 |
| 22 using base::TimeDelta; |
| 23 |
| 24 namespace media { |
| 25 namespace mp4 { |
| 26 |
| 27 class MP4StreamParserTest : public testing::Test { |
| 28 public: |
| 29 MP4StreamParserTest() : parser_(new MP4StreamParser) {} |
| 30 |
| 31 protected: |
| 32 scoped_ptr<MP4StreamParser> parser_; |
| 33 |
| 34 bool AppendData(const uint8* data, size_t length) { |
| 35 parser_->Parse(data, length); |
| 36 return true; |
| 37 } |
| 38 |
| 39 bool AppendDataInPieces(const uint8* data, size_t length) { |
| 40 return AppendDataInPieces(data, length, 7); |
| 41 } |
| 42 |
| 43 bool AppendDataInPieces(const uint8* data, size_t length, size_t piece_size) { |
| 44 const uint8* start = data; |
| 45 const uint8* end = data + length; |
| 46 while (start < end) { |
| 47 size_t append_size = std::min(piece_size, |
| 48 static_cast<size_t>(end - start)); |
| 49 if (!AppendData(start, append_size)) |
| 50 return false; |
| 51 start += append_size; |
| 52 } |
| 53 return true; |
| 54 } |
| 55 |
| 56 void InitF(bool init_ok, base::TimeDelta duration) { |
| 57 DVLOG(1) << "InitF: ok=" << init_ok |
| 58 << ", dur=" << duration.InMilliseconds(); |
| 59 } |
| 60 |
| 61 bool NewConfigF(const AudioDecoderConfig& ac, |
| 62 const VideoDecoderConfig& vc) { |
| 63 DVLOG(1) << "NewConfigF: audio=" << ac.IsValidConfig() |
| 64 << ", video=" << vc.IsValidConfig(); |
| 65 return true; |
| 66 } |
| 67 |
| 68 bool NewBuffersF(const StreamParser::BufferQueue& bufs) { |
| 69 DVLOG(2) << "NewBuffersF: " << bufs.size() << " buffers"; |
| 70 for (StreamParser::BufferQueue::const_iterator buf = bufs.begin(); |
| 71 buf != bufs.end(); buf++) { |
| 72 DVLOG(3) << " n=" << buf - bufs.begin() |
| 73 << ", size=" << (*buf)->GetDataSize() |
| 74 << ", dur=" << (*buf)->GetDuration().InMilliseconds(); |
| 75 } |
| 76 return true; |
| 77 } |
| 78 |
| 79 bool KeyNeededF(scoped_array<uint8> init_data, int init_data_size) { |
| 80 DVLOG(1) << "KeyNeededF: " << init_data_size; |
| 81 return true; |
| 82 } |
| 83 |
| 84 void NewSegmentF(TimeDelta start_dts) { |
| 85 DVLOG(1) << "NewSegmentF: " << start_dts.InMilliseconds(); |
| 86 } |
| 87 |
| 88 void InitializeParser() { |
| 89 parser_->Init( |
| 90 base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this)), |
| 91 base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), |
| 92 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), |
| 93 base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), |
| 94 base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)), |
| 95 base::Bind(&MP4StreamParserTest::NewSegmentF, base::Unretained(this))); |
| 96 } |
| 97 |
| 98 bool ParseMP4File(const std::string& filename) { |
| 99 InitializeParser(); |
| 100 |
| 101 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename); |
| 102 EXPECT_TRUE(AppendDataInPieces(buffer->GetData(), |
| 103 buffer->GetDataSize(), |
| 104 512)); |
| 105 return true; |
| 106 } |
| 107 }; |
| 108 |
| 109 TEST_F(MP4StreamParserTest, TestParseBearDASH) { |
| 110 ParseMP4File("bear.1280x720_dash.mp4"); |
| 111 } |
| 112 |
| 113 } // namespace mp4 |
| 114 } // namespace media |
| OLD | NEW |