AIDL BufferPool implementation (HIDL -> AIDL)

Bug: 254050250
Test: m
Merged-In: I0d7bae2c01bd480d1e99f4b39c4a9013a2828897
Change-Id: I0d7bae2c01bd480d1e99f4b39c4a9013a2828897
diff --git a/media/bufferpool/aidl/default/ClientManager.cpp b/media/bufferpool/aidl/default/ClientManager.cpp
index 54a20b9..de1db50 100644
--- a/media/bufferpool/aidl/default/ClientManager.cpp
+++ b/media/bufferpool/aidl/default/ClientManager.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -13,122 +13,74 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#define LOG_TAG "BufferPoolManager"
+#define LOG_TAG "AidlBufferPoolMgr"
 //#define LOG_NDEBUG 0
 
-#include <bufferpool/ClientManager.h>
-#include <hidl/HidlTransportSupport.h>
+#include <aidl/android/hardware/media/bufferpool2/ResultStatus.h>
+#include <bufferpool2/ClientManager.h>
+
 #include <sys/types.h>
-#include <time.h>
+#include <utils/SystemClock.h>
 #include <unistd.h>
 #include <utils/Log.h>
+
+#include <chrono>
+
 #include "BufferPoolClient.h"
 #include "Observer.h"
 #include "Accessor.h"
 
-namespace android {
-namespace hardware {
-namespace media {
-namespace bufferpool {
-namespace V2_0 {
-namespace implementation {
+namespace aidl::android::hardware::media::bufferpool2::implementation {
 
-static constexpr int64_t kRegisterTimeoutUs = 500000; // 0.5 sec
-static constexpr int64_t kCleanUpDurationUs = 1000000; // TODO: 1 sec tune
-static constexpr int64_t kClientTimeoutUs = 5000000; // TODO: 5 secs tune
+using namespace std::chrono_literals;
 
-/**
- * The holder of the cookie of remote IClientManager.
- * The cookie is process locally unique for each IClientManager.
- * (The cookie is used to notify death of clients to bufferpool process.)
- */
-class ClientManagerCookieHolder {
-public:
-    /**
-     * Creates a cookie holder for remote IClientManager(s).
-     */
-    ClientManagerCookieHolder();
+using Registration = aidl::android::hardware::media::bufferpool2::IClientManager::Registration;
+using aidl::android::hardware::media::bufferpool2::ResultStatus;
 
-    /**
-     * Gets a cookie for a remote IClientManager.
-     *
-     * @param manager   the specified remote IClientManager.
-     * @param added     true when the specified remote IClientManager is added
-     *                  newly, false otherwise.
-     *
-     * @return the process locally unique cookie for the specified IClientManager.
-     */
-    uint64_t getCookie(const sp<IClientManager> &manager, bool *added);
-
-private:
-    uint64_t mSeqId;
-    std::mutex mLock;
-    std::list<std::pair<const wp<IClientManager>, uint64_t>> mManagers;
-};
-
-ClientManagerCookieHolder::ClientManagerCookieHolder() : mSeqId(0){}
-
-uint64_t ClientManagerCookieHolder::getCookie(
-        const sp<IClientManager> &manager,
-        bool *added) {
-    std::lock_guard<std::mutex> lock(mLock);
-    for (auto it = mManagers.begin(); it != mManagers.end();) {
-        const sp<IClientManager> key = it->first.promote();
-        if (key) {
-            if (interfacesEqual(key, manager)) {
-                *added = false;
-                return it->second;
-            }
-            ++it;
-        } else {
-            it = mManagers.erase(it);
-        }
-    }
-    uint64_t id = mSeqId++;
-    *added = true;
-    mManagers.push_back(std::make_pair(manager, id));
-    return id;
-}
+static constexpr int64_t kRegisterTimeoutMs = 500; // 0.5 sec
+static constexpr int64_t kCleanUpDurationMs = 1000; // TODO: 1 sec tune
+static constexpr int64_t kClientTimeoutMs = 5000; // TODO: 5 secs tune
 
 class ClientManager::Impl {
 public:
     Impl();
 
     // BnRegisterSender
-    ResultStatus registerSender(const sp<IAccessor> &accessor,
-                                ConnectionId *pConnectionId);
+    BufferPoolStatus registerSender(const std::shared_ptr<IAccessor> &accessor,
+                                Registration *pRegistration);
 
     // BpRegisterSender
-    ResultStatus registerSender(const sp<IClientManager> &receiver,
+    BufferPoolStatus registerSender(const std::shared_ptr<IClientManager> &receiver,
                                 ConnectionId senderId,
-                                ConnectionId *receiverId);
+                                ConnectionId *receiverId,
+                                bool *isNew);
 
-    ResultStatus create(const std::shared_ptr<BufferPoolAllocator> &allocator,
+    BufferPoolStatus create(const std::shared_ptr<BufferPoolAllocator> &allocator,
                         ConnectionId *pConnectionId);
 
-    ResultStatus close(ConnectionId connectionId);
+    BufferPoolStatus close(ConnectionId connectionId);
 
-    ResultStatus flush(ConnectionId connectionId);
+    BufferPoolStatus flush(ConnectionId connectionId);
 
-    ResultStatus allocate(ConnectionId connectionId,
+    BufferPoolStatus allocate(ConnectionId connectionId,
                           const std::vector<uint8_t> &params,
                           native_handle_t **handle,
                           std::shared_ptr<BufferPoolData> *buffer);
 
-    ResultStatus receive(ConnectionId connectionId,
+    BufferPoolStatus receive(ConnectionId connectionId,
                          TransactionId transactionId,
                          BufferId bufferId,
-                         int64_t timestampUs,
+                         int64_t timestampMs,
                          native_handle_t **handle,
                          std::shared_ptr<BufferPoolData> *buffer);
 
-    ResultStatus postSend(ConnectionId receiverId,
+    BufferPoolStatus postSend(ConnectionId receiverId,
                           const std::shared_ptr<BufferPoolData> &buffer,
                           TransactionId *transactionId,
-                          int64_t *timestampUs);
+                          int64_t *timestampMs);
 
-    ResultStatus getAccessor(ConnectionId connectionId,
-                             sp<IAccessor> *accessor);
+    BufferPoolStatus getAccessor(ConnectionId connectionId,
+                             std::shared_ptr<IAccessor> *accessor);
 
     void cleanUp(bool clearCache = false);
 
@@ -139,13 +91,13 @@
         // This lock is held for brief duration.
         // Blocking operation is not performed while holding the lock.
         std::mutex mMutex;
-        std::list<std::pair<const wp<IAccessor>, const std::weak_ptr<BufferPoolClient>>>
+        std::list<std::pair<const std::weak_ptr<IAccessor>, const std::weak_ptr<BufferPoolClient>>>
                 mClients;
         std::condition_variable mConnectCv;
         bool mConnecting;
-        int64_t mLastCleanUpUs;
+        int64_t mLastCleanUpMs;
 
-        ClientCache() : mConnecting(false), mLastCleanUpUs(getTimestampNow()) {}
+        ClientCache() : mConnecting(false), mLastCleanUpMs(::android::elapsedRealtime()) {}
     } mCache;
 
     // Active clients which can be retrieved via ConnectionId
@@ -157,30 +109,31 @@
                 mClients;
     } mActive;
 
-    sp<Observer> mObserver;
-
-    ClientManagerCookieHolder mRemoteClientCookies;
+    std::shared_ptr<Observer> mObserver;
 };
 
 ClientManager::Impl::Impl()
-    : mObserver(new Observer()) {}
+    : mObserver(::ndk::SharedRefBase::make<Observer>()) {}
 
-ResultStatus ClientManager::Impl::registerSender(
-        const sp<IAccessor> &accessor, ConnectionId *pConnectionId) {
+BufferPoolStatus ClientManager::Impl::registerSender(
+        const std::shared_ptr<IAccessor> &accessor, Registration *pRegistration) {
     cleanUp();
-    int64_t timeoutUs = getTimestampNow() + kRegisterTimeoutUs;
+    int64_t timeoutMs = ::android::elapsedRealtime() + kRegisterTimeoutMs;
     do {
         std::unique_lock<std::mutex> lock(mCache.mMutex);
         for (auto it = mCache.mClients.begin(); it != mCache.mClients.end(); ++it) {
-            sp<IAccessor> sAccessor = it->first.promote();
-            if (sAccessor && interfacesEqual(sAccessor, accessor)) {
+            std::shared_ptr<IAccessor> sAccessor = it->first.lock();
+            if (sAccessor && sAccessor.get() == accessor.get()) {
                 const std::shared_ptr<BufferPoolClient> client = it->second.lock();
                 if (client) {
                     std::lock_guard<std::mutex> lock(mActive.mMutex);
-                    *pConnectionId = client->getConnectionId();
-                    if (mActive.mClients.find(*pConnectionId) != mActive.mClients.end()) {
-                        ALOGV("register existing connection %lld", (long long)*pConnectionId);
-                        return ResultStatus::ALREADY_EXISTS;
+                    pRegistration->connectionId = client->getConnectionId();
+                    if (mActive.mClients.find(pRegistration->connectionId)
+                            != mActive.mClients.end()) {
+                        ALOGV("register existing connection %lld",
+                              (long long)pRegistration->connectionId);
+                        pRegistration->isNew = false;
+                        return ResultStatus::OK;
                     }
                 }
                 mCache.mClients.erase(it);
@@ -190,7 +143,7 @@
         if (!mCache.mConnecting) {
             mCache.mConnecting = true;
             lock.unlock();
-            ResultStatus result = ResultStatus::OK;
+            BufferPoolStatus result = ResultStatus::OK;
             const std::shared_ptr<BufferPoolClient> client =
                     std::make_shared<BufferPoolClient>(accessor, mObserver);
             lock.lock();
@@ -209,26 +162,27 @@
                     std::lock_guard<std::mutex> lock(mActive.mMutex);
                     mActive.mClients.insert(std::make_pair(conId, client));
                 }
-                *pConnectionId = conId;
-                ALOGV("register new connection %lld", (long long)*pConnectionId);
+                pRegistration->connectionId = conId;
+                pRegistration->isNew = true;
+                ALOGV("register new connection %lld", (long long)conId);
             }
             mCache.mConnecting = false;
             lock.unlock();
             mCache.mConnectCv.notify_all();
             return result;
         }
-        mCache.mConnectCv.wait_for(
-                lock, std::chrono::microseconds(kRegisterTimeoutUs));
-    } while (getTimestampNow() < timeoutUs);
+        mCache.mConnectCv.wait_for(lock, kRegisterTimeoutMs*1ms);
+    } while (::android::elapsedRealtime() < timeoutMs);
     // TODO: return timeout error
     return ResultStatus::CRITICAL_ERROR;
 }
 
-ResultStatus ClientManager::Impl::registerSender(
-        const sp<IClientManager> &receiver,
+BufferPoolStatus ClientManager::Impl::registerSender(
+        const std::shared_ptr<IClientManager> &receiver,
         ConnectionId senderId,
-        ConnectionId *receiverId) {
-    sp<IAccessor> accessor;
+        ConnectionId *receiverId,
+        bool *isNew) {
+    std::shared_ptr<IAccessor> accessor;
     bool local = false;
     {
         std::lock_guard<std::mutex> lock(mActive.mMutex);
@@ -239,38 +193,32 @@
         it->second->getAccessor(&accessor);
         local = it->second->isLocal();
     }
-    ResultStatus rs = ResultStatus::CRITICAL_ERROR;
     if (accessor) {
-       Return<void> transResult = receiver->registerSender(
-                accessor,
-                [&rs, receiverId](
-                        ResultStatus status,
-                        int64_t connectionId) {
-                    rs = status;
-                    *receiverId = connectionId;
-                });
-        if (!transResult.isOk()) {
+        Registration registration;
+        ::ndk::ScopedAStatus status = receiver->registerSender(accessor, &registration);
+        if (!status.isOk()) {
             return ResultStatus::CRITICAL_ERROR;
-        } else if (local && rs == ResultStatus::OK) {
-            sp<ConnectionDeathRecipient> recipient = Accessor::getConnectionDeathRecipient();
+        } else if (local) {
+            std::shared_ptr<ConnectionDeathRecipient> recipient =
+                    Accessor::getConnectionDeathRecipient();
             if (recipient)  {
                 ALOGV("client death recipient registered %lld", (long long)*receiverId);
-                bool added;
-                uint64_t cookie = mRemoteClientCookies.getCookie(receiver, &added);
-                recipient->addCookieToConnection(cookie, *receiverId);
-                if (added) {
-                    Return<bool> transResult = receiver->linkToDeath(recipient, cookie);
-                }
+                recipient->addCookieToConnection(receiver->asBinder().get(), *receiverId);
+                AIBinder_linkToDeath(receiver->asBinder().get(), recipient->getRecipient(),
+                                     receiver->asBinder().get());
             }
         }
+        *receiverId = registration.connectionId;
+        *isNew = registration.isNew;
+        return ResultStatus::OK;
     }
-    return rs;
+    return ResultStatus::CRITICAL_ERROR;
 }
 
-ResultStatus ClientManager::Impl::create(
+BufferPoolStatus ClientManager::Impl::create(
         const std::shared_ptr<BufferPoolAllocator> &allocator,
         ConnectionId *pConnectionId) {
-    const sp<Accessor> accessor = new Accessor(allocator);
+    std::shared_ptr<Accessor> accessor = ::ndk::SharedRefBase::make<Accessor>(allocator);
     if (!accessor || !accessor->isValid()) {
         return ResultStatus::CRITICAL_ERROR;
     }
@@ -300,19 +248,19 @@
     return ResultStatus::OK;
 }
 
-ResultStatus ClientManager::Impl::close(ConnectionId connectionId) {
+BufferPoolStatus ClientManager::Impl::close(ConnectionId connectionId) {
     std::unique_lock<std::mutex> lock1(mCache.mMutex);
     std::unique_lock<std::mutex> lock2(mActive.mMutex);
     auto it = mActive.mClients.find(connectionId);
     if (it != mActive.mClients.end()) {
-        sp<IAccessor> accessor;
+        std::shared_ptr<IAccessor> accessor;
         it->second->getAccessor(&accessor);
         std::shared_ptr<BufferPoolClient> closing = it->second;
         mActive.mClients.erase(connectionId);
         for (auto cit = mCache.mClients.begin(); cit != mCache.mClients.end();) {
             // clean up dead client caches
-            sp<IAccessor> cAccessor = cit->first.promote();
-            if (!cAccessor || (accessor && interfacesEqual(cAccessor, accessor))) {
+            std::shared_ptr<IAccessor> cAccessor = cit->first.lock();
+            if (!cAccessor || (accessor && cAccessor.get() ==  accessor.get())) {
                 cit = mCache.mClients.erase(cit);
             } else {
                 cit++;
@@ -326,7 +274,7 @@
     return ResultStatus::NOT_FOUND;
 }
 
-ResultStatus ClientManager::Impl::flush(ConnectionId connectionId) {
+BufferPoolStatus ClientManager::Impl::flush(ConnectionId connectionId) {
     std::shared_ptr<BufferPoolClient> client;
     {
         std::lock_guard<std::mutex> lock(mActive.mMutex);
@@ -339,7 +287,7 @@
     return client->flush();
 }
 
-ResultStatus ClientManager::Impl::allocate(
+BufferPoolStatus ClientManager::Impl::allocate(
         ConnectionId connectionId, const std::vector<uint8_t> &params,
         native_handle_t **handle, std::shared_ptr<BufferPoolData> *buffer) {
     std::shared_ptr<BufferPoolClient> client;
@@ -353,7 +301,7 @@
     }
 #ifdef BUFFERPOOL_CLONE_HANDLES
     native_handle_t *origHandle;
-    ResultStatus res = client->allocate(params, &origHandle, buffer);
+    BufferPoolStatus res = client->allocate(params, &origHandle, buffer);
     if (res != ResultStatus::OK) {
         return res;
     }
@@ -368,9 +316,9 @@
 #endif
 }
 
-ResultStatus ClientManager::Impl::receive(
+BufferPoolStatus ClientManager::Impl::receive(
         ConnectionId connectionId, TransactionId transactionId,
-        BufferId bufferId, int64_t timestampUs,
+        BufferId bufferId, int64_t timestampMs,
         native_handle_t **handle, std::shared_ptr<BufferPoolData> *buffer) {
     std::shared_ptr<BufferPoolClient> client;
     {
@@ -383,8 +331,8 @@
     }
 #ifdef BUFFERPOOL_CLONE_HANDLES
     native_handle_t *origHandle;
-    ResultStatus res = client->receive(
-            transactionId, bufferId, timestampUs, &origHandle, buffer);
+    BufferPoolStatus res = client->receive(
+            transactionId, bufferId, timestampMs, &origHandle, buffer);
     if (res != ResultStatus::OK) {
         return res;
     }
@@ -395,13 +343,13 @@
     }
     return ResultStatus::OK;
 #else
-    return client->receive(transactionId, bufferId, timestampUs, handle, buffer);
+    return client->receive(transactionId, bufferId, timestampMs, handle, buffer);
 #endif
 }
 
-ResultStatus ClientManager::Impl::postSend(
+BufferPoolStatus ClientManager::Impl::postSend(
         ConnectionId receiverId, const std::shared_ptr<BufferPoolData> &buffer,
-        TransactionId *transactionId, int64_t *timestampUs) {
+        TransactionId *transactionId, int64_t *timestampMs) {
     ConnectionId connectionId = buffer->mConnectionId;
     std::shared_ptr<BufferPoolClient> client;
     {
@@ -412,11 +360,11 @@
         }
         client = it->second;
     }
-    return client->postSend(receiverId, buffer, transactionId, timestampUs);
+    return client->postSend(receiverId, buffer, transactionId, timestampMs);
 }
 
-ResultStatus ClientManager::Impl::getAccessor(
-        ConnectionId connectionId, sp<IAccessor> *accessor) {
+BufferPoolStatus ClientManager::Impl::getAccessor(
+        ConnectionId connectionId, std::shared_ptr<IAccessor> *accessor) {
     std::shared_ptr<BufferPoolClient> client;
     {
         std::lock_guard<std::mutex> lock(mActive.mMutex);
@@ -430,16 +378,16 @@
 }
 
 void ClientManager::Impl::cleanUp(bool clearCache) {
-    int64_t now = getTimestampNow();
-    int64_t lastTransactionUs;
+    int64_t now = ::android::elapsedRealtime();
+    int64_t lastTransactionMs;
     std::lock_guard<std::mutex> lock1(mCache.mMutex);
-    if (clearCache || mCache.mLastCleanUpUs + kCleanUpDurationUs < now) {
+    if (clearCache || mCache.mLastCleanUpMs + kCleanUpDurationMs < now) {
         std::lock_guard<std::mutex> lock2(mActive.mMutex);
         int cleaned = 0;
         for (auto it = mActive.mClients.begin(); it != mActive.mClients.end();) {
-            if (!it->second->isActive(&lastTransactionUs, clearCache)) {
-                if (lastTransactionUs + kClientTimeoutUs < now) {
-                    sp<IAccessor> accessor;
+            if (!it->second->isActive(&lastTransactionMs, clearCache)) {
+                if (lastTransactionMs + kClientTimeoutMs < now) {
+                  std::shared_ptr<IAccessor> accessor;
                     it->second->getAccessor(&accessor);
                     it = mActive.mClients.erase(it);
                     ++cleaned;
@@ -450,7 +398,7 @@
         }
         for (auto cit = mCache.mClients.begin(); cit != mCache.mClients.end();) {
             // clean up dead client caches
-            sp<IAccessor> cAccessor = cit->first.promote();
+          std::shared_ptr<IAccessor> cAccessor = cit->first.lock();
             if (!cAccessor) {
                 cit = mCache.mClients.erase(cit);
             } else {
@@ -458,30 +406,32 @@
             }
         }
         ALOGV("# of cleaned connections: %d", cleaned);
-        mCache.mLastCleanUpUs = now;
+        mCache.mLastCleanUpMs = now;
     }
 }
 
-// Methods from ::android::hardware::media::bufferpool::V2_0::IClientManager follow.
-Return<void> ClientManager::registerSender(const sp<::android::hardware::media::bufferpool::V2_0::IAccessor>& bufferPool, registerSender_cb _hidl_cb) {
+::ndk::ScopedAStatus ClientManager::registerSender(
+        const std::shared_ptr<IAccessor>& in_bufferPool, Registration* _aidl_return) {
+    BufferPoolStatus status = ResultStatus::CRITICAL_ERROR;
     if (mImpl) {
-        ConnectionId connectionId = -1;
-        ResultStatus status = mImpl->registerSender(bufferPool, &connectionId);
-        _hidl_cb(status, connectionId);
-    } else {
-        _hidl_cb(ResultStatus::CRITICAL_ERROR, -1);
+        status = mImpl->registerSender(in_bufferPool, _aidl_return);
     }
-    return Void();
+    if (status != ResultStatus::OK) {
+        return ::ndk::ScopedAStatus::fromServiceSpecificError(status);
+    }
+    return ::ndk::ScopedAStatus::ok();
 }
 
 // Methods for local use.
-sp<ClientManager> ClientManager::sInstance;
+std::shared_ptr<ClientManager> ClientManager::sInstance;
 std::mutex ClientManager::sInstanceLock;
 
-sp<ClientManager> ClientManager::getInstance() {
+std::shared_ptr<ClientManager> ClientManager::getInstance() {
     std::lock_guard<std::mutex> lock(sInstanceLock);
     if (!sInstance) {
-        sInstance = new ClientManager();
+        sInstance = ::ndk::SharedRefBase::make<ClientManager>();
+        // TODO: configure thread count for threadpool properly
+        // after b/261652496 is resolved.
     }
     Accessor::createInvalidator();
     Accessor::createEvictor();
@@ -493,7 +443,7 @@
 ClientManager::~ClientManager() {
 }
 
-ResultStatus ClientManager::create(
+BufferPoolStatus ClientManager::create(
         const std::shared_ptr<BufferPoolAllocator> &allocator,
         ConnectionId *pConnectionId) {
     if (mImpl) {
@@ -502,31 +452,32 @@
     return ResultStatus::CRITICAL_ERROR;
 }
 
-ResultStatus ClientManager::registerSender(
-        const sp<IClientManager> &receiver,
+BufferPoolStatus ClientManager::registerSender(
+        const std::shared_ptr<IClientManager> &receiver,
         ConnectionId senderId,
-        ConnectionId *receiverId) {
+        ConnectionId *receiverId,
+        bool *isNew) {
     if (mImpl) {
-        return mImpl->registerSender(receiver, senderId, receiverId);
+        return mImpl->registerSender(receiver, senderId, receiverId, isNew);
     }
     return ResultStatus::CRITICAL_ERROR;
 }
 
-ResultStatus ClientManager::close(ConnectionId connectionId) {
+BufferPoolStatus ClientManager::close(ConnectionId connectionId) {
     if (mImpl) {
         return mImpl->close(connectionId);
     }
     return ResultStatus::CRITICAL_ERROR;
 }
 
-ResultStatus ClientManager::flush(ConnectionId connectionId) {
+BufferPoolStatus ClientManager::flush(ConnectionId connectionId) {
     if (mImpl) {
         return mImpl->flush(connectionId);
     }
     return ResultStatus::CRITICAL_ERROR;
 }
 
-ResultStatus ClientManager::allocate(
+BufferPoolStatus ClientManager::allocate(
         ConnectionId connectionId, const std::vector<uint8_t> &params,
         native_handle_t **handle, std::shared_ptr<BufferPoolData> *buffer) {
     if (mImpl) {
@@ -535,22 +486,22 @@
     return ResultStatus::CRITICAL_ERROR;
 }
 
-ResultStatus ClientManager::receive(
+BufferPoolStatus ClientManager::receive(
         ConnectionId connectionId, TransactionId transactionId,
-        BufferId bufferId, int64_t timestampUs,
+        BufferId bufferId, int64_t timestampMs,
         native_handle_t **handle, std::shared_ptr<BufferPoolData> *buffer) {
     if (mImpl) {
         return mImpl->receive(connectionId, transactionId, bufferId,
-                              timestampUs, handle, buffer);
+                              timestampMs, handle, buffer);
     }
     return ResultStatus::CRITICAL_ERROR;
 }
 
-ResultStatus ClientManager::postSend(
+BufferPoolStatus ClientManager::postSend(
         ConnectionId receiverId, const std::shared_ptr<BufferPoolData> &buffer,
-        TransactionId *transactionId, int64_t* timestampUs) {
+        TransactionId *transactionId, int64_t* timestampMs) {
     if (mImpl && buffer) {
-        return mImpl->postSend(receiverId, buffer, transactionId, timestampUs);
+        return mImpl->postSend(receiverId, buffer, transactionId, timestampMs);
     }
     return ResultStatus::CRITICAL_ERROR;
 }
@@ -561,9 +512,4 @@
     }
 }
 
-}  // namespace implementation
-}  // namespace V2_0
-}  // namespace bufferpool
-}  // namespace media
-}  // namespace hardware
-}  // namespace android
+}  // namespace ::aidl::android::hardware::media::bufferpool2::implementation