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