DRM framework support:
- add a sniffer for DRM files
- add DRMSource and DRMExtractor for es_based DRM
- add pread in FileSource.cpp for container_based DRM
- add native DRM framework API calls in the player for
  DRM audio/video playback

Change-Id: I4b9ef19165c9b4f44ff40eeededb9a665e78a90f
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 274dad9..7bbc9eb 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -187,7 +187,8 @@
       mExtractorFlags(0),
       mLastVideoBuffer(NULL),
       mVideoBuffer(NULL),
-      mSuspensionState(NULL) {
+      mSuspensionState(NULL),
+      mDecryptHandle(NULL) {
     CHECK_EQ(mClient.connect(), OK);
 
     DataSource::RegisterDefaultSniffers();
@@ -286,6 +287,17 @@
         return UNKNOWN_ERROR;
     }
 
+    dataSource->getDrmInfo(&mDecryptHandle, &mDrmManagerClient);
+    if (mDecryptHandle != NULL) {
+        if (RightsStatus::RIGHTS_VALID == mDecryptHandle->status) {
+            if (DecryptApiType::CONTAINER_BASED == mDecryptHandle->decryptApiType) {
+                mDrmManagerClient->consumeRights(mDecryptHandle, Action::PLAY, true);
+            }
+        } else {
+            notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_NO_LICENSE);
+        }
+    }
+
     return setDataSource_l(extractor);
 }
 
@@ -316,6 +328,11 @@
     }
 
     mExtractorFlags = extractor->flags();
+    if (mDecryptHandle != NULL) {
+        if (DecryptApiType::ELEMENTARY_STREAM_BASED == mDecryptHandle->decryptApiType) {
+            mDrmManagerClient->consumeRights(mDecryptHandle, Action::PLAY, true);
+        }
+    }
 
     return OK;
 }
@@ -326,6 +343,15 @@
 }
 
 void AwesomePlayer::reset_l() {
+    if (mDecryptHandle != NULL) {
+            mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
+                    Playback::STOP, 0);
+            mDrmManagerClient->consumeRights(mDecryptHandle,
+                    Action::PLAY, false);
+            mDecryptHandle = NULL;
+            mDrmManagerClient = NULL;
+    }
+
     if (mFlags & PREPARING) {
         mFlags |= PREPARE_CANCELLED;
         if (mConnectingDataSource != NULL) {
@@ -568,6 +594,13 @@
         seekTo_l(0);
     }
 
+    if (mDecryptHandle != NULL) {
+        int64_t position;
+        getPosition(&position);
+        mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
+                Playback::START, position / 1000);
+    }
+
     return OK;
 }
 
@@ -631,6 +664,11 @@
 
     mFlags &= ~PLAYING;
 
+    if (mDecryptHandle != NULL) {
+        mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
+                Playback::PAUSE, 0);
+    }
+
     return OK;
 }
 
@@ -727,6 +765,13 @@
         mWatchForAudioSeekComplete = true;
         mWatchForAudioEOS = true;
         mSeekNotificationSent = false;
+
+        if (mDecryptHandle != NULL) {
+            mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
+                    Playback::PAUSE, 0);
+            mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
+                    Playback::START, mSeekTimeUs / 1000);
+        }
     }
 }
 
@@ -919,6 +964,13 @@
         mFlags |= FIRST_FRAME;
         mSeeking = false;
         mSeekNotificationSent = false;
+
+        if (mDecryptHandle != NULL) {
+            mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
+                    Playback::PAUSE, 0);
+            mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
+                    Playback::START, timeUs / 1000);
+        }
     }
 
     if (mFlags & FIRST_FRAME) {
@@ -1137,6 +1189,17 @@
         return UNKNOWN_ERROR;
     }
 
+    dataSource->getDrmInfo(&mDecryptHandle, &mDrmManagerClient);
+    if (mDecryptHandle != NULL) {
+        if (RightsStatus::RIGHTS_VALID == mDecryptHandle->status) {
+            if (DecryptApiType::CONTAINER_BASED == mDecryptHandle->decryptApiType) {
+                mDrmManagerClient->consumeRights(mDecryptHandle, Action::PLAY, true);
+            }
+        } else {
+            notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_NO_LICENSE);
+        }
+    }
+
     if (dataSource->flags() & DataSource::kWantsPrefetching) {
         mPrefetcher = new Prefetcher;
     }