OSDN Git Service

Port to pie-x86
[android-x86/external-stagefright-plugins.git] / omx / FFmpegOMXPlugin.cpp
1 /*
2  * Copyright (C) 2015 The CyanogenMod 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 "FFmpegOMXPlugin"
19 #include <utils/Log.h>
20
21 #include <media/stagefright/omx/SoftOMXComponent.h>
22
23 #include <media/stagefright/foundation/ADebug.h>
24 #include <media/stagefright/foundation/AString.h>
25
26 #include "FFmpegOMXPlugin.h"
27 #include "FFmpegComponents.h"
28 #include "SoftFFmpegAudio.h"
29 #include "SoftFFmpegVideo.h"
30
31 namespace android {
32
33 OMXPluginBase *createOMXPlugin() {
34     return new FFmpegOMXPlugin();
35 }
36
37 FFmpegOMXPlugin::FFmpegOMXPlugin() {
38 }
39
40 OMX_ERRORTYPE FFmpegOMXPlugin::makeComponentInstance(
41         const char *name,
42         const OMX_CALLBACKTYPE *callbacks,
43         OMX_PTR appData,
44         OMX_COMPONENTTYPE **component) {
45
46     ALOGV("makeComponentInstance '%s'", name);
47
48     sp<SoftOMXComponent> codec;
49
50     for (size_t i = 0; i < kNumAudioComponents; ++i) {
51         if (!strcasecmp(name, android::kAudioComponents[i].mName)) {
52             codec = SoftFFmpegAudio::createSoftOMXComponent(name, callbacks, appData, component);
53             break;
54         }
55     }
56
57     if (codec == NULL) {
58         for (size_t i = 0; i < kNumVideoComponents; ++i) {
59             if (!strcasecmp(name, android::kVideoComponents[i].mName)) {
60                 codec = SoftFFmpegVideo::createSoftOMXComponent(name, callbacks, appData, component);
61                 break;
62             }
63         }
64     }
65
66     if (codec != NULL) {
67         OMX_ERRORTYPE err = codec->initCheck();
68         if (err != OMX_ErrorNone) {
69             return err;
70         }
71
72         codec->incStrong(this);
73
74         return OMX_ErrorNone;
75     }
76
77     return OMX_ErrorInvalidComponentName;
78 }
79
80 OMX_ERRORTYPE FFmpegOMXPlugin::destroyComponentInstance(
81         OMX_COMPONENTTYPE *component) {
82     SoftOMXComponent *me =
83         (SoftOMXComponent *)
84             ((OMX_COMPONENTTYPE *)component)->pComponentPrivate;
85
86     me->prepareForDestruction();
87
88     CHECK_EQ(me->getStrongCount(), 1);
89     me->decStrong(this);
90     me = NULL;
91
92     return OMX_ErrorNone;
93 }
94
95 OMX_ERRORTYPE FFmpegOMXPlugin::enumerateComponents(
96         OMX_STRING name,
97         size_t /* size */,
98         OMX_U32 index) {
99     if (index >= kNumComponents) {
100         return OMX_ErrorNoMore;
101     }
102
103     if (index < kNumAudioComponents) {
104         strcpy(name, kAudioComponents[index].mName);
105     } else {
106         strcpy(name, kVideoComponents[index - kNumAudioComponents].mName);
107     }
108
109     return OMX_ErrorNone;
110 }
111
112 OMX_ERRORTYPE FFmpegOMXPlugin::getRolesOfComponent(
113         const char *name,
114         Vector<String8> *roles) {
115
116     for (size_t i = 0; i < kNumAudioComponents; ++i) {
117         if (strcmp(name, kAudioComponents[i].mName)) {
118             continue;
119         }
120
121         roles->clear();
122         roles->push(String8(kAudioComponents[i].mRole));
123
124         return OMX_ErrorNone;
125     }
126
127     for (size_t i = 0; i < kNumVideoComponents; ++i) {
128         if (strcmp(name, kVideoComponents[i].mName)) {
129             continue;
130         }
131
132         roles->clear();
133         roles->push(String8(kVideoComponents[i].mRole));
134
135         return OMX_ErrorNone;
136     }
137
138     return OMX_ErrorInvalidComponentName;
139 }
140
141 }  // namespace android