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 | 80959a7 | 2017-02-14 15:49:33 -0500 | [diff] [blame] | 26 | #include <string> |
| 27 | |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame] | 28 | #include <android-base/logging.h> |
| 29 | |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 30 | // from LOCAL_C_INCLUDES |
| 31 | #include "MediaCodecService.h" |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame] | 32 | #include "minijail.h" |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 33 | |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 34 | #include <android/hardware/media/omx/1.0/IOmx.h> |
Pawin Vongmasa | 9c47c97 | 2017-02-08 04:09:38 -0800 | [diff] [blame] | 35 | #include <hidl/HidlTransportSupport.h> |
Pawin Vongmasa | 04563aa | 2017-03-09 07:02:01 -0800 | [diff] [blame] | 36 | #include <omx/1.0/Omx.h> |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 37 | |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 38 | using namespace android; |
| 39 | |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame] | 40 | // Must match location in Android.mk. |
Jeff Vander Stoep | 79234e4 | 2017-02-23 10:03:30 -0800 | [diff] [blame] | 41 | static const char kSystemSeccompPolicyPath[] = |
| 42 | "/system/etc/seccomp_policy/mediacodec.policy"; |
| 43 | static const char kVendorSeccompPolicyPath[] = |
| 44 | "/vendor/etc/seccomp_policy/mediacodec.policy"; |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame] | 45 | |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 46 | int main(int argc __unused, char** argv) |
| 47 | { |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame] | 48 | LOG(INFO) << "mediacodecservice starting"; |
Iliyan Malchev | 6772cfb | 2017-04-11 20:19:36 -0700 | [diff] [blame^] | 49 | bool treble = property_get_bool("persist.media.treble_omx", true); |
| 50 | if (treble) { |
| 51 | android::ProcessState::initWithDriver("/dev/vndbinder"); |
| 52 | } |
| 53 | |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 54 | signal(SIGPIPE, SIG_IGN); |
Jeff Vander Stoep | 79234e4 | 2017-02-23 10:03:30 -0800 | [diff] [blame] | 55 | SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath); |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 56 | |
| 57 | strcpy(argv[0], "media.codec"); |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 58 | |
Pawin Vongmasa | 9c47c97 | 2017-02-08 04:09:38 -0800 | [diff] [blame] | 59 | ::android::hardware::configureRpcThreadpool(64, false); |
| 60 | sp<ProcessState> proc(ProcessState::self()); |
| 61 | |
Iliyan Malchev | 6772cfb | 2017-04-11 20:19:36 -0700 | [diff] [blame^] | 62 | if (treble) { |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 63 | using namespace ::android::hardware::media::omx::V1_0; |
Pawin Vongmasa | 0d3a5ed | 2017-02-22 03:19:35 -0800 | [diff] [blame] | 64 | sp<IOmx> omx = new implementation::Omx(); |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 65 | if (omx == nullptr) { |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame] | 66 | LOG(ERROR) << "Cannot create a Treble IOmx service."; |
Pawin Vongmasa | 0d3a5ed | 2017-02-22 03:19:35 -0800 | [diff] [blame] | 67 | } else if (omx->registerAsService() != OK) { |
Jorge Lucangeli Obes | fbfb8e8 | 2017-02-14 10:33:41 -0500 | [diff] [blame] | 68 | LOG(ERROR) << "Cannot register a Treble IOmx service."; |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 69 | } else { |
Pawin Vongmasa | 9c47c97 | 2017-02-08 04:09:38 -0800 | [diff] [blame] | 70 | LOG(INFO) << "Treble IOmx service created."; |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 71 | } |
Pawin Vongmasa | 9c47c97 | 2017-02-08 04:09:38 -0800 | [diff] [blame] | 72 | } else { |
| 73 | MediaCodecService::instantiate(); |
| 74 | LOG(INFO) << "Non-Treble IOMX service created."; |
Pawin Vongmasa | 033975f | 2016-12-27 03:14:55 +0700 | [diff] [blame] | 75 | } |
| 76 | |
Marco Nelissen | 1900e77 | 2016-02-02 16:12:16 -0800 | [diff] [blame] | 77 | ProcessState::self()->startThreadPool(); |
| 78 | IPCThreadState::self()->joinThreadPool(); |
| 79 | } |