From a44153c1a57202fb538659eb50706e60454d6273 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Fri, 3 Dec 2010 16:12:25 -0800 Subject: Squashed commit of the following: commit 9254c845d7c82976fd4b8be406ce4b17eeb0e119 Author: Andreas Huber Date: Fri Dec 3 15:26:12 2010 -0800 Remove obsolete code from the cached data source. Change-Id: I794b986ac8977cbc834dff189221a636ba564e36 commit 2ee33711064c58c53ba65ed9e63dd4b01ec2380e Author: Andreas Huber Date: Fri Dec 3 15:23:13 2010 -0800 LiveSource is dead, long live LiveSession. Change-Id: Ibcd0731ecf9c94f0b3e5db3d53d012d9da2a1c66 commit 9eabb2c3cd8571ab859bdeae0aa7f655c414d8fa Author: Andreas Huber Date: Fri Dec 3 12:49:31 2010 -0800 Respect explicitly signalled discontinuities. Change-Id: I3c0c16a2de7a99742d25db7d1b2ff0258de52271 commit 7f7f7b6b906b6ece6e4d43af7fd5f494e805c5e5 Author: Andreas Huber Date: Fri Dec 3 11:45:57 2010 -0800 Better protection against syncword emulation in AAC ADTS content. Change-Id: I867e80a4556dd46d24ab3e781177c248a5221719 commit fe765766582efcc350aed01135ea603576adccf6 Author: Andreas Huber Date: Fri Dec 3 09:15:59 2010 -0800 New implementation of http live driving code. Change-Id: I31ddf3d6a0d5929b121be704a2b9c3d6775f7737 Change-Id: Id8d1829c8fcb173756965013f848c1d426ef1048 --- media/libstagefright/mpeg2ts/ESQueue.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'media/libstagefright/mpeg2ts/ESQueue.cpp') diff --git a/media/libstagefright/mpeg2ts/ESQueue.cpp b/media/libstagefright/mpeg2ts/ESQueue.cpp index 37bcb23..1fb7c39 100644 --- a/media/libstagefright/mpeg2ts/ESQueue.cpp +++ b/media/libstagefright/mpeg2ts/ESQueue.cpp @@ -49,6 +49,33 @@ void ElementaryStreamQueue::clear() { mFormat.clear(); } +static bool IsSeeminglyValidADTSHeader(const uint8_t *ptr, size_t size) { + if (size < 3) { + // Not enough data to verify header. + return false; + } + + if (ptr[0] != 0xff || (ptr[1] >> 4) != 0x0f) { + return false; + } + + unsigned layer = (ptr[1] >> 1) & 3; + + if (layer != 0) { + return false; + } + + unsigned ID = (ptr[1] >> 3) & 1; + unsigned profile_ObjectType = ptr[2] >> 6; + + if (ID == 1 && profile_ObjectType == 3) { + // MPEG-2 profile 3 is reserved. + return false; + } + + return true; +} + status_t ElementaryStreamQueue::appendData( const void *data, size_t size, int64_t timeUs) { if (mBuffer == NULL || mBuffer->size() == 0) { @@ -96,8 +123,8 @@ status_t ElementaryStreamQueue::appendData( } #else ssize_t startOffset = -1; - for (size_t i = 0; i + 1 < size; ++i) { - if (ptr[i] == 0xff && (ptr[i + 1] >> 4) == 0x0f) { + for (size_t i = 0; i < size; ++i) { + if (IsSeeminglyValidADTSHeader(&ptr[i], size - i)) { startOffset = i; break; } -- cgit v1.1