1 /* 2 * Copyright (C) 2012 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 #ifndef SKIP_CUT_BUFFER_H_ 18 19 #define SKIP_CUT_BUFFER_H_ 20 21 #include <media/stagefright/MediaBuffer.h> 22 #include <media/stagefright/foundation/ABuffer.h> 23 24 namespace android { 25 26 /** 27 * utility class to cut the start and end off a stream of data in MediaBuffers 28 * 29 */ 30 class SkipCutBuffer: public RefBase { 31 public: 32 // 'skip' is the number of frames to skip from the beginning 33 // 'cut' is the number of frames to cut from the end 34 // 'num16BitChannels' is the number of channels, which are assumed to be 16 bit wide each 35 SkipCutBuffer(size_t skip, size_t cut, size_t num16Channels); 36 37 // Submit one MediaBuffer for skipping and cutting. This may consume all or 38 // some of the data in the buffer, or it may add data to it. 39 // After this, the caller should continue processing the buffer as usual. 40 void submit(MediaBuffer *buffer); 41 void submit(const sp<ABuffer>& buffer); // same as above, but with an ABuffer 42 void clear(); 43 size_t size(); // how many bytes are currently stored in the buffer 44 45 protected: 46 virtual ~SkipCutBuffer(); 47 48 private: 49 void write(const char *src, size_t num); 50 size_t read(char *dst, size_t num); 51 int32_t mSkip; 52 int32_t mFrontPadding; 53 int32_t mBackPadding; 54 int32_t mWriteHead; 55 int32_t mReadHead; 56 int32_t mCapacity; 57 char* mCutBuffer; 58 DISALLOW_EVIL_CONSTRUCTORS(SkipCutBuffer); 59 }; 60 61 } // namespace android 62 63 #endif // OMX_CODEC_H_ 64