From 77245813007cf903b4b73f5d0cd20313fbf0e510 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Fri, 28 Sep 2012 16:34:38 -0700 Subject: [PATCH] Even cleaner shutdown. Change-Id: I5a76f83db3a5e43f55eb4e04269d890c2015bae7 related-to-bug: 7247918 --- .../wifi-display/source/Converter.cpp | 4 --- .../wifi-display/source/PlaybackSession.cpp | 38 ++++++++++++---------- .../wifi-display/source/PlaybackSession.h | 6 ++-- .../wifi-display/source/RepeaterSource.cpp | 13 ++++++-- .../wifi-display/source/RepeaterSource.h | 2 ++ 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/media/libstagefright/wifi-display/source/Converter.cpp b/media/libstagefright/wifi-display/source/Converter.cpp index 968a805ed0..99db060d3e 100644 --- a/media/libstagefright/wifi-display/source/Converter.cpp +++ b/media/libstagefright/wifi-display/source/Converter.cpp @@ -301,8 +301,6 @@ status_t Converter::feedEncoderInputBuffers() { if (buffer != NULL) { CHECK(buffer->meta()->findInt64("timeUs", &timeUs)); - ALOGV("in: %s timeUs = %lld us", mIsVideo ? "video" : "audio", timeUs); - memcpy(mEncoderInputBuffers.itemAt(bufferIndex)->data(), buffer->data(), buffer->size()); @@ -353,8 +351,6 @@ status_t Converter::doMoreWork() { notify->setInt32("what", kWhatEOS); notify->post(); } else { - ALOGV("out: %s timeUs = %lld us", mIsVideo ? "video" : "audio", timeUs); - sp buffer = new ABuffer(size); buffer->meta()->setInt64("timeUs", timeUs); diff --git a/media/libstagefright/wifi-display/source/PlaybackSession.cpp b/media/libstagefright/wifi-display/source/PlaybackSession.cpp index 775f23b9d6..829a16d381 100644 --- a/media/libstagefright/wifi-display/source/PlaybackSession.cpp +++ b/media/libstagefright/wifi-display/source/PlaybackSession.cpp @@ -75,8 +75,6 @@ struct WifiDisplaySource::PlaybackSession::Track : public AHandler { status_t start(); void stopAsync(); - bool isStopped() const { return !mStarted; } - void queueAccessUnit(const sp &accessUnit); sp dequeueAccessUnit(); @@ -200,6 +198,8 @@ void WifiDisplaySource::PlaybackSession::Track::onMessageReceived( sp notify = mNotify->dup(); notify->setInt32("what", kWhatStopped); notify->post(); + + ALOGI("kWhatStopped %s posted", mIsAudio ? "audio" : "video"); break; } @@ -267,9 +267,11 @@ WifiDisplaySource::PlaybackSession::PlaybackSession( mNumRTPOctetsSent(0), mNumSRsSent(0), mSendSRPending(false), - mFirstPacketTimeUs(-1ll), - mHistoryLength(0), - mTotalBytesSent(0ll) + mHistoryLength(0) +#if TRACK_BANDWIDTH + ,mFirstPacketTimeUs(-1ll), + ,mTotalBytesSent(0ll) +#endif #if LOG_TRANSPORT_STREAM ,mLogFile(NULL) #endif @@ -747,21 +749,18 @@ void WifiDisplaySource::PlaybackSession::onMessageReceived( CHECK(msg->findSize("trackIndex", &trackIndex)); if (what == Track::kWhatStopped) { - bool allTracksAreStopped = true; - for (size_t i = 0; i < mTracks.size(); ++i) { - const sp &track = mTracks.valueAt(i); - if (!track->isStopped()) { - allTracksAreStopped = false; - break; - } - } + ALOGI("Track %d stopped", trackIndex); - if (!allTracksAreStopped) { + sp track = mTracks.valueFor(trackIndex); + looper()->unregisterHandler(track->id()); + mTracks.removeItem(trackIndex); + track.clear(); + + if (!mTracks.isEmpty()) { + ALOGI("not all tracks are stopped yet"); break; } - mTracks.clear(); - mPacketizer.clear(); #if ENABLE_RETRANSMISSION @@ -1074,12 +1073,15 @@ ssize_t WifiDisplaySource::PlaybackSession::appendTSData( // flush int64_t nowUs = ALooper::GetNowUs(); + +#if TRACK_BANDWIDTH if (mFirstPacketTimeUs < 0ll) { mFirstPacketTimeUs = nowUs; } +#endif // 90kHz time scale - uint32_t rtpTime = ((nowUs - mFirstPacketTimeUs) * 9ll) / 100ll; + uint32_t rtpTime = (nowUs * 9ll) / 100ll; uint8_t *rtp = mTSQueue->data(); rtp[0] = 0x80; @@ -1115,6 +1117,7 @@ ssize_t WifiDisplaySource::PlaybackSession::appendTSData( } else { sendPacket(mRTPSessionID, rtp, mTSQueue->size()); +#if TRACK_BANDWIDTH mTotalBytesSent += mTSQueue->size(); int64_t delayUs = ALooper::GetNowUs() - mFirstPacketTimeUs; @@ -1122,6 +1125,7 @@ ssize_t WifiDisplaySource::PlaybackSession::appendTSData( ALOGV("approx. net bandwidth used: %.2f Mbit/sec", mTotalBytesSent * 8.0 / delayUs); } +#endif } mTSQueue->setInt32Data(mRTPSeqNo - 1); diff --git a/media/libstagefright/wifi-display/source/PlaybackSession.h b/media/libstagefright/wifi-display/source/PlaybackSession.h index 9237a725b3..8d88648350 100644 --- a/media/libstagefright/wifi-display/source/PlaybackSession.h +++ b/media/libstagefright/wifi-display/source/PlaybackSession.h @@ -32,6 +32,7 @@ struct TSPacketizer; #define LOG_TRANSPORT_STREAM 0 #define ENABLE_RETRANSMISSION 0 +#define TRACK_BANDWIDTH 0 // Encapsulates the state of an RTP/RTCP session in the context of wifi // display. @@ -160,12 +161,13 @@ private: bool mSendSRPending; - int64_t mFirstPacketTimeUs; - List > mHistory; size_t mHistoryLength; +#if TRACK_BANDWIDTH + int64_t mFirstPacketTimeUs; uint64_t mTotalBytesSent; +#endif #if LOG_TRANSPORT_STREAM FILE *mLogFile; diff --git a/media/libstagefright/wifi-display/source/RepeaterSource.cpp b/media/libstagefright/wifi-display/source/RepeaterSource.cpp index 483d29c28a..dc216e8438 100644 --- a/media/libstagefright/wifi-display/source/RepeaterSource.cpp +++ b/media/libstagefright/wifi-display/source/RepeaterSource.cpp @@ -13,7 +13,8 @@ namespace android { RepeaterSource::RepeaterSource(const sp &source, double rateHz) - : mSource(source), + : mStarted(false), + mSource(source), mRateHz(rateHz), mBuffer(NULL), mResult(OK), @@ -22,10 +23,12 @@ RepeaterSource::RepeaterSource(const sp &source, double rateHz) } RepeaterSource::~RepeaterSource() { - stop(); + CHECK(!mStarted); } status_t RepeaterSource::start(MetaData *params) { + CHECK(!mStarted); + status_t err = mSource->start(params); if (err != OK) { @@ -46,10 +49,14 @@ status_t RepeaterSource::start(MetaData *params) { postRead(); + mStarted = true; + return OK; } status_t RepeaterSource::stop() { + CHECK(mStarted); + ALOGV("stopping"); if (mLooper != NULL) { @@ -69,6 +76,8 @@ status_t RepeaterSource::stop() { ALOGV("stopped"); + mStarted = false; + return err; } diff --git a/media/libstagefright/wifi-display/source/RepeaterSource.h b/media/libstagefright/wifi-display/source/RepeaterSource.h index 31eb5cda11..3049362b2c 100644 --- a/media/libstagefright/wifi-display/source/RepeaterSource.h +++ b/media/libstagefright/wifi-display/source/RepeaterSource.h @@ -33,6 +33,8 @@ private: Mutex mLock; Condition mCondition; + bool mStarted; + sp mSource; double mRateHz; -- 2.11.0