media: miscellaneous fixes to VT contribution

- fix MediaSource.h path
- fix setDataSource binder code
- use MediaCodecConstants instead of OMX/ACodec constants
- fix spacing
- fix typos
- remove unused code
- commented some tricky code segments
- AAVC/HEVCAssembler: re-read next buffer if buffer was deleted
- RTPSource: pull out constants kMinVideoBitrate and kBufferingPollIntervalUs
- RTPSource: check state early in prepareAsync
- RTPSource: fix potential null dereference in setSource
- ARTPAssembler: make showing queue runtime configurable via debug.stagefright.rtp bool property
- ARTPWriter: fix security issues: protect against reading OOB in
  sendSPSPPSIfIFrame and StripStartcode
- ARTPWriter: free buffers early in destructor
- ARTPWriter: create PPS buffer only if there is PPS
- ARTPConnection: fix security issues: protect against reading OOB in
  parseRTPExt, parseTSFB, and parsePSFB. Also remove remote null-dereference.
- AHEVCAssembler: fix security issues: protect against reading OOB in
  addFragmentedNALUnit

Bug: 121230209
Test: build
Merged-in: Iada8b878e396452c1d281c60f3754e13e34bcddb
Change-Id: Iada8b878e396452c1d281c60f3754e13e34bcddb
diff --git a/media/libmediaplayerservice/nuplayer/RTPSource.cpp b/media/libmediaplayerservice/nuplayer/RTPSource.cpp
index 7e77456..a6601cd 100644
--- a/media/libmediaplayerservice/nuplayer/RTPSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/RTPSource.cpp
@@ -80,6 +80,9 @@
         mLooper->registerHandler(mRTPConn);
     }
 
+    CHECK_EQ(mState, (int)DISCONNECTED);
+    mState = CONNECTING;
+
     setParameters(mRTPParams);
 
     TrackInfo *info = NULL;
@@ -111,7 +114,7 @@
         // index(i) should be started from 1. 0 is reserved for [root]
         mRTPConn->addStream(sockRtp, sockRtcp, desc, i + 1, notify, false);
         mRTPConn->setSelfID(info->mSelfID);
-        mRTPConn->setMinMaxBitrate(videoMinBitrate, info->mAS * 1000);
+        mRTPConn->setMinMaxBitrate(kMinVideoBitrate, info->mAS * 1000 /* kbps */);
 
         info->mRTPSocket = sockRtp;
         info->mRTCPSocket = sockRtcp;
@@ -139,9 +142,6 @@
         info->mSource = source;
     }
 
-    CHECK_EQ(mState, (int)DISCONNECTED);
-    mState = CONNECTING;
-
     if (mInPreparationPhase) {
         mInPreparationPhase = false;
         notifyPrepared();
@@ -340,7 +340,7 @@
 
 void NuPlayer::RTPSource::schedulePollBuffering() {
     sp<AMessage> msg = new AMessage(kWhatPollBuffering, this);
-    msg->post(1000000ll); // 1 second intervals
+    msg->post(kBufferingPollIntervalUs); // 1 second intervals
 }
 
 void NuPlayer::RTPSource::onPollBuffering() {
@@ -412,6 +412,8 @@
                 break;
             }
 
+            // Implicitly assert on valid trackIndex here, which we ensure by
+            // never removing tracks.
             TrackInfo *info = &mTracks.editItemAt(trackIndex);
 
             sp<AnotherPacketSource> source = info->mSource;
@@ -492,6 +494,8 @@
     ALOGV("onTimeUpdate track %d, rtpTime = 0x%08x, ntpTime = %#016llx",
          trackIndex, rtpTime, (long long)ntpTime);
 
+    // convert ntpTime in Q32 seconds to microseconds. Note: this will not lose precision
+    // because ntpTimeUs is at most 52 bits (double holds 53 bits)
     int64_t ntpTimeUs = (int64_t)(ntpTime * 1E6 / (1ll << 32));
 
     TrackInfo *track = &mTracks.editItemAt(trackIndex);
@@ -659,10 +663,10 @@
 
         const char *mime = value.string();
         const char *delimiter = strchr(mime, '/');
-        info->mCodecName = (delimiter + 1);
+        info->mCodecName = delimiter ? (delimiter + 1) : "<none>";
 
         ALOGV("rtp-param-mime-type: mMimeType (%s) => mCodecName (%s)",
-            info->mMimeType.string(), info->mCodecName.string());
+                info->mMimeType.string(), info->mCodecName.string());
     } else if (key == "video-param-decoder-profile") {
         info->mCodecProfile = atoi(value);
     } else if (key == "video-param-decoder-level") {