SkipCutBuffer.h revision a98478bfbcc0f7fb4b164d3dce40ca96df75667d
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
23namespace android {
24
25/**
26 * utility class to cut the start and end off a stream of data in MediaBuffers
27 *
28 */
29class SkipCutBuffer {
30 public:
31    // 'skip' is the number of bytes to skip from the beginning
32    // 'cut' is the number of bytes to cut from the end
33    // 'output_size' is the size in bytes of the MediaBuffers that will be used
34    SkipCutBuffer(int32_t skip, int32_t cut, int32_t output_size);
35    virtual ~SkipCutBuffer();
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 clear();
42    size_t size(); // how many bytes are currently stored in the buffer
43
44 private:
45    void write(const char *src, size_t num);
46    size_t read(char *dst, size_t num);
47    int32_t mFrontPadding;
48    int32_t mBackPadding;
49    int32_t mWriteHead;
50    int32_t mReadHead;
51    int32_t mCapacity;
52    char* mCutBuffer;
53    DISALLOW_EVIL_CONSTRUCTORS(SkipCutBuffer);
54};
55
56}  // namespace android
57
58#endif  // OMX_CODEC_H_
59