Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-stagefright-plugins: Commit

external/stagefright-plugins


Commit MetaInfo

Revisionf8884c8dc29c84d08f7a9c3d6131fcf1228ad63b (tree)
Time2019-10-08 12:20:29
AuthorMichael Goffioul <michael.goffioul@gmai...>
CommiterChih-Wei Huang

Log Message

Port to pie-x86

Change Summary

Incremental Difference

--- a/Android.mk
+++ b/Android.mk
@@ -21,4 +21,4 @@ LOCAL_PATH := $(call my-dir)
2121 SF_COMMON_MK := $(LOCAL_PATH)/common.mk
2222 AV_CODEC_LIB := $(if $(filter true,$(BOARD_USE_LIBAV)),libav,ffmpeg)
2323
24-#include $(call first-makefiles-under,$(LOCAL_PATH))
24+include $(call first-makefiles-under,$(LOCAL_PATH))
--- a/extractor/Android.mk
+++ b/extractor/Android.mk
@@ -7,10 +7,11 @@ LOCAL_SRC_FILES := \
77
88 LOCAL_SHARED_LIBRARIES += \
99 libbinder \
10- libmedia \
10+ libmediaextractor \
1111 libffmpeg_utils \
1212 liblog \
1313
1414 LOCAL_MODULE:= libffmpeg_extractor
15+LOCAL_MODULE_RELATIVE_PATH := extractors
1516
1617 include $(BUILD_SHARED_LIBRARY)
--- a/extractor/FFmpegExtractor.cpp
+++ b/extractor/FFmpegExtractor.cpp
@@ -26,20 +26,20 @@
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>
2931 #include <media/stagefright/foundation/ABitReader.h>
3032 #include <media/stagefright/foundation/ABuffer.h>
3133 #include <media/stagefright/foundation/ADebug.h>
3234 #include <media/stagefright/foundation/AMessage.h>
35+#include <media/stagefright/foundation/avc_utils.h>
3336 #include <media/stagefright/foundation/hexdump.h>
34-#include <media/stagefright/DataSource.h>
3537 #include <media/stagefright/MediaBuffer.h>
3638 #include <media/stagefright/foundation/ADebug.h>
3739 #include <media/stagefright/MediaDefs.h>
3840 #include <media/stagefright/MediaErrors.h>
39-#include <media/stagefright/MediaSource.h>
4041 #include <media/stagefright/MetaData.h>
4142 #include <media/stagefright/Utils.h>
42-#include "include/avc_utils.h"
4343
4444 #include "utils/codec_utils.h"
4545 #include "utils/ffmpeg_cmdutils.h"
@@ -70,15 +70,18 @@ enum {
7070
7171 namespace android {
7272
73-struct FFmpegSource : public MediaSource {
74- FFmpegSource(const sp<FFmpegExtractor> &extractor, size_t index);
73+static const char *findMatchingContainer(const char *name);
74+static MediaExtractor *CreateFFMPEGExtractor(DataSourceBase *source, void *meta);
7575
76- virtual status_t start(MetaData *params);
76+struct FFmpegSource : public MediaTrack {
77+ FFmpegSource(FFmpegExtractor *extractor, size_t index);
78+
79+ virtual status_t start(MetaDataBase *params);
7780 virtual status_t stop();
78- virtual sp<MetaData> getFormat();
81+ virtual status_t getFormat(MetaDataBase &meta);
7982
8083 virtual status_t read(
81- MediaBuffer **buffer, const ReadOptions *options);
84+ MediaBufferBase **buffer, const ReadOptions *options);
8285
8386 protected:
8487 virtual ~FFmpegSource();
@@ -86,7 +89,7 @@ protected:
8689 private:
8790 friend struct FFmpegExtractor;
8891
89- sp<FFmpegExtractor> mExtractor;
92+ FFmpegExtractor *mExtractor;
9093 size_t mTrackIndex;
9194
9295 enum AVMediaType mMediaType;
@@ -110,9 +113,8 @@ private:
110113
111114 ////////////////////////////////////////////////////////////////////////////////
112115
113-FFmpegExtractor::FFmpegExtractor(const sp<DataSource> &source, const sp<AMessage> &meta)
116+FFmpegExtractor::FFmpegExtractor(DataSourceBase *source, const sp<AMessage> &meta)
114117 : mDataSource(source),
115- mMeta(new MetaData),
116118 mInitCheck(NO_INIT),
117119 mFormatCtx(NULL),
118120 mReaderThreadStarted(false),
@@ -159,7 +161,7 @@ size_t FFmpegExtractor::countTracks() {
159161 return mInitCheck == OK ? mTracks.size() : 0;
160162 }
161163
162-sp<IMediaSource> FFmpegExtractor::getTrack(size_t index) {
164+MediaTrack* FFmpegExtractor::getTrack(size_t index) {
163165 ALOGV("FFmpegExtractor::getTrack[%zu]", index);
164166
165167 if (mInitCheck != OK) {
@@ -173,32 +175,33 @@ sp<IMediaSource> FFmpegExtractor::getTrack(size_t index) {
173175 return new FFmpegSource(this, index);
174176 }
175177
176-sp<MetaData> FFmpegExtractor::getTrackMetaData(size_t index, uint32_t flags __unused) {
178+status_t FFmpegExtractor::getTrackMetaData(MetaDataBase &meta, size_t index, uint32_t flags __unused) {
177179 ALOGV("FFmpegExtractor::getTrackMetaData[%zu]", index);
178180
179181 if (mInitCheck != OK) {
180- return NULL;
182+ return UNKNOWN_ERROR;
181183 }
182184
183185 if (index >= mTracks.size()) {
184- return NULL;
186+ return UNKNOWN_ERROR;
185187 }
186188
187189 /* Quick and dirty, just get a frame 1/4 in */
188190 if (mTracks.itemAt(index).mIndex == mVideoStreamIdx &&
189191 mFormatCtx->duration != AV_NOPTS_VALUE) {
190- mTracks.itemAt(index).mMeta->setInt64(
192+ mTracks.editItemAt(index).mMeta.setInt64(
191193 kKeyThumbnailTime, mFormatCtx->duration / 4);
192194 }
193195
194- return mTracks.itemAt(index).mMeta;
196+ meta = mTracks.itemAt(index).mMeta;
197+ return OK;
195198 }
196199
197-sp<MetaData> FFmpegExtractor::getMetaData() {
200+status_t FFmpegExtractor::getMetaData(MetaDataBase &meta) {
198201 ALOGV("FFmpegExtractor::getMetaData");
199202
200203 if (mInitCheck != OK) {
201- return NULL;
204+ return UNKNOWN_ERROR;
202205 }
203206
204207 if (!mParsedMetadata) {
@@ -206,7 +209,8 @@ sp<MetaData> FFmpegExtractor::getMetaData() {
206209 mParsedMetadata = true;
207210 }
208211
209- return mMeta;
212+ meta = mMeta;
213+ return OK;
210214 }
211215
212216 uint32_t FFmpegExtractor::flags() const {
@@ -360,10 +364,10 @@ bool FFmpegExtractor::is_codec_supported(enum AVCodecID codec_id)
360364 return supported;
361365 }
362366
363-sp<MetaData> FFmpegExtractor::setVideoFormat(AVStream *stream)
367+status_t FFmpegExtractor::setVideoFormat(AVStream *stream, MetaDataBase &meta)
364368 {
365369 AVCodecContext *avctx = NULL;
366- sp<MetaData> meta = NULL;
370+ status_t ret = UNKNOWN_ERROR;
367371
368372 avctx = stream->codec;
369373 CHECK_EQ((int)avctx->codec_type, (int)AVMEDIA_TYPE_VIDEO);
@@ -371,70 +375,69 @@ sp<MetaData> FFmpegExtractor::setVideoFormat(AVStream *stream)
371375 switch(avctx->codec_id) {
372376 case AV_CODEC_ID_H264:
373377 if (avctx->extradata[0] == 1) {
374- meta = setAVCFormat(avctx);
378+ ret = setAVCFormat(avctx, meta);
375379 } else {
376- meta = setH264Format(avctx);
380+ ret = setH264Format(avctx, meta);
377381 }
378382 break;
379383 case AV_CODEC_ID_MPEG4:
380- meta = setMPEG4Format(avctx);
384+ ret = setMPEG4Format(avctx, meta);
381385 break;
382386 case AV_CODEC_ID_H263:
383387 case AV_CODEC_ID_H263P:
384388 case AV_CODEC_ID_H263I:
385- meta = setH263Format(avctx);
389+ ret = setH263Format(avctx, meta);
386390 break;
387391 case AV_CODEC_ID_MPEG1VIDEO:
388392 case AV_CODEC_ID_MPEG2VIDEO:
389- meta = setMPEG2VIDEOFormat(avctx);
393+ ret = setMPEG2VIDEOFormat(avctx, meta);
390394 break;
391395 case AV_CODEC_ID_VC1:
392- meta = setVC1Format(avctx);
396+ ret = setVC1Format(avctx, meta);
393397 break;
394398 case AV_CODEC_ID_WMV1:
395- meta = setWMV1Format(avctx);
399+ ret = setWMV1Format(avctx, meta);
396400 break;
397401 case AV_CODEC_ID_WMV2:
398- meta = setWMV2Format(avctx);
402+ ret = setWMV2Format(avctx, meta);
399403 break;
400404 case AV_CODEC_ID_WMV3:
401- meta = setWMV3Format(avctx);
405+ ret = setWMV3Format(avctx, meta);
402406 break;
403407 case AV_CODEC_ID_RV20:
404- meta = setRV20Format(avctx);
408+ ret = setRV20Format(avctx, meta);
405409 break;
406410 case AV_CODEC_ID_RV30:
407- meta = setRV30Format(avctx);
411+ ret = setRV30Format(avctx, meta);
408412 break;
409413 case AV_CODEC_ID_RV40:
410- meta = setRV40Format(avctx);
414+ ret = setRV40Format(avctx, meta);
411415 break;
412416 case AV_CODEC_ID_FLV1:
413- meta = setFLV1Format(avctx);
417+ ret = setFLV1Format(avctx, meta);
414418 break;
415419 case AV_CODEC_ID_HEVC:
416- meta = setHEVCFormat(avctx);
420+ ret = setHEVCFormat(avctx, meta);
417421 break;
418422 case AV_CODEC_ID_VP8:
419- meta = setVP8Format(avctx);
423+ ret = setVP8Format(avctx, meta);
420424 break;
421425 case AV_CODEC_ID_VP9:
422- meta = setVP9Format(avctx);
426+ ret = setVP9Format(avctx, meta);
423427 break;
424428 default:
425429 ALOGD("unsupported video codec (id: %d, name: %s), but give it a chance",
426430 avctx->codec_id, avcodec_get_name(avctx->codec_id));
427- meta = new MetaData;
428- meta->setInt32(kKeyCodecId, avctx->codec_id);
429- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_FFMPEG);
431+ meta.setInt32(kKeyCodecId, avctx->codec_id);
432+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_FFMPEG);
430433 if (avctx->extradata_size > 0) {
431- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
434+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
432435 }
433436 //CHECK(!"Should not be here. Unsupported codec.");
434437 break;
435438 }
436439
437- if (meta != NULL) {
440+ if (ret == OK) {
438441 // rotation
439442 double theta = get_rotation(stream);
440443 int rotationDegrees = 0;
@@ -447,11 +450,11 @@ sp<MetaData> FFmpegExtractor::setVideoFormat(AVStream *stream)
447450 rotationDegrees = 270;
448451 }
449452 if (rotationDegrees != 0) {
450- meta->setInt32(kKeyRotation, rotationDegrees);
453+ meta.setInt32(kKeyRotation, rotationDegrees);
451454 }
452455 }
453456
454- if (meta != NULL) {
457+ if (ret == OK) {
455458 float aspect_ratio;
456459 int width, height;
457460
@@ -471,90 +474,89 @@ sp<MetaData> FFmpegExtractor::setVideoFormat(AVStream *stream)
471474 ALOGI("width: %d, height: %d, bit_rate: % " PRId64 " aspect ratio: %f",
472475 avctx->width, avctx->height, avctx->bit_rate, aspect_ratio);
473476
474- meta->setInt32(kKeyWidth, avctx->width);
475- meta->setInt32(kKeyHeight, avctx->height);
477+ meta.setInt32(kKeyWidth, avctx->width);
478+ meta.setInt32(kKeyHeight, avctx->height);
476479 if ((width > 0) && (height > 0) &&
477480 ((avctx->width != width || avctx->height != height))) {
478- meta->setInt32(kKeySARWidth, width);
479- meta->setInt32(kKeySARHeight, height);
481+ meta.setInt32(kKeySARWidth, width);
482+ meta.setInt32(kKeySARHeight, height);
480483 ALOGI("SAR width: %d, SAR height: %d", width, height);
481484 }
482485 if (avctx->bit_rate > 0) {
483- meta->setInt32(kKeyBitRate, avctx->bit_rate);
486+ meta.setInt32(kKeyBitRate, avctx->bit_rate);
484487 }
485- meta->setCString('ffmt', findMatchingContainer(mFormatCtx->iformat->name));
488+ meta.setCString('ffmt', findMatchingContainer(mFormatCtx->iformat->name));
486489 setDurationMetaData(stream, meta);
487490 }
488491
489- return meta;
492+ return OK;
490493 }
491494
492-sp<MetaData> FFmpegExtractor::setAudioFormat(AVStream *stream)
495+status_t FFmpegExtractor::setAudioFormat(AVStream *stream, MetaDataBase &meta)
493496 {
494497 AVCodecContext *avctx = NULL;
495- sp<MetaData> meta = NULL;
498+ status_t ret = UNKNOWN_ERROR;
496499
497500 avctx = stream->codec;
498501 CHECK_EQ((int)avctx->codec_type, (int)AVMEDIA_TYPE_AUDIO);
499502
500503 switch(avctx->codec_id) {
501504 case AV_CODEC_ID_MP2:
502- meta = setMP2Format(avctx);
505+ ret = setMP2Format(avctx, meta);
503506 break;
504507 case AV_CODEC_ID_MP3:
505- meta = setMP3Format(avctx);
508+ ret = setMP3Format(avctx, meta);
506509 break;
507510 case AV_CODEC_ID_VORBIS:
508- meta = setVORBISFormat(avctx);
511+ ret = setVORBISFormat(avctx, meta);
509512 break;
510513 case AV_CODEC_ID_AC3:
511- meta = setAC3Format(avctx);
514+ ret = setAC3Format(avctx, meta);
512515 break;
513516 case AV_CODEC_ID_AAC:
514- meta = setAACFormat(avctx);
517+ ret = setAACFormat(avctx, meta);
515518 break;
516519 case AV_CODEC_ID_WMAV1:
517- meta = setWMAV1Format(avctx);
520+ ret = setWMAV1Format(avctx, meta);
518521 break;
519522 case AV_CODEC_ID_WMAV2:
520- meta = setWMAV2Format(avctx);
523+ ret = setWMAV2Format(avctx, meta);
521524 break;
522525 case AV_CODEC_ID_WMAPRO:
523- meta = setWMAProFormat(avctx);
526+ ret = setWMAProFormat(avctx, meta);
524527 break;
525528 case AV_CODEC_ID_WMALOSSLESS:
526- meta = setWMALossLessFormat(avctx);
529+ ret = setWMALossLessFormat(avctx, meta);
527530 break;
528531 case AV_CODEC_ID_COOK:
529- meta = setRAFormat(avctx);
532+ ret = setRAFormat(avctx, meta);
530533 break;
531534 case AV_CODEC_ID_APE:
532- meta = setAPEFormat(avctx);
535+ ret = setAPEFormat(avctx, meta);
533536 break;
534537 case AV_CODEC_ID_DTS:
535- meta = setDTSFormat(avctx);
538+ ret = setDTSFormat(avctx, meta);
536539 break;
537540 case AV_CODEC_ID_FLAC:
538- meta = setFLACFormat(avctx);
541+ ret = setFLACFormat(avctx, meta);
539542 break;
540543 case AV_CODEC_ID_ALAC:
541- meta = setALACFormat(avctx);
544+ ret = setALACFormat(avctx, meta);
542545 break;
543546 default:
544547 ALOGD("unsupported audio codec (id: %d, name: %s), but give it a chance",
545548 avctx->codec_id, avcodec_get_name(avctx->codec_id));
546- meta = new MetaData;
547- meta->setInt32(kKeyCodecId, avctx->codec_id);
548- meta->setInt32(kKeyCodedSampleBits, avctx->bits_per_coded_sample);
549- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_FFMPEG);
549+ meta.setInt32(kKeyCodecId, avctx->codec_id);
550+ meta.setInt32(kKeyCodedSampleBits, avctx->bits_per_coded_sample);
551+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_FFMPEG);
550552 if (avctx->extradata_size > 0) {
551- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
553+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
552554 }
553555 //CHECK(!"Should not be here. Unsupported codec.");
554556 break;
555557 }
556558
557- if (meta != NULL) {
559+ if (ret == OK) {
558560 ALOGD("bit_rate: %" PRId64 ", sample_rate: %d, channels: %d, "
559561 "bits_per_coded_sample: %d, block_align: %d "
560562 "bits_per_raw_sample: %d, sample_format: %d",
@@ -562,24 +564,24 @@ sp<MetaData> FFmpegExtractor::setAudioFormat(AVStream *stream)
562564 avctx->bits_per_coded_sample, avctx->block_align,
563565 avctx->bits_per_raw_sample, avctx->sample_fmt);
564566
565- meta->setInt32(kKeyChannelCount, avctx->channels);
566- meta->setInt32(kKeyBitRate, avctx->bit_rate);
567+ meta.setInt32(kKeyChannelCount, avctx->channels);
568+ meta.setInt32(kKeyBitRate, avctx->bit_rate);
567569 int32_t bits = avctx->bits_per_raw_sample > 0 ?
568570 avctx->bits_per_raw_sample :
569571 av_get_bytes_per_sample(avctx->sample_fmt) * 8;
570- meta->setInt32(kKeyBitsPerRawSample, bits);
571- meta->setInt32(kKeySampleRate, avctx->sample_rate);
572- meta->setInt32(kKeyBlockAlign, avctx->block_align);
573- meta->setInt32(kKeySampleFormat, avctx->sample_fmt);
574- //meta->setInt32(kKeyPcmEncoding, sampleFormatToEncoding(avctx->sample_fmt));
575- meta->setCString('ffmt', findMatchingContainer(mFormatCtx->iformat->name));
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));
576578 setDurationMetaData(stream, meta);
577579 }
578580
579- return meta;
581+ return OK;
580582 }
581583
582-void FFmpegExtractor::setDurationMetaData(AVStream *stream, sp<MetaData> &meta)
584+void FFmpegExtractor::setDurationMetaData(AVStream *stream, MetaDataBase &meta)
583585 {
584586 AVCodecContext *avctx = stream->codec;
585587
@@ -592,10 +594,10 @@ void FFmpegExtractor::setDurationMetaData(AVStream *stream, sp<MetaData> &meta)
592594 } else {
593595 ALOGV("%s startTime:N/A", s);
594596 }
595- meta->setInt64(kKeyDuration, duration);
597+ meta.setInt64(kKeyDuration, duration);
596598 } else {
597599 // default when no stream duration
598- meta->setInt64(kKeyDuration, mFormatCtx->duration);
600+ meta.setInt64(kKeyDuration, mFormatCtx->duration);
599601 }
600602 }
601603
@@ -603,11 +605,7 @@ int FFmpegExtractor::stream_component_open(int stream_index)
603605 {
604606 TrackInfo *trackInfo = NULL;
605607 AVCodecContext *avctx = NULL;
606- sp<MetaData> meta = NULL;
607608 bool supported = false;
608- uint32_t type = 0;
609- const void *data = NULL;
610- size_t size = 0;
611609 int ret = 0;
612610
613611 ALOGI("stream_index: %d", stream_index);
@@ -627,7 +625,6 @@ int FFmpegExtractor::stream_component_open(int stream_index)
627625 }
628626 ALOGI("support the codec(%s) disposition(%x)", avcodec_get_name(avctx->codec_id), mFormatCtx->streams[stream_index]->disposition);
629627
630- unsigned streamType;
631628 for (size_t i = 0; i < mTracks.size(); ++i) {
632629 if (stream_index == mTracks.editItemAt(i).mIndex) {
633630 ALOGE("this track already exists");
@@ -641,6 +638,8 @@ int FFmpegExtractor::stream_component_open(int stream_index)
641638 av_get_codec_tag_string(tagbuf, sizeof(tagbuf), avctx->codec_tag);
642639 ALOGV("Tag %s/0x%08x with codec(%s)\n", tagbuf, avctx->codec_tag, avcodec_get_name(avctx->codec_id));
643640
641+ MetaDataBase meta;
642+
644643 switch (avctx->codec_type) {
645644 case AVMEDIA_TYPE_VIDEO:
646645 if (mVideoStreamIdx == -1)
@@ -667,8 +666,7 @@ int FFmpegExtractor::stream_component_open(int stream_index)
667666 ALOGV("video stream no extradata, but we can ignore it.");
668667 }
669668 #endif
670- meta = setVideoFormat(mVideoStream);
671- if (meta == NULL) {
669+ if (setVideoFormat(mVideoStream, meta) != OK) {
672670 ALOGE("setVideoFormat failed");
673671 return -1;
674672 }
@@ -709,8 +707,7 @@ int FFmpegExtractor::stream_component_open(int stream_index)
709707 ALOGV("audio stream no extradata, but we can ignore it.");
710708 }
711709 #endif
712- meta = setAudioFormat(mAudioStream);
713- if (meta == NULL) {
710+ if (setAudioFormat(mAudioStream, meta) != OK) {
714711 ALOGE("setAudioFormat failed");
715712 return -1;
716713 }
@@ -876,7 +873,7 @@ void FFmpegExtractor::fetchStuffsFromSniffedMeta(const sp<AMessage> &meta)
876873 //mime
877874 CHECK(meta->findString("extended-extractor-mime", &mime));
878875 CHECK(mime.c_str() != NULL);
879- mMeta->setCString(kKeyMIMEType, mime.c_str());
876+ mMeta.setCString(kKeyMIMEType, mime.c_str());
880877 }
881878
882879 void FFmpegExtractor::setFFmpegDefaultOpts()
@@ -922,9 +919,7 @@ int FFmpegExtractor::initStreams()
922919 {
923920 int err = 0;
924921 int i = 0;
925- int eof = 0;
926922 int ret = 0, audio_ret = -1, video_ret = -1;
927- int pkt_in_play_range = 0;
928923 AVDictionaryEntry *t = NULL;
929924 AVDictionary **opts = NULL;
930925 int orig_nb_streams = 0;
@@ -935,7 +930,6 @@ int FFmpegExtractor::initStreams()
935930 wanted_stream[AVMEDIA_TYPE_AUDIO] = -1;
936931 wanted_stream[AVMEDIA_TYPE_VIDEO] = -1;
937932 AVDictionary *format_opts = NULL, *codec_opts = NULL;
938- const char *mime = NULL;
939933
940934 setFFmpegDefaultOpts();
941935
@@ -1120,10 +1114,9 @@ void *FFmpegExtractor::ReaderWrapper(void *me) {
11201114 }
11211115
11221116 void FFmpegExtractor::readerEntry() {
1123- int err, i, ret;
1117+ int ret;
11241118 AVPacket pkt1, *pkt = &pkt1;
11251119 int eof = 0;
1126- int pkt_in_play_range = 0;
11271120
11281121 mLock.lock();
11291122
@@ -1323,7 +1316,7 @@ fail:
13231316 ////////////////////////////////////////////////////////////////////////////////
13241317
13251318 FFmpegSource::FFmpegSource(
1326- const sp<FFmpegExtractor> &extractor, size_t index)
1319+ FFmpegExtractor *extractor, size_t index)
13271320 : mExtractor(extractor),
13281321 mTrackIndex(index),
13291322 mIsAVC(false),
@@ -1333,7 +1326,7 @@ FFmpegSource::FFmpegSource(
13331326 mQueue(mExtractor->mTracks.itemAt(index).mQueue),
13341327 mLastPTS(AV_NOPTS_VALUE),
13351328 mTargetTime(AV_NOPTS_VALUE) {
1336- sp<MetaData> meta = mExtractor->mTracks.itemAt(index).mMeta;
1329+ const MetaDataBase& meta = mExtractor->mTracks.itemAt(index).mMeta;
13371330
13381331 {
13391332 AVCodecContext *avctx = mStream->codec;
@@ -1347,7 +1340,7 @@ FFmpegSource::FFmpegSource(
13471340 uint32_t type;
13481341 const void *data;
13491342 size_t size;
1350- CHECK(meta->findData(kKeyAVCC, &type, &data, &size));
1343+ CHECK(meta.findData(kKeyAVCC, &type, &data, &size));
13511344
13521345 const uint8_t *ptr = (const uint8_t *)data;
13531346
@@ -1373,7 +1366,7 @@ FFmpegSource::FFmpegSource(
13731366 uint32_t type;
13741367 const void *data;
13751368 size_t size;
1376- CHECK(meta->findData(kKeyHVCC, &type, &data, &size));
1369+ CHECK(meta.findData(kKeyHVCC, &type, &data, &size));
13771370
13781371 const uint8_t *ptr = (const uint8_t *)data;
13791372
@@ -1400,7 +1393,7 @@ FFmpegSource::~FFmpegSource() {
14001393 mExtractor = NULL;
14011394 }
14021395
1403-status_t FFmpegSource::start(MetaData * /* params */) {
1396+status_t FFmpegSource::start(MetaDataBase * /* params */) {
14041397 ALOGV("FFmpegSource::start %s",
14051398 av_get_media_type_string(mMediaType));
14061399 return OK;
@@ -1412,12 +1405,13 @@ status_t FFmpegSource::stop() {
14121405 return OK;
14131406 }
14141407
1415-sp<MetaData> FFmpegSource::getFormat() {
1416- return mExtractor->mTracks.itemAt(mTrackIndex).mMeta;;
1408+status_t FFmpegSource::getFormat(MetaDataBase &meta) {
1409+ meta = mExtractor->mTracks.itemAt(mTrackIndex).mMeta;
1410+ return OK;
14171411 }
14181412
14191413 status_t FFmpegSource::read(
1420- MediaBuffer **buffer, const ReadOptions *options) {
1414+ MediaBufferBase **buffer, const ReadOptions *options) {
14211415 *buffer = NULL;
14221416
14231417 AVPacket pkt;
@@ -1496,7 +1490,7 @@ retry:
14961490 }
14971491
14981492 MediaBuffer *mediaBuffer = new MediaBuffer(pkt.size + AV_INPUT_BUFFER_PADDING_SIZE);
1499- mediaBuffer->meta_data()->clear();
1493+ mediaBuffer->meta_data().clear();
15001494 mediaBuffer->set_range(0, pkt.size);
15011495
15021496 //copy data
@@ -1567,14 +1561,14 @@ retry:
15671561 av_get_media_type_string(mMediaType), pkt.size, key);
15681562 #endif
15691563
1570- mediaBuffer->meta_data()->setInt64(kKeyTime, timeUs);
1571- mediaBuffer->meta_data()->setInt32(kKeyIsSyncFrame, key);
1564+ mediaBuffer->meta_data().setInt64(kKeyTime, timeUs);
1565+ mediaBuffer->meta_data().setInt32(kKeyIsSyncFrame, key);
15721566
15731567 // deal with seek-to-exact-frame, we might be off a bit and Stagefright will assert on us
15741568 if (seekTimeUs != AV_NOPTS_VALUE && timeUs < seekTimeUs &&
15751569 mode == MediaSource::ReadOptions::SEEK_CLOSEST) {
15761570 mTargetTime = seekTimeUs;
1577- mediaBuffer->meta_data()->setInt64(kKeyTargetTime, seekTimeUs);
1571+ mediaBuffer->meta_data().setInt64(kKeyTargetTime, seekTimeUs);
15781572 }
15791573
15801574 if (mTargetTime != AV_NOPTS_VALUE) {
@@ -1582,7 +1576,7 @@ retry:
15821576 mTargetTime = AV_NOPTS_VALUE;
15831577 } else if (nextPTS != AV_NOPTS_VALUE && nextPTS > mTargetTime) {
15841578 ALOGV("adjust target frame time to %" PRId64, timeUs);
1585- mediaBuffer->meta_data()->setInt64(kKeyTime, mTargetTime);
1579+ mediaBuffer->meta_data().setInt64(kKeyTime, mTargetTime);
15861580 mTargetTime = AV_NOPTS_VALUE;
15871581 }
15881582 }
@@ -1658,7 +1652,6 @@ static enum AVCodecID getCodecId(AVFormatContext *ic, AVMediaType codec_type)
16581652
16591653 static bool hasAudioCodecOnly(AVFormatContext *ic)
16601654 {
1661- enum AVCodecID codec_id = AV_CODEC_ID_NONE;
16621655 bool haveVideo = false;
16631656 bool haveAudio = false;
16641657
@@ -2098,16 +2091,16 @@ fail:
20982091 return container;
20992092 }
21002093
2101-static const char *BetterSniffFFMPEG(const sp<DataSource> &source,
2102- float *confidence, sp<AMessage> meta)
2094+static const char *BetterSniffFFMPEG(DataSourceBase *source,
2095+ float *confidence, AMessage *meta)
21032096 {
21042097 const char *ret = NULL;
21052098 char url[PATH_MAX] = {0};
21062099
2107- ALOGI("android-source:%p", source.get());
2100+ ALOGI("android-source:%p", source);
21082101
21092102 // pass the addr of smart pointer("source")
2110- snprintf(url, sizeof(url), "android-source:%p", source.get());
2103+ snprintf(url, sizeof(url), "android-source:%p", source);
21112104
21122105 ret = SniffFFMPEGCommon(url, confidence,
21132106 (source->flags() & DataSource::kIsCachingDataSource));
@@ -2118,24 +2111,24 @@ static const char *BetterSniffFFMPEG(const sp<DataSource> &source,
21182111 return ret;
21192112 }
21202113
2121-static const char *LegacySniffFFMPEG(const sp<DataSource> &source,
2122- float *confidence, sp<AMessage> meta)
2114+static const char *LegacySniffFFMPEG(DataSourceBase *source,
2115+ float *confidence, AMessage *meta)
21232116 {
21242117 const char *ret = NULL;
2118+ char uri[PATH_MAX] = {0};
21252119 char url[PATH_MAX] = {0};
21262120
2127- String8 uri = source->getUri();
2128- if (!uri.string()) {
2121+ if (!source->getUri(uri, sizeof(uri))) {
21292122 return NULL;
21302123 }
21312124
21322125 if (source->flags() & DataSource::kIsCachingDataSource)
21332126 return NULL;
21342127
2135- ALOGV("source url:%s", uri.string());
2128+ ALOGV("source url:%s", uri);
21362129
21372130 // pass the addr of smart pointer("source") + file name
2138- snprintf(url, sizeof(url), "android-source:%p|file:%s", source.get(), uri.string());
2131+ snprintf(url, sizeof(url), "android-source:%p|file:%s", source, uri);
21392132
21402133 ret = SniffFFMPEGCommon(url, confidence, false);
21412134 if (ret) {
@@ -2145,34 +2138,39 @@ static const char *LegacySniffFFMPEG(const sp<DataSource> &source,
21452138 return ret;
21462139 }
21472140
2148-extern "C" {
2141+static void FreeMeta(void *meta) {
2142+ if (meta != nullptr) {
2143+ static_cast<AMessage *>(meta)->decStrong(nullptr);
2144+ }
2145+}
21492146
2150-bool SniffFFMPEG(
2151- const sp<DataSource> &source, String8 *mimeType, float *confidence,
2152- sp<AMessage> *meta) {
2147+static MediaExtractor::CreatorFunc
2148+SniffFFMPEG(
2149+ DataSourceBase *source, float *confidence, void **meta,
2150+ MediaExtractor::FreeMetaFunc *freeMeta) {
21532151
21542152 float newConfidence = 0.08f;
21552153
2156- ALOGV("SniffFFMPEG (initial confidence: %f, mime: %s)", *confidence,
2157- mimeType == NULL ? "unknown" : *mimeType);
2154+ ALOGV("SniffFFMPEG (initial confidence: %f)", *confidence);
21582155
21592156 // This is a heavyweight sniffer, don't invoke it if Stagefright knows
21602157 // what it is doing already.
2161- if (mimeType != NULL && confidence != NULL) {
2162- if (*mimeType == "application/ogg") {
2163- return false;
2164- }
2158+ if (confidence != NULL) {
21652159 if (*confidence > 0.8f) {
2166- return false;
2160+ return NULL;
21672161 }
21682162 }
21692163
2170- *meta = new AMessage;
2164+ AMessage *msg = new AMessage;
2165+
2166+ *meta = msg;
2167+ *freeMeta = FreeMeta;
2168+ msg->incStrong(nullptr);
21712169
2172- const char *container = BetterSniffFFMPEG(source, &newConfidence, *meta);
2170+ const char *container = BetterSniffFFMPEG(source, &newConfidence, msg);
21732171 if (!container) {
21742172 ALOGW("sniff through BetterSniffFFMPEG failed, try LegacySniffFFMPEG");
2175- container = LegacySniffFFMPEG(source, &newConfidence, *meta);
2173+ container = LegacySniffFFMPEG(source, &newConfidence, msg);
21762174 if (container) {
21772175 ALOGV("sniff through LegacySniffFFMPEG success");
21782176 }
@@ -2182,19 +2180,18 @@ bool SniffFFMPEG(
21822180
21832181 if (container == NULL) {
21842182 ALOGD("SniffFFMPEG failed to sniff this source");
2185- (*meta)->clear();
2183+ msg->decStrong(nullptr);
21862184 *meta = NULL;
2187- return false;
2185+ *freeMeta = NULL;
2186+ return NULL;
21882187 }
21892188
21902189 ALOGD("ffmpeg detected media content as '%s' with confidence %.2f",
21912190 container, newConfidence);
21922191
2193- mimeType->setTo(container);
2194-
2195- (*meta)->setString("extended-extractor", "extended-extractor");
2196- (*meta)->setString("extended-extractor-subtype", "ffmpegextractor");
2197- (*meta)->setString("extended-extractor-mime", container);
2192+ msg->setString("extended-extractor", "extended-extractor");
2193+ msg->setString("extended-extractor-subtype", "ffmpegextractor");
2194+ msg->setString("extended-extractor-mime", container);
21982195
21992196 //debug only
22002197 char value[PROPERTY_VALUE_MAX];
@@ -2205,60 +2202,74 @@ bool SniffFFMPEG(
22052202 }
22062203
22072204 if (newConfidence > *confidence) {
2208- (*meta)->setString("extended-extractor-use", "ffmpegextractor");
2205+ msg->setString("extended-extractor-use", "ffmpegextractor");
22092206 *confidence = newConfidence;
22102207 }
22112208
2212- return true;
2209+ return CreateFFMPEGExtractor;
22132210 }
22142211
2215-MediaExtractor *CreateFFMPEGExtractor(const sp<DataSource> &source, const char *mime, const sp<AMessage> &meta) {
2212+static MediaExtractor *CreateFFMPEGExtractor(DataSourceBase *source, void *meta) {
22162213 MediaExtractor *ret = NULL;
2217- AString notuse;
2218- if (meta.get() && meta->findString("extended-extractor", &notuse) && (
2219- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG) ||
2220- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AAC) ||
2221- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_VORBIS) ||
2222- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_ALAC) ||
2223- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_FLAC) ||
2224- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AC3) ||
2225- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_APE) ||
2226- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_DTS) ||
2227- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II) ||
2228- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_RA) ||
2229- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_WMA) ||
2230- !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_FFMPEG) ||
2231- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG4) ||
2232- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MOV) ||
2233- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MATROSKA) ||
2234- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_TS) ||
2235- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPEG2PS) ||
2236- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_AVI) ||
2237- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_ASF) ||
2238- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WEBM) ||
2239- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WMV) ||
2240- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MPG) ||
2241- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_FLV) ||
2242- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_DIVX) ||
2243- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_RM) ||
2244- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WAV) ||
2245- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_FLAC) ||
2246- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_APE) ||
2247- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_DTS) ||
2248- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_MP2) ||
2249- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_RA) ||
2250- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_OGG) ||
2251- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_VC1) ||
2252- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_HEVC) ||
2253- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_WMA) ||
2254- !strcasecmp(mime, MEDIA_MIMETYPE_CONTAINER_FFMPEG))) {
2255- ret = new FFmpegExtractor(source, meta);
2256- }
2257-
2258- ALOGD("%ssupported mime: %s", (ret ? "" : "un"), mime);
2214+ sp<AMessage> msg = static_cast<AMessage *>(meta);
2215+ AString mime;
2216+ if (msg.get() && msg->findString("extended-extractor-mime", &mime) && (
2217+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_MPEG) ||
2218+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_AAC) ||
2219+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_VORBIS) ||
2220+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_ALAC) ||
2221+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_FLAC) ||
2222+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_AC3) ||
2223+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_APE) ||
2224+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_DTS) ||
2225+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II) ||
2226+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_RA) ||
2227+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_WMA) ||
2228+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_AUDIO_FFMPEG) ||
2229+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_MPEG4) ||
2230+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_MOV) ||
2231+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_MATROSKA) ||
2232+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_TS) ||
2233+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_MPEG2PS) ||
2234+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_AVI) ||
2235+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_ASF) ||
2236+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_WEBM) ||
2237+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_WMV) ||
2238+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_MPG) ||
2239+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_FLV) ||
2240+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_DIVX) ||
2241+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_RM) ||
2242+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_WAV) ||
2243+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_FLAC) ||
2244+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_APE) ||
2245+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_DTS) ||
2246+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_MP2) ||
2247+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_RA) ||
2248+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_OGG) ||
2249+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_VC1) ||
2250+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_HEVC) ||
2251+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_WMA) ||
2252+ !strcasecmp(mime.c_str(), MEDIA_MIMETYPE_CONTAINER_FFMPEG))) {
2253+ ret = new FFmpegExtractor(source, msg);
2254+ }
2255+
2256+ ALOGD("%ssupported mime: %s", (ret ? "" : "un"), mime.c_str());
22592257 return ret;
22602258 }
22612259
2260+extern "C" {
2261+
2262+__attribute__ ((visibility ("default")))
2263+MediaExtractor::ExtractorDef GETEXTRACTORDEF() {
2264+ return {
2265+ MediaExtractor::EXTRACTORDEF_VERSION,
2266+ UUID("280e1e71-d08b-4d8c-ba03-d775497fc4bc"),
2267+ 1, // version
2268+ "FFMPEG Extractor",
2269+ SniffFFMPEG
2270+ };
2271+}
2272+
22622273 }
22632274
22642275 }; // namespace android
--- a/extractor/FFmpegExtractor.h
+++ b/extractor/FFmpegExtractor.h
@@ -18,11 +18,11 @@
1818
1919 #define SUPER_EXTRACTOR_H_
2020
21+#include <media/MediaExtractor.h>
22+#include <media/MediaSource.h>
2123 #include <media/stagefright/foundation/ABase.h>
22-#include <media/stagefright/MediaExtractor.h>
2324 #include <utils/threads.h>
2425 #include <utils/KeyedVector.h>
25-#include <media/stagefright/MediaSource.h>
2626
2727 #include "utils/ffmpeg_utils.h"
2828
@@ -34,13 +34,13 @@ class String8;
3434 struct FFmpegSource;
3535
3636 struct FFmpegExtractor : public MediaExtractor {
37- FFmpegExtractor(const sp<DataSource> &source, const sp<AMessage> &meta);
37+ FFmpegExtractor(DataSourceBase *source, const sp<AMessage> &meta);
3838
3939 virtual size_t countTracks();
40- virtual sp<IMediaSource> getTrack(size_t index);
41- virtual sp<MetaData> getTrackMetaData(size_t index, uint32_t flags);
40+ virtual MediaTrack* getTrack(size_t index);
41+ virtual status_t getTrackMetaData(MetaDataBase &meta, size_t index, uint32_t flags);
4242
43- virtual sp<MetaData> getMetaData();
43+ virtual status_t getMetaData(MetaDataBase &meta);
4444
4545 virtual uint32_t flags() const;
4646
@@ -52,7 +52,7 @@ private:
5252
5353 struct TrackInfo {
5454 int mIndex; //stream index
55- sp<MetaData> mMeta;
55+ MetaDataBase mMeta;
5656 AVStream *mStream;
5757 PacketQueue *mQueue;
5858 };
@@ -63,8 +63,8 @@ private:
6363 mutable Mutex mExtractorMutex;
6464 Condition mCondition;
6565
66- sp<DataSource> mDataSource;
67- sp<MetaData> mMeta;
66+ DataSourceBase *mDataSource;
67+ MetaDataBase mMeta;
6868 status_t mInitCheck;
6969
7070 char mFilename[PATH_MAX];
@@ -112,9 +112,9 @@ private:
112112 void setFFmpegDefaultOpts();
113113 void printTime(int64_t time);
114114 bool is_codec_supported(enum AVCodecID codec_id);
115- sp<MetaData> setVideoFormat(AVStream *stream);
116- sp<MetaData> setAudioFormat(AVStream *stream);
117- void setDurationMetaData(AVStream *stream, sp<MetaData> &meta);
115+ status_t setVideoFormat(AVStream *stream, MetaDataBase &meta);
116+ status_t setAudioFormat(AVStream *stream, MetaDataBase &meta);
117+ void setDurationMetaData(AVStream *stream, MetaDataBase &meta);
118118 int stream_component_open(int stream_index);
119119 void stream_component_close(int stream_index);
120120 void reachedEOS(enum AVMediaType media_type);
@@ -134,6 +134,7 @@ private:
134134 DISALLOW_EVIL_CONSTRUCTORS(FFmpegExtractor);
135135 };
136136
137+/*
137138 extern "C" {
138139
139140 static const char *findMatchingContainer(const char *name);
@@ -146,6 +147,7 @@ MediaExtractor* CreateFFMPEGExtractor(const sp<DataSource> &source,
146147 const char *mime, const sp<AMessage> &meta);
147148
148149 }
150+*/
149151
150152 } // namespace android
151153
--- a/omx/Android.mk
+++ b/omx/Android.mk
@@ -14,6 +14,7 @@ LOCAL_C_INCLUDES += \
1414 LOCAL_SHARED_LIBRARIES += \
1515 libdl \
1616 libffmpeg_utils \
17+ android.hidl.memory@1.0 \
1718 $(if $(filter true,$(BOARD_USE_LIBAV)),libavresample,libswresample) \
1819 liblog \
1920 libnativewindow \
--- a/omx/FFmpegOMXPlugin.cpp
+++ b/omx/FFmpegOMXPlugin.cpp
@@ -85,8 +85,6 @@ OMX_ERRORTYPE FFmpegOMXPlugin::destroyComponentInstance(
8585
8686 me->prepareForDestruction();
8787
88- void *libHandle = me->libHandle();
89-
9088 CHECK_EQ(me->getStrongCount(), 1);
9189 me->decStrong(this);
9290 me = NULL;
--- a/omx/SoftFFmpegVideo.cpp
+++ b/omx/SoftFFmpegVideo.cpp
@@ -515,7 +515,7 @@ void SoftFFmpegVideo::initPacket(AVPacket *pkt,
515515 }
516516
517517 int32_t SoftFFmpegVideo::decodeVideo() {
518- int len = 0, err = 0;
518+ int err = 0;
519519 int gotPic = false;
520520 int32_t ret = ERR_OK;
521521 List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
@@ -591,8 +591,10 @@ int32_t SoftFFmpegVideo::drainOneOutputBuffer() {
591591
592592 uint32_t bufferWidth = outputBufferWidth();
593593 uint32_t bufferHeight = outputBufferHeight();
594+#if DEBUG_FRM
594595 uint32_t frameWidth = mFrame->width;
595596 uint32_t frameHeight = mFrame->height;
597+#endif
596598
597599 data[0] = dst;
598600 data[1] = dst + bufferWidth * bufferHeight;
@@ -601,8 +603,10 @@ int32_t SoftFFmpegVideo::drainOneOutputBuffer() {
601603 linesize[1] = bufferWidth / 2;
602604 linesize[2] = bufferWidth / 2;
603605
606+#if DEBUG_FRM
604607 ALOGD("drainOneOutputBuffer: frame_width=%d frame_height=%d buffer_width=%d buffer_height=%d ctx_width=%d ctx_height=%d mIsAdaptive=%d",
605608 frameWidth, frameHeight, bufferWidth, bufferHeight, mCtx->width, mCtx->height, mIsAdaptive);
609+#endif
606610
607611 int sws_flags = SWS_BICUBIC;
608612 mImgConvertCtx = sws_getCachedContext(mImgConvertCtx,
--- a/utils/Android.mk
+++ b/utils/Android.mk
@@ -10,7 +10,10 @@ LOCAL_SRC_FILES := \
1010
1111 LOCAL_SHARED_LIBRARIES += \
1212 liblog \
13- libmedia
13+ libmediaextractor \
14+ libstagefright
15+
16+LOCAL_STATIC_LIBRARIES += libstagefright_metadatautils
1417
1518 LOCAL_MODULE := libffmpeg_utils
1619
--- a/utils/codec_utils.cpp
+++ b/utils/codec_utils.cpp
@@ -28,10 +28,11 @@ extern "C" {
2828 #include <utils/Errors.h>
2929 #include <media/stagefright/foundation/ABitReader.h>
3030 #include <media/stagefright/foundation/ADebug.h>
31+#include <media/stagefright/foundation/avc_utils.h>
3132 #include <media/stagefright/MediaDefs.h>
3233 #include <media/stagefright/MediaErrors.h>
3334 #include <media/stagefright/MetaData.h>
34-#include "include/avc_utils.h"
35+#include <media/stagefright/MetaDataUtils.h>
3536
3637 #include "codec_utils.h"
3738
@@ -83,7 +84,7 @@ static sp<ABuffer> MakeMPEGVideoESDS(const sp<ABuffer> &csd) {
8384 //http://msdn.microsoft.com/en-us/library/dd757808(v=vs.85).aspx
8485
8586 // H.264 bitstream without start codes.
86-sp<MetaData> setAVCFormat(AVCodecContext *avctx)
87+status_t setAVCFormat(AVCodecContext *avctx, MetaDataBase &meta)
8788 {
8889 ALOGV("AVC");
8990
@@ -99,26 +100,26 @@ sp<MetaData> setAVCFormat(AVCodecContext *avctx)
99100 avctx->height = height;
100101 }
101102
102- sp<MetaData> meta = new MetaData;
103- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
104- meta->setData(kKeyAVCC, kTypeAVCC, avctx->extradata, avctx->extradata_size);
103+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
104+ meta.setData(kKeyAVCC, kTypeAVCC, avctx->extradata, avctx->extradata_size);
105105
106- return meta;
106+ return OK;
107107 }
108108
109109 // H.264 bitstream with start codes.
110-sp<MetaData> setH264Format(AVCodecContext *avctx)
110+status_t setH264Format(AVCodecContext *avctx, MetaDataBase &meta)
111111 {
112112 ALOGV("H264");
113113
114114 CHECK_NE((int)avctx->extradata[0], 1); //configurationVersion
115115
116- sp<ABuffer> buffer = new ABuffer(avctx->extradata_size);
117- memcpy(buffer->data(), avctx->extradata, avctx->extradata_size);
118- return MakeAVCCodecSpecificData(buffer);
116+ if (!MakeAVCCodecSpecificData(meta, avctx->extradata, avctx->extradata_size))
117+ return UNKNOWN_ERROR;
118+
119+ return OK;
119120 }
120121
121-sp<MetaData> setMPEG4Format(AVCodecContext *avctx)
122+status_t setMPEG4Format(AVCodecContext *avctx, MetaDataBase &meta)
122123 {
123124 ALOGV("MPEG4");
124125
@@ -126,30 +127,28 @@ sp<MetaData> setMPEG4Format(AVCodecContext *avctx)
126127 memcpy(csd->data(), avctx->extradata, avctx->extradata_size);
127128 sp<ABuffer> esds = MakeMPEGVideoESDS(csd);
128129
129- sp<MetaData> meta = new MetaData;
130- meta->setData(kKeyESDS, kTypeESDS, esds->data(), esds->size());
130+ meta.setData(kKeyESDS, kTypeESDS, esds->data(), esds->size());
131131
132132 int divxVersion = getDivXVersion(avctx);
133133 if (divxVersion >= 0) {
134- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_DIVX);
135- meta->setInt32(kKeyDivXVersion, divxVersion);
134+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_DIVX);
135+ meta.setInt32(kKeyDivXVersion, divxVersion);
136136 } else {
137- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG4);
137+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG4);
138138 }
139- return meta;
139+ return OK;
140140 }
141141
142-sp<MetaData> setH263Format(AVCodecContext *avctx __unused)
142+status_t setH263Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
143143 {
144144 ALOGV("H263");
145145
146- sp<MetaData> meta = new MetaData;
147- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_H263);
146+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_H263);
148147
149- return meta;
148+ return OK;
150149 }
151150
152-sp<MetaData> setMPEG2VIDEOFormat(AVCodecContext *avctx)
151+status_t setMPEG2VIDEOFormat(AVCodecContext *avctx, MetaDataBase &meta)
153152 {
154153 ALOGV("MPEG%uVIDEO", avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 2 : 1);
155154
@@ -157,160 +156,146 @@ sp<MetaData> setMPEG2VIDEOFormat(AVCodecContext *avctx)
157156 memcpy(csd->data(), avctx->extradata, avctx->extradata_size);
158157 sp<ABuffer> esds = MakeMPEGVideoESDS(csd);
159158
160- sp<MetaData> meta = new MetaData;
161- meta->setData(kKeyESDS, kTypeESDS, esds->data(), esds->size());
162- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG2);
159+ meta.setData(kKeyESDS, kTypeESDS, esds->data(), esds->size());
160+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG2);
163161
164- return meta;
162+ return OK;
165163 }
166164
167-sp<MetaData> setVC1Format(AVCodecContext *avctx)
165+status_t setVC1Format(AVCodecContext *avctx, MetaDataBase &meta)
168166 {
169167 ALOGV("VC1");
170168
171- sp<MetaData> meta = new MetaData;
172- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_VC1);
173- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
169+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_VC1);
170+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
174171
175- return meta;
172+ return OK;
176173 }
177174
178-sp<MetaData> setWMV1Format(AVCodecContext *avctx __unused)
175+status_t setWMV1Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
179176 {
180177 ALOGV("WMV1");
181178
182- sp<MetaData> meta = new MetaData;
183- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_WMV);
184- meta->setInt32(kKeyWMVVersion, kTypeWMVVer_7);
179+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_WMV);
180+ meta.setInt32(kKeyWMVVersion, kTypeWMVVer_7);
185181
186- return meta;
182+ return OK;
187183 }
188184
189-sp<MetaData> setWMV2Format(AVCodecContext *avctx)
185+status_t setWMV2Format(AVCodecContext *avctx, MetaDataBase &meta)
190186 {
191187 ALOGV("WMV2");
192188
193- sp<MetaData> meta = new MetaData;
194- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_WMV);
195- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
196- meta->setInt32(kKeyWMVVersion, kTypeWMVVer_8);
189+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_WMV);
190+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
191+ meta.setInt32(kKeyWMVVersion, kTypeWMVVer_8);
197192
198- return meta;
193+ return OK;
199194 }
200195
201-sp<MetaData> setWMV3Format(AVCodecContext *avctx)
196+status_t setWMV3Format(AVCodecContext *avctx, MetaDataBase &meta)
202197 {
203198 ALOGV("WMV3");
204199
205- sp<MetaData> meta = new MetaData;
206- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_WMV);
207- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
208- meta->setInt32(kKeyWMVVersion, kTypeWMVVer_9);
200+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_WMV);
201+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
202+ meta.setInt32(kKeyWMVVersion, kTypeWMVVer_9);
209203
210- return meta;
204+ return OK;
211205 }
212206
213-sp<MetaData> setRV20Format(AVCodecContext *avctx)
207+status_t setRV20Format(AVCodecContext *avctx, MetaDataBase &meta)
214208 {
215209 ALOGV("RV20");
216210
217- sp<MetaData> meta = new MetaData;
218- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_RV);
219- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
220- meta->setInt32(kKeyRVVersion, kTypeRVVer_G2); //http://en.wikipedia.org/wiki/RealVide
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
221214
222- return meta;
215+ return OK;
223216 }
224217
225-sp<MetaData> setRV30Format(AVCodecContext *avctx)
218+status_t setRV30Format(AVCodecContext *avctx, MetaDataBase &meta)
226219 {
227220 ALOGV("RV30");
228221
229- sp<MetaData> meta = new MetaData;
230- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_RV);
231- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
232- meta->setInt32(kKeyRVVersion, kTypeRVVer_8); //http://en.wikipedia.org/wiki/RealVide
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
233225
234- return meta;
226+ return OK;
235227 }
236228
237-sp<MetaData> setRV40Format(AVCodecContext *avctx)
229+status_t setRV40Format(AVCodecContext *avctx, MetaDataBase &meta)
238230 {
239231 ALOGV("RV40");
240232
241- sp<MetaData> meta = new MetaData;
242- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_RV);
243- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
244- meta->setInt32(kKeyRVVersion, kTypeRVVer_9); //http://en.wikipedia.org/wiki/RealVide
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
245236
246- return meta;
237+ return OK;
247238 }
248239
249-sp<MetaData> setFLV1Format(AVCodecContext *avctx)
240+status_t setFLV1Format(AVCodecContext *avctx, MetaDataBase &meta)
250241 {
251242 ALOGV("FLV1(Sorenson H263)");
252243
253- sp<MetaData> meta = new MetaData;
254- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_FLV1);
255- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
244+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_FLV1);
245+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
256246
257- return meta;
247+ return OK;
258248 }
259249
260-sp<MetaData> setHEVCFormat(AVCodecContext *avctx)
250+status_t setHEVCFormat(AVCodecContext *avctx, MetaDataBase &meta)
261251 {
262252 ALOGV("HEVC");
263253
264- sp<MetaData> meta = new MetaData;
265- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_HEVC);
266- meta->setData(kKeyHVCC, kTypeHVCC, avctx->extradata, avctx->extradata_size);
254+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_HEVC);
255+ meta.setData(kKeyHVCC, kTypeHVCC, avctx->extradata, avctx->extradata_size);
267256
268- return meta;
257+ return OK;
269258 }
270259
271-sp<MetaData> setVP8Format(AVCodecContext *avctx __unused)
260+status_t setVP8Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
272261 {
273262 ALOGV("VP8");
274263
275- sp<MetaData> meta = new MetaData;
276- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_VP8);
264+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_VP8);
277265
278- return meta;
266+ return OK;
279267 }
280268
281-sp<MetaData> setVP9Format(AVCodecContext *avctx __unused)
269+status_t setVP9Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
282270 {
283271 ALOGV("VP9");
284272
285- sp<MetaData> meta = new MetaData;
286- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_VP9);
273+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_VP9);
287274
288- return meta;
275+ return OK;
289276 }
290277
291278 //audio
292279
293-sp<MetaData> setMP2Format(AVCodecContext *avctx __unused)
280+status_t setMP2Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
294281 {
295282 ALOGV("MP2");
296283
297- sp<MetaData> meta = new MetaData;
298- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II);
284+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II);
299285
300- return meta;
286+ return OK;
301287 }
302288
303-sp<MetaData> setMP3Format(AVCodecContext *avctx __unused)
289+status_t setMP3Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
304290 {
305291 ALOGV("MP3");
306292
307- sp<MetaData> meta = new MetaData;
308- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_MPEG);
293+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_MPEG);
309294
310- return meta;
295+ return OK;
311296 }
312297
313-sp<MetaData> setVORBISFormat(AVCodecContext *avctx)
298+status_t setVORBISFormat(AVCodecContext *avctx, MetaDataBase &meta)
314299 {
315300 ALOGV("VORBIS");
316301
@@ -320,143 +305,132 @@ sp<MetaData> setVORBISFormat(AVCodecContext *avctx)
320305 avctx->extradata_size, 30,
321306 header_start, header_len) < 0) {
322307 ALOGE("vorbis extradata corrupt.");
323- return NULL;
308+ return UNKNOWN_ERROR;
324309 }
325310
326- sp<MetaData> meta = new MetaData;
327- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_VORBIS);
311+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_VORBIS);
328312 //identification header
329- meta->setData(kKeyVorbisInfo, 0, header_start[0], header_len[0]);
313+ meta.setData(kKeyVorbisInfo, 0, header_start[0], header_len[0]);
330314 //setup header
331- meta->setData(kKeyVorbisBooks, 0, header_start[2], header_len[2]);
315+ meta.setData(kKeyVorbisBooks, 0, header_start[2], header_len[2]);
332316
333- return meta;
317+ return OK;
334318 }
335319
336-sp<MetaData> setAC3Format(AVCodecContext *avctx __unused)
320+status_t setAC3Format(AVCodecContext *avctx __unused, MetaDataBase &meta)
337321 {
338322 ALOGV("AC3");
339323
340- sp<MetaData> meta = new MetaData;
341- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AC3);
324+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AC3);
342325
343- return meta;
326+ return OK;
344327 }
345328
346-sp<MetaData> setAACFormat(AVCodecContext *avctx)
329+status_t setAACFormat(AVCodecContext *avctx, MetaDataBase &meta)
347330 {
348331 ALOGV("AAC");
349332
350- sp<MetaData> meta = new MetaData;
351- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AAC);
352- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
353- meta->setInt32(kKeyAACAOT, avctx->profile + 1);
354- return meta;
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);
336+
337+ return OK;
355338 }
356339
357-sp<MetaData> setWMAV1Format(AVCodecContext *avctx)
340+status_t setWMAV1Format(AVCodecContext *avctx, MetaDataBase &meta)
358341 {
359342 ALOGV("WMAV1");
360343
361- sp<MetaData> meta = new MetaData;
362- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_WMA);
363- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
364- meta->setInt32(kKeyWMAVersion, kTypeWMA); //FIXME version?
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?
365347
366- return meta;
348+ return OK;
367349 }
368350
369-sp<MetaData> setWMAV2Format(AVCodecContext *avctx)
351+status_t setWMAV2Format(AVCodecContext *avctx, MetaDataBase &meta)
370352 {
371353 ALOGV("WMAV2");
372354
373- sp<MetaData> meta = new MetaData;
374- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_WMA);
375- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
376- meta->setInt32(kKeyWMAVersion, kTypeWMA);
355+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_WMA);
356+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
357+ meta.setInt32(kKeyWMAVersion, kTypeWMA);
377358
378- return meta;
359+ return OK;
379360 }
380361
381-sp<MetaData> setWMAProFormat(AVCodecContext *avctx)
362+status_t setWMAProFormat(AVCodecContext *avctx, MetaDataBase &meta)
382363 {
383364 ALOGV("WMAPro");
384365
385- sp<MetaData> meta = new MetaData;
386- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_WMA);
387- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
388- meta->setInt32(kKeyWMAVersion, kTypeWMAPro);
366+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_WMA);
367+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
368+ meta.setInt32(kKeyWMAVersion, kTypeWMAPro);
389369
390- return meta;
370+ return OK;
391371 }
392372
393-sp<MetaData> setWMALossLessFormat(AVCodecContext *avctx)
373+status_t setWMALossLessFormat(AVCodecContext *avctx, MetaDataBase &meta)
394374 {
395375 ALOGV("WMALOSSLESS");
396376
397- sp<MetaData> meta = new MetaData;
398- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_WMA);
399- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
400- meta->setInt32(kKeyWMAVersion, kTypeWMALossLess);
377+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_WMA);
378+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
379+ meta.setInt32(kKeyWMAVersion, kTypeWMALossLess);
401380
402- return meta;
381+ return OK;
403382 }
404383
405-sp<MetaData> setRAFormat(AVCodecContext *avctx)
384+status_t setRAFormat(AVCodecContext *avctx, MetaDataBase &meta)
406385 {
407386 ALOGV("COOK");
408387
409- sp<MetaData> meta = new MetaData;
410- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_RA);
411- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
388+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_RA);
389+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
412390
413- return meta;
391+ return OK;
414392 }
415393
416-sp<MetaData> setALACFormat(AVCodecContext *avctx)
394+status_t setALACFormat(AVCodecContext *avctx, MetaDataBase &meta)
417395 {
418396 ALOGV("ALAC");
419397
420- sp<MetaData> meta = new MetaData;
421- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_ALAC);
422- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
398+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_ALAC);
399+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
423400
424- return meta;
401+ return OK;
425402 }
426403
427-sp<MetaData> setAPEFormat(AVCodecContext *avctx)
404+status_t setAPEFormat(AVCodecContext *avctx, MetaDataBase &meta)
428405 {
429406 ALOGV("APE");
430407
431- sp<MetaData> meta = new MetaData;
432- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_APE);
433- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
408+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_APE);
409+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
434410
435- return meta;
411+ return OK;
436412 }
437413
438-sp<MetaData> setDTSFormat(AVCodecContext *avctx)
414+status_t setDTSFormat(AVCodecContext *avctx, MetaDataBase &meta)
439415 {
440416 ALOGV("DTS");
441417
442- sp<MetaData> meta = new MetaData;
443- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_DTS);
444- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
418+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_DTS);
419+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
445420
446- return meta;
421+ return OK;
447422 }
448423
449-sp<MetaData> setFLACFormat(AVCodecContext *avctx)
424+status_t setFLACFormat(AVCodecContext *avctx, MetaDataBase &meta)
450425 {
451426 ALOGV("FLAC");
452427
453- sp<MetaData> meta = new MetaData;
454- meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_FLAC);
455- meta->setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
428+ meta.setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_FLAC);
429+ meta.setData(kKeyRawCodecSpecificData, 0, avctx->extradata, avctx->extradata_size);
456430
457431 if (avctx->extradata_size < 10) {
458432 ALOGE("Invalid extradata in FLAC file! (size=%d)", avctx->extradata_size);
459- return meta;
433+ return UNKNOWN_ERROR;
460434 }
461435
462436 ABitReader br(avctx->extradata, avctx->extradata_size);
@@ -465,12 +439,12 @@ sp<MetaData> setFLACFormat(AVCodecContext *avctx)
465439 int32_t minFrameSize = br.getBits(24);
466440 int32_t maxFrameSize = br.getBits(24);
467441
468- meta->setInt32('mibs', minBlockSize);
469- meta->setInt32('mabs', maxBlockSize);
470- meta->setInt32('mifs', minFrameSize);
471- meta->setInt32('mafs', maxFrameSize);
442+ meta.setInt32('mibs', minBlockSize);
443+ meta.setInt32('mabs', maxBlockSize);
444+ meta.setInt32('mifs', minFrameSize);
445+ meta.setInt32('mafs', maxFrameSize);
472446
473- return meta;
447+ return OK;
474448 }
475449
476450 //Convert H.264 NAL format to annex b
@@ -528,8 +502,8 @@ int getDivXVersion(AVCodecContext *avctx)
528502 return -1;
529503 }
530504
531-status_t parseMetadataTags(AVFormatContext *ctx, const sp<MetaData> &meta) {
532- if (meta == NULL || ctx == NULL) {
505+status_t parseMetadataTags(AVFormatContext *ctx, MetaDataBase &meta) {
506+ if (ctx == NULL) {
533507 return NO_INIT;
534508 }
535509
@@ -565,7 +539,7 @@ status_t parseMetadataTags(AVFormatContext *ctx, const sp<MetaData> &meta) {
565539 AVDictionaryEntry *entry = av_dict_get(dict, kMap[i].from, NULL, 0);
566540 if (entry != NULL) {
567541 ALOGV("found key %s with value %s", entry->key, entry->value);
568- meta->setCString(kMap[i].to, entry->value);
542+ meta.setCString(kMap[i].to, entry->value);
569543 }
570544 }
571545
@@ -585,8 +559,8 @@ status_t parseMetadataTags(AVFormatContext *ctx, const sp<MetaData> &meta) {
585559 }
586560 if (mime != NULL) {
587561 ALOGV("found albumart in stream %zu with type %s len %d", i, mime, pkt.size);
588- meta->setData(kKeyAlbumArt, MetaData::TYPE_NONE, pkt.data, pkt.size);
589- meta->setCString(kKeyAlbumArtMIME, mime);
562+ meta.setData(kKeyAlbumArt, MetaData::TYPE_NONE, pkt.data, pkt.size);
563+ meta.setCString(kKeyAlbumArtMIME, mime);
590564 }
591565 }
592566 }
--- a/utils/codec_utils.h
+++ b/utils/codec_utils.h
@@ -29,37 +29,37 @@
2929 namespace android {
3030
3131 //video
32-sp<MetaData> setAVCFormat(AVCodecContext *avctx);
33-sp<MetaData> setH264Format(AVCodecContext *avctx);
34-sp<MetaData> setMPEG4Format(AVCodecContext *avctx);
35-sp<MetaData> setH263Format(AVCodecContext *avctx);
36-sp<MetaData> setMPEG2VIDEOFormat(AVCodecContext *avctx);
37-sp<MetaData> setVC1Format(AVCodecContext *avctx);
38-sp<MetaData> setWMV1Format(AVCodecContext *avctx);
39-sp<MetaData> setWMV2Format(AVCodecContext *avctx);
40-sp<MetaData> setWMV3Format(AVCodecContext *avctx);
41-sp<MetaData> setRV20Format(AVCodecContext *avctx);
42-sp<MetaData> setRV30Format(AVCodecContext *avctx);
43-sp<MetaData> setRV40Format(AVCodecContext *avctx);
44-sp<MetaData> setFLV1Format(AVCodecContext *avctx);
45-sp<MetaData> setHEVCFormat(AVCodecContext *avctx);
46-sp<MetaData> setVP8Format(AVCodecContext *avctx);
47-sp<MetaData> setVP9Format(AVCodecContext *avctx);
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);
4848 //audio
49-sp<MetaData> setMP2Format(AVCodecContext *avctx);
50-sp<MetaData> setMP3Format(AVCodecContext *avctx);
51-sp<MetaData> setVORBISFormat(AVCodecContext *avctx);
52-sp<MetaData> setAC3Format(AVCodecContext *avctx);
53-sp<MetaData> setAACFormat(AVCodecContext *avctx);
54-sp<MetaData> setWMAV1Format(AVCodecContext *avctx);
55-sp<MetaData> setWMAV2Format(AVCodecContext *avctx);
56-sp<MetaData> setWMAProFormat(AVCodecContext *avctx);
57-sp<MetaData> setWMALossLessFormat(AVCodecContext *avctx);
58-sp<MetaData> setRAFormat(AVCodecContext *avctx);
59-sp<MetaData> setAPEFormat(AVCodecContext *avctx);
60-sp<MetaData> setDTSFormat(AVCodecContext *avctx);
61-sp<MetaData> setFLACFormat(AVCodecContext *avctx);
62-sp<MetaData> setALACFormat(AVCodecContext *avctx);
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);
6363
6464 //Convert H.264 NAL format to annex b
6565 status_t convertNal2AnnexB(uint8_t *dst, size_t dst_size,
@@ -67,7 +67,7 @@ status_t convertNal2AnnexB(uint8_t *dst, size_t dst_size,
6767
6868 int getDivXVersion(AVCodecContext *avctx);
6969
70-status_t parseMetadataTags(AVFormatContext *ctx, const sp<MetaData> &meta);
70+status_t parseMetadataTags(AVFormatContext *ctx, MetaDataBase &meta);
7171
7272 AudioEncoding sampleFormatToEncoding(AVSampleFormat fmt);
7373 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/stagefright/DataSource.h>
23+#include <media/DataSourceBase.h>
2424
2525 extern "C" {
2626
@@ -34,14 +34,14 @@ namespace android {
3434 class FFSource
3535 {
3636 public:
37- void set(DataSource *s) { mSource = s; }
37+ void set(DataSourceBase *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- sp<DataSource> mSource;
44+ DataSourceBase *mSource;
4545 int64_t mOffset;
4646 };
4747
@@ -93,9 +93,9 @@ off64_t FFSource::getSize()
9393
9494 static int android_open(URLContext *h, const char *url, int flags __unused)
9595 {
96- // the url in form of "android-source:<DataSource Ptr>",
97- // the DataSource Pointer passed by the ffmpeg extractor
98- DataSource *source = NULL;
96+ // the url in form of "android-source:<DataSourceBase Ptr>",
97+ // the DataSourceBase Pointer passed by the ffmpeg extractor
98+ DataSourceBase *source = NULL;
9999 char url_check[PATH_MAX] = {0};
100100
101101 ALOGV("android source begin open");
@@ -117,14 +117,14 @@ static int android_open(URLContext *h, const char *url, int flags __unused)
117117
118118 if (strcmp(url_check, url) != 0) {
119119
120- String8 uri = source->getUri();
121- if (!uri.string()) {
120+ char uri[PATH_MAX] = {0};
121+ if (!source->getUri(uri, sizeof(uri))) {
122122 ALOGE("ffmpeg open data source error! (source uri)");
123123 return -1;
124124 }
125125
126126 snprintf(url_check, sizeof(url_check), "android-source:%p|file:%s",
127- source, uri.string());
127+ source, uri);
128128
129129 if (strcmp(url_check, url) != 0) {
130130 ALOGE("ffmpeg open data source error! (url check)");
--- a/utils/ffmpeg_utils.cpp
+++ b/utils/ffmpeg_utils.cpp
@@ -44,10 +44,6 @@ extern "C" {
4444 // log
4545 static int flags;
4646
47-// dummy
48-const char program_name[] = "dummy";
49-const int program_birth_year = 2012;
50-
5147 // init ffmpeg
5248 static pthread_mutex_t s_init_mutex = PTHREAD_MUTEX_INITIALIZER;
5349 static int s_ref_count = 0;
@@ -72,7 +68,6 @@ void nam_av_log_callback(void* ptr, int level, const char* fmt, va_list vl)
7268 static int count;
7369 static char prev[1024];
7470 char line[1024];
75- static int is_atty;
7671
7772 if (level > av_log_get_level())
7873 return;
Show on old repository browser