Home | History | Annotate | Download | only in filters
      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 "ZeroFilter"
     19 
     20 #include <media/MediaCodecBuffer.h>
     21 #include <media/stagefright/foundation/ADebug.h>
     22 #include <media/stagefright/foundation/AMessage.h>
     23 
     24 #include "ZeroFilter.h"
     25 
     26 namespace android {
     27 
     28 status_t ZeroFilter::setParameters(const sp<AMessage> &msg) {
     29     sp<AMessage> params;
     30     CHECK(msg->findMessage("params", &params));
     31 
     32     int32_t invert;
     33     if (params->findInt32("invert", &invert)) {
     34         mInvertData = (invert != 0);
     35     }
     36 
     37     return OK;
     38 }
     39 
     40 status_t ZeroFilter::processBuffers(
     41         const sp<MediaCodecBuffer> &srcBuffer, const sp<MediaCodecBuffer> &outBuffer) {
     42     // assuming identical input & output buffers, since we're a copy filter
     43     if (mInvertData) {
     44         uint32_t* src = (uint32_t*)srcBuffer->data();
     45         uint32_t* dest = (uint32_t*)outBuffer->data();
     46         for (size_t i = 0; i < srcBuffer->size() / 4; ++i) {
     47             *(dest++) = *(src++) ^ 0xFFFFFFFF;
     48         }
     49     } else {
     50         memcpy(outBuffer->data(), srcBuffer->data(), srcBuffer->size());
     51     }
     52     outBuffer->setRange(0, srcBuffer->size());
     53 
     54     return OK;
     55 }
     56 
     57 }   // namespace android
     58