summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2013-02-07 23:25:59 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-02-07 23:26:00 +0000
commit7e0b88bca060deb0cd499d528ff88ac9d4a7b954 (patch)
tree9d91ac59f85ff3db800abb9da5e9bda622d96661 /media
parent26b0a9d007e77e088af9ff3810734728f0558e85 (diff)
parenta2eb22c1de262aa3fa7c356537ac2fe165afdf3d (diff)
downloadframeworks_av-7e0b88bca060deb0cd499d528ff88ac9d4a7b954.zip
frameworks_av-7e0b88bca060deb0cd499d528ff88ac9d4a7b954.tar.gz
frameworks_av-7e0b88bca060deb0cd499d528ff88ac9d4a7b954.tar.bz2
Merge "Allow for dynamic reconfiguration of the video bitrate used"
Diffstat (limited to 'media')
-rw-r--r--media/libstagefright/ACodec.cpp48
-rw-r--r--media/libstagefright/MediaCodec.cpp31
-rw-r--r--media/libstagefright/wifi-display/source/Converter.cpp14
-rw-r--r--media/libstagefright/wifi-display/source/Converter.h2
4 files changed, 95 insertions, 0 deletions
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index 7b27843..a6cc4eb 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -374,6 +374,12 @@ void ACodec::initiateSetup(const sp<AMessage> &msg) {
msg->post();
}
+void ACodec::signalSetParameters(const sp<AMessage> &params) {
+ sp<AMessage> msg = new AMessage(kWhatSetParameters, id());
+ msg->setMessage("params", params);
+ msg->post();
+}
+
void ACodec::initiateAllocateComponent(const sp<AMessage> &msg) {
msg->setWhat(kWhatAllocateComponent);
msg->setTarget(id());
@@ -3550,6 +3556,23 @@ bool ACodec::ExecutingState::onMessageReceived(const sp<AMessage> &msg) {
break;
}
+ case kWhatSetParameters:
+ {
+ sp<AMessage> params;
+ CHECK(msg->findMessage("params", &params));
+
+ status_t err = mCodec->setParameters(params);
+
+ sp<AMessage> reply;
+ if (msg->findMessage("reply", &reply)) {
+ reply->setInt32("err", err);
+ reply->post();
+ }
+
+ handled = true;
+ break;
+ }
+
default:
handled = BaseState::onMessageReceived(msg);
break;
@@ -3558,6 +3581,31 @@ bool ACodec::ExecutingState::onMessageReceived(const sp<AMessage> &msg) {
return handled;
}
+status_t ACodec::setParameters(const sp<AMessage> &params) {
+ int32_t videoBitrate;
+ if (params->findInt32("videoBitrate", &videoBitrate)) {
+ OMX_VIDEO_CONFIG_BITRATETYPE configParams;
+ InitOMXParams(&configParams);
+ configParams.nPortIndex = kPortIndexOutput;
+ configParams.nEncodeBitrate = videoBitrate;
+
+ status_t err = mOMX->setConfig(
+ mNode,
+ OMX_IndexConfigVideoBitrate,
+ &configParams,
+ sizeof(configParams));
+
+ if (err != OK) {
+ ALOGE("setConfig(OMX_IndexConfigVideoBitrate, %d) failed w/ err %d",
+ videoBitrate, err);
+
+ return err;
+ }
+ }
+
+ return OK;
+}
+
bool ACodec::ExecutingState::onOMXEvent(
OMX_EVENTTYPE event, OMX_U32 data1, OMX_U32 data2) {
switch (event) {
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index cb8a651..77aceb7 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -1203,6 +1203,23 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
break;
}
+ case kWhatSetParameters:
+ {
+ uint32_t replyID;
+ CHECK(msg->senderAwaitsResponse(&replyID));
+
+ sp<AMessage> params;
+ CHECK(msg->findMessage("params", &params));
+
+ status_t err = onSetParameters(params);
+
+ sp<AMessage> response = new AMessage;
+ response->setInt32("err", err);
+
+ response->postReply(replyID);
+ break;
+ }
+
default:
TRESPASS();
}
@@ -1556,4 +1573,18 @@ void MediaCodec::postActivityNotificationIfPossible() {
}
}
+status_t MediaCodec::setParameters(const sp<AMessage> &params) {
+ sp<AMessage> msg = new AMessage(kWhatSetParameters, id());
+ msg->setMessage("params", params);
+
+ sp<AMessage> response;
+ return PostAndAwaitResponse(msg, &response);
+}
+
+status_t MediaCodec::onSetParameters(const sp<AMessage> &params) {
+ mCodec->signalSetParameters(params);
+
+ return OK;
+}
+
} // namespace android
diff --git a/media/libstagefright/wifi-display/source/Converter.cpp b/media/libstagefright/wifi-display/source/Converter.cpp
index 5628dec..376b0df 100644
--- a/media/libstagefright/wifi-display/source/Converter.cpp
+++ b/media/libstagefright/wifi-display/source/Converter.cpp
@@ -54,6 +54,7 @@ Converter::Converter(
,mFirstSilentFrameUs(-1ll)
,mInSilentMode(false)
#endif
+ ,mPrevVideoBitrate(-1)
{
AString mime;
CHECK(mInputFormat->findString("mime", &mime));
@@ -185,6 +186,7 @@ status_t Converter::initEncoder() {
int32_t audioBitrate = getBitrate("media.wfd.audio-bitrate", 128000);
int32_t videoBitrate = getBitrate("media.wfd.video-bitrate", 5000000);
+ mPrevVideoBitrate = videoBitrate;
ALOGI("using audio bitrate of %d bps, video bitrate of %d bps",
audioBitrate, videoBitrate);
@@ -606,6 +608,18 @@ status_t Converter::feedEncoderInputBuffers() {
}
status_t Converter::doMoreWork() {
+ if (mIsVideo) {
+ int32_t videoBitrate = getBitrate("media.wfd.video-bitrate", 5000000);
+ if (videoBitrate != mPrevVideoBitrate) {
+ sp<AMessage> params = new AMessage;
+
+ params->setInt32("videoBitrate", videoBitrate);
+ mEncoder->setParameters(params);
+
+ mPrevVideoBitrate = videoBitrate;
+ }
+ }
+
status_t err;
for (;;) {
diff --git a/media/libstagefright/wifi-display/source/Converter.h b/media/libstagefright/wifi-display/source/Converter.h
index 3357d61..57802bd 100644
--- a/media/libstagefright/wifi-display/source/Converter.h
+++ b/media/libstagefright/wifi-display/source/Converter.h
@@ -100,6 +100,8 @@ private:
sp<ABuffer> mPartialAudioAU;
+ int32_t mPrevVideoBitrate;
+
status_t initEncoder();
void releaseEncoder();