* Fix strict aliasing error in gcc [ Merge of http://go/wvgerrit/15856 ] This also ensures the alignment of 64-bit memory access in a portable way, without using compiler-specific mechanisms like attributes or platform-specific mechanisms like memalign. (The aliasing error does not show up in clang.) * Return kNotSupported for non-Widevine init data [ Merge of http://go/wvgerrit/15853 ] This also improves logging for the init data parser by including a verbose message for non-Widevine PSSHs and by using a new IsEOF() method to avoid misleading "Unable to read atom size" logs. * Cast RSA_size() to int [ Merge of http://go/wvgerrit/15880 ] It has been suggested that this may be unsigned on some versions of OpenSSL or BoringSSL. * Be strict about warnings for CE CDM [ Merge of http://go/wvgerrit/15831 ] * Enable all warnings and treat warnings as errors in the CE build. * Fix all existing warnings (mostly unused variables, consts, and functions, and one signed/unsigned comparison). * Exclude protobuf warnings rather than maintain a divergent copy. * Fix release build errors [ Merge of http://go/wvgerrit/15855 ] * Level 3 Build With Android Emulator [ Merge of http://go/wvgerrit/15778 ] This CL rebuilds the level 3 libraries with the android emulator sdk_phone_*. This seems to avoid problems with the x86 build using incorrect compiler flags. These libraries work for arm, x86, mips, arm64, and x86_64. The level 3 library is disabled for mips64. Versions: level3/mips/libwvlevel3.a Level3 Library Sep 30 2015 18:29:50 level3/arm/libwvlevel3.a Level3 Library Sep 28 2015 13:18:25 level3/x86/libwvlevel3.a Level3 Library Sep 28 2015 13:08:28 Change-Id: I1e50aa78bdc84ecb905f2e55297d4f48b140341c
71 lines
2.0 KiB
C++
71 lines
2.0 KiB
C++
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
|
|
#ifndef WVCDM_CORE_BUFFER_READER_H_
|
|
#define WVCDM_CORE_BUFFER_READER_H_
|
|
|
|
#include <stdint.h>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "wv_cdm_types.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
// Annotate a function indicating the caller must examine the return value.
|
|
// Use like:
|
|
// int foo() WARN_UNUSED_RESULT;
|
|
// To explicitly ignore a result, see |ignore_result()| in <base/basictypes.h>.
|
|
#if defined(COMPILER_GCC)
|
|
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
|
#else
|
|
#define WARN_UNUSED_RESULT
|
|
#endif
|
|
|
|
class BufferReader {
|
|
public:
|
|
BufferReader(const uint8_t* buf, size_t size)
|
|
: buf_(buf), size_(buf != NULL ? size : 0), pos_(0) {}
|
|
|
|
bool HasBytes(size_t count) const { return pos_ + count <= size_; }
|
|
bool IsEOF() const { return pos_ >= size_; }
|
|
|
|
// Read a value from the stream, performing endian correction,
|
|
// and advance the stream pointer.
|
|
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 ReadString(std::string* str, size_t count) WARN_UNUSED_RESULT;
|
|
bool ReadVec(std::vector<uint8_t>* t, size_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_t* v) WARN_UNUSED_RESULT;
|
|
bool Read4sInto8s(int64_t* v) WARN_UNUSED_RESULT;
|
|
|
|
// Advance the stream by this many bytes.
|
|
bool SkipBytes(size_t nbytes) WARN_UNUSED_RESULT;
|
|
|
|
const uint8_t* data() const { return buf_; }
|
|
size_t size() const { return size_; }
|
|
size_t pos() const { return pos_; }
|
|
|
|
protected:
|
|
const uint8_t* buf_;
|
|
size_t size_;
|
|
size_t pos_;
|
|
|
|
template <typename T>
|
|
bool Read(T* t) WARN_UNUSED_RESULT;
|
|
|
|
CORE_DISALLOW_COPY_AND_ASSIGN(BufferReader);
|
|
};
|
|
|
|
} // namespace wvcdm
|
|
|
|
#endif // WVCDM_CORE_BUFFER_READER_H_
|