Loading media/libmediaplayerservice/nuplayer/NuPlayerDrm.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -191,8 +191,8 @@ NuPlayerDrm::CryptoInfo *NuPlayerDrm::makeCryptoInfo( uint8_t key[kBlockSize], uint8_t iv[kBlockSize], CryptoPlugin::Mode mode, size_t *clearbytes, size_t *encryptedbytes) uint32_t *clearbytes, uint32_t *encryptedbytes) { // size needed to store all the crypto data size_t cryptosize; Loading Loading @@ -236,7 +236,7 @@ NuPlayerDrm::CryptoInfo *NuPlayerDrm::getSampleCryptoInfo(MetaDataBase &meta) if (!meta.findData(kKeyEncryptedSizes, &type, &crypteddata, &cryptedsize)) { return NULL; } size_t numSubSamples = cryptedsize / sizeof(size_t); size_t numSubSamples = cryptedsize / sizeof(uint32_t); if (numSubSamples <= 0) { ALOGE("getSampleCryptoInfo INVALID numSubSamples: %zu", numSubSamples); Loading Loading @@ -285,8 +285,8 @@ NuPlayerDrm::CryptoInfo *NuPlayerDrm::getSampleCryptoInfo(MetaDataBase &meta) (uint8_t*) key, (uint8_t*) iv, (CryptoPlugin::Mode)mode, (size_t*) cleardata, (size_t*) crypteddata); (uint32_t*) cleardata, (uint32_t*) crypteddata); } } // namespace android Loading media/libmediaplayerservice/nuplayer/include/nuplayer/NuPlayerDrm.h +2 −2 Original line number Diff line number Diff line Loading @@ -106,8 +106,8 @@ namespace android { uint8_t key[kBlockSize], uint8_t iv[kBlockSize], CryptoPlugin::Mode mode, size_t *clearbytes, size_t *encryptedbytes); uint32_t *clearbytes, uint32_t *encryptedbytes); static CryptoInfo *getSampleCryptoInfo(MetaDataBase &meta); Loading media/ndk/NdkMediaCodec.cpp +52 −19 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ #include <charconv> #include <inttypes.h> #include <mutex> #include <set> Loading Loading @@ -324,29 +325,61 @@ void CodecHandler::onMessageReceived(const sp<AMessage> &msg) { } AMessage::Type type; int64_t mediaTimeUs, systemNano; size_t index = 0; // TODO. This code has dependency with MediaCodec::CreateFramesRenderedMessage. for (size_t ix = 0; ix < data->countEntries(); ix++) { AString name = data->getEntryNameAt(ix, &type); if (name.startsWith(AStringPrintf("%zu-media-time-us", index).c_str())) { AMessage::ItemData data = msg->getEntryAt(index); data.find(&mediaTimeUs); } else if (name.startsWith(AStringPrintf("%zu-system-nano", index).c_str())) { AMessage::ItemData data = msg->getEntryAt(index); data.find(&systemNano); size_t n = data->countEntries(); thread_local std::vector<std::optional<int64_t>> mediaTimesInUs; thread_local std::vector<std::optional<int64_t>> systemTimesInNs; mediaTimesInUs.resize(n); systemTimesInNs.resize(n); std::fill_n(mediaTimesInUs.begin(), n, std::nullopt); std::fill_n(systemTimesInNs.begin(), n, std::nullopt); for (size_t i = 0; i < n; i++) { AString name = data->getEntryNameAt(i, &type); if (name.endsWith("-media-time-us")) { int64_t mediaTimeUs; AMessage::ItemData itemData = data->getEntryAt(i); itemData.find(&mediaTimeUs); int index = -1; std::from_chars_result result = std::from_chars( name.c_str(), name.c_str() + name.find("-"), index); if (result.ec == std::errc() && 0 <= index && index < n) { mediaTimesInUs[index] = mediaTimeUs; } else { std::error_code ec = std::make_error_code(result.ec); ALOGE("Unexpected media time index: #%d with value %lldus (err=%d %s)", index, (long long)mediaTimeUs, ec.value(), ec.message().c_str()); } } else if (name.endsWith("-system-nano")) { int64_t systemNano; AMessage::ItemData itemData = data->getEntryAt(i); itemData.find(&systemNano); int index = -1; std::from_chars_result result = std::from_chars( name.c_str(), name.c_str() + name.find("-"), index); if (result.ec == std::errc() && 0 <= index && index < n) { systemTimesInNs[index] = systemNano; } else { std::error_code ec = std::make_error_code(result.ec); ALOGE("Unexpected system time index: #%d with value %lldns (err=%d %s)", index, (long long)systemNano, ec.value(), ec.message().c_str()); } } } Mutex::Autolock _l(mCodec->mFrameRenderedCallbackLock); if (mCodec->mFrameRenderedCallback != NULL) { for (size_t i = 0; i < n; ++i) { if (mediaTimesInUs[i] && systemTimesInNs[i]) { mCodec->mFrameRenderedCallback( mCodec, mCodec->mFrameRenderedCallbackUserData, mediaTimeUs, systemNano); mediaTimesInUs[i].value(), systemTimesInNs[i].value()); } else { break; } index++; } } break; Loading services/audioflinger/Threads.h +2 −1 Original line number Diff line number Diff line Loading @@ -1172,7 +1172,7 @@ protected: volatile int32_t mSuspended; int64_t mBytesWritten; int64_t mFramesWritten; // not reset on standby std::atomic<int64_t> mFramesWritten; // not reset on standby int64_t mLastFramesWritten = -1; // track changes in timestamp // server frames written. int64_t mSuspendedFrames; // not reset on standby Loading Loading @@ -1386,6 +1386,7 @@ public: virtual bool hasFastMixer() const = 0; virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex __unused) const { FastTrackUnderruns dummy; return dummy; } const std::atomic<int64_t>& framesWritten() const { return mFramesWritten; } protected: // accessed by both binder threads and within threadLoop(), lock on mutex needed Loading services/audioflinger/Tracks.cpp +13 −3 Original line number Diff line number Diff line Loading @@ -1094,12 +1094,22 @@ status_t AudioFlinger::PlaybackThread::Track::start(AudioSystem::sync_event_t ev __func__, mId, (int)mThreadIoHandle); } // states to reset position info for non-offloaded/direct tracks if (!isOffloaded() && !isDirect() PlaybackThread *playbackThread = (PlaybackThread *)thread.get(); // states to reset position info for pcm tracks if (audio_is_linear_pcm(mFormat) && (state == IDLE || state == STOPPED || state == FLUSHED)) { mFrameMap.reset(); if (!isFastTrack() && (isDirect() || isOffloaded())) { // Start point of track -> sink frame map. If the HAL returns a // frame position smaller than the first written frame in // updateTrackFrameInfo, the timestamp can be interpolated // instead of using a larger value. mFrameMap.push(mAudioTrackServerProxy->framesReleased(), playbackThread->framesWritten()); } } PlaybackThread *playbackThread = (PlaybackThread *)thread.get(); if (isFastTrack()) { // refresh fast track underruns on start because that field is never cleared // by the fast mixer; furthermore, the same track can be recycled, i.e. start Loading Loading
media/libmediaplayerservice/nuplayer/NuPlayerDrm.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -191,8 +191,8 @@ NuPlayerDrm::CryptoInfo *NuPlayerDrm::makeCryptoInfo( uint8_t key[kBlockSize], uint8_t iv[kBlockSize], CryptoPlugin::Mode mode, size_t *clearbytes, size_t *encryptedbytes) uint32_t *clearbytes, uint32_t *encryptedbytes) { // size needed to store all the crypto data size_t cryptosize; Loading Loading @@ -236,7 +236,7 @@ NuPlayerDrm::CryptoInfo *NuPlayerDrm::getSampleCryptoInfo(MetaDataBase &meta) if (!meta.findData(kKeyEncryptedSizes, &type, &crypteddata, &cryptedsize)) { return NULL; } size_t numSubSamples = cryptedsize / sizeof(size_t); size_t numSubSamples = cryptedsize / sizeof(uint32_t); if (numSubSamples <= 0) { ALOGE("getSampleCryptoInfo INVALID numSubSamples: %zu", numSubSamples); Loading Loading @@ -285,8 +285,8 @@ NuPlayerDrm::CryptoInfo *NuPlayerDrm::getSampleCryptoInfo(MetaDataBase &meta) (uint8_t*) key, (uint8_t*) iv, (CryptoPlugin::Mode)mode, (size_t*) cleardata, (size_t*) crypteddata); (uint32_t*) cleardata, (uint32_t*) crypteddata); } } // namespace android Loading
media/libmediaplayerservice/nuplayer/include/nuplayer/NuPlayerDrm.h +2 −2 Original line number Diff line number Diff line Loading @@ -106,8 +106,8 @@ namespace android { uint8_t key[kBlockSize], uint8_t iv[kBlockSize], CryptoPlugin::Mode mode, size_t *clearbytes, size_t *encryptedbytes); uint32_t *clearbytes, uint32_t *encryptedbytes); static CryptoInfo *getSampleCryptoInfo(MetaDataBase &meta); Loading
media/ndk/NdkMediaCodec.cpp +52 −19 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ #include <charconv> #include <inttypes.h> #include <mutex> #include <set> Loading Loading @@ -324,29 +325,61 @@ void CodecHandler::onMessageReceived(const sp<AMessage> &msg) { } AMessage::Type type; int64_t mediaTimeUs, systemNano; size_t index = 0; // TODO. This code has dependency with MediaCodec::CreateFramesRenderedMessage. for (size_t ix = 0; ix < data->countEntries(); ix++) { AString name = data->getEntryNameAt(ix, &type); if (name.startsWith(AStringPrintf("%zu-media-time-us", index).c_str())) { AMessage::ItemData data = msg->getEntryAt(index); data.find(&mediaTimeUs); } else if (name.startsWith(AStringPrintf("%zu-system-nano", index).c_str())) { AMessage::ItemData data = msg->getEntryAt(index); data.find(&systemNano); size_t n = data->countEntries(); thread_local std::vector<std::optional<int64_t>> mediaTimesInUs; thread_local std::vector<std::optional<int64_t>> systemTimesInNs; mediaTimesInUs.resize(n); systemTimesInNs.resize(n); std::fill_n(mediaTimesInUs.begin(), n, std::nullopt); std::fill_n(systemTimesInNs.begin(), n, std::nullopt); for (size_t i = 0; i < n; i++) { AString name = data->getEntryNameAt(i, &type); if (name.endsWith("-media-time-us")) { int64_t mediaTimeUs; AMessage::ItemData itemData = data->getEntryAt(i); itemData.find(&mediaTimeUs); int index = -1; std::from_chars_result result = std::from_chars( name.c_str(), name.c_str() + name.find("-"), index); if (result.ec == std::errc() && 0 <= index && index < n) { mediaTimesInUs[index] = mediaTimeUs; } else { std::error_code ec = std::make_error_code(result.ec); ALOGE("Unexpected media time index: #%d with value %lldus (err=%d %s)", index, (long long)mediaTimeUs, ec.value(), ec.message().c_str()); } } else if (name.endsWith("-system-nano")) { int64_t systemNano; AMessage::ItemData itemData = data->getEntryAt(i); itemData.find(&systemNano); int index = -1; std::from_chars_result result = std::from_chars( name.c_str(), name.c_str() + name.find("-"), index); if (result.ec == std::errc() && 0 <= index && index < n) { systemTimesInNs[index] = systemNano; } else { std::error_code ec = std::make_error_code(result.ec); ALOGE("Unexpected system time index: #%d with value %lldns (err=%d %s)", index, (long long)systemNano, ec.value(), ec.message().c_str()); } } } Mutex::Autolock _l(mCodec->mFrameRenderedCallbackLock); if (mCodec->mFrameRenderedCallback != NULL) { for (size_t i = 0; i < n; ++i) { if (mediaTimesInUs[i] && systemTimesInNs[i]) { mCodec->mFrameRenderedCallback( mCodec, mCodec->mFrameRenderedCallbackUserData, mediaTimeUs, systemNano); mediaTimesInUs[i].value(), systemTimesInNs[i].value()); } else { break; } index++; } } break; Loading
services/audioflinger/Threads.h +2 −1 Original line number Diff line number Diff line Loading @@ -1172,7 +1172,7 @@ protected: volatile int32_t mSuspended; int64_t mBytesWritten; int64_t mFramesWritten; // not reset on standby std::atomic<int64_t> mFramesWritten; // not reset on standby int64_t mLastFramesWritten = -1; // track changes in timestamp // server frames written. int64_t mSuspendedFrames; // not reset on standby Loading Loading @@ -1386,6 +1386,7 @@ public: virtual bool hasFastMixer() const = 0; virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex __unused) const { FastTrackUnderruns dummy; return dummy; } const std::atomic<int64_t>& framesWritten() const { return mFramesWritten; } protected: // accessed by both binder threads and within threadLoop(), lock on mutex needed Loading
services/audioflinger/Tracks.cpp +13 −3 Original line number Diff line number Diff line Loading @@ -1094,12 +1094,22 @@ status_t AudioFlinger::PlaybackThread::Track::start(AudioSystem::sync_event_t ev __func__, mId, (int)mThreadIoHandle); } // states to reset position info for non-offloaded/direct tracks if (!isOffloaded() && !isDirect() PlaybackThread *playbackThread = (PlaybackThread *)thread.get(); // states to reset position info for pcm tracks if (audio_is_linear_pcm(mFormat) && (state == IDLE || state == STOPPED || state == FLUSHED)) { mFrameMap.reset(); if (!isFastTrack() && (isDirect() || isOffloaded())) { // Start point of track -> sink frame map. If the HAL returns a // frame position smaller than the first written frame in // updateTrackFrameInfo, the timestamp can be interpolated // instead of using a larger value. mFrameMap.push(mAudioTrackServerProxy->framesReleased(), playbackThread->framesWritten()); } } PlaybackThread *playbackThread = (PlaybackThread *)thread.get(); if (isFastTrack()) { // refresh fast track underruns on start because that field is never cleared // by the fast mixer; furthermore, the same track can be recycled, i.e. start Loading