Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
Jeff Vander Stoep | c9ea211 | 2016-02-17 10:52:20 -0800 | [diff] [blame] | 3 | ** Copyright 2016, The Android Open Source Project |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 18 | #include <fcntl.h> |
| 19 | #include <sys/prctl.h> |
| 20 | #include <sys/wait.h> |
| 21 | #include <binder/IPCThreadState.h> |
| 22 | #include <binder/ProcessState.h> |
| 23 | #include <binder/IServiceManager.h> |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 24 | #include <cutils/properties.h> |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 25 | |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame^] | 26 | #include <android-base/logging.h> |
| 27 | |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 28 | // from LOCAL_C_INCLUDES |
| 29 | #include "MediaCodecService.h" |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame^] | 30 | #include "minijail.h" |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 31 | |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 32 | #include <android/hardware/media/omx/1.0/IOmx.h> |
| 33 | |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 34 | using namespace android; |
| 35 | |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame^] | 36 | // Must match location in Android.mk. |
| 37 | static const char kSeccompPolicyPath[] = "/system/etc/seccomp_policy/mediacodec-seccomp.policy"; |
| 38 | |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 39 | int main(int argc __unused, char** argv) |
| 40 | { |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame^] | 41 | LOG(INFO) << "mediacodecservice starting"; |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 42 | signal(SIGPIPE, SIG_IGN); |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame^] | 43 | SetUpMinijail(kSeccompPolicyPath); |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 44 | |
| 45 | strcpy(argv[0], "media.codec"); |
| 46 | sp<ProcessState> proc(ProcessState::self()); |
| 47 | sp<IServiceManager> sm = defaultServiceManager(); |
| 48 | MediaCodecService::instantiate(); |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 49 | |
| 50 | // Treble |
| 51 | bool useTrebleOmx = bool(property_get_bool("debug.treble_omx", 0)); |
| 52 | if (useTrebleOmx) { |
| 53 | using namespace ::android::hardware::media::omx::V1_0; |
| 54 | sp<IOmx> omx = IOmx::getService(true); |
| 55 | if (omx == nullptr) { |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame^] | 56 | LOG(ERROR) << "Cannot create a Treble IOmx service."; |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 57 | } else if (omx->registerAsService("default") != OK) { |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame^] | 58 | LOG(ERROR) << "Cannot register a Treble IOmx service."; |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 59 | } else { |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame^] | 60 | LOG(VERBOSE) << "Treble IOmx service created."; |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 64 | ProcessState::self()->startThreadPool(); |
| 65 | IPCThreadState::self()->joinThreadPool(); |
| 66 | } |