diff options
author | Praveen Chavan <pchavan@codeaurora.org> | 2014-08-13 12:53:00 -0700 |
---|---|---|
committer | Lajos Molnar <lajos@google.com> | 2015-05-05 11:55:48 -0700 |
commit | 8b07404cfe564885045a63bb592d6b6dc838b408 (patch) | |
tree | 6933fc329e57267289f88e7bf8a3e2c20c32070b /media/libstagefright/MPEG4Writer.cpp | |
parent | ebea5e7d0697c024c1ddf6001dcd33036e9bd95f (diff) | |
download | frameworks_av-8b07404cfe564885045a63bb592d6b6dc838b408.zip frameworks_av-8b07404cfe564885045a63bb592d6b6dc838b408.tar.gz frameworks_av-8b07404cfe564885045a63bb592d6b6dc838b408.tar.bz2 |
stagefright: Validate track formats passed to MPEG4Writer
Validate the mime type for tracks to start with; and throw
an error for unsupported types rather than let apps re-mux/encode
the whole clip and assert towards the end while writing the header.
The writer asserts if provided with an unsupported mime when
authoring the fourcc, which is done at the end of muxing.
Bug: 17007397
Change-Id: Ie80372940a46038db73107101a2ae6fdecf72eaa
Diffstat (limited to 'media/libstagefright/MPEG4Writer.cpp')
-rw-r--r-- | media/libstagefright/MPEG4Writer.cpp | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp index beb12ec..3bc22f2 100644 --- a/media/libstagefright/MPEG4Writer.cpp +++ b/media/libstagefright/MPEG4Writer.cpp @@ -94,6 +94,7 @@ public: void addChunkOffset(off64_t offset); int32_t getTrackId() const { return mTrackId; } status_t dump(int fd, const Vector<String16>& args) const; + static const char *getFourCCForMime(const char *mime); private: enum { @@ -426,6 +427,33 @@ status_t MPEG4Writer::Track::dump( return OK; } +// static +const char *MPEG4Writer::Track::getFourCCForMime(const char *mime) { + if (mime == NULL) { + return NULL; + } + if (!strncasecmp(mime, "audio/", 6)) { + if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_NB, mime)) { + return "samr"; + } else if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_WB, mime)) { + return "sawb"; + } else if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AAC, mime)) { + return "mp4a"; + } + } else if (!strncasecmp(mime, "video/", 6)) { + if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_MPEG4, mime)) { + return "mp4v"; + } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_H263, mime)) { + return "s263"; + } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime)) { + return "avc1"; + } + } else { + ALOGE("Track (%s) other than video or audio is not supported", mime); + } + return NULL; +} + status_t MPEG4Writer::addSource(const sp<MediaSource> &source) { Mutex::Autolock l(mLock); if (mStarted) { @@ -441,14 +469,11 @@ status_t MPEG4Writer::addSource(const sp<MediaSource> &source) { CHECK(source.get() != NULL); - // A track of type other than video or audio is not supported. const char *mime; source->getFormat()->findCString(kKeyMIMEType, &mime); bool isAudio = !strncasecmp(mime, "audio/", 6); - bool isVideo = !strncasecmp(mime, "video/", 6); - if (!isAudio && !isVideo) { - ALOGE("Track (%s) other than video or audio is not supported", - mime); + if (Track::getFourCCForMime(mime) == NULL) { + ALOGE("Unsupported mime '%s'", mime); return ERROR_UNSUPPORTED; } @@ -2730,17 +2755,13 @@ void MPEG4Writer::Track::writeVideoFourCCBox() { const char *mime; bool success = mMeta->findCString(kKeyMIMEType, &mime); CHECK(success); - if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_MPEG4, mime)) { - mOwner->beginBox("mp4v"); - } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_H263, mime)) { - mOwner->beginBox("s263"); - } else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime)) { - mOwner->beginBox("avc1"); - } else { + const char *fourcc = getFourCCForMime(mime); + if (fourcc == NULL) { ALOGE("Unknown mime type '%s'.", mime); CHECK(!"should not be here, unknown mime type."); } + mOwner->beginBox(fourcc); // video format mOwner->writeInt32(0); // reserved mOwner->writeInt16(0); // reserved mOwner->writeInt16(1); // data ref index @@ -2784,14 +2805,8 @@ void MPEG4Writer::Track::writeAudioFourCCBox() { const char *mime; bool success = mMeta->findCString(kKeyMIMEType, &mime); CHECK(success); - const char *fourcc = NULL; - if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_NB, mime)) { - fourcc = "samr"; - } else if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AMR_WB, mime)) { - fourcc = "sawb"; - } else if (!strcasecmp(MEDIA_MIMETYPE_AUDIO_AAC, mime)) { - fourcc = "mp4a"; - } else { + const char *fourcc = getFourCCForMime(mime); + if (fourcc == NULL) { ALOGE("Unknown mime type '%s'.", mime); CHECK(!"should not be here, unknown mime type."); } |