Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-stagefright-plugins: Commit

external/stagefright-plugins


Commit MetaInfo

Revisiond32297dbe0a712d9b1a2d4cfd2d0d580128ff84c (tree)
Time2019-12-22 00:53:28
AuthorMichael Goffioul <michael.goffioul@gmai...>
CommiterChih-Wei Huang

Log Message

Port to q-x86

Change Summary

Incremental Difference

--- a/extractor/Android.mk
+++ b/extractor/Android.mk
@@ -7,9 +7,9 @@ LOCAL_SRC_FILES := \
77
88 LOCAL_SHARED_LIBRARIES += \
99 libbinder \
10- libmediaextractor \
1110 libffmpeg_utils \
12- liblog \
11+ libmediandk \
12+ liblog
1313
1414 LOCAL_MODULE:= libffmpeg_extractor
1515 LOCAL_MODULE_RELATIVE_PATH := extractors
--- a/extractor/FFmpegExtractor.cpp
+++ b/extractor/FFmpegExtractor.cpp
@@ -26,8 +26,7 @@
2626 #include <utils/misc.h>
2727 #include <utils/String8.h>
2828 #include <cutils/properties.h>
29-#include <media/DataSource.h>
30-#include <media/MediaSource.h>
29+#include <media/DataSourceBase.h>
3130 #include <media/stagefright/foundation/ABitReader.h>
3231 #include <media/stagefright/foundation/ABuffer.h>
3332 #include <media/stagefright/foundation/ADebug.h>
@@ -38,7 +37,6 @@
3837 #include <media/stagefright/foundation/ADebug.h>
3938 #include <media/stagefright/MediaDefs.h>
4039 #include <media/stagefright/MediaErrors.h>
41-#include <media/stagefright/MetaData.h>
4240 #include <media/stagefright/Utils.h>
4341
4442 #include "utils/codec_utils.h"
@@ -71,17 +69,17 @@ enum {
7169 namespace android {
7270
7371 static const char *findMatchingContainer(const char *name);
74-static MediaExtractor *CreateFFMPEGExtractor(DataSourceBase *source, void *meta);
72+static CMediaExtractor *CreateFFMPEGExtractor(CDataSource *source, void *meta);
7573
76-struct FFmpegSource : public MediaTrack {
74+struct FFmpegSource : public MediaTrackHelper {
7775 FFmpegSource(FFmpegExtractor *extractor, size_t index);
7876
79- virtual status_t start(MetaDataBase *params);
80- virtual status_t stop();
81- virtual status_t getFormat(MetaDataBase &meta);
77+ virtual media_status_t start();
78+ virtual media_status_t stop();
79+ virtual media_status_t getFormat(AMediaFormat *meta);
8280
83- virtual status_t read(
84- MediaBufferBase **buffer, const ReadOptions *options);
81+ virtual media_status_t read(
82+ MediaBufferHelper **buffer, const ReadOptions *options);
8583
8684 protected:
8785 virtual ~FFmpegSource();
@@ -113,7 +111,7 @@ private:
113111
114112 ////////////////////////////////////////////////////////////////////////////////
115113
116-FFmpegExtractor::FFmpegExtractor(DataSourceBase *source, const sp<AMessage> &meta)
114+FFmpegExtractor::FFmpegExtractor(DataSourceHelper *source, const sp<AMessage> &meta)
117115 : mDataSource(source),
118116 mInitCheck(NO_INIT),
119117 mFormatCtx(NULL),
@@ -121,6 +119,7 @@ FFmpegExtractor::FFmpegExtractor(DataSourceBase *source, const sp<AMessage> &met
121119 mParsedMetadata(false) {
122120 ALOGV("FFmpegExtractor::FFmpegExtractor");
123121
122+ mMeta = AMediaFormat_new();
124123 fetchStuffsFromSniffedMeta(meta);
125124
126125 packet_queue_init(&mVideoQ);
@@ -155,13 +154,18 @@ FFmpegExtractor::~FFmpegExtractor() {
155154
156155 Mutex::Autolock autoLock(mLock);
157156 deInitStreams();
157+
158+ for (auto& trackInfo : mTracks) {
159+ AMediaFormat_delete(trackInfo.mMeta);
160+ }
161+ AMediaFormat_delete(mMeta);
158162 }
159163
160164 size_t FFmpegExtractor::countTracks() {
161165 return mInitCheck == OK ? mTracks.size() : 0;
162166 }
163167
164-MediaTrack* FFmpegExtractor::getTrack(size_t index) {
168+MediaTrackHelper* FFmpegExtractor::getTrack(size_t index) {
165169 ALOGV("FFmpegExtractor::getTrack[%zu]", index);
166170
167171 if (mInitCheck != OK) {
@@ -175,33 +179,33 @@ MediaTrack* FFmpegExtractor::getTrack(size_t index) {
175179 return new FFmpegSource(this, index);
176180 }
177181
178-status_t FFmpegExtractor::getTrackMetaData(MetaDataBase &meta, size_t index, uint32_t flags __unused) {
182+media_status_t FFmpegExtractor::getTrackMetaData(AMediaFormat *meta, size_t index, uint32_t flags __unused) {
179183 ALOGV("FFmpegExtractor::getTrackMetaData[%zu]", index);
180184
181185 if (mInitCheck != OK) {
182- return UNKNOWN_ERROR;
186+ return AMEDIA_ERROR_UNKNOWN;
183187 }
184188
185189 if (index >= mTracks.size()) {
186- return UNKNOWN_ERROR;
190+ return AMEDIA_ERROR_UNKNOWN;
187191 }
188192
189193 /* Quick and dirty, just get a frame 1/4 in */
190194 if (mTracks.itemAt(index).mIndex == mVideoStreamIdx &&
191195 mFormatCtx->duration != AV_NOPTS_VALUE) {
192- mTracks.editItemAt(index).mMeta.setInt64(
193- kKeyThumbnailTime, mFormatCtx->duration / 4);
196+ AMediaFormat_setInt64(mTracks.editItemAt(index).mMeta,
197+ AMEDIAFORMAT_KEY_THUMBNAIL_TIME, mFormatCtx->duration / 4);
194198 }
195199
196- meta = mTracks.itemAt(index).mMeta;
197- return OK;
200+ AMediaFormat_copy(meta, mTracks.itemAt(index).mMeta);
201+ return AMEDIA_OK;
198202 }
199203
200-status_t FFmpegExtractor::getMetaData(MetaDataBase &meta) {
204+media_status_t FFmpegExtractor::getMetaData(AMediaFormat *meta) {
201205 ALOGV("FFmpegExtractor::getMetaData");
202206
203207 if (mInitCheck != OK) {
204- return UNKNOWN_ERROR;
208+ return AMEDIA_ERROR_UNKNOWN;
205209 }
206210
207211 if (!mParsedMetadata) {
@@ -209,8 +213,8 @@ status_t FFmpegExtractor::getMetaData(MetaDataBase &meta) {
209213 mParsedMetadata = true;
210214 }
211215
212- meta = mMeta;
213- return OK;
216+ AMediaFormat_copy(meta, mMeta);
217+ return AMEDIA_OK;
214218 }
215219
216220 uint32_t FFmpegExtractor::flags() const {
@@ -364,10 +368,10 @@ bool FFmpegExtractor::is_codec_supported(enum AVCodecID codec_id)
364368 return supported;
365369 }
366370
367-status_t FFmpegExtractor::setVideoFormat(AVStream *stream, MetaDataBase &meta)
371+media_status_t FFmpegExtractor::setVideoFormat(AVStream *stream, AMediaFormat *meta)
368372 {
369373 AVCodecContext *avctx = NULL;
370- status_t ret = UNKNOWN_ERROR;
374+ media_status_t ret = AMEDIA_ERROR_UNKNOWN;
371375
372376 avctx = stream->codec;
373377 CHECK_EQ((int)avctx->codec_type, (int)AVMEDIA_TYPE_VIDEO);
@@ -428,16 +432,16 @@ status_t FFmpegExtractor::setVideoFormat(AVStream *stream, MetaDataBase &meta)
428432 default:
429433 ALOGD("unsupported video codec (id: %d, name: %s), but give it a chance",
430434 avctx->codec_id, avcodec_get_name(avctx->codec_id));
431- meta.setInt32(kKeyCodecId, avctx->codec_id);
432- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_FFMPEG);
435+ AMediaFormat_setInt32(meta, "codec-id", avctx->codec_id);
436+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_FFMPEG);
433437 if (avctx->extradata_size > 0) {
434- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
438+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
435439 }
436440 //CHECK(!"Should not be here. Unsupported codec.");
437441 break;
438442 }
439443
440- if (ret == OK) {
444+ if (ret == AMEDIA_OK) {
441445 // rotation
442446 double theta = get_rotation(stream);
443447 int rotationDegrees = 0;
@@ -450,11 +454,11 @@ status_t FFmpegExtractor::setVideoFormat(AVStream *stream, MetaDataBase &meta)
450454 rotationDegrees = 270;
451455 }
452456 if (rotationDegrees != 0) {
453- meta.setInt32(kKeyRotation, rotationDegrees);
457+ AMediaFormat_setInt32(meta, AMEDIAFORMAT_KEY_ROTATION, rotationDegrees);
454458 }
455459 }
456460
457- if (ret == OK) {
461+ if (ret == AMEDIA_OK) {
458462 float aspect_ratio;
459463 int width, height;
460464
@@ -474,28 +478,28 @@ status_t FFmpegExtractor::setVideoFormat(AVStream *stream, MetaDataBase &meta)
474478 ALOGI("width: %d, height: %d, bit_rate: % " PRId64 " aspect ratio: %f",
475479 avctx->width, avctx->height, avctx->bit_rate, aspect_ratio);
476480
477- meta.setInt32(kKeyWidth, avctx->width);
478- meta.setInt32(kKeyHeight, avctx->height);
481+ AMediaFormat_setInt32(meta, AMEDIAFORMAT_KEY_WIDTH, avctx->width);
482+ AMediaFormat_setInt32(meta, AMEDIAFORMAT_KEY_HEIGHT, avctx->height);
479483 if ((width > 0) && (height > 0) &&
480484 ((avctx->width != width || avctx->height != height))) {
481- meta.setInt32(kKeySARWidth, width);
482- meta.setInt32(kKeySARHeight, height);
485+ AMediaFormat_setInt32(meta, AMEDIAFORMAT_KEY_SAR_WIDTH, width);
486+ AMediaFormat_setInt32(meta, AMEDIAFORMAT_KEY_SAR_HEIGHT, height);
483487 ALOGI("SAR width: %d, SAR height: %d", width, height);
484488 }
485489 if (avctx->bit_rate > 0) {
486- meta.setInt32(kKeyBitRate, avctx->bit_rate);
490+ AMediaFormat_setInt32(meta, AMEDIAFORMAT_KEY_BIT_RATE, avctx->bit_rate);
487491 }
488- meta.setCString('ffmt', findMatchingContainer(mFormatCtx->iformat->name));
492+ AMediaFormat_setString(meta, "file-format", findMatchingContainer(mFormatCtx->iformat->name));
489493 setDurationMetaData(stream, meta);
490494 }
491495
492- return OK;
496+ return AMEDIA_OK;
493497 }
494498
495-status_t FFmpegExtractor::setAudioFormat(AVStream *stream, MetaDataBase &meta)
499+media_status_t FFmpegExtractor::setAudioFormat(AVStream *stream, AMediaFormat *meta)
496500 {
497501 AVCodecContext *avctx = NULL;
498- status_t ret = UNKNOWN_ERROR;
502+ media_status_t ret = AMEDIA_ERROR_UNKNOWN;
499503
500504 avctx = stream->codec;
501505 CHECK_EQ((int)avctx->codec_type, (int)AVMEDIA_TYPE_AUDIO);
@@ -546,17 +550,17 @@ status_t FFmpegExtractor::setAudioFormat(AVStream *stream, MetaDataBase &meta)
546550 default:
547551 ALOGD("unsupported audio codec (id: %d, name: %s), but give it a chance",
548552 avctx->codec_id, avcodec_get_name(avctx->codec_id));
549- meta.setInt32(kKeyCodecId, avctx->codec_id);
550- meta.setInt32(kKeyCodedSampleBits, avctx->bits_per_coded_sample);
551- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_FFMPEG);
553+ AMediaFormat_setInt32(meta, "codec-id", avctx->codec_id);
554+ AMediaFormat_setInt32(meta, "coded-sample-bits", avctx->bits_per_coded_sample);
555+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_FFMPEG);
552556 if (avctx->extradata_size > 0) {
553- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
557+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
554558 }
555559 //CHECK(!"Should not be here. Unsupported codec.");
556560 break;
557561 }
558562
559- if (ret == OK) {
563+ if (ret == AMEDIA_OK) {
560564 ALOGD("bit_rate: %" PRId64 ", sample_rate: %d, channels: %d, "
561565 "bits_per_coded_sample: %d, block_align: %d "
562566 "bits_per_raw_sample: %d, sample_format: %d",
@@ -564,24 +568,24 @@ status_t FFmpegExtractor::setAudioFormat(AVStream *stream, MetaDataBase &meta)
564568 avctx->bits_per_coded_sample, avctx->block_align,
565569 avctx->bits_per_raw_sample, avctx->sample_fmt);
566570
567- meta.setInt32(kKeyChannelCount, avctx->channels);
568- meta.setInt32(kKeyBitRate, avctx->bit_rate);
571+ AMediaFormat_setInt32(meta, AMEDIAFORMAT_KEY_CHANNEL_COUNT, avctx->channels);
572+ AMediaFormat_setInt32(meta, AMEDIAFORMAT_KEY_BIT_RATE, avctx->bit_rate);
569573 int32_t bits = avctx->bits_per_raw_sample > 0 ?
570574 avctx->bits_per_raw_sample :
571575 av_get_bytes_per_sample(avctx->sample_fmt) * 8;
572- meta.setInt32(kKeyBitsPerRawSample, bits);
573- meta.setInt32(kKeySampleRate, avctx->sample_rate);
574- meta.setInt32(kKeyBlockAlign, avctx->block_align);
575- meta.setInt32(kKeySampleFormat, avctx->sample_fmt);
576- //meta.setInt32(kKeyPcmEncoding, sampleFormatToEncoding(avctx->sample_fmt));
577- meta.setCString('ffmt', findMatchingContainer(mFormatCtx->iformat->name));
576+ AMediaFormat_setInt32(meta, "bits-per-raw-sample", bits);
577+ AMediaFormat_setInt32(meta, "sample-rate", avctx->sample_rate);
578+ AMediaFormat_setInt32(meta, "block-align", avctx->block_align);
579+ AMediaFormat_setInt32(meta, "sample-format", avctx->sample_fmt);
580+ //AMediaFormat_setInt32(meta, AMEDIAFORMAT_KEY_PCM_ENCODING, sampleFormatToEncoding(avctx->sample_fmt));
581+ AMediaFormat_setString(meta, "file-format", findMatchingContainer(mFormatCtx->iformat->name));
578582 setDurationMetaData(stream, meta);
579583 }
580584
581- return OK;
585+ return AMEDIA_OK;
582586 }
583587
584-void FFmpegExtractor::setDurationMetaData(AVStream *stream, MetaDataBase &meta)
588+void FFmpegExtractor::setDurationMetaData(AVStream *stream, AMediaFormat *meta)
585589 {
586590 AVCodecContext *avctx = stream->codec;
587591
@@ -594,10 +598,10 @@ void FFmpegExtractor::setDurationMetaData(AVStream *stream, MetaDataBase &meta)
594598 } else {
595599 ALOGV("%s startTime:N/A", s);
596600 }
597- meta.setInt64(kKeyDuration, duration);
601+ AMediaFormat_setInt64(meta, AMEDIAFORMAT_KEY_DURATION, duration);
598602 } else {
599603 // default when no stream duration
600- meta.setInt64(kKeyDuration, mFormatCtx->duration);
604+ AMediaFormat_setInt64(meta, AMEDIAFORMAT_KEY_DURATION, mFormatCtx->duration);
601605 }
602606 }
603607
@@ -638,7 +642,7 @@ int FFmpegExtractor::stream_component_open(int stream_index)
638642 av_get_codec_tag_string(tagbuf, sizeof(tagbuf), avctx->codec_tag);
639643 ALOGV("Tag %s/0x%08x with codec(%s)\n", tagbuf, avctx->codec_tag, avcodec_get_name(avctx->codec_id));
640644
641- MetaDataBase meta;
645+ AMediaFormat *meta = AMediaFormat_new();
642646
643647 switch (avctx->codec_type) {
644648 case AVMEDIA_TYPE_VIDEO:
@@ -666,7 +670,7 @@ int FFmpegExtractor::stream_component_open(int stream_index)
666670 ALOGV("video stream no extradata, but we can ignore it.");
667671 }
668672 #endif
669- if (setVideoFormat(mVideoStream, meta) != OK) {
673+ if (setVideoFormat(mVideoStream, meta) != AMEDIA_OK) {
670674 ALOGE("setVideoFormat failed");
671675 return -1;
672676 }
@@ -707,7 +711,7 @@ int FFmpegExtractor::stream_component_open(int stream_index)
707711 ALOGV("audio stream no extradata, but we can ignore it.");
708712 }
709713 #endif
710- if (setAudioFormat(mAudioStream, meta) != OK) {
714+ if (setAudioFormat(mAudioStream, meta) != AMEDIA_OK) {
711715 ALOGE("setAudioFormat failed");
712716 return -1;
713717 }
@@ -800,7 +804,7 @@ void FFmpegExtractor::reachedEOS(enum AVMediaType media_type)
800804
801805 /* seek in the stream */
802806 int FFmpegExtractor::stream_seek(int64_t pos, enum AVMediaType media_type,
803- MediaSource::ReadOptions::SeekMode mode)
807+ MediaTrackHelper::ReadOptions::SeekMode mode)
804808 {
805809 Mutex::Autolock _l(mLock);
806810
@@ -826,19 +830,19 @@ int FFmpegExtractor::stream_seek(int64_t pos, enum AVMediaType media_type,
826830 //}
827831
828832 switch (mode) {
829- case MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC:
833+ case MediaTrackHelper::ReadOptions::SEEK_PREVIOUS_SYNC:
830834 mSeekMin = 0;
831835 mSeekMax = mSeekPos;
832836 break;
833- case MediaSource::ReadOptions::SEEK_NEXT_SYNC:
837+ case MediaTrackHelper::ReadOptions::SEEK_NEXT_SYNC:
834838 mSeekMin = mSeekPos;
835839 mSeekMax = INT64_MAX;
836840 break;
837- case MediaSource::ReadOptions::SEEK_CLOSEST_SYNC:
841+ case MediaTrackHelper::ReadOptions::SEEK_CLOSEST_SYNC:
838842 mSeekMin = 0;
839843 mSeekMax = INT64_MAX;
840844 break;
841- case MediaSource::ReadOptions::SEEK_CLOSEST:
845+ case MediaTrackHelper::ReadOptions::SEEK_CLOSEST:
842846 mSeekMin = 0;
843847 mSeekMax = mSeekPos;
844848 break;
@@ -873,7 +877,7 @@ void FFmpegExtractor::fetchStuffsFromSniffedMeta(const sp<AMessage> &meta)
873877 //mime
874878 CHECK(meta->findString("extended-extractor-mime", &mime));
875879 CHECK(mime.c_str() != NULL);
876- mMeta.setCString(kKeyMIMEType, mime.c_str());
880+ AMediaFormat_setString(mMeta, AMEDIAFORMAT_KEY_MIME, mime.c_str());
877881 }
878882
879883 void FFmpegExtractor::setFFmpegDefaultOpts()
@@ -1326,7 +1330,7 @@ FFmpegSource::FFmpegSource(
13261330 mQueue(mExtractor->mTracks.itemAt(index).mQueue),
13271331 mLastPTS(AV_NOPTS_VALUE),
13281332 mTargetTime(AV_NOPTS_VALUE) {
1329- const MetaDataBase& meta = mExtractor->mTracks.itemAt(index).mMeta;
1333+ AMediaFormat *meta = mExtractor->mTracks.itemAt(index).mMeta;
13301334
13311335 {
13321336 AVCodecContext *avctx = mStream->codec;
@@ -1337,10 +1341,9 @@ FFmpegSource::FFmpegSource(
13371341 && avctx->extradata[0] == 1) {
13381342 mIsAVC = true;
13391343
1340- uint32_t type;
1341- const void *data;
1344+ void *data;
13421345 size_t size;
1343- CHECK(meta.findData(kKeyAVCC, &type, &data, &size));
1346+ CHECK(AMediaFormat_getBuffer(meta, AMEDIAFORMAT_KEY_CSD_AVC, &data, &size));
13441347
13451348 const uint8_t *ptr = (const uint8_t *)data;
13461349
@@ -1363,10 +1366,9 @@ FFmpegSource::FFmpegSource(
13631366 * can recognize hvcC by checking if avctx->extradata[0]==1 or not. */
13641367 mIsHEVC = true;
13651368
1366- uint32_t type;
1367- const void *data;
1369+ void *data;
13681370 size_t size;
1369- CHECK(meta.findData(kKeyHVCC, &type, &data, &size));
1371+ CHECK(AMediaFormat_getBuffer(meta, AMEDIAFORMAT_KEY_CSD_HEVC, &data, &size));
13701372
13711373 const uint8_t *ptr = (const uint8_t *)data;
13721374
@@ -1393,25 +1395,26 @@ FFmpegSource::~FFmpegSource() {
13931395 mExtractor = NULL;
13941396 }
13951397
1396-status_t FFmpegSource::start(MetaDataBase * /* params */) {
1398+media_status_t FFmpegSource::start() {
13971399 ALOGV("FFmpegSource::start %s",
13981400 av_get_media_type_string(mMediaType));
1399- return OK;
1401+ mBufferGroup->init(1, 1024, 64);
1402+ return AMEDIA_OK;
14001403 }
14011404
1402-status_t FFmpegSource::stop() {
1405+media_status_t FFmpegSource::stop() {
14031406 ALOGV("FFmpegSource::stop %s",
14041407 av_get_media_type_string(mMediaType));
1405- return OK;
1408+ return AMEDIA_OK;
14061409 }
14071410
1408-status_t FFmpegSource::getFormat(MetaDataBase &meta) {
1409- meta = mExtractor->mTracks.itemAt(mTrackIndex).mMeta;
1410- return OK;
1411+media_status_t FFmpegSource::getFormat(AMediaFormat *meta) {
1412+ AMediaFormat_copy(meta, mExtractor->mTracks.itemAt(mTrackIndex).mMeta);
1413+ return AMEDIA_OK;
14111414 }
14121415
1413-status_t FFmpegSource::read(
1414- MediaBufferBase **buffer, const ReadOptions *options) {
1416+media_status_t FFmpegSource::read(
1417+ MediaBufferHelper **buffer, const ReadOptions *options) {
14151418 *buffer = NULL;
14161419
14171420 AVPacket pkt;
@@ -1422,7 +1425,7 @@ status_t FFmpegSource::read(
14221425 int64_t seekTimeUs = AV_NOPTS_VALUE;
14231426 int64_t timeUs = AV_NOPTS_VALUE;
14241427 int key = 0;
1425- status_t status = OK;
1428+ media_status_t status = AMEDIA_OK;
14261429 int max_negative_time_frame = 100;
14271430
14281431 int64_t startTimeUs = mStream->start_time == AV_NOPTS_VALUE ? 0 :
@@ -1443,7 +1446,7 @@ retry:
14431446 if (packet_queue_get(mQueue, &pkt, 1) < 0) {
14441447 ALOGD("read %s abort reqeust", av_get_media_type_string(mMediaType));
14451448 mExtractor->reachedEOS(mMediaType);
1446- return ERROR_END_OF_STREAM;
1449+ return AMEDIA_ERROR_END_OF_STREAM;
14471450 }
14481451
14491452 if (seeking) {
@@ -1467,7 +1470,7 @@ retry:
14671470 ALOGD("read %s eos pkt", av_get_media_type_string(mMediaType));
14681471 av_packet_unref(&pkt);
14691472 mExtractor->reachedEOS(mMediaType);
1470- return ERROR_END_OF_STREAM;
1473+ return AMEDIA_ERROR_END_OF_STREAM;
14711474 }
14721475
14731476 key = pkt.flags & AV_PKT_FLAG_KEY ? 1 : 0;
@@ -1489,8 +1492,9 @@ retry:
14891492 mFirstKeyPktTimestamp = pktTS;
14901493 }
14911494
1492- MediaBuffer *mediaBuffer = new MediaBuffer(pkt.size + AV_INPUT_BUFFER_PADDING_SIZE);
1493- mediaBuffer->meta_data().clear();
1495+ MediaBufferHelper *mediaBuffer;
1496+ mBufferGroup->acquire_buffer(&mediaBuffer, false, pkt.size + AV_INPUT_BUFFER_PADDING_SIZE);
1497+ AMediaFormat_clear(mediaBuffer->meta_data());
14941498 mediaBuffer->set_range(0, pkt.size);
14951499
14961500 //copy data
@@ -1501,18 +1505,18 @@ retry:
15011505 mediaBuffer->release();
15021506 mediaBuffer = NULL;
15031507 av_packet_unref(&pkt);
1504- return ERROR_MALFORMED;
1508+ return AMEDIA_ERROR_MALFORMED;
15051509 }
15061510
15071511 uint8_t *dst = (uint8_t *)mediaBuffer->data();
15081512 /* Convert H.264 NAL format to annex b */
15091513 status = convertNal2AnnexB(dst, pkt.size, pkt.data, pkt.size, mNALLengthSize);
1510- if (status != OK) {
1514+ if (status != AMEDIA_OK) {
15111515 ALOGE("convertNal2AnnexB failed");
15121516 mediaBuffer->release();
15131517 mediaBuffer = NULL;
15141518 av_packet_unref(&pkt);
1515- return ERROR_MALFORMED;
1519+ return AMEDIA_ERROR_MALFORMED;
15161520 }
15171521 } else {
15181522 memcpy(mediaBuffer->data(), pkt.data, pkt.size);
@@ -1539,7 +1543,7 @@ retry:
15391543 goto retry;
15401544 } else {
15411545 ALOGE("too many negative timestamp packets, abort decoding");
1542- return ERROR_MALFORMED;
1546+ return AMEDIA_ERROR_MALFORMED;
15431547 }
15441548 }
15451549
@@ -1561,14 +1565,14 @@ retry:
15611565 av_get_media_type_string(mMediaType), pkt.size, key);
15621566 #endif
15631567
1564- mediaBuffer->meta_data().setInt64(kKeyTime, timeUs);
1565- mediaBuffer->meta_data().setInt32(kKeyIsSyncFrame, key);
1568+ AMediaFormat_setInt64(mediaBuffer->meta_data(), AMEDIAFORMAT_KEY_TIME_US, timeUs);
1569+ AMediaFormat_setInt32(mediaBuffer->meta_data(), AMEDIAFORMAT_KEY_IS_SYNC_FRAME, key);
15661570
15671571 // deal with seek-to-exact-frame, we might be off a bit and Stagefright will assert on us
15681572 if (seekTimeUs != AV_NOPTS_VALUE && timeUs < seekTimeUs &&
15691573 mode == MediaSource::ReadOptions::SEEK_CLOSEST) {
15701574 mTargetTime = seekTimeUs;
1571- mediaBuffer->meta_data().setInt64(kKeyTargetTime, seekTimeUs);
1575+ AMediaFormat_setInt64(mediaBuffer->meta_data(), AMEDIAFORMAT_KEY_TARGET_TIME, seekTimeUs);
15721576 }
15731577
15741578 if (mTargetTime != AV_NOPTS_VALUE) {
@@ -1576,7 +1580,7 @@ retry:
15761580 mTargetTime = AV_NOPTS_VALUE;
15771581 } else if (nextPTS != AV_NOPTS_VALUE && nextPTS > mTargetTime) {
15781582 ALOGV("adjust target frame time to %" PRId64, timeUs);
1579- mediaBuffer->meta_data().setInt64(kKeyTime, mTargetTime);
1583+ AMediaFormat_setInt64(mediaBuffer->meta_data(), AMEDIAFORMAT_KEY_TIME_US, mTargetTime);
15801584 mTargetTime = AV_NOPTS_VALUE;
15811585 }
15821586 }
@@ -1585,7 +1589,7 @@ retry:
15851589
15861590 av_packet_unref(&pkt);
15871591
1588- return OK;
1592+ return AMEDIA_OK;
15891593 }
15901594
15911595 ////////////////////////////////////////////////////////////////////////////////
@@ -2091,7 +2095,7 @@ fail:
20912095 return container;
20922096 }
20932097
2094-static const char *BetterSniffFFMPEG(DataSourceBase *source,
2098+static const char *BetterSniffFFMPEG(CDataSource *source,
20952099 float *confidence, AMessage *meta)
20962100 {
20972101 const char *ret = NULL;
@@ -2103,7 +2107,7 @@ static const char *BetterSniffFFMPEG(DataSourceBase *source,
21032107 snprintf(url, sizeof(url), "android-source:%p", source);
21042108
21052109 ret = SniffFFMPEGCommon(url, confidence,
2106- (source->flags() & DataSource::kIsCachingDataSource));
2110+ (source->flags(source->handle) & DataSourceBase::kIsCachingDataSource));
21072111 if (ret) {
21082112 meta->setString("extended-extractor-url", url);
21092113 }
@@ -2111,18 +2115,18 @@ static const char *BetterSniffFFMPEG(DataSourceBase *source,
21112115 return ret;
21122116 }
21132117
2114-static const char *LegacySniffFFMPEG(DataSourceBase *source,
2118+static const char *LegacySniffFFMPEG(CDataSource *source,
21152119 float *confidence, AMessage *meta)
21162120 {
21172121 const char *ret = NULL;
21182122 char uri[PATH_MAX] = {0};
21192123 char url[PATH_MAX] = {0};
21202124
2121- if (!source->getUri(uri, sizeof(uri))) {
2125+ if (!source->getUri(source->handle, uri, sizeof(uri))) {
21222126 return NULL;
21232127 }
21242128
2125- if (source->flags() & DataSource::kIsCachingDataSource)
2129+ if (source->flags(source->handle) & DataSourceBase::kIsCachingDataSource)
21262130 return NULL;
21272131
21282132 ALOGV("source url:%s", uri);
@@ -2144,10 +2148,10 @@ static void FreeMeta(void *meta) {
21442148 }
21452149 }
21462150
2147-static MediaExtractor::CreatorFunc
2151+static CreatorFunc
21482152 SniffFFMPEG(
2149- DataSourceBase *source, float *confidence, void **meta,
2150- MediaExtractor::FreeMetaFunc *freeMeta) {
2153+ CDataSource *source, float *confidence, void **meta,
2154+ FreeMetaFunc *freeMeta) {
21512155
21522156 float newConfidence = 0.08f;
21532157
@@ -2209,8 +2213,8 @@ SniffFFMPEG(
22092213 return CreateFFMPEGExtractor;
22102214 }
22112215
2212-static MediaExtractor *CreateFFMPEGExtractor(DataSourceBase *source, void *meta) {
2213- MediaExtractor *ret = NULL;
2216+static CMediaExtractor *CreateFFMPEGExtractor(CDataSource *source, void *meta) {
2217+ CMediaExtractor *ret = NULL;
22142218 sp<AMessage> msg = static_cast<AMessage *>(meta);
22152219 AString mime;
22162220 if (msg.get() && msg->findString("extended-extractor-mime", &mime) && (
@@ -2250,23 +2254,31 @@ static MediaExtractor *CreateFFMPEGExtractor(DataSourceBase *source, void *meta)
22502254 !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_HEVC) ||
22512255 !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_WMA) ||
22522256 !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_FFMPEG))) {
2253- ret = new FFmpegExtractor(source, msg);
2257+ ret = wrap(new FFmpegExtractor(new DataSourceHelper(source), msg));
22542258 }
22552259
22562260 ALOGD("%ssupported mime: %s", (ret ? "" : "un"), mime.c_str());
22572261 return ret;
22582262 }
22592263
2264+static const char* extensions[] = {
2265+ "adts",
2266+ "dm", "m2ts", "mp3d", "wmv", "asf", "flv", ".ra",
2267+ "rm", "rmvb", "ac3", "ape", "dts", "mp1", "mp2",
2268+ "f4v", "hlv", "nrg", "m2v", "swf", "vc1", "vob",
2269+ "divx", "qcp", "ec3"
2270+};
2271+
22602272 extern "C" {
22612273
22622274 __attribute__ ((visibility ("default")))
2263-MediaExtractor::ExtractorDef GETEXTRACTORDEF() {
2275+ExtractorDef GETEXTRACTORDEF() {
22642276 return {
2265- MediaExtractor::EXTRACTORDEF_VERSION,
2277+ EXTRACTORDEF_VERSION,
22662278 UUID("280e1e71-d08b-4d8c-ba03-d775497fc4bc"),
22672279 1, // version
22682280 "FFMPEG Extractor",
2269- SniffFFMPEG
2281+ { .v3 = { SniffFFMPEG, extensions } }
22702282 };
22712283 }
22722284
--- a/extractor/FFmpegExtractor.h
+++ b/extractor/FFmpegExtractor.h
@@ -18,8 +18,9 @@
1818
1919 #define SUPER_EXTRACTOR_H_
2020
21-#include <media/MediaExtractor.h>
22-#include <media/MediaSource.h>
21+#include <media/MediaExtractorPluginApi.h>
22+#include <media/MediaExtractorPluginHelper.h>
23+#include <media/NdkMediaFormat.h>
2324 #include <media/stagefright/foundation/ABase.h>
2425 #include <utils/threads.h>
2526 #include <utils/KeyedVector.h>
@@ -33,16 +34,17 @@ struct AMessage;
3334 class String8;
3435 struct FFmpegSource;
3536
36-struct FFmpegExtractor : public MediaExtractor {
37- FFmpegExtractor(DataSourceBase *source, const sp<AMessage> &meta);
37+struct FFmpegExtractor : public MediaExtractorPluginHelper {
38+ FFmpegExtractor(DataSourceHelper *source, const sp<AMessage> &meta);
3839
3940 virtual size_t countTracks();
40- virtual MediaTrack* getTrack(size_t index);
41- virtual status_t getTrackMetaData(MetaDataBase &meta, size_t index, uint32_t flags);
41+ virtual MediaTrackHelper* getTrack(size_t index);
42+ virtual media_status_t getTrackMetaData(AMediaFormat *meta, size_t index, uint32_t flags);
4243
43- virtual status_t getMetaData(MetaDataBase &meta);
44+ virtual media_status_t getMetaData(AMediaFormat *meta);
4445
4546 virtual uint32_t flags() const;
47+ virtual const char* name() { return "FFmpegExtractor"; }
4648
4749 protected:
4850 virtual ~FFmpegExtractor();
@@ -52,7 +54,7 @@ private:
5254
5355 struct TrackInfo {
5456 int mIndex; //stream index
55- MetaDataBase mMeta;
57+ AMediaFormat *mMeta;
5658 AVStream *mStream;
5759 PacketQueue *mQueue;
5860 };
@@ -63,8 +65,8 @@ private:
6365 mutable Mutex mExtractorMutex;
6466 Condition mCondition;
6567
66- DataSourceBase *mDataSource;
67- MetaDataBase mMeta;
68+ DataSourceHelper *mDataSource;
69+ AMediaFormat *mMeta;
6870 status_t mInitCheck;
6971
7072 char mFilename[PATH_MAX];
@@ -84,7 +86,7 @@ private:
8486 int mPaused;
8587 int mLastPaused;
8688 int mSeekIdx;
87- MediaSource::ReadOptions::SeekMode mSeekMode;
89+ MediaTrackHelper::ReadOptions::SeekMode mSeekMode;
8890 int64_t mSeekPos;
8991 int64_t mSeekMin;
9092 int64_t mSeekMax;
@@ -112,14 +114,14 @@ private:
112114 void setFFmpegDefaultOpts();
113115 void printTime(int64_t time);
114116 bool is_codec_supported(enum AVCodecID codec_id);
115- status_t setVideoFormat(AVStream *stream, MetaDataBase &meta);
116- status_t setAudioFormat(AVStream *stream, MetaDataBase &meta);
117- void setDurationMetaData(AVStream *stream, MetaDataBase &meta);
117+ media_status_t setVideoFormat(AVStream *stream, AMediaFormat *meta);
118+ media_status_t setAudioFormat(AVStream *stream, AMediaFormat *meta);
119+ void setDurationMetaData(AVStream *stream, AMediaFormat *meta);
118120 int stream_component_open(int stream_index);
119121 void stream_component_close(int stream_index);
120122 void reachedEOS(enum AVMediaType media_type);
121123 int stream_seek(int64_t pos, enum AVMediaType media_type,
122- MediaSource::ReadOptions::SeekMode mode);
124+ MediaTrackHelper::ReadOptions::SeekMode mode);
123125 int check_extradata(AVCodecContext *avctx);
124126
125127 bool mReaderThreadStarted;
@@ -134,21 +136,6 @@ private:
134136 DISALLOW_EVIL_CONSTRUCTORS(FFmpegExtractor);
135137 };
136138
137-/*
138-extern "C" {
139-
140-static const char *findMatchingContainer(const char *name);
141-
142-bool SniffFFMPEG(
143- const sp<DataSource> &source, String8 *mimeType, float *confidence,
144- sp<AMessage> *);
145-
146-MediaExtractor* CreateFFMPEGExtractor(const sp<DataSource> &source,
147- const char *mime, const sp<AMessage> &meta);
148-
149-}
150-*/
151-
152139 } // namespace android
153140
154141 #endif // SUPER_EXTRACTOR_H_
--- a/omx/Android.mk
+++ b/omx/Android.mk
@@ -19,7 +19,7 @@ LOCAL_SHARED_LIBRARIES += \
1919 liblog \
2020 libnativewindow \
2121 libswscale \
22- libstagefright_omx
22+ libstagefright_softomx
2323
2424 LOCAL_MODULE:= libffmpeg_omx
2525
--- a/utils/Android.mk
+++ b/utils/Android.mk
@@ -10,8 +10,7 @@ LOCAL_SRC_FILES := \
1010
1111 LOCAL_SHARED_LIBRARIES += \
1212 liblog \
13- libmediaextractor \
14- libstagefright
13+ libmediandk
1514
1615 LOCAL_STATIC_LIBRARIES += libstagefright_metadatautils
1716
--- a/utils/codec_utils.cpp
+++ b/utils/codec_utils.cpp
@@ -26,12 +26,11 @@ extern "C" {
2626 }
2727
2828 #include <utils/Errors.h>
29+#include <media/NdkMediaFormat.h>
2930 #include <media/stagefright/foundation/ABitReader.h>
3031 #include <media/stagefright/foundation/ADebug.h>
3132 #include <media/stagefright/foundation/avc_utils.h>
3233 #include <media/stagefright/MediaDefs.h>
33-#include <media/stagefright/MediaErrors.h>
34-#include <media/stagefright/MetaData.h>
3534 #include <media/stagefright/MetaDataUtils.h>
3635
3736 #include "codec_utils.h"
@@ -84,7 +83,7 @@ static sp<ABuffer> MakeMPEGVideoESDS(const sp<ABuffer> &csd) {
8483 //http://msdn.microsoft.com/en-us/library/dd757808(v=vs.85).aspx
8584
8685 // H.264 bitstream without start codes.
87-status_t setAVCFormat(AVCodecContext *avctx, MetaDataBase &meta)
86+media_status_t setAVCFormat(AVCodecContext *avctx, AMediaFormat *meta)
8887 {
8988 ALOGV("AVC");
9089
@@ -100,26 +99,26 @@ status_t setAVCFormat(AVCodecContext *avctx, MetaDataBase &meta)
10099 avctx->height = height;
101100 }
102101
103- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
104- meta.setData(kKeyAVCC, kTypeAVCC, avctx->extradata, avctx->extradata_size);
102+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_AVC);
103+ AMediaFormat_setBuffer(meta, AMEDIAFORMAT_KEY_CSD_AVC, avctx->extradata, avctx->extradata_size);
105104
106- return OK;
105+ return AMEDIA_OK;
107106 }
108107
109108 // H.264 bitstream with start codes.
110-status_t setH264Format(AVCodecContext *avctx, MetaDataBase &meta)
109+media_status_t setH264Format(AVCodecContext *avctx, AMediaFormat *meta)
111110 {
112111 ALOGV("H264");
113112
114113 CHECK_NE((int)avctx->extradata[0], 1); //configurationVersion
115114
116115 if (!MakeAVCCodecSpecificData(meta, avctx->extradata, avctx->extradata_size))
117- return UNKNOWN_ERROR;
116+ return AMEDIA_ERROR_UNKNOWN;
118117
119- return OK;
118+ return AMEDIA_OK;
120119 }
121120
122-status_t setMPEG4Format(AVCodecContext *avctx, MetaDataBase &meta)
121+media_status_t setMPEG4Format(AVCodecContext *avctx, AMediaFormat *meta)
123122 {
124123 ALOGV("MPEG4");
125124
@@ -127,28 +126,28 @@ status_t setMPEG4Format(AVCodecContext *avctx, MetaDataBase &meta)
127126 memcpy(csd->data(), avctx->extradata, avctx->extradata_size);
128127 sp<ABuffer> esds = MakeMPEGVideoESDS(csd);
129128
130- meta.setData(kKeyESDS, kTypeESDS, esds->data(), esds->size());
129+ AMediaFormat_setBuffer(meta, AMEDIAFORMAT_KEY_ESDS, esds->data(), esds->size());
131130
132131 int divxVersion = getDivXVersion(avctx);
133132 if (divxVersion >= 0) {
134- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_DIVX);
135- meta.setInt32(kKeyDivXVersion, divxVersion);
133+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_DIVX);
134+ AMediaFormat_setInt32(meta, "divx-version", divxVersion);
136135 } else {
137- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG4);
136+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_MPEG4);
138137 }
139- return OK;
138+ return AMEDIA_OK;
140139 }
141140
142-status_t setH263Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
141+media_status_t setH263Format(AVCodecContext *avctx __unused, AMediaFormat *meta)
143142 {
144143 ALOGV("H263");
145144
146- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_H263);
145+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_H263);
147146
148- return OK;
147+ return AMEDIA_OK;
149148 }
150149
151-status_t setMPEG2VIDEOFormat(AVCodecContext *avctx, MetaDataBase &meta)
150+media_status_t setMPEG2VIDEOFormat(AVCodecContext *avctx, AMediaFormat *meta)
152151 {
153152 ALOGV("MPEG%uVIDEO", avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 2 : 1);
154153
@@ -156,146 +155,146 @@ status_t setMPEG2VIDEOFormat(AVCodecContext *avctx, MetaDataBase &meta)
156155 memcpy(csd->data(), avctx->extradata, avctx->extradata_size);
157156 sp<ABuffer> esds = MakeMPEGVideoESDS(csd);
158157
159- meta.setData(kKeyESDS, kTypeESDS, esds->data(), esds->size());
160- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG2);
158+ AMediaFormat_setBuffer(meta, AMEDIAFORMAT_KEY_ESDS, esds->data(), esds->size());
159+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_MPEG2);
161160
162- return OK;
161+ return AMEDIA_OK;
163162 }
164163
165-status_t setVC1Format(AVCodecContext *avctx, MetaDataBase &meta)
164+media_status_t setVC1Format(AVCodecContext *avctx, AMediaFormat *meta)
166165 {
167166 ALOGV("VC1");
168167
169- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_VC1);
170- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
168+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_VC1);
169+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
171170
172- return OK;
171+ return AMEDIA_OK;
173172 }
174173
175-status_t setWMV1Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
174+media_status_t setWMV1Format(AVCodecContext *avctx __unused, AMediaFormat *meta)
176175 {
177176 ALOGV("WMV1");
178177
179- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_WMV);
180- meta.setInt32(kKeyWMVVersion, kTypeWMVVer_7);
178+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_WMV);
179+ AMediaFormat_setInt32(meta, "wmv-version", kTypeWMVVer_7);
181180
182- return OK;
181+ return AMEDIA_OK;
183182 }
184183
185-status_t setWMV2Format(AVCodecContext *avctx, MetaDataBase &meta)
184+media_status_t setWMV2Format(AVCodecContext *avctx, AMediaFormat *meta)
186185 {
187186 ALOGV("WMV2");
188187
189- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_WMV);
190- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
191- meta.setInt32(kKeyWMVVersion, kTypeWMVVer_8);
188+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_WMV);
189+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
190+ AMediaFormat_setInt32(meta, "wmv-version", kTypeWMVVer_8);
192191
193- return OK;
192+ return AMEDIA_OK;
194193 }
195194
196-status_t setWMV3Format(AVCodecContext *avctx, MetaDataBase &meta)
195+media_status_t setWMV3Format(AVCodecContext *avctx, AMediaFormat *meta)
197196 {
198197 ALOGV("WMV3");
199198
200- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_WMV);
201- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
202- meta.setInt32(kKeyWMVVersion, kTypeWMVVer_9);
199+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_WMV);
200+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
201+ AMediaFormat_setInt32(meta, "wmv-version", kTypeWMVVer_9);
203202
204- return OK;
203+ return AMEDIA_OK;
205204 }
206205
207-status_t setRV20Format(AVCodecContext *avctx, MetaDataBase &meta)
206+media_status_t setRV20Format(AVCodecContext *avctx, AMediaFormat *meta)
208207 {
209208 ALOGV("RV20");
210209
211- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_RV);
212- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
213- meta.setInt32(kKeyRVVersion, kTypeRVVer_G2); //http://en.wikipedia.org/wiki/RealVide
210+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_RV);
211+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
212+ AMediaFormat_setInt32(meta, "rv-version", kTypeRVVer_G2); //http://en.wikipedia.org/wiki/RealVide
214213
215- return OK;
214+ return AMEDIA_OK;
216215 }
217216
218-status_t setRV30Format(AVCodecContext *avctx, MetaDataBase &meta)
217+media_status_t setRV30Format(AVCodecContext *avctx, AMediaFormat *meta)
219218 {
220219 ALOGV("RV30");
221220
222- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_RV);
223- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
224- meta.setInt32(kKeyRVVersion, kTypeRVVer_8); //http://en.wikipedia.org/wiki/RealVide
221+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_RV);
222+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
223+ AMediaFormat_setInt32(meta, "rv-version", kTypeRVVer_8); //http://en.wikipedia.org/wiki/RealVide
225224
226- return OK;
225+ return AMEDIA_OK;
227226 }
228227
229-status_t setRV40Format(AVCodecContext *avctx, MetaDataBase &meta)
228+media_status_t setRV40Format(AVCodecContext *avctx, AMediaFormat *meta)
230229 {
231230 ALOGV("RV40");
232231
233- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_RV);
234- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
235- meta.setInt32(kKeyRVVersion, kTypeRVVer_9); //http://en.wikipedia.org/wiki/RealVide
232+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_RV);
233+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
234+ AMediaFormat_setInt32(meta, "rv-version", kTypeRVVer_9); //http://en.wikipedia.org/wiki/RealVide
236235
237- return OK;
236+ return AMEDIA_OK;
238237 }
239238
240-status_t setFLV1Format(AVCodecContext *avctx, MetaDataBase &meta)
239+media_status_t setFLV1Format(AVCodecContext *avctx, AMediaFormat *meta)
241240 {
242241 ALOGV("FLV1(Sorenson H263)");
243242
244- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_FLV1);
245- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
243+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_FLV1);
244+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
246245
247- return OK;
246+ return AMEDIA_OK;
248247 }
249248
250-status_t setHEVCFormat(AVCodecContext *avctx, MetaDataBase &meta)
249+media_status_t setHEVCFormat(AVCodecContext *avctx, AMediaFormat *meta)
251250 {
252251 ALOGV("HEVC");
253252
254- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_HEVC);
255- meta.setData(kKeyHVCC, kTypeHVCC, avctx->extradata, avctx->extradata_size);
253+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_HEVC);
254+ AMediaFormat_setBuffer(meta, AMEDIAFORMAT_KEY_CSD_HEVC, avctx->extradata, avctx->extradata_size);
256255
257- return OK;
256+ return AMEDIA_OK;
258257 }
259258
260-status_t setVP8Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
259+media_status_t setVP8Format(AVCodecContext *avctx __unused, AMediaFormat *meta)
261260 {
262261 ALOGV("VP8");
263262
264- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_VP8);
263+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_VP8);
265264
266- return OK;
265+ return AMEDIA_OK;
267266 }
268267
269-status_t setVP9Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
268+media_status_t setVP9Format(AVCodecContext *avctx __unused, AMediaFormat *meta)
270269 {
271270 ALOGV("VP9");
272271
273- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_VP9);
272+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_VIDEO_VP9);
274273
275- return OK;
274+ return AMEDIA_OK;
276275 }
277276
278277 //audio
279278
280-status_t setMP2Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
279+media_status_t setMP2Format(AVCodecContext *avctx __unused, AMediaFormat *meta)
281280 {
282281 ALOGV("MP2");
283282
284- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II);
283+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II);
285284
286- return OK;
285+ return AMEDIA_OK;
287286 }
288287
289-status_t setMP3Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
288+media_status_t setMP3Format(AVCodecContext *avctx __unused, AMediaFormat *meta)
290289 {
291290 ALOGV("MP3");
292291
293- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_MPEG);
292+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_MPEG);
294293
295- return OK;
294+ return AMEDIA_OK;
296295 }
297296
298-status_t setVORBISFormat(AVCodecContext *avctx, MetaDataBase &meta)
297+media_status_t setVORBISFormat(AVCodecContext *avctx, AMediaFormat *meta)
299298 {
300299 ALOGV("VORBIS");
301300
@@ -305,132 +304,132 @@ status_t setVORBISFormat(AVCodecContext *avctx, MetaDataBase &meta)
305304 avctx->extradata_size, 30,
306305 header_start, header_len) < 0) {
307306 ALOGE("vorbis extradata corrupt.");
308- return UNKNOWN_ERROR;
307+ return AMEDIA_ERROR_UNKNOWN;
309308 }
310309
311- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_VORBIS);
310+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_VORBIS);
312311 //identification header
313- meta.setData(kKeyVorbisInfo, 0, header_start[0], header_len[0]);
312+ AMediaFormat_setBuffer(meta, AMEDIAFORMAT_KEY_CSD_0, header_start[0], header_len[0]);
314313 //setup header
315- meta.setData(kKeyVorbisBooks, 0, header_start[2], header_len[2]);
314+ AMediaFormat_setBuffer(meta, AMEDIAFORMAT_KEY_CSD_1, header_start[2], header_len[2]);
316315
317- return OK;
316+ return AMEDIA_OK;
318317 }
319318
320-status_t setAC3Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
319+media_status_t setAC3Format(AVCodecContext *avctx __unused, AMediaFormat *meta)
321320 {
322321 ALOGV("AC3");
323322
324- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AC3);
323+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_AC3);
325324
326- return OK;
325+ return AMEDIA_OK;
327326 }
328327
329-status_t setAACFormat(AVCodecContext *avctx, MetaDataBase &meta)
328+media_status_t setAACFormat(AVCodecContext *avctx, AMediaFormat *meta)
330329 {
331330 ALOGV("AAC");
332331
333- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AAC);
334- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
335- meta.setInt32(kKeyAACAOT, avctx->profile + 1);
332+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_AAC);
333+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
334+ AMediaFormat_setInt32(meta, AMEDIAFORMAT_KEY_AAC_PROFILE, avctx->profile + 1);
336335
337- return OK;
336+ return AMEDIA_OK;
338337 }
339338
340-status_t setWMAV1Format(AVCodecContext *avctx, MetaDataBase &meta)
339+media_status_t setWMAV1Format(AVCodecContext *avctx, AMediaFormat *meta)
341340 {
342341 ALOGV("WMAV1");
343342
344- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_WMA);
345- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
346- meta.setInt32(kKeyWMAVersion, kTypeWMA); //FIXME version?
343+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_WMA);
344+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
345+ AMediaFormat_setInt32(meta, "wma-version", kTypeWMA); //FIXME version?
347346
348- return OK;
347+ return AMEDIA_OK;
349348 }
350349
351-status_t setWMAV2Format(AVCodecContext *avctx, MetaDataBase &meta)
350+media_status_t setWMAV2Format(AVCodecContext *avctx, AMediaFormat *meta)
352351 {
353352 ALOGV("WMAV2");
354353
355- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_WMA);
356- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
357- meta.setInt32(kKeyWMAVersion, kTypeWMA);
354+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_WMA);
355+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
356+ AMediaFormat_setInt32(meta, "wma-version", kTypeWMA); //FIXME version?
358357
359- return OK;
358+ return AMEDIA_OK;
360359 }
361360
362-status_t setWMAProFormat(AVCodecContext *avctx, MetaDataBase &meta)
361+media_status_t setWMAProFormat(AVCodecContext *avctx, AMediaFormat *meta)
363362 {
364363 ALOGV("WMAPro");
365364
366- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_WMA);
367- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
368- meta.setInt32(kKeyWMAVersion, kTypeWMAPro);
365+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_WMA);
366+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
367+ AMediaFormat_setInt32(meta, "wma-version", kTypeWMAPro);
369368
370- return OK;
369+ return AMEDIA_OK;
371370 }
372371
373-status_t setWMALossLessFormat(AVCodecContext *avctx, MetaDataBase &meta)
372+media_status_t setWMALossLessFormat(AVCodecContext *avctx, AMediaFormat *meta)
374373 {
375374 ALOGV("WMALOSSLESS");
376375
377- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_WMA);
378- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
379- meta.setInt32(kKeyWMAVersion, kTypeWMALossLess);
376+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_WMA);
377+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
378+ AMediaFormat_setInt32(meta, "wma-version", kTypeWMALossLess);
380379
381- return OK;
380+ return AMEDIA_OK;
382381 }
383382
384-status_t setRAFormat(AVCodecContext *avctx, MetaDataBase &meta)
383+media_status_t setRAFormat(AVCodecContext *avctx, AMediaFormat *meta)
385384 {
386385 ALOGV("COOK");
387386
388- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_RA);
389- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
387+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_RA);
388+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
390389
391- return OK;
390+ return AMEDIA_OK;
392391 }
393392
394-status_t setALACFormat(AVCodecContext *avctx, MetaDataBase &meta)
393+media_status_t setALACFormat(AVCodecContext *avctx, AMediaFormat *meta)
395394 {
396395 ALOGV("ALAC");
397396
398- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_ALAC);
399- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
397+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_ALAC);
398+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
400399
401- return OK;
400+ return AMEDIA_OK;
402401 }
403402
404-status_t setAPEFormat(AVCodecContext *avctx, MetaDataBase &meta)
403+media_status_t setAPEFormat(AVCodecContext *avctx, AMediaFormat *meta)
405404 {
406405 ALOGV("APE");
407406
408- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_APE);
409- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
407+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_APE);
408+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
410409
411- return OK;
410+ return AMEDIA_OK;
412411 }
413412
414-status_t setDTSFormat(AVCodecContext *avctx, MetaDataBase &meta)
413+media_status_t setDTSFormat(AVCodecContext *avctx, AMediaFormat *meta)
415414 {
416415 ALOGV("DTS");
417416
418- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_DTS);
419- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
417+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_DTS);
418+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
420419
421- return OK;
420+ return AMEDIA_OK;
422421 }
423422
424-status_t setFLACFormat(AVCodecContext *avctx, MetaDataBase &meta)
423+media_status_t setFLACFormat(AVCodecContext *avctx, AMediaFormat *meta)
425424 {
426425 ALOGV("FLAC");
427426
428- meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_FLAC);
429- meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
427+ AMediaFormat_setString(meta, AMEDIAFORMAT_KEY_MIME, MEDIA_MIMETYPE_AUDIO_FLAC);
428+ AMediaFormat_setBuffer(meta, "raw-codec-specific-data", avctx->extradata, avctx->extradata_size);
430429
431430 if (avctx->extradata_size < 10) {
432431 ALOGE("Invalid extradata in FLAC file! (size=%d)", avctx->extradata_size);
433- return UNKNOWN_ERROR;
432+ return AMEDIA_ERROR_UNKNOWN;
434433 }
435434
436435 ABitReader br(avctx->extradata, avctx->extradata_size);
@@ -439,21 +438,21 @@ status_t setFLACFormat(AVCodecContext *avctx, MetaDataBase &meta)
439438 int32_t minFrameSize = br.getBits(24);
440439 int32_t maxFrameSize = br.getBits(24);
441440
442- meta.setInt32('mibs', minBlockSize);
443- meta.setInt32('mabs', maxBlockSize);
444- meta.setInt32('mifs', minFrameSize);
445- meta.setInt32('mafs', maxFrameSize);
441+ AMediaFormat_setInt32(meta, "min-block-size", minBlockSize);
442+ AMediaFormat_setInt32(meta, "max-block-size", maxBlockSize);
443+ AMediaFormat_setInt32(meta, "min-frame-size", minFrameSize);
444+ AMediaFormat_setInt32(meta, "max-frame-size", maxFrameSize);
446445
447- return OK;
446+ return AMEDIA_OK;
448447 }
449448
450449 //Convert H.264 NAL format to annex b
451-status_t convertNal2AnnexB(uint8_t *dst, size_t dst_size,
450+media_status_t convertNal2AnnexB(uint8_t *dst, size_t dst_size,
452451 uint8_t *src, size_t src_size, size_t nal_len_size)
453452 {
454453 size_t i = 0;
455454 size_t nal_len = 0;
456- status_t status = OK;
455+ media_status_t status = AMEDIA_OK;
457456
458457 CHECK_EQ(dst_size, src_size);
459458 CHECK(nal_len_size == 3 || nal_len_size == 4);
@@ -466,7 +465,7 @@ status_t convertNal2AnnexB(uint8_t *dst, size_t dst_size,
466465 }
467466 dst[nal_len_size - 1] = 1;
468467 if (nal_len > INT_MAX || nal_len > src_size) {
469- status = ERROR_MALFORMED;
468+ status = AMEDIA_ERROR_MALFORMED;
470469 break;
471470 }
472471 dst += nal_len_size;
@@ -502,35 +501,35 @@ int getDivXVersion(AVCodecContext *avctx)
502501 return -1;
503502 }
504503
505-status_t parseMetadataTags(AVFormatContext *ctx, MetaDataBase &meta) {
504+media_status_t parseMetadataTags(AVFormatContext *ctx, AMediaFormat *meta) {
506505 if (ctx == NULL) {
507- return NO_INIT;
506+ return AMEDIA_ERROR_INVALID_OPERATION;
508507 }
509508
510509 AVDictionary *dict = ctx->metadata;
511510 if (dict == NULL) {
512- return NO_INIT;
511+ return AMEDIA_ERROR_INVALID_OPERATION;
513512 }
514513
515514 struct MetadataMapping {
516515 const char *from;
517- int to;
516+ const char *to;
518517 };
519518
520519 // avformat -> android mapping
521520 static const MetadataMapping kMap[] = {
522- { "track", kKeyCDTrackNumber },
523- { "disc", kKeyDiscNumber },
524- { "album", kKeyAlbum },
525- { "artist", kKeyArtist },
526- { "album_artist", kKeyAlbumArtist },
527- { "composer", kKeyComposer },
528- { "date", kKeyDate },
529- { "genre", kKeyGenre },
530- { "title", kKeyTitle },
531- { "year", kKeyYear },
532- { "compilation", kKeyCompilation },
533- { "location", kKeyLocation },
521+ { "track", AMEDIAFORMAT_KEY_CDTRACKNUMBER },
522+ { "disc", AMEDIAFORMAT_KEY_DISCNUMBER },
523+ { "album", AMEDIAFORMAT_KEY_ALBUM },
524+ { "artist", AMEDIAFORMAT_KEY_ARTIST },
525+ { "album_artist", AMEDIAFORMAT_KEY_ALBUMARTIST },
526+ { "composer", AMEDIAFORMAT_KEY_COMPOSER },
527+ { "date", AMEDIAFORMAT_KEY_DATE },
528+ { "genre", AMEDIAFORMAT_KEY_GENRE },
529+ { "title", AMEDIAFORMAT_KEY_TITLE },
530+ { "year", AMEDIAFORMAT_KEY_YEAR },
531+ { "compilation", AMEDIAFORMAT_KEY_COMPILATION },
532+ { "location", AMEDIAFORMAT_KEY_LOCATION },
534533 };
535534
536535 static const size_t kNumEntries = sizeof(kMap) / sizeof(kMap[0]);
@@ -539,7 +538,7 @@ status_t parseMetadataTags(AVFormatContext *ctx, MetaDataBase &meta) {
539538 AVDictionaryEntry *entry = av_dict_get(dict, kMap[i].from, NULL, 0);
540539 if (entry != NULL) {
541540 ALOGV("found key %s with value %s", entry->key, entry->value);
542- meta.setCString(kMap[i].to, entry->value);
541+ AMediaFormat_setString(meta, kMap[i].to, entry->value);
543542 }
544543 }
545544
@@ -559,14 +558,14 @@ status_t parseMetadataTags(AVFormatContext *ctx, MetaDataBase &meta) {
559558 }
560559 if (mime != NULL) {
561560 ALOGV("found albumart in stream %zu with type %s len %d", i, mime, pkt.size);
562- meta.setData(kKeyAlbumArt, MetaData::TYPE_NONE, pkt.data, pkt.size);
563- meta.setCString(kKeyAlbumArtMIME, mime);
561+ AMediaFormat_setBuffer(meta, AMEDIAFORMAT_KEY_ALBUMART, pkt.data, pkt.size);
564562 }
565563 }
566564 }
567565 }
568566 }
569- return OK;
567+
568+ return AMEDIA_OK;
570569 }
571570
572571 AudioEncoding sampleFormatToEncoding(AVSampleFormat fmt) {
--- a/utils/codec_utils.h
+++ b/utils/codec_utils.h
@@ -26,48 +26,50 @@
2626
2727 #include "ffmpeg_utils.h"
2828
29+struct AMediaFormat;
30+
2931 namespace android {
3032
3133 //video
32-status_t setAVCFormat(AVCodecContext *avctx, MetaDataBase &meta);
33-status_t setH264Format(AVCodecContext *avctx, MetaDataBase &meta);
34-status_t setMPEG4Format(AVCodecContext *avctx, MetaDataBase &meta);
35-status_t setH263Format(AVCodecContext *avctx, MetaDataBase &meta);
36-status_t setMPEG2VIDEOFormat(AVCodecContext *avctx, MetaDataBase &meta);
37-status_t setVC1Format(AVCodecContext *avctx, MetaDataBase &meta);
38-status_t setWMV1Format(AVCodecContext *avctx, MetaDataBase &meta);
39-status_t setWMV2Format(AVCodecContext *avctx, MetaDataBase &meta);
40-status_t setWMV3Format(AVCodecContext *avctx, MetaDataBase &meta);
41-status_t setRV20Format(AVCodecContext *avctx, MetaDataBase &meta);
42-status_t setRV30Format(AVCodecContext *avctx, MetaDataBase &meta);
43-status_t setRV40Format(AVCodecContext *avctx, MetaDataBase &meta);
44-status_t setFLV1Format(AVCodecContext *avctx, MetaDataBase &meta);
45-status_t setHEVCFormat(AVCodecContext *avctx, MetaDataBase &meta);
46-status_t setVP8Format(AVCodecContext *avctx, MetaDataBase &meta);
47-status_t setVP9Format(AVCodecContext *avctx, MetaDataBase &meta);
34+media_status_t setAVCFormat(AVCodecContext *avctx, AMediaFormat *meta);
35+media_status_t setH264Format(AVCodecContext *avctx, AMediaFormat *meta);
36+media_status_t setMPEG4Format(AVCodecContext *avctx, AMediaFormat *meta);
37+media_status_t setH263Format(AVCodecContext *avctx, AMediaFormat *meta);
38+media_status_t setMPEG2VIDEOFormat(AVCodecContext *avctx, AMediaFormat *meta);
39+media_status_t setVC1Format(AVCodecContext *avctx, AMediaFormat *meta);
40+media_status_t setWMV1Format(AVCodecContext *avctx, AMediaFormat *meta);
41+media_status_t setWMV2Format(AVCodecContext *avctx, AMediaFormat *meta);
42+media_status_t setWMV3Format(AVCodecContext *avctx, AMediaFormat *meta);
43+media_status_t setRV20Format(AVCodecContext *avctx, AMediaFormat *meta);
44+media_status_t setRV30Format(AVCodecContext *avctx, AMediaFormat *meta);
45+media_status_t setRV40Format(AVCodecContext *avctx, AMediaFormat *meta);
46+media_status_t setFLV1Format(AVCodecContext *avctx, AMediaFormat *meta);
47+media_status_t setHEVCFormat(AVCodecContext *avctx, AMediaFormat *meta);
48+media_status_t setVP8Format(AVCodecContext *avctx, AMediaFormat *meta);
49+media_status_t setVP9Format(AVCodecContext *avctx, AMediaFormat *meta);
4850 //audio
49-status_t setMP2Format(AVCodecContext *avctx, MetaDataBase &meta);
50-status_t setMP3Format(AVCodecContext *avctx, MetaDataBase &meta);
51-status_t setVORBISFormat(AVCodecContext *avctx, MetaDataBase &meta);
52-status_t setAC3Format(AVCodecContext *avctx, MetaDataBase &meta);
53-status_t setAACFormat(AVCodecContext *avctx, MetaDataBase &meta);
54-status_t setWMAV1Format(AVCodecContext *avctx, MetaDataBase &meta);
55-status_t setWMAV2Format(AVCodecContext *avctx, MetaDataBase &meta);
56-status_t setWMAProFormat(AVCodecContext *avctx, MetaDataBase &meta);
57-status_t setWMALossLessFormat(AVCodecContext *avctx, MetaDataBase &meta);
58-status_t setRAFormat(AVCodecContext *avctx, MetaDataBase &meta);
59-status_t setAPEFormat(AVCodecContext *avctx, MetaDataBase &meta);
60-status_t setDTSFormat(AVCodecContext *avctx, MetaDataBase &meta);
61-status_t setFLACFormat(AVCodecContext *avctx, MetaDataBase &meta);
62-status_t setALACFormat(AVCodecContext *avctx, MetaDataBase &meta);
51+media_status_t setMP2Format(AVCodecContext *avctx, AMediaFormat *meta);
52+media_status_t setMP3Format(AVCodecContext *avctx, AMediaFormat *meta);
53+media_status_t setVORBISFormat(AVCodecContext *avctx, AMediaFormat *meta);
54+media_status_t setAC3Format(AVCodecContext *avctx, AMediaFormat *meta);
55+media_status_t setAACFormat(AVCodecContext *avctx, AMediaFormat *meta);
56+media_status_t setWMAV1Format(AVCodecContext *avctx, AMediaFormat *meta);
57+media_status_t setWMAV2Format(AVCodecContext *avctx, AMediaFormat *meta);
58+media_status_t setWMAProFormat(AVCodecContext *avctx, AMediaFormat *meta);
59+media_status_t setWMALossLessFormat(AVCodecContext *avctx, AMediaFormat *meta);
60+media_status_t setRAFormat(AVCodecContext *avctx, AMediaFormat *meta);
61+media_status_t setAPEFormat(AVCodecContext *avctx, AMediaFormat *meta);
62+media_status_t setDTSFormat(AVCodecContext *avctx, AMediaFormat *meta);
63+media_status_t setFLACFormat(AVCodecContext *avctx, AMediaFormat *meta);
64+media_status_t setALACFormat(AVCodecContext *avctx, AMediaFormat *meta);
6365
6466 //Convert H.264 NAL format to annex b
65-status_t convertNal2AnnexB(uint8_t *dst, size_t dst_size,
67+media_status_t convertNal2AnnexB(uint8_t *dst, size_t dst_size,
6668 uint8_t *src, size_t src_size, size_t nal_len_size);
6769
6870 int getDivXVersion(AVCodecContext *avctx);
6971
70-status_t parseMetadataTags(AVFormatContext *ctx, MetaDataBase &meta);
72+media_status_t parseMetadataTags(AVFormatContext *ctx, AMediaFormat *meta);
7173
7274 AudioEncoding sampleFormatToEncoding(AVSampleFormat fmt);
7375 AVSampleFormat encodingToSampleFormat(AudioEncoding encoding);
--- a/utils/ffmpeg_source.cpp
+++ b/utils/ffmpeg_source.cpp
@@ -20,7 +20,7 @@
2020 #include <stdlib.h>
2121 #include "ffmpeg_source.h"
2222
23-#include <media/DataSourceBase.h>
23+#include <media/MediaExtractorPluginApi.h>
2424
2525 extern "C" {
2626
@@ -34,24 +34,19 @@ namespace android {
3434 class FFSource
3535 {
3636 public:
37- void set(DataSourceBase *s) { mSource = s; }
37+ void set(CDataSource *s) { mSource = s; }
3838 int init_check();
3939 int read(unsigned char *buf, size_t size);
4040 int64_t seek(int64_t pos);
4141 off64_t getSize();
4242
4343 protected:
44- DataSourceBase *mSource;
44+ CDataSource *mSource;
4545 int64_t mOffset;
4646 };
4747
4848 int FFSource::init_check()
4949 {
50- if (mSource->initCheck() != OK) {
51- ALOGE("FFSource initCheck failed");
52- return -1;
53- }
54-
5550 return 0;
5651 }
5752
@@ -59,7 +54,7 @@ int FFSource::read(unsigned char *buf, size_t size)
5954 {
6055 ssize_t n = 0;
6156
62- n = mSource->readAt(mOffset, buf, size);
57+ n = mSource->readAt(mSource->handle, mOffset, buf, size);
6358 if (n == UNKNOWN_ERROR) {
6459 ALOGE("FFSource readAt failed");
6560 return AVERROR(errno);
@@ -81,7 +76,7 @@ off64_t FFSource::getSize()
8176 {
8277 off64_t sz = -1;
8378
84- if (mSource->getSize(&sz) != OK) {
79+ if (mSource->getSize(mSource->handle, &sz) != OK) {
8580 ALOGE("FFSource getSize failed");
8681 return AVERROR(errno);
8782 }
@@ -93,9 +88,9 @@ off64_t FFSource::getSize()
9388
9489 static int android_open(URLContext *h, const char *url, int flags __unused)
9590 {
96- // the url in form of "android-source:<DataSourceBase Ptr>",
91+ // the url in form of "android-source:<CDataSource Ptr>",
9792 // the DataSourceBase Pointer passed by the ffmpeg extractor
98- DataSourceBase *source = NULL;
93+ CDataSource *source = NULL;
9994 char url_check[PATH_MAX] = {0};
10095
10196 ALOGV("android source begin open");
@@ -118,7 +113,7 @@ static int android_open(URLContext *h, const char *url, int flags __unused)
118113 if (strcmp(url_check, url) != 0) {
119114
120115 char uri[PATH_MAX] = {0};
121- if (!source->getUri(uri, sizeof(uri))) {
116+ if (!source->getUri(source->handle, uri, sizeof(uri))) {
122117 ALOGE("ffmpeg open data source error! (source uri)");
123118 return -1;
124119 }
Show on old repository browser