diff options
author | Andreas Huber <andih@google.com> | 2010-06-07 15:19:40 -0700 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2010-06-07 15:34:45 -0700 |
commit | cf7b9c7aae758ac0b99833915053c63c2ac46e09 (patch) | |
tree | 2480a2da149f7ba8fe651876a6173947ec8c6a16 /media/libstagefright/rtsp/AMPEG4AudioAssembler.cpp | |
parent | e71d10e7ad55ccbcb0756c007caef1c959090384 (diff) | |
download | frameworks_av-cf7b9c7aae758ac0b99833915053c63c2ac46e09.zip frameworks_av-cf7b9c7aae758ac0b99833915053c63c2ac46e09.tar.gz frameworks_av-cf7b9c7aae758ac0b99833915053c63c2ac46e09.tar.bz2 |
Initial checkin of preliminary rtsp support for stagefright.
Change-Id: I0722aa888098c0c1361c97a4c1b123d910afc207
Diffstat (limited to 'media/libstagefright/rtsp/AMPEG4AudioAssembler.cpp')
-rw-r--r-- | media/libstagefright/rtsp/AMPEG4AudioAssembler.cpp | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/media/libstagefright/rtsp/AMPEG4AudioAssembler.cpp b/media/libstagefright/rtsp/AMPEG4AudioAssembler.cpp new file mode 100644 index 0000000..0549d84 --- /dev/null +++ b/media/libstagefright/rtsp/AMPEG4AudioAssembler.cpp @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AMPEG4AudioAssembler.h" + +#include "ARTPSource.h" + +#include <media/stagefright/foundation/ABuffer.h> +#include <media/stagefright/foundation/ADebug.h> +#include <media/stagefright/foundation/AMessage.h> + +namespace android { + +AMPEG4AudioAssembler::AMPEG4AudioAssembler(const sp<AMessage> ¬ify) + : mNotifyMsg(notify), + mAccessUnitRTPTime(0), + mNextExpectedSeqNoValid(false), + mNextExpectedSeqNo(0), + mAccessUnitDamaged(false) { +} + +AMPEG4AudioAssembler::~AMPEG4AudioAssembler() { +} + +ARTPAssembler::AssemblyStatus AMPEG4AudioAssembler::assembleMore( + const sp<ARTPSource> &source) { + AssemblyStatus status = addPacket(source); + if (status == MALFORMED_PACKET) { + mAccessUnitDamaged = true; + } + return status; +} + +ARTPAssembler::AssemblyStatus AMPEG4AudioAssembler::addPacket( + const sp<ARTPSource> &source) { + List<sp<ABuffer> > *queue = source->queue(); + + if (queue->empty()) { + return NOT_ENOUGH_DATA; + } + + if (mNextExpectedSeqNoValid) { + List<sp<ABuffer> >::iterator it = queue->begin(); + while (it != queue->end()) { + if ((uint32_t)(*it)->int32Data() >= mNextExpectedSeqNo) { + break; + } + + it = queue->erase(it); + } + + if (queue->empty()) { + return NOT_ENOUGH_DATA; + } + } + + sp<ABuffer> buffer = *queue->begin(); + + if (!mNextExpectedSeqNoValid) { + mNextExpectedSeqNoValid = true; + mNextExpectedSeqNo = (uint32_t)buffer->int32Data(); + } else if ((uint32_t)buffer->int32Data() != mNextExpectedSeqNo) { +#if VERBOSE + LOG(VERBOSE) << "Not the sequence number I expected"; +#endif + + return WRONG_SEQUENCE_NUMBER; + } + + uint32_t rtpTime; + CHECK(buffer->meta()->findInt32("rtp-time", (int32_t *)&rtpTime)); + + if (mPackets.size() > 0 && rtpTime != mAccessUnitRTPTime) { + submitAccessUnit(); + } + mAccessUnitRTPTime = rtpTime; + + mPackets.push_back(buffer); + + queue->erase(queue->begin()); + ++mNextExpectedSeqNo; + + return OK; +} + +void AMPEG4AudioAssembler::submitAccessUnit() { + CHECK(!mPackets.empty()); + +#if VERBOSE + LOG(VERBOSE) << "Access unit complete (" << mPackets.size() << " packets)"; +#endif + + uint64_t ntpTime; + CHECK((*mPackets.begin())->meta()->findInt64( + "ntp-time", (int64_t *)&ntpTime)); + + size_t totalSize = 0; + List<sp<ABuffer> >::iterator it = mPackets.begin(); + while (it != mPackets.end()) { + const sp<ABuffer> &unit = *it; + + size_t n = 0; + while (unit->data()[n] == 0xff) { + ++n; + } + ++n; + + totalSize += unit->size() - n; + ++it; + } + + sp<ABuffer> accessUnit = new ABuffer(totalSize); + size_t offset = 0; + it = mPackets.begin(); + while (it != mPackets.end()) { + const sp<ABuffer> &unit = *it; + + size_t n = 0; + while (unit->data()[n] == 0xff) { + ++n; + } + ++n; + + memcpy((uint8_t *)accessUnit->data() + offset, + unit->data() + n, unit->size() - n); + + offset += unit->size() - n; + + ++it; + } + + accessUnit->meta()->setInt64("ntp-time", ntpTime); + + if (mAccessUnitDamaged) { + accessUnit->meta()->setInt32("damaged", true); + } + + mPackets.clear(); + mAccessUnitDamaged = false; + + sp<AMessage> msg = mNotifyMsg->dup(); + msg->setObject("access-unit", accessUnit); + msg->post(); +} + +void AMPEG4AudioAssembler::packetLost() { + CHECK(mNextExpectedSeqNoValid); + ++mNextExpectedSeqNo; + + mAccessUnitDamaged = true; +} + +} // namespace android |