1 /*
2 * Copyright 2018 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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "C2SoftVp8Enc"
19 #include <utils/Log.h>
20 #include <utils/misc.h>
21
22 #include "C2SoftVp8Enc.h"
23
24 namespace android {
25
C2SoftVp8Enc(const char * name,c2_node_id_t id,const std::shared_ptr<IntfImpl> & intfImpl)26 C2SoftVp8Enc::C2SoftVp8Enc(const char* name, c2_node_id_t id,
27 const std::shared_ptr<IntfImpl>& intfImpl)
28 : C2SoftVpxEnc(name, id, intfImpl), mDCTPartitions(0), mProfile(1) {}
29
C2SoftVp8Enc(const char * name,c2_node_id_t id,const std::shared_ptr<C2ReflectorHelper> & helper)30 C2SoftVp8Enc::C2SoftVp8Enc(const char* name, c2_node_id_t id,
31 const std::shared_ptr<C2ReflectorHelper>& helper)
32 : C2SoftVp8Enc(name, id, std::make_shared<IntfImpl>(helper)) {}
33
setCodecSpecificInterface()34 void C2SoftVp8Enc::setCodecSpecificInterface() {
35 mCodecInterface = vpx_codec_vp8_cx();
36 }
37
setCodecSpecificConfiguration()38 void C2SoftVp8Enc::setCodecSpecificConfiguration() {
39 switch (mProfile) {
40 case 1:
41 mCodecConfiguration->g_profile = 0;
42 break;
43
44 case 2:
45 mCodecConfiguration->g_profile = 1;
46 break;
47
48 case 4:
49 mCodecConfiguration->g_profile = 2;
50 break;
51
52 case 8:
53 mCodecConfiguration->g_profile = 3;
54 break;
55
56 default:
57 mCodecConfiguration->g_profile = 0;
58 }
59 }
60
setCodecSpecificControls()61 vpx_codec_err_t C2SoftVp8Enc::setCodecSpecificControls() {
62 vpx_codec_err_t codec_return = vpx_codec_control(mCodecContext,
63 VP8E_SET_TOKEN_PARTITIONS,
64 mDCTPartitions);
65 if (codec_return != VPX_CODEC_OK) {
66 ALOGE("Error setting dct partitions for vpx encoder.");
67 }
68 return codec_return;
69 }
70
71 class C2SoftVp8EncFactory : public C2ComponentFactory {
72 public:
C2SoftVp8EncFactory()73 C2SoftVp8EncFactory()
74 : mHelper(std::static_pointer_cast<C2ReflectorHelper>(
75 GetCodec2PlatformComponentStore()->getParamReflector())) {}
76
createComponent(c2_node_id_t id,std::shared_ptr<C2Component> * const component,std::function<void (C2Component *)> deleter)77 virtual c2_status_t createComponent(
78 c2_node_id_t id,
79 std::shared_ptr<C2Component>* const component,
80 std::function<void(C2Component*)> deleter) override {
81 *component = std::shared_ptr<C2Component>(
82 new C2SoftVp8Enc(COMPONENT_NAME, id,
83 std::make_shared<C2SoftVpxEnc::IntfImpl>(mHelper)),
84 deleter);
85 return C2_OK;
86 }
87
createInterface(c2_node_id_t id,std::shared_ptr<C2ComponentInterface> * const interface,std::function<void (C2ComponentInterface *)> deleter)88 virtual c2_status_t createInterface(
89 c2_node_id_t id,
90 std::shared_ptr<C2ComponentInterface>* const interface,
91 std::function<void(C2ComponentInterface*)> deleter) override {
92 *interface = std::shared_ptr<C2ComponentInterface>(
93 new SimpleInterface<C2SoftVpxEnc::IntfImpl>(
94 COMPONENT_NAME, id,
95 std::make_shared<C2SoftVpxEnc::IntfImpl>(mHelper)),
96 deleter);
97 return C2_OK;
98 }
99
100 virtual ~C2SoftVp8EncFactory() override = default;
101
102 private:
103 std::shared_ptr<C2ReflectorHelper> mHelper;
104 };
105
106 } // namespace android
107
108 __attribute__((cfi_canonical_jump_table))
CreateCodec2Factory()109 extern "C" ::C2ComponentFactory* CreateCodec2Factory() {
110 ALOGV("in %s", __func__);
111 return new ::android::C2SoftVp8EncFactory();
112 }
113
114 __attribute__((cfi_canonical_jump_table))
DestroyCodec2Factory(::C2ComponentFactory * factory)115 extern "C" void DestroyCodec2Factory(::C2ComponentFactory* factory) {
116 ALOGV("in %s", __func__);
117 delete factory;
118 }
119