blob: 069665a0c501a805f577287eb745609dbdcaebbe [file] [log] [blame]
Chih-Chung Chang99698662011-06-30 14:21:38 +08001/*
2 * Copyright (C) 2011 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 <stdint.h>
18
19#include <utils/RefBase.h>
20#include <utils/threads.h>
21
22#include <media/stagefright/MediaSource.h>
23
24#include "AudioBufferProvider.h"
25#include "AudioResampler.h"
26
27namespace android {
28
29struct MediaBuffer;
30
31class VideoEditorSRC : public MediaSource , public AudioBufferProvider {
32
33 public:
34 VideoEditorSRC(
35 const sp<MediaSource> &source);
36
37 virtual status_t start (MetaData *params = NULL);
38 virtual status_t stop();
39 virtual sp<MetaData> getFormat();
40 virtual status_t read (
41 MediaBuffer **buffer, const ReadOptions *options = NULL);
42
43 virtual status_t getNextBuffer(Buffer* buffer);
44 virtual void releaseBuffer(Buffer* buffer);
45
46 void setResampling(int32_t sampleRate=kFreq32000Hz);
47
48 enum { //Sampling freq
49 kFreq8000Hz = 8000,
50 kFreq11025Hz = 11025,
51 kFreq12000Hz = 12000,
52 kFreq16000Hz = 16000,
53 kFreq22050Hz = 22050,
54 kFreq240000Hz = 24000,
55 kFreq32000Hz = 32000,
56 kFreq44100 = 44100,
57 kFreq48000 = 48000,
58 };
59
60 static const uint16_t UNITY_GAIN = 0x1000;
61 static const int32_t DEFAULT_SAMPLING_FREQ = (int32_t)kFreq32000Hz; // kFreq44100;
62
63 protected :
64 virtual ~VideoEditorSRC();
65 private:
66
67 VideoEditorSRC();
68 VideoEditorSRC &operator=(const VideoEditorSRC &);
69
70 AudioResampler *mResampler;
71 sp<MediaSource> mSource;
72 MediaBuffer *mCopyBuffer;
73 int mBitDepth;
74 int mChannelCnt;
75 int mSampleRate;
76 int32_t mOutputSampleRate;
77 bool mStarted;
78 bool mIsResamplingRequired;
79 bool mIsChannelConvertionRequired; // for mono to stereo
80 sp<MetaData> mOutputFormat;
81 Mutex mLock;
82
83 uint8_t* mInterframeBuffer;
84 int32_t mInterframeBufferPosition;
85 int32_t mLeftover;
86 int32_t mLastReadSize ;
87
88 int64_t mInitialTimeStampUs;
89 int64_t mAccuOutBufferSize;
90
91 int64_t mSeekTimeUs;
92 ReadOptions::SeekMode mSeekMode;
93 int16_t *mReSampledBuffer;
94
95};
96
97} //namespce android
98