1/* 2 * Copyright (C) 2014 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 "RSFilter" 19 20#include <utils/Log.h> 21 22#include <media/stagefright/foundation/ABuffer.h> 23#include <media/stagefright/foundation/ADebug.h> 24#include <media/stagefright/foundation/AMessage.h> 25 26#include "RSFilter.h" 27 28namespace android { 29 30RSFilter::RSFilter() { 31 32} 33 34RSFilter::~RSFilter() { 35 36} 37 38status_t RSFilter::configure(const sp<AMessage> &msg) { 39 status_t err = SimpleFilter::configure(msg); 40 if (err != OK) { 41 return err; 42 } 43 44 if (!msg->findString("cacheDir", &mCacheDir)) { 45 ALOGE("Failed to find cache directory in config message."); 46 return NAME_NOT_FOUND; 47 } 48 49 sp<RenderScriptWrapper> wrapper; 50 if (!msg->findObject("rs-wrapper", (sp<RefBase>*)&wrapper)) { 51 ALOGE("Failed to find RenderScriptWrapper in config message."); 52 return NAME_NOT_FOUND; 53 } 54 55 mRS = wrapper->mContext; 56 mCallback = wrapper->mCallback; 57 58 return OK; 59} 60 61status_t RSFilter::start() { 62 // 32-bit elements for ARGB8888 63 RSC::sp<const RSC::Element> e = RSC::Element::U8_4(mRS); 64 65 RSC::Type::Builder tb(mRS, e); 66 tb.setX(mWidth); 67 tb.setY(mHeight); 68 RSC::sp<const RSC::Type> t = tb.create(); 69 70 mAllocIn = RSC::Allocation::createTyped(mRS, t); 71 mAllocOut = RSC::Allocation::createTyped(mRS, t); 72 73 return OK; 74} 75 76void RSFilter::reset() { 77 mCallback.clear(); 78 mAllocOut.clear(); 79 mAllocIn.clear(); 80 mRS.clear(); 81} 82 83status_t RSFilter::setParameters(const sp<AMessage> &msg) { 84 return mCallback->handleSetParameters(msg); 85} 86 87status_t RSFilter::processBuffers( 88 const sp<ABuffer> &srcBuffer, const sp<ABuffer> &outBuffer) { 89 mAllocIn->copy1DRangeFrom(0, mWidth * mHeight, srcBuffer->data()); 90 mCallback->processBuffers(mAllocIn.get(), mAllocOut.get()); 91 mAllocOut->copy1DRangeTo(0, mWidth * mHeight, outBuffer->data()); 92 93 return OK; 94} 95 96} // namespace android 97