Skip to content

Commit 9084631

Browse files
Gloria WangAndroid Code Review
authored andcommitted
Merge "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"
2 parents c5371fa + d577091 commit 9084631

File tree

15 files changed

+826
-41
lines changed

15 files changed

+826
-41
lines changed

include/media/stagefright/DataSource.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <utils/List.h>
2626
#include <utils/RefBase.h>
2727
#include <utils/threads.h>
28+
#include <drm/DrmManagerClient.h>
2829

2930
namespace android {
3031

@@ -67,6 +68,13 @@ class DataSource : public RefBase {
6768
static void RegisterSniffer(SnifferFunc func);
6869
static void RegisterDefaultSniffers();
6970

71+
// for DRM
72+
virtual DecryptHandle* DrmInitialization(DrmManagerClient *client) {
73+
return NULL;
74+
}
75+
virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) {};
76+
77+
7078
protected:
7179
virtual ~DataSource() {}
7280

include/media/stagefright/FileSource.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <media/stagefright/DataSource.h>
2424
#include <media/stagefright/MediaErrors.h>
2525
#include <utils/threads.h>
26+
#include <drm/DrmManagerClient.h>
2627

2728
namespace android {
2829

@@ -37,15 +38,29 @@ class FileSource : public DataSource {
3738

3839
virtual status_t getSize(off_t *size);
3940

41+
virtual DecryptHandle* DrmInitialization(DrmManagerClient *client);
42+
43+
virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client);
44+
4045
protected:
4146
virtual ~FileSource();
4247

4348
private:
4449
FILE *mFile;
50+
int mFd;
4551
int64_t mOffset;
4652
int64_t mLength;
4753
Mutex mLock;
4854

55+
/*for DRM*/
56+
DecryptHandle *mDecryptHandle;
57+
DrmManagerClient *mDrmManagerClient;
58+
int64_t mDrmBufOffset;
59+
int64_t mDrmBufSize;
60+
unsigned char *mDrmBuf;
61+
62+
ssize_t readAtDRM(off_t offset, void *data, size_t size);
63+
4964
FileSource(const FileSource &);
5065
FileSource &operator=(const FileSource &);
5166
};

include/media/stagefright/MediaErrors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ enum {
3939

4040
// Not technically an error.
4141
INFO_FORMAT_CHANGED = MEDIA_ERROR_BASE - 12,
42+
43+
ERROR_NO_LICENSE = MEDIA_ERROR_BASE - 13,
4244
};
4345

4446
} // namespace android

include/media/stagefright/MediaExtractor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class MediaExtractor : public RefBase {
5454
// CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_PAUSE
5555
virtual uint32_t flags() const;
5656

57+
// for DRM
58+
virtual void setDrmFlag(bool flag) {};
59+
virtual char* getDrmTrackInfo(size_t trackID, int *len) {
60+
return NULL;
61+
}
62+
5763
protected:
5864
MediaExtractor() {}
5965
virtual ~MediaExtractor() {}

include/media/stagefright/MetaData.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ enum {
5050
kKeyBufferID = 'bfID',
5151
kKeyMaxInputSize = 'inpS',
5252
kKeyThumbnailTime = 'thbT', // int64_t (usecs)
53+
kKeyTrackID = 'trID',
54+
kKeyIsDRM = 'idrm', // int32_t (bool)
5355

5456
kKeyAlbum = 'albu', // cstring
5557
kKeyArtist = 'arti', // cstring

media/libstagefright/Android.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ LOCAL_SRC_FILES += \
2323
CachingDataSource.cpp \
2424
CameraSource.cpp \
2525
DataSource.cpp \
26+
DRMExtractor.cpp \
2627
FileSource.cpp \
2728
HTTPDataSource.cpp \
2829
HTTPStream.cpp \
@@ -61,7 +62,8 @@ LOCAL_SHARED_LIBRARIES := \
6162
libsonivox \
6263
libvorbisidec \
6364
libsurfaceflinger_client \
64-
libcamera_client
65+
libcamera_client \
66+
libdrmframework
6567

6668
LOCAL_STATIC_LIBRARIES := \
6769
libstagefright_aacdec \

media/libstagefright/AwesomePlayer.cpp

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ AwesomePlayer::AwesomePlayer()
187187
mExtractorFlags(0),
188188
mLastVideoBuffer(NULL),
189189
mVideoBuffer(NULL),
190-
mSuspensionState(NULL) {
190+
mSuspensionState(NULL),
191+
mDecryptHandle(NULL) {
191192
CHECK_EQ(mClient.connect(), OK);
192193

193194
DataSource::RegisterDefaultSniffers();
@@ -286,6 +287,17 @@ status_t AwesomePlayer::setDataSource_l(
286287
return UNKNOWN_ERROR;
287288
}
288289

290+
dataSource->getDrmInfo(&mDecryptHandle, &mDrmManagerClient);
291+
if (mDecryptHandle != NULL) {
292+
if (RightsStatus::RIGHTS_VALID == mDecryptHandle->status) {
293+
if (DecryptApiType::CONTAINER_BASED == mDecryptHandle->decryptApiType) {
294+
mDrmManagerClient->consumeRights(mDecryptHandle, Action::PLAY, true);
295+
}
296+
} else {
297+
notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_NO_LICENSE);
298+
}
299+
}
300+
289301
return setDataSource_l(extractor);
290302
}
291303

@@ -316,6 +328,11 @@ status_t AwesomePlayer::setDataSource_l(const sp<MediaExtractor> &extractor) {
316328
}
317329

318330
mExtractorFlags = extractor->flags();
331+
if (mDecryptHandle != NULL) {
332+
if (DecryptApiType::ELEMENTARY_STREAM_BASED == mDecryptHandle->decryptApiType) {
333+
mDrmManagerClient->consumeRights(mDecryptHandle, Action::PLAY, true);
334+
}
335+
}
319336

320337
return OK;
321338
}
@@ -326,6 +343,15 @@ void AwesomePlayer::reset() {
326343
}
327344

328345
void AwesomePlayer::reset_l() {
346+
if (mDecryptHandle != NULL) {
347+
mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
348+
Playback::STOP, 0);
349+
mDrmManagerClient->consumeRights(mDecryptHandle,
350+
Action::PLAY, false);
351+
mDecryptHandle = NULL;
352+
mDrmManagerClient = NULL;
353+
}
354+
329355
if (mFlags & PREPARING) {
330356
mFlags |= PREPARE_CANCELLED;
331357
if (mConnectingDataSource != NULL) {
@@ -568,6 +594,13 @@ status_t AwesomePlayer::play_l() {
568594
seekTo_l(0);
569595
}
570596

597+
if (mDecryptHandle != NULL) {
598+
int64_t position;
599+
getPosition(&position);
600+
mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
601+
Playback::START, position / 1000);
602+
}
603+
571604
return OK;
572605
}
573606

@@ -631,6 +664,11 @@ status_t AwesomePlayer::pause_l() {
631664

632665
mFlags &= ~PLAYING;
633666

667+
if (mDecryptHandle != NULL) {
668+
mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
669+
Playback::PAUSE, 0);
670+
}
671+
634672
return OK;
635673
}
636674

@@ -727,6 +765,13 @@ void AwesomePlayer::seekAudioIfNecessary_l() {
727765
mWatchForAudioSeekComplete = true;
728766
mWatchForAudioEOS = true;
729767
mSeekNotificationSent = false;
768+
769+
if (mDecryptHandle != NULL) {
770+
mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
771+
Playback::PAUSE, 0);
772+
mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
773+
Playback::START, mSeekTimeUs / 1000);
774+
}
730775
}
731776
}
732777

@@ -919,6 +964,13 @@ void AwesomePlayer::onVideoEvent() {
919964
mFlags |= FIRST_FRAME;
920965
mSeeking = false;
921966
mSeekNotificationSent = false;
967+
968+
if (mDecryptHandle != NULL) {
969+
mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
970+
Playback::PAUSE, 0);
971+
mDrmManagerClient->setPlaybackStatus(mDecryptHandle,
972+
Playback::START, timeUs / 1000);
973+
}
922974
}
923975

924976
if (mFlags & FIRST_FRAME) {
@@ -1137,6 +1189,17 @@ status_t AwesomePlayer::finishSetDataSource_l() {
11371189
return UNKNOWN_ERROR;
11381190
}
11391191

1192+
dataSource->getDrmInfo(&mDecryptHandle, &mDrmManagerClient);
1193+
if (mDecryptHandle != NULL) {
1194+
if (RightsStatus::RIGHTS_VALID == mDecryptHandle->status) {
1195+
if (DecryptApiType::CONTAINER_BASED == mDecryptHandle->decryptApiType) {
1196+
mDrmManagerClient->consumeRights(mDecryptHandle, Action::PLAY, true);
1197+
}
1198+
} else {
1199+
notifyListener_l(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, ERROR_NO_LICENSE);
1200+
}
1201+
}
1202+
11401203
if (dataSource->flags() & DataSource::kWantsPrefetching) {
11411204
mPrefetcher = new Prefetcher;
11421205
}

0 commit comments

Comments
 (0)