API Extension: Support for optionally specifying a map of extra request headers when specifying the uri of media data to be played.
related-to-bug: 2393577
Original change by Andrei Popescu <andreip@google.com>
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index 5b061b1..8e61011 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -254,12 +254,14 @@
return retriever;
}
-sp<IMediaPlayer> MediaPlayerService::create(pid_t pid, const sp<IMediaPlayerClient>& client, const char* url)
+sp<IMediaPlayer> MediaPlayerService::create(
+ pid_t pid, const sp<IMediaPlayerClient>& client, const char* url,
+ const KeyedVector<String8, String8> *headers)
{
int32_t connId = android_atomic_inc(&mNextConnId);
sp<Client> c = new Client(this, pid, connId, client);
LOGV("Create new client(%d) from pid %d, url=%s, connId=%d", connId, pid, url, connId);
- if (NO_ERROR != c->setDataSource(url))
+ if (NO_ERROR != c->setDataSource(url, headers))
{
c.clear();
return c;
@@ -803,7 +805,8 @@
return p;
}
-status_t MediaPlayerService::Client::setDataSource(const char *url)
+status_t MediaPlayerService::Client::setDataSource(
+ const char *url, const KeyedVector<String8, String8> *headers)
{
LOGV("setDataSource(%s)", url);
if (url == NULL)
@@ -838,7 +841,7 @@
// now set data source
LOGV(" setDataSource");
- mStatus = p->setDataSource(url);
+ mStatus = p->setDataSource(url, headers);
if (mStatus == NO_ERROR) {
mPlayer = p;
} else {
diff --git a/media/libmediaplayerservice/MediaPlayerService.h b/media/libmediaplayerservice/MediaPlayerService.h
index d243b96..ffe1ba0 100644
--- a/media/libmediaplayerservice/MediaPlayerService.h
+++ b/media/libmediaplayerservice/MediaPlayerService.h
@@ -23,6 +23,7 @@
#include <utils/List.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
+#include <utils/String8.h>
#include <utils/Vector.h>
#include <ui/SurfaceComposerClient.h>
@@ -181,7 +182,10 @@
virtual sp<IMediaMetadataRetriever> createMetadataRetriever(pid_t pid);
// House keeping for media player clients
- virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, const char* url);
+ virtual sp<IMediaPlayer> create(
+ pid_t pid, const sp<IMediaPlayerClient>& client, const char* url,
+ const KeyedVector<String8, String8> *headers);
+
virtual sp<IMediaPlayer> create(pid_t pid, const sp<IMediaPlayerClient>& client, int fd, int64_t offset, int64_t length);
virtual sp<IMemory> decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat);
virtual sp<IMemory> decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat);
@@ -219,7 +223,11 @@
Parcel *reply);
sp<MediaPlayerBase> createPlayer(player_type playerType);
- status_t setDataSource(const char *url);
+
+ status_t setDataSource(
+ const char *url,
+ const KeyedVector<String8, String8> *headers);
+
status_t setDataSource(int fd, int64_t offset, int64_t length);
static void notify(void* cookie, int msg, int ext1, int ext2);
diff --git a/media/libmediaplayerservice/MidiFile.cpp b/media/libmediaplayerservice/MidiFile.cpp
index e9cbb97..1b0b05f 100644
--- a/media/libmediaplayerservice/MidiFile.cpp
+++ b/media/libmediaplayerservice/MidiFile.cpp
@@ -115,8 +115,8 @@
release();
}
-status_t MidiFile::setDataSource(const char* path)
-{
+status_t MidiFile::setDataSource(
+ const char* path, const KeyedVector<String8, String8> *) {
LOGV("MidiFile::setDataSource url=%s", path);
Mutex::Autolock lock(mMutex);
diff --git a/media/libmediaplayerservice/MidiFile.h b/media/libmediaplayerservice/MidiFile.h
index 25d4a1b..4a60ece 100644
--- a/media/libmediaplayerservice/MidiFile.h
+++ b/media/libmediaplayerservice/MidiFile.h
@@ -30,7 +30,10 @@
~MidiFile();
virtual status_t initCheck();
- virtual status_t setDataSource(const char* path);
+
+ virtual status_t setDataSource(
+ const char* path, const KeyedVector<String8, String8> *headers);
+
virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
virtual status_t setVideoSurface(const sp<ISurface>& surface) { return UNKNOWN_ERROR; }
virtual status_t prepare();
diff --git a/media/libmediaplayerservice/MidiMetadataRetriever.cpp b/media/libmediaplayerservice/MidiMetadataRetriever.cpp
index 3795b7b..ad95fac 100644
--- a/media/libmediaplayerservice/MidiMetadataRetriever.cpp
+++ b/media/libmediaplayerservice/MidiMetadataRetriever.cpp
@@ -43,7 +43,8 @@
if (mMidiPlayer == 0) {
mMidiPlayer = new MidiFile();
}
- return mMidiPlayer->setDataSource(url);
+ // TODO: support headers in MetadataRetriever interface!
+ return mMidiPlayer->setDataSource(url, NULL /* headers */);
}
status_t MidiMetadataRetriever::setDataSource(int fd, int64_t offset, int64_t length)
diff --git a/media/libmediaplayerservice/StagefrightPlayer.cpp b/media/libmediaplayerservice/StagefrightPlayer.cpp
index 5915105..3135d0c 100644
--- a/media/libmediaplayerservice/StagefrightPlayer.cpp
+++ b/media/libmediaplayerservice/StagefrightPlayer.cpp
@@ -28,8 +28,9 @@
return OK;
}
-status_t StagefrightPlayer::setDataSource(const char *url) {
- LOGV("setDataSource('%s')", url);
+status_t StagefrightPlayer::setDataSource(
+ const char *url, const KeyedVector<String8, String8> *) {
+ LOGI("setDataSource('%s')", url);
return mPlayer->setDataSource(url);
}
diff --git a/media/libmediaplayerservice/StagefrightPlayer.h b/media/libmediaplayerservice/StagefrightPlayer.h
index 9d005cb..9e6674a 100644
--- a/media/libmediaplayerservice/StagefrightPlayer.h
+++ b/media/libmediaplayerservice/StagefrightPlayer.h
@@ -30,7 +30,10 @@
virtual ~StagefrightPlayer();
virtual status_t initCheck();
- virtual status_t setDataSource(const char *url);
+
+ virtual status_t setDataSource(
+ const char *url, const KeyedVector<String8, String8> *headers);
+
virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
virtual status_t setVideoSurface(const sp<ISurface> &surface);
virtual status_t prepare();
diff --git a/media/libmediaplayerservice/TestPlayerStub.cpp b/media/libmediaplayerservice/TestPlayerStub.cpp
index aa49429..169e49a 100644
--- a/media/libmediaplayerservice/TestPlayerStub.cpp
+++ b/media/libmediaplayerservice/TestPlayerStub.cpp
@@ -112,8 +112,8 @@
// Load the dynamic library.
// Create the test player.
// Call setDataSource on the test player with the url in param.
-status_t TestPlayerStub::setDataSource(const char *url)
-{
+status_t TestPlayerStub::setDataSource(
+ const char *url, const KeyedVector<String8, String8> *headers) {
if (!isTestUrl(url) || NULL != mHandle) {
return INVALID_OPERATION;
}
@@ -162,7 +162,7 @@
}
mPlayer = (*mNewPlayer)();
- return mPlayer->setDataSource(mContentUrl);
+ return mPlayer->setDataSource(mContentUrl, headers);
}
// Internal cleanup.
diff --git a/media/libmediaplayerservice/TestPlayerStub.h b/media/libmediaplayerservice/TestPlayerStub.h
index 80d53a8..6e6c3cd 100644
--- a/media/libmediaplayerservice/TestPlayerStub.h
+++ b/media/libmediaplayerservice/TestPlayerStub.h
@@ -65,7 +65,8 @@
virtual status_t initCheck();
// @param url Should be a test url. See class comment.
- virtual status_t setDataSource(const char* url);
+ virtual status_t setDataSource(
+ const char* url, const KeyedVector<String8, String8> *headers);
// Test player for a file descriptor source is not supported.
virtual status_t setDataSource(int, int64_t, int64_t) {
diff --git a/media/libmediaplayerservice/VorbisMetadataRetriever.cpp b/media/libmediaplayerservice/VorbisMetadataRetriever.cpp
index e981678..eac74fc 100644
--- a/media/libmediaplayerservice/VorbisMetadataRetriever.cpp
+++ b/media/libmediaplayerservice/VorbisMetadataRetriever.cpp
@@ -39,7 +39,8 @@
if (mVorbisPlayer == 0) {
mVorbisPlayer = new VorbisPlayer();
}
- return mVorbisPlayer->setDataSource(url);
+ // TODO: support headers in MetadataRetriever interface!
+ return mVorbisPlayer->setDataSource(url, NULL /* headers */);
}
status_t VorbisMetadataRetriever::setDataSource(int fd, int64_t offset, int64_t length)
diff --git a/media/libmediaplayerservice/VorbisPlayer.cpp b/media/libmediaplayerservice/VorbisPlayer.cpp
index 7f0ef21..8181999 100644
--- a/media/libmediaplayerservice/VorbisPlayer.cpp
+++ b/media/libmediaplayerservice/VorbisPlayer.cpp
@@ -86,9 +86,9 @@
release();
}
-status_t VorbisPlayer::setDataSource(const char* path)
-{
- return setdatasource(path, -1, 0, 0x7ffffffffffffffLL); // intentionally less than LONG_MAX
+status_t VorbisPlayer::setDataSource(
+ const char *uri, const KeyedVector<String8, String8> *headers) {
+ return setdatasource(uri, -1, 0, 0x7ffffffffffffffLL); // intentionally less than LONG_MAX
}
status_t VorbisPlayer::setDataSource(int fd, int64_t offset, int64_t length)
diff --git a/media/libmediaplayerservice/VorbisPlayer.h b/media/libmediaplayerservice/VorbisPlayer.h
index 4024654..4a50835 100644
--- a/media/libmediaplayerservice/VorbisPlayer.h
+++ b/media/libmediaplayerservice/VorbisPlayer.h
@@ -37,7 +37,10 @@
virtual void onFirstRef();
virtual status_t initCheck();
- virtual status_t setDataSource(const char* path);
+
+ virtual status_t setDataSource(
+ const char *uri, const KeyedVector<String8, String8> *headers);
+
virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
virtual status_t setVideoSurface(const sp<ISurface>& surface) { return UNKNOWN_ERROR; }
virtual status_t prepare();