1 /*
2  * Copyright 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MMC_CODEC_CLIENT_CODEC_CLIENT_H_
18 #define MMC_CODEC_CLIENT_CODEC_CLIENT_H_
19 
20 #include <dbus/object_proxy.h>
21 #include <stdint.h>
22 
23 #include <memory>
24 
25 #include "mmc/metrics/mmc_rtt_logger.h"
26 #include "mmc/mmc_interface/mmc_interface.h"
27 #include "mmc/proto/mmc_service.pb.h"
28 
29 namespace mmc {
30 
31 // Implementation of MmcInterface.
32 // CodecClient serves as proxy of MMC codec service.
33 class CodecClient : public MmcInterface {
34  public:
35   // Connects to DBus.
36   explicit CodecClient();
37 
38   // Calls |cleanup|.
39   ~CodecClient();
40 
41   // CodecClient is neither copyable nor movable.
42   CodecClient(const CodecClient&) = delete;
43   CodecClient& operator=(const CodecClient&) = delete;
44 
45   // Calls MMC DBus method |CodecInit| with |CodecInitRequest|, opens the socket
46   // for transcoding.
47   //
48   // Returns:
49   //   Input frame size accepted by the transcoder, if init succeeded.
50   //   Negative errno on error, otherwise.
51   int init(const ConfigParam config) override;
52 
53   // Closes the socket, and calls MMC DBus method |CodecCleanUp|.
54   void cleanup() override;
55 
56   // Transfers PCM data between caller and the MMC codec service.
57   //
58   // Returns:
59   //   Transcoded data length, if transcode succeeded.
60   //   Negative errno on error, otherwise.
61   int transcode(uint8_t* i_buf, int i_len, uint8_t* o_buf, int o_len) override;
62 
63  private:
64   int skt_fd_;
65   dbus::ObjectProxy* codec_manager_;  // Owned by the Bus object.
66   scoped_refptr<dbus::Bus> bus_;
67   std::unique_ptr<MmcRttLogger> record_logger_;
68 };
69 
70 }  // namespace mmc
71 
72 #endif  // MMC_CODEC_CLIENT_CODEC_CLIENT_H_
73