Home | History | Annotate | Download | only in stagefright
      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 bytes to skip from the beginning
     33     // 'cut' is the number of bytes to cut from the end
     34     SkipCutBuffer(int32_t skip, int32_t cut);
     35 
     36     // Submit one MediaBuffer for skipping and cutting. This may consume all or
     37     // some of the data in the buffer, or it may add data to it.
     38     // After this, the caller should continue processing the buffer as usual.
     39     void submit(MediaBuffer *buffer);
     40     void submit(const sp<ABuffer>& buffer);    // same as above, but with an ABuffer
     41     void clear();
     42     size_t size(); // how many bytes are currently stored in the buffer
     43 
     44  protected:
     45     virtual ~SkipCutBuffer();
     46 
     47  private:
     48     void write(const char *src, size_t num);
     49     size_t read(char *dst, size_t num);
     50     int32_t mSkip;
     51     int32_t mFrontPadding;
     52     int32_t mBackPadding;
     53     int32_t mWriteHead;
     54     int32_t mReadHead;
     55     int32_t mCapacity;
     56     char* mCutBuffer;
     57     DISALLOW_EVIL_CONSTRUCTORS(SkipCutBuffer);
     58 };
     59 
     60 }  // namespace android
     61 
     62 #endif  // OMX_CODEC_H_
     63