Merge "codec2: set input buffer to nullptr when work is done" into pi-dev
diff --git a/C2VDAAdaptorProxy.cpp b/C2VDAAdaptorProxy.cpp
index e9cc826..2c44e6b 100644
--- a/C2VDAAdaptorProxy.cpp
+++ b/C2VDAAdaptorProxy.cpp
@@ -56,14 +56,14 @@
 
 bool C2VDAAdaptorProxy::establishChannel() {
     ALOGV("establishChannel");
-    ::arc::Future<bool> future(mRelay);
+    auto future = ::arc::Future<bool>::make_shared(mRelay);
     mMojoTaskRunner->PostTask(FROM_HERE,
                               base::Bind(&C2VDAAdaptorProxy::establishChannelOnMojoThread,
-                                         base::Unretained(this), base::Unretained(&future)));
-    return future.wait() && future.get();
+                                         base::Unretained(this), future));
+    return future->wait() && future->get();
 }
 
-void C2VDAAdaptorProxy::establishChannelOnMojoThread(::arc::Future<bool>* future) {
+void C2VDAAdaptorProxy::establishChannelOnMojoThread(std::shared_ptr<::arc::Future<bool>> future) {
     C2ArcVideoAcceleratorFactory& factory = ::android::C2ArcVideoAcceleratorFactory::getInstance();
 
     if (!factory.createVideoDecodeAccelerator(mojo::MakeRequest(&mVDAPtr))) {
@@ -74,10 +74,10 @@
                                                     base::Unretained(this),
                                                     std::string("mVDAPtr (vda pipe)")));
     mVDAPtr.QueryVersion(base::Bind(&C2VDAAdaptorProxy::onVersionReady, base::Unretained(this),
-                                    base::Unretained(future)));
+                                    std::move(future)));
 }
 
-void C2VDAAdaptorProxy::onVersionReady(::arc::Future<bool>* future, uint32_t version) {
+void C2VDAAdaptorProxy::onVersionReady(std::shared_ptr<::arc::Future<bool>> future, uint32_t version) {
     ALOGI("VideoDecodeAccelerator ready (version=%d)", version);
 
     future->set(true);
@@ -202,16 +202,16 @@
         return VideoDecodeAcceleratorAdaptor::PLATFORM_FAILURE;
     }
 
-    ::arc::Future<::arc::mojom::VideoDecodeAccelerator::Result> future(mRelay);
+    auto future = ::arc::Future<::arc::mojom::VideoDecodeAccelerator::Result>::make_shared(mRelay);
     mMojoTaskRunner->PostTask(FROM_HERE, base::Bind(&C2VDAAdaptorProxy::initializeOnMojoThread,
                                                     base::Unretained(this), profile, secureMode,
-                                                    ::arc::FutureCallback(&future)));
+                                                    ::arc::FutureCallback(future)));
 
-    if (!future.wait()) {
+    if (!future->wait()) {
         ALOGE("Connection lost");
         return VideoDecodeAcceleratorAdaptor::PLATFORM_FAILURE;
     }
-    return static_cast<VideoDecodeAcceleratorAdaptor::Result>(future.get());
+    return static_cast<VideoDecodeAcceleratorAdaptor::Result>(future->get());
 }
 
 void C2VDAAdaptorProxy::initializeOnMojoThread(
diff --git a/cmds/Android.mk b/cmds/Android.mk
index aca5706..642c9e1 100644
--- a/cmds/Android.mk
+++ b/cmds/Android.mk
@@ -31,6 +31,7 @@
                           libutils \
                           libv4l2_codec2 \
                           libv4l2_codec2_vda \
+                          android.hardware.media.bufferpool@1.0 \
 
 # -Wno-unused-parameter is needed for libchrome/base codes
 LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter
diff --git a/include/C2VDAAdaptorProxy.h b/include/C2VDAAdaptorProxy.h
index 4f6075b..fbfe009 100644
--- a/include/C2VDAAdaptorProxy.h
+++ b/include/C2VDAAdaptorProxy.h
@@ -5,6 +5,8 @@
 #ifndef ANDROID_C2_VDA_ADAPTOR_PROXY_H
 #define ANDROID_C2_VDA_ADAPTOR_PROXY_H
 
+#include <memory>
+
 #include <VideoDecodeAcceleratorAdaptor.h>
 
 #include <video_decode_accelerator.h>
@@ -61,8 +63,8 @@
 
 private:
     void onConnectionError(const std::string& pipeName);
-    void establishChannelOnMojoThread(::arc::Future<bool>* future);
-    void onVersionReady(::arc::Future<bool>* future, uint32_t version);
+    void establishChannelOnMojoThread(std::shared_ptr<::arc::Future<bool>> future);
+    void onVersionReady(std::shared_ptr<::arc::Future<bool>> future, uint32_t version);
 
     // Closes ipc channel for video acceleration.
     // This must be called before deleting this object.
diff --git a/include/C2VDAComponent.h b/include/C2VDAComponent.h
index e99b3f4..605c57b 100644
--- a/include/C2VDAComponent.h
+++ b/include/C2VDAComponent.h
@@ -13,7 +13,10 @@
 #include <video_decode_accelerator.h>
 
 #include <C2Component.h>
+#include <C2Config.h>
+#include <C2Enum.h>
 #include <C2Param.h>
+#include <C2ParamDef.h>
 
 #include <base/macros.h>
 #include <base/memory/ref_counted.h>
@@ -30,13 +33,16 @@
 
 namespace android {
 
-C2ENUM(ColorFormat, uint32_t,  // enum for output color format
-       kColorFormatYUV420Flexible = 0x7F420888, )
+enum ColorFormat : uint32_t;
+
+namespace {
 
 enum C2VDAParamIndexKind : C2Param::type_index_t {
-    kParamIndexVDAProfile = kParamIndexParamStart + 1,
+    kParamIndexVDAProfile = C2Param::TYPE_INDEX_VENDOR_START,
 };
 
+}
+
 // Codec profile for VDA VideoCodecProfile (see vda/video_codecs.h) [IN]
 // Note: this does not equal to AVC profile index
 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexVDAProfile> C2VDAStreamProfileConfig;
@@ -340,4 +346,7 @@
 
 }  // namespace android
 
+C2ENUM(android::ColorFormat, uint32_t,  // enum for output color format
+       kColorFormatYUV420Flexible = 0x7F420888, )
+
 #endif  // ANDROID_C2_VDA_COMPONENT_H
diff --git a/tests/Android.mk b/tests/Android.mk
index 99d1d0a..ba22580 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -53,6 +53,7 @@
   libutils \
   libv4l2_codec2 \
   libv4l2_codec2_vda \
+  android.hardware.media.bufferpool@1.0 \
 
 LOCAL_C_INCLUDES += \
   $(TOP)/external/libchrome \
diff --git a/vndk/Android.mk b/vndk/Android.mk
index 0863989..77a06b5 100644
--- a/vndk/Android.mk
+++ b/vndk/Android.mk
@@ -35,6 +35,7 @@
                           libstagefright_foundation \
                           libui \
                           libutils \
+                          android.hardware.media.bufferpool@1.0 \
 
 LOCAL_CFLAGS += -Werror -Wall -std=c++14
 LOCAL_CLANG := true