diff options
author | Robert Shih <robertshih@google.com> | 2014-06-12 14:49:23 -0700 |
---|---|---|
committer | Robert Shih <robertshih@google.com> | 2014-07-16 20:32:21 +0000 |
commit | dd235727a1b4e283deeb581559f99c2c8889da07 (patch) | |
tree | f0adac3a3a1cc1c48e40caf470452608f12cbf20 /media/libmediaplayerservice/nuplayer | |
parent | d81d48961da30f657fb095ed00a697bd50266269 (diff) | |
download | frameworks_av-dd235727a1b4e283deeb581559f99c2c8889da07.zip frameworks_av-dd235727a1b4e283deeb581559f99c2c8889da07.tar.gz frameworks_av-dd235727a1b4e283deeb581559f99c2c8889da07.tar.bz2 |
GenericSource: implement getTrackCount/getTrackInfo
Bug: 15153976
Change-Id: I0204c4188d485cda026497469c7cde24f7bd5c95
Diffstat (limited to 'media/libmediaplayerservice/nuplayer')
-rw-r--r-- | media/libmediaplayerservice/nuplayer/GenericSource.cpp | 59 | ||||
-rw-r--r-- | media/libmediaplayerservice/nuplayer/GenericSource.h | 5 |
2 files changed, 61 insertions, 3 deletions
diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.cpp b/media/libmediaplayerservice/nuplayer/GenericSource.cpp index 388f77a..cc0cb01 100644 --- a/media/libmediaplayerservice/nuplayer/GenericSource.cpp +++ b/media/libmediaplayerservice/nuplayer/GenericSource.cpp @@ -81,11 +81,12 @@ void NuPlayer::GenericSource::initFromDataSource( const char *mime; CHECK(meta->findCString(kKeyMIMEType, &mime)); - sp<MediaSource> track; + sp<MediaSource> track = extractor->getTrack(i); if (!strncasecmp(mime, "audio/", 6)) { if (mAudioTrack.mSource == NULL) { - mAudioTrack.mSource = track = extractor->getTrack(i); + mAudioTrack.mIndex = i; + mAudioTrack.mSource = track; if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_VORBIS)) { mAudioIsVorbis = true; @@ -95,11 +96,13 @@ void NuPlayer::GenericSource::initFromDataSource( } } else if (!strncasecmp(mime, "video/", 6)) { if (mVideoTrack.mSource == NULL) { - mVideoTrack.mSource = track = extractor->getTrack(i); + mVideoTrack.mIndex = i; + mVideoTrack.mSource = track; } } if (track != NULL) { + mSources.push(track); int64_t durationUs; if (meta->findInt64(kKeyDuration, &durationUs)) { if (durationUs > mDurationUs) { @@ -194,6 +197,56 @@ status_t NuPlayer::GenericSource::getDuration(int64_t *durationUs) { return OK; } +size_t NuPlayer::GenericSource::getTrackCount() const { + return mSources.size(); +} + +sp<AMessage> NuPlayer::GenericSource::getTrackInfo(size_t trackIndex) const { + size_t trackCount = mSources.size(); + if (trackIndex >= trackCount) { + return NULL; + } + + sp<AMessage> format = new AMessage(); + sp<MetaData> meta = mSources.itemAt(trackIndex)->getFormat(); + + const char *mime; + CHECK(meta->findCString(kKeyMIMEType, &mime)); + + int32_t trackType; + if (!strncasecmp(mime, "video/", 6)) { + trackType = MEDIA_TRACK_TYPE_VIDEO; + } else if (!strncasecmp(mime, "audio/", 6)) { + trackType = MEDIA_TRACK_TYPE_AUDIO; + } else if (!strcasecmp(mime, MEDIA_MIMETYPE_TEXT_3GPP)) { + trackType = MEDIA_TRACK_TYPE_TIMEDTEXT; + } else { + trackType = MEDIA_TRACK_TYPE_UNKNOWN; + } + format->setInt32("type", trackType); + + const char *lang; + if (!meta->findCString(kKeyMediaLanguage, &lang)) { + lang = "und"; + } + format->setString("language", lang); + + if (trackType == MEDIA_TRACK_TYPE_SUBTITLE) { + format->setString("mime", mime); + + int32_t isAutoselect = 1, isDefault = 0, isForced = 0; + meta->findInt32(kKeyTrackIsAutoselect, &isAutoselect); + meta->findInt32(kKeyTrackIsDefault, &isDefault); + meta->findInt32(kKeyTrackIsForced, &isForced); + + format->setInt32("auto", !!isAutoselect); + format->setInt32("default", !!isDefault); + format->setInt32("forced", !!isForced); + } + + return format; +} + status_t NuPlayer::GenericSource::seekTo(int64_t seekTimeUs) { if (mVideoTrack.mSource != NULL) { int64_t actualTimeUs; diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.h b/media/libmediaplayerservice/nuplayer/GenericSource.h index 20d597e..e0cd20f 100644 --- a/media/libmediaplayerservice/nuplayer/GenericSource.h +++ b/media/libmediaplayerservice/nuplayer/GenericSource.h @@ -50,6 +50,8 @@ struct NuPlayer::GenericSource : public NuPlayer::Source { virtual status_t dequeueAccessUnit(bool audio, sp<ABuffer> *accessUnit); virtual status_t getDuration(int64_t *durationUs); + virtual size_t getTrackCount() const; + virtual sp<AMessage> getTrackInfo(size_t trackIndex) const; virtual status_t seekTo(int64_t seekTimeUs); protected: @@ -58,7 +60,10 @@ protected: virtual sp<MetaData> getFormatMeta(bool audio); private: + Vector<sp<MediaSource> > mSources; + struct Track { + size_t mIndex; sp<MediaSource> mSource; sp<AnotherPacketSource> mPackets; }; |