Loading media/extractors/mkv/MatroskaExtractor.cpp +83 −23 Original line number Diff line number Diff line Loading @@ -37,7 +37,9 @@ #include <media/stagefright/MetaDataUtils.h> #include <utils/String8.h> #include <arpa/inet.h> #include <inttypes.h> #include <vector> namespace android { Loading Loading @@ -584,14 +586,80 @@ status_t MatroskaSource::setWebmBlockCryptoInfo(MediaBufferBase *mbuf) { } const uint8_t *data = (const uint8_t *)mbuf->data() + mbuf->range_offset(); bool blockEncrypted = data[0] & 0x1; if (blockEncrypted && mbuf->range_length() < 9) { bool encrypted = data[0] & 0x1; bool partitioned = data[0] & 0x2; if (encrypted && mbuf->range_length() < 9) { // 1-byte signal + 8-byte IV return ERROR_MALFORMED; } MetaDataBase &meta = mbuf->meta_data(); if (blockEncrypted) { if (encrypted) { uint8_t ctrCounter[16] = { 0 }; uint32_t type; const uint8_t *keyId; size_t keyIdSize; const MetaDataBase &trackMeta = mExtractor->mTracks.itemAt(mTrackIndex).mMeta; CHECK(trackMeta.findData(kKeyCryptoKey, &type, (const void **)&keyId, &keyIdSize)); meta.setData(kKeyCryptoKey, 0, keyId, keyIdSize); memcpy(ctrCounter, data + 1, 8); meta.setData(kKeyCryptoIV, 0, ctrCounter, 16); if (partitioned) { /* 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Signal Byte | | * +-+-+-+-+-+-+-+-+ IV | * | | * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | num_partition | Partition 0 offset -> | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| * | -> Partition 0 offset | ... | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| * | ... | Partition n-1 offset -> | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| * | -> Partition n-1 offset | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | * | Clear/encrypted sample data | * | | * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ if (mbuf->range_length() < 10) { return ERROR_MALFORMED; } uint8_t numPartitions = data[9]; if (mbuf->range_length() - 10 < numPartitions * sizeof(uint32_t)) { return ERROR_MALFORMED; } std::vector<uint32_t> plainSizes, encryptedSizes; uint32_t prev = 0; uint32_t frameOffset = 10 + numPartitions * sizeof(uint32_t); const uint32_t *partitions = reinterpret_cast<const uint32_t*>(data + 10); for (uint32_t i = 0; i <= numPartitions; ++i) { uint32_t p_i = i < numPartitions ? ntohl(partitions[i]) : (mbuf->range_length() - frameOffset); if (p_i < prev) { return ERROR_MALFORMED; } uint32_t size = p_i - prev; prev = p_i; if (i % 2) { encryptedSizes.push_back(size); } else { plainSizes.push_back(size); } } if (plainSizes.size() > encryptedSizes.size()) { encryptedSizes.push_back(0); } uint32_t sizeofPlainSizes = sizeof(uint32_t) * plainSizes.size(); uint32_t sizeofEncryptedSizes = sizeof(uint32_t) * encryptedSizes.size(); meta.setData(kKeyPlainSizes, 0, plainSizes.data(), sizeofPlainSizes); meta.setData(kKeyEncryptedSizes, 0, encryptedSizes.data(), sizeofEncryptedSizes); mbuf->set_range(frameOffset, mbuf->range_length() - frameOffset); } else { /* * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 Loading @@ -609,18 +677,10 @@ status_t MatroskaSource::setWebmBlockCryptoInfo(MediaBufferBase *mbuf) { */ int32_t plainSizes[] = { 0 }; int32_t encryptedSizes[] = { static_cast<int32_t>(mbuf->range_length() - 9) }; uint8_t ctrCounter[16] = { 0 }; uint32_t type; const uint8_t *keyId; size_t keyIdSize; const MetaDataBase &trackMeta = mExtractor->mTracks.itemAt(mTrackIndex).mMeta; CHECK(trackMeta.findData(kKeyCryptoKey, &type, (const void **)&keyId, &keyIdSize)); meta.setData(kKeyCryptoKey, 0, keyId, keyIdSize); memcpy(ctrCounter, data + 1, 8); meta.setData(kKeyCryptoIV, 0, ctrCounter, 16); meta.setData(kKeyPlainSizes, 0, plainSizes, sizeof(plainSizes)); meta.setData(kKeyEncryptedSizes, 0, encryptedSizes, sizeof(encryptedSizes)); mbuf->set_range(9, mbuf->range_length() - 9); } } else { /* * 0 1 2 3 Loading media/extractors/mp4/MPEG4Extractor.cpp +7 −2 Original line number Diff line number Diff line Loading @@ -321,8 +321,13 @@ static const char *FourCC2MIME(uint32_t fourcc) { case FOURCC('h', 'e', 'v', '1'): return MEDIA_MIMETYPE_VIDEO_HEVC; default: CHECK(!"should not be here."); return NULL; ALOGW("Unknown fourcc: %c%c%c%c", (fourcc >> 24) & 0xff, (fourcc >> 16) & 0xff, (fourcc >> 8) & 0xff, fourcc & 0xff ); return "application/octet-stream"; } } Loading media/libaaudio/src/fifo/FifoBuffer.cpp +9 −7 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ //#define LOG_NDEBUG 0 #include <utils/Log.h> #include <algorithm> #include "FifoControllerBase.h" #include "FifoController.h" #include "FifoControllerIndirect.h" Loading Loading @@ -85,15 +87,14 @@ void FifoBuffer::fillWrappingBuffer(WrappingBuffer *wrappingBuffer, wrappingBuffer->data[1] = nullptr; wrappingBuffer->numFrames[1] = 0; if (framesAvailable > 0) { uint8_t *source = &mStorage[convertFramesToBytes(startIndex)]; // Does the available data cross the end of the FIFO? if ((startIndex + framesAvailable) > mFrameCapacity) { wrappingBuffer->data[0] = source; wrappingBuffer->numFrames[0] = mFrameCapacity - startIndex; fifo_frames_t firstFrames = mFrameCapacity - startIndex; wrappingBuffer->numFrames[0] = firstFrames; wrappingBuffer->data[1] = &mStorage[0]; wrappingBuffer->numFrames[1] = mFrameCapacity - startIndex; wrappingBuffer->numFrames[1] = framesAvailable - firstFrames; } else { wrappingBuffer->data[0] = source; wrappingBuffer->numFrames[0] = framesAvailable; Loading @@ -102,18 +103,19 @@ void FifoBuffer::fillWrappingBuffer(WrappingBuffer *wrappingBuffer, wrappingBuffer->data[0] = nullptr; wrappingBuffer->numFrames[0] = 0; } } fifo_frames_t FifoBuffer::getFullDataAvailable(WrappingBuffer *wrappingBuffer) { fifo_frames_t framesAvailable = mFifo->getFullFramesAvailable(); // The FIFO might be overfull so clip to capacity. fifo_frames_t framesAvailable = std::min(mFifo->getFullFramesAvailable(), mFrameCapacity); fifo_frames_t startIndex = mFifo->getReadIndex(); fillWrappingBuffer(wrappingBuffer, framesAvailable, startIndex); return framesAvailable; } fifo_frames_t FifoBuffer::getEmptyRoomAvailable(WrappingBuffer *wrappingBuffer) { fifo_frames_t framesAvailable = mFifo->getEmptyFramesAvailable(); // The FIFO might have underrun so clip to capacity. fifo_frames_t framesAvailable = std::min(mFifo->getEmptyFramesAvailable(), mFrameCapacity); fifo_frames_t startIndex = mFifo->getWriteIndex(); fillWrappingBuffer(wrappingBuffer, framesAvailable, startIndex); return framesAvailable; Loading media/libaudioclient/AudioTrackShared.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -725,12 +725,13 @@ int32_t AudioTrackServerProxy::getRear() const const size_t mask = overflowBit - 1; int32_t newRear = (rear & ~mask) | (stop & mask); ssize_t filled = newRear - front; if (filled < 0) { // overflowBit is unsigned, so cast to signed for comparison. if (filled >= (ssize_t)overflowBit) { // front and rear offsets span the overflow bit of the p2 mask // so rebasing newrear. // so rebasing newRear on the rear offset is off by the overflow bit. ALOGV("stop wrap: filled %zx >= overflowBit %zx", filled, overflowBit); newRear += overflowBit; filled += overflowBit; newRear -= overflowBit; filled -= overflowBit; } if (0 <= filled && (size_t) filled <= mFrameCount) { // we're stopped, return the stop level as newRear Loading media/libstagefright/ACodec.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -6777,9 +6777,14 @@ void ACodec::LoadedState::onSetInputSurface(const sp<AMessage> &msg) { sp<RefBase> obj; CHECK(msg->findObject("input-surface", &obj)); if (obj == NULL) { ALOGE("[%s] NULL input surface", mCodec->mComponentName.c_str()); mCodec->mCallback->onInputSurfaceDeclined(BAD_VALUE); return; } sp<PersistentSurface> surface = static_cast<PersistentSurface *>(obj.get()); mCodec->mGraphicBufferSource = surface->getBufferSource(); status_t err = setupInputSurface(); if (err == OK) { Loading Loading
media/extractors/mkv/MatroskaExtractor.cpp +83 −23 Original line number Diff line number Diff line Loading @@ -37,7 +37,9 @@ #include <media/stagefright/MetaDataUtils.h> #include <utils/String8.h> #include <arpa/inet.h> #include <inttypes.h> #include <vector> namespace android { Loading Loading @@ -584,14 +586,80 @@ status_t MatroskaSource::setWebmBlockCryptoInfo(MediaBufferBase *mbuf) { } const uint8_t *data = (const uint8_t *)mbuf->data() + mbuf->range_offset(); bool blockEncrypted = data[0] & 0x1; if (blockEncrypted && mbuf->range_length() < 9) { bool encrypted = data[0] & 0x1; bool partitioned = data[0] & 0x2; if (encrypted && mbuf->range_length() < 9) { // 1-byte signal + 8-byte IV return ERROR_MALFORMED; } MetaDataBase &meta = mbuf->meta_data(); if (blockEncrypted) { if (encrypted) { uint8_t ctrCounter[16] = { 0 }; uint32_t type; const uint8_t *keyId; size_t keyIdSize; const MetaDataBase &trackMeta = mExtractor->mTracks.itemAt(mTrackIndex).mMeta; CHECK(trackMeta.findData(kKeyCryptoKey, &type, (const void **)&keyId, &keyIdSize)); meta.setData(kKeyCryptoKey, 0, keyId, keyIdSize); memcpy(ctrCounter, data + 1, 8); meta.setData(kKeyCryptoIV, 0, ctrCounter, 16); if (partitioned) { /* 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Signal Byte | | * +-+-+-+-+-+-+-+-+ IV | * | | * | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | num_partition | Partition 0 offset -> | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| * | -> Partition 0 offset | ... | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| * | ... | Partition n-1 offset -> | * |-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| * | -> Partition n-1 offset | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | * | Clear/encrypted sample data | * | | * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ if (mbuf->range_length() < 10) { return ERROR_MALFORMED; } uint8_t numPartitions = data[9]; if (mbuf->range_length() - 10 < numPartitions * sizeof(uint32_t)) { return ERROR_MALFORMED; } std::vector<uint32_t> plainSizes, encryptedSizes; uint32_t prev = 0; uint32_t frameOffset = 10 + numPartitions * sizeof(uint32_t); const uint32_t *partitions = reinterpret_cast<const uint32_t*>(data + 10); for (uint32_t i = 0; i <= numPartitions; ++i) { uint32_t p_i = i < numPartitions ? ntohl(partitions[i]) : (mbuf->range_length() - frameOffset); if (p_i < prev) { return ERROR_MALFORMED; } uint32_t size = p_i - prev; prev = p_i; if (i % 2) { encryptedSizes.push_back(size); } else { plainSizes.push_back(size); } } if (plainSizes.size() > encryptedSizes.size()) { encryptedSizes.push_back(0); } uint32_t sizeofPlainSizes = sizeof(uint32_t) * plainSizes.size(); uint32_t sizeofEncryptedSizes = sizeof(uint32_t) * encryptedSizes.size(); meta.setData(kKeyPlainSizes, 0, plainSizes.data(), sizeofPlainSizes); meta.setData(kKeyEncryptedSizes, 0, encryptedSizes.data(), sizeofEncryptedSizes); mbuf->set_range(frameOffset, mbuf->range_length() - frameOffset); } else { /* * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 Loading @@ -609,18 +677,10 @@ status_t MatroskaSource::setWebmBlockCryptoInfo(MediaBufferBase *mbuf) { */ int32_t plainSizes[] = { 0 }; int32_t encryptedSizes[] = { static_cast<int32_t>(mbuf->range_length() - 9) }; uint8_t ctrCounter[16] = { 0 }; uint32_t type; const uint8_t *keyId; size_t keyIdSize; const MetaDataBase &trackMeta = mExtractor->mTracks.itemAt(mTrackIndex).mMeta; CHECK(trackMeta.findData(kKeyCryptoKey, &type, (const void **)&keyId, &keyIdSize)); meta.setData(kKeyCryptoKey, 0, keyId, keyIdSize); memcpy(ctrCounter, data + 1, 8); meta.setData(kKeyCryptoIV, 0, ctrCounter, 16); meta.setData(kKeyPlainSizes, 0, plainSizes, sizeof(plainSizes)); meta.setData(kKeyEncryptedSizes, 0, encryptedSizes, sizeof(encryptedSizes)); mbuf->set_range(9, mbuf->range_length() - 9); } } else { /* * 0 1 2 3 Loading
media/extractors/mp4/MPEG4Extractor.cpp +7 −2 Original line number Diff line number Diff line Loading @@ -321,8 +321,13 @@ static const char *FourCC2MIME(uint32_t fourcc) { case FOURCC('h', 'e', 'v', '1'): return MEDIA_MIMETYPE_VIDEO_HEVC; default: CHECK(!"should not be here."); return NULL; ALOGW("Unknown fourcc: %c%c%c%c", (fourcc >> 24) & 0xff, (fourcc >> 16) & 0xff, (fourcc >> 8) & 0xff, fourcc & 0xff ); return "application/octet-stream"; } } Loading
media/libaaudio/src/fifo/FifoBuffer.cpp +9 −7 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ //#define LOG_NDEBUG 0 #include <utils/Log.h> #include <algorithm> #include "FifoControllerBase.h" #include "FifoController.h" #include "FifoControllerIndirect.h" Loading Loading @@ -85,15 +87,14 @@ void FifoBuffer::fillWrappingBuffer(WrappingBuffer *wrappingBuffer, wrappingBuffer->data[1] = nullptr; wrappingBuffer->numFrames[1] = 0; if (framesAvailable > 0) { uint8_t *source = &mStorage[convertFramesToBytes(startIndex)]; // Does the available data cross the end of the FIFO? if ((startIndex + framesAvailable) > mFrameCapacity) { wrappingBuffer->data[0] = source; wrappingBuffer->numFrames[0] = mFrameCapacity - startIndex; fifo_frames_t firstFrames = mFrameCapacity - startIndex; wrappingBuffer->numFrames[0] = firstFrames; wrappingBuffer->data[1] = &mStorage[0]; wrappingBuffer->numFrames[1] = mFrameCapacity - startIndex; wrappingBuffer->numFrames[1] = framesAvailable - firstFrames; } else { wrappingBuffer->data[0] = source; wrappingBuffer->numFrames[0] = framesAvailable; Loading @@ -102,18 +103,19 @@ void FifoBuffer::fillWrappingBuffer(WrappingBuffer *wrappingBuffer, wrappingBuffer->data[0] = nullptr; wrappingBuffer->numFrames[0] = 0; } } fifo_frames_t FifoBuffer::getFullDataAvailable(WrappingBuffer *wrappingBuffer) { fifo_frames_t framesAvailable = mFifo->getFullFramesAvailable(); // The FIFO might be overfull so clip to capacity. fifo_frames_t framesAvailable = std::min(mFifo->getFullFramesAvailable(), mFrameCapacity); fifo_frames_t startIndex = mFifo->getReadIndex(); fillWrappingBuffer(wrappingBuffer, framesAvailable, startIndex); return framesAvailable; } fifo_frames_t FifoBuffer::getEmptyRoomAvailable(WrappingBuffer *wrappingBuffer) { fifo_frames_t framesAvailable = mFifo->getEmptyFramesAvailable(); // The FIFO might have underrun so clip to capacity. fifo_frames_t framesAvailable = std::min(mFifo->getEmptyFramesAvailable(), mFrameCapacity); fifo_frames_t startIndex = mFifo->getWriteIndex(); fillWrappingBuffer(wrappingBuffer, framesAvailable, startIndex); return framesAvailable; Loading
media/libaudioclient/AudioTrackShared.cpp +5 −4 Original line number Diff line number Diff line Loading @@ -725,12 +725,13 @@ int32_t AudioTrackServerProxy::getRear() const const size_t mask = overflowBit - 1; int32_t newRear = (rear & ~mask) | (stop & mask); ssize_t filled = newRear - front; if (filled < 0) { // overflowBit is unsigned, so cast to signed for comparison. if (filled >= (ssize_t)overflowBit) { // front and rear offsets span the overflow bit of the p2 mask // so rebasing newrear. // so rebasing newRear on the rear offset is off by the overflow bit. ALOGV("stop wrap: filled %zx >= overflowBit %zx", filled, overflowBit); newRear += overflowBit; filled += overflowBit; newRear -= overflowBit; filled -= overflowBit; } if (0 <= filled && (size_t) filled <= mFrameCount) { // we're stopped, return the stop level as newRear Loading
media/libstagefright/ACodec.cpp +6 −1 Original line number Diff line number Diff line Loading @@ -6777,9 +6777,14 @@ void ACodec::LoadedState::onSetInputSurface(const sp<AMessage> &msg) { sp<RefBase> obj; CHECK(msg->findObject("input-surface", &obj)); if (obj == NULL) { ALOGE("[%s] NULL input surface", mCodec->mComponentName.c_str()); mCodec->mCallback->onInputSurfaceDeclined(BAD_VALUE); return; } sp<PersistentSurface> surface = static_cast<PersistentSurface *>(obj.get()); mCodec->mGraphicBufferSource = surface->getBufferSource(); status_t err = setupInputSurface(); if (err == OK) { Loading