VideoEditorSRC.h revision e6815bf8b4eaf9cc861e389cbebe3d7412698e9f
1/*
2 * Copyright (C) 2011 NXP Software
3 * Copyright (C) 2011 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <stdint.h>
19
20#include <utils/RefBase.h>
21#include <utils/threads.h>
22
23#include <media/stagefright/MediaSource.h>
24
25#include "AudioBufferProvider.h"
26#include "AudioResampler.h"
27
28namespace android {
29
30struct MediaBuffer;
31
32class VideoEditorSRC : public MediaSource , public AudioBufferProvider {
33
34    public:
35        VideoEditorSRC(
36            const sp<MediaSource> &source);
37
38        virtual status_t start (MetaData *params = NULL);
39        virtual status_t stop();
40        virtual sp<MetaData> getFormat();
41        virtual status_t read (
42            MediaBuffer **buffer, const ReadOptions *options = NULL);
43
44        virtual status_t getNextBuffer(Buffer* buffer);
45        virtual void releaseBuffer(Buffer* buffer);
46
47        void setResampling(int32_t sampleRate=kFreq32000Hz);
48
49    enum { //Sampling freq
50        kFreq8000Hz = 8000,
51        kFreq11025Hz = 11025,
52        kFreq12000Hz = 12000,
53        kFreq16000Hz = 16000,
54        kFreq22050Hz = 22050,
55        kFreq240000Hz = 24000,
56        kFreq32000Hz = 32000,
57        kFreq44100 = 44100,
58        kFreq48000 = 48000,
59    };
60
61    static const uint16_t UNITY_GAIN = 0x1000;
62    static const int32_t DEFAULT_SAMPLING_FREQ = (int32_t)kFreq32000Hz; // kFreq44100;
63
64    protected :
65        virtual ~VideoEditorSRC();
66    private:
67
68        VideoEditorSRC();
69        VideoEditorSRC &operator=(const VideoEditorSRC &);
70
71        AudioResampler        *mResampler;
72        sp<MediaSource>      mSource;
73        MediaBuffer      *mCopyBuffer;
74        int mBitDepth;
75        int mChannelCnt;
76        int mSampleRate;
77        int32_t mOutputSampleRate;
78        bool mStarted;
79        bool mIsResamplingRequired;
80        bool mIsChannelConvertionRequired; // for mono to stereo
81        sp<MetaData> mOutputFormat;
82        Mutex mLock;
83
84        uint8_t* mInterframeBuffer;
85        int32_t mInterframeBufferPosition;
86        int32_t mLeftover;
87        int32_t mLastReadSize ;
88
89        int64_t mInitialTimeStampUs;
90        int64_t mAccuOutBufferSize;
91
92        int64_t mSeekTimeUs;
93        ReadOptions::SeekMode mSeekMode;
94        int16_t *mReSampledBuffer;
95
96};
97
98} //namespce android
99
100