diff options
-rw-r--r-- | include/media/stagefright/AudioSource.h | 8 | ||||
-rw-r--r-- | include/media/stagefright/SurfaceMediaSource.h | 5 | ||||
-rw-r--r-- | include/media/stagefright/TimeSource.h | 2 | ||||
-rw-r--r-- | media/libstagefright/AudioSource.cpp | 17 | ||||
-rw-r--r-- | media/libstagefright/AwesomePlayer.cpp | 18 | ||||
-rw-r--r-- | media/libstagefright/SurfaceMediaSource.cpp | 13 | ||||
-rw-r--r-- | media/libstagefright/ThrottledSource.cpp | 10 | ||||
-rw-r--r-- | media/libstagefright/TimeSource.cpp | 13 | ||||
-rw-r--r-- | media/libstagefright/TimedEventQueue.cpp | 15 | ||||
-rw-r--r-- | media/libstagefright/foundation/ALooper.cpp | 5 | ||||
-rw-r--r-- | media/libstagefright/omx/tests/OMXHarness.cpp | 12 | ||||
-rw-r--r-- | media/libstagefright/rtsp/ARTPAssembler.cpp | 12 | ||||
-rw-r--r-- | media/libstagefright/wifi-display/source/Converter.cpp | 2 | ||||
-rw-r--r-- | media/libstagefright/wifi-display/source/MediaPuller.cpp | 11 | ||||
-rw-r--r-- | media/libstagefright/wifi-display/source/PlaybackSession.cpp | 11 | ||||
-rw-r--r-- | media/libstagefright/wifi-display/source/WifiDisplaySource.cpp | 9 |
16 files changed, 63 insertions, 100 deletions
diff --git a/include/media/stagefright/AudioSource.h b/include/media/stagefright/AudioSource.h index de7edf3..99f3c3b 100644 --- a/include/media/stagefright/AudioSource.h +++ b/include/media/stagefright/AudioSource.h @@ -53,12 +53,6 @@ struct AudioSource : public MediaSource, public MediaBufferObserver { status_t dataCallback(const AudioRecord::Buffer& buffer); virtual void signalBufferReturned(MediaBuffer *buffer); - // If useLooperTime == true, buffers will carry absolute timestamps - // as returned by ALooper::GetNowUs(), otherwise systemTime() is used - // and buffers contain timestamps relative to start time. - // The default is to _not_ use looper time. - void setUseLooperTime(bool useLooperTime); - protected: virtual ~AudioSource(); @@ -94,8 +88,6 @@ private: List<MediaBuffer * > mBuffersReceived; - bool mUseLooperTime; - void trackMaxAmplitude(int16_t *data, int nSamples); // This is used to raise the volume from mute to the diff --git a/include/media/stagefright/SurfaceMediaSource.h b/include/media/stagefright/SurfaceMediaSource.h index 82e5965..e56527d 100644 --- a/include/media/stagefright/SurfaceMediaSource.h +++ b/include/media/stagefright/SurfaceMediaSource.h @@ -116,6 +116,9 @@ public: // To be called before start() status_t setMaxAcquiredBufferCount(size_t count); + // To be called before start() + status_t setUseAbsoluteTimestamps(); + protected: // Implementation of the BufferQueue::ConsumerListener interface. These @@ -212,6 +215,8 @@ private: size_t mMaxAcquiredBufferCount; + bool mUseAbsoluteTimestamps; + // mFrameAvailableCondition condition used to indicate whether there // is a frame available for dequeuing Condition mFrameAvailableCondition; diff --git a/include/media/stagefright/TimeSource.h b/include/media/stagefright/TimeSource.h index 443673d..8f11e14 100644 --- a/include/media/stagefright/TimeSource.h +++ b/include/media/stagefright/TimeSource.h @@ -41,8 +41,6 @@ public: virtual int64_t getRealTimeUs(); private: - static int64_t GetSystemTimeUs(); - int64_t mStartTimeUs; }; diff --git a/media/libstagefright/AudioSource.cpp b/media/libstagefright/AudioSource.cpp index 3248dbc..861aebe 100644 --- a/media/libstagefright/AudioSource.cpp +++ b/media/libstagefright/AudioSource.cpp @@ -54,9 +54,7 @@ AudioSource::AudioSource( mSampleRate(sampleRate), mPrevSampleTimeUs(0), mNumFramesReceived(0), - mNumClientOwnedBuffers(0), - mUseLooperTime(false) { - + mNumClientOwnedBuffers(0) { ALOGV("sampleRate: %d, channelCount: %d", sampleRate, channelCount); CHECK(channelCount == 1 || channelCount == 2); @@ -102,12 +100,6 @@ status_t AudioSource::initCheck() const { return mInitCheck; } -void AudioSource::setUseLooperTime(bool useLooperTime) { - CHECK(!mStarted); - - mUseLooperTime = useLooperTime; -} - status_t AudioSource::start(MetaData *params) { Mutex::Autolock autoLock(mLock); if (mStarted) { @@ -280,8 +272,7 @@ void AudioSource::signalBufferReturned(MediaBuffer *buffer) { } status_t AudioSource::dataCallback(const AudioRecord::Buffer& audioBuffer) { - int64_t timeUs = - mUseLooperTime ? ALooper::GetNowUs() : (systemTime() / 1000ll); + int64_t timeUs = systemTime() / 1000ll; ALOGV("dataCallbackTimestamp: %lld us", timeUs); Mutex::Autolock autoLock(mLock); @@ -300,9 +291,7 @@ status_t AudioSource::dataCallback(const AudioRecord::Buffer& audioBuffer) { if (mNumFramesReceived == 0 && mPrevSampleTimeUs == 0) { mInitialReadTimeUs = timeUs; // Initial delay - if (mUseLooperTime) { - mStartTimeUs = timeUs; - } else if (mStartTimeUs > 0) { + if (mStartTimeUs > 0) { mStartTimeUs = timeUs - mStartTimeUs; } else { // Assume latency is constant. diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp index 9f069ae..0cb378d 100644 --- a/media/libstagefright/AwesomePlayer.cpp +++ b/media/libstagefright/AwesomePlayer.cpp @@ -755,22 +755,18 @@ void AwesomePlayer::onBufferingUpdate() { if ((mFlags & PLAYING) && !eos && (cachedDurationUs < kLowWaterMarkUs)) { modifyFlags(CACHE_UNDERRUN, SET); - if (mWVMExtractor == NULL) { - ALOGI("cache is running low (%.2f secs) , pausing.", - cachedDurationUs / 1E6); - pause_l(); - ensureCacheIsFetching_l(); - } + ALOGI("cache is running low (%.2f secs) , pausing.", + cachedDurationUs / 1E6); + pause_l(); + ensureCacheIsFetching_l(); sendCacheStats(); notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START); } else if (eos || cachedDurationUs > kHighWaterMarkUs) { if (mFlags & CACHE_UNDERRUN) { modifyFlags(CACHE_UNDERRUN, CLEAR); - if (mWVMExtractor == NULL) { - ALOGI("cache has filled up (%.2f secs), resuming.", - cachedDurationUs / 1E6); - play_l(); - } + ALOGI("cache has filled up (%.2f secs), resuming.", + cachedDurationUs / 1E6); + play_l(); } else if (mFlags & PREPARING) { ALOGV("cache has filled up (%.2f secs), prepare is done", cachedDurationUs / 1E6); diff --git a/media/libstagefright/SurfaceMediaSource.cpp b/media/libstagefright/SurfaceMediaSource.cpp index 97f9c7c..3c002fc 100644 --- a/media/libstagefright/SurfaceMediaSource.cpp +++ b/media/libstagefright/SurfaceMediaSource.cpp @@ -46,8 +46,8 @@ SurfaceMediaSource::SurfaceMediaSource(uint32_t bufferWidth, uint32_t bufferHeig mNumFramesReceived(0), mNumFramesEncoded(0), mFirstFrameTimestamp(0), - mMaxAcquiredBufferCount(4) // XXX double-check the default -{ + mMaxAcquiredBufferCount(4), // XXX double-check the default + mUseAbsoluteTimestamps(false) { ALOGV("SurfaceMediaSource"); if (bufferWidth == 0 || bufferHeight == 0) { @@ -188,6 +188,13 @@ status_t SurfaceMediaSource::setMaxAcquiredBufferCount(size_t count) { return OK; } +status_t SurfaceMediaSource::setUseAbsoluteTimestamps() { + ALOGV("setUseAbsoluteTimestamps"); + Mutex::Autolock lock(mMutex); + mUseAbsoluteTimestamps = true; + + return OK; +} status_t SurfaceMediaSource::stop() { @@ -298,7 +305,7 @@ status_t SurfaceMediaSource::read( MediaBuffer **buffer, } // check for the timing of this buffer - if (mNumFramesReceived == 0) { + if (mNumFramesReceived == 0 && !mUseAbsoluteTimestamps) { mFirstFrameTimestamp = item.mTimestamp; // Initial delay if (mStartTimeNs > 0) { diff --git a/media/libstagefright/ThrottledSource.cpp b/media/libstagefright/ThrottledSource.cpp index b1fcafd..348a9d3 100644 --- a/media/libstagefright/ThrottledSource.cpp +++ b/media/libstagefright/ThrottledSource.cpp @@ -17,16 +17,10 @@ #include "include/ThrottledSource.h" #include <media/stagefright/foundation/ADebug.h> +#include <media/stagefright/foundation/ALooper.h> namespace android { -static int64_t getNowUs() { - struct timeval tv; - gettimeofday(&tv, NULL); - - return (int64_t)tv.tv_usec + tv.tv_sec * 1000000ll; -} - ThrottledSource::ThrottledSource( const sp<DataSource> &source, int32_t bandwidthLimitBytesPerSecond) @@ -52,7 +46,7 @@ ssize_t ThrottledSource::readAt(off64_t offset, void *data, size_t size) { mTotalTransferred += n; - int64_t nowUs = getNowUs(); + int64_t nowUs = ALooper::GetNowUs(); if (mStartTimeUs < 0) { mStartTimeUs = nowUs; diff --git a/media/libstagefright/TimeSource.cpp b/media/libstagefright/TimeSource.cpp index d987fbf..041980f 100644 --- a/media/libstagefright/TimeSource.cpp +++ b/media/libstagefright/TimeSource.cpp @@ -17,24 +17,17 @@ #include <stddef.h> #include <sys/time.h> +#include <media/stagefright/foundation/ALooper.h> #include <media/stagefright/TimeSource.h> namespace android { SystemTimeSource::SystemTimeSource() - : mStartTimeUs(GetSystemTimeUs()) { + : mStartTimeUs(ALooper::GetNowUs()) { } int64_t SystemTimeSource::getRealTimeUs() { - return GetSystemTimeUs() - mStartTimeUs; -} - -// static -int64_t SystemTimeSource::GetSystemTimeUs() { - struct timeval tv; - gettimeofday(&tv, NULL); - - return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; + return ALooper::GetNowUs() - mStartTimeUs; } } // namespace android diff --git a/media/libstagefright/TimedEventQueue.cpp b/media/libstagefright/TimedEventQueue.cpp index 9df15eb..7e9c4bf 100644 --- a/media/libstagefright/TimedEventQueue.cpp +++ b/media/libstagefright/TimedEventQueue.cpp @@ -30,6 +30,7 @@ #include <sys/time.h> #include <media/stagefright/foundation/ADebug.h> +#include <media/stagefright/foundation/ALooper.h> namespace android { @@ -94,7 +95,7 @@ TimedEventQueue::event_id TimedEventQueue::postEventToBack( TimedEventQueue::event_id TimedEventQueue::postEventWithDelay( const sp<Event> &event, int64_t delay_us) { CHECK(delay_us >= 0); - return postTimedEvent(event, getRealTimeUs() + delay_us); + return postTimedEvent(event, ALooper::GetNowUs() + delay_us); } TimedEventQueue::event_id TimedEventQueue::postTimedEvent( @@ -179,14 +180,6 @@ void TimedEventQueue::cancelEvents( } // static -int64_t TimedEventQueue::getRealTimeUs() { - struct timeval tv; - gettimeofday(&tv, NULL); - - return (int64_t)tv.tv_sec * 1000000ll + tv.tv_usec; -} - -// static void *TimedEventQueue::ThreadWrapper(void *me) { androidSetThreadPriority(0, ANDROID_PRIORITY_FOREGROUND); @@ -225,7 +218,7 @@ void TimedEventQueue::threadEntry() { List<QueueItem>::iterator it = mQueue.begin(); eventID = (*it).event->eventID(); - now_us = getRealTimeUs(); + now_us = ALooper::GetNowUs(); int64_t when_us = (*it).realtime_us; int64_t delay_us; @@ -258,7 +251,7 @@ void TimedEventQueue::threadEntry() { if (!timeoutCapped && err == -ETIMEDOUT) { // We finally hit the time this event is supposed to // trigger. - now_us = getRealTimeUs(); + now_us = ALooper::GetNowUs(); break; } } diff --git a/media/libstagefright/foundation/ALooper.cpp b/media/libstagefright/foundation/ALooper.cpp index a5b316d..22777a2 100644 --- a/media/libstagefright/foundation/ALooper.cpp +++ b/media/libstagefright/foundation/ALooper.cpp @@ -63,10 +63,7 @@ private: // static int64_t ALooper::GetNowUs() { - struct timeval tv; - gettimeofday(&tv, NULL); - - return (int64_t)tv.tv_sec * 1000000ll + tv.tv_usec; + return systemTime(SYSTEM_TIME_MONOTONIC) / 1000ll; } ALooper::ALooper() diff --git a/media/libstagefright/omx/tests/OMXHarness.cpp b/media/libstagefright/omx/tests/OMXHarness.cpp index 4b369ed..6cca8da 100644 --- a/media/libstagefright/omx/tests/OMXHarness.cpp +++ b/media/libstagefright/omx/tests/OMXHarness.cpp @@ -27,6 +27,7 @@ #include <binder/MemoryDealer.h> #include <media/IMediaPlayerService.h> #include <media/stagefright/foundation/ADebug.h> +#include <media/stagefright/foundation/ALooper.h> #include <media/stagefright/DataSource.h> #include <media/stagefright/MediaBuffer.h> #include <media/stagefright/MediaDefs.h> @@ -40,13 +41,6 @@ namespace android { -static int64_t getNowUs() { - struct timeval tv; - gettimeofday(&tv, NULL); - - return (int64_t)tv.tv_usec + tv.tv_sec * 1000000; -} - Harness::Harness() : mInitCheck(NO_INIT) { mInitCheck = initOMX(); @@ -126,7 +120,7 @@ status_t Harness::dequeueMessageForNodeIgnoringBuffers( Vector<Buffer> *inputBuffers, Vector<Buffer> *outputBuffers, omx_message *msg, int64_t timeoutUs) { - int64_t finishBy = getNowUs() + timeoutUs; + int64_t finishBy = ALooper::GetNowUs() + timeoutUs; for (;;) { Mutex::Autolock autoLock(mLock); @@ -150,7 +144,7 @@ status_t Harness::dequeueMessageForNodeIgnoringBuffers( status_t err = (timeoutUs < 0) ? mMessageAddedCondition.wait(mLock) : mMessageAddedCondition.waitRelative( - mLock, (finishBy - getNowUs()) * 1000); + mLock, (finishBy - ALooper::GetNowUs()) * 1000); if (err == TIMED_OUT) { return err; diff --git a/media/libstagefright/rtsp/ARTPAssembler.cpp b/media/libstagefright/rtsp/ARTPAssembler.cpp index 1844bc5..c7a65c2 100644 --- a/media/libstagefright/rtsp/ARTPAssembler.cpp +++ b/media/libstagefright/rtsp/ARTPAssembler.cpp @@ -18,19 +18,13 @@ #include <media/stagefright/foundation/ABuffer.h> #include <media/stagefright/foundation/ADebug.h> +#include <media/stagefright/foundation/ALooper.h> #include <media/stagefright/foundation/AMessage.h> #include <stdint.h> namespace android { -static int64_t getNowUs() { - struct timeval tv; - gettimeofday(&tv, NULL); - - return (int64_t)tv.tv_usec + tv.tv_sec * 1000000ll; -} - ARTPAssembler::ARTPAssembler() : mFirstFailureTimeUs(-1) { } @@ -42,7 +36,7 @@ void ARTPAssembler::onPacketReceived(const sp<ARTPSource> &source) { if (status == WRONG_SEQUENCE_NUMBER) { if (mFirstFailureTimeUs >= 0) { - if (getNowUs() - mFirstFailureTimeUs > 10000ll) { + if (ALooper::GetNowUs() - mFirstFailureTimeUs > 10000ll) { mFirstFailureTimeUs = -1; // LOG(VERBOSE) << "waited too long for packet."; @@ -50,7 +44,7 @@ void ARTPAssembler::onPacketReceived(const sp<ARTPSource> &source) { continue; } } else { - mFirstFailureTimeUs = getNowUs(); + mFirstFailureTimeUs = ALooper::GetNowUs(); } break; } else { diff --git a/media/libstagefright/wifi-display/source/Converter.cpp b/media/libstagefright/wifi-display/source/Converter.cpp index 99db060..60cca69 100644 --- a/media/libstagefright/wifi-display/source/Converter.cpp +++ b/media/libstagefright/wifi-display/source/Converter.cpp @@ -132,7 +132,7 @@ status_t Converter::initEncoder() { mOutputFormat->setInt32("bitrate", audioBitrate); } else { mOutputFormat->setInt32("bitrate", videoBitrate); - mOutputFormat->setInt32("frame-rate", 24); + mOutputFormat->setInt32("frame-rate", 60); mOutputFormat->setInt32("i-frame-interval", 1); // Iframes every 1 secs // mOutputFormat->setInt32("prepend-sps-pps-to-idr-frames", 1); } diff --git a/media/libstagefright/wifi-display/source/MediaPuller.cpp b/media/libstagefright/wifi-display/source/MediaPuller.cpp index 82ae001..ab69c4a 100644 --- a/media/libstagefright/wifi-display/source/MediaPuller.cpp +++ b/media/libstagefright/wifi-display/source/MediaPuller.cpp @@ -75,7 +75,16 @@ void MediaPuller::onMessageReceived(const sp<AMessage> &msg) { switch (msg->what()) { case kWhatStart: { - status_t err = mSource->start(); + status_t err; + if (mIsAudio) { + // This atrocity causes AudioSource to deliver absolute + // systemTime() based timestamps (off by 1 us). + sp<MetaData> params = new MetaData; + params->setInt64(kKeyTime, 1ll); + err = mSource->start(params.get()); + } else { + err = mSource->start(); + } if (err == OK) { schedulePull(); diff --git a/media/libstagefright/wifi-display/source/PlaybackSession.cpp b/media/libstagefright/wifi-display/source/PlaybackSession.cpp index 9c065b2..7de607c 100644 --- a/media/libstagefright/wifi-display/source/PlaybackSession.cpp +++ b/media/libstagefright/wifi-display/source/PlaybackSession.cpp @@ -267,7 +267,7 @@ WifiDisplaySource::PlaybackSession::PlaybackSession( mSendSRPending(false), mHistoryLength(0) #if TRACK_BANDWIDTH - ,mFirstPacketTimeUs(-1ll), + ,mFirstPacketTimeUs(-1ll) ,mTotalBytesSent(0ll) #endif #if LOG_TRANSPORT_STREAM @@ -883,11 +883,10 @@ status_t WifiDisplaySource::PlaybackSession::addSource( status_t WifiDisplaySource::PlaybackSession::addVideoSource() { sp<SurfaceMediaSource> source = new SurfaceMediaSource(width(), height()); - sp<MediaSource> videoSource = - new RepeaterSource(source, 24.0 /* rateHz */); + source->setUseAbsoluteTimestamps(); size_t numInputBuffers; - status_t err = addSource(true /* isVideo */, videoSource, &numInputBuffers); + status_t err = addSource(true /* isVideo */, source, &numInputBuffers); if (err != OK) { return err; @@ -908,8 +907,6 @@ status_t WifiDisplaySource::PlaybackSession::addAudioSource() { 2 /* channelCount */); if (audioSource->initCheck() == OK) { - audioSource->setUseLooperTime(true); - return addSource( false /* isVideo */, audioSource, NULL /* numInputBuffers */); } @@ -1123,7 +1120,7 @@ ssize_t WifiDisplaySource::PlaybackSession::appendTSData( int64_t delayUs = ALooper::GetNowUs() - mFirstPacketTimeUs; if (delayUs > 0ll) { - ALOGV("approx. net bandwidth used: %.2f Mbit/sec", + ALOGI("approx. net bandwidth used: %.2f Mbit/sec", mTotalBytesSent * 8.0 / delayUs); } #endif diff --git a/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp b/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp index adb1549..1083a80 100644 --- a/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp +++ b/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp @@ -312,7 +312,12 @@ void WifiDisplaySource::onMessageReceived(const sp<AMessage> &msg) { mClientInfo.mPlaybackSession->getSurfaceTexture(), mClientInfo.mPlaybackSession->width(), mClientInfo.mPlaybackSession->height(), - 0 /* flags */); +#if REQUIRE_HDCP + IRemoteDisplayClient::kDisplayFlagSecure +#else + 0 /* flags */ +#endif + ); } if (mState == ABOUT_TO_PLAY) { @@ -534,7 +539,7 @@ status_t WifiDisplaySource::sendM4(int32_t sessionID) { // use "78 00 02 02 00008000 00000000 00000000 00 0000 0000 00 none none\r\n" AString body = StringPrintf( "wfd_video_formats: " - "78 00 02 02 00008000 00000000 00000000 00 0000 0000 00 none none\r\n" + "30 00 02 02 00000040 00000000 00000000 00 0000 0000 00 none none\r\n" "wfd_audio_codecs: AAC 00000001 00\r\n" // 2 ch AAC 48kHz "wfd_presentation_URL: rtsp://%s/wfd1.0/streamid=0 none\r\n" "wfd_client_rtp_ports: RTP/AVP/%s;unicast 19000 0 mode=play\r\n", |