Remove 6 out of 8 RefBase references from mkv extractor

Bug: 67908544
Test: CTS DecoderTest
Change-Id: I04b6cda83861e70f1de70abc671dd791327be159
(cherry picked from commit ba1f0ab5ce)
gugelfrei
Marco Nelissen 6 years ago
parent 9d3824e06b
commit a1a005fc01

@ -0,0 +1 @@
../../media/libmediaextractor/include/media/ExtractorUtils.h

@ -22,6 +22,7 @@
#include "MatroskaExtractor.h" #include "MatroskaExtractor.h"
#include <media/DataSourceBase.h> #include <media/DataSourceBase.h>
#include <media/ExtractorUtils.h>
#include <media/MediaTrack.h> #include <media/MediaTrack.h>
#include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AUtils.h> #include <media/stagefright/foundation/AUtils.h>
@ -1108,7 +1109,7 @@ static status_t addFlacMetadata(
meta.setData(kKeyFlacMetadata, 0, codecPrivate, codecPrivateSize); meta.setData(kKeyFlacMetadata, 0, codecPrivate, codecPrivateSize);
int32_t maxInputSize = 64 << 10; int32_t maxInputSize = 64 << 10;
sp<FLACDecoder> flacDecoder = FLACDecoder::Create(); FLACDecoder *flacDecoder = FLACDecoder::Create();
if (flacDecoder != NULL if (flacDecoder != NULL
&& flacDecoder->parseMetadata((const uint8_t*)codecPrivate, codecPrivateSize) == OK) { && flacDecoder->parseMetadata((const uint8_t*)codecPrivate, codecPrivateSize) == OK) {
FLAC__StreamMetadata_StreamInfo streamInfo = flacDecoder->getStreamInfo(); FLAC__StreamMetadata_StreamInfo streamInfo = flacDecoder->getStreamInfo();
@ -1120,6 +1121,7 @@ static status_t addFlacMetadata(
&& streamInfo.channels != 0 && streamInfo.channels != 0
&& ((streamInfo.bits_per_sample + 7) / 8) > && ((streamInfo.bits_per_sample + 7) / 8) >
INT32_MAX / streamInfo.max_blocksize / streamInfo.channels) { INT32_MAX / streamInfo.max_blocksize / streamInfo.channels) {
delete flacDecoder;
return ERROR_MALFORMED; return ERROR_MALFORMED;
} }
maxInputSize = ((streamInfo.bits_per_sample + 7) / 8) maxInputSize = ((streamInfo.bits_per_sample + 7) / 8)
@ -1128,6 +1130,7 @@ static status_t addFlacMetadata(
} }
meta.setInt32(kKeyMaxInputSize, maxInputSize); meta.setInt32(kKeyMaxInputSize, maxInputSize);
delete flacDecoder;
return OK; return OK;
} }
@ -1143,13 +1146,13 @@ status_t MatroskaExtractor::synthesizeAVCC(TrackInfo *trackInfo, size_t index) {
} }
const mkvparser::Block::Frame &frame = block->GetFrame(0); const mkvparser::Block::Frame &frame = block->GetFrame(0);
sp<ABuffer> abuf = new ABuffer(frame.len); auto tmpData = heapbuffer<unsigned char>(frame.len);
long n = frame.Read(mReader, abuf->data()); long n = frame.Read(mReader, tmpData.get());
if (n != 0) { if (n != 0) {
return ERROR_MALFORMED; return ERROR_MALFORMED;
} }
if (!MakeAVCCodecSpecificData(trackInfo->mMeta, abuf)) { if (!MakeAVCCodecSpecificData(trackInfo->mMeta, tmpData.get(), frame.len)) {
return ERROR_MALFORMED; return ERROR_MALFORMED;
} }

@ -22,6 +22,7 @@
#include <cutils/properties.h> #include <cutils/properties.h>
#include <media/DataSourceBase.h> #include <media/DataSourceBase.h>
#include <media/ExtractorUtils.h>
#include <media/MediaTrack.h> #include <media/MediaTrack.h>
#include <media/VorbisComment.h> #include <media/VorbisComment.h>
#include <media/stagefright/foundation/ABuffer.h> #include <media/stagefright/foundation/ABuffer.h>
@ -990,21 +991,11 @@ status_t MyOpusExtractor::verifyOpusHeader(MediaBufferBase *buffer) {
return OK; return OK;
} }
struct TmpData {
uint8_t *data;
TmpData(size_t size) {
data = (uint8_t*) malloc(size);
}
~TmpData() {
free(data);
}
};
status_t MyOpusExtractor::verifyOpusComments(MediaBufferBase *buffer) { status_t MyOpusExtractor::verifyOpusComments(MediaBufferBase *buffer) {
// add artificial framing bit so we can reuse _vorbis_unpack_comment // add artificial framing bit so we can reuse _vorbis_unpack_comment
int32_t commentSize = buffer->range_length() + 1; int32_t commentSize = buffer->range_length() + 1;
TmpData commentDataHolder(commentSize); auto tmp = heapbuffer<uint8_t>(commentSize);
uint8_t *commentData = commentDataHolder.data; uint8_t *commentData = tmp.get();
if (commentData == nullptr) { if (commentData == nullptr) {
return ERROR_MALFORMED; return ERROR_MALFORMED;
} }

@ -0,0 +1,32 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef EXTRACTOR_UTILS_H_
#define EXTRACTOR_UTILS_H_
#include <memory>
namespace android {
template <class T>
std::unique_ptr<T[]> heapbuffer(size_t size) {
return std::unique_ptr<T[]>(new (std::nothrow) T[size]);
}
} // namespace android
#endif // UTILS_H_

@ -24,11 +24,12 @@
namespace android { namespace android {
bool MakeAVCCodecSpecificData(MetaDataBase &meta, const sp<ABuffer> &accessUnit) { bool MakeAVCCodecSpecificData(MetaDataBase &meta, const uint8_t *data, size_t size) {
int32_t width; int32_t width;
int32_t height; int32_t height;
int32_t sarWidth; int32_t sarWidth;
int32_t sarHeight; int32_t sarHeight;
sp<ABuffer> accessUnit = new ABuffer((void*)data, size);
sp<ABuffer> csd = MakeAVCCodecSpecificData(accessUnit, &width, &height, &sarWidth, &sarHeight); sp<ABuffer> csd = MakeAVCCodecSpecificData(accessUnit, &width, &height, &sarWidth, &sarHeight);
if (csd == nullptr) { if (csd == nullptr) {
return false; return false;

@ -48,6 +48,7 @@ C2SoftFlacDecoder::C2SoftFlacDecoder(const char *name, c2_node_id_t id)
} }
C2SoftFlacDecoder::~C2SoftFlacDecoder() { C2SoftFlacDecoder::~C2SoftFlacDecoder() {
delete mFLACDecoder;
} }
c2_status_t C2SoftFlacDecoder::onInit() { c2_status_t C2SoftFlacDecoder::onInit() {
@ -77,6 +78,9 @@ c2_status_t C2SoftFlacDecoder::onFlush_sm() {
} }
status_t C2SoftFlacDecoder::initDecoder() { status_t C2SoftFlacDecoder::initDecoder() {
if (mFLACDecoder) {
delete mFLACDecoder;
}
mFLACDecoder = FLACDecoder::Create(); mFLACDecoder = FLACDecoder::Create();
if (!mFLACDecoder) { if (!mFLACDecoder) {
ALOGE("initDecoder: failed to create FLACDecoder"); ALOGE("initDecoder: failed to create FLACDecoder");

@ -46,7 +46,7 @@ private:
kMaxBlockSize = 4096 kMaxBlockSize = 4096
}; };
sp<FLACDecoder> mFLACDecoder; FLACDecoder *mFLACDecoder;
FLAC__StreamMetadata_StreamInfo mStreamInfo; FLAC__StreamMetadata_StreamInfo mStreamInfo;
bool mSignalledError; bool mSignalledError;
bool mSignalledOutputEos; bool mSignalledOutputEos;

@ -57,6 +57,7 @@ SoftFlacDecoder::SoftFlacDecoder(
SoftFlacDecoder::~SoftFlacDecoder() { SoftFlacDecoder::~SoftFlacDecoder() {
ALOGV("dtor:"); ALOGV("dtor:");
delete mFLACDecoder;
} }
void SoftFlacDecoder::initPorts() { void SoftFlacDecoder::initPorts() {

@ -50,7 +50,7 @@ private:
kNumOutputBuffers = 4, kNumOutputBuffers = 4,
}; };
sp<FLACDecoder> mFLACDecoder; FLACDecoder *mFLACDecoder;
FLAC__StreamMetadata_StreamInfo mStreamInfo; FLAC__StreamMetadata_StreamInfo mStreamInfo;
bool mHasStreamInfo; bool mHasStreamInfo;
size_t mInputBufferCount; size_t mInputBufferCount;

@ -220,9 +220,10 @@ static void copyMultiCh24(
} }
// static // static
sp<FLACDecoder> FLACDecoder::Create() { FLACDecoder *FLACDecoder::Create() {
sp<FLACDecoder> decoder = new FLACDecoder(); FLACDecoder *decoder = new (std::nothrow) FLACDecoder();
if (decoder->init() != OK) { if (decoder == NULL || decoder->init() != OK) {
delete decoder;
return NULL; return NULL;
} }
return decoder; return decoder;

@ -26,14 +26,14 @@
namespace android { namespace android {
// packet based FLAC decoder, wrapps libFLAC stream decoder. // packet based FLAC decoder, wrapps libFLAC stream decoder.
class FLACDecoder : public RefBase { class FLACDecoder {
public: public:
enum { enum {
kMaxChannels = 8, kMaxChannels = 8,
}; };
static sp<FLACDecoder> Create(); static FLACDecoder *Create();
FLAC__StreamMetadata_StreamInfo getStreamInfo() const { FLAC__StreamMetadata_StreamInfo getStreamInfo() const {
return mStreamInfo; return mStreamInfo;
@ -43,10 +43,10 @@ public:
status_t decodeOneFrame(const uint8_t *inBuffer, size_t inBufferLen, status_t decodeOneFrame(const uint8_t *inBuffer, size_t inBufferLen,
short *outBuffer, size_t *outBufferLen); short *outBuffer, size_t *outBufferLen);
void flush(); void flush();
virtual ~FLACDecoder();
protected: protected:
FLACDecoder(); FLACDecoder();
virtual ~FLACDecoder() override;
private: private:
// stream properties // stream properties

@ -23,7 +23,7 @@
namespace android { namespace android {
struct ABuffer; struct ABuffer;
bool MakeAVCCodecSpecificData(MetaDataBase &meta, const sp<ABuffer> &accessUnit); bool MakeAVCCodecSpecificData(MetaDataBase &meta, const uint8_t *data, size_t size);
bool MakeAACCodecSpecificData(MetaDataBase &meta, unsigned profile, unsigned sampling_freq_index, bool MakeAACCodecSpecificData(MetaDataBase &meta, unsigned profile, unsigned sampling_freq_index,
unsigned channel_configuration); unsigned channel_configuration);

@ -634,7 +634,7 @@ sp<ABuffer> ElementaryStreamQueue::dequeueAccessUnit() {
if (mFormat == NULL) { if (mFormat == NULL) {
mFormat = new MetaData; mFormat = new MetaData;
if (!MakeAVCCodecSpecificData(*mFormat, accessUnit)) { if (!MakeAVCCodecSpecificData(*mFormat, accessUnit->data(), accessUnit->size())) {
mFormat.clear(); mFormat.clear();
} }
} }
@ -1010,7 +1010,7 @@ sp<ABuffer> ElementaryStreamQueue::dequeueAccessUnitH264() {
} }
if (mFormat == NULL) { if (mFormat == NULL) {
mFormat = new MetaData; mFormat = new MetaData;
if (!MakeAVCCodecSpecificData(*mFormat, mBuffer)) { if (!MakeAVCCodecSpecificData(*mFormat, mBuffer->data(), mBuffer->size())) {
ALOGW("Creating dummy AVC format for scrambled content"); ALOGW("Creating dummy AVC format for scrambled content");
mFormat = new MetaData; mFormat = new MetaData;
mFormat->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC); mFormat->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
@ -1172,7 +1172,9 @@ sp<ABuffer> ElementaryStreamQueue::dequeueAccessUnitH264() {
if (mFormat == NULL) { if (mFormat == NULL) {
mFormat = new MetaData; mFormat = new MetaData;
if (!MakeAVCCodecSpecificData(*mFormat, accessUnit)) { if (!MakeAVCCodecSpecificData(*mFormat,
accessUnit->data(),
accessUnit->size())) {
mFormat.clear(); mFormat.clear();
} }
} }

Loading…
Cancel
Save