OSDN Git Service

Even cleaner shutdown.
authorAndreas Huber <andih@google.com>
Fri, 28 Sep 2012 23:34:38 +0000 (16:34 -0700)
committerAndreas Huber <andih@google.com>
Fri, 28 Sep 2012 23:36:04 +0000 (16:36 -0700)
Change-Id: I5a76f83db3a5e43f55eb4e04269d890c2015bae7
related-to-bug: 7247918

media/libstagefright/wifi-display/source/Converter.cpp
media/libstagefright/wifi-display/source/PlaybackSession.cpp
media/libstagefright/wifi-display/source/PlaybackSession.h
media/libstagefright/wifi-display/source/RepeaterSource.cpp
media/libstagefright/wifi-display/source/RepeaterSource.h

index 968a805..99db060 100644 (file)
@@ -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<ABuffer> buffer = new ABuffer(size);
             buffer->meta()->setInt64("timeUs", timeUs);
 
index 775f23b..829a16d 100644 (file)
@@ -75,8 +75,6 @@ struct WifiDisplaySource::PlaybackSession::Track : public AHandler {
     status_t start();
     void stopAsync();
 
-    bool isStopped() const { return !mStarted; }
-
     void queueAccessUnit(const sp<ABuffer> &accessUnit);
     sp<ABuffer> dequeueAccessUnit();
 
@@ -200,6 +198,8 @@ void WifiDisplaySource::PlaybackSession::Track::onMessageReceived(
             sp<AMessage> 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> &track = mTracks.valueAt(i);
-                    if (!track->isStopped()) {
-                        allTracksAreStopped = false;
-                        break;
-                    }
-                }
+                ALOGI("Track %d stopped", trackIndex);
 
-                if (!allTracksAreStopped) {
+                sp<Track> 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);
index 9237a72..8d88648 100644 (file)
@@ -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<sp<ABuffer> > mHistory;
     size_t mHistoryLength;
 
+#if TRACK_BANDWIDTH
+    int64_t mFirstPacketTimeUs;
     uint64_t mTotalBytesSent;
+#endif
 
 #if LOG_TRANSPORT_STREAM
     FILE *mLogFile;
index 483d29c..dc216e8 100644 (file)
@@ -13,7 +13,8 @@
 namespace android {
 
 RepeaterSource::RepeaterSource(const sp<MediaSource> &source, double rateHz)
-    : mSource(source),
+    : mStarted(false),
+      mSource(source),
       mRateHz(rateHz),
       mBuffer(NULL),
       mResult(OK),
@@ -22,10 +23,12 @@ RepeaterSource::RepeaterSource(const sp<MediaSource> &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;
 }
 
index 31eb5cd..3049362 100644 (file)
@@ -33,6 +33,8 @@ private:
     Mutex mLock;
     Condition mCondition;
 
+    bool mStarted;
+
     sp<MediaSource> mSource;
     double mRateHz;