Loading media/libmedia/NdkWrapper.cpp +46 −3 Original line number Diff line number Diff line Loading @@ -81,11 +81,16 @@ static const char *AMediaFormatKeyGroupInt32[] = { AMEDIAFORMAT_KEY_STRIDE, AMEDIAFORMAT_KEY_TRACK_ID, AMEDIAFORMAT_KEY_WIDTH, AMEDIAFORMAT_KEY_DISPLAY_HEIGHT, AMEDIAFORMAT_KEY_DISPLAY_WIDTH, AMEDIAFORMAT_KEY_TEMPORAL_LAYER_ID, AMEDIAFORMAT_KEY_TRACK_INDEX, }; static const char *AMediaFormatKeyGroupInt64[] = { AMEDIAFORMAT_KEY_DURATION, AMEDIAFORMAT_KEY_REPEAT_PREVIOUS_FRAME_AFTER, AMEDIAFORMAT_KEY_TIME_US, }; static const char *AMediaFormatKeyGroupString[] = { Loading @@ -96,6 +101,14 @@ static const char *AMediaFormatKeyGroupString[] = { static const char *AMediaFormatKeyGroupBuffer[] = { AMEDIAFORMAT_KEY_HDR_STATIC_INFO, AMEDIAFORMAT_KEY_SEI, AMEDIAFORMAT_KEY_MPEG_USER_DATA, }; static const char *AMediaFormatKeyGroupCsd[] = { AMEDIAFORMAT_KEY_CSD_0, AMEDIAFORMAT_KEY_CSD_1, AMEDIAFORMAT_KEY_CSD_2, }; static const char *AMediaFormatKeyGroupRect[] = { Loading @@ -111,6 +124,10 @@ static const char *AMediaFormatKeyGroupFloatInt32[] = { static status_t translateErrorCode(media_status_t err) { if (err == AMEDIA_OK) { return OK; } else if (err == AMEDIA_ERROR_END_OF_STREAM) { return ERROR_END_OF_STREAM; } else if (err == AMEDIA_ERROR_IO) { return ERROR_IO; } else if (err == AMEDIACODEC_INFO_TRY_AGAIN_LATER) { return -EAGAIN; } Loading Loading @@ -303,11 +320,19 @@ AMediaFormat *AMediaFormatWrapper::getAMediaFormat() const { } sp<AMessage> AMediaFormatWrapper::toAMessage() const { sp<AMessage> msg; writeToAMessage(msg); return msg; } void AMediaFormatWrapper::writeToAMessage(sp<AMessage> &msg) const { if (mAMediaFormat == NULL) { return NULL; msg = NULL; } sp<AMessage> msg = new AMessage; if (msg == NULL) { msg = new AMessage; } for (auto& key : AMediaFormatKeyGroupInt32) { int32_t val; if (getInt32(key, &val)) { Loading @@ -334,6 +359,16 @@ sp<AMessage> AMediaFormatWrapper::toAMessage() const { msg->setBuffer(key, buffer); } } for (auto& key : AMediaFormatKeyGroupCsd) { void *data; size_t size; if (getBuffer(key, &data, &size)) { sp<ABuffer> buffer = ABuffer::CreateAsCopy(data, size); buffer->meta()->setInt32(AMEDIAFORMAT_KEY_CSD, 1); buffer->meta()->setInt64(AMEDIAFORMAT_KEY_TIME_US, 0); msg->setBuffer(key, buffer); } } for (auto& key : AMediaFormatKeyGroupRect) { int32_t left, top, right, bottom; if (getRect(key, &left, &top, &right, &bottom)) { Loading @@ -351,7 +386,6 @@ sp<AMessage> AMediaFormatWrapper::toAMessage() const { } } } return msg; } const char* AMediaFormatWrapper::toString() const { Loading Loading @@ -1150,6 +1184,15 @@ int64_t AMediaExtractorWrapper::getSampleTime() { return AMediaExtractor_getSampleTime(mAMediaExtractor); } status_t AMediaExtractorWrapper::getSampleFormat(sp<AMediaFormatWrapper> &formatWrapper) { if (mAMediaExtractor == NULL) { return DEAD_OBJECT; } AMediaFormat *format = AMediaFormat_new(); formatWrapper = new AMediaFormatWrapper(format); return translateErrorCode(AMediaExtractor_getSampleFormat(mAMediaExtractor, format)); } int64_t AMediaExtractorWrapper::getCachedDuration() { if (mAMediaExtractor == NULL) { return -1; Loading media/libmedia/include/media/NdkWrapper.h +4 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ struct AMessage; class MetaData; struct AMediaFormatWrapper : public RefBase { static sp<AMediaFormatWrapper> Create(const sp<AMessage> &message); AMediaFormatWrapper(); Loading @@ -54,6 +55,7 @@ struct AMediaFormatWrapper : public RefBase { AMediaFormat *getAMediaFormat() const; sp<AMessage> toAMessage() const ; void writeToAMessage(sp<AMessage>&) const ; const char* toString() const ; status_t release(); Loading Loading @@ -313,6 +315,8 @@ struct AMediaExtractorWrapper : public RefBase { int64_t getSampleTime(); status_t getSampleFormat(sp<AMediaFormatWrapper> &formatWrapper); int64_t getCachedDuration(); bool advance(); Loading Loading
media/libmedia/NdkWrapper.cpp +46 −3 Original line number Diff line number Diff line Loading @@ -81,11 +81,16 @@ static const char *AMediaFormatKeyGroupInt32[] = { AMEDIAFORMAT_KEY_STRIDE, AMEDIAFORMAT_KEY_TRACK_ID, AMEDIAFORMAT_KEY_WIDTH, AMEDIAFORMAT_KEY_DISPLAY_HEIGHT, AMEDIAFORMAT_KEY_DISPLAY_WIDTH, AMEDIAFORMAT_KEY_TEMPORAL_LAYER_ID, AMEDIAFORMAT_KEY_TRACK_INDEX, }; static const char *AMediaFormatKeyGroupInt64[] = { AMEDIAFORMAT_KEY_DURATION, AMEDIAFORMAT_KEY_REPEAT_PREVIOUS_FRAME_AFTER, AMEDIAFORMAT_KEY_TIME_US, }; static const char *AMediaFormatKeyGroupString[] = { Loading @@ -96,6 +101,14 @@ static const char *AMediaFormatKeyGroupString[] = { static const char *AMediaFormatKeyGroupBuffer[] = { AMEDIAFORMAT_KEY_HDR_STATIC_INFO, AMEDIAFORMAT_KEY_SEI, AMEDIAFORMAT_KEY_MPEG_USER_DATA, }; static const char *AMediaFormatKeyGroupCsd[] = { AMEDIAFORMAT_KEY_CSD_0, AMEDIAFORMAT_KEY_CSD_1, AMEDIAFORMAT_KEY_CSD_2, }; static const char *AMediaFormatKeyGroupRect[] = { Loading @@ -111,6 +124,10 @@ static const char *AMediaFormatKeyGroupFloatInt32[] = { static status_t translateErrorCode(media_status_t err) { if (err == AMEDIA_OK) { return OK; } else if (err == AMEDIA_ERROR_END_OF_STREAM) { return ERROR_END_OF_STREAM; } else if (err == AMEDIA_ERROR_IO) { return ERROR_IO; } else if (err == AMEDIACODEC_INFO_TRY_AGAIN_LATER) { return -EAGAIN; } Loading Loading @@ -303,11 +320,19 @@ AMediaFormat *AMediaFormatWrapper::getAMediaFormat() const { } sp<AMessage> AMediaFormatWrapper::toAMessage() const { sp<AMessage> msg; writeToAMessage(msg); return msg; } void AMediaFormatWrapper::writeToAMessage(sp<AMessage> &msg) const { if (mAMediaFormat == NULL) { return NULL; msg = NULL; } sp<AMessage> msg = new AMessage; if (msg == NULL) { msg = new AMessage; } for (auto& key : AMediaFormatKeyGroupInt32) { int32_t val; if (getInt32(key, &val)) { Loading @@ -334,6 +359,16 @@ sp<AMessage> AMediaFormatWrapper::toAMessage() const { msg->setBuffer(key, buffer); } } for (auto& key : AMediaFormatKeyGroupCsd) { void *data; size_t size; if (getBuffer(key, &data, &size)) { sp<ABuffer> buffer = ABuffer::CreateAsCopy(data, size); buffer->meta()->setInt32(AMEDIAFORMAT_KEY_CSD, 1); buffer->meta()->setInt64(AMEDIAFORMAT_KEY_TIME_US, 0); msg->setBuffer(key, buffer); } } for (auto& key : AMediaFormatKeyGroupRect) { int32_t left, top, right, bottom; if (getRect(key, &left, &top, &right, &bottom)) { Loading @@ -351,7 +386,6 @@ sp<AMessage> AMediaFormatWrapper::toAMessage() const { } } } return msg; } const char* AMediaFormatWrapper::toString() const { Loading Loading @@ -1150,6 +1184,15 @@ int64_t AMediaExtractorWrapper::getSampleTime() { return AMediaExtractor_getSampleTime(mAMediaExtractor); } status_t AMediaExtractorWrapper::getSampleFormat(sp<AMediaFormatWrapper> &formatWrapper) { if (mAMediaExtractor == NULL) { return DEAD_OBJECT; } AMediaFormat *format = AMediaFormat_new(); formatWrapper = new AMediaFormatWrapper(format); return translateErrorCode(AMediaExtractor_getSampleFormat(mAMediaExtractor, format)); } int64_t AMediaExtractorWrapper::getCachedDuration() { if (mAMediaExtractor == NULL) { return -1; Loading
media/libmedia/include/media/NdkWrapper.h +4 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ struct AMessage; class MetaData; struct AMediaFormatWrapper : public RefBase { static sp<AMediaFormatWrapper> Create(const sp<AMessage> &message); AMediaFormatWrapper(); Loading @@ -54,6 +55,7 @@ struct AMediaFormatWrapper : public RefBase { AMediaFormat *getAMediaFormat() const; sp<AMessage> toAMessage() const ; void writeToAMessage(sp<AMessage>&) const ; const char* toString() const ; status_t release(); Loading Loading @@ -313,6 +315,8 @@ struct AMediaExtractorWrapper : public RefBase { int64_t getSampleTime(); status_t getSampleFormat(sp<AMediaFormatWrapper> &formatWrapper); int64_t getCachedDuration(); bool advance(); Loading