author | shipeng.sun <shipeng.sun@amlogic.com> | 2019-03-22 04:14:26 (GMT) |
---|---|---|
committer | Zhi Zhou <zhi.zhou@amlogic.com> | 2019-04-17 02:51:13 (GMT) |
commit | 76b305c524cd2d1541a321578aca9334692e9f4d (patch) | |
tree | 59ae8796f65cbc15ce38268cabd8069a55855835 | |
parent | dccae9cb791f6bdbdeb55ad8faa4f5c50ecd3cc7 (diff) | |
download | av-76b305c524cd2d1541a321578aca9334692e9f4d.zip av-76b305c524cd2d1541a321578aca9334692e9f4d.tar.gz av-76b305c524cd2d1541a321578aca9334692e9f4d.tar.bz2 |
libstagefright: Optinize libstagefirght code [1/7]
PD#SWPL-6136
Problem:
1. Optimize libstagefirght code for send M16 Message
2. Optimize code for rtp package sequence calc
Solution:
1. Add kWhatStop event make sure miracast stop exit sync
2. Add some trace information for Response M16 Request
3. Modify code get surface handle from apk
4. Commit some code to avoid cal rtp packet sequence wrong
5. setsockopt add netwrok receive and send buffer size
Verify:
Verify on darwin
Change-Id: I9e38bdc091aff4c124c41ba2e493340577f14bbe
Signed-off-by: shipeng.sun <shipeng.sun@amlogic.com>
-rw-r--r-- | libstagefright/wifi-display/sink/AmANetworkSession.cpp | 27 | ||||
-rw-r--r-- | libstagefright/wifi-display/sink/RTPSink.cpp | 5 | ||||
-rw-r--r-- | libstagefright/wifi-display/sink/TunnelRenderer.cpp | 111 | ||||
-rw-r--r-- | libstagefright/wifi-display/sink/TunnelRenderer.h | 2 | ||||
-rw-r--r-- | libstagefright/wifi-display/sink/WifiDisplaySink.cpp | 47 | ||||
-rw-r--r-- | libstagefright/wifi-display/sink/WifiDisplaySink.h | 1 |
6 files changed, 97 insertions, 96 deletions
diff --git a/libstagefright/wifi-display/sink/AmANetworkSession.cpp b/libstagefright/wifi-display/sink/AmANetworkSession.cpp index f8aae89..5f48210 100644 --- a/libstagefright/wifi-display/sink/AmANetworkSession.cpp +++ b/libstagefright/wifi-display/sink/AmANetworkSession.cpp @@ -1009,7 +1009,11 @@ status_t AmANetworkSession::createClientOrServer( } if (mode == kModeCreateUDPSession) { - int size = 256 * 1024; + int size = 2048 * 1024; + int sendbuff; + socklen_t optlen = sizeof(sendbuff); + res = getsockopt(s, SOL_SOCKET, SO_SNDBUF, &sendbuff, (socklen_t*)&optlen); + ALOGI("original socket buffer size: %d", sendbuff); res = setsockopt(s, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)); @@ -1024,6 +1028,27 @@ status_t AmANetworkSession::createClientOrServer( err = -errno; goto bail2; } + res = getsockopt(s, SOL_SOCKET, SO_SNDBUF, &sendbuff, (socklen_t*)&optlen); + ALOGI("after socket buffer size: %d", sendbuff); + + //Configure QoS priority for UDP/RTP packets + int opt; + int priority; + priority = 5; /* 5: VI 7: VO */ + opt = priority << 5; + + res = setsockopt(s, SOL_IP, IP_TOS, &opt, sizeof(opt)); + if (res < 0) { + err = -errno; + ALOGD("Socket IP_TOS option:%d", err); + } + + opt = priority; + res = setsockopt(s, SOL_SOCKET, SO_PRIORITY, &opt, sizeof(opt)); + if (res < 0) { + err = -errno; + ALOGD("Socket SO_PRIORITY option:%d", err); + } } else if (mode == kModeCreateTCPDatagramSessionActive) { int flag = 1; res = setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)); diff --git a/libstagefright/wifi-display/sink/RTPSink.cpp b/libstagefright/wifi-display/sink/RTPSink.cpp index 0fd0878..652a23a 100644 --- a/libstagefright/wifi-display/sink/RTPSink.cpp +++ b/libstagefright/wifi-display/sink/RTPSink.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_NDEBUG 0 +//#define LOG_NDEBUG 0 #define LOG_TAG "RTPSink" #include <utils/Log.h> @@ -159,6 +159,7 @@ namespace android mMaxSeq = seq; } +#if 0 else if (udelta <= kRTPSeqMod - kMaxMisorder) { // The sequence number made a very large jump @@ -182,7 +183,7 @@ namespace android { // Duplicate or reordered packet. } - +#endif ++mReceived; buffer->setInt32Data(mCycles | seq); diff --git a/libstagefright/wifi-display/sink/TunnelRenderer.cpp b/libstagefright/wifi-display/sink/TunnelRenderer.cpp index eec7b7c..15948f2 100644 --- a/libstagefright/wifi-display/sink/TunnelRenderer.cpp +++ b/libstagefright/wifi-display/sink/TunnelRenderer.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_NDEBUG 0 +//#define LOG_NDEBUG 0 #define LOG_TAG "TunnelRenderer" #include <utils/Log.h> @@ -238,10 +238,12 @@ namespace android if (mDebugEnable) ALOGE("Miracast debug info enabled\n"); setProperty("sys.pkginfo", "suc:0,fail:0,req:0,total:0, max:0,min:0,retry:0,band:0"); + mIsDestoryState = false; } TunnelRenderer::~TunnelRenderer() { + mIsDestoryState = true; destroyPlayer(); } @@ -292,10 +294,12 @@ namespace android sp<ABuffer> TunnelRenderer::dequeueBuffer() { + if (mIsDestoryState) + return NULL; Mutex::Autolock autoLock(mLock); sp<ABuffer> buffer; - int32_t extSeqNo; + uint32_t extSeqNo; char pkg_info[128]; int64_t curUs; @@ -330,8 +334,8 @@ namespace android else { float noPacketTime = (ALooper::GetNowUs() - mFirstFailedAttemptUs) / 1E6; - ALOGV("no packets available for %.2f secs",noPacketTime); - if (noPacketTime>12.0) //beyond 12S + ALOGE("no packets available for %.2f secs",noPacketTime); + if (noPacketTime > 12.0) //beyond 12S { #if 1 @@ -362,8 +366,7 @@ namespace android { if (mRequestedRetransmission) { - ALOGI("Recovered after requesting retransmission of %d", - extSeqNo); + ALOGE("Recovered after requesting retransmission of %d", extSeqNo); } if (!mRequestedRetry) @@ -402,73 +405,37 @@ namespace android mMinBytesQueued = mMinBytesQueued < mTotalBytesQueued ? mMinBytesQueued : mTotalBytesQueued; return buffer; } - - if (mFirstFailedAttemptUs < 0ll) - { + if (mFirstFailedAttemptUs < 0ll) { mFirstFailedAttemptUs = ALooper::GetNowUs(); ALOGI("failed to get the correct packet the first time."); return NULL; } - - if (mFirstFailedAttemptUs + 10000ll > ALooper::GetNowUs()) - { - // We're willing to wait a little while to get the right packet. - - if (!mRequestedRetransmission) - { - ALOGI("requesting retransmission of seqNo %d", - (mLastDequeuedExtSeqNo + 1) & 0xffff); - - sp<AMessage> notify = mNotifyLost->dup(); - notify->setInt32("seqNo", (mLastDequeuedExtSeqNo + 1) & 0xffff); - notify->post(); - //For miracast, we shuold send request IDR to request a I Frame asap - sp<AMessage> msgNotify = mMsgNotify->dup(); - msgNotify->setInt32("msg", kWahtLostPacketMsg); - msgNotify->post(); - mRequestedRetry = true; - mRequestedRetransmission = true; - mRetryTimes++; - } - else - { - ALOGI("still waiting for the correct packet to arrive."); - } - + if (!mRequestedRetransmission) { + ALOGE("requesting retransmission of seqNo %d", (mLastDequeuedExtSeqNo + 1) & 0xffff); + sp<AMessage> notify = mNotifyLost->dup(); + notify->setInt32("seqNo", (mLastDequeuedExtSeqNo + 1) & 0xffff); + notify->post(); + //For miracast, we shuold send request IDR to request a I Frame asap + sp<AMessage> msgNotify = mMsgNotify->dup(); + msgNotify->setInt32("msg", kWahtLostPacketMsg); + msgNotify->post(); + mRequestedRetry = true; + mRequestedRetransmission = true; + mRetryTimes++; + } + if (mFirstFailedAttemptUs + 10000ll > ALooper::GetNowUs()) { return NULL; } - - ALOGI("dropping packet. extSeqNo %d didn't arrive in time", - mLastDequeuedExtSeqNo + 1); + ALOGI("dropping packet. extSeqNo %d didn't arrive in time", mLastDequeuedExtSeqNo + 1); // Permanent failure, we never received the packet. mPackageFailed++; - - if (mDebugEnable) - { - /*calculate bandwidth every 2s once*/ - curUs = ALooper::GetNowUs(); - if (curUs - mCurTime >= 1000000ll) - { - mBandwidth = mBytesQueued * ((float)1000000ll / (curUs - mCurTime)); - //ALOGI("367 curUs - mCurTime =%lld, bytes=%ld", curUs-mCurTime, mBytesQueued); - mBytesQueued = 0; - mCurTime = ALooper::GetNowUs(); - sprintf(pkg_info, "suc:%d,fail:%d,req:%d, total:%lld, max:%lld,min:%lld,retry:%lld, band:%lld", - mPackageSuccess, mPackageFailed, mPackageRequest, - mTotalBytesQueued, mMaxBytesQueued, mMinBytesQueued, - mRetryTimes, mBandwidth); - setProperty("sys.pkginfo", pkg_info); - } - } mLastDequeuedExtSeqNo = extSeqNo; mFirstFailedAttemptUs = -1ll; mRequestedRetransmission = false; mRequestedRetry = false; - mTotalBytesQueued -= buffer->size(); mMinBytesQueued = mMinBytesQueued < mTotalBytesQueued ? mMinBytesQueued : mTotalBytesQueued; mPackets.erase(mPackets.begin()); - return buffer; } @@ -525,20 +492,19 @@ namespace android displayHeight, PIXEL_FORMAT_RGB_565, 0); - CHECK(mSurfaceControl != NULL); CHECK(mSurfaceControl->isValid()); - - //SurfaceComposerClient::openGlobalTransaction(); - //CHECK_EQ(mSurfaceControl->setLayer(INT_MAX), (status_t)OK); - //CHECK_EQ(mSurfaceControl->show(), (status_t)OK); - //SurfaceComposerClient::closeGlobalTransaction(); - //SurfaceComposerClient::Transaction t; - //t.setLayer(mSurfaceControl, INT_MAX).apply(); - //CHECK_EQ(mSurfaceControl->setLayer(INT_MAX), (status_t)OK); - //CHECK_EQ(mSurfaceControl->show(), (status_t)OK); - //SurfaceControl::closeTransaction(); - +#if ANDROID_PLATFORM_SDK_VERSION <= 27 + SurfaceComposerClient::openGlobalTransaction(); + CHECK_EQ(mSurfaceControl->setLayer(INT_MAX), (status_t)OK); + CHECK_EQ(mSurfaceControl->show(), (status_t)OK); + SurfaceComposerClient::closeGlobalTransaction(); +#else + SurfaceComposerClient::Transaction t; + t.setLayer(mSurfaceControl, INT_MAX); + t.show(mSurfaceControl); + t.apply(); +#endif mSurface = mSurfaceControl->getSurface(); CHECK(mSurface != NULL); } @@ -570,9 +536,8 @@ namespace android data.writeInt32(0); mPlayer->setParameter(KEY_PARAMETER_AML_PLAYER_HDCP_CUSTOM_DATA, data); } -// mPlayer->setVideoSurfaceTexture( - // mBufferProducer != NULL ? mBufferProducer : mSurface->getSurfaceTexture()); - mPlayer->setVideoSurfaceTexture(mSurface->getIGraphicBufferProducer()); + mPlayer->setVideoSurfaceTexture( + mBufferProducer != NULL ? mBufferProducer : mSurface->getIGraphicBufferProducer()); Parcel request; //mPlayer->setParameter(KEY_PARAMETER_AML_PLAYER_DIS_AUTO_BUFFER, request); mPlayer->prepareAsync(); diff --git a/libstagefright/wifi-display/sink/TunnelRenderer.h b/libstagefright/wifi-display/sink/TunnelRenderer.h index 2f3089d..14be8ce 100644 --- a/libstagefright/wifi-display/sink/TunnelRenderer.h +++ b/libstagefright/wifi-display/sink/TunnelRenderer.h @@ -106,7 +106,7 @@ namespace android void destroyPlayer(); void queueBuffer(const sp<ABuffer> &buffer); - + bool mIsDestoryState; DISALLOW_EVIL_CONSTRUCTORS(TunnelRenderer); }; diff --git a/libstagefright/wifi-display/sink/WifiDisplaySink.cpp b/libstagefright/wifi-display/sink/WifiDisplaySink.cpp index 31e7a53..c58cf6e 100644 --- a/libstagefright/wifi-display/sink/WifiDisplaySink.cpp +++ b/libstagefright/wifi-display/sink/WifiDisplaySink.cpp @@ -343,8 +343,7 @@ namespace android msg->post(); } } - else if(err == -104) //connection reset by peer - { + else { sp<AMessage> msg = new AMessage(kWhatSinkNotify, mSinkHandler); ALOGI("post msg kWhatSinkNotify - connection reset by peer"); msg->setString("reason", "RTSP_RESET"); @@ -415,32 +414,27 @@ namespace android switch (msgCode) { -#if 1 case HDCPModule::HDCP_INITIALIZATION_COMPLETE: + { mHDCPRunning = true; mRTPSink->setIsHDCP(true); break; + } case HDCPModule::HDCP_SHUTDOWN_COMPLETE: case HDCPModule::HDCP_SHUTDOWN_FAILED: + { mHDCP->setObserver(NULL); mHDCPObserver.clear(); mHDCP.clear(); mHDCPRunning = false; mHDCPLock.unlock(); + sp<AMessage> sinkMsg = new AMessage(kWhatStopCompleted, mSinkHandler); + ALOGI("post msg kWhatStopCompleted for hdcp mode"); + sinkMsg->post(); break; + } case HDCPModule::HDCP_SESSION_ESTABLISHED: break; -#endif -#if 0 - { - // Ugly hack to make sure that the call to - // HDCPObserver::notify is completely handled before - // we clear the HDCP instance and unload the shared - // library :( - (new AMessage(kWhatFinishStop2, this))->post(300000ll); - break; - } -#endif default: { ALOGE("HDCP failure, shutting down."); @@ -467,16 +461,17 @@ namespace android looper()->unregisterHandler(mRTPSink->id()); mRTPSink.clear(); } -#if 1 if (mHDCP != NULL /*&& mHDCPRunning == true*/) { mHDCPLock.lock(); mHDCPRunning = true; ALOGI("kWhatStop: Initiating HDCP shutdown."); mHDCP->shutdownAsync(); + } else { + sp<AMessage> sinkMsg = new AMessage(kWhatStopCompleted, mSinkHandler); + ALOGI("post msg kWhatStopCompleted"); + sinkMsg->post(); } -#endif //looper()->stop(); - break; } case kWhatNoPacket: @@ -497,6 +492,9 @@ namespace android ALOGI("requesting IDR frame"); sendIDRFrameRequest(mSessionID); } + sp<AMessage> msg = new AMessage(kWhatNoPacket, this); + msg->setInt32("msg", kWahtLostPacketMsg); + msg->post(5000000); break; } default: @@ -750,7 +748,9 @@ namespace android property_set("sys.wfd.state","0"); mState = PLAYING; - + sp<AMessage> requestIdrMsg = new AMessage(kWhatNoPacket, this); + requestIdrMsg->setInt32("msg", kWahtLostPacketMsg); + requestIdrMsg->post(); return OK; } @@ -1047,7 +1047,16 @@ namespace android return; } } - + const char *content = data->getContent(); + if (strstr(content,"wfd_") == NULL) { + AString responseAlive = "RTSP/1.0 200 OK\r\n"; + AppendCommonResponse(&responseAlive, cseq); + responseAlive.append("\r\n"); + ALOGI("===== Response M16 Request ====="); + status_t errAlive = mNetSession->sendRequest(sessionID, responseAlive.c_str()); + CHECK_EQ(errAlive, (status_t)OK); + return; + } //ALOGI("!!! FIXME: HARD CODE with video_formats, audio_codecs and client_rtp_ports"); char body[1024]; diff --git a/libstagefright/wifi-display/sink/WifiDisplaySink.h b/libstagefright/wifi-display/sink/WifiDisplaySink.h index 0294883..9ada8e5 100644 --- a/libstagefright/wifi-display/sink/WifiDisplaySink.h +++ b/libstagefright/wifi-display/sink/WifiDisplaySink.h @@ -126,6 +126,7 @@ namespace android enum { kWhatSinkNotify, + kWhatStopCompleted, }; struct ResponseID |