OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/formats/mp2t/es_parser_test_base.h" |
| 6 |
| 7 #include "base/files/memory_mapped_file.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_util.h" |
| 11 #include "media/base/buffers.h" |
| 12 #include "media/base/stream_parser_buffer.h" |
| 13 #include "media/base/test_data_util.h" |
| 14 #include "media/formats/mp2t/es_parser.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 namespace media { |
| 18 namespace mp2t { |
| 19 |
| 20 EsParserTestBase::Packet::Packet() |
| 21 : offset(0u), |
| 22 size(0u), |
| 23 pts(kNoTimestamp()) { |
| 24 } |
| 25 |
| 26 EsParserTestBase::EsParserTestBase() |
| 27 : config_count_(0u), |
| 28 buffer_count_(0u) { |
| 29 } |
| 30 |
| 31 EsParserTestBase::~EsParserTestBase() { |
| 32 } |
| 33 |
| 34 void EsParserTestBase::LoadStream(const char* filename) { |
| 35 base::FilePath file_path = GetTestDataFilePath(filename); |
| 36 |
| 37 base::MemoryMappedFile stream; |
| 38 ASSERT_TRUE(stream.Initialize(file_path)) |
| 39 << "Couldn't open stream file: " << file_path.MaybeAsASCII(); |
| 40 |
| 41 stream_.resize(stream.length()); |
| 42 memcpy(&stream_[0], stream.data(), stream_.size()); |
| 43 } |
| 44 |
| 45 void EsParserTestBase::NewAudioConfig(const AudioDecoderConfig& config) { |
| 46 config_count_++; |
| 47 } |
| 48 |
| 49 void EsParserTestBase::NewVideoConfig(const VideoDecoderConfig& config) { |
| 50 config_count_++; |
| 51 } |
| 52 |
| 53 void EsParserTestBase::EmitBuffer(scoped_refptr<StreamParserBuffer> buffer) { |
| 54 buffer_timestamps_stream_ << "(" |
| 55 << buffer->timestamp().InMilliseconds() |
| 56 << ") "; |
| 57 buffer_count_++; |
| 58 } |
| 59 |
| 60 bool EsParserTestBase::ProcessPesPackets( |
| 61 EsParser* es_parser, |
| 62 const std::vector<Packet>& pes_packets, |
| 63 bool force_timing) { |
| 64 DCHECK(es_parser); |
| 65 |
| 66 buffer_count_ = 0; |
| 67 config_count_ = 0; |
| 68 buffer_timestamps_stream_.str(std::string()); |
| 69 |
| 70 for (size_t k = 0; k < pes_packets.size(); k++) { |
| 71 size_t cur_pes_offset = pes_packets[k].offset; |
| 72 size_t cur_pes_size = pes_packets[k].size; |
| 73 |
| 74 base::TimeDelta pts = kNoTimestamp(); |
| 75 DecodeTimestamp dts = kNoDecodeTimestamp(); |
| 76 if (pes_packets[k].pts >= base::TimeDelta() || force_timing) |
| 77 pts = pes_packets[k].pts; |
| 78 |
| 79 DCHECK_LT(cur_pes_offset, stream_.size()); |
| 80 if (!es_parser->Parse(&stream_[cur_pes_offset], cur_pes_size, pts, dts)) |
| 81 return false; |
| 82 } |
| 83 es_parser->Flush(); |
| 84 |
| 85 buffer_timestamps_ = buffer_timestamps_stream_.str(); |
| 86 base::TrimWhitespaceASCII( |
| 87 buffer_timestamps_, base::TRIM_ALL, &buffer_timestamps_); |
| 88 return true; |
| 89 } |
| 90 |
| 91 void EsParserTestBase::ComputePacketSize(std::vector<Packet>* packets) { |
| 92 DCHECK(packets); |
| 93 if (packets->size() == 0u) |
| 94 return; |
| 95 |
| 96 Packet* cur = &(*packets)[0]; |
| 97 for (size_t k = 0; k < packets->size() - 1; k++) { |
| 98 Packet* next = &(*packets)[k + 1]; |
| 99 DCHECK_GE(next->offset, cur->offset); |
| 100 cur->size = next->offset - cur->offset; |
| 101 cur = next; |
| 102 } |
| 103 DCHECK_GE(stream_.size(), cur->offset); |
| 104 cur->size = stream_.size() - cur->offset; |
| 105 } |
| 106 |
| 107 } // namespace mp2t |
| 108 } // namespace media |
OLD | NEW |