summaryrefslogtreecommitdiffstats
path: root/media/libmedia/mediaplayer.cpp
diff options
context:
space:
mode:
authorJohn Grossman <johngro@google.com>2012-02-22 15:38:35 -0800
committerJohn Grossman <johngro@google.com>2012-03-01 14:41:35 -0800
commitc795b64060c3af9d7961fc1371e4ccfa8ee3e450 (patch)
treeaafa8ecde306b5420e96b7a6e0965d1f1f4c4fa6 /media/libmedia/mediaplayer.cpp
parent4b77dc28097288cb062fce6bf5de0fb3394877a9 (diff)
downloadframeworks_av-c795b64060c3af9d7961fc1371e4ccfa8ee3e450.zip
frameworks_av-c795b64060c3af9d7961fc1371e4ccfa8ee3e450.tar.gz
frameworks_av-c795b64060c3af9d7961fc1371e4ccfa8ee3e450.tar.bz2
Switch the way we configure for MediaPlayer retransmission.
This is a cherry-pick of I6ab07d89b2eeb0650e634b8c3b7a0b36aba4e7dd with merge conflicts addressed by hand and additional changes made in response to code review feedback. Move in the direction of a more publishable API for configuring a media player for retransmission. It used to be that we used a custom invoke and a modified URL (prefixed with aahTX://). There are many issues with this technique and it was never meant to stand the test of time. This CL gets rid of all that. A new (but currently hidden) method was introduced to the java level MediaPlayer API, called setRetransmitTarget(InetSocketAddress), which allows an app writer to set the retransmit target. For now, this method needs to be called before a call to setDataSource (which is pretty unusual for the MediaPlayer API) because this mid level code uses this as a cue to instantiate an aahTX player instead of relying on the data source to select a player. When retranmit functionality becomes part of the existing android player implemenation, this set-retrans-before-set-data-source behavior can go away, along with the aahTX player itself. Change-Id: I3b46c5227bbf69acb2f3cc4f93cfccad9777be98 Signed-off-by: John Grossman <johngro@google.com>
Diffstat (limited to 'media/libmedia/mediaplayer.cpp')
-rw-r--r--media/libmedia/mediaplayer.cpp53
1 files changed, 50 insertions, 3 deletions
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
index 9d45907..4ff1862 100644
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -61,6 +61,7 @@ MediaPlayer::MediaPlayer()
mAudioSessionId = AudioSystem::newAudioSessionId();
AudioSystem::acquireAudioSessionId(mAudioSessionId);
mSendLevel = 0;
+ mRetransmitEndpointValid = false;
}
MediaPlayer::~MediaPlayer()
@@ -93,6 +94,7 @@ void MediaPlayer::clear_l()
mCurrentPosition = -1;
mSeekPosition = -1;
mVideoWidth = mVideoHeight = 0;
+ mRetransmitEndpointValid = false;
}
status_t MediaPlayer::setListener(const sp<MediaPlayerListener>& listener)
@@ -144,7 +146,8 @@ status_t MediaPlayer::setDataSource(
const sp<IMediaPlayerService>& service(getMediaPlayerService());
if (service != 0) {
sp<IMediaPlayer> player(service->create(getpid(), this, mAudioSessionId));
- if (NO_ERROR != player->setDataSource(url, headers)) {
+ if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
+ (NO_ERROR != player->setDataSource(url, headers))) {
player.clear();
}
err = attachNewPlayer(player);
@@ -160,7 +163,8 @@ status_t MediaPlayer::setDataSource(int fd, int64_t offset, int64_t length)
const sp<IMediaPlayerService>& service(getMediaPlayerService());
if (service != 0) {
sp<IMediaPlayer> player(service->create(getpid(), this, mAudioSessionId));
- if (NO_ERROR != player->setDataSource(fd, offset, length)) {
+ if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
+ (NO_ERROR != player->setDataSource(fd, offset, length))) {
player.clear();
}
err = attachNewPlayer(player);
@@ -175,7 +179,8 @@ status_t MediaPlayer::setDataSource(const sp<IStreamSource> &source)
const sp<IMediaPlayerService>& service(getMediaPlayerService());
if (service != 0) {
sp<IMediaPlayer> player(service->create(getpid(), this, mAudioSessionId));
- if (NO_ERROR != player->setDataSource(source)) {
+ if ((NO_ERROR != doSetRetransmitEndpoint(player)) ||
+ (NO_ERROR != player->setDataSource(source))) {
player.clear();
}
err = attachNewPlayer(player);
@@ -469,6 +474,20 @@ status_t MediaPlayer::reset_l()
return NO_ERROR;
}
+status_t MediaPlayer::doSetRetransmitEndpoint(const sp<IMediaPlayer>& player) {
+ Mutex::Autolock _l(mLock);
+
+ if (player == NULL) {
+ return UNKNOWN_ERROR;
+ }
+
+ if (mRetransmitEndpointValid) {
+ return player->setRetransmitEndpoint(&mRetransmitEndpoint);
+ }
+
+ return OK;
+}
+
status_t MediaPlayer::reset()
{
ALOGV("reset");
@@ -597,6 +616,34 @@ status_t MediaPlayer::getParameter(int key, Parcel *reply)
return INVALID_OPERATION;
}
+status_t MediaPlayer::setRetransmitEndpoint(const char* addrString,
+ uint16_t port) {
+ ALOGV("MediaPlayer::setRetransmitEndpoint(%s:%hu)",
+ addrString ? addrString : "(null)", port);
+
+ Mutex::Autolock _l(mLock);
+ if ((mPlayer != NULL) || (mCurrentState != MEDIA_PLAYER_IDLE))
+ return INVALID_OPERATION;
+
+ if (NULL == addrString) {
+ mRetransmitEndpointValid = false;
+ return OK;
+ }
+
+ struct in_addr saddr;
+ if(!inet_aton(addrString, &saddr)) {
+ return BAD_VALUE;
+ }
+
+ memset(&mRetransmitEndpoint, 0, sizeof(&mRetransmitEndpoint));
+ mRetransmitEndpoint.sin_family = AF_INET;
+ mRetransmitEndpoint.sin_addr = saddr;
+ mRetransmitEndpoint.sin_port = htons(port);
+ mRetransmitEndpointValid = true;
+
+ return OK;
+}
+
void MediaPlayer::notify(int msg, int ext1, int ext2, const Parcel *obj)
{
ALOGV("message received msg=%d, ext1=%d, ext2=%d", msg, ext1, ext2);