Home | History | Annotate | Download | only in include
      1 // Copyright 2017 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef ANDROID_C2_VDA_ADAPTOR_PROXY_H
      6 #define ANDROID_C2_VDA_ADAPTOR_PROXY_H
      7 
      8 #include <memory>
      9 
     10 #include <VideoDecodeAcceleratorAdaptor.h>
     11 
     12 #include <video_decode_accelerator.h>
     13 
     14 #include <arc/Future.h>
     15 #include <mojo/public/cpp/bindings/binding.h>
     16 
     17 #include <components/arc/common/video.mojom.h>
     18 #include <components/arc/common/video_decode_accelerator.mojom.h>
     19 
     20 namespace arc {
     21 class MojoProcessSupport;
     22 }  // namespace arc
     23 
     24 namespace android {
     25 namespace arc {
     26 class C2VDAAdaptorProxy : public VideoDecodeAcceleratorAdaptor,
     27                           public ::arc::mojom::VideoDecodeClient {
     28 public:
     29     C2VDAAdaptorProxy();
     30     explicit C2VDAAdaptorProxy(::arc::MojoProcessSupport* MojomProcessSupport);
     31     ~C2VDAAdaptorProxy() override;
     32 
     33     // Establishes ipc channel for video acceleration. Returns true if channel
     34     // connected successfully.
     35     // This must be called before all other methods.
     36     bool establishChannel();
     37 
     38     // Implementation of the VideoDecodeAcceleratorAdaptor interface.
     39     Result initialize(media::VideoCodecProfile profile, bool secureMode,
     40                       VideoDecodeAcceleratorAdaptor::Client* client) override;
     41     void decode(int32_t bitstreamId, int handleFd, off_t offset, uint32_t size) override;
     42     void assignPictureBuffers(uint32_t numOutputBuffers) override;
     43     void importBufferForPicture(int32_t pictureBufferId, HalPixelFormat format, int handleFd,
     44                                 const std::vector<VideoFramePlane>& planes) override;
     45     void reusePictureBuffer(int32_t pictureBufferId) override;
     46     void flush() override;
     47     void reset() override;
     48     void destroy() override;
     49 
     50     // ::arc::mojom::VideoDecodeClient implementations.
     51     void ProvidePictureBuffers(::arc::mojom::PictureBufferFormatPtr format) override;
     52     void PictureReady(::arc::mojom::PicturePtr picture) override;
     53     void NotifyEndOfBitstreamBuffer(int32_t bitstream_id) override;
     54     void NotifyError(::arc::mojom::VideoDecodeAccelerator::Result error) override;
     55 
     56     // The following functions are called as callbacks.
     57     void NotifyResetDone(::arc::mojom::VideoDecodeAccelerator::Result result);
     58     void NotifyFlushDone(::arc::mojom::VideoDecodeAccelerator::Result result);
     59 
     60     static media::VideoDecodeAccelerator::SupportedProfiles GetSupportedProfiles(
     61             InputCodec inputCodec);
     62 
     63 private:
     64     void onConnectionError(const std::string& pipeName);
     65     void establishChannelOnMojoThread(std::shared_ptr<::arc::Future<bool>> future);
     66     void onVersionReady(std::shared_ptr<::arc::Future<bool>> future, uint32_t version);
     67 
     68     // Closes ipc channel for video acceleration.
     69     // This must be called before deleting this object.
     70     void closeChannelOnMojoThread();
     71 
     72     // mojo thread corresponding part of C2VDAAdaptorProxy implementations.
     73     void initializeOnMojoThread(const media::VideoCodecProfile profile, const bool mSecureMode,
     74                                 const ::arc::mojom::VideoDecodeAccelerator::InitializeCallback& cb);
     75     void decodeOnMojoThread(int32_t bitstreamId, int ashmemFd, off_t offset, uint32_t bytesUsed);
     76     void assignPictureBuffersOnMojoThread(uint32_t numOutputBuffers);
     77 
     78     void importBufferForPictureOnMojoThread(int32_t pictureBufferId, HalPixelFormat format,
     79                                             int handleFd,
     80                                             const std::vector<VideoFramePlane>& planes);
     81     void reusePictureBufferOnMojoThread(int32_t pictureBufferId);
     82     void flushOnMojoThread();
     83     void resetOnMojoThread();
     84 
     85     VideoDecodeAcceleratorAdaptor::Client* mClient;
     86 
     87     // Task runner for mojom functions.
     88     const scoped_refptr<::base::SingleThreadTaskRunner> mMojoTaskRunner;
     89 
     90     // |mVDAPtr| and |mBinding| should only be called on |mMojoTaskRunner| after bound.
     91     ::arc::mojom::VideoDecodeAcceleratorPtr mVDAPtr;
     92     mojo::Binding<::arc::mojom::VideoDecodeClient> mBinding;
     93 
     94     // Used to cancel the wait on arc::Future.
     95     sp<::arc::CancellationRelay> mRelay;
     96 
     97     DISALLOW_COPY_AND_ASSIGN(C2VDAAdaptorProxy);
     98 };
     99 }  // namespace arc
    100 }  // namespace android
    101 
    102 #endif  // ANDROID_C2_VDA_ADAPTOR_PROXY_H
    103