1 /* 2 * Copyright 2016, 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_TAG "WOmxObserver-utils" 18 19 #include <vector> 20 21 #include <utils/Log.h> 22 #include <cutils/native_handle.h> 23 #include <binder/Binder.h> 24 25 #include <media/omx/1.0/WOmxObserver.h> 26 #include <media/omx/1.0/Conversion.h> 27 28 namespace android { 29 namespace hardware { 30 namespace media { 31 namespace omx { 32 namespace V1_0 { 33 namespace utils { 34 35 // LWOmxObserver 36 LWOmxObserver::LWOmxObserver(sp<IOmxObserver> const& base) : mBase(base) { 37 } 38 39 void LWOmxObserver::onMessages(std::list<omx_message> const& lMessages) { 40 hidl_vec<Message> tMessages; 41 std::vector<native_handle_t*> handles(lMessages.size()); 42 tMessages.resize(lMessages.size()); 43 size_t i = 0; 44 for (auto const& message : lMessages) { 45 wrapAs(&tMessages[i], &handles[i], message); 46 ++i; 47 } 48 auto transResult = mBase->onMessages(tMessages); 49 if (!transResult.isOk()) { 50 ALOGE("LWOmxObserver::onMessages - Transaction failed"); 51 } 52 for (auto& handle : handles) { 53 native_handle_close(handle); 54 native_handle_delete(handle); 55 } 56 } 57 58 // TWOmxObserver 59 TWOmxObserver::TWOmxObserver(sp<IOMXObserver> const& base) : mBase(base) { 60 } 61 62 Return<void> TWOmxObserver::onMessages(const hidl_vec<Message>& tMessages) { 63 std::list<omx_message> lMessages; 64 for (size_t i = 0; i < tMessages.size(); ++i) { 65 lMessages.push_back(omx_message{}); 66 convertTo(&lMessages.back(), tMessages[i]); 67 } 68 mBase->onMessages(lMessages); 69 return Return<void>(); 70 } 71 72 } // namespace utils 73 } // namespace V1_0 74 } // namespace omx 75 } // namespace media 76 } // namespace hardware 77 } // namespace android 78