summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-rw-r--r--media/libmedia/AudioSystem.cpp8
-rw-r--r--media/libmedia/AudioTrack.cpp4
-rw-r--r--media/libmediaplayerservice/nuplayer/StreamingSource.cpp2
-rw-r--r--media/libstagefright/AACExtractor.cpp33
-rw-r--r--media/libstagefright/AwesomePlayer.cpp3
-rw-r--r--media/libstagefright/SurfaceMediaSource.cpp28
-rw-r--r--media/libstagefright/mpeg2ts/ATSParser.cpp21
-rw-r--r--media/libstagefright/mpeg2ts/ATSParser.h12
8 files changed, 88 insertions, 23 deletions
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp
index bb91fa9..853a5f6 100644
--- a/media/libmedia/AudioSystem.cpp
+++ b/media/libmedia/AudioSystem.cpp
@@ -727,6 +727,14 @@ status_t AudioSystem::isStreamActive(int stream, bool* state, uint32_t inPastMs)
}
+void AudioSystem::clearAudioConfigCache()
+{
+ Mutex::Autolock _l(gLock);
+ LOGV("clearAudioConfigCache()");
+ gStreamOutputMap.clear();
+ gOutputs.clear();
+}
+
// ---------------------------------------------------------------------------
void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who) {
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index cecedb5..3b6c64d 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -1164,6 +1164,10 @@ status_t AudioTrack::restoreTrack_l(audio_track_cblk_t*& cblk, bool fromStart)
cblk->cv.broadcast();
cblk->lock.unlock();
+ // refresh the audio configuration cache in this process to make sure we get new
+ // output parameters in getOutput_l() and createTrack_l()
+ AudioSystem::clearAudioConfigCache();
+
// if the new IAudioTrack is created, createTrack_l() will modify the
// following member variables: mAudioTrack, mCblkMemory and mCblk.
// It will also delete the strong references on previous IAudioTrack and IMemory
diff --git a/media/libmediaplayerservice/nuplayer/StreamingSource.cpp b/media/libmediaplayerservice/nuplayer/StreamingSource.cpp
index a6a3a18..f41e9d2 100644
--- a/media/libmediaplayerservice/nuplayer/StreamingSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/StreamingSource.cpp
@@ -42,7 +42,7 @@ NuPlayer::StreamingSource::~StreamingSource() {
void NuPlayer::StreamingSource::start() {
mStreamListener = new NuPlayerStreamListener(mSource, 0);
- mTSParser = new ATSParser;
+ mTSParser = new ATSParser(ATSParser::TS_TIMESTAMPS_ARE_ABSOLUTE);
mStreamListener->start();
}
diff --git a/media/libstagefright/AACExtractor.cpp b/media/libstagefright/AACExtractor.cpp
index a5a6b64..52b1200 100644
--- a/media/libstagefright/AACExtractor.cpp
+++ b/media/libstagefright/AACExtractor.cpp
@@ -33,8 +33,6 @@
namespace android {
-#define ADTS_HEADER_LENGTH 7
-
class AACSource : public MediaSource {
public:
AACSource(const sp<DataSource> &source,
@@ -88,7 +86,16 @@ uint32_t get_sample_rate(const uint8_t sf_index)
return 0;
}
-static size_t getFrameSize(const sp<DataSource> &source, off64_t offset) {
+// Returns the frame length in bytes as described in an ADTS header starting at the given offset,
+// or 0 if the size can't be read due to an error in the header or a read failure.
+// The returned value is the AAC frame size with the ADTS header length (regardless of
+// the presence of the CRC).
+// If headerSize is non-NULL, it will be used to return the size of the header of this ADTS frame.
+static size_t getAdtsFrameLength(const sp<DataSource> &source, off64_t offset, size_t* headerSize) {
+
+ const size_t kAdtsHeaderLengthNoCrc = 7;
+ const size_t kAdtsHeaderLengthWithCrc = 9;
+
size_t frameSize = 0;
uint8_t syncword[2];
@@ -111,7 +118,15 @@ static size_t getFrameSize(const sp<DataSource> &source, off64_t offset) {
}
frameSize = (header[0] & 0x3) << 11 | header[1] << 3 | header[2] >> 5;
- frameSize += ADTS_HEADER_LENGTH + protectionAbsent ? 0 : 2;
+
+ // protectionAbsent is 0 if there is CRC
+ size_t headSize = protectionAbsent ? kAdtsHeaderLengthNoCrc : kAdtsHeaderLengthWithCrc;
+ if (headSize > frameSize) {
+ return 0;
+ }
+ if (headerSize != NULL) {
+ *headerSize = headSize;
+ }
return frameSize;
}
@@ -148,7 +163,7 @@ AACExtractor::AACExtractor(const sp<DataSource> &source)
if (mDataSource->getSize(&streamSize) == OK) {
while (offset < streamSize) {
- if ((frameSize = getFrameSize(source, offset)) == 0) {
+ if ((frameSize = getAdtsFrameLength(source, offset, NULL)) == 0) {
return;
}
@@ -268,8 +283,8 @@ status_t AACSource::read(
}
}
- size_t frameSize, frameSizeWithoutHeader;
- if ((frameSize = getFrameSize(mDataSource, mOffset)) == 0) {
+ size_t frameSize, frameSizeWithoutHeader, headerSize;
+ if ((frameSize = getAdtsFrameLength(mDataSource, mOffset, &headerSize)) == 0) {
return ERROR_END_OF_STREAM;
}
@@ -279,8 +294,8 @@ status_t AACSource::read(
return err;
}
- frameSizeWithoutHeader = frameSize - ADTS_HEADER_LENGTH;
- if (mDataSource->readAt(mOffset + ADTS_HEADER_LENGTH, buffer->data(),
+ frameSizeWithoutHeader = frameSize - headerSize;
+ if (mDataSource->readAt(mOffset + headerSize, buffer->data(),
frameSizeWithoutHeader) != (ssize_t)frameSizeWithoutHeader) {
buffer->release();
buffer = NULL;
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 142dda0..f98b0de 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -513,7 +513,8 @@ void AwesomePlayer::reset_l() {
// If we did this later, audio would continue playing while we
// shutdown the video-related resources and the player appear to
// not be as responsive to a reset request.
- if (mAudioPlayer == NULL && mAudioSource != NULL) {
+ if ((mAudioPlayer == NULL || !(mFlags & AUDIOPLAYER_STARTED))
+ && mAudioSource != NULL) {
// If we had an audio player, it would have effectively
// taken possession of the audio source and stopped it when
// _it_ is stopped. Otherwise this is still our responsibility.
diff --git a/media/libstagefright/SurfaceMediaSource.cpp b/media/libstagefright/SurfaceMediaSource.cpp
index 91b81c2..50dd804 100644
--- a/media/libstagefright/SurfaceMediaSource.cpp
+++ b/media/libstagefright/SurfaceMediaSource.cpp
@@ -46,9 +46,10 @@ SurfaceMediaSource::SurfaceMediaSource(uint32_t bufW, uint32_t bufH) :
mSynchronousMode(true),
mConnectedApi(NO_CONNECTED_API),
mFrameRate(30),
+ mStopped(false),
mNumFramesReceived(0),
mNumFramesEncoded(0),
- mStopped(false) {
+ mFirstFrameTimestamp(0) {
LOGV("SurfaceMediaSource::SurfaceMediaSource");
sp<ISurfaceComposer> composer(ComposerService::getComposerService());
mGraphicBufferAlloc = composer->createGraphicBufferAlloc();
@@ -471,10 +472,25 @@ status_t SurfaceMediaSource::queueBuffer(int bufIndex, int64_t timestamp,
return -EINVAL;
}
+ if (mNumFramesReceived == 0) {
+ mFirstFrameTimestamp = timestamp;
+ // Initial delay
+ if (mStartTimeNs > 0) {
+ if (timestamp < mStartTimeNs) {
+ // This frame predates start of record, discard
+ mSlots[bufIndex].mBufferState = BufferSlot::FREE;
+ mDequeueCondition.signal();
+ return OK;
+ }
+ mStartTimeNs = timestamp - mStartTimeNs;
+ }
+ }
+ timestamp = mStartTimeNs + (timestamp - mFirstFrameTimestamp);
+
+ mNumFramesReceived++;
if (mSynchronousMode) {
// in synchronous mode we queue all buffers in a FIFO
mQueue.push_back(bufIndex);
- mNumFramesReceived++;
LOGV("Client queued buf# %d @slot: %d, Q size = %d, handle = %p, timestamp = %lld",
mNumFramesReceived, bufIndex, mQueue.size(),
mSlots[bufIndex].mGraphicBuffer->handle, timestamp);
@@ -684,6 +700,13 @@ int32_t SurfaceMediaSource::getFrameRate( ) const {
status_t SurfaceMediaSource::start(MetaData *params)
{
LOGV("started!");
+
+ mStartTimeNs = 0;
+ int64_t startTimeUs;
+ if (params && params->findInt64(kKeyTime, &startTimeUs)) {
+ mStartTimeNs = startTimeUs * 1000;
+ }
+
return OK;
}
@@ -753,6 +776,7 @@ status_t SurfaceMediaSource::read( MediaBuffer **buffer,
mCurrentBuf = mSlots[mCurrentSlot].mGraphicBuffer;
int64_t prevTimeStamp = mCurrentTimestamp;
mCurrentTimestamp = mSlots[mCurrentSlot].mTimestamp;
+
mNumFramesEncoded++;
// Pass the data to the MediaBuffer. Pass in only the metadata
passMetadataBufferLocked(buffer);
diff --git a/media/libstagefright/mpeg2ts/ATSParser.cpp b/media/libstagefright/mpeg2ts/ATSParser.cpp
index 5bbc2b4..74a3b32 100644
--- a/media/libstagefright/mpeg2ts/ATSParser.cpp
+++ b/media/libstagefright/mpeg2ts/ATSParser.cpp
@@ -325,14 +325,16 @@ sp<MediaSource> ATSParser::Program::getSource(SourceType type) {
}
int64_t ATSParser::Program::convertPTSToTimestamp(uint64_t PTS) {
- if (!mFirstPTSValid) {
- mFirstPTSValid = true;
- mFirstPTS = PTS;
- PTS = 0;
- } else if (PTS < mFirstPTS) {
- PTS = 0;
- } else {
- PTS -= mFirstPTS;
+ if (!(mParser->mFlags & TS_TIMESTAMPS_ARE_ABSOLUTE)) {
+ if (!mFirstPTSValid) {
+ mFirstPTSValid = true;
+ mFirstPTS = PTS;
+ PTS = 0;
+ } else if (PTS < mFirstPTS) {
+ PTS = 0;
+ } else {
+ PTS -= mFirstPTS;
+ }
}
return (PTS * 100) / 9;
@@ -734,7 +736,8 @@ sp<MediaSource> ATSParser::Stream::getSource(SourceType type) {
////////////////////////////////////////////////////////////////////////////////
-ATSParser::ATSParser() {
+ATSParser::ATSParser(uint32_t flags)
+ : mFlags(flags) {
}
ATSParser::~ATSParser() {
diff --git a/media/libstagefright/mpeg2ts/ATSParser.h b/media/libstagefright/mpeg2ts/ATSParser.h
index 1e6451d..d12d998 100644
--- a/media/libstagefright/mpeg2ts/ATSParser.h
+++ b/media/libstagefright/mpeg2ts/ATSParser.h
@@ -38,7 +38,16 @@ struct ATSParser : public RefBase {
DISCONTINUITY_FORMATCHANGE
};
- ATSParser();
+ enum Flags {
+ // The 90kHz clock (PTS/DTS) is absolute, i.e. PTS=0 corresponds to
+ // a media time of 0.
+ // If this flag is _not_ specified, the first PTS encountered in a
+ // program of this stream will be assumed to correspond to media time 0
+ // instead.
+ TS_TIMESTAMPS_ARE_ABSOLUTE = 1
+ };
+
+ ATSParser(uint32_t flags = 0);
void feedTSPacket(const void *data, size_t size);
@@ -73,6 +82,7 @@ private:
struct Program;
struct Stream;
+ uint32_t mFlags;
Vector<sp<Program> > mPrograms;
void parseProgramAssociationTable(ABitReader *br);