From d0181f31d10f5126e836fd38bd6bf54d4c4d4872 Mon Sep 17 00:00:00 2001 From: avi Date: Thu, 10 Dec 2015 11:41:47 -0800 Subject: Remove kint32max. BUG=138542, 488550 Review URL: https://codereview.chromium.org/1499423004 Cr-Commit-Position: refs/heads/master@{#364429} --- media/formats/mp4/box_reader.cc | 61 +++++++++++++++++++++++---------------- media/formats/mp4/box_reader.h | 63 ++++++++++++++++++++++------------------- 2 files changed, 70 insertions(+), 54 deletions(-) (limited to 'media/formats') diff --git a/media/formats/mp4/box_reader.cc b/media/formats/mp4/box_reader.cc index 8200b19..4f32031 100644 --- a/media/formats/mp4/box_reader.cc +++ b/media/formats/mp4/box_reader.cc @@ -16,7 +16,7 @@ namespace mp4 { Box::~Box() {} -bool BufferReader::Read1(uint8* v) { +bool BufferReader::Read1(uint8_t* v) { RCHECK(HasBytes(1)); *v = buf_[pos_++]; return true; @@ -35,18 +35,30 @@ template bool BufferReader::Read(T* v) { return true; } -bool BufferReader::Read2(uint16* v) { return Read(v); } -bool BufferReader::Read2s(int16* v) { return Read(v); } -bool BufferReader::Read4(uint32* v) { return Read(v); } -bool BufferReader::Read4s(int32* v) { return Read(v); } -bool BufferReader::Read8(uint64* v) { return Read(v); } -bool BufferReader::Read8s(int64* v) { return Read(v); } +bool BufferReader::Read2(uint16_t* v) { + return Read(v); +} +bool BufferReader::Read2s(int16_t* v) { + return Read(v); +} +bool BufferReader::Read4(uint32_t* v) { + return Read(v); +} +bool BufferReader::Read4s(int32_t* v) { + return Read(v); +} +bool BufferReader::Read8(uint64_t* v) { + return Read(v); +} +bool BufferReader::Read8s(int64_t* v) { + return Read(v); +} bool BufferReader::ReadFourCC(FourCC* v) { - return Read4(reinterpret_cast(v)); + return Read4(reinterpret_cast(v)); } -bool BufferReader::ReadVec(std::vector* vec, uint64 count) { +bool BufferReader::ReadVec(std::vector* vec, uint64_t count) { RCHECK(HasBytes(count)); vec->clear(); vec->insert(vec->end(), buf_ + pos_, buf_ + pos_ + count); @@ -54,28 +66,28 @@ bool BufferReader::ReadVec(std::vector* vec, uint64 count) { return true; } -bool BufferReader::SkipBytes(uint64 bytes) { +bool BufferReader::SkipBytes(uint64_t bytes) { RCHECK(HasBytes(bytes)); pos_ += bytes; return true; } -bool BufferReader::Read4Into8(uint64* v) { - uint32 tmp; +bool BufferReader::Read4Into8(uint64_t* v) { + uint32_t tmp; RCHECK(Read4(&tmp)); *v = tmp; return true; } -bool BufferReader::Read4sInto8s(int64* v) { +bool BufferReader::Read4sInto8s(int64_t* v) { // Beware of the need for sign extension. - int32 tmp; + int32_t tmp; RCHECK(Read4s(&tmp)); *v = tmp; return true; } -BoxReader::BoxReader(const uint8* buf, +BoxReader::BoxReader(const uint8_t* buf, const int size, const scoped_refptr& media_log, bool is_EOS) @@ -85,8 +97,7 @@ BoxReader::BoxReader(const uint8* buf, version_(0), flags_(0), scanned_(false), - is_EOS_(is_EOS) { -} + is_EOS_(is_EOS) {} BoxReader::~BoxReader() { if (scanned_ && !children_.empty()) { @@ -98,7 +109,7 @@ BoxReader::~BoxReader() { } // static -BoxReader* BoxReader::ReadTopLevelBox(const uint8* buf, +BoxReader* BoxReader::ReadTopLevelBox(const uint8_t* buf, const int buf_size, const scoped_refptr& media_log, bool* err) { @@ -111,14 +122,14 @@ BoxReader* BoxReader::ReadTopLevelBox(const uint8* buf, return NULL; } - if (reader->size() <= static_cast(buf_size)) + if (reader->size() <= static_cast(buf_size)) return reader.release(); return NULL; } // static -bool BoxReader::StartTopLevelBox(const uint8* buf, +bool BoxReader::StartTopLevelBox(const uint8_t* buf, const int buf_size, const scoped_refptr& media_log, FourCC* type, @@ -136,7 +147,7 @@ bool BoxReader::StartTopLevelBox(const uint8* buf, } // static -BoxReader* BoxReader::ReadConcatentatedBoxes(const uint8* buf, +BoxReader* BoxReader::ReadConcatentatedBoxes(const uint8_t* buf, const int buf_size) { return new BoxReader(buf, buf_size, new MediaLog(), true); } @@ -212,7 +223,7 @@ bool BoxReader::MaybeReadChild(Box* child) { } bool BoxReader::ReadFullBoxHeader() { - uint32 vflags; + uint32_t vflags; RCHECK(Read4(&vflags)); version_ = vflags >> 24; flags_ = vflags & 0xffffff; @@ -220,7 +231,7 @@ bool BoxReader::ReadFullBoxHeader() { } bool BoxReader::ReadHeader(bool* err) { - uint64 size = 0; + uint64_t size = 0; *err = false; if (!HasBytes(8)) { @@ -252,8 +263,8 @@ bool BoxReader::ReadHeader(bool* err) { // Implementation-specific: support for boxes larger than 2^31 has been // removed. - if (size < static_cast(pos_) || - size > static_cast(kint32max)) { + if (size < static_cast(pos_) || + size > static_cast(std::numeric_limits::max())) { *err = true; return false; } diff --git a/media/formats/mp4/box_reader.h b/media/formats/mp4/box_reader.h index 957c287..3fff191 100644 --- a/media/formats/mp4/box_reader.h +++ b/media/formats/mp4/box_reader.h @@ -5,6 +5,9 @@ #ifndef MEDIA_FORMATS_MP4_BOX_READER_H_ #define MEDIA_FORMATS_MP4_BOX_READER_H_ +#include + +#include #include #include @@ -32,53 +35,55 @@ struct MEDIA_EXPORT Box { class MEDIA_EXPORT BufferReader { public: - BufferReader(const uint8* buf, const int size) : buf_(buf), pos_(0) { + BufferReader(const uint8_t* buf, const int size) : buf_(buf), pos_(0) { CHECK(buf); - size_ = base::checked_cast(size); + size_ = base::checked_cast(size); } - bool HasBytes(uint64 count) { + bool HasBytes(uint64_t count) { // As the size of a box is implementation limited to 2^31, fail if // attempting to check for too many bytes. - return (pos_ <= size_ && count < static_cast(kint32max) && + return (pos_ <= size_ && + count < + static_cast(std::numeric_limits::max()) && size_ - pos_ >= count); } // Read a value from the stream, perfoming endian correction, and advance the // stream pointer. - bool Read1(uint8* v) WARN_UNUSED_RESULT; - bool Read2(uint16* v) WARN_UNUSED_RESULT; - bool Read2s(int16* v) WARN_UNUSED_RESULT; - bool Read4(uint32* v) WARN_UNUSED_RESULT; - bool Read4s(int32* v) WARN_UNUSED_RESULT; - bool Read8(uint64* v) WARN_UNUSED_RESULT; - bool Read8s(int64* v) WARN_UNUSED_RESULT; + bool Read1(uint8_t* v) WARN_UNUSED_RESULT; + bool Read2(uint16_t* v) WARN_UNUSED_RESULT; + bool Read2s(int16_t* v) WARN_UNUSED_RESULT; + bool Read4(uint32_t* v) WARN_UNUSED_RESULT; + bool Read4s(int32_t* v) WARN_UNUSED_RESULT; + bool Read8(uint64_t* v) WARN_UNUSED_RESULT; + bool Read8s(int64_t* v) WARN_UNUSED_RESULT; bool ReadFourCC(FourCC* v) WARN_UNUSED_RESULT; - bool ReadVec(std::vector* t, uint64 count) WARN_UNUSED_RESULT; + bool ReadVec(std::vector* t, uint64_t count) WARN_UNUSED_RESULT; // These variants read a 4-byte integer of the corresponding signedness and // store it in the 8-byte return type. - bool Read4Into8(uint64* v) WARN_UNUSED_RESULT; - bool Read4sInto8s(int64* v) WARN_UNUSED_RESULT; + bool Read4Into8(uint64_t* v) WARN_UNUSED_RESULT; + bool Read4sInto8s(int64_t* v) WARN_UNUSED_RESULT; // Advance the stream by this many bytes. - bool SkipBytes(uint64 nbytes) WARN_UNUSED_RESULT; + bool SkipBytes(uint64_t nbytes) WARN_UNUSED_RESULT; - const uint8* data() const { return buf_; } + const uint8_t* data() const { return buf_; } // This returns the size of the box as specified in the box header. Initially // it is the buffer size until the header is read. Note that the size // specified in the box header may be different than the number of bytes // actually provided. - uint64 size() const { return size_; } - uint64 pos() const { return pos_; } + uint64_t size() const { return size_; } + uint64_t pos() const { return pos_; } protected: - const uint8* buf_; - uint64 size_; - uint64 pos_; + const uint8_t* buf_; + uint64_t size_; + uint64_t pos_; template bool Read(T* t) WARN_UNUSED_RESULT; }; @@ -93,7 +98,7 @@ class MEDIA_EXPORT BoxReader : public BufferReader { // values are only expected when insufficient data is available. // // |buf| is retained but not owned, and must outlive the BoxReader instance. - static BoxReader* ReadTopLevelBox(const uint8* buf, + static BoxReader* ReadTopLevelBox(const uint8_t* buf, const int buf_size, const scoped_refptr& media_log, bool* err); @@ -104,7 +109,7 @@ class MEDIA_EXPORT BoxReader : public BufferReader { // true. The semantics of |*err| are the same as above. // // |buf| is not retained. - static bool StartTopLevelBox(const uint8* buf, + static bool StartTopLevelBox(const uint8_t* buf, const int buf_size, const scoped_refptr& media_log, FourCC* type, @@ -116,7 +121,7 @@ class MEDIA_EXPORT BoxReader : public BufferReader { // with any type of box -- it does not have to be IsValidTopLevelBox(). // // |buf| is retained but not owned, and must outlive the BoxReader instance. - static BoxReader* ReadConcatentatedBoxes(const uint8* buf, + static BoxReader* ReadConcatentatedBoxes(const uint8_t* buf, const int buf_size); // Returns true if |type| is recognized to be a top-level box, false @@ -169,15 +174,15 @@ class MEDIA_EXPORT BoxReader : public BufferReader { bool ReadFullBoxHeader() WARN_UNUSED_RESULT; FourCC type() const { return type_; } - uint8 version() const { return version_; } - uint32 flags() const { return flags_; } + uint8_t version() const { return version_; } + uint32_t flags() const { return flags_; } const scoped_refptr& media_log() const { return media_log_; } private: // Create a BoxReader from |buf|. |is_EOS| should be true if |buf| is // complete stream (i.e. no additional data is expected to be appended). - BoxReader(const uint8* buf, + BoxReader(const uint8_t* buf, const int size, const scoped_refptr& media_log, bool is_EOS); @@ -200,8 +205,8 @@ class MEDIA_EXPORT BoxReader : public BufferReader { scoped_refptr media_log_; FourCC type_; - uint8 version_; - uint32 flags_; + uint8_t version_; + uint32_t flags_; typedef std::multimap ChildMap; -- cgit v1.1