1 /* 2 * Copyright (C) 2018 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 #include <inttypes.h> 18 19 #define LOG_TAG "OmxGraphicBufferSource" 20 //#define LOG_NDEBUG 0 21 #include <utils/Log.h> 22 23 #include <media/stagefright/bqhelper/ComponentWrapper.h> 24 #include <media/stagefright/bqhelper/GraphicBufferSource.h> 25 #include <media/stagefright/omx/OmxGraphicBufferSource.h> 26 27 namespace android { 28 29 namespace { 30 31 class OmxComponentWrapper : public ComponentWrapper { 32 public: 33 explicit OmxComponentWrapper(const sp<IOmxNodeWrapper> &node) 34 : mOmxNode(node) {} 35 virtual ~OmxComponentWrapper() = default; 36 37 status_t submitBuffer( 38 int32_t bufferId, const sp<GraphicBuffer> &buffer, 39 int64_t timestamp, int fenceFd) override { 40 return mOmxNode->emptyBuffer( 41 bufferId, OMX_BUFFERFLAG_ENDOFFRAME, buffer, timestamp, fenceFd); 42 } 43 44 status_t submitEos(int32_t bufferId) override { 45 return mOmxNode->emptyBuffer(bufferId, OMX_BUFFERFLAG_ENDOFFRAME | OMX_BUFFERFLAG_EOS); 46 } 47 48 void dispatchDataSpaceChanged( 49 int32_t dataSpace, int32_t aspects, int32_t pixelFormat) override { 50 mOmxNode->dispatchDataSpaceChanged(dataSpace, aspects, pixelFormat); 51 } 52 53 private: 54 sp<IOmxNodeWrapper> mOmxNode; 55 56 DISALLOW_EVIL_CONSTRUCTORS(OmxComponentWrapper); 57 }; 58 59 } // namespace 60 61 Status OmxGraphicBufferSource::onOmxExecuting() { 62 return start(); 63 } 64 65 Status OmxGraphicBufferSource::onOmxIdle() { 66 return stop(); 67 } 68 69 Status OmxGraphicBufferSource::onOmxLoaded(){ 70 return release(); 71 } 72 73 status_t OmxGraphicBufferSource::configure( 74 const sp<IOmxNodeWrapper>& omxNode, 75 int32_t dataSpace, 76 int32_t bufferCount, 77 uint32_t frameWidth, 78 uint32_t frameHeight, 79 uint32_t consumerUsage) { 80 if (omxNode == NULL) { 81 return BAD_VALUE; 82 } 83 84 return GraphicBufferSource::configure( 85 new OmxComponentWrapper(omxNode), dataSpace, bufferCount, 86 frameWidth, frameHeight, consumerUsage); 87 } 88 89 } // namespace android 90